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

Go to the source code of this file.

Data Structures

struct  Adjustment_t
 Adjustment_t - struct to hold a controller adjustment. More...
 

Macros

#define XADJUSTMENT_H_
 

Enumerations

enum  CL_type {
  CL_NONE = 0x0001, CL_CONTINUOS = 0x0002, CL_TOGGLE = 0x0004, CL_BUTTON = 0x0008,
  CL_ENUM = 0x0016, CL_VIEWPORT = 0x0032, CL_METER = 0x0064, CL_LOGARITHMIC = 0x0128,
  CL_LOGSCALE = 0x0256
}
 CL_type - define the type of the controller adjustment one of this types must be given when set up a Adjustment_t for a Wdiget_t. More...
 

Functions

Adjustment_tadd_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 More...
 
void set_adjustment (Adjustment_t *adj, float std_value, float value, float min_value, float max_value, float step, CL_type type)
 *set_adjustment - set a new range to a existing Adjustment_t it will be created if it not exsits yet More...
 
void * delete_adjustment (Adjustment_t *adj)
 delete_adjustment - freeing the memory of the Adjustment_t You usually don't need to call this, as it get handled by main_quit() -> destroy_widget() More...
 
float adj_get_state (Adjustment_t *adj)
 adj_get_state - get the current state of the Adjustment_t More...
 
void adj_set_state (Adjustment_t *adj, float state)
 adj_set_state - set the current state of the Adjustment_t More...
 
float adj_get_value (Adjustment_t *adj)
 adj_get_value - get the current value of the Adjustment_t More...
 
void adj_set_value (Adjustment_t *adj, float value)
 adj_set_value - set the current value to the Adjustment_t More...
 
void adj_set_start_value (void *w)
 adj_set_start_value - internal use to store the value when pointer movment starts More...
 
void adj_set_scale (Adjustment_t *adj, float value)
 adj_set_scale - internal use to scale the pointer movement (0.1 -1.0) More...
 
void adj_set_log_scale (Adjustment_t *adj, float value)
 adj_set_log_scale - internal use to set the logarithmic scale More...
 
void adj_set_motion_state (void *w, float x, float y)
 adj_set_motion_state - internal use to set value and state of the Adjustment_t on mouse pointer movment More...
 
void check_value_changed (Adjustment_t *adj, float *value)
 check_value_changed - check if Adjustment_t value have changed and send value_changed_callback (VALUE_CHANGED) and adj_callback (ADJ_INTERN) if so More...
 

Macro Definition Documentation

◆ XADJUSTMENT_H_

#define XADJUSTMENT_H_

Definition at line 24 of file xadjustment.h.

Enumeration Type Documentation

◆ CL_type

enum CL_type

CL_type - define the type of the controller adjustment one of this types must be given when set up a Adjustment_t for a Wdiget_t.

Parameters
CL_NONE- Widget_t didn't request a adjustment
CL_CONTINUOS- Widget_t request a continuos adjustment
CL_TOGGLE- Widget_t request a toggle adjustment
CL_BUTTON- Widget_t request a button adjustment
CL_ENUM- Widget_t request a enum adjustment
CL_LOGARITHMIC- Widget_t request a logarithmic adjustment
Enumerator
CL_NONE 

Widget_t didn't request a adjustment

CL_CONTINUOS 

Widget_t request a continuos adjustment

CL_TOGGLE 

Widget_t request a toggle adjustment

CL_BUTTON 

Widget_t request a button adjustment

CL_ENUM 

Widget_t request a enum adjustment

CL_VIEWPORT 

Widget_t request a viewport adjustment

CL_METER 

Widget_t request a viewport adjustment

CL_LOGARITHMIC 

Widget_t request a logarithmic adjustment

CL_LOGSCALE 

Widget_t request a logarithmic scaled adjustment

Definition at line 45 of file xadjustment.h.

