Bind actions to cursor keys in LdCanvas.
If there's a selection, move it. Otherwise move the viewport.
This commit is contained in:
parent
c091f71f9a
commit
a967a2c3b8
|
@ -172,6 +172,7 @@ static void on_adjustment_value_changed
|
||||||
static void on_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
|
static void on_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static void update_adjustments (LdCanvas *self);
|
static void update_adjustments (LdCanvas *self);
|
||||||
|
static void ld_canvas_real_move (LdCanvas *self, gdouble dx, gdouble dy);
|
||||||
|
|
||||||
static void diagram_connect_signals (LdCanvas *self);
|
static void diagram_connect_signals (LdCanvas *self);
|
||||||
static void diagram_disconnect_signals (LdCanvas *self);
|
static void diagram_disconnect_signals (LdCanvas *self);
|
||||||
|
@ -247,10 +248,19 @@ ld_canvas_class_init (LdCanvasClass *klass)
|
||||||
|
|
||||||
klass->set_scroll_adjustments = ld_canvas_real_set_scroll_adjustments;
|
klass->set_scroll_adjustments = ld_canvas_real_set_scroll_adjustments;
|
||||||
klass->cancel_operation = ld_canvas_real_cancel_operation;
|
klass->cancel_operation = ld_canvas_real_cancel_operation;
|
||||||
|
klass->move = ld_canvas_real_move;
|
||||||
|
|
||||||
binding_set = gtk_binding_set_by_class (klass);
|
binding_set = gtk_binding_set_by_class (klass);
|
||||||
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
|
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
|
||||||
"cancel-operation", 0);
|
"cancel-operation", 0);
|
||||||
|
gtk_binding_entry_add_signal (binding_set, GDK_Left, 0,
|
||||||
|
"move", 2, G_TYPE_DOUBLE, (gdouble) -1, G_TYPE_DOUBLE, (gdouble) 0);
|
||||||
|
gtk_binding_entry_add_signal (binding_set, GDK_Right, 0,
|
||||||
|
"move", 2, G_TYPE_DOUBLE, (gdouble) 1, G_TYPE_DOUBLE, (gdouble) 0);
|
||||||
|
gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
|
||||||
|
"move", 2, G_TYPE_DOUBLE, (gdouble) 0, G_TYPE_DOUBLE, (gdouble) -1);
|
||||||
|
gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
|
||||||
|
"move", 2, G_TYPE_DOUBLE, (gdouble) 0, G_TYPE_DOUBLE, (gdouble) 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LdCanvas:diagram:
|
* LdCanvas:diagram:
|
||||||
|
@ -311,6 +321,21 @@ ld_canvas_class_init (LdCanvasClass *klass)
|
||||||
g_cclosure_marshal_VOID__VOID,
|
g_cclosure_marshal_VOID__VOID,
|
||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LdCanvas::move:
|
||||||
|
* @self: an #LdCanvas object.
|
||||||
|
* @dx: The difference by which to move on the horizontal axis.
|
||||||
|
* @dy: The difference by which to move on the vertical axis.
|
||||||
|
*
|
||||||
|
* Move the selection, if any, or the document.
|
||||||
|
*/
|
||||||
|
klass->move_signal = g_signal_new
|
||||||
|
("move", G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||||
|
G_STRUCT_OFFSET (LdCanvasClass, move), NULL, NULL,
|
||||||
|
ld_marshal_VOID__DOUBLE_DOUBLE,
|
||||||
|
G_TYPE_NONE, 2, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (LdCanvasPrivate));
|
g_type_class_add_private (klass, sizeof (LdCanvasPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,6 +577,42 @@ update_adjustments (LdCanvas *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_canvas_real_move (LdCanvas *self, gdouble dx, gdouble dy)
|
||||||
|
{
|
||||||
|
LdDiagram *diagram;
|
||||||
|
GList *selection, *iter;
|
||||||
|
|
||||||
|
/* TODO: Check/move boundaries, also implement normal
|
||||||
|
* getters and setters for priv->x and priv->y.
|
||||||
|
*/
|
||||||
|
diagram = self->priv->diagram;
|
||||||
|
selection = ld_diagram_get_selection (diagram);
|
||||||
|
if (selection)
|
||||||
|
{
|
||||||
|
ld_diagram_begin_user_action (diagram);
|
||||||
|
for (iter = selection; iter; iter = g_list_next (iter))
|
||||||
|
{
|
||||||
|
gdouble x, y;
|
||||||
|
|
||||||
|
g_object_get (iter->data, "x", &x, "y", &y, NULL);
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
g_object_set (iter->data, "x", x, "y", y, NULL);
|
||||||
|
}
|
||||||
|
ld_diagram_end_user_action (diagram);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self->priv->x += dx;
|
||||||
|
self->priv->y += dy;
|
||||||
|
|
||||||
|
simulate_motion (self);
|
||||||
|
update_adjustments (self);
|
||||||
|
}
|
||||||
|
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===== Generic interface etc. ============================================ */
|
/* ===== Generic interface etc. ============================================ */
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* ld-canvas.h
|
* ld-canvas.h
|
||||||
*
|
*
|
||||||
* This file is a part of logdiag.
|
* This file is a part of logdiag.
|
||||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||||
*
|
*
|
||||||
* See the file LICENSE for licensing information.
|
* See the file LICENSE for licensing information.
|
||||||
*
|
*
|
||||||
|
@ -47,10 +47,12 @@ struct _LdCanvasClass
|
||||||
GtkDrawingAreaClass parent_class;
|
GtkDrawingAreaClass parent_class;
|
||||||
|
|
||||||
guint cancel_operation_signal;
|
guint cancel_operation_signal;
|
||||||
|
guint move_signal;
|
||||||
|
|
||||||
void (*set_scroll_adjustments) (LdCanvas *self,
|
void (*set_scroll_adjustments) (LdCanvas *self,
|
||||||
GtkAdjustment *horizontal, GtkAdjustment *vertical);
|
GtkAdjustment *horizontal, GtkAdjustment *vertical);
|
||||||
void (*cancel_operation) (LdCanvas *self);
|
void (*cancel_operation) (LdCanvas *self);
|
||||||
|
void (*move) (LdCanvas *self, gdouble dx, gdouble dy);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
VOID:OBJECT,OBJECT
|
VOID:OBJECT,OBJECT
|
||||||
VOID:OBJECT,STRING
|
VOID:OBJECT,STRING
|
||||||
|
VOID:DOUBLE,DOUBLE
|
||||||
|
|
Loading…
Reference in New Issue