Hermes2D  2.0
view_support.h
1 // This file is part of Hermes2D.
2 //
3 // Copyright 2009-2010 Ivo Hanak <hanak@byte.cz>
4 // Copyright 2005-2008 Jakub Cerveny <jakub.cerveny@gmail.com>
5 // Copyright 2005-2008 Lenka Dubcova <dubcova@gmail.com>
6 // Copyright 2005-2008 Pavel Solin <solin@unr.edu>
7 //
8 // Hermes2D is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Hermes2D is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
20 
21 // $Id: view.h 1086 2008-10-21 09:05:44Z jakub $
22 
23 #ifndef __H2D_VIEW_SUPPORT_H
24 #define __H2D_VIEW_SUPPORT_H
25 
26 namespace Hermes
27 {
28  namespace Hermes2D
29  {
30  namespace Views
31  {
32  // you can define NOGLUT to turn off all OpenGL stuff in Hermes2D
33 #ifndef NOGLUT
34 
35  /* types */
36  class HERMES_API ViewMonitor
37  {
38  protected:
39  pthread_mutexattr_t mutex_attr;
40  pthread_mutex_t mutex;
41  pthread_cond_t cond_cross_thread_call;
42  pthread_cond_t cond_keypress;
43  pthread_cond_t cond_close;
44  pthread_cond_t cond_drawing_finished;
45  public:
46  ViewMonitor();
47  ~ViewMonitor();
48  inline void enter() { pthread_mutex_lock(&mutex); };
49  inline void leave() { pthread_mutex_unlock(&mutex); };
50  inline void signal_keypress() { pthread_cond_broadcast(&cond_keypress); };
51  inline void wait_keypress() { pthread_cond_wait(&cond_keypress, &mutex); };
52  inline void signal_close() { pthread_cond_broadcast(&cond_close); };
53  inline void wait_close() { pthread_cond_wait(&cond_close, &mutex); };
54  inline void signal_drawing_finished() { pthread_cond_broadcast(&cond_drawing_finished); };
55  inline void wait_drawing_fisnihed() { pthread_cond_wait(&cond_drawing_finished, &mutex); };
56  inline void signal_cross_thread_call() { pthread_cond_broadcast(&cond_cross_thread_call); };
57  inline void wait_cross_thread_call() { pthread_cond_wait(&cond_cross_thread_call, &mutex); };
58  };
59 
60  /* exported types */
61  extern ViewMonitor view_sync;
62 
63  /* exported functions */
64  class View;
65 
66  HERMES_API bool init_glut();
67  HERMES_API bool shutdown_glut();
68  extern "C"
69  {
70  int add_view(View* view, int x, int y, int width, int height, const char* title);
71  }
72  extern void set_view_title(int view_id, const char* title);
73  extern void refresh_view(int view_id);
74  extern void remove_view(int view_id);
75  //extern void force_view_thread_shutdown(); ///< Forces view thread to shutdown.
76  extern void wait_for_all_views_close(const char* text);
77  extern void wait_for_any_key(const char* text);
78 
79  extern void on_display_stub(void);
80  extern void on_reshape_stub(int width, int height);
81  extern void on_mouse_move_stub(int x, int y);
82  extern void on_key_down_stub(unsigned char key, int x, int y);
83  extern void on_special_key_stub(int key, int x, int y);
84  extern void on_entry_stub(int state);
85  extern void on_mouse_click_stub(int button, int state, int x, int y);
86  extern void on_close_stub();
87 
88 #endif
89  }
90  }
91 }
92 #endif