libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xadjustment.h
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 #pragma once
22 
23 #ifndef XADJUSTMENT_H_
24 #define XADJUSTMENT_H_
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include "xputty.h"
31 
32 
33 /**
34  *
35  * @brief CL_type - define the type of the controller adjustment
36  * one of this types must be given when set up a Adjustment_t for a Wdiget_t
37  * @param CL_NONE - Widget_t didn't request a adjustment
38  * @param CL_CONTINUOS - Widget_t request a continuos adjustment
39  * @param CL_TOGGLE - Widget_t request a toggle adjustment
40  * @param CL_BUTTON - Widget_t request a button adjustment
41  * @param CL_ENUM - Widget_t request a enum adjustment
42  * @param CL_LOGARITHMIC - Widget_t request a logarithmic adjustment
43  */
44 
45 typedef enum {
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;
65 
66 /**
67  *
68  * @brief Adjustment_t - struct to hold a controller adjustment
69  * @param *w - pointer to the Widget_t contain the adjustment
70  * @param std_value - the standart value for the adjustment
71  * @param value - the current value of the adjustment
72  * @param min_value - the minimal value of the adjustment
73  * @param max_value - the maximal value of the adjustment
74  * @param step - the step to increase/decrease the adjustment
75  * @param start_value - internal use to store the current value when pointer
76  * movement starts
77  * @param type - should be on of the CL_type
78  */
79 
80 struct Adjustment_t {
81 /** pointer to the Widget_t contain the adjustment */
83 /** the standart value for the adjustment */
84  float std_value;
85 /** the current value of the adjustment */
86  float value;
87 /** the minimal value of the adjustment */
88  float min_value;
89 /** the maximal value of the adjustment */
90  float max_value;
91 /** the step to increase/decrease the adjustment */
92  float step;
93 /** internal use to store the current value when pointer movement starts */
94  float start_value;
95 /** the scalling to increase/decrease the adjustment on pointer motion*/
96  float scale;
97 /** should be on of the CL_ type */
99 /** scale factor for logarithmic adjustment **/
100  float log_scale;
101 };
102 
103 /**
104  * @brief *add_adjustment - adding a adjustment to a Widget_t
105  * @param *w - pointer to the Widget_t request a Adjustment_t
106  * @param std_value - standard value of the Adjustment_t
107  * @param value - current value of the Adjustment_t
108  * @param min_value - minimum value of the Adjustment_t
109  * @param max_value - maximal value of the Adjustment_t
110  * @param step - step to increase/decrease the Adjustment_t
111  * @param type - set CL_type of Adjustment_t
112  * @return *adj - pointer to the Adjustment_t
113  */
114 
115 Adjustment_t *add_adjustment(Widget_t *w, float std_value, float value,
116  float min_value,float max_value, float step, CL_type type);
117 
118 
119 /**
120  * @brief *set_adjustment - set a new range to a existing Adjustment_t
121  * it will be created if it not exsits yet
122  * @param *w - pointer to the Widget_t request a Adjustment_t
123  * @param std_value - standard value of the Adjustment_t
124  * @param value - current value of the Adjustment_t
125  * @param min_value - minimum value of the Adjustment_t
126  * @param max_value - maximal value of the Adjustment_t
127  * @param step - step to increase/decrease the Adjustment_t
128  * @param type - set CL_type of Adjustment_t
129  * @return *adj - pointer to Adjustment_t
130  */
131 
132 void set_adjustment(Adjustment_t *adj, float std_value, float value,
133  float min_value,float max_value, float step, CL_type type);
134 
135 /**
136  * @brief delete_adjustment - freeing the memory of the Adjustment_t
137  * You usually don't need to call this, as it get handled by main_quit() -> destroy_widget()
138  * @param *adj - pointer to the Adjustment to free
139  * @return *void
140  */
141 
142 void *delete_adjustment(Adjustment_t *adj);
143 
144 /**
145  * @brief adj_get_state - get the current state of the Adjustment_t
146  * @param *adj - pointer to the Adjustment_t
147  * @return float - return the Adjustment_t state mapped to (0<->1)
148  */
149 
150 float adj_get_state(Adjustment_t *adj);
151 
152 /**
153  * @brief adj_set_state - set the current state of the Adjustment_t
154  * @param *adj - pointer to the Adjustment_t
155  * @return float - set the Adjustment_t state mapped to (0<->1)
156  */
157 
158 void adj_set_state(Adjustment_t *adj, float state);
159 
160 /**
161  * @brief adj_get_value - get the current value of the Adjustment_t
162  * @param *adj - pointer to the Adjustment_t
163  * @return float - return the Adjustment_t value
164  */
165 
166 float adj_get_value(Adjustment_t *adj);
167 
168 /**
169  * @brief adj_set_value - set the current value to the Adjustment_t
170  * @param *adj - pointer to the Adjustment_t
171  * @param value - value to set the Adjustment_t to
172  * @return void
173  */
174 
175 void adj_set_value(Adjustment_t *adj, float value);
176 
177 /**
178  * @brief adj_set_start_value - internal use to store the value when pointer movment starts
179  * @param *w - pointer to Widget_t containing the Adjustment_t
180  * @return void
181  */
182 
183 void adj_set_start_value(void *w);
184 
185 /**
186  * @brief adj_set_scale - internal use to scale the pointer movement (0.1 -1.0)
187  * @param *adj - pointer to the Adjustment_t
188  * @param value - value to set the scaleing factor to
189  * @return void
190  */
191 
192 void adj_set_scale(Adjustment_t *adj, float value);
193 
194 /**
195  * @brief adj_set_log_scale - internal use to set the logarithmic scale
196  * @param *adj - pointer to the Adjustment_t
197  * @param value - value to set the scaleing factor to
198  * @return void
199  */
200 
201 void adj_set_log_scale(Adjustment_t *adj, float value);
202 
203 /**
204  * @brief adj_set_motion_state - internal use to set value and state of the Adjustment_t
205  * on mouse pointer movment
206  * @param *w - pointer to Widget_t containing Adjustment_t
207  * @param x - movment on the x-axis
208  * @param y - movement on the y-axis
209  * @return void
210  */
211 
212 void adj_set_motion_state(void *w, float x, float y);
213 
214 /**
215  * @brief check_value_changed - check if Adjustment_t value have changed and send
216  * value_changed_callback (VALUE_CHANGED) and adj_callback (ADJ_INTERN) if so
217  * @param *adj - pointer to the Adjustment_t
218  * @param value - value to check
219  * @return void
220  */
221 
222 void check_value_changed(Adjustment_t *adj, float *value);
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif //XADJUSTMENT_H_
Adjustment_t::std_value
float std_value
Definition: xadjustment.h:84
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
Definition: xadjustment.c:173
CL_TOGGLE
@ CL_TOGGLE
Definition: xadjustment.h:51
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
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
CL_ENUM
@ CL_ENUM
Definition: xadjustment.h:55
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
Definition: xadjustment.c:183
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 movme...
Definition: xadjustment.c:187
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
Adjustment_t::type
CL_type type
Definition: xadjustment.h:98
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)
Definition: xadjustment.c:179
adj_set_value
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
Definition: xadjustment.c:163
Adjustment_t::w
Widget_t * w
Definition: xadjustment.h:82
xputty.h
CL_VIEWPORT
@ CL_VIEWPORT
Definition: xadjustment.h:57
Adjustment_t::log_scale
float log_scale
Definition: xadjustment.h:100
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,...
Definition: xadjustment.c:133
CL_LOGSCALE
@ CL_LOGSCALE
Definition: xadjustment.h:63
Adjustment_t
Adjustment_t - struct to hold a controller adjustment.
Definition: xadjustment.h:80
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
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
Definition: xadjustment.c:80
adj_set_state
void adj_set_state(Adjustment_t *adj, float state)
adj_set_state - set the current state of the Adjustment_t
Definition: xadjustment.c:141
CL_NONE
@ CL_NONE
Definition: xadjustment.h:47
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
Adjustment_t::start_value
float start_value
Definition: xadjustment.h:94
Adjustment_t::scale
float scale
Definition: xadjustment.h:96
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
Adjustment_t::step
float step
Definition: xadjustment.h:92
Adjustment_t::min_value
float min_value
Definition: xadjustment.h:88
CL_CONTINUOS
@ CL_CONTINUOS
Definition: xadjustment.h:49