Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
knob.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __GUI_WIDGETS_KNOB_H__
11#define __GUI_WIDGETS_KNOB_H__
12
13#include "utils/types.h"
14
15#include "gtk_wrapper.h"
16
17#define KNOB_WIDGET_TYPE (knob_widget_get_type ())
18G_DECLARE_FINAL_TYPE (KnobWidget, knob_widget, Z, KNOB_WIDGET, GtkWidget)
19
20
29enum class KnobType
30{
31 KNOB_TYPE_NORMAL,
32
35};
36
37typedef struct Port Port;
38
39typedef struct _KnobWidget
40{
41 GtkWidget parent_instance;
42
43 KnobType type;
44
47
50
54
57
60
63
66
68 void * object;
69
71 int size;
73 bool hover;
75 float zero;
77 bool arc;
79 int bevel;
81 bool flat;
83 float min;
85 float max;
86
88 GdkRGBA start_color;
90 GdkRGBA end_color;
91
93 GtkGestureDrag * drag;
95 double last_x;
97 double last_y;
98
99 bool drag_updated;
100
101 PangoLayout * layout;
102
105
107 GtkPopoverMenu * popover_menu;
108} KnobWidget;
109
124 GenericFloatGetter get_val,
125 GenericFloatGetter get_default_val,
126 GenericFloatSetter set_val,
127 void * object,
128 KnobType type,
129 float min,
130 float max,
131 int size,
132 float zero);
133
134#define knob_widget_new_simple( \
135 getter, default_getter, setter, obj, min, max, size, zero) \
136 _knob_widget_new ( \
137 (GenericFloatGetter) getter, (GenericFloatGetter) default_getter, \
138 (GenericFloatSetter) setter, (void *) obj, KnobType::KNOB_TYPE_NORMAL, \
139 min, max, size, zero)
140
144#define knob_widget_new_port(conn, size) \
145 _knob_widget_new ( \
146 NULL, NULL, (void *) conn, KnobType::KNOB_TYPE_PORT_MULTIPLIER, 0.f, 1.f, \
147 size, 0.f)
148
153#endif
void(* GenericStringCopyGetter)(void *object, char *buf)
Getter prototype for strings to be saved in the given buffer.
Definition types.h:98
float(* GenericFloatGetter)(void *object)
Getter prototype for float values.
Definition types.h:77
void(* GenericFloatSetter)(void *object, float val)
Setter prototype for float values.
Definition types.h:82
KnobWidget * _knob_widget_new(GenericFloatGetter get_val, GenericFloatGetter get_default_val, GenericFloatSetter set_val, void *object, KnobType type, float min, float max, int size, float zero)
Creates a knob widget with the given options and binds it to the given value.
KnobType
Type of knob.
Definition knob.h:30
@ KNOB_TYPE_PORT_MULTIPLIER
Port connection multiplier.
double last_x
Used in gesture drag.
Definition knob.h:95
GdkRGBA start_color
Color away from zero point.
Definition knob.h:88
float zero
Zero point 0.0-1.0.
Definition knob.h:75
GenericFloatSetter setter
Setter.
Definition knob.h:56
GenericFloatGetter getter
Getter for the actual value.
Definition knob.h:46
GenericFloatGetter snapped_getter
Getter for a snapped value (used if passed).
Definition knob.h:53
float min
Min value (eg, 1).
Definition knob.h:83
bool flat
Flat or 3D.
Definition knob.h:81
GenericFloatSetter end_setter
Float setter for drag end.
Definition knob.h:62
GdkRGBA end_color
Color closer to zero point.
Definition knob.h:90
GtkGestureDrag * drag
Used in drag gesture.
Definition knob.h:93
bool arc
Draw arc around the knob or not.
Definition knob.h:77
float last_real_val
Last drawn real val.
Definition knob.h:104
GtkPopoverMenu * popover_menu
To be optionally used for context menus.
Definition knob.h:107
float max
Max value (eg, 180).
Definition knob.h:85
GenericFloatGetter default_getter
Getter for the default actual value.
Definition knob.h:49
int size
Size in px.
Definition knob.h:71
double last_y
Used in gesture drag.
Definition knob.h:97
void * object
Object to call get/set with.
Definition knob.h:68
GenericStringCopyGetter hover_str_getter
Value to show when hovering (optional).
Definition knob.h:65
int bevel
Bevel.
Definition knob.h:79
GenericFloatSetter init_setter
Float setter for drag begin.
Definition knob.h:59
bool hover
Whether hovering or not.
Definition knob.h:73
Must ONLY be created via port_new()
Definition port.h:136
Custom types.