1 /*************************************************************************** 2 * Copyright (C) 2011 by Pere Rafols Soler * 3 * sapista2@gmail.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 ***************************************************************************/ 20 21 #ifndef KNOB_WIDGET2_H 22 #define KNOB_WIDGET2_H 23 24 #include <cmath> 25 #include <string> 26 #include <vector> 27 #include <gtkmm/drawingarea.h> 28 #include <gdkmm/pixbuf.h> 29 #include <glibmm/refptr.h> 30 #include <cairomm/surface.h> 31 32 #define KNOB_TYPE_LIN 0 33 #define KNOB_TYPE_FREQ 1 34 #define KNOB_TYPE_TIME 2 35 36 class KnobWidget2 : public Gtk::DrawingArea 37 { 38 public: 39 KnobWidget2(float fMin, float fMax, std::string sLabel, std::string sUnits, const char *knobIconPath, int iType = KNOB_TYPE_LIN, bool snap2ZerodB = false); 40 ~KnobWidget2(); 41 void set_value(float fValue); 42 double get_value(); 43 44 //signal accessor: 45 typedef sigc::signal<void> signal_KnobChanged; 46 signal_KnobChanged signal_changed(); 47 48 49 protected: 50 //Override default signal handler: 51 virtual bool on_expose_event(GdkEventExpose* event); 52 virtual bool on_mouse_leave_widget(GdkEventCrossing* event); 53 void redraw(); 54 55 //Mouse grab signal handlers 56 virtual bool on_button_press_event(GdkEventButton* event); 57 virtual bool on_button_release_event(GdkEventButton* event); 58 virtual bool on_scrollwheel_event(GdkEventScroll* event); 59 virtual bool on_mouse_motion_event(GdkEventMotion* event); 60 61 float m_fMin; //Min representable value 62 float m_fMax; //Max representable value 63 bool bMotionIsConnected; 64 float m_Value; 65 std::string m_Label; 66 std::string m_Units; 67 int m_TypeKnob; 68 69 int width; 70 int height; 71 int mouse_move_ant; 72 bool m_snap2Zero; 73 bool m_focus; 74 double m_slowMultiplier; 75 76 //Fader change signal 77 signal_KnobChanged m_KnobChangedSignal; 78 79 private: 80 std::string m_knobIconPath; 81 Cairo::RefPtr<Cairo::ImageSurface> m_image_surface_ptr; 82 Glib::RefPtr<Gdk::Pixbuf> m_image_ptr; 83 Cairo::RefPtr< Cairo::Context> m_image_context_ptr; 84 }; 85 #endif