2 * Custom controls (line graph, knob).
3 * Copyright (C) 2007-2010 Krzysztof Foltman, Torben Hohn, Markus Schmidt
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include <calf/giface.h>
23 #include <calf/custom_ctl.h>
24 #include <gdk/gdkkeysyms.h>
31 using namespace calf_plugins
;
34 ///////////////////////////////////////// utility functions ///////////////////////////////////////////////
36 void line_graph_background(cairo_t
* c
, int x
, int y
, int sx
, int sy
, int ox
, int oy
, float brightness
, int shadow
, float lights
, float dull
)
38 float br
= brightness
* 0.5 + 0.5;
40 // outer frame (black)
44 c
, pad
+ x
, pad
+ y
, sx
+ ox
* 2 - pad
* 2, sy
+ oy
* 2 - pad
* 2);
45 cairo_set_source_rgb(c
, 0, 0, 0);
51 c
, pad
+ x
, pad
+ y
, sx
+ ox
* 2 - pad
* 2, sy
+ oy
* 2 - pad
* 2);
52 cairo_pattern_t
*pat2
= cairo_pattern_create_linear (
53 x
, y
, x
, y
+ sy
+ oy
* 2 - pad
* 2);
54 cairo_pattern_add_color_stop_rgba (pat2
, 0, 0.23, 0.23, 0.23, 1);
55 cairo_pattern_add_color_stop_rgba (pat2
, 0.33, 0.13, 0.13, 0.13, 1);
56 cairo_pattern_add_color_stop_rgba (pat2
, 0.33, 0.05, 0.05, 0.05, 1);
57 cairo_pattern_add_color_stop_rgba (pat2
, 0.5, 0, 0, 0, 1);
58 cairo_set_source (c
, pat2
);
60 cairo_pattern_destroy(pat2
);
62 cairo_rectangle(c
, x
+ ox
- 1, y
+ oy
- 1, sx
+ 2, sy
+ 2);
63 cairo_set_source_rgb (c
, 0, 0, 0);
66 // inner yellowish screen
67 cairo_pattern_t
*pt
= cairo_pattern_create_linear(x
+ ox
, y
+ oy
, x
+ ox
, y
+ sy
);
68 cairo_pattern_add_color_stop_rgb(pt
, 0.0, br
* 0.71, br
* 0.82, br
* 0.33);
69 cairo_pattern_add_color_stop_rgb(pt
, 1.0, br
* 0.89, br
* 1.00, br
* 0.54);
70 cairo_set_source (c
, pt
);
71 cairo_rectangle(c
, x
+ ox
, y
+ oy
, sx
, sy
);
73 cairo_pattern_destroy(pt
);
77 pt
= cairo_pattern_create_linear(x
+ ox
, y
+ oy
, x
+ ox
, y
+ oy
+ shadow
);
78 cairo_pattern_add_color_stop_rgba(pt
, 0.0, 0,0,0,0.6);
79 cairo_pattern_add_color_stop_rgba(pt
, 1.0, 0,0,0,0);
80 cairo_set_source (c
, pt
);
81 cairo_rectangle(c
, x
+ ox
, y
+ oy
, sx
, shadow
);
83 cairo_pattern_destroy(pt
);
86 pt
= cairo_pattern_create_linear(x
+ ox
, y
+ oy
, x
+ ox
+ (float)shadow
* 0.7, y
+ oy
);
87 cairo_pattern_add_color_stop_rgba(pt
, 0.0, 0,0,0,0.3);
88 cairo_pattern_add_color_stop_rgba(pt
, 1.0, 0,0,0,0);
89 cairo_set_source (c
, pt
);
90 cairo_rectangle(c
, x
+ ox
, y
+ oy
, (float)shadow
* 0.7, sy
);
92 cairo_pattern_destroy(pt
);
95 pt
= cairo_pattern_create_linear(x
+ ox
+ sx
- (float)shadow
* 0.7, y
+ oy
, x
+ ox
+ sx
, y
+ oy
);
96 cairo_pattern_add_color_stop_rgba(pt
, 0.0, 0,0,0,0);
97 cairo_pattern_add_color_stop_rgba(pt
, 1.0, 0,0,0,0.3);
98 cairo_set_source (c
, pt
);
99 cairo_rectangle(c
, x
+ ox
+ sx
- (float)shadow
* 0.7, y
+ oy
, 5, sy
);
101 cairo_pattern_destroy(pt
);
106 pt
= cairo_pattern_create_linear(x
+ ox
, y
+ oy
, x
+ ox
+ sx
/ 2, y
+ oy
);
107 cairo_pattern_add_color_stop_rgba(pt
, 0.0, 0,0,0,dull
);
108 cairo_pattern_add_color_stop_rgba(pt
, 1.0, 0,0,0,0);
109 cairo_set_source (c
, pt
);
110 cairo_rectangle(c
, x
+ ox
, y
+ oy
, sx
/ 2, sy
);
112 cairo_pattern_destroy(pt
);
115 pt
= cairo_pattern_create_linear(x
+ ox
+ sx
/ 2, y
+ oy
, x
+ ox
+ sx
, y
+ oy
);
116 cairo_pattern_add_color_stop_rgba(pt
, 0.0, 0,0,0,0);
117 cairo_pattern_add_color_stop_rgba(pt
, 1.0, 0,0,0,dull
);
118 cairo_set_source (c
, pt
);
119 cairo_rectangle(c
, x
+ ox
+ sx
/ 2, y
+ oy
, sx
/ 2, sy
);
121 cairo_pattern_destroy(pt
);
128 while(light_w
/ div
> 300)
131 cairo_rectangle(c
, x
+ ox
, y
+ oy
, sx
, sy
);
132 for(int i
= 0; i
< div
; i
++) {
133 cairo_pattern_t
*pt
= cairo_pattern_create_radial(
134 x
+ ox
+ w
* i
+ w
/ 2.f
, y
+ oy
, 1,
135 x
+ ox
+ w
* i
+ w
/ 2.f
, y
+ ox
+ sy
* 0.25, w
/ 2.f
);
136 cairo_pattern_add_color_stop_rgba (pt
, 0, 1, 1, 0.8, lights
);
137 cairo_pattern_add_color_stop_rgba (pt
, 1, 0.89, 1.00, 0.45, 0);
138 cairo_set_source (c
, pt
);
139 cairo_fill_preserve(c
);
140 pt
= cairo_pattern_create_radial(
141 x
+ ox
+ w
* i
+ w
/ 2.f
, y
+ oy
+ sy
, 1,
142 x
+ ox
+ w
* i
+ w
/ 2.f
, y
+ ox
+ sy
* 0.75, w
/ 2.f
);
143 cairo_pattern_add_color_stop_rgba (pt
, 0, 1, 1, 0.8, lights
);
144 cairo_pattern_add_color_stop_rgba (pt
, 1, 0.89, 1.00, 0.45, 0);
145 cairo_set_source (c
, pt
);
146 cairo_fill_preserve(c
);
151 ///////////////////////////////////////// phase graph ///////////////////////////////////////////////
154 calf_phase_graph_draw_background( cairo_t
*ctx
, int sx
, int sy
, int ox
, int oy
)
156 int cx
= ox
+ sx
/ 2;
157 int cy
= oy
+ sy
/ 2;
159 line_graph_background(ctx
, 0, 0, sx
, sy
, ox
, oy
);
160 cairo_set_source_rgb(ctx
, 0.35, 0.4, 0.2);
161 cairo_select_font_face(ctx
, "Sans", CAIRO_FONT_SLANT_NORMAL
, CAIRO_FONT_WEIGHT_NORMAL
);
162 cairo_set_font_size(ctx
, 9);
163 cairo_text_extents_t te
;
165 cairo_text_extents (ctx
, "M", &te
);
166 cairo_move_to (ctx
, cx
+ 5, oy
+ 12);
167 cairo_show_text (ctx
, "M");
169 cairo_text_extents (ctx
, "S", &te
);
170 cairo_move_to (ctx
, ox
+ 5, cy
- 5);
171 cairo_show_text (ctx
, "S");
173 cairo_text_extents (ctx
, "L", &te
);
174 cairo_move_to (ctx
, ox
+ 18, oy
+ 12);
175 cairo_show_text (ctx
, "L");
177 cairo_text_extents (ctx
, "R", &te
);
178 cairo_move_to (ctx
, ox
+ sx
- 22, oy
+ 12);
179 cairo_show_text (ctx
, "R");
181 cairo_set_line_width(ctx
, 1);
183 cairo_move_to(ctx
, ox
, oy
+ sy
* 0.5);
184 cairo_line_to(ctx
, ox
+ sx
, oy
+ sy
* 0.5);
187 cairo_move_to(ctx
, ox
+ sx
* 0.5, oy
);
188 cairo_line_to(ctx
, ox
+ sx
* 0.5, oy
+ sy
);
191 cairo_set_source_rgba(ctx
, 0, 0, 0, 0.2);
192 cairo_move_to(ctx
, ox
, oy
);
193 cairo_line_to(ctx
, ox
+ sx
, oy
+ sy
);
196 cairo_move_to(ctx
, ox
, oy
+ sy
);
197 cairo_line_to(ctx
, ox
+ sx
, oy
);
201 calf_phase_graph_copy_surface(cairo_t
*ctx
, cairo_surface_t
*source
, float fade
= 1.f
)
203 // copy a surface to a cairo context
205 cairo_set_source_surface(ctx
, source
, 0, 0);
207 float rnd
= (float)rand() / (float)RAND_MAX
/ 100;
208 cairo_paint_with_alpha(ctx
, fade
* 0.35 + 0.05 + rnd
);
215 calf_phase_graph_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
217 g_assert(CALF_IS_PHASE_GRAPH(widget
));
218 CalfPhaseGraph
*pg
= CALF_PHASE_GRAPH(widget
);
224 int sx
= widget
->allocation
.width
- ox
* 2, sy
= widget
->allocation
.height
- oy
* 2;
228 int cx
= ox
+ sx
/ 2;
229 int cy
= oy
+ sy
/ 2;
231 // some values as pointers for the audio plug-in call
233 float *data
= new float[2 * sx
];
234 float * phase_buffer
= 0;
238 bool use_fade
= true;
242 // cairo initialization stuff
243 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(widget
->window
));
247 if( pg
->background
== NULL
) {
248 // looks like its either first call or the widget has been resized.
249 // create the background surface (stolen from line graph)...
250 cairo_surface_t
*window_surface
= cairo_get_target(c
);
251 pg
->background
= cairo_surface_create_similar(window_surface
,
253 widget
->allocation
.width
,
254 widget
->allocation
.height
);
255 pg
->cache
= cairo_surface_create_similar(window_surface
,
257 widget
->allocation
.width
,
258 widget
->allocation
.height
);
260 // ...and draw some bling bling onto it...
261 ctx_back
= cairo_create(pg
->background
);
262 calf_phase_graph_draw_background(ctx_back
, sx
, sy
, ox
, oy
);
263 // ...and copy it to the cache
264 ctx_cache
= cairo_create(pg
->cache
);
265 calf_phase_graph_copy_surface(ctx_cache
, pg
->background
, 1);
267 ctx_back
= cairo_create(pg
->background
);
268 ctx_cache
= cairo_create(pg
->cache
);
271 pg
->source
->get_phase_graph(&phase_buffer
, &length
, &mode
, &use_fade
,
272 &fade
, &accuracy
, &display
);
274 // process some values set by the plug-in
276 accuracy
= 12 - accuracy
;
278 calf_phase_graph_copy_surface(ctx_cache
, pg
->background
, use_fade
? fade
: 1);
281 cairo_rectangle(ctx_cache
, ox
, oy
, sx
, sy
);
282 cairo_clip(ctx_cache
);
283 cairo_set_source_rgba(ctx_cache
, 0.35, 0.4, 0.2, 1);
285 for(int i
= 0; i
< length
; i
+= accuracy
) {
286 float l
= phase_buffer
[i
];
287 float r
= phase_buffer
[i
+ 1];
288 if(l
== 0.f
and r
== 0.f
) continue;
289 else if(r
== 0.f
and l
> 0.f
) _a
= M_PI
/ 2.f
;
290 else if(r
== 0.f
and l
< 0.f
) _a
= 3.f
*M_PI
/ 2.f
;
291 else _a
= pg
->_atan(l
/ r
, l
, r
);
292 double _R
= sqrt(pow(l
, 2) + pow(r
, 2));
294 float x
= (-1.f
)*_R
* cos(_a
);
295 float y
= _R
* sin(_a
);
296 // mask the cached values
300 cairo_rectangle (ctx_cache
, x
* rad
+ cx
, y
* rad
+ cy
, 1, 1);
304 cairo_rectangle (ctx_cache
, x
* rad
+ cx
- 0.25, y
* rad
+ cy
- 0.25, 1.5, 1.5);
308 cairo_rectangle (ctx_cache
, x
* rad
+ cx
- 0.5, y
* rad
+ cy
- 0.5, 2, 2);
312 if(i
== 0) cairo_move_to(ctx_cache
,
313 x
* rad
+ cx
, y
* rad
+ cy
);
314 else cairo_line_to(ctx_cache
,
315 x
* rad
+ cx
, y
* rad
+ cy
);
319 if(i
== 0) cairo_move_to(ctx_cache
,
320 x
* rad
+ cx
, y
* rad
+ cy
);
321 else cairo_line_to(ctx_cache
,
322 x
* rad
+ cx
, y
* rad
+ cy
);
331 cairo_fill(ctx_cache
);
334 cairo_fill(ctx_cache
);
337 cairo_set_line_width(ctx_cache
, 0.5);
338 cairo_stroke(ctx_cache
);
343 calf_phase_graph_copy_surface(c
, pg
->cache
, 1);
346 cairo_destroy(ctx_back
);
347 cairo_destroy(ctx_cache
);
349 // printf("exposed %p %dx%d %d+%d\n", widget->window, event->area.x, event->area.y, event->area.width, event->area.height);
354 calf_phase_graph_size_request (GtkWidget
*widget
,
355 GtkRequisition
*requisition
)
357 g_assert(CALF_IS_PHASE_GRAPH(widget
));
358 // CalfLineGraph *lg = CALF_LINE_GRAPH(widget);
362 calf_phase_graph_size_allocate (GtkWidget
*widget
,
363 GtkAllocation
*allocation
)
365 g_assert(CALF_IS_PHASE_GRAPH(widget
));
366 CalfPhaseGraph
*lg
= CALF_PHASE_GRAPH(widget
);
368 GtkWidgetClass
*parent_class
= (GtkWidgetClass
*) g_type_class_peek_parent( CALF_PHASE_GRAPH_GET_CLASS( lg
) );
371 cairo_surface_destroy(lg
->background
);
372 lg
->background
= NULL
;
374 widget
->allocation
= *allocation
;
375 GtkAllocation
&a
= widget
->allocation
;
376 if (a
.width
> a
.height
) {
377 a
.x
+= (a
.width
- a
.height
) / 2;
380 if (a
.width
< a
.height
) {
381 a
.y
+= (a
.height
- a
.width
) / 2;
384 parent_class
->size_allocate(widget
, &a
);
388 calf_phase_graph_class_init (CalfPhaseGraphClass
*klass
)
390 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
391 widget_class
->expose_event
= calf_phase_graph_expose
;
392 widget_class
->size_request
= calf_phase_graph_size_request
;
393 widget_class
->size_allocate
= calf_phase_graph_size_allocate
;
397 calf_phase_graph_unrealize (GtkWidget
*widget
, CalfPhaseGraph
*pg
)
400 cairo_surface_destroy(pg
->background
);
401 pg
->background
= NULL
;
405 calf_phase_graph_init (CalfPhaseGraph
*self
)
407 GtkWidget
*widget
= GTK_WIDGET(self
);
408 widget
->requisition
.width
= 40;
409 widget
->requisition
.height
= 40;
410 self
->background
= NULL
;
411 g_signal_connect(GTK_OBJECT(widget
), "unrealize", G_CALLBACK(calf_phase_graph_unrealize
), (gpointer
)self
);
415 calf_phase_graph_new()
417 return GTK_WIDGET(g_object_new (CALF_TYPE_PHASE_GRAPH
, NULL
));
421 calf_phase_graph_get_type (void)
423 static GType type
= 0;
425 static const GTypeInfo type_info
= {
426 sizeof(CalfPhaseGraphClass
),
427 NULL
, /* base_init */
428 NULL
, /* base_finalize */
429 (GClassInitFunc
)calf_phase_graph_class_init
,
430 NULL
, /* class_finalize */
431 NULL
, /* class_data */
432 sizeof(CalfPhaseGraph
),
434 (GInstanceInitFunc
)calf_phase_graph_init
437 GTypeInfo
*type_info_copy
= new GTypeInfo(type_info
);
439 for (int i
= 0; ; i
++) {
440 char *name
= g_strdup_printf("CalfPhaseGraph%u%d", ((unsigned int)(intptr_t)calf_phase_graph_class_init
) >> 16, i
);
441 if (g_type_from_name(name
)) {
445 type
= g_type_register_static( GTK_TYPE_DRAWING_AREA
,
457 ///////////////////////////////////////// toggle ///////////////////////////////////////////////
460 calf_toggle_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
462 g_assert(CALF_IS_TOGGLE(widget
));
464 CalfToggle
*self
= CALF_TOGGLE(widget
);
466 int x
= widget
->allocation
.x
+ widget
->allocation
.width
/ 2 - self
->size
* 15 - self
->size
* 2;
467 int y
= widget
->allocation
.y
+ widget
->allocation
.height
/ 2 - self
->size
* 10 - self
->size
* 3;
468 int width
= self
->size
* 34;
469 int height
= self
->size
* 26;
471 gdk_draw_pixbuf(GDK_DRAWABLE(widget
->window
),
472 widget
->style
->fg_gc
[0],
473 self
->toggle_image
[self
->size
- 1],
475 20 - self
->size
* 3 + (self
->size
* 20 + 40) * floor(.5 + gtk_range_get_value(GTK_RANGE(widget
))),
480 GDK_RGB_DITHER_NORMAL
, 0, 0);
485 calf_toggle_size_request (GtkWidget
*widget
,
486 GtkRequisition
*requisition
)
488 g_assert(CALF_IS_TOGGLE(widget
));
490 CalfToggle
*self
= CALF_TOGGLE(widget
);
492 requisition
->width
= 30 * self
->size
;
493 requisition
->height
= 20 * self
->size
;
497 calf_toggle_button_press (GtkWidget
*widget
, GdkEventButton
*event
)
499 g_assert(CALF_IS_TOGGLE(widget
));
500 GtkAdjustment
*adj
= gtk_range_get_adjustment(GTK_RANGE(widget
));
501 if (gtk_range_get_value(GTK_RANGE(widget
)) == adj
->lower
)
503 gtk_range_set_value(GTK_RANGE(widget
), adj
->upper
);
505 gtk_range_set_value(GTK_RANGE(widget
), adj
->lower
);
511 calf_toggle_key_press (GtkWidget
*widget
, GdkEventKey
*event
)
513 switch(event
->keyval
)
518 return calf_toggle_button_press(widget
, NULL
);
524 calf_toggle_class_init (CalfToggleClass
*klass
)
526 // GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
527 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
528 widget_class
->expose_event
= calf_toggle_expose
;
529 widget_class
->size_request
= calf_toggle_size_request
;
530 widget_class
->button_press_event
= calf_toggle_button_press
;
531 widget_class
->key_press_event
= calf_toggle_key_press
;
535 calf_toggle_init (CalfToggle
*self
)
537 GtkWidget
*widget
= GTK_WIDGET(self
);
538 GTK_WIDGET_SET_FLAGS (GTK_WIDGET(self
), GTK_CAN_FOCUS
);
539 widget
->requisition
.width
= 30;
540 widget
->requisition
.height
= 20;
542 GError
*error
= NULL
;
543 self
->toggle_image
[0] = gdk_pixbuf_new_from_file(PKGLIBDIR
"/toggle1_silver.png", &error
);
544 self
->toggle_image
[1] = gdk_pixbuf_new_from_file(PKGLIBDIR
"/toggle2_silver.png", &error
);
545 g_assert(self
->toggle_image
!= NULL
);
551 GtkAdjustment
*adj
= (GtkAdjustment
*)gtk_adjustment_new(0, 0, 1, 1, 0, 0);
552 return calf_toggle_new_with_adjustment(adj
);
555 static gboolean
calf_toggle_value_changed(gpointer obj
)
557 GtkWidget
*widget
= (GtkWidget
*)obj
;
558 CalfToggle
*self
= CALF_TOGGLE(widget
);
559 gtk_widget_queue_draw_area(widget
,
560 widget
->allocation
.x
- self
->size
* 2,
561 widget
->allocation
.y
- self
->size
* 3,
567 GtkWidget
*calf_toggle_new_with_adjustment(GtkAdjustment
*_adjustment
)
569 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_TOGGLE
, NULL
));
571 gtk_range_set_adjustment(GTK_RANGE(widget
), _adjustment
);
572 g_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(calf_toggle_value_changed
), widget
);
578 calf_toggle_get_type (void)
580 static GType type
= 0;
583 static const GTypeInfo type_info
= {
584 sizeof(CalfToggleClass
),
585 NULL
, /* base_init */
586 NULL
, /* base_finalize */
587 (GClassInitFunc
)calf_toggle_class_init
,
588 NULL
, /* class_finalize */
589 NULL
, /* class_data */
592 (GInstanceInitFunc
)calf_toggle_init
595 for (int i
= 0; ; i
++) {
596 char *name
= g_strdup_printf("CalfToggle%u%d",
597 ((unsigned int)(intptr_t)calf_toggle_class_init
) >> 16, i
);
598 if (g_type_from_name(name
)) {
602 type
= g_type_register_static( GTK_TYPE_RANGE
,
613 ///////////////////////////////////////// frame ///////////////////////////////////////////////
617 calf_frame_new(const char *label
)
619 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_FRAME
, NULL
));
620 CalfFrame
*self
= CALF_FRAME(widget
);
621 gtk_frame_set_label(GTK_FRAME(self
), label
);
625 calf_frame_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
627 g_assert(CALF_IS_FRAME(widget
));
628 if (gtk_widget_is_drawable (widget
)) {
630 GdkWindow
*window
= widget
->window
;
631 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(window
));
632 cairo_text_extents_t extents
;
634 int ox
= widget
->allocation
.x
;
635 int oy
= widget
->allocation
.y
;
636 int sx
= widget
->allocation
.width
;
637 int sy
= widget
->allocation
.height
;
646 cairo_rectangle(c
, ox
, oy
, sx
, sy
);
650 const gchar
*lab
= gtk_frame_get_label(GTK_FRAME(widget
));
652 cairo_select_font_face(c
, "Sans",
653 CAIRO_FONT_SLANT_NORMAL
,
654 CAIRO_FONT_WEIGHT_NORMAL
);
655 cairo_set_font_size(c
, size
);
657 cairo_text_extents(c
, lab
, &extents
);
659 double lw
= extents
.width
+ txp
* 2.;
661 cairo_set_line_width(c
, 1.);
663 cairo_move_to(c
, ox
+ rad
+ txp
+ m
, oy
+ size
- 2 + m
);
664 cairo_set_source_rgb(c
, 0.99,0.99,0.99);
665 cairo_show_text(c
, lab
);
667 cairo_set_source_rgb(c
, 0.9,0.9,0.9);
670 cairo_move_to(c
, ox
+ a
+ m
, oy
+ pad
+ rad
+ a
+ m
);
671 cairo_arc (c
, ox
+ rad
+ a
+ m
, oy
+ rad
+ a
+ pad
+ m
, rad
, 1 * M_PI
, 1.5 * M_PI
);
672 cairo_move_to(c
, ox
+ rad
+ a
+ lw
+ m
, oy
+ a
+ pad
+ m
);
673 cairo_line_to(c
, ox
+ sx
+ a
- rad
- m
- 1, oy
+ a
+ pad
+ m
);
674 cairo_arc (c
, ox
+ sx
- rad
+ a
- 2*m
- 1, oy
+ rad
+ a
+ pad
+ m
, rad
, 1.5 * M_PI
, 2 * M_PI
);
675 cairo_line_to(c
, ox
+ sx
+ a
- 2*m
- 1, oy
+ a
+ sy
- rad
- 2*m
- 1);
677 cairo_arc (c
, ox
+ sx
- rad
+ a
- 2*m
- 1, oy
+ sy
- rad
+ a
- 2*m
- 1, rad
, 0 * M_PI
, 0.5 * M_PI
);
679 cairo_line_to(c
, ox
+ a
+ rad
+ m
, oy
+ sy
+ a
- 2*m
- 1);
680 cairo_arc (c
, ox
+ rad
+ a
+ m
, oy
+ sy
- rad
+ a
- 2*m
- 1, rad
, 0.5 * M_PI
, 1 * M_PI
);
681 cairo_line_to(c
, ox
+ a
+ m
, oy
+ a
+ rad
+ pad
+ m
);
686 cairo_set_source_rgb(c
, 0.66,0.66,0.66);
689 cairo_move_to(c
, ox
+ a
+ m
, oy
+ pad
+ rad
+ a
+ m
);
690 cairo_arc (c
, ox
+ rad
+ a
+ m
, oy
+ rad
+ a
+ pad
+ m
, rad
, 1 * M_PI
, 1.5 * M_PI
);
691 cairo_move_to(c
, ox
+ rad
+ a
+ lw
+ m
, oy
+ a
+ pad
+ m
);
693 cairo_line_to(c
, ox
+ sx
+ a
- rad
- m
, oy
+ a
+ pad
+ m
);
694 cairo_arc (c
, ox
+ sx
- rad
+ a
- 2*m
- 1, oy
+ rad
+ a
+ pad
+ m
, rad
, 1.5 * M_PI
, 2 * M_PI
);
695 cairo_line_to(c
, ox
+ sx
+ a
- 2*m
- 1, oy
+ a
+ sy
- rad
- 2*m
);
696 cairo_arc (c
, ox
+ sx
- rad
+ a
- 2*m
- 1, oy
+ sy
- rad
+ a
- 2*m
- 1, rad
, 0 * M_PI
, 0.5 * M_PI
);
697 cairo_line_to(c
, ox
+ a
+ rad
+ m
, oy
+ sy
+ a
- 2*m
- 1);
698 cairo_arc (c
, ox
+ rad
+ a
+ m
, oy
+ sy
- rad
+ a
- 2*m
- 1, rad
, 0.5 * M_PI
, 1 * M_PI
);
699 cairo_line_to(c
, ox
+ a
+ m
, oy
+ a
+ rad
+ pad
+ m
);
704 if (gtk_bin_get_child(GTK_BIN(widget
))) {
705 gtk_container_propagate_expose(GTK_CONTAINER(widget
),
706 gtk_bin_get_child(GTK_BIN(widget
)),
713 calf_frame_class_init (CalfFrameClass
*klass
)
715 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
716 widget_class
->expose_event
= calf_frame_expose
;
720 calf_frame_init (CalfFrame
*self
)
722 GtkWidget
*widget
= GTK_WIDGET(self
);
723 widget
->requisition
.width
= 40;
724 widget
->requisition
.height
= 40;
728 calf_frame_get_type (void)
730 static GType type
= 0;
732 static const GTypeInfo type_info
= {
733 sizeof(CalfFrameClass
),
734 NULL
, /* base_init */
735 NULL
, /* base_finalize */
736 (GClassInitFunc
)calf_frame_class_init
,
737 NULL
, /* class_finalize */
738 NULL
, /* class_data */
741 (GInstanceInitFunc
)calf_frame_init
744 for (int i
= 0; ; i
++) {
745 char *name
= g_strdup_printf("CalfFrame%u%d",
746 ((unsigned int)(intptr_t)calf_frame_class_init
) >> 16, i
);
747 if (g_type_from_name(name
)) {
751 type
= g_type_register_static(GTK_TYPE_FRAME
,
762 ///////////////////////////////////////// combo box ///////////////////////////////////////////////
768 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_COMBOBOX
, NULL
));
772 calf_combobox_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
774 g_assert(CALF_IS_COMBOBOX(widget
));
776 if (gtk_widget_is_drawable (widget
)) {
780 GtkTreeModel
*model
= gtk_combo_box_get_model(GTK_COMBO_BOX (widget
));
783 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget
), &iter
))
784 gtk_tree_model_get (model
, &iter
, 0, &lab
, -1);
788 GdkWindow
*window
= widget
->window
;
789 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(window
));
791 int x
= widget
->allocation
.x
;
792 int y
= widget
->allocation
.y
;
793 int sx
= widget
->allocation
.width
;
794 int sy
= widget
->allocation
.height
;
798 cairo_rectangle(c
, x
, y
, sx
, sy
);
801 gtk_widget_get_pointer(GTK_WIDGET(widget
), &mx
, &my
);
802 if (mx
>= 0 and mx
< sx
and my
>= 0 and my
< sy
)
805 line_graph_background(c
, x
, y
, sx
- pad
* 2, sy
- pad
* 2, pad
, pad
, g_ascii_isspace(lab
[0]) ? 0 : 1, 4, hover
? 0.5 : 0, hover
? 0.1 : 0.25);
807 cairo_select_font_face(c
, "Sans",
808 CAIRO_FONT_SLANT_NORMAL
,
809 CAIRO_FONT_WEIGHT_NORMAL
);
810 cairo_set_font_size(c
, 12);
812 cairo_move_to(c
, x
+ pad
+ 3, y
+ sy
/ 2 + 5);
813 cairo_set_source_rgb(c
, 0.,0.,0.);
814 cairo_show_text(c
, lab
);
817 cairo_surface_t
*image
;
818 image
= cairo_image_surface_create_from_png(PKGLIBDIR
"combo_arrow.png");
819 cairo_set_source_surface(c
, image
, x
+ sx
- 20, y
+ sy
/ 2 - 5);
820 cairo_rectangle(c
, x
, y
, sx
, sy
);
829 calf_combobox_class_init (CalfComboboxClass
*klass
)
831 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
832 widget_class
->expose_event
= calf_combobox_expose
;
836 calf_combobox_init (CalfCombobox
*self
)
838 GtkWidget
*widget
= GTK_WIDGET(self
);
839 widget
->requisition
.width
= 40;
840 widget
->requisition
.height
= 20;
844 calf_combobox_get_type (void)
846 static GType type
= 0;
848 static const GTypeInfo type_info
= {
849 sizeof(CalfComboboxClass
),
850 NULL
, /* base_init */
851 NULL
, /* base_finalize */
852 (GClassInitFunc
)calf_combobox_class_init
,
853 NULL
, /* class_finalize */
854 NULL
, /* class_data */
855 sizeof(CalfCombobox
),
857 (GInstanceInitFunc
)calf_combobox_init
860 for (int i
= 0; ; i
++) {
861 char *name
= g_strdup_printf("CalfCombobox%u%d",
862 ((unsigned int)(intptr_t)calf_combobox_class_init
) >> 16, i
);
863 if (g_type_from_name(name
)) {
867 type
= g_type_register_static(GTK_TYPE_COMBO_BOX_TEXT
,
879 ///////////////////////////////////////// notebook ///////////////////////////////////////////////
881 #define GTK_NOTEBOOK_PAGE(_glist_) ((GtkNotebookPage *)((GList *)(_glist_))->data)
882 struct _GtkNotebookPage
885 GtkWidget
*tab_label
;
886 GtkWidget
*menu_label
;
887 GtkWidget
*last_focus_child
; /* Last descendant of the page that had focus */
889 guint default_menu
: 1; /* If true, we create the menu label ourself */
890 guint default_tab
: 1; /* If true, we create the tab label ourself */
894 guint reorderable
: 1;
895 guint detachable
: 1;
897 /* if true, the tab label was visible on last allocation; we track this so
898 * that we know to redraw the tab area if a tab label was hidden then shown
899 * without changing position */
900 guint tab_allocated_visible
: 1;
902 GtkRequisition requisition
;
903 GtkAllocation allocation
;
905 gulong mnemonic_activate_signal
;
906 gulong notify_visible_handler
;
912 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_NOTEBOOK
, NULL
));
916 calf_notebook_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
918 g_assert(CALF_IS_NOTEBOOK(widget
));
920 GtkNotebook
*notebook
;
921 notebook
= GTK_NOTEBOOK (widget
);
922 CalfNotebookClass
*klass
= CALF_NOTEBOOK_CLASS(GTK_OBJECT_GET_CLASS(widget
));
924 if (gtk_widget_is_drawable (widget
)) {
926 GdkWindow
*window
= widget
->window
;
927 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(window
));
928 cairo_pattern_t
*pat
= NULL
;
930 int x
= widget
->allocation
.x
;
931 int y
= widget
->allocation
.y
;
932 int sx
= widget
->allocation
.width
;
933 int sy
= widget
->allocation
.height
;
934 int tx
= widget
->style
->xthickness
;
935 int ty
= widget
->style
->ythickness
;
937 int bh
= lh
+ 2 * ty
;
939 cairo_rectangle(c
, x
, y
, sx
, sy
);
944 if (notebook
->show_tabs
) {
945 GtkNotebookPage
*page
;
949 gtk_widget_style_get(widget
, "tab-overlap", &sp
, NULL
);
951 pages
= notebook
->children
;
955 page
= GTK_NOTEBOOK_PAGE (pages
);
957 if (page
->tab_label
->window
== event
->window
&&
958 gtk_widget_is_drawable (page
->tab_label
)) {
959 int lx
= page
->tab_label
->allocation
.x
;
960 int lw
= page
->tab_label
->allocation
.width
;
962 // fix the labels position
963 page
->tab_label
->allocation
.y
= y
+ ty
;
964 page
->tab_label
->allocation
.height
= lh
;
966 // draw tab background
967 cairo_rectangle(c
, lx
- tx
, y
, lw
+ 2 * tx
, bh
);
968 cairo_set_source_rgba(c
, 0,0,0, page
!= notebook
->cur_page
? 0.25 : 0.5);
971 if (page
== notebook
->cur_page
) {
973 cairo_rectangle(c
, lx
- tx
+ 2, y
+ 2, lw
+ 2 * tx
- 4, 2);
974 pat
= cairo_pattern_create_radial(lx
+ lw
/ 2, y
+ bh
/ 2, 1, lx
+ lw
/ 2, y
+ bh
/ 2, lw
+ tx
* 2);
975 cairo_pattern_add_color_stop_rgb(pat
, 0, 50. / 255, 1, 1);
976 cairo_pattern_add_color_stop_rgb(pat
, 0.3, 2. / 255, 180. / 255, 1);
977 cairo_pattern_add_color_stop_rgb(pat
, 0.5, 19. / 255, 220. / 255, 1);
978 cairo_pattern_add_color_stop_rgb(pat
, 1, 2. / 255, 120. / 255, 1);
979 cairo_set_source(c
, pat
);
982 cairo_rectangle(c
, lx
- tx
+ 2, y
+ 1, lw
+ 2 * tx
- 4, 1);
983 cairo_set_source_rgba(c
, 0,0,0,0.5);
986 cairo_rectangle(c
, lx
- tx
+ 2, y
+ 4, lw
+ 2 * tx
- 4, 1);
987 cairo_set_source_rgba(c
, 1,1,1,0.3);
992 gtk_container_propagate_expose (GTK_CONTAINER (notebook
), page
->tab_label
, event
);
1000 cairo_rectangle(c
, x
, y
+ add
, sx
, sy
- add
);
1001 cairo_set_source_rgba(c
, 0,0,0,0.5);
1005 cairo_rectangle(c
, x
+ 0.5, y
+ add
+ 0.5, sx
- 1, sy
- add
- 1);
1006 pat
= cairo_pattern_create_linear(x
, y
+ add
, x
, y
+ sy
- add
);
1007 cairo_pattern_add_color_stop_rgba(pat
, 0, 0, 0, 0, 0.3);
1008 cairo_pattern_add_color_stop_rgba(pat
, 0.5, 0.5, 0.5, 0.5, 0);
1009 cairo_pattern_add_color_stop_rgba(pat
, 1, 1, 1, 1, 0.2);
1010 cairo_set_source (c
, pat
);
1011 cairo_set_line_width(c
, 1);
1012 cairo_stroke_preserve(c
);
1014 int sw
= gdk_pixbuf_get_width(klass
->screw
);
1015 int sh
= gdk_pixbuf_get_height(klass
->screw
);
1018 gdk_cairo_set_source_pixbuf(c
, klass
->screw
, x
, y
+ add
);
1019 cairo_fill_preserve(c
);
1020 gdk_cairo_set_source_pixbuf(c
, klass
->screw
, x
+ sx
- sw
, y
+ add
);
1021 cairo_fill_preserve(c
);
1022 gdk_cairo_set_source_pixbuf(c
, klass
->screw
, x
, y
+ sy
- sh
);
1023 cairo_fill_preserve(c
);
1024 gdk_cairo_set_source_pixbuf(c
, klass
->screw
, x
+ sx
- sh
, y
+ sy
- sh
);
1025 cairo_fill_preserve(c
);
1027 // propagate expose to all children
1028 if (notebook
->cur_page
)
1029 gtk_container_propagate_expose (GTK_CONTAINER (notebook
),
1030 notebook
->cur_page
->child
,
1033 cairo_pattern_destroy(pat
);
1041 calf_notebook_class_init (CalfNotebookClass
*klass
)
1043 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1044 widget_class
->expose_event
= calf_notebook_expose
;
1046 klass
->screw
= gdk_pixbuf_new_from_file (PKGLIBDIR
"screw_black.png", 0);
1050 calf_notebook_init (CalfNotebook
*self
)
1052 //GtkWidget *widget = GTK_WIDGET(self);
1056 calf_notebook_get_type (void)
1058 static GType type
= 0;
1060 static const GTypeInfo type_info
= {
1061 sizeof(CalfNotebookClass
),
1062 NULL
, /* base_init */
1063 NULL
, /* base_finalize */
1064 (GClassInitFunc
)calf_notebook_class_init
,
1065 NULL
, /* class_finalize */
1066 NULL
, /* class_data */
1067 sizeof(CalfNotebook
),
1068 0, /* n_preallocs */
1069 (GInstanceInitFunc
)calf_notebook_init
1072 for (int i
= 0; ; i
++) {
1073 char *name
= g_strdup_printf("CalfNotebook%u%d",
1074 ((unsigned int)(intptr_t)calf_notebook_class_init
) >> 16, i
);
1075 if (g_type_from_name(name
)) {
1079 type
= g_type_register_static(GTK_TYPE_NOTEBOOK
,
1090 ///////////////////////////////////////// fader ///////////////////////////////////////////////
1092 static void calf_fader_set_layout(GtkWidget
*widget
)
1094 GtkRange
*range
= GTK_RANGE(widget
);
1095 CalfFader
*fader
= CALF_FADER(widget
);
1096 CalfFaderLayout layout
= fader
->layout
;
1098 int hor
= fader
->horizontal
;
1101 layout
.x
= widget
->allocation
.x
;
1102 layout
.y
= widget
->allocation
.y
;
1103 layout
.w
= widget
->allocation
.width
;
1104 layout
.h
= widget
->allocation
.height
;
1107 layout
.tx
= range
->range_rect
.x
+ layout
.x
;
1108 layout
.ty
= range
->range_rect
.y
+ layout
.y
;
1109 layout
.tw
= range
->range_rect
.width
;
1110 layout
.th
= range
->range_rect
.height
;
1111 layout
.tc
= hor
? layout
.ty
+ layout
.th
/ 2 : layout
.tx
+ layout
.tw
/ 2;
1114 layout
.scw
= gdk_pixbuf_get_width(fader
->screw
);
1115 layout
.sch
= gdk_pixbuf_get_height(fader
->screw
);
1116 layout
.scx1
= hor
? layout
.tx
: layout
.tc
- layout
.scw
/ 2;
1117 layout
.scy1
= hor
? layout
.tc
- layout
.sch
/ 2 : layout
.ty
;
1118 layout
.scx2
= hor
? layout
.tx
+ layout
.tw
- layout
.scw
: layout
.tc
- layout
.scw
/ 2;
1119 layout
.scy2
= hor
? layout
.tc
- layout
.sch
/ 2 : layout
.ty
+ layout
.th
- layout
.sch
;
1122 layout
.sw
= hor
? layout
.tw
- layout
.scw
* 2 - 2: 2;
1123 layout
.sh
= hor
? 2 : layout
.th
- layout
.sch
* 2 - 2;
1124 layout
.sx
= hor
? layout
.tx
+ layout
.scw
+ 1 : layout
.tc
- 1;
1125 layout
.sy
= hor
? layout
.tc
- 1 : layout
.ty
+ layout
.sch
+ 1;
1128 layout
.slw
= gdk_pixbuf_get_width(fader
->slider
);
1129 layout
.slh
= gdk_pixbuf_get_height(fader
->slider
);
1130 layout
.slx
= fader
->horizontal
? 0 : layout
.tc
- layout
.slw
/ 2;
1131 layout
.sly
= fader
->horizontal
? layout
.tc
- layout
.slh
/ 2 : 0;
1133 //printf("widg %d %d %d %d | trgh %d %d %d %d %d | slid %d %d %d %d | slit %d %d %d %d\n",
1134 //layout.x, layout.y, layout.w, layout.h,
1135 //layout.tx, layout.ty, layout.tw, layout.th, layout.tc,
1136 //layout.slx, layout.sly, layout.slw, layout.slh,
1137 //layout.sx, layout.sy, layout.sw, layout.sh);
1139 fader
->layout
= layout
;
1143 calf_fader_new(const int horiz
= 0, const int size
= 2, const double min
= 0, const double max
= 1, const double step
= 0.1)
1148 adj
= gtk_adjustment_new (min
, min
, max
, step
, 10 * step
, 0);
1150 if (fabs (step
) >= 1.0 || step
== 0.0)
1153 digits
= std::min(5, abs((gint
) floor (log10 (fabs (step
)))));
1155 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_FADER
, NULL
));
1156 CalfFader
*self
= CALF_FADER(widget
);
1158 GTK_RANGE(widget
)->orientation
= horiz
? GTK_ORIENTATION_HORIZONTAL
: GTK_ORIENTATION_VERTICAL
;
1159 gtk_range_set_adjustment(GTK_RANGE(widget
), GTK_ADJUSTMENT(adj
));
1160 gtk_scale_set_digits(GTK_SCALE(widget
), digits
);
1163 self
->horizontal
= horiz
;
1166 gchar
* file
= g_strdup_printf("%sslider%d-%s.png", PKGLIBDIR
, size
, horiz
? "horiz" : "vert");
1167 self
->slider
= gdk_pixbuf_new_from_file (file
, 0);
1168 file
= g_strdup_printf("%sslider%d-%s-prelight.png", PKGLIBDIR
, size
, horiz
? "horiz" : "vert");
1169 self
->sliderpre
= gdk_pixbuf_new_from_file(file
, 0);
1171 self
->screw
= gdk_pixbuf_new_from_file (PKGLIBDIR
"screw_silver.png", 0);
1176 static bool calf_fader_hover(GtkWidget
*widget
)
1178 CalfFader
*fader
= CALF_FADER(widget
);
1179 CalfFaderLayout layout
= fader
->layout
;
1181 gtk_widget_get_pointer(GTK_WIDGET(widget
), &mx
, &my
);
1183 if ((fader
->horizontal
and mx
+ layout
.x
>= layout
.tx
1184 and mx
+ layout
.x
< layout
.tx
+ layout
.tw
1185 and my
+ layout
.y
>= layout
.sly
1186 and my
+ layout
.y
< layout
.sly
+ layout
.slh
)
1187 or (!fader
->horizontal
and mx
+ layout
.x
>= layout
.slx
1188 and mx
+ layout
.x
< layout
.slx
+ layout
.slw
1189 and my
+ layout
.y
>= layout
.ty
1190 and my
+ layout
.y
< layout
.ty
+ layout
.th
))
1194 static void calf_fader_check_hover_change(GtkWidget
*widget
)
1196 CalfFader
*fader
= CALF_FADER(widget
);
1197 bool hover
= calf_fader_hover(widget
);
1198 if (hover
!= fader
->hover
)
1199 gtk_widget_queue_draw(widget
);
1200 fader
->hover
= hover
;
1203 calf_fader_motion (GtkWidget
*widget
, GdkEventMotion
*event
)
1205 calf_fader_check_hover_change(widget
);
1210 calf_fader_enter (GtkWidget
*widget
, GdkEventCrossing
*event
)
1212 calf_fader_check_hover_change(widget
);
1217 calf_fader_leave (GtkWidget
*widget
, GdkEventCrossing
*event
)
1219 CALF_FADER(widget
)->hover
= false;
1220 gtk_widget_queue_draw(widget
);
1224 calf_fader_allocate (GtkWidget
*widget
, GtkAllocation
*allocation
)
1226 calf_fader_set_layout(widget
);
1229 calf_fader_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
1231 g_assert(CALF_IS_FADER(widget
));
1232 if (gtk_widget_is_drawable (widget
)) {
1234 GdkWindow
*window
= widget
->window
;
1235 GtkScale
*scale
= GTK_SCALE(widget
);
1236 GtkRange
*range
= GTK_RANGE(widget
);
1237 CalfFader
*fader
= CALF_FADER(widget
);
1238 CalfFaderLayout layout
= fader
->layout
;
1239 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(window
));
1241 cairo_rectangle(c
, layout
.x
, layout
.y
, layout
.w
, layout
.h
);
1245 double r
= range
->adjustment
->upper
- range
->adjustment
->lower
;
1246 double v0
= range
->adjustment
->value
- range
->adjustment
->lower
;
1247 if ((fader
->horizontal
and gtk_range_get_inverted(range
))
1248 or (!fader
->horizontal
and gtk_range_get_inverted(range
)))
1250 int vp
= v0
/ r
* (fader
->horizontal
? layout
.w
- layout
.slw
: layout
.h
- layout
.slh
)
1251 + (fader
->horizontal
? layout
.slw
: layout
.slh
) / 2
1252 + (fader
->horizontal
? layout
.x
: layout
.y
);
1253 layout
.slx
= fader
->horizontal
? vp
- layout
.slw
/ 2 : layout
.tc
- layout
.slw
/ 2;
1254 layout
.sly
= fader
->horizontal
? layout
.tc
- layout
.slh
/ 2 : vp
- layout
.slh
/ 2;
1256 cairo_rectangle(c
, layout
.sx
- 1, layout
.sy
- 1, layout
.sw
, layout
.sh
);
1257 cairo_set_source_rgba(c
, 0,0,0, 0.25);
1259 cairo_rectangle(c
, layout
.sx
+ 1, layout
.sy
+ 1, layout
.sw
, layout
.sh
);
1260 cairo_set_source_rgba(c
, 1,1,1, 0.125);
1262 cairo_rectangle(c
, layout
.sx
, layout
.sy
, layout
.sw
, layout
.sh
);
1263 cairo_set_source_rgb(c
, 0,0,0);
1267 cairo_rectangle(c
, layout
.x
, layout
.y
, layout
.w
, layout
.h
);
1268 gdk_cairo_set_source_pixbuf(c
, fader
->screw
, layout
.scx1
, layout
.scy1
);
1269 cairo_fill_preserve(c
);
1270 gdk_cairo_set_source_pixbuf(c
, fader
->screw
, layout
.scx2
, layout
.scy2
);
1271 cairo_fill_preserve(c
);
1274 if (fader
->hover
or gtk_grab_get_current() == widget
)
1275 gdk_cairo_set_source_pixbuf(c
, fader
->sliderpre
, layout
.slx
, layout
.sly
);
1277 gdk_cairo_set_source_pixbuf(c
, fader
->slider
, layout
.slx
, layout
.sly
);
1281 if (scale
->draw_value
) {
1282 PangoLayout
*layout
;
1284 layout
= gtk_scale_get_layout (scale
);
1285 gtk_scale_get_layout_offsets (scale
, &_x
, &_y
);
1286 gtk_paint_layout (widget
->style
, window
, GTK_STATE_NORMAL
, FALSE
, NULL
,
1287 widget
, fader
->horizontal
? "hscale" : "vscale", _x
, _y
, layout
);
1296 calf_fader_class_init (CalfFaderClass
*klass
)
1298 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1299 widget_class
->expose_event
= calf_fader_expose
;
1303 calf_fader_init (CalfFader
*self
)
1305 GtkWidget
*widget
= GTK_WIDGET(self
);
1306 widget
->requisition
.width
= 40;
1307 widget
->requisition
.height
= 40;
1309 gtk_signal_connect(GTK_OBJECT(widget
), "motion-notify-event", GTK_SIGNAL_FUNC (calf_fader_motion
), NULL
);
1310 gtk_signal_connect(GTK_OBJECT(widget
), "enter-notify-event", GTK_SIGNAL_FUNC (calf_fader_enter
), NULL
);
1311 gtk_signal_connect(GTK_OBJECT(widget
), "leave-notify-event", GTK_SIGNAL_FUNC (calf_fader_leave
), NULL
);
1312 gtk_signal_connect(GTK_OBJECT(widget
), "size-allocate", GTK_SIGNAL_FUNC (calf_fader_allocate
), NULL
);
1316 calf_fader_get_type (void)
1318 static GType type
= 0;
1320 static const GTypeInfo type_info
= {
1321 sizeof(CalfFaderClass
),
1322 NULL
, /* base_init */
1323 NULL
, /* base_finalize */
1324 (GClassInitFunc
)calf_fader_class_init
,
1325 NULL
, /* class_finalize */
1326 NULL
, /* class_data */
1328 0, /* n_preallocs */
1329 (GInstanceInitFunc
)calf_fader_init
1332 for (int i
= 0; ; i
++) {
1333 char *name
= g_strdup_printf("CalfFader%u%d",
1334 ((unsigned int)(intptr_t)calf_fader_class_init
) >> 16, i
);
1335 if (g_type_from_name(name
)) {
1339 type
= g_type_register_static(GTK_TYPE_SCALE
,
1351 ///////////////////////////////////////// button ///////////////////////////////////////////////
1354 calf_button_new(const gchar
*label
)
1356 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_BUTTON
, NULL
));
1357 gtk_button_set_label(GTK_BUTTON(widget
), label
);
1361 calf_button_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
1363 g_assert(CALF_IS_BUTTON(widget
) || CALF_IS_TOGGLE_BUTTON(widget
) || CALF_IS_RADIO_BUTTON(widget
));
1365 if (gtk_widget_is_drawable (widget
)) {
1369 GdkWindow
*window
= widget
->window
;
1370 GtkWidget
*child
= GTK_BIN (widget
)->child
;
1371 cairo_t
*c
= gdk_cairo_create(GDK_DRAWABLE(window
));
1372 cairo_pattern_t
*pat
= NULL
;
1374 int x
= widget
->allocation
.x
;
1375 int y
= widget
->allocation
.y
;
1376 int sx
= widget
->allocation
.width
;
1377 int sy
= widget
->allocation
.height
;
1379 cairo_rectangle(c
, x
, y
, sx
, sy
);
1382 cairo_rectangle(c
, x
, y
, sx
, sy
);
1383 pat
= cairo_pattern_create_radial(x
+ sx
/ 2, y
+ sy
/ 2, 1, x
+ sx
/ 2, y
+ sy
/ 2, sx
/ 2);
1384 switch (gtk_widget_get_state(widget
)) {
1385 case GTK_STATE_NORMAL
:
1387 cairo_pattern_add_color_stop_rgb(pat
, 0.3, 39. / 255, 52. / 255, 87. / 255);
1388 cairo_pattern_add_color_stop_rgb(pat
, 1.0, 6. / 255, 5. / 255, 14. / 255);
1390 case GTK_STATE_PRELIGHT
:
1391 cairo_pattern_add_color_stop_rgb(pat
, 0.3, 19. / 255, 237. / 255, 254. / 255);
1392 cairo_pattern_add_color_stop_rgb(pat
, 1.0, 0. / 255, 45. / 255, 206. / 255);
1394 case GTK_STATE_ACTIVE
:
1395 case GTK_STATE_SELECTED
:
1396 cairo_pattern_add_color_stop_rgb(pat
, 0.0, 19. / 255, 237. / 255, 254. / 255);
1397 cairo_pattern_add_color_stop_rgb(pat
, 0.3, 10. / 255, 200. / 255, 240. / 255);
1398 cairo_pattern_add_color_stop_rgb(pat
, 0.7, 19. / 255, 237. / 255, 254. / 255);
1399 cairo_pattern_add_color_stop_rgb(pat
, 1.0, 2. / 255, 168. / 255, 230. / 255);
1403 cairo_set_source(c
, pat
);
1406 cairo_rectangle(c
, x
+ pad
, y
+ pad
, sx
- pad
* 2, sy
- pad
* 2);
1407 if (CALF_IS_TOGGLE_BUTTON(widget
) or CALF_IS_RADIO_BUTTON(widget
)) {
1408 cairo_new_sub_path (c
);
1409 cairo_rectangle(c
, x
+ sx
- pad
* 2 - 23, y
+ sy
/ 2 - 1, 22, 2);
1410 cairo_set_fill_rule(c
, CAIRO_FILL_RULE_EVEN_ODD
);
1412 pat
= cairo_pattern_create_linear(x
+ pad
, y
+ pad
, x
+ pad
, y
+ sy
- pad
* 2);
1413 cairo_pattern_add_color_stop_rgb(pat
, 0.0, 0.92, 0.92, 0.92);
1414 cairo_pattern_add_color_stop_rgb(pat
, 1.0, 0.70, 0.70, 0.70);
1415 cairo_set_source(c
, pat
);
1418 int _h
= GTK_WIDGET(GTK_BIN(widget
)->child
)->allocation
.height
+ 0;
1419 int _y
= y
+ (sy
- _h
) / 2;
1420 cairo_rectangle(c
, x
+ pad
, _y
, sx
- pad
* 2, _h
);
1421 if (CALF_IS_TOGGLE_BUTTON(widget
) or CALF_IS_RADIO_BUTTON(widget
)) {
1422 cairo_new_sub_path (c
);
1423 cairo_rectangle(c
, x
+ sx
- pad
* 2 - 23, y
+ sy
/ 2 - 1, 22, 2);
1424 cairo_set_fill_rule(c
, CAIRO_FILL_RULE_EVEN_ODD
);
1426 pat
= cairo_pattern_create_linear(x
+ pad
, _y
, x
+ pad
, _y
+ _h
);
1427 cairo_pattern_add_color_stop_rgb(pat
, 1.0, 0.92, 0.92, 0.92);
1428 cairo_pattern_add_color_stop_rgb(pat
, 0.0, 0.70, 0.70, 0.70);
1429 cairo_set_source(c
, pat
);
1433 gtk_container_propagate_expose (GTK_CONTAINER (widget
), child
, event
);
1439 calf_button_class_init (CalfButtonClass
*klass
)
1441 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1442 widget_class
->expose_event
= calf_button_expose
;
1446 calf_button_init (CalfButton
*self
)
1448 GtkWidget
*widget
= GTK_WIDGET(self
);
1449 widget
->requisition
.width
= 40;
1450 widget
->requisition
.height
= 20;
1454 calf_button_get_type (void)
1456 static GType type
= 0;
1458 static const GTypeInfo type_info
= {
1459 sizeof(CalfButtonClass
),
1460 NULL
, /* base_init */
1461 NULL
, /* base_finalize */
1462 (GClassInitFunc
)calf_button_class_init
,
1463 NULL
, /* class_finalize */
1464 NULL
, /* class_data */
1466 0, /* n_preallocs */
1467 (GInstanceInitFunc
)calf_button_init
1470 for (int i
= 0; ; i
++) {
1471 char *name
= g_strdup_printf("CalfButton%u%d",
1472 ((unsigned int)(intptr_t)calf_button_class_init
) >> 16, i
);
1473 if (g_type_from_name(name
)) {
1477 type
= g_type_register_static(GTK_TYPE_BUTTON
,
1489 ///////////////////////////////////////// toggle button ///////////////////////////////////////////////
1492 calf_toggle_button_new(const gchar
*label
)
1494 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_TOGGLE_BUTTON
, NULL
));
1495 gtk_button_set_label(GTK_BUTTON(widget
), label
);
1500 calf_toggle_button_class_init (CalfToggleButtonClass
*klass
)
1502 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1503 widget_class
->expose_event
= calf_button_expose
;
1507 calf_toggle_button_init (CalfToggleButton
*self
)
1509 GtkWidget
*widget
= GTK_WIDGET(self
);
1510 widget
->requisition
.width
= 40;
1511 widget
->requisition
.height
= 20;
1515 calf_toggle_button_get_type (void)
1517 static GType type
= 0;
1519 static const GTypeInfo type_info
= {
1520 sizeof(CalfToggleButtonClass
),
1521 NULL
, /* base_init */
1522 NULL
, /* base_finalize */
1523 (GClassInitFunc
)calf_toggle_button_class_init
,
1524 NULL
, /* class_finalize */
1525 NULL
, /* class_data */
1526 sizeof(CalfToggleButton
),
1527 0, /* n_preallocs */
1528 (GInstanceInitFunc
)calf_toggle_button_init
1531 for (int i
= 0; ; i
++) {
1532 char *name
= g_strdup_printf("CalfToggleButton%u%d",
1533 ((unsigned int)(intptr_t)calf_toggle_button_class_init
) >> 16, i
);
1534 if (g_type_from_name(name
)) {
1538 type
= g_type_register_static(GTK_TYPE_TOGGLE_BUTTON
,
1549 ///////////////////////////////////////// radio button ///////////////////////////////////////////////
1552 calf_radio_button_new(const gchar
*label
)
1554 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_RADIO_BUTTON
, NULL
));
1555 gtk_button_set_label(GTK_BUTTON(widget
), label
);
1560 calf_radio_button_class_init (CalfRadioButtonClass
*klass
)
1562 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1563 widget_class
->expose_event
= calf_button_expose
;
1567 calf_radio_button_init (CalfRadioButton
*self
)
1569 GtkWidget
*widget
= GTK_WIDGET(self
);
1570 widget
->requisition
.width
= 40;
1571 widget
->requisition
.height
= 20;
1575 calf_radio_button_get_type (void)
1577 static GType type
= 0;
1579 static const GTypeInfo type_info
= {
1580 sizeof(CalfRadioButtonClass
),
1581 NULL
, /* base_init */
1582 NULL
, /* base_finalize */
1583 (GClassInitFunc
)calf_radio_button_class_init
,
1584 NULL
, /* class_finalize */
1585 NULL
, /* class_data */
1586 sizeof(CalfRadioButton
),
1587 0, /* n_preallocs */
1588 (GInstanceInitFunc
)calf_radio_button_init
1591 for (int i
= 0; ; i
++) {
1592 char *name
= g_strdup_printf("CalfRadioButton%u%d",
1593 ((unsigned int)(intptr_t)calf_radio_button_class_init
) >> 16, i
);
1594 if (g_type_from_name(name
)) {
1598 type
= g_type_register_static(GTK_TYPE_RADIO_BUTTON
,
1609 ///////////////////////////////////////// tap button ///////////////////////////////////////////////
1612 calf_tap_button_new()
1614 GtkWidget
*widget
= GTK_WIDGET( g_object_new (CALF_TYPE_TAP_BUTTON
, NULL
));
1619 calf_tap_button_expose (GtkWidget
*widget
, GdkEventExpose
*event
)
1621 g_assert(CALF_IS_TAP_BUTTON(widget
));
1622 CalfTapButton
*self
= CALF_TAP_BUTTON(widget
);
1624 int x
= widget
->allocation
.x
+ widget
->allocation
.width
/ 2 - 35;
1625 int y
= widget
->allocation
.y
+ widget
->allocation
.height
/ 2 - 35;
1629 gdk_draw_pixbuf(GDK_DRAWABLE(widget
->window
),
1630 widget
->style
->fg_gc
[0],
1631 self
->image
[self
->state
],
1638 GDK_RGB_DITHER_NORMAL
, 0, 0);
1643 calf_tap_button_size_request (GtkWidget
*widget
,
1644 GtkRequisition
*requisition
)
1646 g_assert(CALF_IS_TAP_BUTTON(widget
));
1647 requisition
->width
= 70;
1648 requisition
->height
= 70;
1651 calf_tap_button_class_init (CalfTapButtonClass
*klass
)
1653 GtkWidgetClass
*widget_class
= GTK_WIDGET_CLASS(klass
);
1654 widget_class
->expose_event
= calf_tap_button_expose
;
1655 widget_class
->size_request
= calf_tap_button_size_request
;
1658 calf_tap_button_init (CalfTapButton
*self
)
1660 GtkWidget
*widget
= GTK_WIDGET(self
);
1661 widget
->requisition
.width
= 70;
1662 widget
->requisition
.height
= 70;
1664 GError
*error
= NULL
;
1665 self
->image
[0] = gdk_pixbuf_new_from_file(PKGLIBDIR
"/tap_inactive.png", &error
);
1666 self
->image
[1] = gdk_pixbuf_new_from_file(PKGLIBDIR
"/tap_prelight.png", &error
);
1667 self
->image
[2] = gdk_pixbuf_new_from_file(PKGLIBDIR
"/tap_active.png", &error
);
1671 calf_tap_button_get_type (void)
1673 static GType type
= 0;
1675 static const GTypeInfo type_info
= {
1676 sizeof(CalfTapButtonClass
),
1677 NULL
, /* base_init */
1678 NULL
, /* base_finalize */
1679 (GClassInitFunc
)calf_tap_button_class_init
,
1680 NULL
, /* class_finalize */
1681 NULL
, /* class_data */
1682 sizeof(CalfTapButton
),
1683 0, /* n_preallocs */
1684 (GInstanceInitFunc
)calf_tap_button_init
1687 for (int i
= 0; ; i
++) {
1688 char *name
= g_strdup_printf("CalfTapButton%u%d",
1689 ((unsigned int)(intptr_t)calf_tap_button_class_init
) >> 16, i
);
1690 if (g_type_from_name(name
)) {
1694 type
= g_type_register_static(GTK_TYPE_BUTTON
,