45  {
46 /** Widget_t didn't request a adjustment */
47  CL_NONE = 0x0001,
48 /** Widget_t request a continuos adjustment */
49  CL_CONTINUOS = 0x0002,
50 /** Widget_t request a toggle adjustment */
51  CL_TOGGLE = 0x0004,
52 /** Widget_t request a button adjustment */
53  CL_BUTTON = 0x0008,
54 /** Widget_t request a enum adjustment */
55  CL_ENUM = 0x0016,
56 /** Widget_t request a viewport adjustment */
57  CL_VIEWPORT = 0x0032,
58 /** Widget_t request a viewport adjustment */
59  CL_METER = 0x0064,
60 /** Widget_t request a logarithmic adjustment */
61  CL_LOGARITHMIC = 0x0128,
62 /** Widget_t request a logarithmic scaled adjustment */
63  CL_LOGSCALE = 0x0256,
64 }CL_type;

Function Documentation

◆ 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

Parameters
*w- pointer to the Widget_t request a Adjustment_t
std_value- standard value of the Adjustment_t
value- current value of the Adjustment_t
min_value- minimum value of the Adjustment_t
max_value- maximal value of the Adjustment_t
step- step to increase/decrease the Adjustment_t
type- set CL_type of Adjustment_t
Returns
*adj - pointer to the Adjustment_t

Definition at line 25 of file xadjustment.c.

26  {
27  Adjustment_t *adj = (Adjustment_t*)malloc(sizeof(Adjustment_t));
28  assert(adj);
29  adj->log_scale = 20.0;
30 
31  switch(type) {
32  case (CL_LOGSCALE) :
33  *(adj) = (Adjustment_t) {
34  .w = w,
35  .std_value = powf(10,(std_value/adj->log_scale)),
36  .value = powf(10,(value/adj->log_scale)),
37  .min_value = powf(10,(min_value/adj->log_scale)),
38  .max_value = powf(10,(max_value/adj->log_scale)),
39  .step = step,
40  .start_value = powf(10,(value/adj->log_scale)),
41  .scale = 1.0,
42  .type = type,
43  .log_scale = adj->log_scale
44  };
45  break;
46  case (CL_LOGARITHMIC) :
47  *(adj) = (Adjustment_t) {
48  .w = w,
49  .std_value = log10(std_value),
50  .value = log10(value),
51  .min_value = log10(min_value),
52  .max_value = log10(max_value),
53  .step = step,
54  .start_value = log10(value),
55  .scale = 1.0,
56  .type = type,
57  .log_scale = adj->log_scale
58  };
59  break;
60  default:
61  *(adj) = (Adjustment_t) {
62  .w = w,
63  .std_value = std_value,
64  .value = value,
65  .min_value = min_value,
66  .max_value = max_value,
67  .step = step,
68  .start_value = value,
69  .scale = 1.0,
70  .type = type,
71  .log_scale = adj->log_scale
72  };
73  break;
74  }
75 
76  debug_print("Widget_t add adjustment\n");
77  return adj;
78 }

References CL_LOGARITHMIC, CL_LOGSCALE, debug_print, Adjustment_t::log_scale, and Widget_t::scale.

◆ adj_get_state()

float adj_get_state ( Adjustment_t adj)

adj_get_state - get the current state of the Adjustment_t

Parameters
*adj- pointer to the Adjustment_t
Returns
float - return the Adjustment_t state mapped to (0<->1)

Definition at line 148 of file xadjustment.c.

148  {
149  if (!adj) return 0.0;
150  return (adj->value - adj->min_value) /
151  (adj->max_value - adj->min_value);
152 }

References Adjustment_t::max_value, Adjustment_t::min_value, and Adjustment_t::value.

◆ adj_get_value()

float adj_get_value ( Adjustment_t adj)

adj_get_value - get the current value of the Adjustment_t

Parameters
*adj- pointer to the Adjustment_t
Returns
float - return the Adjustment_t value

Definition at line 154 of file xadjustment.c.

154  {
155  if (!adj) return 0.0;
156  if (adj->type == CL_LOGSCALE)
157  return log10(adj->value)*adj->log_scale;
158  else if (adj->type == CL_LOGARITHMIC)
159  return powf(10,adj->value);
160  return (adj->value);
161 }

References CL_LOGARITHMIC, CL_LOGSCALE, Adjustment_t::log_scale, Adjustment_t::type, and Adjustment_t::value.

◆ adj_set_log_scale()

void adj_set_log_scale ( Adjustment_t adj,
float  value 
)

adj_set_log_scale - internal use to set the logarithmic scale

