libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xslider_private.h File Reference
#include "xslider.h"
Include dependency graph for xslider_private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XSLIDER_PRIVATE_H_
 

Functions

void _pattern_vslider (Widget_t *w, Color_state st, int width)
 _pattern_vslider - set pattern for the slider base More...
 
void _pattern_hslider (Widget_t *w, Color_state st, int width)
 _pattern_hslider - set pattern for the slider base More...
 
void _draw_vslider (void *w_, void *user_data)
 _draw_vslider - internal draw the slider to the buffer More...
 
void _draw_hslider (void *w_, void *user_data)
 _draw_hslider - internal draw the slider to the buffer More...
 
void _slider_released (void *w_, void *button_, void *user_data)
 _slider_released - redraw the slider when button released More...
 

Macro Definition Documentation

◆ XSLIDER_PRIVATE_H_

#define XSLIDER_PRIVATE_H_

Definition at line 24 of file xslider_private.h.

Function Documentation

◆ _draw_hslider()

void _draw_hslider ( void *  w_,
void *  user_data 
)

_draw_hslider - internal draw the slider to the buffer

Parameters
*w_- void pointer to the Widget_t button
*user_data- void pointer to attached user_data
Returns
void

Definition at line 117 of file xslider_private.c.

117  {
118  Widget_t *w = (Widget_t*)w_;
119  XWindowAttributes attrs;
120  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
121  int width = attrs.width-2;
122  int height = attrs.height-2;
123  float center = (float)height/2;
124  float upcenter = (float)height;
125 
126  if (attrs.map_state != IsViewable) return;
127 
128  float sliderstate = adj_get_state(w->adj_x);
129 
130  _pattern_hslider(w, get_color_state(w), height);
131  cairo_move_to (w->crb, center, center);
132  cairo_line_to(w->crb,width-center-10,center);
133  cairo_set_line_cap (w->crb,CAIRO_LINE_CAP_ROUND);
134  cairo_set_line_width(w->crb,center);
135  cairo_stroke(w->crb);
136 
138  cairo_move_to (w->crb, center, center);
139  cairo_line_to(w->crb,width-center-10,center);
140  cairo_set_line_width(w->crb,center/10);
141  cairo_stroke(w->crb);
142 
144  cairo_arc(w->crb, (center) +
145  ((width-10-upcenter) * sliderstate),center, center/2, 0, 2 * M_PI );
146  cairo_fill_preserve(w->crb);
147  cairo_set_line_width(w->crb,1);
148  cairo_stroke(w->crb);
149 
151  cairo_arc(w->crb, (center) +
152  ((width-10-upcenter) * sliderstate),center, center/3, 0, 2 * M_PI );
153  cairo_fill_preserve(w->crb);
155  cairo_set_line_width(w->crb,center/15);
156  cairo_stroke(w->crb);
157  cairo_new_path (w->crb);
158 
159  cairo_text_extents_t extents;
160 
161 
163  cairo_set_font_size (w->crb, w->app->normal_font/w->scale.ascale);
164  cairo_text_extents(w->crb,w->label , &extents);
165 
166  cairo_move_to (w->crb, width/2-extents.width/2, height );
167  cairo_show_text(w->crb, w->label);
168  cairo_new_path (w->crb);
169 
170  cairo_set_font_size (w->crb, w->app->small_font/w->scale.ascale);
171  char s[64];
172  const char* format[] = {"%.1f", "%.2f", "%.3f"};
173  float value = adj_get_value(w->adj);
174  if (fabs(w->adj->step)>0.99) {
175  snprintf(s, 63,"%d", (int) value);
176  } else if (fabs(w->adj->step)>0.09) {
177  snprintf(s, 63, format[1-1], value);
178  } else {
179  snprintf(s, 63, format[2-1], value);
180  }
181  cairo_text_extents(w->crb,s , &extents);
182  cairo_move_to (w->crb, width/2-extents.width/2, extents.height );
183  cairo_show_text(w->crb, s);
184  cairo_new_path (w->crb);
185 }

