diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2006-06-09 22:01:23 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2006-06-09 22:01:23 (GMT) |
commit | 616f1ab3e76932dba5355531eeb6f50b55d55439 (patch) | |
tree | e4f2310015b72e44bb56ea6dd960b34481d88391 | |
parent | e5de5bce063224d4ccfa54d0e3450f1ebde1e998 (diff) |
More work on the theme and on the engine
-rw-r--r-- | gtk-engine/src/olpc-rc-style.c | 62 | ||||
-rw-r--r-- | gtk-engine/src/olpc-rc-style.h | 12 | ||||
-rw-r--r-- | gtk-engine/src/olpc-style.c | 107 | ||||
-rw-r--r-- | gtk-engine/theme/gtkrc | 29 | ||||
-rwxr-xr-x | test/gtk-engine-test.py | 16 |
5 files changed, 130 insertions, 96 deletions
diff --git a/gtk-engine/src/olpc-rc-style.c b/gtk-engine/src/olpc-rc-style.c index a71b087..dfedbf0 100644 --- a/gtk-engine/src/olpc-rc-style.c +++ b/gtk-engine/src/olpc-rc-style.c @@ -25,14 +25,14 @@ #include <gtk/gtk.h> #include <string.h> -static void olpc_rc_style_init (OlpcRcStyle *style); +static void olpc_rc_style_init (OlpcRcStyle *style); static void olpc_rc_style_class_init (OlpcRcStyleClass *klass); static void olpc_rc_style_finalize (GObject *object); enum { - TOKEN_WINDOW_TOP_COLOR = G_TOKEN_LAST + 1, - TOKEN_WINDOW_BOTTOM_COLOR + TOKEN_TOP_COLOR = G_TOKEN_LAST + 1, + TOKEN_BOTTOM_COLOR }; static struct @@ -42,8 +42,8 @@ static struct } theme_symbols[] = { - { "window-top-color", TOKEN_WINDOW_TOP_COLOR }, - { "window-bottom-color", TOKEN_WINDOW_BOTTOM_COLOR } + { "top-color", TOKEN_TOP_COLOR }, + { "bottom-color", TOKEN_BOTTOM_COLOR } }; static GtkRcStyleClass *parent_class; @@ -78,59 +78,58 @@ olpc_rc_style_create_style (GtkRcStyle *style) } static GTokenType -olpc_rc_style_parse_window_top_color (OlpcRcStyle *rc_style, - GtkSettings *settings, - GScanner *scanner) +olpc_rc_style_parse_top_color (OlpcRcStyle *rc_style, + GtkSettings *settings, + GScanner *scanner) { GTokenType token; token = g_scanner_get_next_token (scanner); - if (token != TOKEN_WINDOW_TOP_COLOR) - return TOKEN_WINDOW_TOP_COLOR; + if (token != TOKEN_TOP_COLOR) + return TOKEN_TOP_COLOR; token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_EQUAL_SIGN) return G_TOKEN_EQUAL_SIGN; token = gtk_rc_parse_color (scanner, - &rc_style->window_top_color); + &rc_style->top_color); if (token != G_TOKEN_NONE) return token; - rc_style->window_top_color.pixel = TRUE; + rc_style->top_color.pixel = TRUE; return G_TOKEN_NONE; } static GTokenType -olpc_rc_style_parse_window_bottom_color (OlpcRcStyle *rc_style, - GtkSettings *settings, - GScanner *scanner) +olpc_rc_style_parse_bottom_color (OlpcRcStyle *rc_style, + GtkSettings *settings, + GScanner *scanner) { GTokenType token; token = g_scanner_get_next_token (scanner); - if (token != TOKEN_WINDOW_BOTTOM_COLOR) - return TOKEN_WINDOW_BOTTOM_COLOR; + if (token != TOKEN_BOTTOM_COLOR) + return TOKEN_BOTTOM_COLOR; token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_EQUAL_SIGN) return G_TOKEN_EQUAL_SIGN; - token = gtk_rc_parse_color (scanner, - &rc_style->window_bottom_color); + token = gtk_rc_parse_color (scanner, &rc_style->bottom_color); if (token != G_TOKEN_NONE) return token; - rc_style->window_bottom_color.pixel = TRUE; + rc_style->bottom_color.pixel = TRUE; return G_TOKEN_NONE; } static GTokenType olpc_rc_style_parse (GtkRcStyle *rc_style, - GtkSettings *settings, - GScanner *scanner) + GtkSettings *settings, + GScanner *scanner) { static GQuark scope_id = 0; OlpcRcStyle *olpc_style = OLPC_RC_STYLE (rc_style); @@ -166,11 +165,11 @@ olpc_rc_style_parse (GtkRcStyle *rc_style, switch (token) { - case TOKEN_WINDOW_TOP_COLOR: - expected = olpc_rc_style_parse_window_top_color (olpc_style, settings, scanner); + case TOKEN_TOP_COLOR: + expected = olpc_rc_style_parse_top_color (olpc_style, settings, scanner); break; - case TOKEN_WINDOW_BOTTOM_COLOR: - expected = olpc_rc_style_parse_window_bottom_color (olpc_style, settings, scanner); + case TOKEN_BOTTOM_COLOR: + expected = olpc_rc_style_parse_bottom_color (olpc_style, settings, scanner); break; default: g_scanner_get_next_token (scanner); @@ -191,19 +190,18 @@ olpc_rc_style_parse (GtkRcStyle *rc_style, } static void -olpc_rc_style_merge (GtkRcStyle *dest, - GtkRcStyle *src) +olpc_rc_style_merge (GtkRcStyle *dest, GtkRcStyle *src) { if (OLPC_IS_RC_STYLE (src)) { OlpcRcStyle *olpc_dest = OLPC_RC_STYLE (dest); OlpcRcStyle *olpc_src = OLPC_RC_STYLE (src); - if (olpc_src->window_top_color.pixel) - olpc_dest->window_top_color = olpc_src->window_top_color; + if (olpc_src->top_color.pixel) + olpc_dest->top_color = olpc_src->top_color; - if (olpc_src->window_bottom_color.pixel) - olpc_dest->window_bottom_color = olpc_src->window_bottom_color; + if (olpc_src->bottom_color.pixel) + olpc_dest->bottom_color = olpc_src->bottom_color; } parent_class->merge (dest, src); diff --git a/gtk-engine/src/olpc-rc-style.h b/gtk-engine/src/olpc-rc-style.h index 4fe7968..85d65dd 100644 --- a/gtk-engine/src/olpc-rc-style.h +++ b/gtk-engine/src/olpc-rc-style.h @@ -28,18 +28,18 @@ extern GType olpc_type_rc_style; -#define OLPC_TYPE_RC_STYLE olpc_type_rc_style -#define OLPC_RC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OLPC_TYPE_RC_STYLE, OlpcRcStyle)) -#define OLPC_RC_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OLPC_TYPE_RC_STYLE, OlpcRcStyleClass)) -#define OLPC_IS_RC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OLPC_TYPE_RC_STYLE)) +#define OLPC_TYPE_RC_STYLE olpc_type_rc_style +#define OLPC_RC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), OLPC_TYPE_RC_STYLE, OlpcRcStyle)) +#define OLPC_RC_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OLPC_TYPE_RC_STYLE, OlpcRcStyleClass)) +#define OLPC_IS_RC_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OLPC_TYPE_RC_STYLE)) #define OLPC_IS_RC_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OLPC_TYPE_RC_STYLE)) #define OLPC_RC_STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), OLPC_TYPE_RC_STYLE, OlpcRcStyleClass)) typedef struct _OlpcRcStyle { GtkRcStyle parent_instance; - GdkColor window_top_color; - GdkColor window_bottom_color; + GdkColor top_color; + GdkColor bottom_color; } OlpcRcStyle; typedef struct _OlpcRcStyleClass { diff --git a/gtk-engine/src/olpc-style.c b/gtk-engine/src/olpc-style.c index fad1cd2..14111cb 100644 --- a/gtk-engine/src/olpc-style.c +++ b/gtk-engine/src/olpc-style.c @@ -122,10 +122,12 @@ draw_button (GtkStyle *style, cairo_translate(cr, area->x, area->y); - cairo_rectangle(cr, 0, 0, area->width, area->height); + olpc_rounded_rectangle(cr, 0, 0, area->width, area->height, + 5.0, CORNER_TOPLEFT | CORNER_TOPRIGHT | + CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT); - pattern = create_linear_pattern(&rc_style->window_top_color, - &rc_style->window_bottom_color, + pattern = create_linear_pattern(&rc_style->top_color, + &rc_style->bottom_color, area->height); cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); @@ -139,30 +141,28 @@ draw_button (GtkStyle *style, static void draw_entry (GtkStyle *style, + GtkStateType state, GtkWidget *widget, GdkWindow *window, - GdkRectangle *area) + GdkRectangle *area, + int x, + int y, + int width, + int height) { cairo_t *cr; - const float RADIUS = 10.0; - - cr = gdk_cairo_create (window); - - cairo_translate(cr, area->x + 0.5, area->y + 0.5); - cairo_set_line_width(cr, 1.0); - /* Fill the entry's base color */ - cairo_rectangle(cr, 1.5, 1.5, area->width - 4, area->height - 4); - set_cairo_color(cr, style->base[0]); - cairo_fill(cr); - - /* Draw the border */ - set_cairo_color(cr, style->fg[0]); - olpc_rounded_rectangle(cr, 1, 1, area->width - 3, area->height - 3, - RADIUS, CORNER_TOPLEFT | CORNER_TOPRIGHT | + cr = gdk_cairo_create(window); + cairo_translate(cr, x, y); + + olpc_rounded_rectangle(cr, 0, 0, width, height, + 5.0, CORNER_TOPLEFT | CORNER_TOPRIGHT | CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT); - cairo_stroke (cr); - cairo_destroy (cr); + cairo_set_line_width (cr, 1); + set_cairo_color(cr, style->fg[state]); + cairo_stroke(cr); + + cairo_destroy(cr); } static void @@ -182,15 +182,15 @@ draw_window_background (GtkStyle *style, if (!GTK_WIDGET_MAPPED (widget)) return; - if (!rc_style->window_top_color.pixel) + if (!rc_style->top_color.pixel) top_color = style->bg[widget->state]; else - top_color = rc_style->window_top_color; + top_color = rc_style->top_color; - if (!rc_style->window_bottom_color.pixel) + if (!rc_style->bottom_color.pixel) bottom_color = style->bg[widget->state]; else - bottom_color = rc_style->window_bottom_color; + bottom_color = rc_style->bottom_color; cr = gdk_cairo_create (window); @@ -229,6 +229,32 @@ draw_window_background (GtkStyle *style, } static void +olpc_draw_shadow (GtkStyle *style, + GdkWindow *window, + GtkStateType state_type, + GtkShadowType shadow_type, + GdkRectangle *area, + GtkWidget *widget, + const gchar *detail, + int x, + int y, + int width, + int height) +{ + if (strcmp(detail, "entry") == 0 || + strcmp(detail, "scrolled_window") == 0) { + draw_entry(style, state_type, widget, window, area, + x, y, width, height); + } else if (strcmp(detail, "toolbar") == 0) { + } else { + olpc_style_parent_class->draw_shadow (style, window, + state_type, shadow_type, + area, widget, detail, + x, y, width, height); + } +} + +static void olpc_draw_box (GtkStyle *style, GdkWindow *window, GtkStateType state_type, @@ -241,11 +267,11 @@ olpc_draw_box (GtkStyle *style, int width, int height) { - if (strcmp(detail, "button") == 0 || - strcmp(detail, "buttondefault") == 0) { - draw_button(style, state_type, widget, window, area); + if ((strcmp(detail, "button") == 0 || + strcmp(detail, "buttondefault") == 0)) { + draw_button(style, state_type, widget, window, area); } else { - olpc_style_parent_class->draw_flat_box (style, window, + olpc_style_parent_class->draw_box (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height); @@ -276,29 +302,6 @@ olpc_draw_flat_box (GtkStyle *style, } static void -olpc_draw_shadow (GtkStyle *style, - GdkWindow *window, - GtkStateType state_type, - GtkShadowType shadow_type, - GdkRectangle *area, - GtkWidget *widget, - const gchar *detail, - int x, - int y, - int width, - int height) -{ - if (strcmp(detail, "entrylll") == 0) { - draw_entry(style, widget, window, area); - } else { - olpc_style_parent_class->draw_shadow (style, window, - state_type, shadow_type, - area, widget, detail, - x, y, width, height); - } -} - -static void olpc_style_init (OlpcStyle *style) { } diff --git a/gtk-engine/theme/gtkrc b/gtk-engine/theme/gtkrc index fdeb5d2..4303a10 100644 --- a/gtk-engine/theme/gtkrc +++ b/gtk-engine/theme/gtkrc @@ -1,5 +1,8 @@ style "olpc-default" { + bg[NORMAL] = "#adf03e" + bg[ACTIVE] = "#e8f0dc" + engine "olpc" { } @@ -9,8 +12,8 @@ style "olpc-window" = "olpc-default" { engine "olpc" { - window-top-color = "#a9e351" - window-bottom-color = "#f7fcef" + top-color = "#a9e351" + bottom-color = "#f7fcef" } } @@ -20,8 +23,8 @@ style "olpc-button" = "olpc-default" engine "olpc" { - window-top-color = "#adf03e" - window-bottom-color = "#9ad637" + top-color = "#adf03e" + bottom-color = "#9ad637" } } @@ -30,8 +33,26 @@ style "olpc-button-label" = "olpc-default" fg[NORMAL] = "#FFFFFF" } +style "olpc-toolbar" = "olpc-default" +{ + bg[NORMAL] = "#f1fae3" +} + +style "olpc-entry" = "olpc-default" +{ + fg[NORMAL] = "#adf03e" +} + +style "olpc-scrolled-window" = "olpc-default" +{ + fg[NORMAL] = "#bfc1c0" +} + class "GtkWidget" style "olpc-default" class "GtkWindow" style "olpc-window" class "GtkButton" style "olpc-button" +class "GtkToolbar" style "olpc-toolbar" +class "GtkEntry" style "olpc-entry" +class "GtkScrolledWindow" style "olpc-scrolled-window" widget_class "*.GtkButton.GtkLabel" style "olpc-button-label" diff --git a/test/gtk-engine-test.py b/test/gtk-engine-test.py index b0adeae..4487002 100755 --- a/test/gtk-engine-test.py +++ b/test/gtk-engine-test.py @@ -7,9 +7,9 @@ import gtk class Base: def __init__(self): window = gtk.Window(gtk.WINDOW_TOPLEVEL) - window.set_default_size(400, 400) + window.set_default_size(300, 200) - vbox = gtk.VBox(False, 6) + vbox = gtk.VBox(False, 12) vbox.set_border_width(12) hbox = gtk.HBox(False, 12) @@ -25,6 +25,18 @@ class Base: vbox.pack_start(hbox, False) hbox.show() + + sw = gtk.ScrolledWindow() + sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) + sw.set_size_request(150, 120) + + text_view = gtk.TextView() + sw.add(text_view) + text_view.show() + + vbox.pack_start(sw, False) + sw.show() + window.add(vbox) vbox.show() |