31static void set_default_theme(
Xputty *main) {
34 { 0.68, 0.44, 0.00, 1.00},
35 { 0.1, 0.1, 0.1, 1.0},
36 { 0.1, 0.1, 0.1, 1.0},
37 { 0.85, 0.52, 0.00, 1.00},
38 { 0.1, 0.1, 0.1, 0.2},
39 { 0.0, 0.0, 0.0, 1.0},
44 { 1.0, 1.0, 1.0, 1.0},
45 { 0.25, 0.25, 0.25, 1.0},
46 { 0.2, 0.2, 0.2, 1.0},
47 { 0.7, 0.7, 0.7, 1.0},
48 { 0.1, 0.1, 0.1, 0.4},
49 { 0.3, 0.3, 0.3, 1.0},
54 { 0.9, 0.9, 0.9, 1.0},
55 { 0.2, 0.2, 0.2, 1.0},
56 { 0.1, 0.1, 0.1, 1.0},
57 { 1.0, 1.0, 1.0, 1.0},
58 { 0.18, 0.18, 0.18, 0.2},
59 { 0.18, 0.18, 0.18, 1.0},
60 { 0.18, 0.18, 0.28, 1.0}
64static void set_default_knob_color(
KnobColors* kp) {
67 { 0.349, 0.313, 0.243, 1.0},
68 { 0.349, 0.235, 0.011, 1.0},
69 { 0.15, 0.15, 0.15, 1.0},
70 { 0.1, 0.1, 0.1, 1.00},
71 { 0.05, 0.05, 0.05, 1.0},
72 { 0.349, 0.313, 0.243, 1.0},
73 { 0.349, 0.235, 0.011, 1.0},
74 { 0.15, 0.15, 0.15, 1.0},
75 { 0.1, 0.1, 0.1, 1.00},
76 { 0.05, 0.05, 0.05, 1.0},
81static void draw_window(
void *w_,
void* user_data) {
87 cairo_set_line_width(w->
crb,4);
90 cairo_text_extents_t extents;
93 cairo_text_extents(w->
crb,w->
label , &extents);
94 double tw = extents.width/2.0;
100 cairo_new_path (w->
crb);
104static void draw_my_knob(
void *w_,
void* user_data) {
107 int width = w->
width-2;
110 const double scale_zero = 20 * (M_PI/180);
115 int grow = (width > height) ? height:width;
120 int knobx = (width - knob_x) * 0.5;
121 int knobx1 = width* 0.5;
123 int knoby = (height - knob_y) * 0.5;
124 int knoby1 = height * 0.5;
127 double angle = scale_zero + knobstate * 2 * (M_PI - scale_zero);
129 double pointer_off =knob_x/3.5;
130 double radius = min(knob_x-pointer_off, knob_y-pointer_off) / 2;
131 double lengh_x = (knobx+radius+pointer_off/2) - radius * sin(angle);
132 double lengh_y = (knoby+radius+pointer_off/2) + radius * cos(angle);
133 double radius_x = (knobx+radius+pointer_off/2) - radius/ 1.18 * sin(angle);
134 double radius_y = (knoby+radius+pointer_off/2) + radius/ 1.18 * cos(angle);
135 cairo_pattern_t* pat;
136 cairo_new_path (w->
crb);
138 pat = cairo_pattern_create_linear (0, 0, 0, knob_y);
139 cairo_pattern_add_color_stop_rgba (pat, 1, ui->kp->p1f[0],ui->kp->p1f[1],ui->kp->p1f[2],ui->kp->p1f[3]);
140 cairo_pattern_add_color_stop_rgba (pat, 0.75, ui->kp->p2f[0],ui->kp->p2f[1],ui->kp->p2f[2],ui->kp->p2f[3]);
141 cairo_pattern_add_color_stop_rgba (pat, 0.5, ui->kp->p3f[0],ui->kp->p3f[1],ui->kp->p3f[2],ui->kp->p3f[3]);
142 cairo_pattern_add_color_stop_rgba (pat, 0.25, ui->kp->p4f[0],ui->kp->p4f[1],ui->kp->p4f[2],ui->kp->p4f[3]);
143 cairo_pattern_add_color_stop_rgba (pat, 0, ui->kp->p5f[0],ui->kp->p5f[1],ui->kp->p5f[2],ui->kp->p5f[3]);
145 cairo_scale (w->
crb, 0.95, 1.05);
146 cairo_arc(w->
crb,knobx1+arc_offset/2, knoby1-arc_offset, knob_x/2.2, 0, 2 * M_PI );
147 cairo_set_source (w->
crb, pat);
148 cairo_fill_preserve (w->
crb);
149 cairo_set_source_rgb (w->
crb, 0.1, 0.1, 0.1);
150 cairo_set_line_width(w->
crb,1);
151 cairo_stroke(w->
crb);
152 cairo_scale (w->
crb, 1.05, 0.95);
153 cairo_new_path (w->
crb);
154 cairo_pattern_destroy (pat);
157 pat = cairo_pattern_create_linear (0, 0, 0, knob_y);
158 cairo_pattern_add_color_stop_rgba (pat, 0, ui->kp->p1k[0],ui->kp->p1k[1],ui->kp->p1k[2],ui->kp->p1k[3]);
159 cairo_pattern_add_color_stop_rgba (pat, 0.25, ui->kp->p2k[0],ui->kp->p2k[1],ui->kp->p2k[2],ui->kp->p2k[3]);
160 cairo_pattern_add_color_stop_rgba (pat, 0.5, ui->kp->p3k[0],ui->kp->p3k[1],ui->kp->p3k[2],ui->kp->p3k[3]);
161 cairo_pattern_add_color_stop_rgba (pat, 0.75, ui->kp->p4k[0],ui->kp->p4k[1],ui->kp->p4k[2],ui->kp->p4k[3]);
162 cairo_pattern_add_color_stop_rgba (pat, 1, ui->kp->p5k[0],ui->kp->p5k[1],ui->kp->p5k[2],ui->kp->p5k[3]);
164 cairo_arc(w->
crb,knobx1, knoby1, knob_x/2.6, 0, 2 * M_PI );
165 cairo_set_source (w->
crb, pat);
166 cairo_fill_preserve (w->
crb);
167 cairo_set_source_rgb (w->
crb, 0.1, 0.1, 0.1);
168 cairo_set_line_width(w->
crb,1);
169 cairo_stroke(w->
crb);
170 cairo_new_path (w->
crb);
171 cairo_pattern_destroy (pat);
176 cairo_set_line_cap(w->
crb, CAIRO_LINE_CAP_ROUND);
177 cairo_set_line_join(w->
crb, CAIRO_LINE_JOIN_BEVEL);
178 cairo_move_to(w->
crb, radius_x, radius_y);
179 cairo_line_to(w->
crb,lengh_x,lengh_y);
180 cairo_set_line_width(w->
crb,3);
181 cairo_stroke(w->
crb);
182 cairo_new_path (w->
crb);
184 cairo_text_extents_t extents;
189 const char* format[] = {
"%.1f",
"%.2f",
"%.3f"};
191 snprintf(s, 63,
"%d", (
int) value);
192 }
else if (fabs(w->
adj->
step)>0.09) {
193 snprintf(s, 63, format[1-1], value);
195 snprintf(s, 63, format[2-1], value);
198 cairo_text_extents(w->
crb, s, &extents);
199 cairo_move_to (w->
crb, knobx1-extents.width/2, knoby1+extents.height/2);
200 cairo_show_text(w->
crb, s);
201 cairo_new_path (w->
crb);
206 cairo_text_extents(w->
crb,w->
label , &extents);
208 cairo_move_to (w->
crb, knobx1-extents.width/2, height-2 );
210 cairo_new_path (w->
crb);
214static void value_changed(
void *w_,
void* user_data) {
217 if (ui->block_event != w->
data) {
219 ui->write_function(ui->controller,w->
data,
sizeof(
float),0,&v);
222 ui->block_event = -1;
227 X11_UI* ui,
int x,
int y,
int width,
int height) {
238 X11_UI* ui,
int x,
int y,
int width,
int height) {
248 X11_UI* ui,
int x,
int y,
int width,
int height) {
258 X11_UI* ui,
int x,
int y,
int width,
int height) {
268 size_t len,
int active,
X11_UI* ui,
int x,
int y,
int width,
int height) {
271 for(; st < len; st++) {
282static LV2UI_Handle instantiate(
const LV2UI_Descriptor * descriptor,
283 const char * plugin_uri,
const char * bundle_path,
284 LV2UI_Write_Function write_function,
285 LV2UI_Controller controller, LV2UI_Widget * widget,
286 const LV2_Feature *
const * features) {
291 fprintf(stderr,
"ERROR: failed to instantiate plugin with URI %s\n", plugin_uri);
304 for (; features[i]; ++i) {
305 if (!strcmp(features[i]->URI, LV2_UI__parent)) {
307 }
else if (!strcmp(features[i]->URI, LV2_UI__resize)) {
308 ui->
resize = (LV2UI_Resize*)features[i]->data;
313 fprintf(stderr,
"ERROR: Failed to open parentXwindow for %s\n", plugin_uri);
320 set_default_knob_color(ui->
kp);
321 set_default_theme(&ui->
main);
346 return (LV2UI_Handle)ui;
350static void cleanup(LV2UI_Handle handle) {
367static void port_event(LV2UI_Handle handle, uint32_t port_index,
368 uint32_t buffer_size, uint32_t format,
369 const void * buffer) {
371 float value = *(
float*)buffer;
373 for (;i<CONTROLS;i++) {
386static int ui_idle(LV2UI_Handle handle) {
394static int ui_resize(LV2UI_Feature_Handle handle,
int w,
int h) {
402static const void* extension_data(
const char* uri) {
403 static const LV2UI_Idle_Interface idle = { ui_idle };
404 static const LV2UI_Resize resize = { 0 ,ui_resize };
405 if (!strcmp(uri, LV2_UI__idleInterface)) {
408 if (!strcmp(uri, LV2_UI__resize)) {
414static const LV2UI_Descriptor descriptors[] = {
415 {PLUGIN_UI_URI,instantiate,cleanup,port_event,extension_data},
416#ifdef GXPLUGIN_UI_URI2
417 {PLUGIN_UI_URI2,instantiate,cleanup,port_event,extension_data},
428 if (index >=
sizeof(descriptors) /
sizeof(descriptors[0])) {
431 return descriptors + index;
LV2_SYMBOL_EXPORT const LV2UI_Descriptor * lv2ui_descriptor(uint32_t index)
Widget_t * add_my_knob(Widget_t *w, PortIndex index, const char *label, X11_UI *ui, int x, int y, int width, int height)
Widget_t * add_my_switch_image(Widget_t *w, PortIndex index, const char *label, X11_UI *ui, int x, int y, int width, int height)
Widget_t * add_my_image_knob(Widget_t *w, PortIndex index, const char *label, X11_UI *ui, int x, int y, int width, int height)
Widget_t * add_my_value_knob(Widget_t *w, PortIndex index, const char *label, X11_UI *ui, int x, int y, int width, int height)
Widget_t * add_my_combobox(Widget_t *w, PortIndex index, const char *label, const char **items, size_t len, int active, X11_UI *ui, int x, int y, int width, int height)
void plugin_create_controller_widgets(X11_UI *ui, const char *plugin_uri)
const char * plugin_set_name()
void plugin_value_changed(X11_UI *ui, Widget_t *w, PortIndex index)
void plugin_cleanup(X11_UI *ui)
void plugin_set_window_size(int *w, int *h, const char *plugin_uri)
void plugin_port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void *buffer)
Color_t - struct used to set cairo color for Widget_t.
xevfunc value_changed_callback
Widget_t * widget[CONTROLS]
LV2UI_Write_Function write_function
Xputty - the main struct. It should be declared before any other call to a Xputty function....
void adj_set_value(Adjustment_t *adj, float value)
adj_set_value - set the current value to the Adjustment_t
float adj_get_value(Adjustment_t *adj)
adj_get_value - get the current value of the Adjustment_t
float adj_get_state(Adjustment_t *adj)
adj_get_state - get the current state of the Adjustment_t
Color_state get_color_state(Widget_t *wid)
get_color_state - get the Color_state to use in relation to the Widget_t state
void use_text_color_scheme(Widget_t *w, Color_state st)
use_text_color_scheme - use text Colors to paint on Widget_t
void set_pattern(Widget_t *w, Colors *from, Colors *to, Color_mod mod)
set_pattern - set pattern for the selected Colors
void combobox_set_active_entry(Widget_t *w, int active)
combobox_set_active_entry - set the active combobox entry
void combobox_add_entry(Widget_t *wid, const char *label)
combobox_add_entry - add a entry to the combobox
Widget_t * add_combobox(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_combobox - add a combobox
Widget_t * add_image_knob(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_image_knob - add a knob from image to a Widget_t without value display on the knob connect to fun...
Widget_t * add_knob(Widget_t *parent, const char *label, int x, int y, int width, int height)
add_knob - add a knob to a Widget_t connect to func.value_changed_callback to implement your actions ...
void main_quit(Xputty *main)
main_quit - destroy all remaining Widget_t's from the main->childlist. Free all resources which may...
void main_init(Xputty *main)
main_init - open the Display and init the main->childlist. Set the bool run to true....
void run_embedded(Xputty *main)
run_embedded - the main event loop to run embedded UI's. It should be start after your Widget_t's b...