Parameters
*adj- pointer to the Adjustment_t
value- value to set the scaleing factor to
Returns
void

Definition at line 183 of file xadjustment.c.

183  {
184  adj->log_scale = value;
185 }

References Adjustment_t::log_scale.

◆ adj_set_motion_state()

void adj_set_motion_state ( void *  w,
float  x,
float  y 
)

adj_set_motion_state - internal use to set value and state of the Adjustment_t on mouse pointer movment

Parameters
*w- pointer to Widget_t containing Adjustment_t
x- movment on the x-axis
y- movement on the y-axis
Returns
void

Definition at line 187 of file xadjustment.c.

187  {
188  Widget_t * wid = (Widget_t*)w;
189  if(wid->adj_x) {
190  float value= wid->adj_x->value;
191  switch(wid->adj_x->type) {
192  case (CL_LOGSCALE):
193  case (CL_LOGARITHMIC):
194  case (CL_CONTINUOS):
195  {
196  float state = (wid->adj_x->start_value - wid->adj_x->min_value) /
197  (wid->adj_x->max_value - wid->adj_x->min_value);
198  float nsteps = wid->adj_x->step / (wid->adj_x->max_value - wid->adj_x->min_value);
199  float nvalue = min(1.0,max(0.0,state + ((float)(x - wid->pos_x)*wid->adj_x->scale *nsteps)));
200  float prevalue = nvalue * (wid->adj_x->max_value - wid->adj_x->min_value) + wid->adj_x->min_value;
201  float mulscale = round(prevalue/wid->adj_x->step);
202  value = min(wid->adj_x->max_value,max(wid->adj_x->min_value,mulscale*wid->adj_x->step));
203  }
204  break;
205  case (CL_TOGGLE):
206  // dont toggle on motion!
207  // value = wid->adj_x->value ? 0.0 : 1.0;
208  break;
209  default:
210  break;
211  }
212  check_value_changed(wid->adj_x, &value);
213  }
214  if(wid->adj_y) {
215  float value = wid->adj_y->value;
216  switch(wid->adj_y->type) {
217  case (CL_LOGSCALE):
218  case (CL_LOGARITHMIC):
219  case (CL_CONTINUOS):
220  {
221  float state = (wid->adj_y->start_value - wid->adj_y->min_value) /
222  (wid->adj_y->max_value - wid->adj_y->min_value);
223  float nsteps = wid->adj_y->step / (wid->adj_y->max_value - wid->adj_y->min_value);
224  float nvalue = min(1.0,max(0.0,state + ((float)(wid->pos_y - y)*wid->adj_y->scale *nsteps)));
225  float prevalue = nvalue * (wid->adj_y->max_value - wid->adj_y->min_value) + wid->adj_y->min_value;
226  float mulscale = round(prevalue/wid->adj_y->step);
227  value = min(wid->adj_y->max_value,max(wid->adj_y->min_value,mulscale*wid->adj_y->step));
228  }
229  break;
230  case (CL_TOGGLE):
231  // dont toggle on motion!
232  // value = wid->adj_y->value ? 0.0 : 1.0;
233  break;
234  default:
235  break;
236  }
237  check_value_changed(wid->adj_y, &value);
238  }
239 }

References Widget_t::adj_x, Widget_t::adj_y, check_value_changed(), CL_CONTINUOS, CL_LOGARITHMIC, CL_LOGSCALE, CL_TOGGLE, max, Adjustment_t::max_value, min, Adjustment_t::min_value, Widget_t::pos_x, Widget_t::pos_y, Adjustment_t::scale, Adjustment_t::start_value, Adjustment_t::step, Adjustment_t::type, and Adjustment_t::value.

◆ adj_set_scale()

void adj_set_scale ( Adjustment_t adj,
float  value 
)

adj_set_scale - internal use to scale the pointer movement (0.1 -1.0)

Parameters
*adj- pointer to the Adjustment_t
value- value to set the scaleing factor to
Returns
void

Definition at line 179 of file xadjustment.c.

179  {
180  adj->scale = value;
181 }

References Adjustment_t::scale.

◆ adj_set_start_value()

void adj_set_start_value ( void *  w)

adj_set_start_value - internal use to store the value when pointer movment starts

