Hermes2D  3.0
view_support.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 // $Id: view.h 1086 2008-10-21 09:05:44Z jakub $
17 
18 #ifndef __H2D_VIEW_SUPPORT_H
19 #define __H2D_VIEW_SUPPORT_H
20 #ifndef NOGLUT
21 #include <pthread.h>
22 #endif
23 namespace Hermes
24 {
25  namespace Hermes2D
26  {
27  namespace Views
28  {
29  // you can define NOGLUT to turn off all OpenGL stuff in Hermes2D
30 #ifndef NOGLUT
31 
32  /* types */
34  class HERMES_API ViewMonitor
35  {
36  protected:
38  pthread_mutexattr_t mutex_attr;
40  pthread_mutex_t mutex;
42  pthread_cond_t cond_cross_thread_call;
44  pthread_cond_t cond_keypress;
46  pthread_cond_t cond_close;
48  pthread_cond_t cond_drawing_finished;
49  public:
50  ViewMonitor();
51  ~ViewMonitor();
53  inline void enter() { pthread_mutex_lock(&mutex); };
55  inline void leave() { pthread_mutex_unlock(&mutex); };
57  inline void signal_keypress() { pthread_cond_broadcast(&cond_keypress); };
59  inline void wait_keypress() { pthread_cond_wait(&cond_keypress, &mutex); };
61  inline void signal_close() { pthread_cond_broadcast(&cond_close); };
63  inline void wait_close() { pthread_cond_wait(&cond_close, &mutex); };
65  inline void signal_drawing_finished() { pthread_cond_broadcast(&cond_drawing_finished); };
67  inline void wait_drawing_fisnihed() { pthread_cond_wait(&cond_drawing_finished, &mutex); };
69  inline void signal_cross_thread_call() { pthread_cond_broadcast(&cond_cross_thread_call); };
71  inline void wait_cross_thread_call() { pthread_cond_wait(&cond_cross_thread_call, &mutex); };
72  };
73 
74  /* exported types */
76  extern ViewMonitor view_sync;
77 
78  /* exported functions */
79  class View;
80 
82  HERMES_API bool init_glut();
84  HERMES_API bool shutdown_glut();
85  extern "C"
86  {
88  int add_view(View* view, int x, int y, int width, int height, const char* title);
89  }
91  extern void set_view_title(int view_id, const char* title);
93  extern void refresh_view(int view_id);
95  extern void remove_view(int view_id);
97  //extern void force_view_thread_shutdown();
99  extern void wait_for_all_views_close(const char* text);
101  extern void wait_for_any_key(const char* text);
102 
103  extern void on_display_stub(void);
104  extern void on_reshape_stub(int width, int height);
105  extern void on_mouse_move_stub(int x, int y);
106  extern void on_key_down_stub(unsigned char key, int x, int y);
107  extern void on_special_key_stub(int key, int x, int y);
108  extern void on_entry_stub(int state);
109  extern void on_mouse_click_stub(int button, int state, int x, int y);
110  extern void on_close_stub();
111 
112 #endif
113  }
114  }
115 }
116 #endif
Definition: adapt.h:24
void refresh_view(int view_id)
Forces redisplay of a view.
void remove_view(int view_id)
Removes a view.
pthread_cond_t cond_drawing_finished
Condition used to signal that drawing has finished.
Definition: view_support.h:48
pthread_mutex_t mutex
Mutex that protects monitor.
Definition: view_support.h:40
void signal_drawing_finished()
signals drawing finished inside a protected section
Definition: view_support.h:65
void signal_close()
signals close inside a protected section
Definition: view_support.h:61
void leave()
leaves protected section
Definition: view_support.h:55
void wait_close()
waits for close inside a protected section
Definition: view_support.h:63
void enter()
enters protected section
Definition: view_support.h:53
ViewMonitor view_sync
synchronization between all views. Used to access OpenGL and signal a window close event and a keypre...
void wait_drawing_fisnihed()
waits for drawing finished inside a protected section
Definition: view_support.h:67
int add_view(View *view, int x, int y, int width, int height, const char *title)
Adds a view.
void wait_for_any_key(const char *text)
Waits for a keypress which is not processed.
void wait_keypress()
waits for keypress inside a protected section
Definition: view_support.h:59
pthread_cond_t cond_cross_thread_call
Condition used to signal a cross-thread call.
Definition: view_support.h:42
void signal_keypress()
signals keypress inside a protected section
Definition: view_support.h:57
void wait_cross_thread_call()
waits for finishing of a cross-thread call
Definition: view_support.h:71
void signal_cross_thread_call()
signals that cross-thread-call finished
Definition: view_support.h:69
HERMES_API bool init_glut()
Initialize GLUT.
pthread_cond_t cond_close
Condition used to signal close of a window.
Definition: view_support.h:46
< A monitor used to synchronize thread in views.
Definition: view_support.h:34
void wait_for_all_views_close(const char *text)
Forces view thread to shutdown.
pthread_cond_t cond_keypress
Condition used to signal a keypress.
Definition: view_support.h:44
void set_view_title(int view_id, const char *title)
Sets title of a view.
pthread_mutexattr_t mutex_attr
Mutext attributes.
Definition: view_support.h:38
HERMES_API bool shutdown_glut()
Shutdown GLUT.