[cairo-commit] cairo-gtk-engine/src Makefile.am, 1.8,
1.9 caligula-draw-grassy.c, NONE, 1.1 caligula-draw-grassy.h,
NONE, 1.1 caligula-draw-sketchy.c, 1.2,
1.3 caligula-draw-swirly.c, NONE, 1.1 caligula-draw-swirly.h,
NONE, 1.1 caligula-draw.c, 1.4, 1.5
Kristian Hogsberg
commit at pdx.freedesktop.org
Wed Feb 9 14:49:56 PST 2005
Committed by: krh
Update of /cvs/cairo/cairo-gtk-engine/src
In directory gabe:/tmp/cvs-serv15865/src
Modified Files:
Makefile.am caligula-draw-sketchy.c caligula-draw.c
Added Files:
caligula-draw-grassy.c caligula-draw-grassy.h
caligula-draw-swirly.c caligula-draw-swirly.h
Log Message:
2005-02-09 Kristian Høgsberg <krh at redhat.com>
* src/Makefile.am (libcaligula_la_SOURCES): Add new source files.
* src/caligula-draw-swirly.c, src/caligula-draw-swirly.h: Split
out the swirly button code into these files.
* src/caligula-draw-grassy.c, src/caligula-draw-grassy.h: Split
out the grassy button code into these files.
* src/caligula-draw.c (caligula_draw_box): Pick a random box type.
* src/caligula-draw-sketchy.c (rand_double): Use caligula_rand.
Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/Makefile.am,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- Makefile.am 9 Feb 2005 22:18:43 -0000 1.8
+++ Makefile.am 9 Feb 2005 22:49:54 -0000 1.9
@@ -24,6 +24,10 @@
caligula-draw-shadowed.h \
caligula-draw-sketchy.c \
caligula-draw-sketchy.h \
+ caligula-draw-swirly.c \
+ caligula-draw-swirly.h \
+ caligula-draw-grassy.c \
+ caligula-draw-grassy.h \
caligula-rand.c \
caligula-rand.h
--- NEW FILE: caligula-draw-grassy.c ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: caligula-draw-grassy.h ---
(This appears to be a binary file; contents omitted.)
Index: caligula-draw-sketchy.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-draw-sketchy.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- caligula-draw-sketchy.c 9 Feb 2005 20:21:04 -0000 1.2
+++ caligula-draw-sketchy.c 9 Feb 2005 22:49:54 -0000 1.3
@@ -30,6 +30,7 @@
#include <assert.h>
#include "caligula-draw-sketchy.h"
+#include "caligula-rand.h"
typedef struct pt {
double x;
@@ -62,7 +63,7 @@
static double
rand_double (double max)
{
- return max * rand()/(RAND_MAX+1.0);
+ return max * caligula_rand() / (CALIGULA_RAND_MAX + 1.0);
}
/* Return the bearing of the line segment from a to b */
--- NEW FILE: caligula-draw-swirly.c ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: caligula-draw-swirly.h ---
(This appears to be a binary file; contents omitted.)
Index: caligula-draw.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-draw.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- caligula-draw.c 9 Feb 2005 22:18:43 -0000 1.4
+++ caligula-draw.c 9 Feb 2005 22:49:54 -0000 1.5
@@ -27,6 +27,10 @@
#include "caligula-draw.h"
#include "caligula-rand.h"
+#include "caligula-draw-sketchy.h"
+#include "caligula-draw-swirly.h"
+#include "caligula-draw-grassy.h"
+#include "caligula-draw-shadowed.h"
static cairo_t *
caligula_begin_paint (GdkDrawable *window, gint *x_offset, gint *y_offset)
@@ -60,252 +64,6 @@
cairo_destroy (cr);
}
-#if 0 /* Swirly button */
-
-enum { LEFT, RIGHT };
-#define STRENGTH 10
-
-static void
-draw_swoosh (cairo_t *cr, int side, int x, int y, int width, int height,
- int top_x, int top_y, int left_x, int left_y,
- int right_x, int right_y, int bottom_x, int bottom_y)
-{
- cairo_pattern_t *pattern;
-
- cairo_save (cr);
-
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- if (side == LEFT) {
- cairo_new_path (cr);
- cairo_move_to (cr, top_x, y);
- cairo_line_to (cr, right_x + 1, y);
- cairo_line_to (cr, right_x + 1, top_y - 1);
- cairo_line_to (cr, left_x - 1, top_y - 1);
- cairo_line_to (cr, left_x - 1, bottom_y + 1);
- cairo_line_to (cr, x, bottom_y + 1);
- cairo_line_to (cr, x, left_y);
- cairo_close_path (cr);
- cairo_clip (cr);
- }
- else {
- cairo_new_path (cr);
- cairo_move_to (cr, bottom_x, y + height);
- cairo_line_to (cr, x + width, right_y);
- cairo_line_to (cr, x + width, top_y - 1);
- cairo_line_to (cr, right_x + 1, top_y - 1);
- cairo_line_to (cr, right_x + 1, bottom_y + 1);
- cairo_line_to (cr, left_x - 1, bottom_y + 1);
- cairo_line_to (cr, left_x - 1, y + height);
- cairo_close_path (cr);
- cairo_clip (cr);
- }
-
- cairo_new_path (cr);
- cairo_move_to (cr, top_x, top_y);
- cairo_curve_to (cr,
- top_x + STRENGTH, top_y,
- right_x, right_y - STRENGTH,
- right_x, right_y);
-
- cairo_curve_to (cr,
- right_x, right_y + STRENGTH,
- bottom_x + STRENGTH, bottom_y,
- bottom_x, bottom_y);
-
- cairo_curve_to (cr,
- bottom_x - STRENGTH, bottom_y,
- left_x, left_y + STRENGTH,
- left_x, left_y);
-
- cairo_curve_to (cr,
- left_x, left_y - STRENGTH,
- top_x - STRENGTH, top_y,
- top_x, top_y);
- cairo_close_path (cr);
-
- top_y += 1;
- left_x += 4;
- right_x -= 4;
- bottom_y -= 1;
-
- cairo_move_to (cr, top_x, top_y);
- cairo_curve_to (cr,
- top_x + STRENGTH, top_y,
- right_x, right_y - STRENGTH,
- right_x, right_y);
-
- cairo_curve_to (cr,
- right_x, right_y + STRENGTH,
- bottom_x + STRENGTH, bottom_y,
- bottom_x, bottom_y);
-
- cairo_curve_to (cr,
- bottom_x - STRENGTH, bottom_y,
- left_x, left_y + STRENGTH,
- left_x, left_y);
-
- cairo_curve_to (cr,
- left_x, left_y - STRENGTH,
- top_x - STRENGTH, top_y,
- top_x, top_y);
-
- if (side == LEFT)
- pattern = cairo_pattern_create_linear (left_x, bottom_y, top_x, top_y);
- else
- pattern = cairo_pattern_create_linear (right_x, top_y,
- bottom_x, bottom_y);
-
- cairo_pattern_add_color_stop (pattern, 0, 0, 0, 0.5, 0.5);
- cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0.2, 1);
- cairo_set_pattern (cr, pattern);
- cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
- cairo_fill (cr);
- cairo_pattern_destroy (pattern);
-
- cairo_restore (cr);
-}
-
-static void
-swoosh (cairo_t *cr, int x, int y, int width, int height)
-{
- int top_x, top_y, left_x, left_y, right_x, right_y, bottom_x, bottom_y;
-
- top_x = x + caligula_rand_within (15, 40);
- top_y = y - 2;
- left_x = x - 4;
- left_y = caligula_rand_within (y + height / 2 - 5, y + height / 2 + 5);
- right_x = left_x + caligula_rand_within (50, 60);
- right_y = caligula_rand_within (y + height / 2 - 5, y + height / 2 + 5);
- bottom_x = x + caligula_rand_within (10, 20);
- bottom_y = y + height - caligula_rand_within (0, 4);
-
- draw_swoosh (cr, LEFT, x, y, width, height,
- top_x, top_y, left_x, left_y,
- right_x, right_y, bottom_x, bottom_y);
-
- top_x = x + width - caligula_rand_within (10, 20);
- top_y = y + caligula_rand_within (0, 4);
- right_x = x + width + 4;
- right_y = y + caligula_rand_within (height / 2 - 5, height / 2 + 5);
- left_x = right_x - caligula_rand_within (50, 60);
- left_y = y + caligula_rand_within (height / 2 - 5, height / 2 + 5);
- bottom_x = x + width - caligula_rand_within (15, 40);
- bottom_y = y + height + 2;
-
- draw_swoosh (cr, RIGHT, x, y, width, height,
- top_x, top_y, left_x, left_y,
- right_x, right_y, bottom_x, bottom_y);
-}
-
-static void
-draw_button (cairo_t *cr, int x, int y, int width, int height)
-{
- cairo_text_extents_t extents;
- cairo_pattern_t *pattern;
- int text_x, text_y;
- const double gray = 0.92;
- const double outline_gray = 0.50;
-
- /* Gradient fill */
- pattern = cairo_pattern_create_linear (x, y, x, y + height);
- cairo_pattern_add_color_stop (pattern, 0, 0, 0, 0, 1);
- cairo_pattern_add_color_stop (pattern, 0.035, gray, gray, gray, 1);
- cairo_pattern_add_color_stop (pattern, 0.25, 1, 1, 1, 1);
- cairo_pattern_add_color_stop (pattern, 0.45, gray, gray, gray, 1);
- cairo_pattern_add_color_stop (pattern, 0.91, 1, 1, 1, 1);
- cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0, 0);
- cairo_set_pattern (cr, pattern);
-
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
-
- /* Outline */
- cairo_set_alpha (cr, 1);
- cairo_set_rgb_color (cr, outline_gray, outline_gray, outline_gray);
- cairo_set_line_width (cr, 1);
- cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1);
- cairo_stroke (cr);
-
- swoosh (cr, x, y, width, height);
-}
-
-#else /* Grass like button */
-
-static void
-swoosh (cairo_t *cr, int x, int y, int width, int height)
-{
- const double swoosh_alpha = 0.10;
- double top_x, top_y, right_x, right_y;
-
- top_x = x + caligula_rand_within (width / 2, width);
- top_y = y - caligula_rand_within (0, height * 2);
- right_x = x + caligula_rand_within (0, width);
- right_y = y + height + caligula_rand_within (0, height);
-
- cairo_new_path (cr);
- cairo_move_to (cr, top_x, top_y);
- cairo_curve_to (cr,
- top_x + 5, top_y - 5,
- right_x, right_y - 5,
- right_x, right_y);
-
- cairo_curve_to (cr,
- right_x, right_y - 5,
- top_x - 5, top_y,
- top_x, top_y);
-
- cairo_close_path (cr);
- cairo_set_rgb_color (cr, 0, 0, 0);
- cairo_set_alpha (cr, swoosh_alpha);
- cairo_fill (cr);
-}
-
-static void
-draw_button (cairo_t *cr, int x, int y, int width, int height)
-{
- cairo_pattern_t *pattern;
- const double gray = 0.92;
- const double outline_gray = 0.50;
-
- cairo_save (cr);
-
- cairo_rectangle (cr, x, y, width, height);
-#if 1
- cairo_clip (cr);
-#endif
-
- cairo_set_rgb_color (cr, 1, 1, 1);
- cairo_fill (cr);
-
- /* Gradient fill */
- pattern = cairo_pattern_create_linear (x, y, x, y + height);
- cairo_pattern_add_color_stop (pattern, 0, 0, 0, 0, 1);
- cairo_pattern_add_color_stop (pattern, 0.035, gray, gray, gray, 1);
- cairo_pattern_add_color_stop (pattern, 0.25, 1, 1, 1, 1);
- cairo_pattern_add_color_stop (pattern, 0.45, gray, gray, gray, 1);
- cairo_pattern_add_color_stop (pattern, 0.91, 1, 1, 1, 1);
- cairo_pattern_add_color_stop (pattern, 1, 0, 0, 0, 0);
- cairo_set_pattern (cr, pattern);
-
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
-
- swoosh (cr, x, y, width, height);
- swoosh (cr, x, y, width, height);
- swoosh (cr, x, y, width, height);
-
- /* Outline */
- cairo_set_alpha (cr, 1);
- cairo_set_rgb_color (cr, outline_gray, outline_gray, outline_gray);
- cairo_set_line_width (cr, 1);
- cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1);
- cairo_stroke (cr);
-
- cairo_restore (cr);
-}
-
-#endif /* end of buttons */
-
void
caligula_draw_box (GtkStyle * style,
GdkWindow * window,
@@ -318,12 +76,24 @@
{
cairo_t *cr;
gint x_offset, y_offset;
+ gint box;
caligula_srand ((unsigned)widget);
cr = caligula_begin_paint (window, &x_offset, &y_offset);
- draw_button (cr, x, y, width, height);
+ box = caligula_rand_within (0, 3);
+ switch (box) {
+ case 0:
+ caligula_draw_sketchy_box (cr, x, y, width, height);
+ break;
+ case 1:
+ caligula_draw_swirly_box (cr, x, y, width, height);
+ break;
+ default:
+ caligula_draw_grassy_box (cr, x, y, width, height);
+ break;
+ }
caligula_end_paint (cr);
}
More information about the cairo-commit
mailing list