Panda3D

Loading...
Searching...
No Matches
cocoaGraphicsWindow.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file cocoaGraphicsWindow.h
10 * @author rdb
11 * @date 2012-05-14
12 */
13
14#ifndef COCOAGRAPHICSWINDOW_H
15#define COCOAGRAPHICSWINDOW_H
16
17#include "pandabase.h"
18
19#include "cocoaGraphicsPipe.h"
20#include "graphicsWindow.h"
21
22#import <AppKit/NSEvent.h>
23#import <AppKit/NSView.h>
24#import <AppKit/NSWindow.h>
25
26#import <CoreVideo/CoreVideo.h>
27
28/**
29 * An interface to the Cocoa system for managing OpenGL windows under Mac OS
30 * X.
31 */
32 class CocoaGraphicsWindow : public GraphicsWindow {
33 public:
34 CocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
35 const std::string &name,
36 const FrameBufferProperties &fb_prop,
37 const WindowProperties &win_prop,
38 int flags,
39 GraphicsStateGuardian *gsg,
40 GraphicsOutput *host);
41 virtual ~CocoaGraphicsWindow();
42
43 virtual bool move_pointer(int device, int x, int y);
44 virtual bool begin_frame(FrameMode mode, Thread *current_thread);
45 virtual void end_frame(FrameMode mode, Thread *current_thread);
46 virtual void end_flip();
47
48 virtual void process_events();
49 virtual void set_properties_now(WindowProperties &properties);
50
51 void handle_move_event();
52 void handle_resize_event();
53 void handle_minimize_event(bool minimized);
54 void handle_foreground_event(bool foreground);
55 bool handle_close_request();
56 void handle_close_event();
57 void handle_key_event(NSEvent *event);
58 void handle_mouse_button_event(int button, bool down);
59 void handle_mouse_moved_event(bool in_window, double x, double y, bool absolute);
60 void handle_wheel_event(double x, double y);
61 virtual ButtonMap *get_keyboard_map() const;
62
63 INLINE NSWindow *get_nswindow() const;
64 INLINE NSView *get_nsview() const;
65
66 protected:
67 virtual void close_window();
68 virtual bool open_window();
69
70#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
71 CFMutableArrayRef find_display_modes(int width, int height);
72 bool do_switch_fullscreen(CGDisplayModeRef mode);
73#else
74 CFDictionaryRef find_display_mode(int width, int height);
75 bool do_switch_fullscreen(CFDictionaryRef mode);
76#endif
77
78 virtual void mouse_mode_absolute();
79 virtual void mouse_mode_relative();
80
81 private:
82 NSData *load_image_data(const Filename &filename);
83 NSImage *load_image(const Filename &filename);
84
85 NSCursor *load_cursor(const Filename &filename);
86
87 void handle_modifier(NSUInteger modifierFlags, NSUInteger mask, ButtonHandle button);
88 ButtonHandle map_key(unsigned short c) const;
89 ButtonHandle map_raw_key(unsigned short keycode) const;
90
91 private:
92 NSWindow *_window;
93 NSView *_view;
94 NSUInteger _modifier_keys;
95 UInt32 _dead_key_state;
96 CGDirectDisplayID _display;
97 PT(GraphicsWindowInputDevice) _input;
98 bool _mouse_hidden;
99 bool _context_needs_update;
100 bool _vsync_enabled = false;
101
102#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
103 CGDisplayModeRef _fullscreen_mode;
104 CGDisplayModeRef _windowed_mode;
105#else
106 CFDictionaryRef _fullscreen_mode;
107 CFDictionaryRef _windowed_mode;
108#endif
109
110 typedef pmap<Filename, NSData*> IconImages;
111 IconImages _images;
112
113 public:
114 // Just so CocoaPandaView can access it.
115 NSCursor *_cursor;
116
117 public:
118 static TypeHandle get_class_type() {
119 return _type_handle;
120 }
121 static void init_type() {
122 GraphicsWindow::init_type();
123 register_type(_type_handle, "CocoaGraphicsWindow",
124 GraphicsWindow::get_class_type());
125 }
126 virtual TypeHandle get_type() const {
127 return get_class_type();
128 }
129 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
130
131 private:
132 static TypeHandle _type_handle;
133};
134
135#include "cocoaGraphicsWindow.I"
136
137#endif
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition buttonHandle.h:26
ButtonMap
This class represents a map containing all of the buttons of a (keyboard) device, though it can also ...
Definition buttonMap.h:30
CocoaGraphicsWindow::end_flip
virtual void end_flip()
This function will be called within the draw thread after begin_flip() has been called on all windows...
CocoaGraphicsWindow::get_nsview
NSView * get_nsview() const
Returns a pointer to the underlying NSView.
Definition cocoaGraphicsWindow.I:26
CocoaGraphicsWindow::move_pointer
virtual bool move_pointer(int device, int x, int y)
Forces the pointer to the indicated position within the window, if possible.
CocoaGraphicsWindow::end_frame
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.
CocoaGraphicsWindow::begin_frame
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.
CocoaGraphicsWindow::set_properties_now
virtual void set_properties_now(WindowProperties &properties)
Applies the requested set of properties to the window, if possible, for instance to request a change ...
CocoaGraphicsWindow::get_nswindow
NSWindow * get_nswindow() const
Returns a pointer to the underlying NSWindow.
Definition cocoaGraphicsWindow.I:18
CocoaGraphicsWindow::get_keyboard_map
virtual ButtonMap * get_keyboard_map() const
Returns a ButtonMap containing the association between raw buttons and virtual buttons.
CocoaGraphicsWindow::process_events
virtual void process_events()
Do whatever processing is necessary to ensure that the window responds to user events.
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
FrameBufferProperties
A container for the various kinds of properties we might ask to have on a graphics frameBuffer before...
Definition frameBufferProperties.h:26
GraphicsStateGuardian
Encapsulates all the communication with a particular instance of a given rendering backend.
Definition graphicsStateGuardian.h:65
GraphicsWindowInputDevice
This is a virtual input device that represents the keyboard and mouse pair that is associated with a ...
Definition graphicsWindowInputDevice.h:28
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
WindowProperties
A container for the various kinds of properties we might ask to have on a graphics window before we o...
Definition windowProperties.h:29
cocoaGraphicsPipe.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
cocoaGraphicsWindow.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
graphicsWindow.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22