Panda3D
|
00001 // Filename: tinyOsxGraphicsWindow.h 00002 // Created by: drose (12May08) 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 TINYOSXGRAPHICSWINDOW_H 00016 #define TINYOSXGRAPHICSWINDOW_H 00017 00018 #include "pandabase.h" 00019 00020 #if defined(IS_OSX) && !defined(BUILD_IPHONE) 00021 00022 #include <Carbon/Carbon.h> 00023 00024 #include "graphicsWindow.h" 00025 #include "buttonHandle.h" 00026 #include "tinyGraphicsStateGuardian.h" 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Class : TinyOsxGraphicsWindow 00030 // Description : Opens a window on OS X to display the TinyPanda 00031 // software rendering. 00032 //////////////////////////////////////////////////////////////////// 00033 class TinyOsxGraphicsWindow : public GraphicsWindow { 00034 public: 00035 TinyOsxGraphicsWindow(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 ~TinyOsxGraphicsWindow(); 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 process_events(); 00050 virtual bool supports_pixel_zoom() const; 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 ReleaseSystemResources(); 00062 inline void SendKeyEvent( ButtonHandle key, bool down); 00063 00064 protected: 00065 virtual void close_window(); 00066 virtual bool open_window(); 00067 00068 private: 00069 00070 bool OSOpenWindow(WindowProperties &properties); 00071 00072 // 00073 // a singleton .. for the events to find the right pipe to push the event into 00074 // 00075 00076 00077 public: // do not call direct .. 00078 OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown); 00079 OSStatus handleTextInput (EventHandlerCallRef myHandler, EventRef event); 00080 OSStatus handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event); 00081 ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event ); 00082 static TinyOsxGraphicsWindow * GetCurrentOSxWindow (WindowRef hint); 00083 00084 void HandleModifireDeleta(UInt32 modifiers); 00085 void HandleButtonDelta(UInt32 new_buttons); 00086 void DoResize(void); 00087 00088 OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event); 00089 00090 virtual void user_close_request(); 00091 void SystemCloseWindow(); 00092 void SystemSetWindowForground(bool forground); 00093 void SystemPointToLocalPoint(Point &qdGlobalPoint); 00094 void LocalPointToSystemPoint(Point &qdLocalPoint); 00095 bool set_icon_filename(const Filename &icon_filename); 00096 00097 void set_pointer_in_window(int x, int y); 00098 void set_pointer_out_of_window(); 00099 00100 private: 00101 void create_frame_buffer(); 00102 00103 private: 00104 ZBuffer *_frame_buffer; 00105 00106 private: 00107 UInt32 _last_key_modifiers; 00108 UInt32 _last_buttons; 00109 WindowRef _osx_window; 00110 bool _is_fullscreen; 00111 00112 CGImageRef _pending_icon; 00113 CGImageRef _current_icon; 00114 00115 int _ID; 00116 static TinyOsxGraphicsWindow *FullScreenWindow; 00117 00118 CFDictionaryRef _originalMode; 00119 00120 // True if _properties.get_cursor_hidden() is true. 00121 bool _cursor_hidden; 00122 00123 // True if the cursor is actually hidden right now via system calls. 00124 bool _display_hide_cursor; 00125 00126 SInt32 _wheel_delta; 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, "TinyOsxGraphicsWindow", 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 "tinyOsxGraphicsWindow.I" 00147 00148 #endif // IS_OSX 00149 00150 #endif 00151