GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_render.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2023 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
9#ifndef GP_WIDGET_RENDER_H
10#define GP_WIDGET_RENDER_H
11
12#include <core/gp_core.h>
13#include <gfx/gp_gfx.h>
14#include <text/gp_text.h>
15#include <utils/gp_timer.h>
16#include <utils/gp_bbox.h>
17
18#include <widgets/gp_widget_types.h>
19#include <widgets/gp_widgets_color_scheme.h>
20
21struct gp_widget_render_ctx {
22 gp_pixmap *buf;
23
24 enum gp_widgets_color_scheme color_scheme;
25
26 /* colors */
27 union {
28 gp_pixel colors[GP_WIDGETS_THEME_COLORS + 16];
29 struct {
30 gp_pixel text_color;
31 gp_pixel fg_color;
32 gp_pixel bg_color;
33 gp_pixel hl_color;
34 gp_pixel sel_color;
35 gp_pixel alert_color;
36 gp_pixel warn_color;
37 gp_pixel accept_color;
38 gp_pixel fill_color;
39 gp_pixel col_disabled;
40 /* 16 colors */
41 gp_pixel black;
42 gp_pixel red;
43 gp_pixel green;
44 gp_pixel yellow;
45 gp_pixel blue;
46 gp_pixel magenta;
47 gp_pixel cyan;
48 gp_pixel gray;
49 gp_pixel br_black;
50 gp_pixel br_red;
51 gp_pixel br_green;
52 gp_pixel br_yellow;
53 gp_pixel br_blue;
54 gp_pixel br_magenta;
55 gp_pixel br_cyan;
56 gp_pixel white;
57 } __attribute__((packed));
58 };
59
60 /* fonts */
61 gp_text_style *font;
62 gp_text_style *font_bold;
63
64 gp_text_style *font_big;
65 gp_text_style *font_big_bold;
66
67 gp_text_style *font_mono;
68 gp_text_style *font_mono_bold;
69
70 /* pixel type used for drawing */
71 gp_pixel_type pixel_type;
72
73 /* padding between widgets */
74 uint8_t padd;
75 /* frame thickness 0 == 1px */
76 uint8_t fr_thick;
77 /* frame roundness */
78 uint8_t fr_round;
79 /* cursor thickness 0 == 1px */
80 uint8_t cur_thick;
81 /* font size */
82 uint8_t font_size;
83 /* font size in mm */
84 float font_size_mm;
85 /* maximal delay between two clicks for a double click */
86 uint16_t dclick_ms;
87 /* feedback delay, how long should be button pressed, tbox red etc */
88 uint16_t feedback_ms;
89 /* area to update on a screen after a call to gp_widget_render() */
90 gp_bbox *flip;
91
92 /* passed down if only part of the layout has to be rendered */
93 gp_bbox *bbox;
94
95 /* if set focused widget uses bold font, useful for 1bpp */
96 int focused_is_bold:1;
97 /* draws rectangles around container widgets */
98 int debug_layout:1;
99};
100
101static inline int gp_widgets_is_dclick(uint64_t time_now, uint64_t time_prev,
102 const gp_widget_render_ctx *ctx)
103{
104 if (time_now - time_prev < (uint64_t)ctx->dclick_ms)
105 return 1;
106
107 return 0;
108}
109
115const gp_pixmap *gp_widget_render_buffer(void);
116
117typedef struct gp_widget_timer {
118 uint32_t (*callback)(void *priv);
119 void *priv;
120 /* do not touch */
121 gp_timer tmr;
122} gp_widget_timer;
123
124enum gp_widget_render_timer_flags {
125 GP_TIMER_RESCHEDULE = 0x01,
126};
127
128void gp_widget_render_timer(gp_widget *self, int flags, unsigned int timeout_ms);
129void gp_widget_render_timer_cancel(gp_widget *self);
130
136const gp_widget_render_ctx *gp_widgets_render_ctx(void);
137
144void gp_widgets_getopt(int *argc, char **argv[]);
145
154void gp_widgets_register_callback(int (*on_event)(gp_event *));
155
167void gp_widgets_main_loop(struct gp_widget *layout,
168 void (*init)(int argc, char *argv[]),
169 int argc, char *argv[])
170 __attribute__((noreturn));
171
177void gp_widgets_exit(int exit_value) __attribute__((noreturn));
178
186gp_widget *gp_widget_layout_replace(gp_widget *layout);
187
197long gp_dialog_run(gp_dialog *dialog);
198
205void gp_widgets_clipboard_set(const char *str, size_t len);
206
215char *gp_widgets_clipboard_get(void);
216
224void gp_widgets_clipboard_request(gp_widget *self);
225
234void gp_widgets_clipboard_request_cancel(gp_widget *self);
235
236/*
237 * TODO: Obsolete?
238 */
239void gp_widgets_redraw(gp_widget *layout);
240
241/*
242 * TODO: Obsolete?
243 */
244int gp_widgets_process_events(gp_widget *layout);
245
246/*
247 * TODO: Obsolete?
248 */
249void gp_widgets_layout_init(gp_widget *layout, const char *win_tittle);
250
258void gp_widget_render_zoom(int zoom_inc);
259
260#endif /* GP_WIDGET_RENDER_H */
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
A bounding box implementation.
Includes all core headers.
gp_pixel_type
List of all pixel types.
Timers and timer queue implementation.
A bounding box.
Definition gp_bbox.h:23
A dialog.
Definition gp_dialog.h:26
A pixmap buffer.
Definition gp_pixmap.h:33
A timer.
Definition gp_timer.h:26