blob: d679bcbd5525d044ee13ccda04d7904322c34c69 [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050023#ifndef _CAIRO_UTIL_H
24#define _CAIRO_UTIL_H
25
Jason Ekstrand01c9ec32013-10-13 19:08:39 -050026#include <stdint.h>
Pekka Paalanen4fbb6532012-11-30 13:37:28 +020027#include <cairo.h>
Kristian Høgsberg6006ecb2012-11-29 12:23:36 -050028
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050029void
Benjamin Franzke47eb8f42011-10-07 09:08:56 +020030surface_flush_device(cairo_surface_t *surface);
31
32void
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040033tile_mask(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -040034 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040035
36void
37tile_source(cairo_t *cr, cairo_surface_t *surface,
Kristian Høgsberg9a686242010-08-18 15:28:04 -040038 int x, int y, int width, int height, int margin, int top_margin);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040039
Kristian Høgsberg1e164b92011-09-13 14:47:46 -040040void
41rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius);
42
Kristian Høgsberg27d38662011-10-20 13:11:12 -040043cairo_surface_t *
Kristian Høgsbergf02a6492012-03-12 01:05:25 -040044load_cairo_surface(const char *filename);
Kristian Høgsberg27d38662011-10-20 13:11:12 -040045
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040046struct theme {
47 cairo_surface_t *active_frame;
48 cairo_surface_t *inactive_frame;
49 cairo_surface_t *shadow;
50 int frame_radius;
51 int margin;
52 int width;
53 int titlebar_height;
54};
55
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040056struct theme *
57theme_create(void);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040058void
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040059theme_destroy(struct theme *t);
60
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060061enum {
62 THEME_FRAME_ACTIVE = 1,
63 THEME_FRAME_MAXIMIZED,
64};
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040065
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040066void
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040067theme_render_frame(struct theme *t,
68 cairo_t *cr, int width, int height,
69 const char *title, uint32_t flags);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040070
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040071enum theme_location {
72 THEME_LOCATION_INTERIOR = 0,
73 THEME_LOCATION_RESIZING_TOP = 1,
74 THEME_LOCATION_RESIZING_BOTTOM = 2,
75 THEME_LOCATION_RESIZING_LEFT = 4,
76 THEME_LOCATION_RESIZING_TOP_LEFT = 5,
77 THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6,
78 THEME_LOCATION_RESIZING_RIGHT = 8,
79 THEME_LOCATION_RESIZING_TOP_RIGHT = 9,
80 THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10,
81 THEME_LOCATION_RESIZING_MASK = 15,
82 THEME_LOCATION_EXTERIOR = 16,
83 THEME_LOCATION_TITLEBAR = 17,
84 THEME_LOCATION_CLIENT_AREA = 18,
85};
86
87enum theme_location
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060088theme_get_location(struct theme *t, int x, int y, int width, int height, int flags);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040089
Jason Ekstrand01c9ec32013-10-13 19:08:39 -050090struct frame;
91
92enum frame_status {
93 FRAME_STATUS_NONE = 0,
94 FRAME_STATUS_REPAINT = 0x1,
95 FRAME_STATUS_MINIMIZE = 0x2,
96 FRAME_STATUS_MAXIMIZE = 0x4,
97 FRAME_STATUS_CLOSE = 0x8,
98 FRAME_STATUS_MENU = 0x10,
99 FRAME_STATUS_RESIZE = 0x20,
100 FRAME_STATUS_MOVE = 0x40,
101 FRAME_STATUS_ALL = 0x7f
102};
103
104enum frame_flag {
105 FRAME_FLAG_ACTIVE = 0x1,
106 FRAME_FLAG_MAXIMIZED = 0x2
107};
108
109enum {
110 FRAME_BUTTON_NONE = 0,
111 FRAME_BUTTON_CLOSE = 0x1,
112 FRAME_BUTTON_MAXIMIZE = 0x2,
113 FRAME_BUTTON_MINIMIZE = 0x4,
114 FRAME_BUTTON_ALL = 0x7
115};
116
117enum frame_button_state {
118 FRAME_BUTTON_RELEASED = 0,
119 FRAME_BUTTON_PRESSED = 1
120};
121
122struct frame *
123frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
124 const char *title);
125
126void
127frame_destroy(struct frame *frame);
128
129/* May set FRAME_STATUS_REPAINT */
130int
131frame_set_title(struct frame *frame, const char *title);
132
133/* May set FRAME_STATUS_REPAINT */
134void
135frame_set_flag(struct frame *frame, enum frame_flag flag);
136
137/* May set FRAME_STATUS_REPAINT */
138void
139frame_unset_flag(struct frame *frame, enum frame_flag flag);
140
141/* May set FRAME_STATUS_REPAINT */
142void
143frame_resize(struct frame *frame, int32_t width, int32_t height);
144
145/* May set FRAME_STATUS_REPAINT */
146void
147frame_resize_inside(struct frame *frame, int32_t width, int32_t height);
148
149int32_t
150frame_width(struct frame *frame);
151
152int32_t
153frame_height(struct frame *frame);
154
155void
156frame_interior(struct frame *frame, int32_t *x, int32_t *y,
157 int32_t *width, int32_t *height);
158void
159frame_input_rect(struct frame *frame, int32_t *x, int32_t *y,
160 int32_t *width, int32_t *height);
161void
162frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
163 int32_t *width, int32_t *height);
164
165uint32_t
166frame_status(struct frame *frame);
167
168void
169frame_status_clear(struct frame *frame, enum frame_status status);
170
171/* May set FRAME_STATUS_REPAINT */
172enum theme_location
173frame_pointer_enter(struct frame *frame, void *pointer, int x, int y);
174
175/* May set FRAME_STATUS_REPAINT */
176enum theme_location
177frame_pointer_motion(struct frame *frame, void *pointer, int x, int y);
178
179/* May set FRAME_STATUS_REPAINT */
180void
181frame_pointer_leave(struct frame *frame, void *pointer);
182
183/* May set:
184 * FRAME_STATUS_MINIMIZE
185 * FRAME_STATUS_MAXIMIZE
186 * FRAME_STATUS_CLOSE
187 * FRAME_STATUS_MENU
188 * FRAME_STATUS_RESIZE
189 * FRAME_STATUS_MOVE
190 */
191enum theme_location
192frame_pointer_button(struct frame *frame, void *pointer,
193 uint32_t button, enum frame_button_state state);
194
Jason Ekstrand3f66cf92013-10-13 19:08:40 -0500195void
196frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y);
197
198void
199frame_touch_up(struct frame *frame, void *data, int32_t id);
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500200
201void
202frame_repaint(struct frame *frame, cairo_t *cr);
203
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500204#endif