1 /* === S Y N F I G ========================================================= */ 2 /*! \file widgets/widget_ruler.h 3 ** \brief Template Header 4 ** 5 ** $Id$ 6 ** 7 ** \legal 8 ** ......... ... 2014 Ivan Mahonin 9 ** 10 ** This package is free software; you can redistribute it and/or 11 ** modify it under the terms of the GNU General Public License as 12 ** published by the Free Software Foundation; either version 2 of 13 ** the License, or (at your option) any later version. 14 ** 15 ** This package is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 ** General Public License for more details. 19 ** \endlegal 20 */ 21 /* ========================================================================= */ 22 23 /* === S T A R T =========================================================== */ 24 25 #ifndef __SYNFIG_STUDIO_WIDGET_RULER_H 26 #define __SYNFIG_STUDIO_WIDGET_RULER_H 27 28 /* === H E A D E R S ======================================================= */ 29 30 #include <sigc++/sigc++.h> 31 32 #include <gtkmm/drawingarea.h> 33 #include <pangomm/layout.h> 34 35 #include <synfig/real.h> 36 #include <synfig/string.h> 37 38 /* === M A C R O S ========================================================= */ 39 40 /* === T Y P E D E F S ===================================================== */ 41 42 /* === C L A S S E S & S T R U C T S ======================================= */ 43 44 namespace studio { 45 46 class Widget_Ruler : public Gtk::DrawingArea 47 { 48 private: 49 bool is_vertical; 50 Glib::RefPtr<Pango::Layout> layout; 51 synfig::Real min; 52 synfig::Real max; 53 synfig::Real position; 54 55 void draw_line( 56 const ::Cairo::RefPtr< ::Cairo::Context>& cr, 57 synfig::Real position, 58 synfig::Real size, 59 const Gdk::RGBA &color, 60 synfig::Real width, 61 synfig::Real height ); 62 63 void draw_text( 64 const ::Cairo::RefPtr< ::Cairo::Context>& cr, 65 synfig::Real position, 66 const synfig::String &text, 67 int size, 68 const Gdk::RGBA &color, 69 synfig::Real offset, 70 synfig::Real width, 71 synfig::Real height ); 72 73 public: 74 Widget_Ruler(bool is_vertical); 75 ~Widget_Ruler(); 76 get_screen_min()77 synfig::Real get_screen_min() const 78 { return 0.0; } get_screen_max()79 synfig::Real get_screen_max() const 80 { return (synfig::Real)(is_vertical ? get_height() : get_width()); } 81 position_to_screen(synfig::Real value)82 synfig::Real position_to_screen(synfig::Real value) const 83 { return (value - min)/(max - min)*(get_screen_max()-get_screen_min()) + get_screen_min(); } position_from_screen(synfig::Real value)84 synfig::Real position_from_screen(synfig::Real value) const 85 { return (value - get_screen_min())/(get_screen_max()-get_screen_min())*(max - min) + min; } 86 distance_to_screen(synfig::Real value)87 synfig::Real distance_to_screen(synfig::Real value) const 88 { return value/(max - min)*(get_screen_max()-get_screen_min()); } distance_from_screen(synfig::Real value)89 synfig::Real distance_from_screen(synfig::Real value) const 90 { return value/(get_screen_max()-get_screen_min())*(max - min); } 91 get_min()92 synfig::Real get_min() const { return min; } 93 void set_min(synfig::Real value); 94 get_max()95 synfig::Real get_max() const { return max; } 96 void set_max(synfig::Real value); 97 get_position()98 synfig::Real get_position() const { return position; } 99 void set_position(synfig::Real value); 100 get_screen_position()101 synfig::Real get_screen_position() const 102 { return position_to_screen(get_position()); } set_screen_position(synfig::Real value)103 void set_screen_position(synfig::Real value) 104 { set_position(position_from_screen(value)); } 105 106 bool on_draw(const ::Cairo::RefPtr< ::Cairo::Context>& cr); 107 }; // END of class Widget_Ruler 108 109 }; // END of namespace studio 110 111 /* === E N D =============================================================== */ 112 113 #endif 114