From 24a6782ee37fe2057675d7699670f7890909b7b5 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 20 Oct 2002 01:43:41 +0000 Subject: [PATCH] Added grid to view. Created distinct gnome_canvas_groups for each distinct layer in view. Grid and markup visibility are now controlled by view menu. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@166 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/canvas-hacktext.c | 18 ++ glabels2/src/glabels-ui.xml | 21 +- glabels2/src/prefs.c | 24 ++ glabels2/src/prefs.h | 72 +++--- glabels2/src/ui.c | 100 ++++++-- glabels2/src/view-object.c | 11 +- glabels2/src/view.c | 415 +++++++++++++++++++++------------ glabels2/src/view.h | 52 +++-- glabels2/src/window.c | 12 + 9 files changed, 501 insertions(+), 224 deletions(-) diff --git a/glabels2/src/canvas-hacktext.c b/glabels2/src/canvas-hacktext.c index 8db1ef4c..fb4af0c3 100644 --- a/glabels2/src/canvas-hacktext.c +++ b/glabels2/src/canvas-hacktext.c @@ -433,6 +433,15 @@ gl_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_p gnome_canvas_item_reset_bounds (item); + g_print ("%s: Affine = {%f, %f, %f, %f, %f, %f}\n", + __FUNCTION__, + affine[0], + affine[1], + affine[2], + affine[3], + affine[4], + affine[5]); + hacktext->priv->affine[0] = affine[0]; hacktext->priv->affine[1] = affine[1]; hacktext->priv->affine[2] = -affine[2]; @@ -463,6 +472,15 @@ gl_canvas_hacktext_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_p hacktext->priv->pgl = pgl; } + g_print ("%s: Affine = {%f, %f, %f, %f, %f, %f}\n\n", + __FUNCTION__, + hacktext->priv->affine[0], + hacktext->priv->affine[1], + hacktext->priv->affine[2], + hacktext->priv->affine[3], + hacktext->priv->affine[4], + hacktext->priv->affine[5]); + gl_canvas_hacktext_req_repaint (hacktext, &ibbox); hacktext->item.x1 = ibbox.x0; diff --git a/glabels2/src/glabels-ui.xml b/glabels2/src/glabels-ui.xml index 63f8222c..9c00a0f3 100644 --- a/glabels2/src/glabels-ui.xml +++ b/glabels2/src/glabels-ui.xml @@ -82,6 +82,12 @@ + + + + @@ -256,7 +262,7 @@ - + @@ -268,7 +274,7 @@ - + @@ -276,9 +282,14 @@ - - - + + + + + + + + diff --git a/glabels2/src/prefs.c b/glabels2/src/prefs.c index 14bfdd0a..c91618b2 100644 --- a/glabels2/src/prefs.c +++ b/glabels2/src/prefs.c @@ -62,6 +62,9 @@ glPreferences *gl_prefs = NULL; #define PREF_DRAWING_TOOLBAR_BUTTONS_STYLE "/drawing-toolbar-buttons-style" #define PREF_DRAWING_TOOLBAR_VIEW_TOOLTIPS "/drawing-toolbar-view-tooltips" +#define PREF_GRID_VISIBLE "/grid-visible" +#define PREF_MARKUP_VISIBLE "/markup-visible" + #define PREF_MAX_RECENTS "/max-recents" /* Default values */ @@ -235,6 +238,16 @@ gl_prefs_save_settings (void) gl_prefs->drawing_toolbar_view_tooltips, NULL); + /* View properties */ + gconf_client_set_bool (gconf_client, + BASE_KEY PREF_GRID_VISIBLE, + gl_prefs->grid_visible, + NULL); + + gconf_client_set_bool (gconf_client, + BASE_KEY PREF_MARKUP_VISIBLE, + gl_prefs->markup_visible, + NULL); /* Recent files */ gconf_client_set_int (gconf_client, @@ -365,6 +378,17 @@ gl_prefs_load_settings (void) TRUE); + /* View properties */ + gl_prefs->grid_visible = + get_bool (gconf_client, + BASE_KEY PREF_GRID_VISIBLE, + TRUE); + + gl_prefs->markup_visible = + get_bool (gconf_client, + BASE_KEY PREF_MARKUP_VISIBLE, + TRUE); + /* Recent files */ gl_prefs->max_recents = get_int (gconf_client, diff --git a/glabels2/src/prefs.h b/glabels2/src/prefs.h index 27fcd96d..50f7dba3 100644 --- a/glabels2/src/prefs.h +++ b/glabels2/src/prefs.h @@ -25,6 +25,8 @@ #include #include +G_BEGIN_DECLS + typedef struct _glPreferences glPreferences; typedef enum { @@ -42,56 +44,66 @@ typedef enum { struct _glPreferences { /* Units */ - glPrefsUnits units; + glPrefsUnits units; /* Page size */ - gchar *default_page_size; + gchar *default_page_size; /* Text properties */ gchar *default_font_family; - gdouble default_font_size; - GnomeFontWeight default_font_weight; - gboolean default_font_italic_flag; - guint default_text_color; - GtkJustification default_text_alignment; + gdouble default_font_size; + GnomeFontWeight default_font_weight; + gboolean default_font_italic_flag; + guint default_text_color; + GtkJustification default_text_alignment; /* Line properties */ - gdouble default_line_width; - guint default_line_color; + gdouble default_line_width; + guint default_line_color; /* Fill properties */ - guint default_fill_color; + guint default_fill_color; /* User Interface/Main Toolbar */ - gboolean main_toolbar_visible; - glToolbarSetting main_toolbar_buttons_style; - gboolean main_toolbar_view_tooltips; + gboolean main_toolbar_visible; + glToolbarSetting main_toolbar_buttons_style; + gboolean main_toolbar_view_tooltips; /* User Interface/Drawing Toolbar */ - gboolean drawing_toolbar_visible; - glToolbarSetting drawing_toolbar_buttons_style; - gboolean drawing_toolbar_view_tooltips; + gboolean drawing_toolbar_visible; + glToolbarSetting drawing_toolbar_buttons_style; + gboolean drawing_toolbar_view_tooltips; - /* User Interface/MDI Mode */ - gint mdi_mode; - gint mdi_tabs_position; /* Tabs position in mdi notebook */ + /* View properties */ + gboolean grid_visible; + gboolean markup_visible; /* Recent files */ - gint max_recents; + gint max_recents; }; -extern glPreferences *gl_prefs; +glPreferences *gl_prefs; + +void gl_prefs_save_settings (void); + +void gl_prefs_load_settings (void); + +void gl_prefs_init (void); + + +const gchar *gl_prefs_get_page_size (void); + +glPrefsUnits gl_prefs_get_units (void); + +const gchar *gl_prefs_get_units_string (void); + +gdouble gl_prefs_get_units_per_point (void); + +gdouble gl_prefs_get_units_step_size (void); -extern void gl_prefs_save_settings (void); -extern void gl_prefs_load_settings (void); -extern void gl_prefs_init (void); +gint gl_prefs_get_units_precision (void); -extern const gchar *gl_prefs_get_page_size (void); -extern glPrefsUnits gl_prefs_get_units (void); -extern const gchar *gl_prefs_get_units_string (void); -extern gdouble gl_prefs_get_units_per_point (void); -extern gdouble gl_prefs_get_units_step_size (void); -extern gint gl_prefs_get_units_precision (void); +G_END_DECLS #endif /* __PREFS_H__ */ diff --git a/glabels2/src/ui.c b/glabels2/src/ui.c index 7ba3f0f8..831060ac 100644 --- a/glabels2/src/ui.c +++ b/glabels2/src/ui.c @@ -120,6 +120,8 @@ static gchar* doc_verbs [] = { "/menu/Objects/CreateObjects", "/menu/Objects/Order", "/menu/Objects/RotateFlip", + "/commands/ViewGrid", + "/commands/ViewMarkup", NULL }; @@ -168,6 +170,8 @@ static void set_app_main_toolbar_style (BonoboUIComponent *ui_compo static void set_app_drawing_toolbar_style (BonoboUIComponent *ui_component); +static void set_view_style (BonoboUIComponent *ui_component); + static void set_verb_sensitive (BonoboUIComponent *ui_component, gchar *cname, gboolean sensitive); @@ -256,6 +260,17 @@ gl_ui_init (BonoboUIComponent *ui_component, (gpointer)win); + /* Set view grid and markup visibility according to prefs */ + set_view_style (ui_component); + + /* Add listener for the view grid & markup */ + bonobo_ui_component_add_listener (ui_component, "ViewGrid", + (BonoboUIListenerFn)view_menu_item_toggled_cb, + (gpointer)win); + bonobo_ui_component_add_listener (ui_component, "ViewMarkup", + (BonoboUIListenerFn)view_menu_item_toggled_cb, + (gpointer)win); + set_verb_list_sensitive (ui_component, doc_verbs, FALSE); /* Status bar */ @@ -455,8 +470,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, s = (strcmp (state, "1") == 0); - if ((strcmp (path, "ViewMainToolbar") == 0) && - (s != gl_prefs->main_toolbar_visible)) + if (strcmp (path, "ViewMainToolbar") == 0) { gl_prefs->main_toolbar_visible = s; set_app_main_toolbar_style (ui_component); @@ -465,8 +479,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "MainToolbarSystem") == 0) && - (gl_prefs->main_toolbar_buttons_style != GL_TOOLBAR_SYSTEM)) + if (s && (strcmp (path, "MainToolbarSystem") == 0)) { gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_SYSTEM; set_app_main_toolbar_style (ui_component); @@ -475,8 +488,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "MainToolbarIcon") == 0) && - (gl_prefs->main_toolbar_buttons_style != GL_TOOLBAR_ICONS)) + if (s && (strcmp (path, "MainToolbarIcon") == 0)) { gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS; set_app_main_toolbar_style (ui_component); @@ -485,8 +497,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "MainToolbarIconText") == 0) && - (gl_prefs->main_toolbar_buttons_style != GL_TOOLBAR_ICONS_AND_TEXT)) + if (s && (strcmp (path, "MainToolbarIconText") == 0)) { gl_prefs->main_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT; set_app_main_toolbar_style (ui_component); @@ -495,8 +506,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if ((strcmp (path, "MainToolbarTooltips") == 0) && - (s != gl_prefs->main_toolbar_view_tooltips)) + if (strcmp (path, "MainToolbarTooltips") == 0) { gl_prefs->main_toolbar_view_tooltips = s; set_app_main_toolbar_style (ui_component); @@ -505,8 +515,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if ((strcmp (path, "ViewDrawingToolbar") == 0) && - (s != gl_prefs->drawing_toolbar_visible)) + if (strcmp (path, "ViewDrawingToolbar") == 0) { gl_prefs->drawing_toolbar_visible = s; set_app_drawing_toolbar_style (ui_component); @@ -515,8 +524,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "DrawingToolbarSystem") == 0) && - (gl_prefs->drawing_toolbar_buttons_style != GL_TOOLBAR_SYSTEM)) + if (s && (strcmp (path, "DrawingToolbarSystem") == 0)) { gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_SYSTEM; set_app_drawing_toolbar_style (ui_component); @@ -525,8 +533,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "DrawingToolbarIcon") == 0) && - (gl_prefs->drawing_toolbar_buttons_style != GL_TOOLBAR_ICONS)) + if (s && (strcmp (path, "DrawingToolbarIcon") == 0)) { gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS; set_app_drawing_toolbar_style (ui_component); @@ -535,8 +542,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if (s && (strcmp (path, "DrawingToolbarIconText") == 0) && - (gl_prefs->drawing_toolbar_buttons_style != GL_TOOLBAR_ICONS_AND_TEXT)) + if (s && (strcmp (path, "DrawingToolbarIconText") == 0)) { gl_prefs->drawing_toolbar_buttons_style = GL_TOOLBAR_ICONS_AND_TEXT; set_app_drawing_toolbar_style (ui_component); @@ -545,8 +551,7 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } - if ((strcmp (path, "DrawingToolbarTooltips") == 0) && - (s != gl_prefs->drawing_toolbar_view_tooltips)) + if (strcmp (path, "DrawingToolbarTooltips") == 0) { gl_prefs->drawing_toolbar_view_tooltips = s; set_app_drawing_toolbar_style (ui_component); @@ -555,6 +560,32 @@ view_menu_item_toggled_cb (BonoboUIComponent *ui_component, return; } + if (strcmp (path, "ViewGrid") == 0) + { + gl_prefs->grid_visible = s; + if (s) { + gl_view_show_grid (GL_VIEW(GL_WINDOW(win)->view)); + } else { + gl_view_hide_grid (GL_VIEW(GL_WINDOW(win)->view)); + } + gl_prefs_save_settings (); + + return; + } + + if (strcmp (path, "ViewMarkup") == 0) + { + gl_prefs->markup_visible = s; + if (s) { + gl_view_show_markup (GL_VIEW(GL_WINDOW(win)->view)); + } else { + gl_view_hide_markup (GL_VIEW(GL_WINDOW(win)->view)); + } + gl_prefs_save_settings (); + + return; + } + } /*---------------------------------------------------------------------------*/ @@ -779,6 +810,35 @@ set_app_drawing_toolbar_style (BonoboUIComponent *ui_component) gl_debug (DEBUG_UI, "END"); } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Set visibility of grid and markup. */ +/*---------------------------------------------------------------------------*/ +static void +set_view_style (BonoboUIComponent *ui_component) +{ + GConfClient *client; + gboolean labels; + + gl_debug (DEBUG_UI, "START"); + + g_return_if_fail (BONOBO_IS_UI_COMPONENT(ui_component)); + + bonobo_ui_component_freeze (ui_component, NULL); + + set_verb_state (ui_component, + "/commands/ViewGrid", + gl_prefs->grid_visible); + + set_verb_state (ui_component, + "/commands/ViewMarkup", + gl_prefs->markup_visible); + + error: + bonobo_ui_component_thaw (ui_component, NULL); + + gl_debug (DEBUG_UI, "END"); +} + /*---------------------------------------------------------------------------*/ /* Set sensitivity of verb. */ diff --git a/glabels2/src/view-object.c b/glabels2/src/view-object.c index c93a77f5..8756faa1 100644 --- a/glabels2/src/view-object.c +++ b/glabels2/src/view-object.c @@ -221,10 +221,9 @@ gl_view_object_set_object (glViewObject *view_object, gl_label_object_get_size (GL_LABEL_OBJECT(object), &w, &h); /* create canvas group to contain items representing object */ - canvas = GNOME_CANVAS (view_object->private->view->canvas); - root = gnome_canvas_root (canvas); view_object->private->group = - gnome_canvas_item_new (root, gnome_canvas_group_get_type (), + gnome_canvas_item_new (view_object->private->view->label_group, + gnome_canvas_group_get_type (), "x", x, "y", y, NULL); @@ -580,7 +579,6 @@ lower_object_cb (GtkWidget *widget, glViewObject *view_object) { glLabelObject *object; - glView *view; gl_debug (DEBUG_VIEW, "START"); @@ -588,8 +586,9 @@ lower_object_cb (GtkWidget *widget, gnome_canvas_item_lower_to_bottom (view_object->private->group); /* now raise it above all items that form the backgound */ - gnome_canvas_item_raise (view_object->private->group, - view_object->private->view->n_bg_items); + gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM(view_object->private->view->markup_group)); + gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM(view_object->private->view->grid_group)); + gnome_canvas_item_lower_to_bottom (GNOME_CANVAS_ITEM(view_object->private->view->bg_group)); gl_debug (DEBUG_VIEW, "END"); } diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 150b672b..a922d995 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -46,10 +46,14 @@ /* Private macros and constants. */ /*==========================================================================*/ +#define OUTLINE_COLOR GL_COLOR (173, 216, 230) +#define PAPER_COLOR GL_COLOR (255, 255, 255) +#define GRID_COLOR GL_COLOR (192, 192, 192) +#define MARKUP_COLOR GL_COLOR (240, 100, 100) + #define SEL_LINE_COLOR GL_COLOR_A (0, 0, 255, 128) #define SEL_FILL_COLOR GL_COLOR_A (192, 192, 255, 128) - /*==========================================================================*/ /* Private types. */ /*==========================================================================*/ @@ -97,13 +101,19 @@ static void gl_view_construct_selection (glView *view); static gdouble get_apropriate_scale (gdouble w, gdouble h); -static void draw_bg_fg (glView *view); +static void draw_layers (glView *view); + +static void draw_label_layer (glView *view); + +static void draw_bg_fg_layers (glView *view); static void draw_bg_fg_rect (glView *view); static void draw_bg_fg_rounded_rect (glView *view); static void draw_bg_fg_round (glView *view); static void draw_bg_fg_cd (glView *view); -static void draw_markup (glView *view); +static void draw_grid_layer (glView *view); + +static void draw_markup_layer (glView *view); static void draw_markup_margin (glView *view, glTemplateMarkupMargin *margin); @@ -124,6 +134,11 @@ static void unselect_object_real (glView *view, static gboolean object_at (glView *view, gdouble x, gdouble y); + +static gboolean is_item_member_of_group (glView *view, + GnomeCanvasItem *item, + GnomeCanvasItem *group); + static gboolean is_object_selected (glView *view, glViewObject *view_object); @@ -262,6 +277,8 @@ gl_view_init (glView *view) view->label = NULL; + view->grid_spacing = 9; + gl_debug (DEBUG_VIEW, "END"); } @@ -342,9 +359,6 @@ gl_view_construct_canvas (glView *view) gdouble scale; glLabel *label = view->label; gdouble label_width, label_height; - GList *p_obj; - glLabelObject *object; - glViewObject *view_object; gl_debug (DEBUG_VIEW, "START"); @@ -375,42 +389,11 @@ gl_view_construct_canvas (glView *view) gnome_canvas_set_scroll_region (GNOME_CANVAS (view->canvas), 0.0, 0.0, label_width, label_height); - /* Draw background shape of label/card */ - draw_bg_fg (view); - gl_debug (DEBUG_VIEW, "n_bg_items = %d, n_fg_items = %d", - view->n_bg_items, view->n_fg_items); + draw_layers (view); g_signal_connect (G_OBJECT (view->canvas), "event", G_CALLBACK (canvas_event), view); - for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) { - object = (glLabelObject *) p_obj->data; - - if (GL_IS_LABEL_BOX (object)) { - view_object = gl_view_box_new (GL_LABEL_BOX(object), - view); - } else if (GL_IS_LABEL_ELLIPSE (object)) { - view_object = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), - view); - } else if (GL_IS_LABEL_LINE (object)) { - view_object = gl_view_line_new (GL_LABEL_LINE(object), - view); - } else if (GL_IS_LABEL_IMAGE (object)) { - view_object = gl_view_image_new (GL_LABEL_IMAGE(object), - view); - } else if (GL_IS_LABEL_TEXT (object)) { - view_object = gl_view_text_new (GL_LABEL_TEXT(object), - view); - } else if (GL_IS_LABEL_BARCODE (object)) { - view_object = gl_view_barcode_new (GL_LABEL_BARCODE(object), - view); - } else { - /* Should not happen! */ - view_object = NULL; - g_warning ("Invalid label object type."); - } - } - gl_debug (DEBUG_VIEW, "END"); return view->canvas; @@ -480,19 +463,94 @@ get_apropriate_scale (gdouble w, gdouble h) return 0.25; } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Create, draw and order layers. */ +/*---------------------------------------------------------------------------*/ +static void +draw_layers (glView *view) +{ + draw_bg_fg_layers (view); + draw_grid_layer (view); + draw_markup_layer (view); + draw_label_layer (view); + + gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group)); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Draw label layer. */ +/*---------------------------------------------------------------------------*/ +static void +draw_label_layer (glView *view) +{ + GnomeCanvasGroup *group; + glLabel *label; + GList *p_obj; + glLabelObject *object; + glViewObject *view_object; + + group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); + view->label_group = GNOME_CANVAS_GROUP( + gnome_canvas_item_new (group, + gnome_canvas_group_get_type (), + "x", 0.0, + "y", 0.0, + NULL)); + + label = view->label; + + for (p_obj = label->objects; p_obj != NULL; p_obj = p_obj->next) { + object = (glLabelObject *) p_obj->data; + + if (GL_IS_LABEL_BOX (object)) { + view_object = gl_view_box_new (GL_LABEL_BOX(object), + view); + } else if (GL_IS_LABEL_ELLIPSE (object)) { + view_object = gl_view_ellipse_new (GL_LABEL_ELLIPSE(object), + view); + } else if (GL_IS_LABEL_LINE (object)) { + view_object = gl_view_line_new (GL_LABEL_LINE(object), + view); + } else if (GL_IS_LABEL_IMAGE (object)) { + view_object = gl_view_image_new (GL_LABEL_IMAGE(object), + view); + } else if (GL_IS_LABEL_TEXT (object)) { + view_object = gl_view_text_new (GL_LABEL_TEXT(object), + view); + } else if (GL_IS_LABEL_BARCODE (object)) { + view_object = gl_view_barcode_new (GL_LABEL_BARCODE(object), + view); + } else { + /* Should not happen! */ + view_object = NULL; + g_warning ("Invalid label object type."); + } + } +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. Draw background and foreground outlines. */ /*---------------------------------------------------------------------------*/ static void -draw_bg_fg (glView *view) +draw_bg_fg_layers (glView *view) { - glLabel *label; - glTemplate *template; + glLabel *label; + glTemplate *template; + GnomeCanvasGroup *group; - view->n_bg_items = 0; - view->bg_item_list = NULL; - view->n_fg_items = 0; - view->fg_item_list = NULL; + group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); + view->bg_group = GNOME_CANVAS_GROUP( + gnome_canvas_item_new (group, + gnome_canvas_group_get_type (), + "x", 0.0, + "y", 0.0, + NULL)); + view->fg_group = GNOME_CANVAS_GROUP( + gnome_canvas_item_new (group, + gnome_canvas_group_get_type (), + "x", 0.0, + "y", 0.0, + NULL)); label = view->label; template = gl_label_get_template (label); @@ -533,7 +591,6 @@ draw_bg_fg_rect (glView *view) glTemplate *template; gdouble w, h; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -543,35 +600,26 @@ draw_bg_fg_rect (glView *view) gl_label_get_size (label, &w, &h); template = gl_label_get_template (label); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - /* Background */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->bg_group, gnome_canvas_rect_get_type (), "x1", 0.0, "y1", 0.0, "x2", w, "y2", h, - "fill_color", "white", + "fill_color_rgba", PAPER_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); - - /* Markup */ - draw_markup (view); /* Foreground */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->fg_group, gnome_canvas_rect_get_type (), "x1", 0.0, "y1", 0.0, "x2", w, "y2", h, "width_pixels", 2, - "outline_color", "light blue", + "outline_color_rgba", OUTLINE_COLOR, NULL); - view->n_fg_items++; - view->fg_item_list = g_list_append (view->fg_item_list, item); gl_debug (DEBUG_VIEW, "END"); } @@ -588,15 +636,12 @@ draw_bg_fg_rounded_rect (glView *view) glTemplate *template; gdouble r, w, h; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (GL_IS_VIEW (view)); g_return_if_fail (label != NULL); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - gl_label_get_size (label, &w, &h); template = gl_label_get_template (label); r = template->label.rect.r; @@ -629,26 +674,19 @@ draw_bg_fg_rounded_rect (glView *view) } /* Background */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->bg_group, gnome_canvas_polygon_get_type (), "points", points, - "fill_color", "white", + "fill_color_rgba", PAPER_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); - - /* Markup */ - draw_markup (view); /* Foreground */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->fg_group, gnome_canvas_polygon_get_type (), "points", points, "width_pixels", 2, - "outline_color", "light blue", + "outline_color_rgba", OUTLINE_COLOR, NULL); - view->n_fg_items++; - view->fg_item_list = g_list_append (view->fg_item_list, item); gnome_canvas_points_free (points); @@ -665,7 +703,6 @@ draw_bg_fg_round (glView *view) glTemplate *template; gdouble r; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -674,37 +711,28 @@ draw_bg_fg_round (glView *view) template = gl_label_get_template (label); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - r = template->label.round.r; /* Background */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->bg_group, gnome_canvas_ellipse_get_type (), "x1", 0.0, "y1", 0.0, "x2", 2.0*r, "y2", 2.0*r, - "fill_color", "white", + "fill_color_rgba", PAPER_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); - - /* Markup */ - draw_markup (view); /* Foreground */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->fg_group, gnome_canvas_ellipse_get_type (), "x1", 0.0, "y1", 0.0, "x2", 2.0*r, "y2", 2.0*r, "width_pixels", 2, - "outline_color", "light blue", + "outline_color_rgba", OUTLINE_COLOR, NULL); - view->n_fg_items++; - view->fg_item_list = g_list_append (view->fg_item_list, item); gl_debug (DEBUG_VIEW, "END"); } @@ -719,7 +747,6 @@ draw_bg_fg_cd (glView *view) glTemplate *template; gdouble r1, r2; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -728,63 +755,108 @@ draw_bg_fg_cd (glView *view) template = gl_label_get_template (label); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - r1 = template->label.cd.r1; r2 = template->label.cd.r2; /* Background */ /* outer circle */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->bg_group, gnome_canvas_ellipse_get_type (), "x1", 0.0, "y1", 0.0, "x2", 2.0*r1, "y2", 2.0*r1, - "fill_color", "white", + "fill_color_rgba", PAPER_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); /* hole */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->bg_group, gnome_canvas_ellipse_get_type (), "x1", r1 - r2, "y1", r1 - r2, "x2", r1 + r2, "y2", r1 + r2, - "fill_color", "gray", + "fill_color_rgba", GRID_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); - - /* Markup */ - draw_markup (view); /* Foreground */ /* outer circle */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->fg_group, gnome_canvas_ellipse_get_type (), "x1", 0.0, "y1", 0.0, "x2", 2.0*r1, "y2", 2.0*r1, "width_pixels", 2, - "outline_color", "light blue", + "outline_color_rgba", OUTLINE_COLOR, NULL); - view->n_fg_items++; - view->fg_item_list = g_list_append (view->fg_item_list, item); /* hole */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->fg_group, gnome_canvas_ellipse_get_type (), "x1", r1 - r2, "y1", r1 - r2, "x2", r1 + r2, "y2", r1 + r2, "width_pixels", 2, - "outline_color", "light blue", + "outline_color_rgba", OUTLINE_COLOR, NULL); - view->n_fg_items++; - view->fg_item_list = g_list_append (view->fg_item_list, item); + + gl_debug (DEBUG_VIEW, "END"); +} + +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Draw grid lines. */ +/*---------------------------------------------------------------------------*/ +static void +draw_grid_layer (glView *view) +{ + gdouble w, h, x, y; + GnomeCanvasPoints *points; + GnomeCanvasItem *item; + GnomeCanvasGroup *group; + + gl_debug (DEBUG_VIEW, "START"); + + g_return_if_fail (view && GL_IS_VIEW (view)); + g_return_if_fail (view->label && GL_IS_LABEL(view->label)); + + gl_label_get_size (view->label, &w, &h); + + group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); + view->grid_group = GNOME_CANVAS_GROUP( + gnome_canvas_item_new (group, + gnome_canvas_group_get_type (), + "x", 0.0, + "y", 0.0, + NULL)); + points = gnome_canvas_points_new (2); + + points->coords[1] = 0.0; + points->coords[3] = h; + for ( x=view->grid_spacing; x < w; x += view->grid_spacing ) { + points->coords[0] = points->coords[2] = x; + + item = gnome_canvas_item_new (view->grid_group, + gnome_canvas_line_get_type (), + "points", points, + "width_pixels", 1, + "fill_color_rgba", GRID_COLOR, + NULL); + } + + points->coords[0] = 0.0; + points->coords[2] = w; + for ( y=view->grid_spacing; y < h; y += view->grid_spacing ) { + points->coords[1] = points->coords[3] = y; + + item = gnome_canvas_item_new (view->grid_group, + gnome_canvas_line_get_type (), + "points", points, + "width_pixels", 1, + "fill_color_rgba", GRID_COLOR, + NULL); + } + + gnome_canvas_points_free (points); gl_debug (DEBUG_VIEW, "END"); } @@ -793,13 +865,21 @@ draw_bg_fg_cd (glView *view) /* PRIVATE. Draw markup lines. */ /*---------------------------------------------------------------------------*/ static void -draw_markup (glView *view) +draw_markup_layer (glView *view) { + GnomeCanvasGroup *group; glLabel *label; glTemplate *template; GList *p; glTemplateMarkup *markup; + group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); + view->markup_group = GNOME_CANVAS_GROUP( + gnome_canvas_item_new (group, + gnome_canvas_group_get_type (), + "x", 0.0, + "y", 0.0, + NULL)); label = view->label; template = gl_label_get_template (label); @@ -873,7 +953,6 @@ draw_markup_margin_rect (glView *view, glTemplate *template; gdouble w, h, m; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -884,20 +963,16 @@ draw_markup_margin_rect (glView *view, template = gl_label_get_template (label); m = margin->size; - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - /* Bounding box @ margin */ - gnome_canvas_item_new (group, + gnome_canvas_item_new (view->markup_group, gnome_canvas_rect_get_type (), "x1", m, "y1", m, "x2", w - m, "y2", h - m, "width_pixels", 1, - "outline_color", "light blue", + "outline_color_rgba", MARKUP_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); gl_debug (DEBUG_VIEW, "END"); } @@ -915,15 +990,12 @@ draw_markup_margin_rounded_rect (glView *view, glTemplate *template; gdouble r, w, h, m; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (GL_IS_VIEW (view)); g_return_if_fail (label != NULL); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - gl_label_get_size (label, &w, &h); template = gl_label_get_template (label); r = template->label.rect.r; @@ -960,15 +1032,13 @@ draw_markup_margin_rounded_rect (glView *view, points->coords[i_coords++] = m + r - r * sin (i_theta * M_PI / 180.0); } - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->markup_group, gnome_canvas_polygon_get_type (), "points", points, "width_pixels", 1, - "outline_color", "light blue", + "outline_color_rgba", MARKUP_COLOR, NULL); gnome_canvas_points_free (points); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); gl_debug (DEBUG_VIEW, "END"); } @@ -984,7 +1054,6 @@ draw_markup_margin_round (glView *view, glTemplate *template; gdouble r, m; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -993,22 +1062,19 @@ draw_markup_margin_round (glView *view, template = gl_label_get_template (label); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - r = template->label.round.r; m = margin->size; /* Margin outline */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->markup_group, gnome_canvas_ellipse_get_type (), "x1", m, "y1", m, "x2", 2.0*r - m, "y2", 2.0*r - m, "width_pixels", 1, - "outline_color", "light blue", NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); + "outline_color_rgba", MARKUP_COLOR, + NULL); gl_debug (DEBUG_VIEW, "END"); } @@ -1024,7 +1090,6 @@ draw_markup_margin_cd (glView *view, glTemplate *template; gdouble m, r1, r2; GnomeCanvasItem *item; - GnomeCanvasGroup *group; gl_debug (DEBUG_VIEW, "START"); @@ -1033,35 +1098,30 @@ draw_markup_margin_cd (glView *view, template = gl_label_get_template (label); - group = gnome_canvas_root (GNOME_CANVAS (view->canvas)); - r1 = template->label.cd.r1; r2 = template->label.cd.r2; m = margin->size; /* outer margin */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->markup_group, gnome_canvas_ellipse_get_type (), "x1", m, "y1", m, "x2", 2.0*r1 - m, "y2", 2.0*r1 - m, "width_pixels", 1, - "outline_color", "light blue", NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); + "outline_color_rgba", MARKUP_COLOR, + NULL); /* inner margin */ - item = gnome_canvas_item_new (group, + item = gnome_canvas_item_new (view->markup_group, gnome_canvas_ellipse_get_type (), "x1", r1 - r2 - m, "y1", r1 - r2 - m, "x2", r1 + r2 + m, "y2", r1 + r2 + m, "width_pixels", 1, - "outline_color", "light blue", + "outline_color_rgba", MARKUP_COLOR, NULL); - view->n_bg_items++; - view->bg_item_list = g_list_append (view->bg_item_list, item); gl_debug (DEBUG_VIEW, "END"); } @@ -1074,9 +1134,51 @@ gl_view_raise_fg (glView *view) { GList *p; - for (p = view->fg_item_list; p != NULL; p = p->next) { - gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(p->data)); - } + gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM(view->fg_group)); +} + +/*****************************************************************************/ +/* Show grid. */ +/*****************************************************************************/ +void gl_view_show_grid (glView *view) +{ + gnome_canvas_item_show (GNOME_CANVAS_ITEM(view->grid_group)); +} + +/*****************************************************************************/ +/* Hide grid. */ +/*****************************************************************************/ +void gl_view_hide_grid (glView *view) +{ + gnome_canvas_item_hide (GNOME_CANVAS_ITEM(view->grid_group)); +} + +/*****************************************************************************/ +/* Set grid spacing. */ +/*****************************************************************************/ +void gl_view_set_grid_spacing (glView *view, + gdouble spacing) +{ + view->grid_spacing = spacing; + + gtk_object_destroy (GTK_OBJECT(view->grid_group)); + draw_grid_layer (view); +} + +/*****************************************************************************/ +/* Show markup. */ +/*****************************************************************************/ +void gl_view_show_markup (glView *view) +{ + gnome_canvas_item_show (GNOME_CANVAS_ITEM(view->markup_group)); +} + +/*****************************************************************************/ +/* Hide markup. */ +/*****************************************************************************/ +void gl_view_hide_markup (glView *view) +{ + gnome_canvas_item_hide (GNOME_CANVAS_ITEM(view->markup_group)); } /*****************************************************************************/ @@ -1335,13 +1437,32 @@ object_at (glView *view, if (item == NULL) return FALSE; - /* ignore our background items */ - if (g_list_find (view->bg_item_list, item) != NULL) + /* ignore items not in label group, e.g. background items */ + if (!is_item_member_of_group(view, item, GNOME_CANVAS_ITEM(view->label_group))) return FALSE; return TRUE; } +/*---------------------------------------------------------------------------*/ +/* PRIVATE. Is the item a child (or grandchild, etc.) of group. */ +/*---------------------------------------------------------------------------*/ +static gboolean +is_item_member_of_group (glView *view, + GnomeCanvasItem *item, + GnomeCanvasItem *group) +{ + GnomeCanvasItem *parent; + GnomeCanvasItem *root_group; + + root_group = GNOME_CANVAS_ITEM(gnome_canvas_root (GNOME_CANVAS (view->canvas))); + + for ( parent=item->parent; parent && (parent!=root_group); parent=parent->parent) { + if (parent == group) return TRUE; + } + return FALSE; +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. Is the object in our current selection? */ /*---------------------------------------------------------------------------*/ diff --git a/glabels2/src/view.h b/glabels2/src/view.h index b46fb9e1..812e651a 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -39,7 +39,7 @@ typedef enum { #define GL_IS_VIEW(obj) (GTK_CHECK_TYPE ((obj), GL_TYPE_VIEW)) #define GL_IS_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_VIEW)) -typedef struct _glView glView; +typedef struct _glView glView; typedef struct _glViewClass glViewClass; #include "view-object.h" @@ -47,14 +47,18 @@ typedef struct _glViewClass glViewClass; struct _glView { GtkVBox parent_widget; - glLabel *label; + glLabel *label; - GtkWidget *canvas; + GtkWidget *canvas; gdouble scale; - gint n_bg_items; - GList *bg_item_list; - gint n_fg_items; - GList *fg_item_list; + + GnomeCanvasGroup *bg_group; /* Background layer */ + GnomeCanvasGroup *grid_group; /* Grid layer */ + GnomeCanvasGroup *markup_group; /* Markup layer */ + GnomeCanvasGroup *label_group; /* Label layer (user objects) */ + GnomeCanvasGroup *fg_group; /* Foreground layer */ + + gdouble grid_spacing; glViewState state; glLabelObjectType create_type; @@ -74,16 +78,21 @@ struct _glViewClass { GtkVBoxClass parent_class; /* Selection changed signal */ - void (*selection_changed) (glView *view, gpointer user_data); + void (*selection_changed) (glView *view, + gpointer user_data); /* Signals to support a status bar */ - void (*zoom_changed) (glView *view, - gdouble zoom, gpointer user_data); - void (*pointer_moved) (glView *view, - gdouble x, gdouble y, gpointer user_data); - void (*pointer_exit) (glView *view, gpointer user_data); - void (*mode_changed) (glView *view, - gpointer user_data); + void (*zoom_changed) (glView *view, + gdouble zoom, + gpointer user_data); + void (*pointer_moved) (glView *view, + gdouble x, + gdouble y, + gpointer user_data); + void (*pointer_exit) (glView *view, + gpointer user_data); + void (*mode_changed) (glView *view, + gpointer user_data); }; G_BEGIN_DECLS @@ -96,10 +105,21 @@ GtkWidget *gl_view_new (glLabel *label); void gl_view_raise_fg (glView *view); +void gl_view_show_grid (glView *view); + +void gl_view_hide_grid (glView *view); + +void gl_view_set_grid_spacing (glView *view, + gdouble spacing); + +void gl_view_show_markup (glView *view); + +void gl_view_hide_markup (glView *view); + void gl_view_arrow_mode (glView *view); void gl_view_object_create_mode (glView *view, - glLabelObjectType type); + glLabelObjectType type); void gl_view_select_object (glView *view, diff --git a/glabels2/src/window.c b/glabels2/src/window.c index 8aa91f4c..e42384ed 100644 --- a/glabels2/src/window.c +++ b/glabels2/src/window.c @@ -327,6 +327,18 @@ gl_window_set_label (glWindow *window, gtk_widget_show_all (window->view); + if (gl_prefs->grid_visible) { + gl_view_show_grid (GL_VIEW(window->view)); + } else { + gl_view_hide_grid (GL_VIEW(window->view)); + } + + if (gl_prefs->markup_visible) { + gl_view_show_markup (GL_VIEW(window->view)); + } else { + gl_view_hide_markup (GL_VIEW(window->view)); + } + gl_ui_update_all (window->uic, GL_VIEW(window->view)); string = g_strdup_printf ("%3.0f%%", -- 2.39.5