Panda3D
 All Classes Functions Variables Enumerations
osxGraphicsWindow.h
00001 ////////////////////////////////////////////////////////////////////
00002 //
00003 // PANDA 3D SOFTWARE
00004 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00005 //
00006 // All use of this software is subject to the terms of the revised BSD
00007 // license.  You should have received a copy of this license along
00008 // with this source code in a file named "LICENSE."
00009 //
00010 ////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef OSXGRAPHICSWINDOW_H
00013 #define OSXGRAPHICSWINDOW_H
00014 
00015 #include "pandabase.h"
00016 #include "graphicsWindow.h"
00017 #include "buttonHandle.h"
00018 
00019 #include <Carbon/Carbon.h>
00020 
00021 #define __glext_h_
00022 #include <OpenGL/gl.h>
00023 #include <AGL/agl.h>
00024 
00025 #define HACK_SCREEN_HASH_CONTEXT true
00026 OSStatus report_agl_error(const string &comment);
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : osxGraphicsWindow
00030 // Description : An interface to the osx/ system for managing GL
00031 //               windows under X.
00032 ////////////////////////////////////////////////////////////////////
00033 class osxGraphicsWindow : public GraphicsWindow {
00034 public:
00035   osxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, 
00036                     const string &name,
00037                     const FrameBufferProperties &fb_prop,
00038                     const WindowProperties &win_prop,
00039                     int flags,
00040                     GraphicsStateGuardian *gsg,
00041                     GraphicsOutput *host);
00042   virtual ~osxGraphicsWindow();
00043 
00044   virtual bool move_pointer(int device, int x, int y);
00045 
00046   virtual bool begin_frame(FrameMode mode, Thread *current_thread);
00047   virtual void end_frame(FrameMode mode, Thread *current_thread);
00048   virtual void begin_flip();
00049   virtual void end_flip();
00050   virtual void process_events();
00051   
00052   virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
00053                                   int x_size, int y_size);
00054   
00055   virtual void mouse_mode_absolute();
00056   virtual void mouse_mode_relative();
00057 
00058   virtual void set_properties_now(WindowProperties &properties);
00059 
00060 private:
00061   void release_system_resources(bool destructing);
00062   inline void send_key_event(ButtonHandle key, bool down);
00063 
00064 protected:
00065   virtual void close_window();
00066   virtual bool open_window();
00067 
00068 private:
00069   bool os_open_window(WindowProperties &properties);
00070 
00071   //
00072   // a singleton .. for the events to find the right pipe to push the event into
00073   //
00074 
00075 public: // do not call direct ..
00076   OSStatus handle_key_input(EventHandlerCallRef myHandler, EventRef event, 
00077                             Boolean keyDown);
00078   OSStatus handle_text_input(EventHandlerCallRef myHandler, EventRef event);
00079   OSStatus handle_window_mouse_events(EventHandlerCallRef myHandler, EventRef event);
00080   ButtonHandle osx_translate_key(UInt32 key,  EventRef event);
00081   static osxGraphicsWindow *get_current_osx_window(WindowRef hint);
00082 
00083   void handle_modifier_delta(UInt32 new_modifiers);
00084   void handle_button_delta(UInt32 new_buttons);
00085   void do_resize();
00086 
00087   OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
00088 
00089   virtual void user_close_request();
00090   void system_close_window();
00091   void system_set_window_foreground(bool foreground);
00092   void system_point_to_local_point(Point &global_point);
00093   void local_point_to_system_point(Point &local_point);
00094   AGLContext get_gsg_context();
00095   AGLContext get_context();
00096   OSStatus build_gl(bool full_screen);
00097   bool set_icon_filename(const Filename &icon_filename);
00098 
00099   void set_pointer_in_window(int x, int y);
00100   void set_pointer_out_of_window();
00101 
00102 private:
00103   UInt32 _last_key_modifiers;
00104   UInt32 _last_buttons;
00105   WindowRef _osx_window;
00106   bool _is_fullscreen;
00107 
00108   CGImageRef _pending_icon;
00109   CGImageRef _current_icon;
00110   
00111   int _ID;
00112   static osxGraphicsWindow *full_screen_window; 
00113   
00114 #ifdef HACK_SCREEN_HASH_CONTEXT
00115   AGLContext _holder_aglcontext;
00116 #endif
00117   CFDictionaryRef _originalMode;
00118 
00119   // True if _properties.get_cursor_hidden() is true.
00120   bool _cursor_hidden;
00121 
00122   // True if the cursor is actually hidden right now via system calls.
00123   bool _display_hide_cursor;
00124 
00125   SInt32 _wheel_hdelta;
00126   SInt32 _wheel_vdelta;
00127 
00128 public:
00129   static TypeHandle get_class_type() {
00130     return _type_handle;
00131   }
00132   static void init_type() {
00133     GraphicsWindow::init_type();
00134     register_type(_type_handle, "osxGraphicsWindow",
00135                   GraphicsWindow::get_class_type());
00136   }
00137   virtual TypeHandle get_type() const {
00138     return get_class_type();
00139   }
00140   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00141 
00142 private:
00143   static TypeHandle _type_handle;
00144 };
00145 
00146 #include "osxGraphicsWindow.I"
00147 
00148 #endif
00149 
 All Classes Functions Variables Enumerations