Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <mpg@redhat.com>2006-06-08 20:56:35 (GMT)
committer Marco Pesenti Gritti <mpg@redhat.com>2006-06-08 20:56:35 (GMT)
commite5de5bce063224d4ccfa54d0e3450f1ebde1e998 (patch)
treec372a7f45552c7616fa65ba1be72be15bf2d6a87
parent140562703bdf7e752a172ae53bc4d3571b06def2 (diff)
More work on the theme...
-rw-r--r--gtk-engine/src/olpc-style.c232
-rw-r--r--gtk-engine/theme/gtkrc33
-rwxr-xr-xtest/gtk-engine-test.py42
3 files changed, 267 insertions, 40 deletions
diff --git a/gtk-engine/src/olpc-style.c b/gtk-engine/src/olpc-style.c
index 46410fb..fad1cd2 100644
--- a/gtk-engine/src/olpc-style.c
+++ b/gtk-engine/src/olpc-style.c
@@ -20,6 +20,8 @@
*/
#include <stdlib.h>
+#include <math.h>
+#include <string.h>
#include <cairo.h>
#include <cairo-xlib.h>
@@ -32,35 +34,143 @@
static GtkStyleClass *olpc_style_parent_class;
-static cairo_t *
-olpc_begin_paint (GdkDrawable *window,
- GdkRectangle *area)
+enum {
+ CORNER_TOPLEFT = 1,
+ CORNER_TOPRIGHT = 2,
+ CORNER_BOTTOMLEFT = 4,
+ CORNER_BOTTOMRIGHT = 8
+};
+
+/******* Drawing functions, split them out at some point **********/
+
+static void
+olpc_rounded_rectangle (cairo_t *cr,
+ double x, double y, double w, double h,
+ double radius, int corners)
{
- cairo_t *cr;
+ if (corners & CORNER_TOPLEFT)
+ cairo_move_to (cr, x+radius, y);
+ else
+ cairo_move_to (cr, x, y);
+
+ if (corners & CORNER_TOPRIGHT)
+ cairo_arc (cr, x+w-radius, y+radius, radius, M_PI * 1.5, M_PI * 2);
+ else
+ cairo_line_to (cr, x+w, y);
+
+ if (corners & CORNER_BOTTOMRIGHT)
+ cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI * 0.5);
+ else
+ cairo_line_to (cr, x+w, y+h);
+
+ if (corners & CORNER_BOTTOMLEFT)
+ cairo_arc (cr, x+radius, y+h-radius, radius, M_PI * 0.5, M_PI);
+ else
+ cairo_line_to (cr, x, y+h);
+
+ if (corners & CORNER_TOPLEFT)
+ cairo_arc (cr, x+radius, y+radius, radius, M_PI, M_PI * 1.5);
+ else
+ cairo_line_to (cr, x, y);
+}
- cr = gdk_cairo_create (window);
+/************************************************************************/
- if (area) {
- cairo_rectangle (cr, area->x, area->y, area->width, area->height);
- cairo_clip (cr);
- cairo_new_path (cr);
- }
+static void
+set_cairo_color (cairo_t *cr, GdkColor color)
+{
+ double r, g, b;
- return cr;
+ r = (double)color.red / (double)65535;
+ g = (double)color.green / (double)65535;
+ b = (double)color.blue / (double)65535;
+
+ cairo_set_source_rgb (cr, r, g, b);
+}
+
+static cairo_pattern_t *
+create_linear_pattern(GdkColor *top, GdkColor *bottom, int height)
+{
+ cairo_pattern_t *pattern;
+
+ pattern = cairo_pattern_create_linear(0, 0, 0, height);
+
+ cairo_pattern_add_color_stop_rgb(pattern, 0.0,
+ top->red / 65535.,
+ top->green / 65535.,
+ top->blue / 65535.);
+ cairo_pattern_add_color_stop_rgb(pattern, 1.0,
+ bottom->red / 65535.,
+ bottom->green / 65535.,
+ bottom->blue / 65535.);
+
+ return pattern;
}
static void
-olpc_end_paint (cairo_t *cr)
+draw_button (GtkStyle *style,
+ GtkStateType state,
+ GtkWidget *widget,
+ GdkWindow *window,
+ GdkRectangle *area)
{
- cairo_destroy (cr);
+ OlpcRcStyle *rc_style = OLPC_RC_STYLE (style->rc_style);
+ cairo_t *cr;
+ cairo_pattern_t *pattern;
+
+ cr = gdk_cairo_create(window);
+
+ cairo_translate(cr, area->x, area->y);
+
+ cairo_rectangle(cr, 0, 0, area->width, area->height);
+
+ pattern = create_linear_pattern(&rc_style->window_top_color,
+ &rc_style->window_bottom_color,
+ area->height);
+ cairo_set_source (cr, pattern);
+ cairo_pattern_destroy (pattern);
+ cairo_fill_preserve(cr);
+
+ set_cairo_color(cr, style->fg[state]);
+ cairo_stroke(cr);
+
+ cairo_destroy(cr);
}
static void
-draw_window_background (GtkStyle *style,
+draw_entry (GtkStyle *style,
GtkWidget *widget,
GdkWindow *window,
GdkRectangle *area)
{
+ 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 |
+ CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT);
+ cairo_stroke (cr);
+ cairo_destroy (cr);
+}
+
+static void
+draw_window_background (GtkStyle *style,
+ GtkWidget *widget,
+ GdkWindow *window,
+ GdkRectangle *area)
+{
OlpcRcStyle *rc_style = OLPC_RC_STYLE (style->rc_style);
cairo_t *cr;
GdkColor top_color;
@@ -82,7 +192,7 @@ draw_window_background (GtkStyle *style,
else
bottom_color = rc_style->window_bottom_color;
- cr = olpc_begin_paint (window, area);
+ cr = gdk_cairo_create (window);
if (top_color.red == bottom_color.red &&
top_color.green == bottom_color.green &&
@@ -115,30 +225,76 @@ draw_window_background (GtkStyle *style,
}
cairo_paint (cr);
-
- olpc_end_paint (cr);
+ cairo_destroy (cr);
}
static void
-olpc_draw_flat_box (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)
+olpc_draw_box (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, "button") == 0 ||
+ strcmp(detail, "buttondefault") == 0) {
+ draw_button(style, state_type, widget, window, area);
+ } else {
+ olpc_style_parent_class->draw_flat_box (style, window,
+ state_type, shadow_type,
+ area, widget, detail,
+ x, y, width, height);
+ }
+}
+
+static void
+olpc_draw_flat_box (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 (widget && GTK_IS_WINDOW (widget)) {
- draw_window_background (style, widget, window, area);
+ draw_window_background(style, widget, window, area);
+ } else {
+ olpc_style_parent_class->draw_flat_box (style, window,
+ state_type, shadow_type,
+ area, widget, detail,
+ x, y, width, height);
+ }
+}
+
+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_flat_box (style, window,
- state_type, shadow_type,
- area, widget, detail,
- x, y, width, height);
+ olpc_style_parent_class->draw_shadow (style, window,
+ state_type, shadow_type,
+ area, widget, detail,
+ x, y, width, height);
}
}
@@ -150,11 +306,13 @@ olpc_style_init (OlpcStyle *style)
static void
olpc_style_class_init (OlpcStyleClass *klass)
{
- GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
+ GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
- style_class->draw_flat_box = olpc_draw_flat_box;
-
- olpc_style_parent_class = g_type_class_peek_parent (klass);
+ style_class->draw_flat_box = olpc_draw_flat_box;
+ style_class->draw_box = olpc_draw_box;
+ style_class->draw_shadow = olpc_draw_shadow;
+
+ olpc_style_parent_class = g_type_class_peek_parent (klass);
}
GType olpc_type_style = 0;
diff --git a/gtk-engine/theme/gtkrc b/gtk-engine/theme/gtkrc
index e533936..fdeb5d2 100644
--- a/gtk-engine/theme/gtkrc
+++ b/gtk-engine/theme/gtkrc
@@ -1,10 +1,37 @@
-style "olpc-window"
+style "olpc-default"
{
+ engine "olpc"
+ {
+ }
+}
+
+style "olpc-window" = "olpc-default"
+{
+ engine "olpc"
+ {
+ window-top-color = "#a9e351"
+ window-bottom-color = "#f7fcef"
+ }
+}
+
+style "olpc-button" = "olpc-default"
+{
+ fg[NORMAL] = "#FFFFFF"
+
engine "olpc"
{
- window-top-color = "#a9e351"
- window-bottom-color = "#f7fcef"
+ window-top-color = "#adf03e"
+ window-bottom-color = "#9ad637"
}
}
+style "olpc-button-label" = "olpc-default"
+{
+ fg[NORMAL] = "#FFFFFF"
+}
+
+class "GtkWidget" style "olpc-default"
class "GtkWindow" style "olpc-window"
+class "GtkButton" style "olpc-button"
+
+widget_class "*.GtkButton.GtkLabel" style "olpc-button-label"
diff --git a/test/gtk-engine-test.py b/test/gtk-engine-test.py
new file mode 100755
index 0000000..b0adeae
--- /dev/null
+++ b/test/gtk-engine-test.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+class Base:
+ def __init__(self):
+ window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ window.set_default_size(400, 400)
+
+ vbox = gtk.VBox(False, 6)
+ vbox.set_border_width(12)
+
+ hbox = gtk.HBox(False, 12)
+
+ button = gtk.Button("Button")
+ hbox.pack_start(button, False)
+ button.show()
+
+ entry = gtk.Entry()
+ hbox.pack_start(entry, False)
+ entry.show()
+
+ vbox.pack_start(hbox, False)
+ hbox.show()
+
+ window.add(vbox)
+ vbox.show()
+
+ window.show()
+
+ def main(self):
+ gtk.main()
+
+settings = gtk.settings_get_default()
+
+if settings.get_property('gtk-theme-name') != 'olpc':
+ settings.set_string_property('gtk-theme-name', 'olpc', '')
+
+base = Base()
+base.main()