summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2007-12-06 18:50:01 +0100
committerGuillaume Seguin <guillaume@segu.in>2007-12-06 18:50:01 +0100
commitac64b24f9b8b157cef29bcb20ee675801bbe1572 (patch)
tree0e30cea6fb2a0d52ba41da5589e13ee74cd2ff2e
parentfefcd04cde32b38a304c860d38df73336777c93c (diff)
downloadgmathlib-ac64b24f9b8b157cef29bcb20ee675801bbe1572.tar.gz
gmathlib-ac64b24f9b8b157cef29bcb20ee675801bbe1572.tar.bz2
* Rework current symbol outlining in gMathView
-rw-r--r--gmathview/gmathview.c55
-rw-r--r--gmathview/gmathview_utils.c12
-rw-r--r--include/gmathview.h3
3 files changed, 26 insertions, 44 deletions
diff --git a/gmathview/gmathview.c b/gmathview/gmathview.c
index df81995..1e2223a 100644
--- a/gmathview/gmathview.c
+++ b/gmathview/gmathview.c
@@ -37,14 +37,13 @@ struct _GMathViewPrivate
GMathCairoContext *cairo_context;
GMathBoxed *current_boxed;
- cairo_surface_t *work_surface;
};
-static void
-g_math_view_update_surface (GMathView *mathview);
-
G_DEFINE_TYPE (GMathView, g_math_view, GTK_TYPE_DRAWING_AREA)
+static void
+g_math_view_force_redraw (GMathView *mathview);
+
static gboolean
g_math_view_do_expose (GtkWidget *widget, GdkEventExpose *event);
@@ -140,7 +139,7 @@ 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;
- g_math_view_update_surface (G_MATH_VIEW (widget));
+ g_math_view_force_redraw (G_MATH_VIEW (widget));
return FALSE;
}
@@ -175,11 +174,14 @@ g_math_view_do_expose (GtkWidget *widget, GdkEventExpose *event)
event->area.width, event->area.height);
cairo_clip (cr);
- if (priv->work_surface)
+ if (priv->boxed && priv->boxed->surface)
{
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_surface (cr, priv->work_surface, 0, 0);
+ cairo_set_source_surface (cr, priv->boxed->surface,
+ BASE_OFFSET, BASE_OFFSET);
cairo_paint (cr);
+ if (priv->current_boxed)
+ g_math_view_outline_boxed (cr, priv->current_boxed);
}
cairo_destroy (cr);
@@ -188,50 +190,31 @@ g_math_view_do_expose (GtkWidget *widget, GdkEventExpose *event)
}
void
-g_math_view_update_surface (GMathView *mathview)
+g_math_view_update (GMathView *mathview)
{
GMathViewPrivate *priv;
+ int width, height;
priv = G_MATH_VIEW_GET_PRIVATE (mathview);
- if (priv->work_surface)
- {
- cairo_surface_destroy (priv->work_surface);
- priv->work_surface = NULL;
- }
-
- if (priv->boxed && priv->boxed->surface)
+ if (priv->boxed)
{
- priv->work_surface = g_math_view_copy_surface (priv->boxed->surface);
- if (priv->current_boxed)
- g_math_view_outline_boxed (priv->work_surface, priv->current_boxed);
+ if (priv->boxed->surface)
+ cairo_surface_destroy (priv->boxed->surface);
+ gmathboxed_free (priv->boxed);
+ priv->boxed = NULL;
}
- g_math_view_force_redraw (mathview);
-}
-
-void
-g_math_view_update (GMathView *mathview)
-{
- GMathViewPrivate *priv;
- int width, height;
-
- priv = G_MATH_VIEW_GET_PRIVATE (mathview);
-
priv->boxed = gmathcairo_render_boxed (priv->cairo_context, priv->formula);
if (priv->boxed && priv->boxed->surface)
{
- gmathboxed_rec_offset (priv->boxed, 0, 0);
- width = priv->boxed->box.width;
- height = priv->boxed->box.height;
- priv->work_surface = g_math_view_copy_surface (priv->boxed->surface);
+ gmathboxed_rec_offset (priv->boxed, BASE_OFFSET, BASE_OFFSET);
+ width = priv->boxed->box.width + 2 * BASE_OFFSET;
+ height = priv->boxed->box.height + 2 * BASE_OFFSET;
}
else
- {
width = height = 0;
- priv->work_surface = NULL;
- }
gtk_widget_set_size_request (GTK_WIDGET (mathview), width, height);
diff --git a/gmathview/gmathview_utils.c b/gmathview/gmathview_utils.c
index c466594..0bc2412 100644
--- a/gmathview/gmathview_utils.c
+++ b/gmathview/gmathview_utils.c
@@ -47,19 +47,17 @@ g_math_view_copy_surface (cairo_surface_t *source)
}
void
-g_math_view_outline_boxed (cairo_surface_t *surface, GMathBoxed *boxed)
+g_math_view_outline_boxed (cairo_t *cr, GMathBoxed *boxed)
{
- cairo_t *cr;
-
- if (!surface || !boxed)
+ if (!cr || !boxed)
return;
- cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 0, 0, 0);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_set_line_width (cr, OUTLINE_WIDTH);
+
cairo_rectangle (cr, boxed->box.x, boxed->box.y,
boxed->box.width, boxed->box.height);
cairo_stroke (cr);
-
- cairo_destroy (cr);
}
diff --git a/include/gmathview.h b/include/gmathview.h
index 8f59233..6aeb5b1 100644
--- a/include/gmathview.h
+++ b/include/gmathview.h
@@ -34,6 +34,7 @@
#include <gmathcairo.h>
#define OUTLINE_WIDTH 1
+#define BASE_OFFSET 2
G_BEGIN_DECLS
@@ -95,6 +96,6 @@ cairo_surface_t*
g_math_view_copy_surface (cairo_surface_t *source);
void
-g_math_view_outline_boxed (cairo_surface_t *surface, GMathBoxed *boxed);
+g_math_view_outline_boxed (cairo_t *cr, GMathBoxed *boxed);
#endif