blob: a8eb8741b8ee86f94e6dcb519e8c926b54a60c73 [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øgsbergc680e902013-10-23 21:49:30 -070067theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags);
68void
Kristian Høgsberg5adb4802012-05-15 22:25:28 -040069theme_render_frame(struct theme *t,
70 cairo_t *cr, int width, int height,
71 const char *title, uint32_t flags);
Kristian Høgsberg42abdf52012-05-15 22:14:27 -040072
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040073enum theme_location {
74 THEME_LOCATION_INTERIOR = 0,
75 THEME_LOCATION_RESIZING_TOP = 1,
76 THEME_LOCATION_RESIZING_BOTTOM = 2,
77 THEME_LOCATION_RESIZING_LEFT = 4,
78 THEME_LOCATION_RESIZING_TOP_LEFT = 5,
79 THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6,
80 THEME_LOCATION_RESIZING_RIGHT = 8,
81 THEME_LOCATION_RESIZING_TOP_RIGHT = 9,
82 THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10,
83 THEME_LOCATION_RESIZING_MASK = 15,
84 THEME_LOCATION_EXTERIOR = 16,
85 THEME_LOCATION_TITLEBAR = 17,
86 THEME_LOCATION_CLIENT_AREA = 18,
87};
88
89enum theme_location
Scott Moreauc6a7e4b2012-09-28 02:45:06 -060090theme_get_location(struct theme *t, int x, int y, int width, int height, int flags);
Kristian Høgsbergf96e6c02012-05-22 16:38:53 -040091
Jason Ekstrand01c9ec32013-10-13 19:08:39 -050092struct frame;
93
94enum frame_status {
95 FRAME_STATUS_NONE = 0,
96 FRAME_STATUS_REPAINT = 0x1,
97 FRAME_STATUS_MINIMIZE = 0x2,
98 FRAME_STATUS_MAXIMIZE = 0x4,
99 FRAME_STATUS_CLOSE = 0x8,
100 FRAME_STATUS_MENU = 0x10,
101 FRAME_STATUS_RESIZE = 0x20,
102 FRAME_STATUS_MOVE = 0x40,
103 FRAME_STATUS_ALL = 0x7f
104};
105
106enum frame_flag {
107 FRAME_FLAG_ACTIVE = 0x1,
108 FRAME_FLAG_MAXIMIZED = 0x2
109};
110
111enum {
112 FRAME_BUTTON_NONE = 0,
113 FRAME_BUTTON_CLOSE = 0x1,
114 FRAME_BUTTON_MAXIMIZE = 0x2,
115 FRAME_BUTTON_MINIMIZE = 0x4,
116 FRAME_BUTTON_ALL = 0x7
117};
118
119enum frame_button_state {
120 FRAME_BUTTON_RELEASED = 0,
121 FRAME_BUTTON_PRESSED = 1
122};
123
124struct frame *
125frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
126 const char *title);
127
128void
129frame_destroy(struct frame *frame);
130
131/* May set FRAME_STATUS_REPAINT */
132int
133frame_set_title(struct frame *frame, const char *title);
134
135/* May set FRAME_STATUS_REPAINT */
136void
137frame_set_flag(struct frame *frame, enum frame_flag flag);
138
139/* May set FRAME_STATUS_REPAINT */
140void
141frame_unset_flag(struct frame *frame, enum frame_flag flag);
142
143/* May set FRAME_STATUS_REPAINT */
144void
145frame_resize(struct frame *frame, int32_t width, int32_t height);
146
147/* May set FRAME_STATUS_REPAINT */
148void
149frame_resize_inside(struct frame *frame, int32_t width, int32_t height);
150
151int32_t
152frame_width(struct frame *frame);
153
154int32_t
155frame_height(struct frame *frame);
156
157void
158frame_interior(struct frame *frame, int32_t *x, int32_t *y,
159 int32_t *width, int32_t *height);
160void
161frame_input_rect(struct frame *frame, int32_t *x, int32_t *y,
162 int32_t *width, int32_t *height);
163void
164frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y,
165 int32_t *width, int32_t *height);
166
167uint32_t
168frame_status(struct frame *frame);
169
170void
171frame_status_clear(struct frame *frame, enum frame_status status);
172
173/* May set FRAME_STATUS_REPAINT */
174enum theme_location
175frame_pointer_enter(struct frame *frame, void *pointer, int x, int y);
176
177/* May set FRAME_STATUS_REPAINT */
178enum theme_location
179frame_pointer_motion(struct frame *frame, void *pointer, int x, int y);
180
181/* May set FRAME_STATUS_REPAINT */
182void
183frame_pointer_leave(struct frame *frame, void *pointer);
184
185/* May set:
186 * FRAME_STATUS_MINIMIZE
187 * FRAME_STATUS_MAXIMIZE
188 * FRAME_STATUS_CLOSE
189 * FRAME_STATUS_MENU
190 * FRAME_STATUS_RESIZE
191 * FRAME_STATUS_MOVE
192 */
193enum theme_location
194frame_pointer_button(struct frame *frame, void *pointer,
195 uint32_t button, enum frame_button_state state);
196
Jason Ekstrand3f66cf92013-10-13 19:08:40 -0500197void
198frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y);
199
200void
201frame_touch_up(struct frame *frame, void *data, int32_t id);
Jason Ekstrand01c9ec32013-10-13 19:08:39 -0500202
203void
204frame_repaint(struct frame *frame, cairo_t *cr);
205
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500206#endif