Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Straigh line support #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void paint_update_temporary_shape(struct swappy_state *state, double x,
break;
case SWAPPY_PAINT_MODE_ARROW:
paint->can_draw = true; // all set
paint->content.shape.should_center_at_from = is_control_pressed;

paint->content.shape.to.x = x;
paint->content.shape.to.y = y;
Expand Down
24 changes: 13 additions & 11 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static void render_shape_arrow(cairo_t *cr, struct swappy_paint_shape shape) {
double fty = shape.to.y - shape.from.y;
double ftn = sqrt(ftx * ftx + fty * fty);

double r = 20;
double r = shape.should_center_at_from ? 0 : 20;
double scaling_factor = shape.w / 4;

double alpha = G_PI / 6;
Expand Down Expand Up @@ -269,16 +269,18 @@ static void render_shape_arrow(cairo_t *cr, struct swappy_paint_shape shape) {
cairo_restore(cr);

// Draw arrow
cairo_save(cr);
cairo_translate(cr, shape.to.x, shape.to.y);
cairo_rotate(cr, theta);
cairo_scale(cr, scaling_factor, scaling_factor);
cairo_move_to(cr, 0, 0);
cairo_line_to(cr, xa, ya);
cairo_line_to(cr, xb, yb);
cairo_line_to(cr, 0, 0);
cairo_fill(cr);
cairo_restore(cr);
if (!shape.should_center_at_from) {
cairo_save(cr);
cairo_translate(cr, shape.to.x, shape.to.y);
cairo_rotate(cr, theta);
cairo_scale(cr, scaling_factor, scaling_factor);
cairo_move_to(cr, 0, 0);
cairo_line_to(cr, xa, ya);
cairo_line_to(cr, xb, yb);
cairo_line_to(cr, 0, 0);
cairo_fill(cr);
cairo_restore(cr);
}
}

static void render_shape_ellipse(cairo_t *cr, struct swappy_paint_shape shape) {
Expand Down