Panda3D
|
00001 // Filename: graphicsWindow.h 00002 // Created by: mike (09Jan97) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef GRAPHICSWINDOW_H 00016 #define GRAPHICSWINDOW_H 00017 00018 #include "pandabase.h" 00019 00020 #include "graphicsOutput.h" 00021 #include "graphicsWindowInputDevice.h" 00022 #include "graphicsWindowProc.h" 00023 #include "graphicsWindowProcCallbackData.h" 00024 #ifdef HAVE_PYTHON 00025 #include "pythonGraphicsWindowProc.h" 00026 #endif 00027 #include "windowProperties.h" 00028 #include "mouseData.h" 00029 #include "modifierButtons.h" 00030 #include "buttonEvent.h" 00031 #include "keyboardButton.h" 00032 #include "pnotify.h" 00033 #include "lightMutex.h" 00034 #include "lightReMutex.h" 00035 #include "pvector.h" 00036 #include "windowHandle.h" 00037 #include "touchInfo.h" 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Class : GraphicsWindow 00041 // Description : A window, fullscreen or on a desktop, into which a 00042 // graphics device sends its output for interactive 00043 // display. 00044 //////////////////////////////////////////////////////////////////// 00045 class EXPCL_PANDA_DISPLAY GraphicsWindow : public GraphicsOutput { 00046 protected: 00047 GraphicsWindow(GraphicsEngine *engine, 00048 GraphicsPipe *pipe, 00049 const string &name, 00050 const FrameBufferProperties &fb_prop, 00051 const WindowProperties &win_prop, 00052 int flags, 00053 GraphicsStateGuardian *gsg, 00054 GraphicsOutput *host); 00055 00056 PUBLISHED: 00057 virtual ~GraphicsWindow(); 00058 00059 const WindowProperties get_properties() const; 00060 const WindowProperties get_requested_properties() const; 00061 void clear_rejected_properties(); 00062 WindowProperties get_rejected_properties() const; 00063 void request_properties(const WindowProperties &requested_properties); 00064 INLINE bool is_closed() const; 00065 virtual bool is_active() const; 00066 INLINE bool is_fullscreen() const; 00067 00068 void set_window_event(const string &window_event); 00069 string get_window_event() const; 00070 00071 void set_close_request_event(const string &close_request_event); 00072 string get_close_request_event() const; 00073 00074 INLINE void set_unexposed_draw(bool unexposed_draw); 00075 INLINE bool get_unexposed_draw() const; 00076 00077 INLINE WindowHandle *get_window_handle() const; 00078 00079 // Mouse and keyboard routines 00080 int get_num_input_devices() const; 00081 string get_input_device_name(int device) const; 00082 MAKE_SEQ(get_input_device_names, get_num_input_devices, get_input_device_name); 00083 bool has_pointer(int device) const; 00084 bool has_keyboard(int device) const; 00085 00086 00087 void enable_pointer_events(int device); 00088 void disable_pointer_events(int device); 00089 void enable_pointer_mode(int device, double speed); 00090 void disable_pointer_mode(int device); 00091 00092 MouseData get_pointer(int device) const; 00093 virtual bool move_pointer(int device, int x, int y); 00094 virtual void close_ime(); 00095 00096 #ifdef HAVE_PYTHON 00097 void add_python_event_handler(PyObject* handler, PyObject* name); 00098 void remove_python_event_handler(PyObject* name); 00099 #endif 00100 00101 public: 00102 // No need to publish these. 00103 bool has_button_event(int device) const; 00104 ButtonEvent get_button_event(int device); 00105 bool has_pointer_event(int device) const; 00106 PT(PointerEventList) get_pointer_events(int device); 00107 00108 virtual void add_window_proc( const GraphicsWindowProc* wnd_proc_object ){}; 00109 virtual void remove_window_proc( const GraphicsWindowProc* wnd_proc_object ){}; 00110 virtual void clear_window_procs(){}; 00111 virtual bool supports_window_procs() const; 00112 00113 virtual int verify_window_sizes(int numsizes, int *dimen); 00114 00115 virtual bool is_touch_event(GraphicsWindowProcCallbackData* callbackData); 00116 virtual int get_num_touches(); 00117 virtual TouchInfo get_touch_info(int index); 00118 00119 public: 00120 virtual void request_open(); 00121 virtual void request_close(); 00122 00123 // It is an error to call any of the following methods from any 00124 // thread other than the window thread. These methods are normally 00125 // called by the GraphicsEngine. 00126 virtual void set_close_now(); 00127 virtual void process_events(); 00128 virtual void set_properties_now(WindowProperties &properties); 00129 00130 protected: 00131 virtual void close_window(); 00132 virtual bool open_window(); 00133 virtual void reset_window(bool swapchain); 00134 00135 virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin, 00136 int x_size, int y_size); 00137 00138 virtual void mouse_mode_absolute(); 00139 virtual void mouse_mode_relative(); 00140 00141 // It is an error to call any of the following methods from any 00142 // thread other than the window thread. 00143 void system_changed_properties(const WindowProperties &properties); 00144 void system_changed_size(int x_size, int y_size); 00145 00146 protected: 00147 int add_input_device(const GraphicsWindowInputDevice &device); 00148 typedef vector_GraphicsWindowInputDevice InputDevices; 00149 InputDevices _input_devices; 00150 LightMutex _input_lock; 00151 00152 protected: 00153 WindowProperties _properties; 00154 PT(WindowHandle) _window_handle; 00155 PT(WindowHandle) _parent_window_handle; 00156 00157 bool _got_expose_event; 00158 00159 private: 00160 LightReMutex _properties_lock; 00161 // protects _requested_properties, _rejected_properties, and 00162 // _window_event. 00163 00164 WindowProperties _requested_properties; 00165 WindowProperties _rejected_properties; 00166 string _window_event; 00167 string _close_request_event; 00168 bool _unexposed_draw; 00169 00170 #ifdef HAVE_PYTHON 00171 typedef pset<PythonGraphicsWindowProc*> PythonWinProcClasses; 00172 PythonWinProcClasses _python_window_proc_classes; 00173 #endif 00174 00175 public: 00176 static TypeHandle get_class_type() { 00177 return _type_handle; 00178 } 00179 static void init_type() { 00180 GraphicsOutput::init_type(); 00181 register_type(_type_handle, "GraphicsWindow", 00182 GraphicsOutput::get_class_type()); 00183 } 00184 virtual TypeHandle get_type() const { 00185 return get_class_type(); 00186 } 00187 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00188 00189 private: 00190 static TypeHandle _type_handle; 00191 00192 friend class GraphicsEngine; 00193 }; 00194 00195 #include "graphicsWindow.I" 00196 00197 #endif /* GRAPHICSWINDOW_H */