From: Jim Evins Date: Thu, 12 Apr 2007 02:27:48 +0000 (+0000) Subject: 2007-04-11 Jim Evins X-Git-Tag: glabels-2_3_0~345 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=50418d4af1223ea832c83b09ac0e67027f97fd78;p=glabels 2007-04-11 Jim Evins * src/cairo-label-path.c: (gl_cairo_label_path), (gl_cairo_rect_label_path), (gl_cairo_round_label_path), (gl_cairo_cd_label_path): * src/cairo-label-path.h: * src/mini-preview-pixbuf.c: (draw_paper), (draw_label_outlines), (draw_label_outline): * src/print.c: (draw_outline), (clip_to_outline): * src/view.c: (draw_bg_layer), (draw_fg_layer): * src/wdgt-mini-preview.c: (draw_labels): * src/wdgt-rotate-label.c: (drawingarea_update): Modified to universally use gl_cairo_label_path() to create paths for labels. Added shadow to mini preview in rotate widget. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@651 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 1d4b430b..c3fab5cd 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,18 @@ +2007-04-11 Jim Evins + + * src/cairo-label-path.c: (gl_cairo_label_path), + (gl_cairo_rect_label_path), (gl_cairo_round_label_path), + (gl_cairo_cd_label_path): + * src/cairo-label-path.h: + * src/mini-preview-pixbuf.c: (draw_paper), (draw_label_outlines), + (draw_label_outline): + * src/print.c: (draw_outline), (clip_to_outline): + * src/view.c: (draw_bg_layer), (draw_fg_layer): + * src/wdgt-mini-preview.c: (draw_labels): + * src/wdgt-rotate-label.c: (drawingarea_update): + Modified to universally use gl_cairo_label_path() to create paths + for labels. Added shadow to mini preview in rotate widget. + 2007-04-10 Jim Evins * libglabels/template.h: diff --git a/glabels2/src/cairo-label-path.c b/glabels2/src/cairo-label-path.c index ac42a87a..cb63bb26 100644 --- a/glabels2/src/cairo-label-path.c +++ b/glabels2/src/cairo-label-path.c @@ -44,13 +44,16 @@ /*===========================================*/ static void gl_cairo_rect_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag); static void gl_cairo_round_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag); static void gl_cairo_cd_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag); @@ -59,27 +62,28 @@ static void gl_cairo_cd_label_path (cairo_t *cr, /*--------------------------------------------------------------------------*/ void gl_cairo_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag) { const glTemplateLabelType *label_type; gl_debug (DEBUG_PATH, "START"); - label_type = gl_template_get_first_label_type (label->template); + label_type = gl_template_get_first_label_type (template); switch (label_type->shape) { case GL_TEMPLATE_SHAPE_RECT: - gl_cairo_rect_label_path (cr, label, waste_flag); + gl_cairo_rect_label_path (cr, template, rotate_flag, waste_flag); break; case GL_TEMPLATE_SHAPE_ROUND: - gl_cairo_round_label_path (cr, label, waste_flag); + gl_cairo_round_label_path (cr, template, rotate_flag, waste_flag); break; case GL_TEMPLATE_SHAPE_CD: - gl_cairo_cd_label_path (cr, label, waste_flag); + gl_cairo_cd_label_path (cr, template, rotate_flag, waste_flag); break; default: @@ -95,7 +99,8 @@ gl_cairo_label_path (cairo_t *cr, /*--------------------------------------------------------------------------*/ static void gl_cairo_rect_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag) { const glTemplateLabelType *label_type; @@ -104,21 +109,32 @@ gl_cairo_rect_label_path (cairo_t *cr, gl_debug (DEBUG_PATH, "START"); - label_type = gl_template_get_first_label_type (label->template); - gl_label_get_size (label, &w, &h); + label_type = gl_template_get_first_label_type (template); r = label_type->size.rect.r; - if (waste_flag) + x_waste = 0.0; + y_waste = 0.0; + + if (rotate_flag) { - x_waste = label_type->size.rect.x_waste; - y_waste = label_type->size.rect.x_waste; + gl_template_get_label_size (label_type, &h, &w); + if (waste_flag) + { + x_waste = label_type->size.rect.y_waste; + y_waste = label_type->size.rect.x_waste; + } } else { - x_waste = 0.0; - y_waste = 0.0; + gl_template_get_label_size (label_type, &w, &h); + if (waste_flag) + { + x_waste = label_type->size.rect.x_waste; + y_waste = label_type->size.rect.y_waste; + } } + if ( r == 0.0 ) { cairo_rectangle (cr, -x_waste, -y_waste, w+x_waste, h+y_waste); @@ -141,7 +157,8 @@ gl_cairo_rect_label_path (cairo_t *cr, /*--------------------------------------------------------------------------*/ static void gl_cairo_round_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag) { const glTemplateLabelType *label_type; @@ -150,9 +167,17 @@ gl_cairo_round_label_path (cairo_t *cr, gl_debug (DEBUG_PATH, "START"); - label_type = gl_template_get_first_label_type (label->template); - gl_label_get_size (label, &w, &h); + label_type = gl_template_get_first_label_type (template); + if (rotate_flag) + { + gl_template_get_label_size (label_type, &h, &w); + } + else + { + gl_template_get_label_size (label_type, &w, &h); + } + if (waste_flag) { waste = label_type->size.round.waste; @@ -173,7 +198,8 @@ gl_cairo_round_label_path (cairo_t *cr, /*--------------------------------------------------------------------------*/ static void gl_cairo_cd_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag) { const glTemplateLabelType *label_type; @@ -185,8 +211,16 @@ gl_cairo_cd_label_path (cairo_t *cr, gl_debug (DEBUG_PATH, "START"); - label_type = gl_template_get_first_label_type (label->template); - gl_label_get_size (label, &w, &h); + label_type = gl_template_get_first_label_type (template); + + if (rotate_flag) + { + gl_template_get_label_size (label_type, &h, &w); + } + else + { + gl_template_get_label_size (label_type, &w, &h); + } xc = w/2.0; yc = h/2.0; diff --git a/glabels2/src/cairo-label-path.h b/glabels2/src/cairo-label-path.h index 79f1cd5b..386f63b3 100644 --- a/glabels2/src/cairo-label-path.h +++ b/glabels2/src/cairo-label-path.h @@ -26,12 +26,13 @@ #define __CAIRO_LABEL_PATH_H__ #include -#include "label.h" +#include G_BEGIN_DECLS void gl_cairo_label_path (cairo_t *cr, - glLabel *label, + glTemplate *template, + gboolean rotate_flag, gboolean waste_flag); G_END_DECLS diff --git a/glabels2/src/mini-preview-pixbuf.c b/glabels2/src/mini-preview-pixbuf.c index b8f5e99a..1fd467d1 100644 --- a/glabels2/src/mini-preview-pixbuf.c +++ b/glabels2/src/mini-preview-pixbuf.c @@ -25,6 +25,7 @@ #include #include "mini-preview-pixbuf.h" +#include "cairo-label-path.h" #include #include @@ -46,30 +47,15 @@ /*===========================================*/ static void draw_paper (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble scale); static void draw_label_outlines (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble scale); static void draw_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); - -static void draw_rect_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); - -static void draw_round_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); - -static void draw_cd_label_outline (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble x0, gdouble y0); @@ -143,7 +129,7 @@ gl_mini_preview_pixbuf_new (glTemplate *template, /*--------------------------------------------------------------------------*/ static void draw_paper (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble scale) { gl_debug (DEBUG_MINI_PREVIEW, "START"); @@ -165,7 +151,7 @@ draw_paper (cairo_t *cr, /*--------------------------------------------------------------------------*/ static void draw_label_outlines (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble scale) { const glTemplateLabelType *label_type; @@ -201,150 +187,17 @@ draw_label_outlines (cairo_t *cr, /*--------------------------------------------------------------------------*/ static void draw_label_outline (cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble x0, gdouble y0) { - const glTemplateLabelType *label_type; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - cairo_save (cr); - - label_type = gl_template_get_first_label_type (template); - - switch (label_type->shape) { - - case GL_TEMPLATE_SHAPE_RECT: - draw_rect_label_outline (cr, template, x0, y0); - break; - - case GL_TEMPLATE_SHAPE_ROUND: - draw_round_label_outline (cr, template, x0, y0); - break; - - case GL_TEMPLATE_SHAPE_CD: - draw_cd_label_outline (cr, template, x0, y0); - break; - - default: - g_message ("Unknown label style"); - break; - } - - cairo_restore (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw rectangular label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_rect_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - gl_debug (DEBUG_MINI_PREVIEW, "START"); cairo_save (cr); - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); + cairo_translate (cr, x0, y0); - cairo_rectangle (cr, x0, y0, w, h); - - cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); - cairo_fill_preserve (cr); - - cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); - cairo_stroke (cr); - - cairo_restore (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw round label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_round_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - cairo_save (cr); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - cairo_arc (cr, x0+w/2, y0+h/2, w/2, 0.0, 2*M_PI); - - cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); - cairo_fill_preserve (cr); - - cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); - cairo_stroke (cr); - - cairo_restore (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw cd label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_cd_label_outline (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - gdouble xc, yc; - gdouble r1, r2; - gdouble theta1, theta2; - - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - cairo_save (cr); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - xc = x0 + w/2.0; - yc = y0 + h/2.0; - - r1 = label_type->size.cd.r1; - r2 = label_type->size.cd.r2; - - theta1 = acos (w / (2.0*r1)); - theta2 = asin (h / (2.0*r1)); - - /* Outer radius, may be clipped in the case of business card CDs. */ - /* Do as a series of 4 arcs, to account for clipping. */ - cairo_new_path (cr); - cairo_arc (cr, xc, yc, r1, theta1, theta2); - cairo_arc (cr, xc, yc, r1, M_PI-theta2, M_PI-theta1); - cairo_arc (cr, xc, yc, r1, M_PI+theta1, M_PI+theta2); - cairo_arc (cr, xc, yc, r1, 2*M_PI-theta2, 2*M_PI-theta1); - cairo_close_path (cr); - - /* Hole */ - cairo_new_sub_path (cr); - cairo_arc (cr, xc, yc, r2, 0.0, 2*M_PI); + gl_cairo_label_path (cr, template, FALSE, FALSE); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -352,11 +205,9 @@ draw_cd_label_outline (cairo_t *cr, cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); cairo_stroke (cr); - + cairo_restore (cr); gl_debug (DEBUG_MINI_PREVIEW, "END"); } - - diff --git a/glabels2/src/print.c b/glabels2/src/print.c index 621f4e29..15f07135 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -535,7 +535,7 @@ draw_outline (PrintInfo *pi, cairo_set_source_rgba (pi->cr, 0.0, 0.0, 0.0, 1.0); cairo_set_line_width (pi->cr, 0.25); - gl_cairo_label_path (pi->cr, label, FALSE); + gl_cairo_label_path (pi->cr, label->template, FALSE, FALSE); cairo_stroke (pi->cr); @@ -553,7 +553,7 @@ clip_to_outline (PrintInfo *pi, { gl_debug (DEBUG_PRINT, "START"); - gl_cairo_label_path (pi->cr, label, TRUE); + gl_cairo_label_path (pi->cr, label->template, FALSE, TRUE); cairo_set_fill_rule (pi->cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_clip (pi->cr); diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 19de2484..9cc6243c 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -746,7 +746,7 @@ draw_bg_layer (glView *view, g_return_if_fail (view && GL_IS_VIEW (view)); g_return_if_fail (view->label && GL_IS_LABEL (view->label)); - gl_cairo_label_path (cr, view->label, FALSE); + gl_cairo_label_path (cr, view->label->template, view->label->rotate_flag, FALSE); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -874,7 +874,7 @@ draw_fg_layer (glView *view, g_return_if_fail (view && GL_IS_VIEW (view)); g_return_if_fail (view->label && GL_IS_LABEL (view->label)); - gl_cairo_label_path (cr, view->label, FALSE); + gl_cairo_label_path (cr, view->label->template, view->label->rotate_flag, FALSE); cairo_set_line_width (cr, 3.0/(view->home_scale * view->zoom)); cairo_set_source_rgb (cr, 0.68, 0.85, 0.90); diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c index 01501399..49e4a472 100644 --- a/glabels2/src/wdgt-mini-preview.c +++ b/glabels2/src/wdgt-mini-preview.c @@ -28,6 +28,7 @@ #include +#include "cairo-label-path.h" #include "marshal.h" #include "color.h" @@ -117,24 +118,8 @@ static void draw_paper (glWdgtMiniPreview *preview, gdouble line_width); static void draw_labels (glWdgtMiniPreview *preview, cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble line_width); -static void create_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); -static void create_rect_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); -static void create_round_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); -static void create_cd_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0); static gint find_closest_label (glWdgtMiniPreview *preview, gdouble x, @@ -680,7 +665,7 @@ draw_paper (glWdgtMiniPreview *preview, static void draw_labels (glWdgtMiniPreview *preview, cairo_t *cr, - const glTemplate *template, + glTemplate *template, gdouble line_width) { const glTemplateLabelType *label_type; @@ -703,7 +688,8 @@ draw_labels (glWdgtMiniPreview *preview, cairo_save (cr); - create_label_path (cr, template, origins[i].x, origins[i].y); + cairo_translate (cr, origins[i].x, origins[i].y); + gl_cairo_label_path (cr, template, FALSE, FALSE); if ( ((i+1) >= preview->priv->highlight_first) && ((i+1) <= preview->priv->highlight_last) ) @@ -733,133 +719,3 @@ draw_labels (glWdgtMiniPreview *preview, gl_debug (DEBUG_MINI_PREVIEW, "END"); } -/*--------------------------------------------------------------------------*/ -/* Create label path */ -/*--------------------------------------------------------------------------*/ -static void -create_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - label_type = gl_template_get_first_label_type (template); - - switch (label_type->shape) { - - case GL_TEMPLATE_SHAPE_RECT: - create_rect_label_path (cr, template, x0, y0); - break; - - case GL_TEMPLATE_SHAPE_ROUND: - create_round_label_path (cr, template, x0, y0); - break; - - case GL_TEMPLATE_SHAPE_CD: - create_cd_label_path (cr, template, x0, y0); - break; - - default: - g_message ("Unknown label style"); - break; - } - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* Create rectangular label path */ -/*--------------------------------------------------------------------------*/ -static void -create_rect_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - cairo_rectangle (cr, x0, y0, w, h); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* Create round label path */ -/*--------------------------------------------------------------------------*/ -static void -create_round_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - cairo_arc (cr, x0+w/2, y0+h/2, w/2, 0.0, 2*M_PI); - cairo_close_path (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* Create cd label path */ -/*--------------------------------------------------------------------------*/ -static void -create_cd_label_path (cairo_t *cr, - const glTemplate *template, - gdouble x0, - gdouble y0) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - gdouble xc, yc; - gdouble r1, r2; - gdouble theta1, theta2; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - xc = x0 + w/2.0; - yc = y0 + h/2.0; - - r1 = label_type->size.cd.r1; - r2 = label_type->size.cd.r2; - - /* - * Outer path (may be clipped) - */ - theta1 = acos (w / (2.0*r1)); - theta2 = asin (h / (2.0*r1)); - - cairo_new_path (cr); - cairo_arc (cr, xc, yc, r1, theta1, theta2); - cairo_arc (cr, xc, yc, r1, M_PI-theta2, M_PI-theta1); - cairo_arc (cr, xc, yc, r1, M_PI+theta1, M_PI+theta2); - cairo_arc (cr, xc, yc, r1, 2*M_PI-theta2, 2*M_PI-theta1); - cairo_close_path (cr); - - - /* Inner path (hole) */ - cairo_new_sub_path (cr); - cairo_arc (cr, xc, yc, r2, 0.0, 2*M_PI); - cairo_close_path (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index f0f19ce2..dbeb8150 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -36,6 +36,7 @@ #include "marshal.h" #include "color.h" #include +#include "cairo-label-path.h" #include "debug.h" @@ -48,6 +49,10 @@ #define LINE_COLOR GL_COLOR(0,0,0) #define FILL_COLOR GL_COLOR(255,255,255) +#define SHADOW_X_OFFSET 3 +#define SHADOW_Y_OFFSET 3 + + /*===========================================*/ /* Private types */ /*===========================================*/ @@ -86,22 +91,6 @@ static void drawingarea_update (GtkDrawingArea *drawing_ glTemplate *template, gboolean rotate_flag); -static void draw_rect_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color); - -static void draw_round_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color); - - -static void draw_cd_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color); - static gboolean expose_cb (GtkWidget *drawingarea, GdkEventExpose *event, gpointer user_data); @@ -243,7 +232,7 @@ drawingarea_update (GtkDrawingArea *drawing_area, const glTemplateLabelType *label_type; gdouble m, m_canvas, w, h, scale; GtkStyle *style; - guint line_color, fill_color; + guint line_color, fill_color, shadow_color; cairo_t *cr; if (!GTK_WIDGET_DRAWABLE (GTK_WIDGET (drawing_area))) @@ -261,172 +250,59 @@ drawingarea_update (GtkDrawingArea *drawing_area, label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); + if (rotate_flag) + { + gl_template_get_label_size (label_type, &h, &w); + } + else + { + gl_template_get_label_size (label_type, &w, &h); + } m = MAX (w, h); scale = MINI_PREVIEW_MAX_PIXELS / m; m_canvas = MINI_PREVIEW_CANVAS_PIXELS / scale; + style = gtk_widget_get_style (GTK_WIDGET (drawing_area)); + /* Adjust sensitivity (should the canvas be grayed?) */ if (w != h) { line_color = LINE_COLOR; fill_color = FILL_COLOR; } else { - style = gtk_widget_get_style (GTK_WIDGET (drawing_area)); line_color = gl_color_from_gdk_color (&style->text[GTK_STATE_INSENSITIVE]); fill_color = gl_color_from_gdk_color (&style->base[GTK_STATE_INSENSITIVE]); } + shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]); + + cr = gdk_cairo_create (GTK_WIDGET (drawing_area)->window); cairo_identity_matrix (cr); cairo_translate (cr, MINI_PREVIEW_CANVAS_PIXELS/2, MINI_PREVIEW_CANVAS_PIXELS/2); cairo_scale (cr, scale, scale); - if (rotate_flag) - { - cairo_rotate (cr, M_PI/2.0); - } - - cairo_set_line_width (cr, 1.0/scale); - - switch (label_type->shape) { - - case GL_TEMPLATE_SHAPE_RECT: - draw_rect_label_outline (cr, template, line_color, fill_color); - break; - - case GL_TEMPLATE_SHAPE_ROUND: - draw_round_label_outline (cr, template, line_color, fill_color); - break; - - case GL_TEMPLATE_SHAPE_CD: - draw_cd_label_outline (cr, template, line_color, fill_color); - break; - - default: - g_message ("Unknown label style"); - break; - } - - cairo_destroy (cr); - -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw rectangular label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_rect_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - cairo_save (cr); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - cairo_rectangle (cr, -w/2.0, -h/2.0, w, h); - - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(fill_color), - GL_COLOR_F_GREEN(fill_color), - GL_COLOR_F_BLUE(fill_color)); - cairo_fill_preserve (cr); - - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(line_color), - GL_COLOR_F_GREEN(line_color), - GL_COLOR_F_BLUE(line_color)); - cairo_stroke (cr); - - cairo_restore (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw round label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_round_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color) -{ - const glTemplateLabelType *label_type; - gdouble w, h; + cairo_translate (cr, -w/2.0, -h/2.0); - gl_debug (DEBUG_MINI_PREVIEW, "START"); - - cairo_save (cr); - - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - cairo_arc (cr, 0.0, 0.0, w/2, 0.0, 2*M_PI); + /* + * Shadow + */ + cairo_save (cr); + cairo_translate (cr, SHADOW_X_OFFSET/scale, SHADOW_Y_OFFSET/scale); + gl_cairo_label_path (cr, template, rotate_flag, FALSE); cairo_set_source_rgb (cr, - GL_COLOR_F_RED(fill_color), - GL_COLOR_F_GREEN(fill_color), - GL_COLOR_F_BLUE(fill_color)); - cairo_fill_preserve (cr); - - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(line_color), - GL_COLOR_F_GREEN(line_color), - GL_COLOR_F_BLUE(line_color)); - cairo_stroke (cr); - - cairo_restore (cr); - - gl_debug (DEBUG_MINI_PREVIEW, "END"); -} - -/*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw cd label outline. */ -/*--------------------------------------------------------------------------*/ -static void -draw_cd_label_outline (cairo_t *cr, - const glTemplate *template, - guint line_color, - guint fill_color) -{ - const glTemplateLabelType *label_type; - gdouble w, h; - gdouble r1, r2; - gdouble theta1, theta2; - - gl_debug (DEBUG_MINI_PREVIEW, "START"); + GL_COLOR_F_RED(shadow_color), + GL_COLOR_F_GREEN(shadow_color), + GL_COLOR_F_BLUE(shadow_color)); + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + cairo_fill (cr); + cairo_restore (cr); - cairo_save (cr); + /* + * Label + outline + */ + gl_cairo_label_path (cr, template, rotate_flag, FALSE); - label_type = gl_template_get_first_label_type (template); - gl_template_get_label_size (label_type, &w, &h); - - r1 = label_type->size.cd.r1; - r2 = label_type->size.cd.r2; - - /* Outer radius, may be clipped in the case of business card CDs. */ - /* Do as a series of 4 arcs, to account for clipping. */ - theta1 = acos (w / (2.0*r1)); - theta2 = asin (h / (2.0*r1)); - - cairo_new_path (cr); - cairo_arc (cr, 0.0, 0.0, r1, theta1, theta2); - cairo_arc (cr, 0.0, 0.0, r1, M_PI-theta2, M_PI-theta1); - cairo_arc (cr, 0.0, 0.0, r1, M_PI+theta1, M_PI+theta2); - cairo_arc (cr, 0.0, 0.0, r1, 2*M_PI-theta2, 2*M_PI-theta1); - cairo_close_path (cr); - - /* Hole */ - cairo_new_sub_path (cr); - cairo_arc (cr, 0.0, 0.0, r2, 0.0, 2*M_PI); - cairo_set_source_rgb (cr, GL_COLOR_F_RED(fill_color), GL_COLOR_F_GREEN(fill_color), @@ -434,19 +310,20 @@ draw_cd_label_outline (cairo_t *cr, cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill_preserve (cr); + cairo_set_line_width (cr, 1.0/scale); cairo_set_source_rgb (cr, GL_COLOR_F_RED(line_color), GL_COLOR_F_GREEN(line_color), GL_COLOR_F_BLUE(line_color)); cairo_stroke (cr); - cairo_restore (cr); - gl_debug (DEBUG_MINI_PREVIEW, "END"); + cairo_destroy (cr); + } /*--------------------------------------------------------------------------*/ -/* PRIVATE. Draw cd label outline. */ +/* PRIVATE. Expose handler. */ /*--------------------------------------------------------------------------*/ static gboolean expose_cb (GtkWidget *drawingarea, GdkEventExpose *event, gpointer user_data)