window: Move theme rendering code to cairo-util

Kristian Høgsberg 13 years ago
parent 291c69cf93
commit 42abdf5c80
  1. 52
      clients/cairo-util.c
  2. 15
      clients/cairo-util.h
  3. 62
      clients/window.c

@ -314,3 +314,55 @@ load_cairo_surface(const char *filename)
return cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
width, height, stride);
}
void
display_render_theme(struct theme *t)
{
cairo_t *cr;
cairo_pattern_t *pattern;
t->margin = 32;
t->width = 6;
t->titlebar_height = 27;
t->frame_radius = 3;
t->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->shadow);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 0, 0, 0, 1);
rounded_rect(cr, 32, 32, 96, 96, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
blur_surface(t->shadow, 64);
t->active_frame =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->active_frame);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
pattern = cairo_pattern_create_linear(16, 16, 16, 112);
cairo_pattern_add_color_stop_rgb(pattern, 0.0, 1.0, 1.0, 1.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.2, 0.8, 0.8, 0.8);
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
rounded_rect(cr, 0, 0, 128, 128, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
t->inactive_frame =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->inactive_frame);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 0.75, 0.75, 0.75, 1);
rounded_rect(cr, 0, 0, 128, 128, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
}
void
fini_theme(struct theme *t)
{
cairo_surface_destroy(t->active_frame);
cairo_surface_destroy(t->inactive_frame);
cairo_surface_destroy(t->shadow);
}

@ -43,4 +43,19 @@ rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius);
cairo_surface_t *
load_cairo_surface(const char *filename);
struct theme {
cairo_surface_t *active_frame;
cairo_surface_t *inactive_frame;
cairo_surface_t *shadow;
int frame_radius;
int margin;
int width;
int titlebar_height;
};
void
display_render_theme(struct theme *t);
void
fini_theme(struct theme *t);
#endif

@ -66,16 +66,6 @@
struct cursor;
struct shm_pool;
struct theme {
cairo_surface_t *active_frame;
cairo_surface_t *inactive_frame;
cairo_surface_t *shadow;
int frame_radius;
int margin;
int width;
int titlebar_height;
};
struct display {
struct wl_display *display;
struct wl_compositor *compositor;
@ -3130,58 +3120,6 @@ display_handle_global(struct wl_display *display, uint32_t id,
}
}
static void
display_render_theme(struct theme *t)
{
cairo_t *cr;
cairo_pattern_t *pattern;
t->margin = 32;
t->width = 6;
t->titlebar_height = 27;
t->frame_radius = 3;
t->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->shadow);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 0, 0, 0, 1);
rounded_rect(cr, 32, 32, 96, 96, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
blur_surface(t->shadow, 64);
t->active_frame =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->active_frame);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
pattern = cairo_pattern_create_linear(16, 16, 16, 112);
cairo_pattern_add_color_stop_rgb(pattern, 0.0, 1.0, 1.0, 1.0);
cairo_pattern_add_color_stop_rgb(pattern, 0.2, 0.8, 0.8, 0.8);
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
rounded_rect(cr, 0, 0, 128, 128, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
t->inactive_frame =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->inactive_frame);
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgba(cr, 0.75, 0.75, 0.75, 1);
rounded_rect(cr, 0, 0, 128, 128, t->frame_radius);
cairo_fill(cr);
cairo_destroy(cr);
}
static void
fini_theme(struct theme *t)
{
cairo_surface_destroy(t->active_frame);
cairo_surface_destroy(t->inactive_frame);
cairo_surface_destroy(t->shadow);
}
static void
init_xkb(struct display *d)
{

Loading…
Cancel
Save