static void gv_rotate_tool_button_press(GvTool *r_tool, GdkEventButton *event) { GvRotateTool *tool = GV_ROTATE_TOOL(r_tool); if( event->state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK) ) return; /* -------------------------------------------------------------------- */ /* Have we selected an active control point on the scale/rotate */ /* dohickey? */ /* -------------------------------------------------------------------- */ if( tool->rrmode == RRMODE_DISPLAY && tool->shape_id != -1 ) { gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y, &tool->v_head.x, &tool->v_head.y); /* ** Is this location a hit on an arrow head? */ tool->rrmode = gv_rotate_tool_classify_hit( tool, tool->v_head.x, tool->v_head.y ); /* ** Copy the original state of this shape, and disable undo till we are ** done. */ if( tool->rrmode != RRMODE_DISPLAY ) { if( event->button != 1 ) tool->rrmode = RRMODE_ROTATESCALE; tool->original = gv_shape_copy( gv_shapes_get_shape( tool->layer->data, tool->shape_id )); gv_undo_close(); gv_undo_disable(); } } /* -------------------------------------------------------------------- */ /* Are we selecting a shape? Note, currently we cannot clear */ /* our selection in resize/rotate mode - should we be able to? */ /* -------------------------------------------------------------------- */ if (event->button == 1 && tool->rrmode == RRMODE_DISPLAY ) { int shape_id; if (!gv_rotate_tool_configure(tool)) return; if (gv_shape_layer_pick_shape(GV_SHAPE_LAYER(tool->layer), GV_TOOL(tool)->view, event->x, event->y, &shape_id)) { GvShape *shape; /* Is the shape rotatable? */ shape = gv_shapes_get_shape( tool->layer->data, shape_id ); if( TRUE ) { gv_shape_layer_clear_selection( GV_SHAPE_LAYER(tool->layer)); gv_shape_layer_select_shape( GV_SHAPE_LAYER(tool->layer), shape_id); tool->shape_id = shape_id; gv_view_area_queue_draw(GV_TOOL(tool)->view); } } return; } }
static gboolean gv_rect_tool_button_press(GvTool *r_tool, GdkEventButton *event) { GvRectTool *tool = GV_RECT_TOOL(r_tool); if (event->button == 1 && !tool->drawing ) { GvNodeInfo edit_node; int before, shape_id, is_rectangle = FALSE; if (!gv_rect_tool_configure(tool)) return FALSE; if (gv_shape_layer_pick_shape(GV_SHAPE_LAYER(tool->layer), GV_TOOL(tool)->view, event->x, event->y, &shape_id)) { GvShape *shape; /* Is the shape a rectangle? */ shape = gv_shapes_get_shape( tool->layer->data, shape_id ); if( shape != NULL && gv_shape_type(shape) == GVSHAPE_AREA && gv_shape_get_rings( shape ) == 1 && gv_shape_get_nodes( shape, 0 ) == 5 ) { gvgeocoord x1, y1, x2, y2; x1 = gv_shape_get_x(shape,0,0); y1 = gv_shape_get_y(shape,0,0); x2 = gv_shape_get_x(shape,0,2); y2 = gv_shape_get_y(shape,0,2); tool->winding = 1; is_rectangle = gv_shape_get_x(shape,0,1) == x1 && gv_shape_get_y(shape,0,1) == y2 && gv_shape_get_x(shape,0,3) == x2 && gv_shape_get_y(shape,0,3) == y1 && gv_shape_get_x(shape,0,4) == x1 && gv_shape_get_y(shape,0,4) == y1; if( !is_rectangle ) { tool->winding = 0; is_rectangle = gv_shape_get_x(shape,0,1) == x2 && gv_shape_get_y(shape,0,1) == y1 && gv_shape_get_x(shape,0,3) == x1 && gv_shape_get_y(shape,0,3) == y2 && gv_shape_get_x(shape,0,4) == x1 && gv_shape_get_y(shape,0,4) == y1; } if( is_rectangle ) { gv_shape_layer_clear_selection( GV_SHAPE_LAYER(tool->layer)); gv_shape_layer_select_shape( GV_SHAPE_LAYER(tool->layer), shape_id); } } } /* Is the user selecting an existing rectangles edge/corner? */ if (is_rectangle && gv_shape_layer_pick_node(GV_SHAPE_LAYER(tool->layer), GV_TOOL(tool)->view, event->x, event->y, &before, &edit_node) ) { if( tool->winding == 0 ) { if( before ) edit_node.node_id = 5 - edit_node.node_id; else edit_node.node_id = 4 - edit_node.node_id; } if( before && edit_node.node_id == 1 ) tool->picked = PICK_SIDE_LEFT; else if( before && edit_node.node_id == 2 ) tool->picked = PICK_SIDE_BOTTOM; else if( before && edit_node.node_id == 3 ) tool->picked = PICK_SIDE_RIGHT; else if( before && edit_node.node_id == 4 ) tool->picked = PICK_SIDE_TOP; else if( edit_node.node_id == 0 ) tool->picked = PICK_CORNER_TOPLEFT; else if( edit_node.node_id == 1 ) tool->picked = PICK_CORNER_BOTTOMLEFT; else if( edit_node.node_id == 2 ) tool->picked = PICK_CORNER_BOTTOMRIGHT; else if( edit_node.node_id == 3 ) tool->picked = PICK_CORNER_TOPRIGHT; else if( edit_node.node_id == 4 ) tool->picked = PICK_CORNER_TOPLEFT; else { g_warning( "Yikes! What node is this?" ); return FALSE; } tool->reshaping = TRUE; tool->shape_id = edit_node.shape_id; /* Close down undo. A single operation describing the new ring will be pushed to undo when drawing stops. */ gv_undo_close(); gv_undo_disable(); return FALSE; } /* Map pointer position to tail vertex */ gv_view_area_map_pointer(GV_TOOL(tool)->view, event->x, event->y, &tool->v_tail.x, &tool->v_tail.y); if( gv_tool_check_bounds( GV_TOOL(tool), tool->v_tail.x, tool->v_tail.y ) ) { /* Start a new rect */ tool->drawing = TRUE; tool->v_head = tool->v_tail; } } return FALSE; }