Panda3D

graphicsWindow.h

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 "windowProperties.h"
00023 #include "mouseData.h"
00024 #include "modifierButtons.h"
00025 #include "buttonEvent.h"
00026 #include "keyboardButton.h"
00027 #include "pnotify.h"
00028 #include "lightMutex.h"
00029 #include "lightReMutex.h"
00030 #include "pvector.h"
00031 #include "windowHandle.h"
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : GraphicsWindow
00035 // Description : A window, fullscreen or on a desktop, into which a
00036 //               graphics device sends its output for interactive
00037 //               display.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_DISPLAY GraphicsWindow : public GraphicsOutput {
00040 protected:
00041   GraphicsWindow(GraphicsEngine *engine,
00042                  GraphicsPipe *pipe, 
00043                  const string &name,
00044                  const FrameBufferProperties &fb_prop,
00045                  const WindowProperties &win_prop,
00046                  int flags,
00047                  GraphicsStateGuardian *gsg,
00048                  GraphicsOutput *host);
00049 
00050 PUBLISHED:
00051   virtual ~GraphicsWindow();
00052 
00053   const WindowProperties get_properties() const;
00054   const WindowProperties get_requested_properties() const;
00055   void clear_rejected_properties();
00056   WindowProperties get_rejected_properties() const;
00057   void request_properties(const WindowProperties &requested_properties);
00058   INLINE bool is_closed() const;
00059   virtual bool is_active() const;
00060   INLINE bool is_fullscreen() const;
00061 
00062   void set_window_event(const string &window_event);
00063   string get_window_event() const;
00064 
00065   void set_close_request_event(const string &close_request_event);
00066   string get_close_request_event() const;
00067 
00068   INLINE WindowHandle *get_window_handle() const;
00069   
00070   // Mouse and keyboard routines
00071   int get_num_input_devices() const;
00072   string get_input_device_name(int device) const;
00073   MAKE_SEQ(get_input_device_names, get_num_input_devices, get_input_device_name);
00074   bool has_pointer(int device) const;
00075   bool has_keyboard(int device) const;
00076   
00077 
00078   void enable_pointer_events(int device);
00079   void disable_pointer_events(int device);
00080   void enable_pointer_mode(int device, double speed);
00081   void disable_pointer_mode(int device);
00082 
00083   MouseData get_pointer(int device) const;
00084   virtual bool move_pointer(int device, int x, int y);
00085   virtual void close_ime();
00086 
00087 public:
00088   // No need to publish these.
00089   bool has_button_event(int device) const;
00090   ButtonEvent get_button_event(int device);
00091   bool has_pointer_event(int device) const;
00092   PT(PointerEventList) get_pointer_events(int device);
00093 
00094   virtual int verify_window_sizes(int numsizes, int *dimen);
00095 
00096 public:
00097   virtual void request_open();
00098   virtual void request_close();
00099 
00100   // It is an error to call any of the following methods from any
00101   // thread other than the window thread.  These methods are normally
00102   // called by the GraphicsEngine.
00103   virtual void set_close_now();
00104   virtual void process_events();
00105   virtual void set_properties_now(WindowProperties &properties);
00106 
00107 protected:
00108   virtual void close_window();
00109   virtual bool open_window();
00110   virtual void reset_window(bool swapchain);
00111 
00112   virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
00113                                   int x_size, int y_size);
00114 
00115   virtual void mouse_mode_absolute();
00116   virtual void mouse_mode_relative();
00117 
00118   // It is an error to call any of the following methods from any
00119   // thread other than the window thread.
00120   void system_changed_properties(const WindowProperties &properties);
00121   void system_changed_size(int x_size, int y_size);
00122 
00123 private:
00124   static unsigned int parse_color_mask(const string &word);
00125 
00126 protected:
00127   INLINE void add_input_device(const GraphicsWindowInputDevice &device);
00128   typedef vector_GraphicsWindowInputDevice InputDevices;
00129   InputDevices _input_devices;
00130   LightMutex _input_lock;
00131 
00132 protected:
00133   WindowProperties _properties;
00134   PT(WindowHandle) _window_handle;
00135   PT(WindowHandle) _parent_window_handle;
00136 
00137 private:
00138   LightReMutex _properties_lock; 
00139   // protects _requested_properties, _rejected_properties, and
00140   // _window_event.
00141 
00142   WindowProperties _requested_properties;
00143   WindowProperties _rejected_properties;
00144   string _window_event;
00145   string _close_request_event;
00146   
00147 public:
00148   static TypeHandle get_class_type() {
00149     return _type_handle;
00150   }
00151   static void init_type() {
00152     GraphicsOutput::init_type();
00153     register_type(_type_handle, "GraphicsWindow",
00154                   GraphicsOutput::get_class_type());
00155   }
00156   virtual TypeHandle get_type() const {
00157     return get_class_type();
00158   }
00159   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00160 
00161 private:
00162   static TypeHandle _type_handle;
00163 
00164   friend class GraphicsEngine;
00165 };
00166 
00167 #include "graphicsWindow.I"
00168 
00169 #endif /* GRAPHICSWINDOW_H */
 All Classes Functions Variables Enumerations