Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Berg <benjamin@sipsolutions.net>2008-01-27 18:53:21 (GMT)
committer Benjamin Berg <benjamin@sipsolutions.net>2008-01-27 18:53:21 (GMT)
commit4dcca9419345d8e00c98ef5147a380415e36bd16 (patch)
tree02fe01a6b8ed34126c9437d4b08e357dc1e669fa /gtk
parent438196b2b7f1e31ba9c95abbc070091978468c59 (diff)
Draw filled and triangular arrows on black background.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/engine/sugar-drawing.c59
-rw-r--r--gtk/engine/sugar-info.c16
-rw-r--r--gtk/engine/sugar-info.h2
-rw-r--r--gtk/engine/sugar-style.c3
4 files changed, 75 insertions, 5 deletions
diff --git a/gtk/engine/sugar-drawing.c b/gtk/engine/sugar-drawing.c
index 7dd95eb..d74f6b7 100644
--- a/gtk/engine/sugar-drawing.c
+++ b/gtk/engine/sugar-drawing.c
@@ -325,8 +325,8 @@ sugar_draw_button_default (cairo_t *cr, SugarInfo *info)
sugar_rounded_inner_stroke (cr, pos, line_width, info->max_radius, info->corners, info->cont_edges);
}
-void
-sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
+static void
+sugar_draw_rounded_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
{
SugarInfo *info = &arrow_info->info;
SugarRectangle *pos = &info->pos;
@@ -352,7 +352,7 @@ sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
break;
case GTK_ARROW_RIGHT:
cairo_rotate (cr, -G_PI_2);
- run_length = MIN (pos->width, pos->height / 2.0);
+ run_length = MIN ((pos->width - line_width), (pos->height - line_width) / 2.0);
break;
default:
g_assert_not_reached ();
@@ -372,6 +372,59 @@ sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
cairo_restore (cr);
}
+static void
+sugar_draw_filled_triangle_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
+{
+ SugarInfo *info = &arrow_info->info;
+ SugarRectangle *pos = &info->pos;
+ gdouble height;
+
+ cairo_save (cr);
+
+ /* Center, so that rotation, etc. is easier. */
+ cairo_translate (cr, pos->x + pos->width / 2.0, pos->y + pos->height / 2.0);
+
+ switch (arrow_info->dir) {
+ case GTK_ARROW_DOWN:
+ height = MIN (pos->width / 2.0, pos->height);
+ break;
+ case GTK_ARROW_UP:
+ cairo_rotate (cr, G_PI);
+ height = MIN (pos->width / 2.0, pos->height);
+ break;
+ case GTK_ARROW_LEFT:
+ cairo_rotate (cr, G_PI_2);
+ height = MIN (pos->width, pos->height / 2.0);
+ break;
+ case GTK_ARROW_RIGHT:
+ cairo_rotate (cr, -G_PI_2);
+ height = MIN (pos->width, pos->height / 2.0);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ gdk_cairo_set_source_color (cr, &info->style->fg[info->state]);
+
+ cairo_move_to (cr, -height, -height / 2.0);
+ cairo_line_to (cr, 0, height / 2.0);
+ cairo_line_to (cr, height, -height / 2.0);
+ cairo_close_path (cr);
+
+ cairo_fill (cr);
+
+ cairo_restore (cr);
+}
+
+void
+sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info)
+{
+ if (!arrow_info->filled_triangle)
+ sugar_draw_rounded_arrow (cr, arrow_info);
+ else
+ sugar_draw_filled_triangle_arrow (cr, arrow_info);
+}
+
void
sugar_draw_radio_button (cairo_t *cr, SugarInfo *info)
{
diff --git a/gtk/engine/sugar-info.c b/gtk/engine/sugar-info.c
index 7482288..954a930 100644
--- a/gtk/engine/sugar-info.c
+++ b/gtk/engine/sugar-info.c
@@ -181,6 +181,22 @@ sugar_fill_range_info (SugarRangeInfo *range_info, gboolean trough)
}
void
+sugar_fill_arrow_info (SugarArrowInfo *arrow_info,
+ GtkArrowType arrow_type)
+{
+ SugarInfo *info = &arrow_info->info;
+ GdkColor *color;
+
+ arrow_info->dir = arrow_type;
+ arrow_info->filled_triangle = FALSE;
+
+ /* If the background is black, then we draw a solid triangle. */
+ color = &info->style->bg[GTK_STATE_NORMAL];
+ if (color->red == 0 && color->green == 0 && color->blue == 0)
+ arrow_info->filled_triangle = TRUE;
+}
+
+void
sugar_fill_generic_info (SugarInfo *info,
GtkStyle *style,
GtkStateType state_type,
diff --git a/gtk/engine/sugar-info.h b/gtk/engine/sugar-info.h
index c58ff52..ea6a6b4 100644
--- a/gtk/engine/sugar-info.h
+++ b/gtk/engine/sugar-info.h
@@ -82,9 +82,11 @@ typedef struct {
typedef struct {
SugarInfo info;
GtkArrowType dir;
+ gboolean filled_triangle;
} SugarArrowInfo;
G_GNUC_INTERNAL void sugar_info_get_style_property (SugarInfo *info, const gchar *property, gpointer dest);
+G_GNUC_INTERNAL void sugar_fill_arrow_info (SugarArrowInfo *arrow_info, GtkArrowType arrow_type);
G_GNUC_INTERNAL void sugar_fill_generic_info (SugarInfo *info, GtkStyle *style, GtkStateType state_type, GtkShadowType shadow_type, GtkWidget *widget, const gchar *detail, gint x, gint y, gint width, gint height);
G_GNUC_INTERNAL void sugar_fill_range_info (SugarRangeInfo *range_info, gboolean trough);
G_GNUC_INTERNAL void sugar_remove_corners (SugarCorners *corners, SugarEdges edge);
diff --git a/gtk/engine/sugar-style.c b/gtk/engine/sugar-style.c
index 678ef6b..b9af65f 100644
--- a/gtk/engine/sugar-style.c
+++ b/gtk/engine/sugar-style.c
@@ -647,8 +647,7 @@ sugar_style_draw_arrow (GtkStyle *style,
cr = sugar_cairo_create (window, area);
sugar_fill_generic_info (info, style, state_type, shadow_type, widget, detail, x, y, width, height);
-
- arrow_info.dir = arrow_type;
+ sugar_fill_arrow_info (&arrow_info, arrow_type);
sugar_draw_arrow (cr, &arrow_info);