References _pattern_hslider(), Widget_t::adj, adj_get_state(), adj_get_value(), Widget_t::adj_x, Widget_t::app, Resize_t::ascale, Widget_t::crb, Xputty::dpy, get_color_state(), Widget_t::label, NORMAL_, Xputty::normal_font, Widget_t::scale, Xputty::small_font, Adjustment_t::step, use_bg_color_scheme(), use_fg_color_scheme(), use_shadow_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _draw_vslider()

void _draw_vslider ( void *  w_,
void *  user_data 
)

_draw_vslider - internal draw the slider to the buffer

Parameters
*w_- void pointer to the Widget_t button
*user_data- void pointer to attached user_data
Returns
void

Definition at line 47 of file xslider_private.c.

47  {
48  Widget_t *w = (Widget_t*)w_;
49  XWindowAttributes attrs;
50  XGetWindowAttributes(w->app->dpy, (Window)w->widget, &attrs);
51  int width = attrs.width-2;
52  int height = attrs.height-2;
53  float center = (float)width/2;
54  float upcenter = (float)width;
55 
56  if (attrs.map_state != IsViewable) return;
57 
58  float sliderstate = adj_get_state(w->adj_y);
59 
60  _pattern_vslider(w, get_color_state(w), width);
61  cairo_move_to (w->crb, center, center);
62  cairo_line_to(w->crb,center,height-center-10);
63  cairo_set_line_cap (w->crb,CAIRO_LINE_CAP_ROUND);
64  cairo_set_line_width(w->crb,center);
65  cairo_stroke(w->crb);
66 
68  cairo_move_to (w->crb, center, center);
69  cairo_line_to(w->crb,center,height-center-10);
70  cairo_set_line_width(w->crb,center/10);
71  cairo_stroke(w->crb);
72 
74  cairo_arc(w->crb,center, (height-center-10) -
75  ((height-10-upcenter) * sliderstate), center/2, 0, 2 * M_PI );
76  cairo_fill_preserve(w->crb);
77  cairo_set_line_width(w->crb,1);
78  cairo_stroke(w->crb);
79 
80 
82  cairo_arc(w->crb,center, (height-center-10) -
83  ((height-10-upcenter) * sliderstate), center/3, 0, 2 * M_PI );
84  cairo_fill_preserve(w->crb);
86  cairo_set_line_width(w->crb,center/15);
87  cairo_stroke(w->crb);
88  cairo_new_path (w->crb);
89 
90  cairo_text_extents_t extents;
91 
92 
94  cairo_set_font_size (w->crb, center/1.8);
95  cairo_text_extents(w->crb,w->label , &extents);
96 
97  cairo_move_to (w->crb, center-extents.width/2, height-center/2.1);
98  cairo_show_text(w->crb, w->label);
99  cairo_new_path (w->crb);
100 
101  char s[64];
102  const char* format[] = {"%.1f", "%.2f", "%.3f"};
103  float value = adj_get_value(w->adj);
104  if (fabs(w->adj->step)>0.99) {
105  snprintf(s, 63,"%d", (int) value);
106  } else if (fabs(w->adj->step)>0.09) {
107  snprintf(s, 63, format[1-1], value);
108  } else {
109  snprintf(s, 63, format[2-1], value);
110  }
111  cairo_text_extents(w->crb,s , &extents);
112  cairo_move_to (w->crb, center-extents.width/2, extents.height );
113  cairo_show_text(w->crb, s);
114  cairo_new_path (w->crb);
115 }

References _pattern_vslider(), Widget_t::adj, adj_get_state(), adj_get_value(), Widget_t::adj_y, Widget_t::app, Widget_t::crb, Xputty::dpy, get_color_state(), Widget_t::label, NORMAL_, Adjustment_t::step, use_bg_color_scheme(), use_fg_color_scheme(), use_shadow_color_scheme(), use_text_color_scheme(), and Widget_t::widget.

◆ _pattern_hslider()

void _pattern_hslider ( Widget_t w,
Color_state  st,
int  width 
)

_pattern_hslider - set pattern for the slider base

Parameters
*w_- void pointer to the Widget_t button
st- the Widget_t Color_t mode to use
width- the width of the base
Returns
void

Definition at line 36 of file xslider_private.c.

