Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
| 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øgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 23 | #ifndef _CAIRO_UTIL_H |
| 24 | #define _CAIRO_UTIL_H |
| 25 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 26 | #include <stdint.h> |
Pekka Paalanen | 4fbb653 | 2012-11-30 13:37:28 +0200 | [diff] [blame] | 27 | #include <cairo.h> |
Kristian Høgsberg | 6006ecb | 2012-11-29 12:23:36 -0500 | [diff] [blame] | 28 | |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 29 | void |
Benjamin Franzke | 47eb8f4 | 2011-10-07 09:08:56 +0200 | [diff] [blame] | 30 | surface_flush_device(cairo_surface_t *surface); |
| 31 | |
| 32 | void |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 33 | tile_mask(cairo_t *cr, cairo_surface_t *surface, |
Kristian Høgsberg | 9a68624 | 2010-08-18 15:28:04 -0400 | [diff] [blame] | 34 | int x, int y, int width, int height, int margin, int top_margin); |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 35 | |
| 36 | void |
| 37 | tile_source(cairo_t *cr, cairo_surface_t *surface, |
Kristian Høgsberg | 9a68624 | 2010-08-18 15:28:04 -0400 | [diff] [blame] | 38 | int x, int y, int width, int height, int margin, int top_margin); |
Kristian Høgsberg | dcb71b6 | 2010-06-15 17:16:35 -0400 | [diff] [blame] | 39 | |
Kristian Høgsberg | 1e164b9 | 2011-09-13 14:47:46 -0400 | [diff] [blame] | 40 | void |
| 41 | rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius); |
| 42 | |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 43 | cairo_surface_t * |
Kristian Høgsberg | f02a649 | 2012-03-12 01:05:25 -0400 | [diff] [blame] | 44 | load_cairo_surface(const char *filename); |
Kristian Høgsberg | 27d3866 | 2011-10-20 13:11:12 -0400 | [diff] [blame] | 45 | |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 46 | struct 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øgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 56 | struct theme * |
| 57 | theme_create(void); |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 58 | void |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 59 | theme_destroy(struct theme *t); |
| 60 | |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 61 | enum { |
| 62 | THEME_FRAME_ACTIVE = 1, |
Kristian Høgsberg | 89f4bc4 | 2013-10-23 22:12:13 -0700 | [diff] [blame] | 63 | THEME_FRAME_MAXIMIZED = 2, |
| 64 | THEME_FRAME_NO_TITLE = 4 |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 65 | }; |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 66 | |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 67 | void |
Kristian Høgsberg | c680e90 | 2013-10-23 21:49:30 -0700 | [diff] [blame] | 68 | theme_set_background_source(struct theme *t, cairo_t *cr, uint32_t flags); |
| 69 | void |
Kristian Høgsberg | 5adb480 | 2012-05-15 22:25:28 -0400 | [diff] [blame] | 70 | theme_render_frame(struct theme *t, |
| 71 | cairo_t *cr, int width, int height, |
| 72 | const char *title, uint32_t flags); |
Kristian Høgsberg | 42abdf5 | 2012-05-15 22:14:27 -0400 | [diff] [blame] | 73 | |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 74 | enum theme_location { |
| 75 | THEME_LOCATION_INTERIOR = 0, |
| 76 | THEME_LOCATION_RESIZING_TOP = 1, |
| 77 | THEME_LOCATION_RESIZING_BOTTOM = 2, |
| 78 | THEME_LOCATION_RESIZING_LEFT = 4, |
| 79 | THEME_LOCATION_RESIZING_TOP_LEFT = 5, |
| 80 | THEME_LOCATION_RESIZING_BOTTOM_LEFT = 6, |
| 81 | THEME_LOCATION_RESIZING_RIGHT = 8, |
| 82 | THEME_LOCATION_RESIZING_TOP_RIGHT = 9, |
| 83 | THEME_LOCATION_RESIZING_BOTTOM_RIGHT = 10, |
| 84 | THEME_LOCATION_RESIZING_MASK = 15, |
| 85 | THEME_LOCATION_EXTERIOR = 16, |
| 86 | THEME_LOCATION_TITLEBAR = 17, |
| 87 | THEME_LOCATION_CLIENT_AREA = 18, |
| 88 | }; |
| 89 | |
| 90 | enum theme_location |
Scott Moreau | c6a7e4b | 2012-09-28 02:45:06 -0600 | [diff] [blame] | 91 | theme_get_location(struct theme *t, int x, int y, int width, int height, int flags); |
Kristian Høgsberg | f96e6c0 | 2012-05-22 16:38:53 -0400 | [diff] [blame] | 92 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 93 | struct frame; |
| 94 | |
| 95 | enum frame_status { |
| 96 | FRAME_STATUS_NONE = 0, |
| 97 | FRAME_STATUS_REPAINT = 0x1, |
| 98 | FRAME_STATUS_MINIMIZE = 0x2, |
| 99 | FRAME_STATUS_MAXIMIZE = 0x4, |
| 100 | FRAME_STATUS_CLOSE = 0x8, |
| 101 | FRAME_STATUS_MENU = 0x10, |
| 102 | FRAME_STATUS_RESIZE = 0x20, |
| 103 | FRAME_STATUS_MOVE = 0x40, |
| 104 | FRAME_STATUS_ALL = 0x7f |
| 105 | }; |
| 106 | |
| 107 | enum frame_flag { |
| 108 | FRAME_FLAG_ACTIVE = 0x1, |
| 109 | FRAME_FLAG_MAXIMIZED = 0x2 |
| 110 | }; |
| 111 | |
| 112 | enum { |
| 113 | FRAME_BUTTON_NONE = 0, |
| 114 | FRAME_BUTTON_CLOSE = 0x1, |
| 115 | FRAME_BUTTON_MAXIMIZE = 0x2, |
| 116 | FRAME_BUTTON_MINIMIZE = 0x4, |
| 117 | FRAME_BUTTON_ALL = 0x7 |
| 118 | }; |
| 119 | |
| 120 | enum frame_button_state { |
| 121 | FRAME_BUTTON_RELEASED = 0, |
| 122 | FRAME_BUTTON_PRESSED = 1 |
| 123 | }; |
| 124 | |
| 125 | struct frame * |
| 126 | frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons, |
| 127 | const char *title); |
| 128 | |
| 129 | void |
| 130 | frame_destroy(struct frame *frame); |
| 131 | |
| 132 | /* May set FRAME_STATUS_REPAINT */ |
| 133 | int |
| 134 | frame_set_title(struct frame *frame, const char *title); |
| 135 | |
| 136 | /* May set FRAME_STATUS_REPAINT */ |
| 137 | void |
| 138 | frame_set_flag(struct frame *frame, enum frame_flag flag); |
| 139 | |
| 140 | /* May set FRAME_STATUS_REPAINT */ |
| 141 | void |
| 142 | frame_unset_flag(struct frame *frame, enum frame_flag flag); |
| 143 | |
| 144 | /* May set FRAME_STATUS_REPAINT */ |
| 145 | void |
| 146 | frame_resize(struct frame *frame, int32_t width, int32_t height); |
| 147 | |
| 148 | /* May set FRAME_STATUS_REPAINT */ |
| 149 | void |
| 150 | frame_resize_inside(struct frame *frame, int32_t width, int32_t height); |
| 151 | |
| 152 | int32_t |
| 153 | frame_width(struct frame *frame); |
| 154 | |
| 155 | int32_t |
| 156 | frame_height(struct frame *frame); |
| 157 | |
| 158 | void |
| 159 | frame_interior(struct frame *frame, int32_t *x, int32_t *y, |
| 160 | int32_t *width, int32_t *height); |
| 161 | void |
| 162 | frame_input_rect(struct frame *frame, int32_t *x, int32_t *y, |
| 163 | int32_t *width, int32_t *height); |
| 164 | void |
| 165 | frame_opaque_rect(struct frame *frame, int32_t *x, int32_t *y, |
| 166 | int32_t *width, int32_t *height); |
| 167 | |
Jasper St. Pierre | 7407345 | 2014-02-01 18:36:41 -0500 | [diff] [blame^] | 168 | int |
| 169 | frame_get_shadow_margin(struct frame *frame); |
| 170 | |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 171 | uint32_t |
| 172 | frame_status(struct frame *frame); |
| 173 | |
| 174 | void |
| 175 | frame_status_clear(struct frame *frame, enum frame_status status); |
| 176 | |
| 177 | /* May set FRAME_STATUS_REPAINT */ |
| 178 | enum theme_location |
| 179 | frame_pointer_enter(struct frame *frame, void *pointer, int x, int y); |
| 180 | |
| 181 | /* May set FRAME_STATUS_REPAINT */ |
| 182 | enum theme_location |
| 183 | frame_pointer_motion(struct frame *frame, void *pointer, int x, int y); |
| 184 | |
| 185 | /* May set FRAME_STATUS_REPAINT */ |
| 186 | void |
| 187 | frame_pointer_leave(struct frame *frame, void *pointer); |
| 188 | |
Jason Ekstrand | 0bdd58f | 2013-10-27 22:25:03 -0500 | [diff] [blame] | 189 | /* Call to indicate that a button has been pressed/released. The return |
| 190 | * value for a button release will be the same as for the corresponding |
| 191 | * press. This allows you to more easily track grabs. If you want the |
| 192 | * actual location, simply keep the location from the last |
| 193 | * frame_pointer_motion call. |
| 194 | * |
| 195 | * May set: |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 196 | * FRAME_STATUS_MINIMIZE |
| 197 | * FRAME_STATUS_MAXIMIZE |
| 198 | * FRAME_STATUS_CLOSE |
| 199 | * FRAME_STATUS_MENU |
| 200 | * FRAME_STATUS_RESIZE |
| 201 | * FRAME_STATUS_MOVE |
| 202 | */ |
| 203 | enum theme_location |
| 204 | frame_pointer_button(struct frame *frame, void *pointer, |
| 205 | uint32_t button, enum frame_button_state state); |
| 206 | |
Jason Ekstrand | 3f66cf9 | 2013-10-13 19:08:40 -0500 | [diff] [blame] | 207 | void |
| 208 | frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y); |
| 209 | |
| 210 | void |
| 211 | frame_touch_up(struct frame *frame, void *data, int32_t id); |
Jason Ekstrand | 01c9ec3 | 2013-10-13 19:08:39 -0500 | [diff] [blame] | 212 | |
| 213 | void |
| 214 | frame_repaint(struct frame *frame, cairo_t *cr); |
| 215 | |
Kristian Høgsberg | 2f2cfae | 2008-11-08 22:46:30 -0500 | [diff] [blame] | 216 | #endif |