diff options
author | Benjamin Berg <benjamin@sipsolutions.net> | 2007-08-10 16:24:03 (GMT) |
---|---|---|
committer | Benjamin Berg <benjamin@sipsolutions.net> | 2007-08-10 16:24:03 (GMT) |
commit | 1d9d64d25eba1fdcf5b9b333facb1b487c241682 (patch) | |
tree | 7895c79378dc95368c6e2dc45efef3b8fb12670d /gtk | |
parent | c87334c4c59e55888e1b823e3d380836698ab024 (diff) |
Added support for palette and palette invoker drawing.
There are still some bugs that need to be resolved with the menu placment.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/engine/sugar-drawing.c | 57 | ||||
-rw-r--r-- | gtk/engine/sugar-drawing.h | 5 | ||||
-rw-r--r-- | gtk/engine/sugar-info.c | 52 | ||||
-rw-r--r-- | gtk/engine/sugar-info.h | 8 | ||||
-rw-r--r-- | gtk/engine/sugar-rc-style.c | 9 | ||||
-rw-r--r-- | gtk/engine/sugar-rc-style.h | 6 | ||||
-rw-r--r-- | gtk/engine/sugar-style.c | 71 | ||||
-rw-r--r-- | gtk/theme/gtkrc.em | 65 |
8 files changed, 224 insertions, 49 deletions
diff --git a/gtk/engine/sugar-drawing.c b/gtk/engine/sugar-drawing.c index 9786308..7dd95eb 100644 --- a/gtk/engine/sugar-drawing.c +++ b/gtk/engine/sugar-drawing.c @@ -513,3 +513,60 @@ sugar_draw_progressbar_bar (cairo_t *cr, SugarInfo *info, GtkProgressBarOrientat } } + +void +sugar_draw_menu (cairo_t *cr, + SugarInfo *info, + SugarGapInfo *gap) +{ + SugarRectangle *pos = &info->pos; + gdouble line_width = info->rc_style->line_width; + + gdk_cairo_set_source_color (cr, &info->style->bg[GTK_STATE_NORMAL]); + sugar_cairo_rectangle (cr, pos); + + cairo_fill (cr); + + /* Draw the border, clipped if the gap is set (ie. for a palette) */ + cairo_save (cr); + + /* Add 1.0 to prevent visual artifacts, no idea why this happens. */ + sugar_clip_gap (cr, info, gap, line_width, line_width + 1.0); + gdk_cairo_set_source_color (cr, &info->style->bg[GTK_STATE_ACTIVE]); + cairo_set_line_width (cr, line_width); + + sugar_rounded_inner_stroke (cr, pos, line_width, 0, info->corners, info->cont_edges); + + cairo_restore (cr); +} + +void +sugar_draw_palette_invoker (cairo_t *cr, + SugarInfo *info, + SugarGapInfo *gap) +{ + SugarRectangle *pos = &info->pos; + gdouble line_width = info->rc_style->line_width; + + gdk_cairo_set_source_color (cr, &info->style->bg[GTK_STATE_PRELIGHT]); + sugar_cairo_rectangle (cr, pos); + + cairo_fill (cr); + + if (info->shadow != GTK_SHADOW_NONE) { + /* Draw an outline if there is a shadow. */ + cairo_save (cr); + + /* Add 1.0 to prevent visual artifacts, no idea why this happens. */ + sugar_clip_gap (cr, info, gap, line_width, line_width + 1.0); + /* WHAT COLOR TO USE HERE? */ + gdk_cairo_set_source_color (cr, &info->style->bg[GTK_STATE_ACTIVE]); + cairo_set_line_width (cr, line_width); + + sugar_rounded_inner_stroke (cr, pos, line_width, 0, info->corners, info->cont_edges); + + cairo_restore (cr); + } +} + + diff --git a/gtk/engine/sugar-drawing.h b/gtk/engine/sugar-drawing.h index 7e04f18..dce0235 100644 --- a/gtk/engine/sugar-drawing.h +++ b/gtk/engine/sugar-drawing.h @@ -36,4 +36,7 @@ G_GNUC_INTERNAL void sugar_draw_arrow (cairo_t *cr, SugarArrowInfo *arrow_info); G_GNUC_INTERNAL void sugar_draw_radio_button (cairo_t *cr, SugarInfo *info); G_GNUC_INTERNAL void sugar_draw_check_button (cairo_t *cr, SugarInfo *info); G_GNUC_INTERNAL void sugar_draw_progressbar_trough (cairo_t *cr, SugarInfo *info, gboolean fill); -G_GNUC_INTERNAL void sugar_draw_progressbar_bar (cairo_t *cr, SugarInfo *info,GtkProgressBarOrientation orientation); +G_GNUC_INTERNAL void sugar_draw_progressbar_bar (cairo_t *cr, SugarInfo *info, GtkProgressBarOrientation orientation); +G_GNUC_INTERNAL void sugar_draw_menu (cairo_t *cr, SugarInfo *info, SugarGapInfo *gap); +G_GNUC_INTERNAL void sugar_draw_palette_invoker (cairo_t *cr, SugarInfo *info, SugarGapInfo *gap); + diff --git a/gtk/engine/sugar-info.c b/gtk/engine/sugar-info.c index c1a3fa6..5a9f776 100644 --- a/gtk/engine/sugar-info.c +++ b/gtk/engine/sugar-info.c @@ -106,7 +106,7 @@ sugar_fill_range_info (SugarRangeInfo *range_info, gboolean trough) if (DETAIL ("trough-lower") || DETAIL ("trough-upper")) { /* If there is no real scale, assume that it is not inverted. */ - if (info->widget && GTK_IS_RANGE (info->widget) && gtk_range_get_inverted (info->widget)) + if (info->widget && GTK_IS_RANGE (info->widget) && gtk_range_get_inverted (GTK_RANGE (info->widget))) inverted = TRUE; if (DETAIL ("trough-upper")) @@ -130,7 +130,7 @@ sugar_fill_range_info (SugarRangeInfo *range_info, gboolean trough) if (DETAIL ("trough-lower") || DETAIL ("trough-upper")) { /* If there is no real scale, assume that it is not inverted. */ - if (info->widget && GTK_IS_RANGE (info->widget) && gtk_range_get_inverted (info->widget)) + if (info->widget && GTK_IS_RANGE (info->widget) && gtk_range_get_inverted (GTK_RANGE (info->widget))) inverted = TRUE; if (DETAIL ("trough-upper")) @@ -191,6 +191,14 @@ sugar_fill_generic_info (SugarInfo *info, info->ltr = sugar_widget_is_ltr (widget); + /* nasty little special cases ... */ + if (!DETAIL ("palette-invoker")) { + info->pos.x += info->rc_style->fake_padding; + info->pos.y += info->rc_style->fake_padding; + info->pos.width -= 2*info->rc_style->fake_padding; + info->pos.height -= 2*info->rc_style->fake_padding; + } + /* Ignore the prelight state in some cases. */ if (info->state == GTK_STATE_PRELIGHT) { if (DETAIL ("button") || DETAIL ("buttondefault") || @@ -203,3 +211,43 @@ sugar_fill_generic_info (SugarInfo *info, } } } + +void +sugar_clip_gap (cairo_t *cr, + SugarInfo *info, + SugarGapInfo *gap, + gdouble padding, + gdouble size) +{ + SugarRectangle *pos = &info->pos; + + /* Don't clip anything, if there is no gap. */ + if (gap == NULL) + return; + + /* Nothing clipped away. */ + if (2*padding >= gap->size) + return; + + /* The whole area, then subtract the correct region. */ + cairo_rectangle (cr, pos->x, pos->y, pos->width, pos->height); + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + + /* This assumes that there is enough space for size ... */ + switch (gap->side) { + case GTK_POS_TOP: + cairo_rectangle (cr, pos->x + gap->start + padding, pos->y, gap->size - 2*padding, size); + break; + case GTK_POS_BOTTOM: + cairo_rectangle (cr, pos->x + gap->start + padding, pos->y + pos->height - size, gap->size - 2*padding, size); + break; + case GTK_POS_LEFT: + cairo_rectangle (cr, pos->x, pos->y + gap->start + padding, size, gap->size - 2*padding); + break; + case GTK_POS_RIGHT: + cairo_rectangle (cr, pos->x + pos->width - size, pos->y + gap->start + padding, size, gap->size - 2*padding); + break; + } + cairo_clip (cr); +} + diff --git a/gtk/engine/sugar-info.h b/gtk/engine/sugar-info.h index 43203b9..c58ff52 100644 --- a/gtk/engine/sugar-info.h +++ b/gtk/engine/sugar-info.h @@ -21,6 +21,7 @@ #define __SUGAR_INFO_H #include <gtk/gtkwidget.h> +#include <cairo.h> #include "sugar-style.h" #include "sugar-rc-style.h" @@ -51,6 +52,12 @@ typedef struct { } SugarRectangle; typedef struct { + GtkPositionType side; + gdouble start; + gdouble size; +} SugarGapInfo; + +typedef struct { GtkWidget *widget; GtkStyle *style; SugarRcStyle *rc_style; @@ -81,5 +88,6 @@ G_GNUC_INTERNAL void sugar_info_get_style_property (SugarInfo *info, const gchar 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); +G_GNUC_INTERNAL void sugar_clip_gap (cairo_t *cr, SugarInfo *info, SugarGapInfo *gap, gdouble padding, gdouble size); #endif /* __SUGAR_INFO_H */ diff --git a/gtk/engine/sugar-rc-style.c b/gtk/engine/sugar-rc-style.c index d35d9a6..2502d09 100644 --- a/gtk/engine/sugar-rc-style.c +++ b/gtk/engine/sugar-rc-style.c @@ -33,6 +33,7 @@ static gchar symbols[] = "thick_line_width\0" "max_radius\0" "scrollbar_border\0" + "fake_padding\0" "label_fg_color\0" "bg\0" "fg\0" @@ -46,6 +47,7 @@ typedef enum { TOKEN_THICK_LINE_WIDTH, TOKEN_MAX_RADIUS, TOKEN_SCROLLBAR_BORDER, + TOKEN_FAKE_PADDING, TOKEN_LABEL_FG_COLOR, TOKEN_BG, TOKEN_FG, @@ -85,6 +87,7 @@ sugar_rc_style_init (SugarRcStyle *rc_style) rc_style->thick_line_width = 4; rc_style->max_radius = 5; rc_style->scrollbar_border = 5; + rc_style->fake_padding = 0; rc_style->hint = NULL; rc_style->apply_label_color.bg = 0; rc_style->apply_label_color.fg = 0; @@ -241,6 +244,10 @@ sugar_rc_style_parse (GtkRcStyle *rc_style, token = sugar_rc_parse_float(scanner, &sugar_rc_style->scrollbar_border); sugar_rc_style->flags |= OPTION_SCROLLBAR_BORDER; break; + case TOKEN_FAKE_PADDING: + token = sugar_rc_parse_float(scanner, &sugar_rc_style->fake_padding); + sugar_rc_style->flags |= OPTION_FAKE_PADDING; + break; case TOKEN_HINT: token = sugar_rc_parse_string(scanner, &sugar_rc_style->hint); sugar_rc_style->flags |= OPTION_HINT; @@ -301,6 +308,8 @@ sugar_rc_style_merge (GtkRcStyle *dest, sugar_dest->max_radius = sugar_src->max_radius; if (flags & OPTION_SCROLLBAR_BORDER) sugar_dest->scrollbar_border = sugar_src->scrollbar_border; + if (flags & OPTION_FAKE_PADDING) + sugar_dest->fake_padding = sugar_src->fake_padding; if (flags & OPTION_LABEL_FG_COLOR) sugar_dest->label_fg_color = sugar_src->label_fg_color; if (flags & OPTION_HINT) { diff --git a/gtk/engine/sugar-rc-style.h b/gtk/engine/sugar-rc-style.h index c6849d9..d584f8b 100644 --- a/gtk/engine/sugar-rc-style.h +++ b/gtk/engine/sugar-rc-style.h @@ -34,8 +34,9 @@ typedef enum { OPTION_THICK_LINE_WIDTH = 1 << 1, OPTION_MAX_RADIUS = 1 << 2, OPTION_SCROLLBAR_BORDER = 1 << 3, - OPTION_HINT = 1 << 4, - OPTION_LABEL_FG_COLOR = 1 << 5 + OPTION_FAKE_PADDING = 1 << 4, + OPTION_HINT = 1 << 5, + OPTION_LABEL_FG_COLOR = 1 << 6 } SugarRcStyleOptions; typedef struct { @@ -63,6 +64,7 @@ struct _SugarRcStyle { gdouble thick_line_width; gdouble max_radius; gdouble scrollbar_border; + gdouble fake_padding; /* The purpose of this color is to be able to apply a color from * a different style at merge time. This cannot be done with symbolic diff --git a/gtk/engine/sugar-style.c b/gtk/engine/sugar-style.c index dd910ee..11b104e 100644 --- a/gtk/engine/sugar-style.c +++ b/gtk/engine/sugar-style.c @@ -398,18 +398,17 @@ sugar_style_draw_box (GtkStyle *style, gdk_cairo_set_source_color (cr, &style->bg[state_type]); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); - } else if (DETAIL ("menu")) { - gdouble line_width = SUGAR_RC_STYLE (style->rc_style)->line_width; + } else if (DETAIL ("menu") || DETAIL ("palette")) { + SugarInfo info; - gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_INSENSITIVE]); - cairo_rectangle (cr, x, y, width, height); - cairo_fill (cr); + sugar_fill_generic_info (&info, style, state_type, shadow_type, widget, detail, x, y, width, height); + sugar_draw_menu (cr, &info, NULL); + } else if (DETAIL ("palette-invoker")) { + SugarInfo info; - gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); - cairo_set_line_width (cr, line_width); - cairo_rectangle (cr, x + line_width / 2, y + line_width / 2, - width - line_width, height - line_width); - cairo_stroke (cr); + sugar_fill_generic_info (&info, style, state_type, shadow_type, widget, detail, x, y, width, height); + + sugar_draw_palette_invoker (cr, &info, NULL); } else { parent_class->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height); } @@ -417,6 +416,57 @@ sugar_style_draw_box (GtkStyle *style, } static void +sugar_style_draw_box_gap (GtkStyle *style, + GdkWindow *window, + GtkStateType state_type, + GtkShadowType shadow_type, + GdkRectangle *area, + GtkWidget *widget, + const gchar *detail, + gint x, + gint y, + gint width, + gint height, + GtkPositionType gap_side, + gint gap_x, + gint gap_width) +{ + cairo_t *cr; + + SANITIZE_SIZE + + cr = sugar_cairo_create (window, area); + + if (DETAIL ("palette-invoker")) { + SugarInfo info; + SugarGapInfo gap; + + sugar_fill_generic_info (&info, style, state_type, shadow_type, widget, detail, x, y, width, height); + + gap.side = gap_side; + gap.start = gap_x; + gap.size = gap_width; + + sugar_draw_palette_invoker (cr, &info, &gap); + } else if (DETAIL ("palette")) { + SugarInfo info; + SugarGapInfo gap; + + sugar_fill_generic_info (&info, style, state_type, shadow_type, widget, detail, x, y, width, height); + + gap.side = gap_side; + gap.start = gap_x; + gap.size = gap_width; + + sugar_draw_menu (cr, &info, &gap); + } else { + parent_class->draw_box_gap (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_x, gap_width); + } + + cairo_destroy (cr); +} + +static void sugar_style_draw_flat_box (GtkStyle *style, GdkWindow *window, GtkStateType state_type, @@ -680,6 +730,7 @@ sugar_style_class_init (SugarStyleClass *klass) style_class->draw_vline = sugar_style_draw_vline; style_class->draw_extension = sugar_style_draw_extension; style_class->draw_box = sugar_style_draw_box; + style_class->draw_box_gap = sugar_style_draw_box_gap; style_class->draw_flat_box = sugar_style_draw_flat_box; style_class->draw_shadow = sugar_style_draw_shadow; style_class->draw_focus = sugar_style_draw_focus; diff --git a/gtk/theme/gtkrc.em b/gtk/theme/gtkrc.em index ec88a2a..548daff 100644 --- a/gtk/theme/gtkrc.em +++ b/gtk/theme/gtkrc.em @@ -19,6 +19,7 @@ if theme == "sugar-xo": subcell_size = 15 bullet_size = 9.5 font_height = 24 + default_padding = 6 else: # About 50% smaller xo = False line_width = 1.125 @@ -26,6 +27,7 @@ else: # About 50% smaller subcell_size = 7 bullet_size = 5 font_height = 12 + default_padding = 3 radio_size = my_floor(subcell_size + bullet_size + line_width) @@ -145,17 +147,6 @@ style "window-child" } } -style "palette" -{ - bg[NORMAL] = $black -} - -style "palette-child" -{ - fg[NORMAL] = $white -} - - style "groupbox-panel" { bg[NORMAL] = $selection_grey @@ -192,6 +183,19 @@ style "groupbox-palette-child" style "menu" { + bg[NORMAL] = $black + bg[ACTIVE] = $button_grey + + GtkMenu::horizontal-padding = 0 + GtkMenu::vertical-padding = 0 + + xthickness = 0 + ythickness = 0 +} + +# Can this all be moved in the menuitem style? +style "menu-child" +{ color["bg_color"] = $black fg[NORMAL] = $white @@ -201,21 +205,6 @@ style "menu" bg[INSENSITIVE] = $black base[INSENSITIVE] = $black - # The following colors are for the check and radio menu items - base[NORMAL] = $white - base[PRELIGHT] = $white - base[ACTIVE] = $text_field_grey - - text[PRELIGHT] = $toolbar_grey - text[NORMAL] = $toolbar_grey - text[ACTIVE] = $toolbar_grey - - GtkMenu::horizontal-padding = 0 - GtkMenu::vertical-padding = 0 - - xthickness = 0 - ythickness = 0 - engine "sugar" { label_fg_color = $white } @@ -347,6 +336,7 @@ style "toolbutton" engine "sugar" { max_radius = 5.0 + fake_padding = $default_padding } } @@ -431,9 +421,15 @@ style "menuitem" bg[PRELIGHT] = $button_grey - # For check/radio menu items - text[NORMAL] = $white - text[PRELIGHT] = $white + # The following colors are for the check and radio menu items + base[NORMAL] = $white + base[PRELIGHT] = $white + base[ACTIVE] = $text_field_grey + + text[PRELIGHT] = $toolbar_grey + text[NORMAL] = $toolbar_grey + text[ACTIVE] = $toolbar_grey + GtkMenuItem::horizontal-padding = $line_width xthickness = $(my_ceil(line_width * 2)) @@ -469,8 +465,8 @@ widget_class "*<SugarToolbox>*" style "toolbox" widget_class "*<GtkToolbar>*" style "toolbox" # SugarPalette -widget_class "*<SugarPalette>" style "palette" -widget_class "*<SugarPalette>*" style "palette-child" +widget_class "<SugarPalette>" style "menu" +widget_class "<SugarPalette>.*" style "menu-child" # SugarFrameWindow widget_class "*<SugarFrameWindow>*" style "frame" @@ -483,8 +479,8 @@ widget_class "*<SugarPanel>*" style "panel" widget_class "<GtkWindow>*<SugarGroupBox>*<GtkEventBox>" style "groupbox-panel" widget_class "<GtkWindow>*<SugarGroupBox>*" style "groupbox-panel-child" -widget_class "*<SugarPalette>*<SugarGroupBox>*<GtkEventBox>" style "groupbox-palette" -widget_class "*<SugarPalette>*<SugarGroupBox>*" style "groupbox-palette-child" +widget_class "<SugarPalette>*<SugarGroupBox>*<GtkEventBox>" style "groupbox-palette" +widget_class "<SugarPalette>*<SugarGroupBox>*" style "groupbox-palette-child" @@ -500,7 +496,8 @@ widget_class "*<SugarPalette>*<SugarGroupBox>*" style "groupbox-palette-child" widget_class "*<GtkToolButton>*" style "toolbutton" # Menu -widget_class "*<GtkMenuShell>*" style "menu" # Why is this menu shell? +widget_class "*<GtkMenuShell>" style "menu" # Why is this menu shell? +widget_class "*<GtkMenuShell>.*" style "menu-child" # Why is this menu shell? widget_class "*<GtkMenuItem>*" style "menuitem" widget_class "*<GtkSeparatorMenuItem>*" style "separatormenuitem" |