1 // TimeBar.hh --- Time Bar 2 // 3 // Copyright (C) 2002, 2003, 2004, 2006, 2007, 2009, 2011 Rob Caelers & Raymond Penners 4 // All rights reserved. 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 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 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 #ifndef TIMEBAR_HH 21 #define TIMEBAR_HH 22 23 #include <string> 24 25 #include <gtkmm.h> 26 #include <gdkmm.h> 27 28 #include "ITimeBar.hh" 29 30 class TimeBar : public Gtk::DrawingArea, public ITimeBar 31 { 32 public: 33 TimeBar(); 34 virtual ~TimeBar(); 35 36 void set_progress(int value, int max_value); 37 void set_secondary_progress(int value, int max_value); 38 39 void set_text(std::string text); 40 41 void update(); 42 void set_bar_color(ColorId color); 43 void set_secondary_bar_color(ColorId color); 44 void set_text_alignment(int align); 45 46 void set_border_size(int size); 47 void set_rotation(int r); 48 49 void get_minimum_size(int &width, int &height) const; 50 void get_preferred_size(int &width, int &height) const; 51 52 private: 53 #ifdef HAVE_GTK3 54 void draw_bar(const Cairo::RefPtr<Cairo::Context>& cr, 55 int x, int y, int width, int height, 56 int winw, int winh); 57 void set_color(const Cairo::RefPtr<Cairo::Context>& cr, const Gdk::Color &color); 58 void set_color(const Cairo::RefPtr<Cairo::Context>& cr, const Gdk::RGBA &color); 59 #else 60 void draw_bar(Glib::RefPtr<Gdk::Window> &window, 61 const Glib::RefPtr<Gdk::GC> &gc, 62 bool filled, int x, int y, int width, int height, 63 int winw, int winh); 64 #endif 65 void set_text_color(Gdk::Color color); 66 67 protected: 68 #ifdef HAVE_GTK3 69 virtual Gtk::SizeRequestMode get_request_mode_vfunc() const; 70 virtual void get_preferred_width_vfunc(int& minimum_width, int& natural_width) const; 71 virtual void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const; 72 virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const; 73 virtual void get_preferred_height_for_width_vfunc(int width, int& minimum_height, int& natural_height) const; 74 virtual void on_size_allocate(Gtk::Allocation& allocation); 75 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr); 76 #else 77 virtual void on_realize(); 78 virtual bool on_expose_event(GdkEventExpose *event); 79 virtual void on_size_request(GtkRequisition *requisition); 80 virtual void on_size_allocate(Gtk::Allocation& allocation); 81 #endif 82 83 private: 84 static Gdk::Color bar_colors[COLOR_ID_SIZEOF]; 85 86 #ifndef HAVE_GTK3 87 //! Graphic context. 88 Glib::RefPtr<Gdk::GC> window_gc; 89 #endif 90 91 //! Color of the time-bar. 92 ColorId bar_color; 93 94 //! Color of the time-bar. 95 ColorId secondary_bar_color; 96 97 //! Color of the text. 98 Gdk::Color bar_text_color; 99 100 //! The current value. 101 int bar_value; 102 103 //! The maximum value. 104 int bar_max_value; 105 106 //! The current value. 107 int secondary_bar_value; 108 109 //! The maximum value. 110 int secondary_bar_max_value; 111 112 //! Text to show; 113 std::string bar_text; 114 115 //! Text alignment 116 int bar_text_align; 117 118 //! Bar rotation (clockwise degrees) 119 int rotation; 120 }; 121 122 123 #endif // TIMEBAR_HH 124