Panda3D
 All Classes Functions Variables Enumerations
tinyOsxGraphicsWindow.h
1 // Filename: tinyOsxGraphicsWindow.h
2 // Created by: drose (12May08)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TINYOSXGRAPHICSWINDOW_H
16 #define TINYOSXGRAPHICSWINDOW_H
17 
18 #include "pandabase.h"
19 
20 #if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON) && !__LP64__
21 
22 #include <Carbon/Carbon.h>
23 
24 #include "graphicsWindow.h"
25 #include "buttonHandle.h"
26 #include "tinyGraphicsStateGuardian.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : TinyOsxGraphicsWindow
30 // Description : Opens a window on OS X to display the TinyPanda
31 // software rendering.
32 ////////////////////////////////////////////////////////////////////
33 class TinyOsxGraphicsWindow : public GraphicsWindow {
34 public:
35  TinyOsxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
36  const string &name,
37  const FrameBufferProperties &fb_prop,
38  const WindowProperties &win_prop,
39  int flags,
41  GraphicsOutput *host);
42  virtual ~TinyOsxGraphicsWindow();
43 
44  virtual bool move_pointer(int device, int x, int y);
45 
46  virtual bool begin_frame(FrameMode mode, Thread *current_thread);
47  virtual void end_frame(FrameMode mode, Thread *current_thread);
48  virtual void begin_flip();
49  virtual void process_events();
50  virtual bool supports_pixel_zoom() const;
51 
52  virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
53  int x_size, int y_size);
54 
55  virtual void mouse_mode_absolute();
56  virtual void mouse_mode_relative();
57 
58  virtual void set_properties_now(WindowProperties &properties);
59 
60 private:
61  void ReleaseSystemResources();
62  inline void SendKeyEvent( ButtonHandle key, bool down);
63 
64 protected:
65  virtual void close_window();
66  virtual bool open_window();
67 
68 private:
69 
70  bool OSOpenWindow(WindowProperties &properties);
71 
72  //
73  // a singleton .. for the events to find the right pipe to push the event into
74  //
75 
76 
77 public: // do not call direct ..
78  OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown);
79  OSStatus handleTextInput (EventHandlerCallRef myHandler, EventRef event);
80  OSStatus handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event);
81  ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event );
82  static TinyOsxGraphicsWindow * GetCurrentOSxWindow (WindowRef hint);
83 
84  void HandleModifireDeleta(UInt32 modifiers);
85  void HandleButtonDelta(UInt32 new_buttons);
86  void DoResize(void);
87 
88  OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
89 
90  virtual void user_close_request();
91  void SystemCloseWindow();
92  void SystemSetWindowForground(bool forground);
93  void SystemPointToLocalPoint(Point &qdGlobalPoint);
94  void LocalPointToSystemPoint(Point &qdLocalPoint);
95  bool set_icon_filename(const Filename &icon_filename);
96 
97  void set_pointer_in_window(int x, int y);
98  void set_pointer_out_of_window();
99 
100 private:
101  void create_frame_buffer();
102 
103 private:
104  ZBuffer *_frame_buffer;
105 
106 private:
107  UInt32 _last_key_modifiers;
108  UInt32 _last_buttons;
109  WindowRef _osx_window;
110  bool _is_fullscreen;
111 
112  CGImageRef _pending_icon;
113  CGImageRef _current_icon;
114 
115  int _ID;
116  static TinyOsxGraphicsWindow *FullScreenWindow;
117 
118  CFDictionaryRef _originalMode;
119 
120  // True if _properties.get_cursor_hidden() is true.
121  bool _cursor_hidden;
122 
123  // True if the cursor is actually hidden right now via system calls.
124  bool _display_hide_cursor;
125 
126  SInt32 _wheel_delta;
127 
128 public:
129  static TypeHandle get_class_type() {
130  return _type_handle;
131  }
132  static void init_type() {
133  GraphicsWindow::init_type();
134  register_type(_type_handle, "TinyOsxGraphicsWindow",
135  GraphicsWindow::get_class_type());
136  }
137  virtual TypeHandle get_type() const {
138  return get_class_type();
139  }
140  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
141 
142 private:
143  static TypeHandle _type_handle;
144 };
145 
146 #include "tinyOsxGraphicsWindow.I"
147 
148 #endif // IS_OSX
149 
150 #endif
151 
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
virtual bool move_pointer(int device, int x, int y)
Forces the pointer to the indicated position within the window, if possible.
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
virtual void end_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread after rendering is completed for a given frame...
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
A container for the various kinds of properties we might ask to have on a graphics window before we o...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
virtual bool supports_pixel_zoom() const
Returns true if a call to set_pixel_zoom() will be respected, false if it will be ignored...
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
This is a base class for the various different classes that represent the result of a frame of render...
A thread; that is, a lightweight process.
Definition: thread.h:51
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
virtual bool begin_frame(FrameMode mode, Thread *current_thread)
This function will be called within the draw thread before beginning rendering for a given frame...