Parameters
*w- pointer to Widget_t containing the Adjustment_t
Returns
void

Definition at line 173 of file xadjustment.c.

173  {
174  Widget_t * wid = (Widget_t*)w;
175  if(wid->adj_x)wid->adj_x->start_value = wid->adj_x->value;
176  if(wid->adj_y)wid->adj_y->start_value = wid->adj_y->value;
177 }

References Widget_t::adj_x, Widget_t::adj_y, Adjustment_t::start_value, and Adjustment_t::value.

◆ adj_set_state()

void adj_set_state ( Adjustment_t adj,
float  state 
)

adj_set_state - set the current state of the Adjustment_t

Parameters
*adj- pointer to the Adjustment_t
Returns
float - set the Adjustment_t state mapped to (0<->1)

Definition at line 141 of file xadjustment.c.

141  {
142  if (!adj) return;
143  float nvalue = min(1.0,max(0.0,state));
144  float value = nvalue * (adj->max_value - adj->min_value) + adj->min_value;
145  check_value_changed(adj, &value);
146 }

References check_value_changed(), max, Adjustment_t::max_value, min, and Adjustment_t::min_value.

◆ adj_set_value()

void adj_set_value ( Adjustment_t adj,
float  value 
)

adj_set_value - set the current value to the Adjustment_t

Parameters
*adj- pointer to the Adjustment_t
value- value to set the Adjustment_t to
Returns
void

Definition at line 163 of file xadjustment.c.

163  {
164  if (!adj) return;
165  if (adj->type == CL_LOGSCALE)
166  v = powf(10,(v/adj->log_scale));
167  else if (adj->type == CL_LOGARITHMIC)
168  v = log10(v);
169  v = min(adj->max_value,max(adj->min_value, v));
170  check_value_changed(adj, &v);
171 }

References check_value_changed(), CL_LOGARITHMIC, CL_LOGSCALE, Adjustment_t::log_scale, max, Adjustment_t::max_value, min, Adjustment_t::min_value, and Adjustment_t::type.

◆ check_value_changed()

void check_value_changed ( Adjustment_t adj,
float *  value 
)

check_value_changed - check if Adjustment_t value have changed and send value_changed_callback (VALUE_CHANGED) and adj_callback (ADJ_INTERN) if so

Parameters
*adj- pointer to the Adjustment_t
value- value to check
Returns
void

Definition at line 241 of file xadjustment.c.

241  {
242  debug_print("Adjustment_t check_value_changed %f\n", *(value));
243  if(fabs(*(value) - adj->value)>=0.00001) {
244  adj->value = *(value);
245  adj->w->func.adj_callback(adj->w, NULL);
246  adj->w->func.value_changed_callback(adj->w, value);
247  }
248 }

References Func_t::adj_callback, debug_print, Widget_t::func, Adjustment_t::value, Func_t::value_changed_callback, and Adjustment_t::w.

◆ delete_adjustment()

void* delete_adjustment ( Adjustment_t adj)

delete_adjustment - freeing the memory of the Adjustment_t You usually don't need to call this, as it get handled by main_quit() -> destroy_widget()

Parameters
*adj- pointer to the Adjustment to free
Returns
*void

Definition at line 133 of file xadjustment.c.

133  {
134  if(adj) {
135  free(adj);
136  debug_print("Widget_t delete adjustment\n");
137  }
138  return NULL;
139 }

References debug_print.

◆ set_adjustment()

void set_adjustment ( Adjustment_t adj,
float  std_value,
float  value,
float  min_value,
float  max_value,
float  step,
CL_type  type 
)

*set_adjustment - set a new range to a existing Adjustment_t it will be created if it not exsits yet

Parameters
*w- pointer to the Widget_t request a Adjustment_t
std_value- standard value of the Adjustment_t
value- current value of the Adjustment_t
min_value- minimum value of the Adjustment_t
max_value- maximal value of the Adjustment_t
step- step to increase/decrease the Adjustment_t
type- set CL_type of Adjustment_t
Returns
*adj - pointer to Adjustment_t

Definition at line 80 of file xadjustment.c.

