libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xbutton.c
Go to the documentation of this file.
1 /*
2  * 0BSD
3  *
4  * BSD Zero Clause License
5  *
6  * Copyright (c) 2019 Hermann Meyer
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted.
10 
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  *
19  */
20 
21 
22 #include "xbutton.h"
23 #include "xbutton_private.h"
24 
25 
26 Widget_t* add_button(Widget_t *parent, const char * label,
27  int x, int y, int width, int height) {
28 
29  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
30  wid->label = label;
31  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
32  wid->adj = wid->adj_y;
33  wid->scale.gravity = CENTER;
39  return wid;
40 }
41 
42 Widget_t* add_on_off_button(Widget_t *parent, const char * label,
43  int x, int y, int width, int height) {
44 
45  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
46  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
47  wid->adj = wid->adj_y;
48  wid->scale.gravity = CENTER;
54  return wid;
55 }
56 
57 Widget_t* add_toggle_button(Widget_t *parent, const char * label,
58  int x, int y, int width, int height) {
59 
60  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
61  wid->label = label;
62  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
63  wid->adj = wid->adj_y;
64  wid->scale.gravity = CENTER;
70  return wid;
71 }
72 
73 Widget_t* add_image_toggle_button(Widget_t *parent, const char * label,
74  int x, int y, int width, int height) {
75 
76  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
77  wid->label = label;
78  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
79  wid->adj = wid->adj_y;
80  wid->scale.gravity = CENTER;
86  return wid;
87 }
88 
89 Widget_t* add_switch_image_button(Widget_t *parent, const char * label,
90  int x, int y, int width, int height) {
91 
92  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
93  wid->label = label;
94  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
95  wid->adj = wid->adj_y;
96  wid->scale.gravity = ASPECT;
102  return wid;
103 }
104 
105 Widget_t* add_check_button(Widget_t *parent, const char * label,
106  int x, int y, int width, int height) {
107 
108  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
109  wid->label = label;
110  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
111  wid->adj = wid->adj_y;
112  wid->scale.gravity = CENTER;
118  return wid;
119 }
120 
121 int get_width(const char *label) {
122  return max(1, strlen(label)*12);
123 }
124 
125 Widget_t* add_check_box(Widget_t *parent, const char * label,
126  int x, int y, int width, int height) {
127 
128  Widget_t *wid = create_widget(parent->app, parent, x, y, get_width(label), height);
129  wid->label = label;
130  wid->adj_y = add_adjustment(wid,0.0, 0.0, 0.0, 1.0,1.0, CL_TOGGLE);
131  wid->adj = wid->adj_y;
132  wid->scale.gravity = CENTER;
138  return wid;
139 }
Func_t::leave_callback
xevfunc leave_callback
Definition: xwidget.h:83
Func_t::enter_callback
xevfunc enter_callback
Definition: xwidget.h:82
CL_TOGGLE
@ CL_TOGGLE
Definition: xadjustment.h:51
add_check_box
Widget_t * add_check_box(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_check_box - add a check box to a Widget_t connect to func.value_changed_callback to implement you...
Definition: xbutton.c:125
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
add_image_toggle_button
Widget_t * add_image_toggle_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_image_toggle_button - add a button to a Widget_t connect to func.value_changed_callback to implem...
Definition: xbutton.c:73
add_on_off_button
Widget_t * add_on_off_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_on_off_button - add a button with default on/off label to a Widget_t connect to func....
Definition: xbutton.c:42
create_widget
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition: xwidget.c:268
transparent_draw
void transparent_draw(void *wid, void *user_data)
transparent_draw - copy parent surface to child surface you usaualy didn't need to call this,...
Definition: xwidget.c:469
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
add_toggle_button
Widget_t * add_toggle_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_toggle_button - add a button to a Widget_t connect to func.value_changed_callback to implement yo...
Definition: xbutton.c:57
CENTER
@ CENTER
Definition: xwidget.h:165
get_width
int get_width(const char *label)
Definition: xbutton.c:121
_draw_check_button
void _draw_check_button(void *w_, void *user_data)
_draw_check_button - internal draw the button to the buffer
Definition: xbutton_private.c:310
_draw_on_off_button
void _draw_on_off_button(void *w_, void *user_data)
_draw_on_off_button - internal draw the on/off button to the buffer
Definition: xbutton_private.c:243
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
_draw_button
void _draw_button(void *w_, void *user_data)
_draw_button - internal draw the button to the buffer
Definition: xbutton_private.c:191
Widget_t::app
Xputty * app
Definition: xwidget.h:300
add_check_button
Widget_t * add_check_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_check_button - add a button to a Widget_t connect to func.value_changed_callback to implement you...
Definition: xbutton.c:105
Func_t::button_press_callback
evfunc button_press_callback
Definition: xwidget.h:93
xbutton.h
add_switch_image_button
Widget_t * add_switch_image_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_switch_image_button - add a button to a Widget_t connect to func.value_changed_callback to implem...
Definition: xbutton.c:89
_draw_switch_image_button
void _draw_switch_image_button(void *w_, void *user_data)
draw switch_image_button - internal draw the button to the buffer
Definition: xbutton_private.c:114
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
_button_released
void _button_released(void *w_, void *button_, void *user_data)
_button_released - redraw the button and send state via user_callback
Definition: xbutton_private.c:394
ASPECT
@ ASPECT
Definition: xwidget.h:167
xbutton_private.h
add_button
Widget_t * add_button(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_button - add a button to a Widget_t connect to func.value_changed_callback to implement your acti...
Definition: xbutton.c:26
_button_pressed
void _button_pressed(void *w_, void *button, void *user_data)
_button_pressed - redraw the button and send state via user_callback
Definition: xbutton_private.c:389
Func_t::button_release_callback
evfunc button_release_callback
Definition: xwidget.h:94
_toggle_button_released
void _toggle_button_released(void *w_, void *button_, void *user_data)
_toggle_button_released - redraw the button and send state via user_callback
Definition: xbutton_private.c:411
_draw_ti_button
void _draw_ti_button(void *w_, void *user_data)
_draw_ti_button - internal draw the button to the buffer
Definition: xbutton_private.c:285
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
add_adjustment
Adjustment_t * add_adjustment(Widget_t *w, float std_value, float value, float min_value, float max_value, float step, CL_type type)
*add_adjustment - adding a adjustment to a Widget_t
Definition: xadjustment.c:25
max
#define max(x, y)
max - set a minimal value (x) as return value
Definition: xputty.h:86
_toggle_button_pressed
void _toggle_button_pressed(void *w_, void *button, void *user_data)
_toggle_button_pressed - redraw the button and send state via user_callback
Definition: xbutton_private.c:406
_draw_check_box
void _draw_check_box(void *w_, void *user_data)
_draw_check_box - internal draw the check box to the buffer
Definition: xbutton_private.c:343
Widget_t::label
const char * label
Definition: xwidget.h:326