KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gui_window.h
Go to the documentation of this file.
1 /* $Id: gui_window.h 18278 2014-11-25 01:42:10Z ksimek $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef KJB_CPP_GUI_WINDOW_H
23 #define KJB_CPP_GUI_WINDOW_H
24 
25 #ifdef KJB_HAVE_OPENGL
26 
27 #include <gui_cpp/gui_overlay.h>
28 #include <gui_cpp/gui_button.h>
30 #include <boost/shared_ptr.hpp>
31 #include <boost/function.hpp>
32 
33 namespace kjb
34 {
35 namespace gui
36 {
37 
43 class Window : public Interactive_overlay
44 {
45 typedef Window Self;
46 typedef Interactive_overlay Base;
47 
48 private:
49  // pass this to boost::shared_ptr's constructor to prevent destruction of
50  // unner object
51  struct null_deleter
52  {
53  void operator()(void const*) const
54  { }
55  };
56 
57  class Close_button : public Abstract_button
58  {
59  public:
60  Close_button(int x, int y, int width, int height, const boost::function0<void>& callback);
61 
62  virtual void render_down() const;
63  virtual void render_up() const
64  {
65  render_down();
66  }
67 
68  private:
69  void render_circle_() const;
70  void render_plus_() const;
71  };
72 
73 public:
74  Window(
75  int x,
76  int y,
77  int width,
78  int height);
79 
80  virtual void render() const;
81 
82 // ATTACH METHODS
86  void attach(Interactive_overlay* overlay);
87 
91  void attach(boost::shared_ptr<Interactive_overlay> overlay);
92 
96  void attach(Overlay* overlay);
97 
101  void attach(boost::shared_ptr<Overlay> overlay);
102 
106  void set_close_callback(const boost::function0<void>& callback);
107 
115  void set_clicked_callback(const boost::function0<void>& callback);
116 
117 // EVENT HANDLERS
121  bool mouse_event(int button, int state, int x, int y);
122 
123  bool mouse_double_event(int button, int state, int x, int y);
124 
125  bool motion_event(int x, int y);
126 
127  bool passive_motion_event(int x, int y);
128 
129  bool keyboard_event(unsigned int key, int x, int y);
130 
131  bool special_event(int key, int x, int y);
132 
133  void claim_focus();
134 
135  void yield_focus();
136 
137 // WINDOW MODIFIERS
138 
141  virtual void set_size(int width, int height);
142 
145  virtual void set_position(int x, int y);
146 
147  void redisplay();
153  void close();
154 
155  void hide();
156 
157  void show();
158 
159  void hide_titlebar();
160 
161  void show_titlebar();
162 
163 private:
165  bool mouse_dispatch_(int button, int state, int x, int y);
166 
167  bool cursor_on_left_border(int cursor_x, int cursor_y) const;
168 
169  bool cursor_on_right_border(int cursor_x, int cursor_y) const;
170 
171  bool cursor_on_bottom_border(int cursor_x, int cursor_y) const;
172 
173  bool cursor_on_top_border(int cursor_x, int cursor_y) const;
174 
175  bool has_focus() const;
176 
177 
178 // SPECIALIZED CLICK FUNCTIONS
183 #ifdef KJB_HAVE_GLUT
184  bool title_bar_click_(int button, int state, int x, int y);
185 #endif
186 
191 #ifdef KJB_HAVE_GLUT
192  bool resize_click_(int button, int state, int x, int y);
193 #endif
194 
195 // SPECIALIZED DRAG FUNCTIONS
201  void drag_move_(int cursor_x, int cursor_y);
202 
208  void drag_resize_(int cursor_x, int cursor_y);
209 
210 // GEOMETRY HELPERS
214  inline bool point_inside_window_(int pt_x, int pt_y)
215  {
216  if( pt_x < x() ) return false;
217  if( pt_x >= x() + width() ) return false;
218  if( pt_y < y() ) return false;
219  if( pt_y >= y() + height() ) return false;
220  return true;
221  }
222 
227  void update_overlay_geometry_();
228 
229  void update_close_button_geometry_();
230 
231 // WINDOW DECORATION RENDERING
232  void render_background_() const;
233 
234  void render_border_() const;
235 
236  void render_title_bar_() const;
237 
238 private:
239 
240  enum Click_state {click_none, click_resize, click_move};
241  enum Resize_state {resize_none, resize_left, resize_right, resize_bottom, resize_top};
242 
243 private:
244 
245  bool visible_;
246  bool listening_;
247  bool has_focus_;
248  boost::function0<void> clicked_callback_;
249 
250  Close_button close_button_;
251  boost::function0<void> close_callback_;
252 
253  boost::shared_ptr<Overlay> overlay_;
254  boost::shared_ptr<Event_listener> listener_;
255 
256  Click_state click_state_;
257  Resize_state x_resize_state_;
258  Resize_state y_resize_state_;
259  int move_offset_x_;
260  int move_offset_y_;
261 
262  bool special_cursor_; // are we currently using a non-default cursor?
263 
264  bool show_titlebar_;
265  static const int TITLE_BAR_HEIGHT;
266  static const int BORDER_WIDTH;
267  static const int BORDER_SLOP;
268  static const int MIN_WINDOW_HEIGHT;
269  static const int MIN_WINDOW_WIDTH;
270  static const int PADDING;
271  static const int CLOSE_BUTTON_HEIGHT;
272  static const int CLOSE_BUTTON_WIDTH;
273  static const int CLOSE_BUTTON_X_OFFSET;
274  static const int CLOSE_BUTTON_Y_OFFSET;
275 };
276 
277 }
278 }
279 
280 #endif /* have_opengl */
281 
282 #endif
height
Definition: APPgetLargeConnectedEdges.m:33
x
Definition: APPgetLargeConnectedEdges.m:100
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56