28 #include <glib/gstdio.h>
30 #include <gdk/gdkkeysyms.h>
50 Gdk::Color* MotionFeedback::base_color;
52 MotionFeedback::MotionFeedback (Glib::RefPtr<Gdk::Pixbuf> pix,
58 const char *widget_name,
59 bool with_numeric_display,
64 , default_value (default_val)
65 , step_inc (step_increment)
66 , page_inc (page_increment)
77 char value_name[1024];
83 HBox* hpacker = manage (
new HBox);
84 hpacker->pack_start (
pixwin,
true,
true);
86 pack_start (*hpacker,
false,
false);
89 if (with_numeric_display) {
97 value->set_justify (Gtk::JUSTIFY_RIGHT);
102 hpacker = manage (
new HBox);
105 hpacker->set_border_width (6);
107 pack_start (*hpacker,
false,
false);
110 snprintf (value_name,
sizeof(value_name),
"%sValue", widget_name);
111 value->set_name (value_name);
117 value->set_text (buf);
121 pixwin.set_events (Gdk::BUTTON_PRESS_MASK|
122 Gdk::BUTTON_RELEASE_MASK|
123 Gdk::POINTER_MOTION_MASK|
124 Gdk::ENTER_NOTIFY_MASK|
125 Gdk::LEAVE_NOTIFY_MASK|
128 Gdk::KEY_RELEASE_MASK);
130 pixwin.set_flags (CAN_FOCUS);
158 switch (ev->button) {
169 gtk_grab_add(GTK_WIDGET(
pixwin.gobj()));
184 switch (ev->button) {
189 (GTK_WIDGET(
pixwin.gobj()));
206 (GTK_WIDGET(
pixwin.gobj()));
212 return VBox::on_button_release_event (ev);
227 return VBox::on_motion_notify_event (ev);
234 if (ev->state & Gdk::BUTTON1_MASK) {
243 if (y_delta == 0)
return TRUE;
245 y_delta *= 1 + (x_delta/100);
246 y_delta *= multiplier;
251 }
else if (ev->state & Gdk::BUTTON2_MASK) {
257 double angle = std::atan2 (y, x) / M_PI;
263 angle = -(2.0/3.0) * (angle - 1.25);
283 pixwin.unset_flags (HAS_FOCUS);
301 switch (ev->keyval) {
343 GdkWindow *window =
pixwin.get_window()->gobj();
345 int32_t phase = lrint (display_val * 64.0);
350 double pt = (display_val * 2.0) - 1.0;
364 double nom = phase / 64.0;
365 double diff = display_val - nom;
368 phase = (phase + 1) % 64;
370 phase = (phase + 63) % 64;
373 phase = std::min (phase, (int32_t) 63);
375 GtkWidget* widget = GTK_WIDGET(
pixwin.gobj());
376 gdk_draw_pixbuf (GDK_DRAWABLE(window), widget->style->fg_gc[0],
382 subwidth, subheight, GDK_RGB_DITHER_NORMAL, 0, 0);
406 switch (ev->direction) {
408 case GDK_SCROLL_RIGHT:
412 case GDK_SCROLL_DOWN:
413 case GDK_SCROLL_LEFT:
435 value->set_text (buf);
453 value->set_text (buf);
475 Glib::RefPtr<Gdk::Pixbuf>
478 Glib::RefPtr<Gdk::Pixbuf>
pixbuf;
481 GError *gerror = NULL;
483 fd = g_file_open_tmp (
"mfimgXXXXXX", &path, &gerror);
487 g_error_free (gerror);
494 GdkColor col2 = {0,0,0,0};
495 GdkColor col3 = {0,0,0,0};
506 cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size * 64, size);
507 cairo_t* cr = cairo_create (surface);
509 for (
int i = 0; i < 64; ++i) {
511 core_draw (cr, i, size, 20, size*i, 0, &bright, &dark);
515 if (cairo_surface_write_to_png (surface, path) != CAIRO_STATUS_SUCCESS) {
521 cairo_surface_destroy (surface);
524 pixbuf = Gdk::Pixbuf::create_from_file (path);
525 }
catch (
const Gdk::PixbufError &e) {
528 error <<
_(
"motionfeedback: unknown exception") <<
endmsg;
539 const GdkColor* bright,
const GdkColor* dark)
549 double start_angle_x;
550 double start_angle_y;
553 double progress_radius;
554 double progress_radius_inner;
555 double progress_radius_outer;
557 g_return_if_fail (cr != NULL);
559 progress_radius = 40.0;
560 progress_radius_inner = progress_radius - (progress_width / 2.0);
561 progress_radius_outer = progress_radius + (progress_width / 2.0);
563 const double pad = 2.0;
564 const double actual_width = ((2.0 * pad) + (2.0 * progress_radius_outer));
565 const double scale_factor = size / actual_width;
572 xc = (xorigin + (size / 2.0)) * (1.0/scale_factor);
573 yc = (yorigin + (size / 2.0)) * (1.0/scale_factor);
575 value = (phase * 1.0) / (65 - 1);
577 start_angle = ((180 - 65) * G_PI) / 180;
578 end_angle = ((360 + 65) * G_PI) / 180;
580 value_angle = start_angle + (value * (end_angle - start_angle));
581 value_x = cos (value_angle);
582 value_y = sin (value_angle);
583 start_angle_x = cos (start_angle);
584 start_angle_y = sin (start_angle);
585 end_angle_x = cos (end_angle);
586 end_angle_y = sin (end_angle);
588 cairo_scale (cr, scale_factor, scale_factor);
591 cairo_set_source_rgb (cr, 0.3, 0.3, 0.3 );
592 cairo_set_line_width (cr, progress_width);
593 cairo_arc (cr, xc, yc, progress_radius, start_angle, end_angle);
597 float r = (
value) * (((
float)bright->red)/G_MAXUINT16) + (1.0-value)*(((float)dark->red)/G_MAXUINT16);
598 float g = (
value) * (((
float)bright->green)/G_MAXUINT16) + (1.0-
value)*(((
float)dark->green)/G_MAXUINT16);
599 float b = (
value) * (((
float)bright->blue)/G_MAXUINT16) + (1.0-
value)*(((
float)dark->blue)/G_MAXUINT16);
602 cairo_set_source_rgb (cr, r,g,b);
603 cairo_set_line_width (cr, progress_width);
604 cairo_arc (cr, xc, yc, progress_radius, start_angle, value_angle);
608 cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, progress_radius_outer);
609 cairo_pattern_add_color_stop_rgba (shade_pattern, 0, 1,1,1, 0.3);
610 cairo_pattern_add_color_stop_rgba (shade_pattern, 1, 1,1,1, 0.0);
611 cairo_set_source (cr, shade_pattern);
612 cairo_arc (cr, xc, yc, progress_radius_outer-1, 0, 2.0*G_PI);
614 cairo_pattern_destroy (shade_pattern);
617 cairo_set_source_rgb (cr, 0, 0, 0 );
618 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
619 cairo_set_line_width (cr, 1.0/scale_factor);
620 cairo_move_to (cr, xc + (progress_radius_outer * start_angle_x), yc + (progress_radius_outer * start_angle_y));
621 cairo_line_to (cr, xc + (progress_radius_inner * start_angle_x), yc + (progress_radius_inner * start_angle_y));
623 cairo_move_to (cr, xc + (progress_radius_outer * end_angle_x), yc + (progress_radius_outer * end_angle_y));
624 cairo_line_to (cr, xc + (progress_radius_inner * end_angle_x), yc + (progress_radius_inner * end_angle_y));
626 cairo_arc (cr, xc, yc, progress_radius_outer, start_angle, end_angle);
628 cairo_arc (cr, xc, yc, progress_radius_inner, start_angle, end_angle);
633 cairo_translate(cr, 6, 6 );
634 cairo_set_source_rgba (cr, 0,0,0,0.1 );
635 cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
640 cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1 );
641 cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
645 shade_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, progress_radius_outer);
646 cairo_pattern_add_color_stop_rgba (shade_pattern, 0, 1,1,1, 0.5);
647 cairo_pattern_add_color_stop_rgba (shade_pattern, 1, 0,0,0, 0.3);
648 cairo_set_source (cr, shade_pattern);
649 cairo_arc (cr, xc, yc, progress_radius_inner-1, 0, 2.0*G_PI);
651 cairo_pattern_destroy (shade_pattern);
654 cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 0.5 );
655 cairo_arc (cr, xc, yc, progress_radius_inner-5, 0, 2.0*G_PI);
660 cairo_translate(cr, 2, 2 );
661 cairo_set_source_rgba (cr, 0,0,0,0.5 );
662 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
663 cairo_set_line_width (cr, 4);
664 cairo_move_to (cr, xc + (progress_radius_inner * value_x), yc + (progress_radius_inner * value_y));
665 cairo_line_to (cr, xc + ((progress_radius_inner*0.4) * value_x), yc + ((progress_radius_inner*0.4) * value_y));
668 cairo_set_source_rgba (cr, 1,1,1,0.7 );
669 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
670 cairo_set_line_width (cr, 4.0);
671 cairo_move_to (cr, xc + (progress_radius_inner * value_x), yc + (progress_radius_inner * value_y));
672 cairo_line_to (cr, xc + ((progress_radius_inner*0.4) * value_x), yc + ((progress_radius_inner*0.4) * value_y));
virtual double to_display_value(double)=0
virtual double adjust(double nominal_delta)=0
LIBGTKMM2EXT_API void prolooks_hsv_set_value(ProlooksHSV *self, double value)
BindingProxy binding_proxy
static void default_printer(char buf[32], const boost::shared_ptr< PBD::Controllable > &, void *)
bool pixwin_button_press_event(GdkEventButton *)
virtual double to_control_value(double)=0
static uint32_t GainFineScaleModifier
bool pixwin_motion_notify_event(GdkEventMotion *)
void set_controllable(boost::shared_ptr< PBD::Controllable >)
LIBPBD_API Transmitter error
bool pixwin_scroll_event(GdkEventScroll *)
virtual ~MotionFeedback()
std::ostream & endmsg(std::ostream &ostr)
PBD::ScopedConnection controller_connection
virtual double upper() const
static uint32_t TertiaryModifier
static uint32_t PrimaryModifier
void pixwin_size_request(GtkRequisition *)
LIBGTKMM2EXT_API void prolooks_hsv_set_saturation(ProlooksHSV *self, double value)
static void core_draw(cairo_t *, int, double, double, double, double, const GdkColor *bright, const GdkColor *dark)
bool pixwin_button_release_event(GdkEventButton *)
static uint32_t SecondaryModifier
bool pixwin_key_press_event(GdkEventKey *)
static Gdk::Color * base_color
virtual double lower() const
Glib::RefPtr< Gdk::Pixbuf > pixbuf
virtual double get_value(void) const =0
bool button_press_handler(GdkEventButton *)
Gtk::EventBox * value_packer
static Glib::RefPtr< Gdk::Pixbuf > render_pixbuf(int size)
boost::shared_ptr< PBD::Controllable > controllable() const
virtual void set_value(double)=0
bool pixwin_enter_notify_event(GdkEventCrossing *)
void controllable_value_changed()
PBD::Signal0< void > Changed
LIBGTKMM2EXT_API void prolooks_hsv_to_gdk_color(ProlooksHSV *self, GdkColor *result)
LIBGTKMM2EXT_API ProlooksHSV * prolooks_hsv_new_for_gdk_color(const GdkColor *color)
boost::shared_ptr< PBD::Controllable > _controllable
static bool modifier_state_equals(guint state, ModifierMask)
bool pixwin_leave_notify_event(GdkEventCrossing *)
static void set_lamp_color(const std::string &)
void(* print_func)(char buf[32], const boost::shared_ptr< PBD::Controllable > &, void *)
#define MISSING_INVALIDATOR
bool pixwin_expose_event(GdkEventExpose *)
std::string string_compose(const std::string &fmt, const T1 &o1)
virtual void set_controllable(boost::shared_ptr< PBD::Controllable > c)
static uint32_t GainExtraFineScaleModifier