libxputty 0.1
Loading...
Searching...
No Matches
xvaluedisplay_private.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
23
24
25void _draw_valuedisplay(void *w_, void* user_data) {
26 Widget_t *w = (Widget_t*)w_;
27 if (!w) return;
28 Metrics_t metrics;
29 os_get_window_metrics(w, &metrics);
30 int width = metrics.width-2;
31 int height = metrics.height-2;
32 if (!metrics.visible) return;
33
34 cairo_rectangle(w->crb,2.0, 2.0, width, height);
35
36 if(w->state==0) {
37 cairo_set_line_width(w->crb, 1.0);
39 cairo_fill_preserve(w->crb);
41 } else if(w->state==1) {
43 cairo_fill_preserve(w->crb);
44 cairo_set_line_width(w->crb, 1.5);
46 } else if(w->state==2) {
48 cairo_fill_preserve(w->crb);
49 cairo_set_line_width(w->crb, 1.0);
51 } else if(w->state==3) {
53 cairo_fill_preserve(w->crb);
54 cairo_set_line_width(w->crb, 1.0);
56 } else if(w->state==4) {
58 cairo_fill_preserve(w->crb);
59 cairo_set_line_width(w->crb, 1.0);
61 }
62 cairo_stroke(w->crb);
63
64 cairo_rectangle(w->crb,4.0, 4.0, width, height);
65 cairo_stroke(w->crb);
66 cairo_rectangle(w->crb,3.0, 3.0, width, height);
67 cairo_stroke(w->crb);
68
69 cairo_text_extents_t extents;
70
71 char s[64];
72 const char* format[] = {"%.1f", "%.2f", "%.3f"};
73 float value = adj_get_value(w->adj);
74 if (fabs(w->adj->step)>0.99) {
75 snprintf(s, 63,"%d", (int) value);
76 } else if (fabs(w->adj->step)>0.09) {
77 snprintf(s, 63, format[1-1], value);
78 } else {
79 snprintf(s, 63, format[2-1], value);
80 }
81
82
84 float font_size = w->app->normal_font/w->scale.ascale;
85 cairo_set_font_size (w->crb, font_size);
86 cairo_text_extents(w->crb,s , &extents);
87 cairo_move_to (w->crb, (width-extents.width)*0.5, (height+extents.height)*0.55);
88 cairo_show_text(w->crb, s);
89 cairo_new_path (w->crb);
90
91}
92
93void _draw_spinbox(void *w_, void* user_data) {
94 Widget_t *w = (Widget_t*)w_;
95 Widget_t *p = (Widget_t*)w->parent;
96 Widget_t *parent = (Widget_t*)p->parent;
97 if (!w) return;
98 Metrics_t metrics;
99 os_get_window_metrics(w, &metrics);
100 int width = metrics.width-2;
101 int height = metrics.height-2;
102 if (!metrics.visible) return;
103
104 cairo_rectangle(w->crb,2.0, 2.0, width, height);
106 cairo_fill_preserve(w->crb);
108 cairo_stroke(w->crb);
109
110 cairo_text_extents_t extents;
111
112 char s[64];
113 const char* format[] = {"%.1f", "%.2f", "%.3f"};
114 float value = adj_get_value(parent->adj);
115 if (fabs(parent->adj->step)>0.99) {
116 snprintf(s, 63,"%d", (int) value);
117 } else if (fabs(parent->adj->step)>0.09) {
118 snprintf(s, 63, format[1-1], value);
119 } else {
120 snprintf(s, 63, format[2-1], value);
121 }
122
123
125 float font_size = w->app->normal_font/w->scale.ascale;
126 cairo_set_font_size (w->crb, font_size);
127 cairo_text_extents(w->crb,s , &extents);
128 cairo_move_to (w->crb, (width-extents.width)*0.5, (height+extents.height)*0.55);
129 cairo_show_text(w->crb, s);
130 cairo_new_path (w->crb);
131}
132
133void _draw_buttons(void *w_, void* user_data) {
134 Widget_t *w = (Widget_t*)w_;
135 Metrics_t metrics;
136 os_get_window_metrics(w, &metrics);
137 int width = metrics.width-2;
138 int height = metrics.height-2;
139 if (!metrics.visible) return;
140
141 cairo_rectangle(w->crb,0.0, 2.0, width, height-2);
143 cairo_fill_preserve(w->crb);
145 cairo_stroke(w->crb);
146 cairo_rectangle(w->crb,0.0, height/2, width, height-2);
147 cairo_stroke(w->crb);
149 float font_size = w->app->big_font/w->scale.ascale;
150 cairo_set_font_size (w->crb, font_size);
151 cairo_move_to (w->crb, 5,18);
152 cairo_show_text(w->crb, "+");
153 cairo_move_to (w->crb, 7,38);
154 cairo_show_text(w->crb, "-");
155}
156
157void _buttons_released(void *w_, void* button_, void* user_data) {
158 Widget_t *w = (Widget_t*)w_;
159 Widget_t *p = (Widget_t*)w->parent;
160 Widget_t *parent = (Widget_t*)p->parent;
161 XButtonEvent *xbutton = (XButtonEvent*)button_;
162 if (!w) return;
163 Metrics_t metrics;
164 os_get_window_metrics(w, &metrics);
165 int height = metrics.height-2;
166 if (!metrics.visible) return;
167 if (xbutton->button == Button1) {
168 if (xbutton->y > height/2)
169 adj_set_value(parent->adj, adj_get_value(parent->adj)-parent->adj->step);
170 else
171 adj_set_value(parent->adj, adj_get_value(parent->adj)+parent->adj->step);
172 expose_widget(p);
173 } else if (xbutton->button == Button4) {
174 adj_set_value(parent->adj, adj_get_value(parent->adj)+parent->adj->step);
175 expose_widget(p);
176 } else if (xbutton->button == Button5) {
177 adj_set_value(parent->adj, adj_get_value(parent->adj)-parent->adj->step);
178 expose_widget(p);
179 }
180}
181
182void _popup_spinbox(void *w_, void* button, void* user_data) {
183 Widget_t *w = (Widget_t*)w_;
184 Widget_t *spin_box = (Widget_t*)w->childlist->childs[0];
185 int x1, y1;
186 os_translate_coords(w, w->widget, os_get_root_window(w->app, IS_WIDGET), 0, 0, &x1, &y1);
187 os_move_window(spin_box->app->dpy,spin_box,x1-10, y1-10);
188 pop_widget_show_all(spin_box);
189 int err = os_grab_pointer(w);
190 w->app->hold_grab = spin_box;
191 if (err) debug_print("Error grap pointer\n");
192}
Widget_t ** childs
Definition xchildlist.h:51
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
float ascale
Definition xwidget.h:369
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Resize_t scale
Definition xwidget.h:525
Adjustment_t * adj
Definition xwidget.h:497
void * parent
Definition xwidget.h:471
Window widget
Definition xwidget.h:469
cairo_t * crb
Definition xwidget.h:489
int state
Definition xwidget.h:511
Childlist_t * childlist
Definition xwidget.h:499
Xputty * app
Definition xwidget.h:465
int button
int big_font
Definition xputty.h:250
int normal_font
Definition xputty.h:248
Display * dpy
Definition xputty.h:232
Widget_t * hold_grab
Definition xputty.h:238
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
void use_frame_color_scheme(Widget_t *w, Color_state st)
use_frame_color_scheme - use frame Colors to paint on Widget_t
Definition xcolor.c:280
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
Definition xcolor.c:222
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
Definition xcolor.c:266
void use_bg_color_scheme(Widget_t *w, Color_state st)
use_bg_color_scheme - use background Colors to paint on Widget_t
Definition xcolor.c:252
void use_shadow_color_scheme(Widget_t *w, Color_state st)
use_shadow_color_scheme - use shadow Colors to paint on Widget_t
Definition xcolor.c:273
@ NORMAL_
Definition xcolor.h:44
@ INSENSITIVE_
Definition xcolor.h:48
@ SELECTED_
Definition xcolor.h:46
@ PRELIGHT_
Definition xcolor.h:45
@ ACTIVE_
Definition xcolor.h:47
void _draw_buttons(void *w_, void *user_data)
_draw_buttons - draw the spinbox buttons
void _draw_spinbox(void *w_, void *user_data)
_draw_spinbox - draw a spinbox expose call
void _buttons_released(void *w_, void *button_, void *user_data)
_buttons_released - set the spinbox value on button releases
void _draw_valuedisplay(void *w_, void *user_data)
_draw_valuedisplay - draw a valuedisplay on expose call
void _popup_spinbox(void *w_, void *button, void *user_data)
_popup_spinbox - show a spinbox above a valuedisplay
void os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t
int os_grab_pointer(Widget_t *w)
os_grab_pointer - grab the mouse pointer. Works only on linux
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void os_translate_coords(Widget_t *w, Window from_window, Window to_window, int from_x, int from_y, int *to_x, int *to_y)
os_translate_coords - get x,y related to destination Window
void os_move_window(Display *dpy, Widget_t *w, int x, int y)
os_move_window - Move a Widget_t
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition xwidget.c:445
@ IS_WIDGET
Definition xwidget.h:388
void pop_widget_show_all(Widget_t *w)
pop_widget_show_all - map/show popup widget with all it's childs
Definition xwidget.c:400