libxputty 0.1
Loading...
Searching...
No Matches
Functions
xvaluedisplay_private.c File Reference

Go to the source code of this file.

Functions

void _draw_valuedisplay (void *w_, void *user_data)
 _draw_valuedisplay - draw a valuedisplay on expose call
 
void _draw_spinbox (void *w_, void *user_data)
 _draw_spinbox - draw a spinbox expose call
 
void _draw_buttons (void *w_, void *user_data)
 _draw_buttons - draw the spinbox buttons
 
void _buttons_released (void *w_, void *button_, void *user_data)
 _buttons_released - set the spinbox value on button releases
 
void _popup_spinbox (void *w_, void *button, void *user_data)
 _popup_spinbox - show a spinbox above a valuedisplay
 

Function Documentation

◆ _buttons_released()

void _buttons_released ( void *  w_,
void *  button,
void *  user_data 
)

_buttons_released - set the spinbox value on button releases

Parameters
*w_- The Widget_t contain the button
*button- the XButtonEvent
*user_data- attached user_data

Definition at line 157 of file xvaluedisplay_private.c.

157 {
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}
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
Adjustment_t * adj
Definition xwidget.h:497
void * parent
Definition xwidget.h:471
int button
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 os_get_window_metrics(Widget_t *w, Metrics_t *metrics)
os_get_window_metrics - Get the Merics_t struct related to a Widget_t
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition xwidget.c:445

References Widget_t::adj, adj_get_value(), adj_set_value(), XEvent::button, expose_widget(), Metrics_t::height, os_get_window_metrics(), Widget_t::parent, Adjustment_t::step, Metrics_t::visible, and XEvent::y.

Referenced by add_popup_spinbox().

◆ _draw_buttons()

void _draw_buttons ( void *  w_,
void *  user_data 
)

_draw_buttons - draw the spinbox buttons

Parameters
*w_- The Widget_t contain the spinbox
*user_data- attached user_data

Definition at line 133 of file xvaluedisplay_private.c.

133 {
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}
float ascale
Definition xwidget.h:369
Resize_t scale
Definition xwidget.h:525
cairo_t * crb
Definition xwidget.h:489
Xputty * app
Definition xwidget.h:465
int big_font
Definition xputty.h:250
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
@ NORMAL_
Definition xcolor.h:44

References Widget_t::app, Resize_t::ascale, Xputty::big_font, Widget_t::crb, get_color_state(), Metrics_t::height, NORMAL_, os_get_window_metrics(), Widget_t::scale, use_bg_color_scheme(), use_text_color_scheme(), Metrics_t::visible, and Metrics_t::width.

Referenced by add_popup_spinbox().

◆ _draw_spinbox()

void _draw_spinbox ( void *  w_,
void *  user_data 
)

_draw_spinbox - draw a spinbox expose call

Parameters
*w_- The Widget_t contain the spinbox
*user_data- attached user_data

Definition at line 93 of file xvaluedisplay_private.c.

93 {
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}

References Widget_t::adj, adj_get_value(), Widget_t::app, Resize_t::ascale, Widget_t::crb, get_color_state(), Metrics_t::height, NORMAL_, Xputty::normal_font, os_get_window_metrics(), Widget_t::parent, Widget_t::scale, Adjustment_t::step, use_bg_color_scheme(), use_text_color_scheme(), Metrics_t::visible, and Metrics_t::width.

Referenced by add_popup_spinbox().

◆ _draw_valuedisplay()

void _draw_valuedisplay ( void *  w_,
void *  user_data 
)

_draw_valuedisplay - draw a valuedisplay on expose call

Parameters
*w_- The Widget_t contain the valuedisplay
*user_data- attached user_data

Definition at line 25 of file xvaluedisplay_private.c.

25 {
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}
int state
Definition xwidget.h:511
int normal_font
Definition xputty.h:248
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
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
@ INSENSITIVE_
Definition xcolor.h:48
@ SELECTED_
Definition xcolor.h:46
@ PRELIGHT_
Definition xcolor.h:45
@ ACTIVE_
Definition xcolor.h:47

References ACTIVE_, Widget_t::adj, adj_get_value(), Widget_t::app, Resize_t::ascale, Widget_t::crb, get_color_state(), Metrics_t::height, INSENSITIVE_, NORMAL_, Xputty::normal_font, os_get_window_metrics(), PRELIGHT_, Widget_t::scale, SELECTED_, Widget_t::state, Adjustment_t::step, use_frame_color_scheme(), use_shadow_color_scheme(), use_text_color_scheme(), Metrics_t::visible, and Metrics_t::width.

Referenced by add_valuedisplay().

◆ _popup_spinbox()

void _popup_spinbox ( void *  w_,
void *  button,
void *  user_data 
)

_popup_spinbox - show a spinbox above a valuedisplay

Parameters
*w_- The Widget_t contain the valuedisplay
*button- the XButtonEvent
*user_data- attached user_data

Definition at line 182 of file xvaluedisplay_private.c.

182 {
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
Childlist_t * childlist
Definition xwidget.h:499
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
@ 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

References Widget_t::app, Widget_t::childlist, Childlist_t::childs, Xputty::dpy, Xputty::hold_grab, IS_WIDGET, os_get_root_window(), os_grab_pointer(), os_move_window(), os_translate_coords(), pop_widget_show_all(), and Widget_t::widget.

Referenced by add_valuedisplay().