Пример #1
0
static void
gv_rect_tool_key_press(GvTool *rtool, GdkEventKey *event)
{
    GvRectTool *tool = GV_RECT_TOOL(rtool);

    if (!gv_rect_tool_configure(tool)) return;

    switch (event->keyval)
    {
        case GDK_Delete:
        case GDK_BackSpace:
        case GDK_Escape:
          if( tool->drawing )
          {
              tool->drawing = FALSE;
              gv_view_area_queue_draw(GV_TOOL(tool)->view);
          }
          if( tool->reshaping )
          {
              /* Reopen undo.  Push a memento describing the ring addition */
              gv_undo_enable();
              gv_undo_open();

              tool->reshaping = FALSE;
              gv_view_area_queue_draw(GV_TOOL(tool)->view);
          }
          break;
    }
}
Пример #2
0
void 
gv_rotate_tool_terminate( GvRotateTool *tool )
{
    if( tool->rrmode == RRMODE_DISPLAY )
        return;

    if( tool->original != NULL 
        && gv_shapes_get_shape( tool->layer->data, tool->shape_id) != NULL )
    {
        gv_shapes_replace_shapes( tool->layer->data, 1, &(tool->shape_id), 
                                  &(tool->original), FALSE );
        tool->original = NULL;
        gv_undo_enable();
        gv_undo_open();
    }
    else if( tool->original != NULL )
    {
        gv_shape_delete( tool->original );
        tool->original = NULL;
        gv_undo_enable();
        gv_undo_open();
    }

    tool->shape_id = -1;
    tool->rrmode = RRMODE_DISPLAY;
    gv_view_area_queue_draw(GV_TOOL(tool)->view);
}
Пример #3
0
static gboolean
gv_rect_tool_motion_notify(GvTool *r_tool, GdkEventMotion *event)
{
    GvRectTool *tool = GV_RECT_TOOL(r_tool);

    if (tool->drawing)
    {
        /* 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);

        gv_tool_clamp_to_bounds( GV_TOOL(tool),
                                 &tool->v_tail.x, &tool->v_tail.y );

        gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }

    if (tool->reshaping)
    {
        /* 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);
        gv_rect_tool_reshape( tool, tool->v_tail.x, tool->v_tail.y );
    }
    return FALSE;
}
Пример #4
0
void
gv_rotate_tool_set_layer(GvRotateTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
	g_warning("gv_rotate_tool_set_layer(): inactive tool");
	return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_rotate_tool_set_layer(): layer is read-only" );
        return;
    }

    gv_rotate_tool_terminate( tool );
    tool->shape_id = -1;

    /* Disconnect from the previous layer (for draw) */
    if (tool->layer)
    {
        tool->rrmode = RRMODE_DISPLAY;

        /** TODO: Not sure that we need to unselect ... try to remove later */

	gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
	gtk_signal_disconnect_by_data(GTK_OBJECT(tool->layer), (gpointer)tool);
	gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }
 
    if( layer == NULL )
        tool->layer = NULL;
    else
        tool->layer = GV_SHAPES_LAYER(layer);

    if (layer)
    {
	gv_view_area_set_active_layer(GV_TOOL(tool)->view, GTK_OBJECT(layer));
	
        /* Redraw when the layer draws */
	gtk_signal_connect_object_after(GTK_OBJECT(layer), "draw",
					GTK_SIGNAL_FUNC(gv_rotate_tool_draw),
					GTK_OBJECT(tool));
        /* Recover if layer destroyed */
        gtk_signal_connect(
            GTK_OBJECT(layer), "destroy", 
            GTK_SIGNAL_FUNC(gv_rotate_tool_layer_destroy),
            GTK_OBJECT(tool));
    }
}
Пример #5
0
void
gv_rect_tool_set_layer(GvRectTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
        g_warning("gv_rect_tool_set_layer(): inactive tool");
        return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_rect_tool_set_layer(): layer is read-only" );
        return;
    }

    /* Disconnect from the previous layer (for draw) */
    if (tool->layer)
    {
        if (tool->drawing)
            tool->drawing = FALSE;

        gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
        g_signal_handlers_disconnect_matched (tool->layer, G_SIGNAL_MATCH_DATA,
                                                0, 0, NULL, NULL, tool);
        gv_view_area_queue_draw(GV_TOOL(tool)->view);
    }

    if( layer == NULL )
        tool->layer = NULL;
    else
        tool->layer = GV_SHAPES_LAYER(layer);

    if (layer)
    {
        gv_view_area_set_active_layer(GV_TOOL(tool)->view, G_OBJECT(layer));

        /* Redraw when the layer draws */
        g_signal_connect_object(layer, "draw",
                                G_CALLBACK(gv_rect_tool_draw),
                                GV_TOOL(tool), G_CONNECT_SWAPPED | G_CONNECT_AFTER);

        /* recover if layer destroyed */
        g_signal_connect_swapped(layer, "teardown",
                                G_CALLBACK(gv_rect_tool_layer_destroy),
                                tool);
    }
}
Пример #6
0
void
gv_point_tool_set_layer(GvPointTool *tool, GvShapeLayer *layer)
{
    if (GV_TOOL(tool)->view == NULL)
    {
	g_warning("gv_point_tool_set_layer(): inactive tool");
	return;
    }

    if( layer != NULL 
        && !GV_IS_POINT_LAYER(layer) && !GV_IS_SHAPES_LAYER(layer) )
    {
        g_warning( "gv_point_tool_set_layer(): not a point capable layer" );
        return;
    }

    if( layer != NULL && gv_data_is_read_only( GV_DATA(layer) ) )
    {
        g_warning( "gv_point_tool_set_layer(): layer is read-only" );
        return;
    }

    /* Disconnect from the previous layer */
    if (tool->layer)
    {
	gv_shape_layer_clear_selection(GV_SHAPE_LAYER(tool->layer));
	gv_view_area_queue_draw(GV_TOOL(tool)->view);
        gtk_signal_disconnect_by_data( GTK_OBJECT(tool->layer), 
                                       GTK_OBJECT(tool) );
    }
    
    tool->layer = layer;

    if (layer)
    {
	gv_view_area_set_active_layer(GV_TOOL(tool)->view, GTK_OBJECT(layer));
        gtk_signal_connect(
            GTK_OBJECT(layer), "destroy", 
            GTK_SIGNAL_FUNC(gv_point_tool_layer_destroy),
            GTK_OBJECT(tool));
    }
}
Пример #7
0
static void
gv_rotate_tool_motion_notify(GvTool *r_tool, GdkEventMotion *event)
{
    GvRotateTool *tool = GV_ROTATE_TOOL(r_tool);
    GvShape  *wrk_shape;

    if (tool->rrmode == RRMODE_DISPLAY )
        return;


    wrk_shape = gv_shape_copy(tool->original);

    /* 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);

    /* Compute rotation from base. */
    if( tool->rrmode == RRMODE_ROTATE 
        || tool->rrmode == RRMODE_ROTATESCALE )
    {
        double dx = tool->v_tail.x - tool->v_pivot.x;
        double dy = tool->v_tail.y - tool->v_pivot.y;

        if( fabs(dy) < fabs(dx)/1000000.0 )
            tool->rotation = M_PI/2;
        else
            tool->rotation = atan(fabs(dx/dy));


        if( dy < 0.0 && dx >= 0.0 )
            tool->rotation = M_PI - tool->rotation;
        else if( dy >= 0.0 && dx < 0.0 )
            tool->rotation = -tool->rotation;
        else if( dy < 0.0 && dx < 0.0 )
            tool->rotation -= M_PI;


        tool->rotation = (tool->rotation / M_PI) * 180;

        gv_shape_rotate( wrk_shape, tool->rotation );
    }

    /* Compute Scaling from base. */
    if( tool->rrmode == RRMODE_SCALE 
        || tool->rrmode == RRMODE_ROTATESCALE )
    {
        double dx, dy, old_length, new_length;

        dx = tool->v_tail.x - tool->v_pivot.x;
        dy = tool->v_tail.y - tool->v_pivot.y;
        new_length = sqrt(dx*dx + dy*dy);
        
        dx = tool->v_head.x - tool->v_pivot.x;
        dy = tool->v_head.y - tool->v_pivot.y;
        old_length = sqrt(dx*dx + dy*dy);

        tool->scaling = new_length / old_length;

        gv_shape_scale( wrk_shape, tool->scaling );
    }
    
    /* Apply to the shapes object ... this will create an undo step */
    gv_shapes_replace_shapes( tool->layer->data, 1, &(tool->shape_id), 
                              &wrk_shape, FALSE );

    gv_view_area_queue_draw(GV_TOOL(tool)->view);
}
Пример #8
0
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;
    }

}