Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Berg <benjamin@sipsolutions.net>2007-05-18 19:38:45 (GMT)
committer Benjamin Berg <benjamin@sipsolutions.net>2007-05-18 19:38:45 (GMT)
commit17487584b0d88ec267ee781a9166df2cb01a3a58 (patch)
tree07ecf7981247371cf2a59042a59373f11beedcf1
parentd5ae0774baf0df17ef5ca05325b5f943c46d9e11 (diff)
Add arrow drawing. We may need to patch GTK+ to get better arrow sizes.
-rw-r--r--gtk/engine/sugar-drawing.c46
-rw-r--r--gtk/engine/sugar-drawing.h1
-rw-r--r--gtk/engine/sugar-info.h5
-rw-r--r--gtk/engine/sugar-style.c34
-rw-r--r--gtk/theme/gtkrc.em1
5 files changed, 87 insertions, 0 deletions
diff --git a/gtk/engine/sugar-drawing.c b/gtk/engine/sugar-drawing.c
index 6a70129..906c9cb 100644
--- a/gtk/engine/sugar-drawing.c
+++ b/gtk/engine/sugar-drawing.c
@@ -307,5 +307,51 @@ 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)
+{
+ SugarInfo *info = &arrow_info->info;
+ GdkRectangle *pos = &info->pos;
+ gdouble line_width = info->rc_style->thick_line_width;
+ gdouble run_length;
+
+ 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:
+ run_length = MIN ((pos->width - line_width) / 2.0, pos->height - line_width);
+ break;
+ case GTK_ARROW_UP:
+ cairo_rotate (cr, G_PI);
+ run_length = MIN ((pos->width - line_width) / 2.0, pos->height - line_width);
+ break;
+ case GTK_ARROW_LEFT:
+ cairo_rotate (cr, G_PI_2);
+ run_length = MIN (pos->width - line_width, (pos->height - line_width) / 2.0);
+ break;
+ case GTK_ARROW_RIGHT:
+ cairo_rotate (cr, -G_PI_2);
+ run_length = MIN (pos->width, pos->height / 2.0);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ cairo_set_line_width (cr, line_width);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
+ gdk_cairo_set_source_color (cr, &info->style->fg[info->state]);
+
+ cairo_move_to (cr, -run_length, -run_length / 2.0);
+ cairo_line_to (cr, 0, run_length / 2.0);
+ cairo_line_to (cr, run_length, -run_length / 2.0);
+
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+}
diff --git a/gtk/engine/sugar-drawing.h b/gtk/engine/sugar-drawing.h
index 09e94d5..9532849 100644
--- a/gtk/engine/sugar-drawing.h
+++ b/gtk/engine/sugar-drawing.h
@@ -30,3 +30,4 @@ G_GNUC_INTERNAL void sugar_draw_scrollbar_slider (cairo_t *cr, SugarRangeInfo *r
G_GNUC_INTERNAL void sugar_draw_entry (cairo_t *cr, SugarInfo *info);
G_GNUC_INTERNAL void sugar_draw_button (cairo_t *cr, SugarInfo *info);
G_GNUC_INTERNAL void sugar_draw_button_default (cairo_t *cr, SugarInfo *info);
+G_GNUC_INTERNAL void sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info);
diff --git a/gtk/engine/sugar-info.h b/gtk/engine/sugar-info.h
index 7415e51..86b2999 100644
--- a/gtk/engine/sugar-info.h
+++ b/gtk/engine/sugar-info.h
@@ -65,6 +65,11 @@ typedef struct {
gboolean trough_fill;
} SugarRangeInfo;
+typedef struct {
+ SugarInfo info;
+ GtkArrowType dir;
+} SugarArrowInfo;
+
G_GNUC_INTERNAL void sugar_info_get_style_property (SugarInfo *info, const gchar *property, gpointer dest);
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);
diff --git a/gtk/engine/sugar-style.c b/gtk/engine/sugar-style.c
index cb33f15..ee143b2 100644
--- a/gtk/engine/sugar-style.c
+++ b/gtk/engine/sugar-style.c
@@ -424,7 +424,40 @@ sugar_style_draw_shadow (GtkStyle *style,
cairo_destroy (cr);
}
+static void
+sugar_style_draw_arrow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state_type,
+ GtkShadowType shadow_type,
+ GdkRectangle *area,
+ GtkWidget *widget,
+ const gchar *detail,
+ GtkArrowType arrow_type,
+ gboolean fill,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ SugarArrowInfo arrow_info;
+ SugarInfo *info = &arrow_info.info;
+ cairo_t *cr;
+
+ if (arrow_type == GTK_ARROW_NONE)
+ return;
+
+ SANITIZE_SIZE
+
+ 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_draw_arrow (cr, &arrow_info);
+
+ cairo_destroy (cr);
+}
static void
sugar_style_draw_extension(GtkStyle *style,
@@ -498,6 +531,7 @@ sugar_style_class_init (SugarStyleClass *klass)
style_class->draw_shadow = sugar_style_draw_shadow;
style_class->draw_focus = sugar_style_draw_focus;
style_class->draw_slider = sugar_style_draw_slider;
+ style_class->draw_arrow = sugar_style_draw_arrow;
style_class->draw_layout = sugar_style_draw_layout;
}
diff --git a/gtk/theme/gtkrc.em b/gtk/theme/gtkrc.em
index 3ff37c2..05fb133 100644
--- a/gtk/theme/gtkrc.em
+++ b/gtk/theme/gtkrc.em
@@ -133,6 +133,7 @@ style "vscale" = "scale"
style "spinbutton"
{
+ fg[NORMAL] = "#ffffff"
engine "sugar" {
hint = "spinbutton"
}