36  {
37  Colors *c = get_color_scheme(w->app,st);
38  if (!c) return;
39  cairo_pattern_t *pat = cairo_pattern_create_linear (2, 2, 2, height);
40  cairo_pattern_add_color_stop_rgba(pat, 0.0, c->base[0], c->base[1], c->base[2], c->base[3]);
41  cairo_pattern_add_color_stop_rgba(pat, 0.5, 0.0, 0.0, 0.0, 0.0);
42  cairo_pattern_add_color_stop_rgba(pat, 1.0, c->base[0], c->base[1], c->base[2], c->base[3]);
43  cairo_set_source(w->crb, pat);
44  cairo_pattern_destroy (pat);
45 }

References Widget_t::app, Colors::base, Widget_t::crb, and get_color_scheme().

◆ _pattern_vslider()

void _pattern_vslider ( Widget_t w,
Color_state  st,
int  width 
)

_pattern_vslider - set pattern for the slider base

Parameters
*w_- void pointer to the Widget_t button
st- the Widget_t Color_t mode to use
width- the width of the base
Returns
void

Definition at line 25 of file xslider_private.c.

25  {
26  Colors *c = get_color_scheme(w->app,st);
27  if (!c) return;
28  cairo_pattern_t *pat = cairo_pattern_create_linear (2, 2, width, 2);
29  cairo_pattern_add_color_stop_rgba(pat, 0.0, c->base[0], c->base[1], c->base[2], c->base[3]);
30  cairo_pattern_add_color_stop_rgba(pat, 0.5, 0.0, 0.0, 0.0, 0.0);
31  cairo_pattern_add_color_stop_rgba(pat, 1.0, c->base[0], c->base[1], c->base[2], c->base[3]);
32  cairo_set_source(w->crb, pat);
33  cairo_pattern_destroy (pat);
34 }

References Widget_t::app, Colors::base, Widget_t::crb, and get_color_scheme().

◆ _slider_released()

void _slider_released ( void *  w_,
void *  button_,
void *  user_data 
)

_slider_released - redraw the slider when button released

Parameters
*w_- void pointer to the Widget_t button
*user_data- void pointer to attached user_data
Returns
void

Definition at line 187 of file xslider_private.c.

187  {
188  Widget_t *w = (Widget_t*)w_;
189  expose_widget(w);
190 }

References expose_widget().

use_text_color_scheme
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:199
_pattern_vslider
void _pattern_vslider(Widget_t *w, Color_state st, int width)
_pattern_vslider - set pattern for the slider base
Definition: xslider_private.c:25
expose_widget
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition: xwidget.c:461
adj_get_state
float adj_get_state(Adjustment_t *adj)
adj_get_state - get the current state of the Adjustment_t
Definition: xadjustment.c:148
Colors::base
double base[4]
Definition: xcolor.h:76
get_color_state
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:155
use_shadow_color_scheme
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:206
Xputty::normal_font
int normal_font
Definition: xputty.h:191
adj_get_value
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
Definition: xadjustment.c:154
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
use_fg_color_scheme
void use_fg_color_scheme(Widget_t *w, Color_state st)
use_fg_color_scheme - use forground Colors to paint on Widget_t
Definition: xcolor.c:178
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
use_bg_color_scheme
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:185
Widget_t::app
Xputty * app
Definition: xwidget.h:300
Xputty::dpy
Display * dpy
Definition: xputty.h:181
Colors
Color_t - struct used to set cairo color for Widget_t.
Definition: xcolor.h:73
Resize_t::ascale
float ascale
Definition: xwidget.h:214
Widget_t::widget
Window widget
Definition: xwidget.h:302
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
_pattern_hslider
void _pattern_hslider(Widget_t *w, Color_state st, int height)
_pattern_hslider - set pattern for the slider base
Definition: xslider_private.c:36
NORMAL_
@ NORMAL_
Definition: xcolor.h:39
Xputty::small_font
int small_font
Definition: xputty.h:189
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
get_color_scheme
Colors * get_color_scheme(Xputty *main, Color_state st)
get_color_scheme - get pointer to the Colors struct to use in relation to the Color_state
Definition: xcolor.c:130
Widget_t::label
const char * label
Definition: xwidget.h:326
Adjustment_t::step
float step
Definition: xadjustment.h:92
Widget_t::adj_x
Adjustment_t * adj_x
Definition: xwidget.h:330