2008-12-02 23:15:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
2012-02-08 19:11:42 +04:00
|
|
|
* Copyright © 2012 Intel Corporation
|
2008-12-02 23:15:01 +03:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2012-02-08 21:46:57 +04:00
|
|
|
#include "../config.h"
|
|
|
|
|
2008-11-09 06:46:30 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
#include "cairo-util.h"
|
|
|
|
|
2012-03-12 09:05:25 +04:00
|
|
|
#include "../shared/config-parser.h"
|
2012-02-08 21:46:57 +04:00
|
|
|
|
2008-11-18 06:23:55 +03:00
|
|
|
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
|
|
|
|
|
2011-10-07 11:08:56 +04:00
|
|
|
void
|
|
|
|
surface_flush_device(cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
cairo_device_t *device;
|
|
|
|
|
|
|
|
device = cairo_surface_get_device(surface);
|
|
|
|
if (device)
|
|
|
|
cairo_device_flush(device);
|
|
|
|
}
|
|
|
|
|
2008-11-09 06:46:30 +03:00
|
|
|
void
|
2008-11-09 07:27:27 +03:00
|
|
|
blur_surface(cairo_surface_t *surface, int margin)
|
2008-11-09 06:46:30 +03:00
|
|
|
{
|
|
|
|
int32_t width, height, stride, x, y, z, w;
|
|
|
|
uint8_t *src, *dst;
|
|
|
|
uint32_t *s, *d, a, p;
|
2008-11-18 06:23:55 +03:00
|
|
|
int i, j, k, size, half;
|
2012-03-21 09:07:49 +04:00
|
|
|
uint32_t kernel[71];
|
2008-11-09 06:46:30 +03:00
|
|
|
double f;
|
|
|
|
|
2008-11-18 06:23:55 +03:00
|
|
|
size = ARRAY_LENGTH(kernel);
|
2008-11-09 06:46:30 +03:00
|
|
|
width = cairo_image_surface_get_width(surface);
|
|
|
|
height = cairo_image_surface_get_height(surface);
|
|
|
|
stride = cairo_image_surface_get_stride(surface);
|
|
|
|
src = cairo_image_surface_get_data(surface);
|
|
|
|
|
2009-09-12 23:58:48 +04:00
|
|
|
dst = malloc(height * stride);
|
2008-11-09 06:46:30 +03:00
|
|
|
|
|
|
|
half = size / 2;
|
2011-01-22 06:19:40 +03:00
|
|
|
a = 0;
|
2008-11-09 06:46:30 +03:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
f = (i - half);
|
2010-06-16 00:18:58 +04:00
|
|
|
kernel[i] = exp(- f * f / ARRAY_LENGTH(kernel)) * 10000;
|
2011-01-22 06:19:40 +03:00
|
|
|
a += kernel[i];
|
2008-11-09 06:46:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
s = (uint32_t *) (src + i * stride);
|
|
|
|
d = (uint32_t *) (dst + i * stride);
|
|
|
|
for (j = 0; j < width; j++) {
|
2008-11-18 06:23:55 +03:00
|
|
|
if (margin < j && j < width - margin) {
|
|
|
|
d[j] = s[j];
|
2008-11-09 07:27:27 +03:00
|
|
|
continue;
|
2008-11-18 06:23:55 +03:00
|
|
|
}
|
|
|
|
|
2008-11-09 06:46:30 +03:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
z = 0;
|
|
|
|
w = 0;
|
|
|
|
for (k = 0; k < size; k++) {
|
|
|
|
if (j - half + k < 0 || j - half + k >= width)
|
|
|
|
continue;
|
|
|
|
p = s[j - half + k];
|
|
|
|
|
|
|
|
x += (p >> 24) * kernel[k];
|
|
|
|
y += ((p >> 16) & 0xff) * kernel[k];
|
|
|
|
z += ((p >> 8) & 0xff) * kernel[k];
|
|
|
|
w += (p & 0xff) * kernel[k];
|
|
|
|
}
|
|
|
|
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
s = (uint32_t *) (dst + i * stride);
|
|
|
|
d = (uint32_t *) (src + i * stride);
|
|
|
|
for (j = 0; j < width; j++) {
|
2008-11-18 06:23:55 +03:00
|
|
|
if (margin <= i && i < height - margin) {
|
|
|
|
d[j] = s[j];
|
2008-11-09 07:27:27 +03:00
|
|
|
continue;
|
2008-11-18 06:23:55 +03:00
|
|
|
}
|
|
|
|
|
2008-11-09 06:46:30 +03:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
z = 0;
|
|
|
|
w = 0;
|
|
|
|
for (k = 0; k < size; k++) {
|
|
|
|
if (i - half + k < 0 || i - half + k >= height)
|
|
|
|
continue;
|
|
|
|
s = (uint32_t *) (dst + (i - half + k) * stride);
|
|
|
|
p = s[j];
|
|
|
|
|
|
|
|
x += (p >> 24) * kernel[k];
|
|
|
|
y += ((p >> 16) & 0xff) * kernel[k];
|
|
|
|
z += ((p >> 8) & 0xff) * kernel[k];
|
|
|
|
w += (p & 0xff) * kernel[k];
|
|
|
|
}
|
|
|
|
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-12 23:58:48 +04:00
|
|
|
free(dst);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_surface_mark_dirty(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_mask(cairo_t *cr, cairo_surface_t *surface,
|
2010-08-18 23:28:04 +04:00
|
|
|
int x, int y, int width, int height, int margin, int top_margin)
|
2010-06-16 01:16:35 +04:00
|
|
|
{
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_matrix_t matrix;
|
2010-08-18 23:28:04 +04:00
|
|
|
int i, fx, fy, vmargin;
|
2010-06-16 01:16:35 +04:00
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
2012-04-03 18:53:15 +04:00
|
|
|
cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);
|
2010-06-16 01:16:35 +04:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
fx = i & 1;
|
|
|
|
fy = i >> 1;
|
|
|
|
|
|
|
|
cairo_matrix_init_translate(&matrix,
|
|
|
|
-x + fx * (128 - width),
|
|
|
|
-y + fy * (128 - height));
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
|
2010-08-18 23:28:04 +04:00
|
|
|
if (fy)
|
|
|
|
vmargin = margin;
|
|
|
|
else
|
|
|
|
vmargin = top_margin;
|
|
|
|
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_reset_clip(cr);
|
|
|
|
cairo_rectangle(cr,
|
|
|
|
x + fx * (width - margin),
|
2010-08-18 23:28:04 +04:00
|
|
|
y + fy * (height - vmargin),
|
|
|
|
margin, vmargin);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_mask(cr, pattern);
|
|
|
|
}
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Top stretch */
|
2012-03-21 20:37:04 +04:00
|
|
|
cairo_matrix_init_translate(&matrix, 60, 0);
|
|
|
|
cairo_matrix_scale(&matrix, 8.0 / width, 1);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -x - width / 2, -y);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
cairo_rectangle(cr, x + margin, y, width - 2 * margin, margin);
|
|
|
|
|
|
|
|
cairo_reset_clip(cr);
|
|
|
|
cairo_rectangle(cr,
|
|
|
|
x + margin,
|
|
|
|
y,
|
|
|
|
width - 2 * margin, margin);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_mask(cr, pattern);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Bottom stretch */
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, 0, -height + 128);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
|
|
|
|
cairo_reset_clip(cr);
|
|
|
|
cairo_rectangle(cr, x + margin, y + height - margin,
|
|
|
|
width - 2 * margin, margin);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_mask(cr, pattern);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Left stretch */
|
2012-03-21 20:37:04 +04:00
|
|
|
cairo_matrix_init_translate(&matrix, 0, 60);
|
|
|
|
cairo_matrix_scale(&matrix, 1, 8.0 / height);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -x, -y - height / 2);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
cairo_reset_clip(cr);
|
|
|
|
cairo_rectangle(cr, x, y + margin, margin, height - 2 * margin);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_mask(cr, pattern);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Right stretch */
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -width + 128, 0);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
cairo_rectangle(cr, x + width - margin, y + margin,
|
|
|
|
margin, height - 2 * margin);
|
|
|
|
cairo_reset_clip(cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_mask(cr, pattern);
|
|
|
|
|
|
|
|
cairo_pattern_destroy(pattern);
|
|
|
|
cairo_reset_clip(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_source(cairo_t *cr, cairo_surface_t *surface,
|
2010-08-18 23:28:04 +04:00
|
|
|
int x, int y, int width, int height, int margin, int top_margin)
|
2010-06-16 01:16:35 +04:00
|
|
|
{
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
cairo_matrix_t matrix;
|
2010-08-18 23:28:04 +04:00
|
|
|
int i, fx, fy, vmargin;
|
2010-06-16 01:16:35 +04:00
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
pattern = cairo_pattern_create_for_surface (surface);
|
2012-04-03 18:53:15 +04:00
|
|
|
cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_set_source(cr, pattern);
|
|
|
|
cairo_pattern_destroy(pattern);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
fx = i & 1;
|
|
|
|
fy = i >> 1;
|
|
|
|
|
|
|
|
cairo_matrix_init_translate(&matrix,
|
|
|
|
-x + fx * (128 - width),
|
|
|
|
-y + fy * (128 - height));
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
|
2010-08-18 23:28:04 +04:00
|
|
|
if (fy)
|
|
|
|
vmargin = margin;
|
|
|
|
else
|
|
|
|
vmargin = top_margin;
|
|
|
|
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_rectangle(cr,
|
|
|
|
x + fx * (width - margin),
|
2010-08-18 23:28:04 +04:00
|
|
|
y + fy * (height - vmargin),
|
|
|
|
margin, vmargin);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_fill(cr);
|
|
|
|
}
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Top stretch */
|
2012-03-21 20:37:04 +04:00
|
|
|
cairo_matrix_init_translate(&matrix, 60, 0);
|
|
|
|
cairo_matrix_scale(&matrix, 8.0 / (width - 2 * margin), 1);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -x - width / 2, -y);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
2010-08-18 23:28:04 +04:00
|
|
|
cairo_rectangle(cr, x + margin, y, width - 2 * margin, top_margin);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Bottom stretch */
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, 0, -height + 128);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
|
|
|
cairo_rectangle(cr, x + margin, y + height - margin,
|
|
|
|
width - 2 * margin, margin);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Left stretch */
|
2012-03-21 20:37:04 +04:00
|
|
|
cairo_matrix_init_translate(&matrix, 0, 60);
|
|
|
|
cairo_matrix_scale(&matrix, 1, 8.0 / (height - margin - top_margin));
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -x, -y - height / 2);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
2010-08-18 23:28:04 +04:00
|
|
|
cairo_rectangle(cr, x, y + top_margin,
|
|
|
|
margin, height - margin - top_margin);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
2012-02-09 21:06:56 +04:00
|
|
|
/* Right stretch */
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_matrix_translate(&matrix, -width + 128, 0);
|
|
|
|
cairo_pattern_set_matrix(pattern, &matrix);
|
2010-08-18 23:28:04 +04:00
|
|
|
cairo_rectangle(cr, x + width - margin, y + top_margin,
|
|
|
|
margin, height - margin - top_margin);
|
2010-06-16 01:16:35 +04:00
|
|
|
cairo_fill(cr);
|
2008-11-09 06:46:30 +03:00
|
|
|
}
|
2011-09-13 22:47:46 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
|
|
|
|
{
|
|
|
|
cairo_move_to(cr, x0, y0 + radius);
|
|
|
|
cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
|
|
|
|
cairo_line_to(cr, x1 - radius, y0);
|
|
|
|
cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
|
|
|
|
cairo_line_to(cr, x1, y1 - radius);
|
|
|
|
cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
|
|
|
|
cairo_line_to(cr, x0 + radius, y1);
|
|
|
|
cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
|
|
|
|
cairo_close_path(cr);
|
|
|
|
}
|
2011-10-20 21:11:12 +04:00
|
|
|
|
2012-01-26 00:43:48 +04:00
|
|
|
cairo_surface_t *
|
2012-03-12 09:05:25 +04:00
|
|
|
load_cairo_surface(const char *filename)
|
2012-01-26 00:43:48 +04:00
|
|
|
{
|
2012-03-12 09:05:25 +04:00
|
|
|
pixman_image_t *image;
|
|
|
|
int width, height, stride;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
image = load_image(filename);
|
2012-03-15 00:07:58 +04:00
|
|
|
if (image == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-12 09:05:25 +04:00
|
|
|
data = pixman_image_get_data(image);
|
|
|
|
width = pixman_image_get_width(image);
|
|
|
|
height = pixman_image_get_height(image);
|
|
|
|
stride = pixman_image_get_stride(image);
|
|
|
|
|
|
|
|
return cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height, stride);
|
2012-01-26 00:43:48 +04:00
|
|
|
}
|
2012-05-16 06:14:27 +04:00
|
|
|
|
2012-05-16 06:25:28 +04:00
|
|
|
struct theme *
|
|
|
|
theme_create(void)
|
2012-05-16 06:14:27 +04:00
|
|
|
{
|
2012-05-16 06:25:28 +04:00
|
|
|
struct theme *t;
|
2012-05-16 06:14:27 +04:00
|
|
|
cairo_t *cr;
|
|
|
|
cairo_pattern_t *pattern;
|
|
|
|
|
2012-05-16 06:25:28 +04:00
|
|
|
t = malloc(sizeof *t);
|
2012-05-16 06:14:27 +04:00
|
|
|
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);
|
2012-05-16 06:25:28 +04:00
|
|
|
|
|
|
|
return t;
|
2012-05-16 06:14:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-16 06:25:28 +04:00
|
|
|
theme_destroy(struct theme *t)
|
2012-05-16 06:14:27 +04:00
|
|
|
{
|
|
|
|
cairo_surface_destroy(t->active_frame);
|
|
|
|
cairo_surface_destroy(t->inactive_frame);
|
|
|
|
cairo_surface_destroy(t->shadow);
|
2012-05-16 06:25:28 +04:00
|
|
|
free(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
theme_render_frame(struct theme *t,
|
|
|
|
cairo_t *cr, int width, int height,
|
|
|
|
const char *title, uint32_t flags)
|
|
|
|
{
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
cairo_font_extents_t font_extents;
|
|
|
|
cairo_surface_t *source;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.45);
|
|
|
|
tile_mask(cr, t->shadow,
|
|
|
|
2, 2, width + 8, height + 8,
|
|
|
|
64, 64);
|
|
|
|
|
|
|
|
if (flags & THEME_FRAME_ACTIVE)
|
|
|
|
source = t->active_frame;
|
|
|
|
else
|
|
|
|
source = t->inactive_frame;
|
|
|
|
|
|
|
|
tile_source(cr, source,
|
|
|
|
t->margin, t->margin,
|
|
|
|
width - t->margin * 2, height - t->margin * 2,
|
|
|
|
t->width, t->titlebar_height);
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_select_font_face(cr, "sans",
|
|
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
|
|
CAIRO_FONT_WEIGHT_BOLD);
|
|
|
|
cairo_set_font_size(cr, 14);
|
|
|
|
cairo_text_extents(cr, title, &extents);
|
|
|
|
cairo_font_extents (cr, &font_extents);
|
|
|
|
x = (width - extents.width) / 2;
|
|
|
|
y = t->margin +
|
|
|
|
(t->titlebar_height -
|
|
|
|
font_extents.ascent - font_extents.descent) / 2 +
|
|
|
|
font_extents.ascent;
|
|
|
|
|
|
|
|
if (flags & THEME_FRAME_ACTIVE) {
|
|
|
|
cairo_move_to(cr, x + 1, y + 1);
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
cairo_show_text(cr, title);
|
|
|
|
cairo_move_to(cr, x, y);
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
cairo_show_text(cr, title);
|
|
|
|
} else {
|
|
|
|
cairo_move_to(cr, x, y);
|
|
|
|
cairo_set_source_rgb(cr, 0.4, 0.4, 0.4);
|
|
|
|
cairo_show_text(cr, title);
|
|
|
|
}
|
2012-05-16 06:14:27 +04:00
|
|
|
}
|
2012-05-23 00:38:53 +04:00
|
|
|
|
|
|
|
enum theme_location
|
|
|
|
theme_get_location(struct theme *t, int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
int vlocation, hlocation, location;
|
|
|
|
const int grip_size = 8;
|
|
|
|
|
|
|
|
if (x < t->margin)
|
|
|
|
hlocation = THEME_LOCATION_EXTERIOR;
|
|
|
|
else if (t->margin <= x && x < t->margin + grip_size)
|
|
|
|
hlocation = THEME_LOCATION_RESIZING_LEFT;
|
|
|
|
else if (x < width - t->margin - grip_size)
|
|
|
|
hlocation = THEME_LOCATION_INTERIOR;
|
|
|
|
else if (x < width - t->margin)
|
|
|
|
hlocation = THEME_LOCATION_RESIZING_RIGHT;
|
|
|
|
else
|
|
|
|
hlocation = THEME_LOCATION_EXTERIOR;
|
|
|
|
|
|
|
|
if (y < t->margin)
|
|
|
|
vlocation = THEME_LOCATION_EXTERIOR;
|
|
|
|
else if (t->margin <= y && y < t->margin + grip_size)
|
|
|
|
vlocation = THEME_LOCATION_RESIZING_TOP;
|
|
|
|
else if (y < height - t->margin - grip_size)
|
|
|
|
vlocation = THEME_LOCATION_INTERIOR;
|
|
|
|
else if (y < height - t->margin)
|
|
|
|
vlocation = THEME_LOCATION_RESIZING_BOTTOM;
|
|
|
|
else
|
|
|
|
vlocation = THEME_LOCATION_EXTERIOR;
|
|
|
|
|
|
|
|
location = vlocation | hlocation;
|
|
|
|
if (location & THEME_LOCATION_EXTERIOR)
|
|
|
|
location = THEME_LOCATION_EXTERIOR;
|
|
|
|
if (location == THEME_LOCATION_INTERIOR &&
|
|
|
|
y < t->margin + t->titlebar_height)
|
|
|
|
location = THEME_LOCATION_TITLEBAR;
|
|
|
|
else if (location == THEME_LOCATION_INTERIOR)
|
|
|
|
location = THEME_LOCATION_CLIENT_AREA;
|
|
|
|
|
|
|
|
return location;
|
|
|
|
}
|