GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_render.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2024 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
13#ifndef GP_WIDGET_RENDER_H
14#define GP_WIDGET_RENDER_H
15
16#include <core/gp_core.h>
17#include <core/gp_compiler.h>
18#include <gfx/gp_gfx.h>
19#include <text/gp_text.h>
20#include <utils/gp_timer.h>
21#include <utils/gp_bbox.h>
22
25
32
35
37 union {
45 struct {
66 /* 16 colors */
67 gp_pixel black;
68 gp_pixel red;
69 gp_pixel green;
70 gp_pixel yellow;
71 gp_pixel blue;
72 gp_pixel magenta;
73 gp_pixel cyan;
74 gp_pixel gray;
75 gp_pixel br_black;
76 gp_pixel br_red;
77 gp_pixel br_green;
78 gp_pixel br_yellow;
79 gp_pixel br_blue;
80 gp_pixel br_magenta;
81 gp_pixel br_cyan;
82 gp_pixel white;
83 } GP_PACKED;
84 };
85
98
101
103 uint8_t padd;
105 uint8_t fr_thick;
107 uint8_t fr_round;
109 uint8_t cur_thick;
110 /* font size */
111 uint8_t font_size;
112 /* font size in mm */
113 float font_size_mm;
114 /* maximal delay between two clicks for a double click */
115 uint16_t dclick_ms;
116 /* feedback delay, how long should be button pressed, tbox red etc */
117 uint16_t feedback_ms;
118 /* area to update on a screen after a call to gp_widget_render() */
119 gp_bbox *flip;
120
121 /* passed down if only part of the layout has to be rendered */
122 gp_bbox *bbox;
123
124 /* if set focused widget uses bold font, useful for 1bpp */
125 int focused_is_bold:1;
126 /* draws rectangles around container widgets */
127 int debug_layout:1;
128};
129
130static inline int gp_widgets_is_dclick(uint64_t time_now, uint64_t time_prev,
131 const gp_widget_render_ctx *ctx)
132{
133 if (time_now - time_prev < (uint64_t)ctx->dclick_ms)
134 return 1;
135
136 return 0;
137}
138
145
146typedef struct gp_widget_timer {
147 uint32_t (*callback)(void *priv);
148 void *priv;
149 /* do not touch */
150 gp_timer tmr;
151} gp_widget_timer;
152
153enum gp_widget_render_timer_flags {
154 GP_TIMER_RESCHEDULE = 0x01,
155};
156
157void gp_widget_render_timer(gp_widget *self, int flags, unsigned int timeout_ms);
158void gp_widget_render_timer_cancel(gp_widget *self);
159
166
173void gp_widgets_getopt(int *argc, char **argv[]);
174
183void gp_widgets_register_callback(int (*on_event)(gp_event *));
184
196void gp_widgets_main_loop(struct gp_widget *layout,
197 void (*init)(int argc, char *argv[]),
198 int argc, char *argv[])
199 __attribute__((noreturn));
200
206void gp_widgets_exit(int exit_value) __attribute__((noreturn));
207
216
227
234void gp_widgets_clipboard_set(const char *str, size_t len);
235
245
254
264
265/*
266 * TODO: Obsolete?
267 */
268void gp_widgets_redraw(gp_widget *layout);
269
270/*
271 * TODO: Obsolete?
272 */
273int gp_widgets_process_events(gp_widget *layout);
274
275/*
276 * TODO: Obsolete?
277 */
278void gp_widgets_layout_init(gp_widget *layout, const char *win_tittle);
279
287void gp_widget_render_zoom(int zoom_inc);
288
289#endif /* GP_WIDGET_RENDER_H */
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
A bounding box implementation.
A compiler dependent macros.
#define GP_PACKED
Expand to packed attribute if supported by the compiler.
Definition gp_compiler.h:55
Includes all core headers.
gp_pixel_type
List of all pixel types.
A text drawing functions.
Timers and timer queue implementation.
void gp_widgets_clipboard_request_cancel(gp_widget *self)
Cancel clipboard data request.
void gp_widgets_main_loop(struct gp_widget *layout, void(*init)(int argc, char *argv[]), int argc, char *argv[]) __attribute__((noreturn))
Widgets main loop.
void gp_widgets_clipboard_set(const char *str, size_t len)
Sets the clipboard data.
long gp_dialog_run(gp_dialog *dialog)
Runs a dialog.
void gp_widgets_getopt(int *argc, char **argv[])
Parses options, returns positional arguments, e.g. paths.
void gp_widgets_exit(int exit_value) __attribute__((noreturn))
Exits the appliaction.
const gp_pixmap * gp_widget_render_buffer(void)
Returns a pointer to a render pixmap.
gp_widget * gp_widget_layout_replace(gp_widget *layout)
Replace a application layout.
void gp_widgets_clipboard_request(gp_widget *self)
Request clipboard data.
const gp_widget_render_ctx * gp_widgets_render_ctx(void)
Returns a pointer to the current render context.
void gp_widgets_register_callback(int(*on_event)(gp_event *))
Register application event callback.
void gp_widget_render_zoom(int zoom_inc)
Increases/decreases font sizes, etc.
char * gp_widgets_clipboard_get(void)
Returns clipboard data.
Common widget types.
Colors and color scheme.
gp_widgets_color_scheme
A color scheme.
@ GP_WIDGETS_THEME_COLORS
The number of theme colors.
A bounding box.
Definition gp_bbox.h:23
A dialog.
Definition gp_dialog.h:26
An input event.
Definition gp_event.h:153
A pixmap buffer.
Definition gp_pixmap.h:33
A text style.
A timer.
Definition gp_timer.h:26
Global widget (rendering) context.
gp_pixel col_disabled
A disabled widget color.
uint8_t fr_thick
Frame thickness 0 == 1px.
gp_pixel_type pixel_type
Pixel type used for drawing.
gp_pixel warn_color
A warning color.
gp_pixel hl_color
A highlight color.
gp_pixel text_color
A text color.
gp_pixel alert_color
An alert color.
uint8_t padd
Padding between widgets.
uint8_t fr_round
Frame roundness.
gp_text_style * font_bold
Default bold font.
gp_pixmap * buf
A pixmap to render the widget to.
gp_text_style * font
Default font.
gp_pixel colors[GP_WIDGETS_THEME_COLORS+16]
Currrently active colors as an array.
uint8_t cur_thick
Text cursor thickness 0 == 1px.
gp_pixel fill_color
A fill color.
gp_text_style * font_mono_bold
Default monospace bold font.
gp_pixel accept_color
An accept color.
gp_text_style * font_big
Default big font.
gp_text_style * font_big_bold
Default big bold font.
gp_pixel fg_color
A foreground color.
gp_pixel sel_color
A selection color.
gp_pixel bg_color
A background color.
enum gp_widgets_color_scheme color_scheme
Active color scheme.
gp_text_style * font_mono
Default monospace font.
A widget base.
Definition gp_widget.h:28