summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-12-06 21:39:53 +0100
committerGuillaume Seguin <guillaume@segu.in>2007-12-06 21:39:53 +0100
commit4b4e85a8e7cf5b685960166bd057aa1bf1c0c11c (patch)
tree23b7801103f416cdacb68aa7dc854b82cc23bdc2
parentac64b24f9b8b157cef29bcb20ee675801bbe1572 (diff)
downloadgmathlib-4b4e85a8e7cf5b685960166bd057aa1bf1c0c11c.tar.gz
gmathlib-4b4e85a8e7cf5b685960166bd057aa1bf1c0c11c.tar.bz2
* Improve symbol selection for gMathView (a future highlight mode)
-rw-r--r--gmathview/gmathview.c19
-rw-r--r--gmathview/gmathview_utils.c15
-rw-r--r--include/gmathview.h10
3 files changed, 43 insertions, 1 deletions
diff --git a/gmathview/gmathview.c b/gmathview/gmathview.c
index 1e2223a..66c5a27 100644
--- a/gmathview/gmathview.c
+++ b/gmathview/gmathview.c
@@ -37,6 +37,7 @@ struct _GMathViewPrivate
GMathCairoContext *cairo_context;
GMathBoxed *current_boxed;
+ GMathSelectionType selection_type;
};
G_DEFINE_TYPE (GMathView, g_math_view, GTK_TYPE_DRAWING_AREA)
@@ -86,6 +87,9 @@ g_math_view_init (GMathView *mathview)
priv->context = gmathcontext_new ();
priv->cairo_context = gmathcairocontext_new (priv->context);
+ priv->current_boxed = NULL;
+ priv->selection_type = GMathSelectionNone;
+
gtk_widget_add_events (GTK_WIDGET (mathview),
GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK);
}
@@ -139,6 +143,14 @@ g_math_view_on_button_press (GtkWidget *widget, GdkEventButton *event)
g_message ("*CLICK* on symbol of type %s", container->symbol->type);
priv->current_boxed = container;
+
+ if (event->type == GDK_BUTTON_PRESS)
+ priv->selection_type = GMathSelectionOutline;
+ else if (event->type == GDK_2BUTTON_PRESS)
+ priv->selection_type = GMathSelectionHighlight;
+ else
+ priv->selection_type = GMathSelectionNone;
+
g_math_view_force_redraw (G_MATH_VIEW (widget));
return FALSE;
@@ -181,7 +193,12 @@ g_math_view_do_expose (GtkWidget *widget, GdkEventExpose *event)
BASE_OFFSET, BASE_OFFSET);
cairo_paint (cr);
if (priv->current_boxed)
- g_math_view_outline_boxed (cr, priv->current_boxed);
+ {
+ if (priv->selection_type == GMathSelectionOutline)
+ g_math_view_outline_boxed (cr, priv->current_boxed);
+ /*else if (priv->selection_type == GMathSelectionHighlight)
+ g_math_view_highlight_boxed (cr, priv->current_boxed);*/
+ }
}
cairo_destroy (cr);
diff --git a/gmathview/gmathview_utils.c b/gmathview/gmathview_utils.c
index 0bc2412..2d71253 100644
--- a/gmathview/gmathview_utils.c
+++ b/gmathview/gmathview_utils.c
@@ -61,3 +61,18 @@ g_math_view_outline_boxed (cairo_t *cr, GMathBoxed *boxed)
boxed->box.width, boxed->box.height);
cairo_stroke (cr);
}
+
+void
+g_math_view_highlight_boxed (cairo_t *cr, GMathBoxed *boxed)
+{
+ if (!cr || !boxed)
+ return;
+
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_XOR);
+ cairo_set_line_width (cr, OUTLINE_WIDTH);
+
+ cairo_rectangle (cr, boxed->box.x, boxed->box.y,
+ boxed->box.width, boxed->box.height);
+ cairo_fill (cr);
+}
diff --git a/include/gmathview.h b/include/gmathview.h
index 6aeb5b1..6c34ebd 100644
--- a/include/gmathview.h
+++ b/include/gmathview.h
@@ -64,6 +64,13 @@ struct _GMathViewClass
GtkDrawingAreaClass parent_class;
};
+typedef enum
+{
+ GMathSelectionNone,
+ GMathSelectionOutline,
+ GMathSelectionHighlight
+} GMathSelectionType;
+
GType
g_math_view_get_type (void) G_GNUC_CONST;
@@ -98,4 +105,7 @@ g_math_view_copy_surface (cairo_surface_t *source);
void
g_math_view_outline_boxed (cairo_t *cr, GMathBoxed *boxed);
+void
+g_math_view_highlight_boxed (cairo_t *cr, GMathBoxed *boxed);
+
#endif