UniWidgets  1.2.0
UScale.h
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * This library is free software; you can redistribute it and/or
00003  * modify it under the terms of the LGPL
00004  *****************************************************************************/
00005 
00006 #ifndef USCALE_H
00007 #define USCALE_H
00008 
00009 #include <vector>
00010 #include <map>
00011 
00012 #include <sigc++/sigc++.h>
00013 
00014 #include <gtkmm.h>
00015 
00016 #include <plotmm/doubleintmap.h>
00017 #include <plotmm/scalediv.h>
00018 
00019 namespace Pango {
00020     class Layout;
00021     class FontDescription;
00022 }
00026     class ScaleLabels : public Gtk::EventBox {
00027         public:
00028             ScaleLabels(Gtk::PositionType p);
00029             virtual ~ScaleLabels();
00030 
00032             Pango::FontDescription *font() { return &font_; }
00033             void set_labels(int offs, const std::map<int,double> &labels);
00034 
00035             void set_labels_color(Gdk::Color color);
00036             void set_labels_font(Pango::FontDescription fd);
00037             void set_enabled(bool b);
00039             bool enabled() const { return enabled_; }
00040             Glib::ustring format(double) const;
00041             int text_width(const Glib::ustring &) const;
00042             int text_height(const Glib::ustring &) const;
00044             inline Gtk::PositionType position(){ return position_; };
00045 
00046             inline void set_scaleDiv(const PlotMM::ScaleDiv &Div){ scaleDiv_ = Div;};
00047             inline void set_scaleMap(const PlotMM::DoubleIntMap &Map){ scaleMap_ = Map;};
00048 
00049         protected:
00050             virtual void newsize_();
00051             virtual void requestsize_() {}
00052             virtual bool on_map_event(GdkEvent *event);
00053 
00054             int offset_;
00055             int layw_, layh_;
00056             int range_;
00057             std::map<int,double> labels_;
00058             Glib::RefPtr<Pango::Layout> layout_;
00059             Pango::FontDescription font_;
00060             Gdk::Color label_color;
00061             bool is_show;
00062 
00063             PlotMM::ScaleDiv scaleDiv_;
00064             PlotMM::DoubleIntMap scaleMap_;
00065 
00066         private:
00067             Gtk::PositionType position_;
00068             bool enabled_;
00069     };
00070 
00074     class VScaleLabels : public ScaleLabels {
00075         public:
00076             VScaleLabels(Gtk::PositionType p);
00077             virtual ~VScaleLabels();
00078 
00079         protected:
00080             virtual bool on_expose_event(GdkEventExpose* event);
00081             virtual void update_();
00082             virtual void requestsize_();
00083     };
00084 
00088     class HScaleLabels : public ScaleLabels {
00089         public:
00090             HScaleLabels(Gtk::PositionType p);
00091             virtual ~HScaleLabels();
00092 
00093             inline void set_curPos(double pos)
00094             {
00095                 last_pos = cur_pos;
00096                 cur_pos = pos;
00097             };
00098             inline void use_real_time(bool state){ use_real_time_flag = state;};
00099 
00100         protected:
00101             virtual bool on_expose_event(GdkEventExpose* event);
00102             virtual void update_();
00103             virtual void requestsize_();
00104             double cur_pos;
00105             double last_pos;
00106             time_t last_time;
00107             bool use_real_time_flag;
00108     };
00109 
00110 
00111 
00115     class Scale : public Gtk::EventBox
00116     {
00117         public:
00118             Scale(Gtk::PositionType p, ScaleLabels *labels= 0);
00119             virtual ~Scale();
00120 
00121             void set_position(Gtk::PositionType p);
00123             Gtk::PositionType position() const { return position_; }
00124 
00125             void set_ticklengths(int major, int minor);
00126             void set_scale_color(Gdk::Color color);
00128             int major_ticklength() const { return majorTL_; }
00130             int minor_ticklength() const { return minorTL_; }
00131 
00133             inline ScaleLabels* get_labels(){return labels_;};
00134 
00135             void set_enabled(bool b);
00137             bool enabled() const { return enabled_; }
00138             inline void set_max_major(int max){maxMaj = max;};
00139             inline void set_max_minor(int max){maxMin = max;};
00140 
00142             const PlotMM::DoubleIntMap &scale_map() const { return scaleMap_; }
00143 
00144             void set_range(double l, double r);
00145             void set_range(double l, double r, bool lg);
00146 
00147             void set_autoscale(bool b);
00149             bool autoscale() const { return autoscale_; }
00150             void begin_autoscale();
00151             void autoscale(double min, double max);
00152             void end_autoscale();
00153 
00157             sigc::signal1<void,bool> signal_enabled;
00158 
00159         protected:
00160             virtual void on_realize();
00161             virtual bool on_expose_event(GdkEventExpose* event);
00162             virtual bool on_map_event(GdkEvent *event);
00163 
00165             virtual void on_tick_change() {}
00166             virtual void redraw() = 0;
00167 
00168             Glib::RefPtr<Gdk::Window> window_;
00169             ScaleLabels *labels_;
00170             Gdk::Color scale_color;
00171             int maxMaj;
00172             int maxMin;
00173             bool is_show;
00174 
00175             PlotMM::ScaleDiv scaleDiv_;
00176             PlotMM::DoubleIntMap scaleMap_;
00177 
00178         private:
00179             Gtk::PositionType position_;
00180             bool autoscale_;
00181             bool enabled_;
00182             int majorTL_, minorTL_;
00183             double asMin_, asMax_;
00184     };
00185 
00189     class VScale : public Scale
00190     {
00191         public:
00192             VScale(Gtk::PositionType p, ScaleLabels *l= 0);
00193             virtual ~VScale();
00194 
00195         protected:
00196             virtual void redraw();
00197             virtual void on_tick_change();
00198     };
00199 
00203     class HScale : public Scale
00204     {
00205         public:
00206             HScale(Gtk::PositionType p, ScaleLabels *l= 0);
00207             virtual ~HScale();
00208 
00209         protected:
00210             virtual void redraw();
00211             virtual void on_tick_change();
00212     };
00213 
00217     class Web : public Gtk::EventBox
00218     {
00219         public:
00220             Web();
00221             virtual ~Web();
00222 
00223             void set_web_color(Gdk::Color color);
00224 
00225             void set_enabled(bool b);
00227             bool enabled() const { return enabled_; }
00228             inline void set_max_h_major(int max){maxMajH = max;};
00229             inline void set_max_h_minor(int max){maxMinH = max;};
00230             inline void set_max_v_major(int max){maxMajV = max;};
00231             inline void set_max_v_minor(int max){maxMinV = max;};
00232 
00234             const PlotMM::DoubleIntMap &h_map() const { return HMap_; }
00235             const PlotMM::DoubleIntMap &v_map() const { return VMap_; }
00236 
00237             void set_h_range(double l, double r);
00238             void set_h_range(double l, double r, bool lg);
00239             void set_v_range(double l, double r);
00240             void set_v_range(double l, double r, bool lg);
00241 
00245             sigc::signal1<void,bool> signal_enabled;
00246 
00247         protected:
00248             virtual void on_realize();
00249             virtual bool on_expose_event(GdkEventExpose* event);
00250             virtual bool on_map_event(GdkEvent *event);
00251 
00252             virtual void redraw();
00253 
00254             Gdk::Color web_color;
00255             int maxMajH;
00256             int maxMinH;
00257             int maxMajV;
00258             int maxMinV;
00259             bool is_show;
00260 
00261             Glib::RefPtr<Gdk::Window> window_;
00262 
00263             PlotMM::ScaleDiv HDiv_;
00264             PlotMM::DoubleIntMap HMap_;
00265             PlotMM::ScaleDiv VDiv_;
00266             PlotMM::DoubleIntMap VMap_;
00267 
00268         private:
00269             bool enabled_;
00270     };
00271 
00272 #endif