Panda3D
osxGraphicsWindow.h
1 ////////////////////////////////////////////////////////////////////
2 //
3 // PANDA 3D SOFTWARE
4 // Copyright (c) Carnegie Mellon University. All rights reserved.
5 //
6 // All use of this software is subject to the terms of the revised BSD
7 // license. You should have received a copy of this license along
8 // with this source code in a file named "LICENSE."
9 //
10 ////////////////////////////////////////////////////////////////////
11 
12 #ifndef OSXGRAPHICSWINDOW_H
13 #define OSXGRAPHICSWINDOW_H
14 
15 #include "pandabase.h"
16 #include "graphicsWindow.h"
17 #include "buttonHandle.h"
18 
19 #include <Carbon/Carbon.h>
20 
21 #define __glext_h_
22 #include <OpenGL/gl.h>
23 #include <AGL/agl.h>
24 
25 #define HACK_SCREEN_HASH_CONTEXT true
26 OSStatus report_agl_error(const string &comment);
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : osxGraphicsWindow
30 // Description : An interface to the osx/ system for managing GL
31 // windows under X.
32 ////////////////////////////////////////////////////////////////////
34 public:
36  const string &name,
37  const FrameBufferProperties &fb_prop,
38  const WindowProperties &win_prop,
39  int flags,
41  GraphicsOutput *host);
42  virtual ~osxGraphicsWindow();
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 end_flip();
50  virtual void process_events();
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 release_system_resources(bool destructing);
62  inline void send_key_event(ButtonHandle key, bool down);
63 
64 protected:
65  virtual void close_window();
66  virtual bool open_window();
67 
68 private:
69  bool os_open_window(WindowProperties &properties);
70 
71  //
72  // a singleton .. for the events to find the right pipe to push the event into
73  //
74 
75 public: // do not call direct ..
76  OSStatus handle_key_input(EventHandlerCallRef myHandler, EventRef event,
77  Boolean keyDown);
78  OSStatus handle_text_input(EventHandlerCallRef myHandler, EventRef event);
79  OSStatus handle_window_mouse_events(EventHandlerCallRef myHandler, EventRef event);
80  ButtonHandle osx_translate_key(UInt32 key, EventRef event);
81  static osxGraphicsWindow *get_current_osx_window(WindowRef hint);
82 
83  void handle_modifier_delta(UInt32 new_modifiers);
84  void handle_button_delta(UInt32 new_buttons);
85  void do_resize();
86 
87  OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
88 
89  virtual void user_close_request();
90  void system_close_window();
91  void system_set_window_foreground(bool foreground);
92  void system_point_to_local_point(Point &global_point);
93  void local_point_to_system_point(Point &local_point);
94  AGLContext get_gsg_context();
95  AGLContext get_context();
96  OSStatus build_gl(bool full_screen);
97  bool set_icon_filename(const Filename &icon_filename);
98 
99  void set_pointer_in_window(int x, int y);
100  void set_pointer_out_of_window();
101 
102 private:
103  UInt32 _last_key_modifiers;
104  UInt32 _last_buttons;
105  WindowRef _osx_window;
106  bool _is_fullscreen;
107 
108  CGImageRef _pending_icon;
109  CGImageRef _current_icon;
110 
111  int _ID;
112  static osxGraphicsWindow *full_screen_window;
113 
114 #ifdef HACK_SCREEN_HASH_CONTEXT
115  AGLContext _holder_aglcontext;
116 #endif
117  CFDictionaryRef _originalMode;
118 
119  // True if _properties.get_cursor_hidden() is true.
120  bool _cursor_hidden;
121 
122  // True if the cursor is actually hidden right now via system calls.
123  bool _display_hide_cursor;
124 
125  SInt32 _wheel_hdelta;
126  SInt32 _wheel_vdelta;
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, "osxGraphicsWindow",
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 "osxGraphicsWindow.I"
147 
148 #endif
149 
virtual bool move_pointer(int device, int x, int y)
Forces the pointer to the indicated position within the window, if possible.
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
virtual void begin_flip()
This function will be called within the draw thread after end_frame() has been called on all windows...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
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...
An interface to the osx/ system for managing GL windows under X.
An object to create GraphicsOutputs that share a particular 3-D API.
Definition: graphicsPipe.h:58
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...
This is a base class for the various different classes that represent the result of a frame of render...
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
A thread; that is, a lightweight process.
Definition: thread.h:51
virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin, int x_size, int y_size)
Called from the window thread in response to a request from within the code (via request_properties()...
Encapsulates all the communication with a particular instance of a given rendering backend...
This class is the main interface to controlling the render process.
virtual void mouse_mode_absolute()
reattaches mouse to location
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 void mouse_mode_relative()
detaches mouse.
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...