MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
widgets.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; version 2 of the
7  * License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 
26 #ifndef _WIDGETS_H_
27 #define _WIDGETS_H_
28 
29 #include <list>
30 
31 #include "glib.h"
32 #include "cairo/cairo.h"
33 
34 #include "mforms/base.h"
35 #include "mforms/drawbox.h"
36 #include "mforms/box.h"
37 #include "mforms/label.h"
38 #include "mforms/table.h"
39 #include "base/threaded_timer.h"
40 #include "base/geometry.h"
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 namespace mforms {
44 
45  typedef std::list<double> ThresholdList;
46 
47  class MFORMS_EXPORT BaseWidget : public DrawBox
48  {
49  public:
50  BaseWidget();
51  ~BaseWidget();
52 
53  void set_right_align(bool flag);
54  void enable_auto_scale(bool enable);
55  double get_upper_range() const;
56  void set_value_range(double low, double high);
57  void set_thresholds(ThresholdList lower_thresholds, ThresholdList upper_thresholds);
58  void set_description(const std::string& description);
59 #ifndef SWIG
60  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
61  virtual void get_layout_size(int* w, int* h);
62 
63  virtual void step() {};
64 #endif
65 
66  protected:
67  cairo_surface_t* _background;
68  bool _auto_scale;
69  bool _right_align;
70  base::Rect _diagram_area;
71  int _layout_width;
72  int _layout_height;
73 
74  void lock();
75  void unlock();
76  double normalize(double input);
77  virtual void prepare_background() {};
78  virtual void destroy_background();
79  virtual void range_updated(double scale, double offset) {};
80  virtual bool layout(cairo_t *cr);
81  void auto_scale(double value);
82  bool compute_scale(double min, double max);
83  virtual void get_minmax_values(double* min, double* max);
84  private:
85  base::Mutex _lock;
86  double _lower_limit;
87  double _upper_limit;
88  ThresholdList _lower_thresholds;
89  ThresholdList _upper_thresholds;
90  std::string _description;
91 
92  int _last_width; // Needed to detect when we need a re-layout.
93  int _last_height;
94 
95  int _description_offset; // Depends on alignment.
96 
97  cairo_t* _layout_context;
98  cairo_surface_t* _layout_surface;
99  void create_context_for_layout();
100  };
101 
102  class MFORMS_EXPORT WidgetSeparator : public DrawBox
103  {
104  protected:
105  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
106  };
107 
108  // Number of values to use for the heartbeat.
109  #define HEARTBEAT_DATA_SIZE 80
110 
111  class MFORMS_EXPORT HeartbeatWidget : public BaseWidget
112  {
113  public:
114  HeartbeatWidget();
115  ~HeartbeatWidget();
116 #ifndef SWIG
117  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
118  virtual void step();
119 #endif
120  void set_value(double value);
121  protected:
122  virtual void prepare_background();
123  virtual void range_updated(double scale, double offset);
124  virtual void get_minmax_values(double* min, double* max);
125  private:
126  int _pivot;
127  double _luminance[HEARTBEAT_DATA_SIZE];
128  double _deflection[HEARTBEAT_DATA_SIZE];
129  };
130 
134  class MFORMS_EXPORT ServerStatusWidget : public BaseWidget
135  {
136  public:
137  ServerStatusWidget();
138  ~ServerStatusWidget();
139 
140 #ifndef SWIG
141  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
142 #endif
143  void set_server_status(int status);
144  protected:
145  virtual bool layout(cairo_t *cr);
146  private:
147  int _status; // -1 for unknown, 0 for not-running, 1 for running.
148 
149  cairo_surface_t* _image_unknown;
150  cairo_surface_t* _image_running;
151  cairo_surface_t* _image_stopped;
152  };
153 
157  class MFORMS_EXPORT BarGraphWidget : public BaseWidget
158  {
159  public:
160  BarGraphWidget();
161  ~BarGraphWidget();
162 
163 #ifndef SWIG
164  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
165 #endif
166  void set_value(double value);
167  protected:
168  virtual void prepare_background();
169  virtual void destroy_background();
170  void create_value_gradient();
171  virtual void range_updated(double scale, double offset);
172  virtual void get_minmax_values(double* min, double* max);
173  private:
174  double _value;
175  cairo_pattern_t* _value_gradient;
176  cairo_surface_t* _grid;
177  };
178 
183  #define LINE_SERIES_DATA_SIZE 500
184 
185  class MFORMS_EXPORT LineDiagramWidget : public BaseWidget
186  {
187  public:
188  LineDiagramWidget();
189  ~LineDiagramWidget();
190 
191 #ifndef SWIG
192  virtual void repaint(cairo_t *cr, int areax, int areay, int areaw, int areah);
193  virtual void step();
194 #endif
195  void set_value(double value);
196  protected:
197  virtual void prepare_background();
198  virtual void destroy_background();
199  virtual void range_updated(double scale, double offset);
200  virtual void get_minmax_values(double* min, double* max);
201  private:
202  double _next_value;
203  double _deflection[LINE_SERIES_DATA_SIZE];
204  double _timestamp[LINE_SERIES_DATA_SIZE];
205  int _time_in_view; // Seconds to show in the widget.
206  cairo_pattern_t* _value_gradient;
207  GTimer* _clock; // Used to generate timestamps for incoming values.
208  cairo_surface_t* _grid;
209  double _content_alpha; // Used to blend out the content for special feedback.
210  double _warning_alpha; // Alpha for warning feedback.
211  double _last_shift; // The animation timer is faster than our shift needs to be.
212  // Hence determine the distance since the last shift before we do the next.
213  double _sleep_start; // 0 if not sleeping, otherwise the timestamp of when
214  // sleeping started.
215  enum {Awake, GoSleeping, Sleeping, Awaking} _sleep_mode;
216 
217  cairo_text_extents_t _warning_extents;
218 
219  void show_feedback(cairo_t* cr, const base::Rect& bounds);
220  void begin_sleeping(double timestamp);
221  void end_sleeping(double timestamp);
222  bool feedback_step();
223  };
224 
225 }
226 
227 #endif // !DOXYGEN_SHOULD_SKIP_THIS
228 
229 #endif // _WIDGETS_H_
#define MFORMS_EXPORT
Definition: base.h:33
MySQL Workbench 6.1 documentation