81  {
82  if (!adj) adj = (Adjustment_t*)malloc(sizeof(Adjustment_t));
83  assert(adj);
84 
85  switch(type) {
86  case (CL_LOGSCALE) :
87  *(adj) = (Adjustment_t) {
88  .w = adj->w,
89  .std_value = powf(10,(std_value/adj->log_scale)),
90  .value = powf(10,(value/adj->log_scale)),
91  .min_value = powf(10,(min_value/adj->log_scale)),
92  .max_value = powf(10,(max_value/adj->log_scale)),
93  .step = step,
94  .start_value = powf(10,(value/adj->log_scale)),
95  .scale = 1.0,
96  .type = type,
97  .log_scale = adj->log_scale
98  };
99  break;
100  case (CL_LOGARITHMIC) :
101  *(adj) = (Adjustment_t) {
102  .w = adj->w,
103  .std_value = log10(std_value),
104  .value = log10(value),
105  .min_value = log10(min_value),
106  .max_value = log10(max_value),
107  .step = step,
108  .start_value = log10(value),
109  .scale = 1.0,
110  .type = type,
111  .log_scale = adj->log_scale
112  };
113  break;
114  default:
115  *(adj) = (Adjustment_t) {
116  .w = adj->w,
117  .std_value = std_value,
118  .value = value,
119  .min_value = min_value,
120  .max_value = max_value,
121  .step = step,
122  .start_value = value,
123  .scale = 1.0,
124  .type = type,
125  .log_scale = adj->log_scale
126  };
127  break;
128  }
129 
130  debug_print("Widget_t set adjustment\n");
131 }

References CL_LOGARITHMIC, CL_LOGSCALE, debug_print, Adjustment_t::log_scale, Widget_t::scale, and Adjustment_t::w.

CL_TOGGLE
@ CL_TOGGLE
Definition: xadjustment.h:51
CL_type
CL_type
CL_type - define the type of the controller adjustment one of this types must be given when set up a ...
Definition: xadjustment.h:45
Adjustment_t::value
float value
Definition: xadjustment.h:86
CL_LOGARITHMIC
@ CL_LOGARITHMIC
Definition: xadjustment.h:61
min
#define min(x, y)
min - set a maximal value (x) as return value
Definition: xputty.h:78
CL_ENUM
@ CL_ENUM
Definition: xadjustment.h:55
Widget_t::pos_y
int pos_y
Definition: xwidget.h:346
Adjustment_t::type
CL_type type
Definition: xadjustment.h:98
Adjustment_t::w
Widget_t * w
Definition: xadjustment.h:82
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
CL_VIEWPORT
@ CL_VIEWPORT
Definition: xadjustment.h:57
Adjustment_t::log_scale
float log_scale
Definition: xadjustment.h:100
Widget_t::pos_x
int pos_x
Definition: xwidget.h:344
CL_LOGSCALE
@ CL_LOGSCALE
Definition: xadjustment.h:63
Adjustment_t
Adjustment_t - struct to hold a controller adjustment.
Definition: xadjustment.h:80
debug_print
#define debug_print(...)
debug_print - print out state messages when compiled with the -DDEBUG flag
Definition: xputty.h:64
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
CL_BUTTON
@ CL_BUTTON
Definition: xadjustment.h:53
CL_METER
@ CL_METER
Definition: xadjustment.h:59
Adjustment_t::max_value
float max_value
Definition: xadjustment.h:90
Func_t::adj_callback
xevfunc adj_callback
Definition: xwidget.h:84
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
CL_NONE
@ CL_NONE
Definition: xadjustment.h:47
Adjustment_t::start_value
float start_value
Definition: xadjustment.h:94
Adjustment_t::scale
float scale
Definition: xadjustment.h:96
max
#define max(x, y)
max - set a minimal value (x) as return value
Definition: xputty.h:86
Func_t::value_changed_callback
xevfunc value_changed_callback
Definition: xwidget.h:85
Adjustment_t::step
float step
Definition: xadjustment.h:92
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88
check_value_changed
void check_value_changed(Adjustment_t *adj, float *value)
check_value_changed - check if Adjustment_t value have changed and send value_changed_callback (VALUE...
Definition: xadjustment.c:241
Widget_t::adj_x
Adjustment_t * adj_x
Definition: xwidget.h:330
CL_CONTINUOS
@ CL_CONTINUOS
Definition: xadjustment.h:49