libxputty  0.1
A damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces
xtuner.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 
22 #include "xtuner.h"
23 #include "xtuner_private.h"
24 
25 void tuner_set_temperament (Widget_t *w, float temp) {
26  XTuner *xt = (XTuner *)w->parent_struct;
27  xt->temperament = temp;
28  if((int)temp == 0) xt->temp_adjust = 3;
29  else if((int)temp == 1) xt->temp_adjust = 6;
30  else if((int)temp == 2) xt->temp_adjust = 7;
31  else if((int)temp == 3) xt->temp_adjust = 9;
32  else if((int)temp == 4) xt->temp_adjust = 15;
33  else xt->temp_adjust = 3;
34 }
35 
36 void tuner_set_ref_freq (Widget_t *w, float ref) {
37  XTuner *xt = (XTuner *)w->parent_struct;
38  xt->ref_freq = ref;
39 }
40 
41 static void xtuner_mem_free(void *w_, void* user_data) {
42  Widget_t *w = (Widget_t*)w_;
43  XTuner *xt = (XTuner *)w->parent_struct;
44  free(xt);
45 }
46 
47 Widget_t* add_tuner(Widget_t *parent, const char * label,
48  int x, int y, int width, int height) {
49 
50  XTuner *xt = (XTuner*)malloc(sizeof(XTuner));
51  Widget_t *wid = create_widget(parent->app, parent, x, y, width, height);
52  wid->parent_struct = xt;
53  wid->label = label;
54  wid->adj_y = add_adjustment(wid,20.0, 20.0, 20.0, 20000.0,0.01, CL_CONTINUOS);
55  wid->adj = wid->adj_y;
56  wid->scale.gravity = CENTER;
57  wid->flags &= ~USE_TRANSPARENCY;
58  wid->flags |= HAS_MEM;
59  cairo_select_font_face (wid->crb, "Sans", CAIRO_FONT_SLANT_NORMAL,
60  CAIRO_FONT_WEIGHT_NORMAL);
61  wid->func.mem_free_callback = xtuner_mem_free;
63  return wid;
64 }
XTuner
Definition: xtuner.h:33
Resize_t::gravity
Gravity gravity
Definition: xwidget.h:192
Widget_t::parent_struct
void * parent_struct
Definition: xwidget.h:306
create_widget
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition: xwidget.c:268
Func_t::expose_callback
xevfunc expose_callback
Definition: xwidget.h:80
CENTER
@ CENTER
Definition: xwidget.h:165
Widget_t::crb
cairo_t * crb
Definition: xwidget.h:318
Widget_t::flags
long long flags
Definition: xwidget.h:324
Widget_t::adj
Adjustment_t * adj
Definition: xwidget.h:334
xtuner_private.h
XTuner::temperament
float temperament
Definition: xtuner.h:35
Widget_t::scale
Resize_t scale
Definition: xwidget.h:356
HAS_MEM
@ HAS_MEM
Definition: xwidget.h:251
Widget_t::app
Xputty * app
Definition: xwidget.h:300
USE_TRANSPARENCY
@ USE_TRANSPARENCY
Definition: xwidget.h:243
Widget_t
Widget_t - struct to hold the basic Widget_t info.
Definition: xwidget.h:298
XTuner::temp_adjust
int temp_adjust
Definition: xtuner.h:36
tuner_set_temperament
void tuner_set_temperament(Widget_t *w, float temp)
Definition: xtuner.c:25
Func_t::mem_free_callback
xevfunc mem_free_callback
Definition: xwidget.h:87
_draw_tuner
void _draw_tuner(void *w_, void *user_data)
_draw_tuner - draw the tuner on expose call
Definition: xtuner_private.c:69
Widget_t::adj_y
Adjustment_t * adj_y
Definition: xwidget.h:332
Widget_t::func
Func_t func
Definition: xwidget.h:310
xtuner.h
XTuner::ref_freq
float ref_freq
Definition: xtuner.h:34
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
add_tuner
Widget_t * add_tuner(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_tuner - add a tuner widget to a Widget_t
Definition: xtuner.c:47
tuner_set_ref_freq
void tuner_set_ref_freq(Widget_t *w, float ref)
Definition: xtuner.c:36
Widget_t::label
const char * label
Definition: xwidget.h:326
CL_CONTINUOS
@ CL_CONTINUOS
Definition: xadjustment.h:49