diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/objects.c | 26 | ||||
-rw-r--r-- | src/objects.h | 11 | ||||
-rw-r--r-- | src/slide_render.c | 20 | ||||
-rw-r--r-- | src/slide_render.h | 5 | ||||
-rw-r--r-- | src/tool_image.c | 66 | ||||
-rw-r--r-- | src/tool_text.c | 114 |
6 files changed, 143 insertions, 99 deletions
diff --git a/src/objects.c b/src/objects.c index f1e9259..01e347e 100644 --- a/src/objects.c +++ b/src/objects.c @@ -170,3 +170,29 @@ void delete_object(struct object *o) o->delete_object(o); free(o); } + + +enum corner which_corner(double xp, double yp, struct object *o) +{ + double x, y; /* Relative to object position */ + + x = xp - o->x; + y = yp - o->y; + + if ( x < 0.0 ) return CORNER_NONE; + if ( y < 0.0 ) return CORNER_NONE; + if ( x > o->bb_width ) return CORNER_NONE; + if ( y > o->bb_height ) return CORNER_NONE; + + /* Top left? */ + if ( (x<20.0) && (y<20.0) ) return CORNER_TL; + if ( (x>o->bb_width-20.0) && (y<20.0) ) return CORNER_TR; + if ( (x<20.0) && (y>o->bb_height-20.0) ) { + return CORNER_BL; + } + if ( (x>o->bb_width-20.0) && (y>o->bb_height-20.0) ) { + return CORNER_BR; + } + + return CORNER_NONE; +} diff --git a/src/objects.h b/src/objects.h index 5b3a8b1..fd567e1 100644 --- a/src/objects.h +++ b/src/objects.h @@ -75,6 +75,16 @@ struct image }; +enum corner +{ + CORNER_NONE, + CORNER_TL, + CORNER_TR, + CORNER_BL, + CORNER_BR +}; + + extern struct image *get_image(struct image_store *is, char *filename); extern struct image_store *image_store_new(void); extern void unref_image(struct image *i); @@ -84,5 +94,6 @@ extern void notify_style_update(struct presentation *p, extern void delete_object(struct object *o); +extern enum corner which_corner(double xp, double yp, struct object *o); #endif /* OBJECTS_H */ diff --git a/src/slide_render.c b/src/slide_render.c index d686c77..07b57ec 100644 --- a/src/slide_render.c +++ b/src/slide_render.c @@ -112,6 +112,26 @@ void redraw_slide(struct slide *s) } +void draw_rubberband_box(cairo_t *cr, double x, double y, + double width, double height) +{ + cairo_new_path(cr); + cairo_rectangle(cr, x, y, width, height); + cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); + cairo_set_line_width(cr, 0.5); + cairo_stroke(cr); +} + + +void draw_resize_handle(cairo_t *cr, double x, double y) +{ + cairo_new_path(cr); + cairo_rectangle(cr, x, y, 20.0, 20.0); + cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5); + cairo_fill(cr); +} + + void draw_editing_box(cairo_t *cr, double xmin, double ymin, double width, double height) { diff --git a/src/slide_render.h b/src/slide_render.h index ac3674d..6218924 100644 --- a/src/slide_render.h +++ b/src/slide_render.h @@ -32,6 +32,11 @@ extern void redraw_slide(struct slide *s); +extern void draw_rubberband_box(cairo_t *cr, double xmin, double ymin, + double width, double height); + +extern void draw_resize_handle(cairo_t *cr, double x, double y); + extern void draw_editing_box(cairo_t *cr, double xmin, double ymin, double width, double height); diff --git a/src/tool_image.c b/src/tool_image.c index 719e84d..16ebfa8 100644 --- a/src/tool_image.c +++ b/src/tool_image.c @@ -44,16 +44,6 @@ enum image_drag_reason }; -enum corner -{ - CORNER_NONE, - CORNER_TL, - CORNER_TR, - CORNER_BL, - CORNER_BR -}; - - struct image_toolinfo { struct toolinfo base; @@ -203,32 +193,6 @@ struct object *add_image_object(struct slide *s, double x, double y, } -static enum corner which_corner(double xp, double yp, struct object *o) -{ - double x, y; /* Relative to object position */ - - x = xp - o->x; - y = yp - o->y; - - if ( x < 0.0 ) return CORNER_NONE; - if ( y < 0.0 ) return CORNER_NONE; - if ( x > o->bb_width ) return CORNER_NONE; - if ( y > o->bb_height ) return CORNER_NONE; - - /* Top left? */ - if ( (x<20.0) && (y<20.0) ) return CORNER_TL; - if ( (x>o->bb_width-20.0) && (y<20.0) ) return CORNER_TR; - if ( (x<20.0) && (y>o->bb_height-20.0) ) { - return CORNER_BL; - } - if ( (x>o->bb_width-20.0) && (y>o->bb_height-20.0) ) { - return CORNER_BR; - } - - return CORNER_NONE; -} - - static void calculate_box_size(struct object *o, double x, double y, struct image_toolinfo *ti) { @@ -367,15 +331,6 @@ static int deselect_object(struct object *o, struct toolinfo *tip) } -static void resize_handle(cairo_t *cr, double x, double y) -{ - cairo_new_path(cr); - cairo_rectangle(cr, x, y, 20.0, 20.0); - cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5); - cairo_fill(cr); -} - - static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) { struct image_toolinfo *ti = (struct image_toolinfo *)tip; @@ -386,24 +341,17 @@ static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) draw_editing_box(cr, n->x, n->y, n->bb_width, n->bb_height); /* Draw resize handles */ - resize_handle(cr, n->x+n->bb_width-20.0, - n->y+n->bb_height-20.0); /* BR */ - resize_handle(cr, n->x, n->y+n->bb_height-20.0); /* BL */ - resize_handle(cr, n->x+n->bb_width-20.0, n->y); /* TR */ - resize_handle(cr, n->x, n->y); /* TL */ + draw_resize_handle(cr, n->x, n->y+n->bb_height-20.0); + draw_resize_handle(cr, n->x+n->bb_width-20.0, n->y); + draw_resize_handle(cr, n->x, n->y); + draw_resize_handle(cr, n->x+n->bb_width-20.0, + n->y+n->bb_height-20.0); } if ( ti->drag_reason == IMAGE_DRAG_REASON_RESIZE ) { - - /* FIXME: Use common draw_rubberband_box() routine */ - cairo_new_path(cr); - cairo_rectangle(cr, ti->box_x, ti->box_y, - ti->box_width, ti->box_height); - cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); - cairo_set_line_width(cr, 0.5); - cairo_stroke(cr); - + draw_rubberband_box(cr, ti->box_x, ti->box_y, + ti->box_width, ti->box_height); } } diff --git a/src/tool_text.c b/src/tool_text.c index b371b7d..b22a466 100644 --- a/src/tool_text.c +++ b/src/tool_text.c @@ -50,12 +50,13 @@ struct text_toolinfo struct toolinfo base; PangoContext *pc; enum text_drag_reason drag_reason; + enum corner drag_corner; double box_x; double box_y; double box_width; double box_height; - double drag_offset_x; - double drag_offset_y; + double drag_initial_x; + double drag_initial_y; }; @@ -464,6 +465,54 @@ static struct object *add_text_object(struct slide *s, double x, double y, } +static void calculate_box_size(struct object *o, double x, double y, + struct text_toolinfo *ti) +{ + double ddx, ddy; + + ddx = x - ti->drag_initial_x; + ddy = y - ti->drag_initial_y; + + switch ( ti->drag_corner ) { + + case CORNER_BR : + ti->box_x = o->x; + ti->box_y = o->y; + ti->box_width = o->bb_width + ddx; + ti->box_height = o->bb_height + ddy; + break; + + case CORNER_BL : + ti->box_x = o->x + ddx; + ti->box_y = o->y; + ti->box_width = o->bb_width - ddx; + ti->box_height = o->bb_height + ddy; + break; + + case CORNER_TL : + ti->box_x = o->x + ddx; + ti->box_y = o->y + ddy; + ti->box_width = o->bb_width - ddx; + ti->box_height = o->bb_height - ddy; + break; + + case CORNER_TR : + ti->box_x = o->x; + ti->box_y = o->y + ddy; + ti->box_width = o->bb_width + ddx; + ti->box_height = o->bb_height - ddy; + break; + + case CORNER_NONE : + break; + + } + + if ( ti->box_width < 20.0 ) ti->box_width = 20.0; + if ( ti->box_height < 20.0 ) ti->box_height = 20.0; +} + + static void click_select(struct presentation *p, struct toolinfo *tip, double x, double y, GdkEventButton *event, enum drag_status *drag_status, @@ -472,6 +521,7 @@ static void click_select(struct presentation *p, struct toolinfo *tip, int xp, yp; double xo, yo; gboolean v; + enum corner c; struct text_toolinfo *ti = (struct text_toolinfo *)tip; struct text_object *o = (struct text_object *)p->editing_object; int idx, trail; @@ -481,24 +531,16 @@ static void click_select(struct presentation *p, struct toolinfo *tip, xo = x - o->base.x; yo = y - o->base.y; /* Within the resizing region? */ - if ( (xo > o->base.bb_width - 20.0) && (yo > o->base.bb_height - 20.0) - && (!o->furniture) ) + c = which_corner(x, y, &o->base); + if ( (c != CORNER_NONE) && !o->furniture ) { - double cx, cy; - ti->drag_reason = TEXT_DRAG_REASON_RESIZE; + ti->drag_corner = c; - /* Initial size of rubber band box */ - ti->box_x = o->base.x; ti->box_y = o->base.y; - ti->box_width = o->base.bb_width; - ti->box_height = o->base.bb_height; + ti->drag_initial_x = x; + ti->drag_initial_y = y; - /* Coordinates of the bottom right corner */ - cx = o->base.x + o->base.bb_width; - cy = o->base.y + o->base.bb_height; - - ti->drag_offset_x = x - cx; - ti->drag_offset_y = y - cy; + calculate_box_size((struct object *)o, x, y, ti); /* Tell the MCP what we did, and return */ *drag_status = DRAG_STATUS_DRAGGING; @@ -521,12 +563,12 @@ static void drag(struct toolinfo *tip, struct presentation *p, { struct text_toolinfo *ti = (struct text_toolinfo *)tip; - ti->box_width = x - ti->drag_offset_x - ti->box_x; - ti->box_height = y - ti->drag_offset_y - ti->box_y; - if ( ti->box_width < 20.0 ) ti->box_width = 20.0; - if ( ti->box_height < 20.0 ) ti->box_height = 20.0; + if ( ti->drag_reason == TEXT_DRAG_REASON_RESIZE ) { - redraw_overlay(p); + calculate_box_size(o, x, y, ti); + redraw_overlay(p); + + } } @@ -535,11 +577,10 @@ static void end_drag(struct toolinfo *tip, struct presentation *p, { struct text_toolinfo *ti = (struct text_toolinfo *)tip; - ti->box_width = x - ti->drag_offset_x - ti->box_x; - ti->box_height = y - ti->drag_offset_y - ti->box_y; - if ( ti->box_width < 20.0 ) ti->box_width = 20.0; - if ( ti->box_height < 20.0 ) ti->box_height = 20.0; + calculate_box_size((struct object *)o, x, y, ti); + o->x = ti->box_x; + o->y = ti->box_y; o->bb_width = ti->box_width; o->bb_height = ti->box_height; update_text((struct text_object *)o); @@ -612,12 +653,12 @@ static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) if ( !o->furniture ) { - /* Draw resize handle */ - cairo_new_path(cr); - cairo_rectangle(cr, n->x+n->bb_width-20.0, - n->y+n->bb_height-20.0, 20.0, 20.0); - cairo_set_source_rgba(cr, 0.9, 0.9, 0.9, 0.5); - cairo_fill(cr); + /* Draw resize handles */ + draw_resize_handle(cr, n->x, n->y+n->bb_height-20.0); + draw_resize_handle(cr, n->x+n->bb_width-20.0, n->y); + draw_resize_handle(cr, n->x, n->y); + draw_resize_handle(cr, n->x+n->bb_width-20.0, + n->y+n->bb_height-20.0); } @@ -625,15 +666,8 @@ static void draw_overlay(struct toolinfo *tip, cairo_t *cr, struct object *n) } if ( ti->drag_reason == TEXT_DRAG_REASON_RESIZE ) { - - /* FIXME: Use common draw_rubberband_box() routine */ - cairo_new_path(cr); - cairo_rectangle(cr, ti->box_x, ti->box_y, - ti->box_width, ti->box_height); - cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); - cairo_set_line_width(cr, 0.5); - cairo_stroke(cr); - + draw_rubberband_box(cr, ti->box_x, ti->box_y, + ti->box_width, ti->box_height); } } |