diff options
author | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:24:39 +1000 |
commit | 393b5cd1dc438872af89d334ef6e5fcc59f27d47 (patch) | |
tree | 6a14521219942a08a1b95cb2f5a923a9edd60f63 /libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h | |
parent | Add a note about rasters suggested start up code. (diff) | |
download | SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.zip SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.gz SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.bz2 SledjHamr-393b5cd1dc438872af89d334ef6e5fcc59f27d47.tar.xz |
Added Irrlicht 1.8, but without all the Windows binaries.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h b/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h new file mode 100644 index 0000000..174c68f --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.h | |||
@@ -0,0 +1,251 @@ | |||
1 | // Copyright (C) 2005-2006 Etienne Petitjean | ||
2 | // Copyright (C) 2007-2012 Christian Stehno | ||
3 | // This file is part of the "Irrlicht Engine". | ||
4 | // For conditions of distribution and use, see copyright notice in Irrlicht.h | ||
5 | |||
6 | #ifndef __C_IRR_DEVICE_MACOSX_H_INCLUDED__ | ||
7 | #define __C_IRR_DEVICE_MACOSX_H_INCLUDED__ | ||
8 | |||
9 | #include "IrrCompileConfig.h" | ||
10 | |||
11 | #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ | ||
12 | |||
13 | #include "CIrrDeviceStub.h" | ||
14 | #include "IrrlichtDevice.h" | ||
15 | #include "IImagePresenter.h" | ||
16 | #include "IGUIEnvironment.h" | ||
17 | #include "ICursorControl.h" | ||
18 | |||
19 | #include <OpenGL/OpenGL.h> | ||
20 | #include <map> | ||
21 | |||
22 | class NSWindow; | ||
23 | class NSOpenGLContext; | ||
24 | class NSBitmapImageRep; | ||
25 | |||
26 | namespace irr | ||
27 | { | ||
28 | class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter | ||
29 | { | ||
30 | public: | ||
31 | |||
32 | //! constructor | ||
33 | CIrrDeviceMacOSX(const SIrrlichtCreationParameters& params); | ||
34 | |||
35 | //! destructor | ||
36 | virtual ~CIrrDeviceMacOSX(); | ||
37 | |||
38 | //! runs the device. Returns false if device wants to be deleted | ||
39 | virtual bool run(); | ||
40 | |||
41 | //! Cause the device to temporarily pause execution and let other processes to run | ||
42 | // This should bring down processor usage without major performance loss for Irrlicht | ||
43 | virtual void yield(); | ||
44 | |||
45 | //! Pause execution and let other processes to run for a specified amount of time. | ||
46 | virtual void sleep(u32 timeMs, bool pauseTimer); | ||
47 | |||
48 | //! sets the caption of the window | ||
49 | virtual void setWindowCaption(const wchar_t* text); | ||
50 | |||
51 | //! returns if window is active. if not, nothing need to be drawn | ||
52 | virtual bool isWindowActive() const; | ||
53 | |||
54 | //! Checks if the Irrlicht window has focus | ||
55 | virtual bool isWindowFocused() const; | ||
56 | |||
57 | //! Checks if the Irrlicht window is minimized | ||
58 | virtual bool isWindowMinimized() const; | ||
59 | |||
60 | //! presents a surface in the client area | ||
61 | virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0 ); | ||
62 | |||
63 | //! notifies the device that it should close itself | ||
64 | virtual void closeDevice(); | ||
65 | |||
66 | //! Sets if the window should be resizable in windowed mode. | ||
67 | virtual void setResizable(bool resize); | ||
68 | |||
69 | //! Returns true if the window is resizable, false if not | ||
70 | virtual bool isResizable() const; | ||
71 | |||
72 | //! Minimizes the window if possible | ||
73 | virtual void minimizeWindow(); | ||
74 | |||
75 | //! Maximizes the window if possible. | ||
76 | virtual void maximizeWindow(); | ||
77 | |||
78 | //! Restore the window to normal size if possible. | ||
79 | virtual void restoreWindow(); | ||
80 | |||
81 | //! Activate any joysticks, and generate events for them. | ||
82 | virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); | ||
83 | |||
84 | //! \return Returns a pointer to a list with all video modes | ||
85 | //! supported by the gfx adapter. | ||
86 | virtual video::IVideoModeList* getVideoModeList(); | ||
87 | |||
88 | //! Get the device type | ||
89 | virtual E_DEVICE_TYPE getType() const | ||
90 | { | ||
91 | return EIDT_OSX; | ||
92 | } | ||
93 | |||
94 | void flush(); | ||
95 | void setMouseLocation(int x, int y); | ||
96 | void setResize(int width, int height); | ||
97 | void setCursorVisible(bool visible); | ||
98 | |||
99 | private: | ||
100 | |||
101 | //! create the driver | ||
102 | void createDriver(); | ||
103 | |||
104 | //! Implementation of the macos x cursor control | ||
105 | class CCursorControl : public gui::ICursorControl | ||
106 | { | ||
107 | public: | ||
108 | |||
109 | CCursorControl(const core::dimension2d<u32>& wsize, CIrrDeviceMacOSX *device) | ||
110 | : WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), Device(device), UseReferenceRect(false) | ||
111 | { | ||
112 | CursorPos.X = CursorPos.Y = 0; | ||
113 | if (WindowSize.Width!=0) | ||
114 | InvWindowSize.Width = 1.0f / WindowSize.Width; | ||
115 | if (WindowSize.Height!=0) | ||
116 | InvWindowSize.Height = 1.0f / WindowSize.Height; | ||
117 | } | ||
118 | |||
119 | //! Changes the visible state of the mouse cursor. | ||
120 | virtual void setVisible(bool visible) | ||
121 | { | ||
122 | IsVisible = visible; | ||
123 | Device->setCursorVisible(visible); | ||
124 | } | ||
125 | |||
126 | //! Returns if the cursor is currently visible. | ||
127 | virtual bool isVisible() const | ||
128 | { | ||
129 | return IsVisible; | ||
130 | } | ||
131 | |||
132 | //! Sets the new position of the cursor. | ||
133 | virtual void setPosition(const core::position2d<f32> &pos) | ||
134 | { | ||
135 | setPosition(pos.X, pos.Y); | ||
136 | } | ||
137 | |||
138 | //! Sets the new position of the cursor. | ||
139 | virtual void setPosition(f32 x, f32 y) | ||
140 | { | ||
141 | setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height)); | ||
142 | } | ||
143 | |||
144 | //! Sets the new position of the cursor. | ||
145 | virtual void setPosition(const core::position2d<s32> &pos) | ||
146 | { | ||
147 | if (CursorPos.X != pos.X || CursorPos.Y != pos.Y) | ||
148 | setPosition(pos.X, pos.Y); | ||
149 | } | ||
150 | |||
151 | //! Sets the new position of the cursor. | ||
152 | virtual void setPosition(s32 x, s32 y) | ||
153 | { | ||
154 | if (UseReferenceRect) | ||
155 | { | ||
156 | Device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | Device->setMouseLocation(x,y); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | //! Returns the current position of the mouse cursor. | ||
165 | virtual const core::position2d<s32>& getPosition() | ||
166 | { | ||
167 | return CursorPos; | ||
168 | } | ||
169 | |||
170 | //! Returns the current position of the mouse cursor. | ||
171 | virtual core::position2d<f32> getRelativePosition() | ||
172 | { | ||
173 | if (!UseReferenceRect) | ||
174 | { | ||
175 | return core::position2d<f32>(CursorPos.X * InvWindowSize.Width, | ||
176 | CursorPos.Y * InvWindowSize.Height); | ||
177 | } | ||
178 | |||
179 | return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(), | ||
180 | CursorPos.Y / (f32)ReferenceRect.getHeight()); | ||
181 | } | ||
182 | |||
183 | //! Sets an absolute reference rect for calculating the cursor position. | ||
184 | virtual void setReferenceRect(core::rect<s32>* rect=0) | ||
185 | { | ||
186 | if (rect) | ||
187 | { | ||
188 | ReferenceRect = *rect; | ||
189 | UseReferenceRect = true; | ||
190 | |||
191 | // prevent division through zero and uneven sizes | ||
192 | |||
193 | if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2) | ||
194 | ReferenceRect.LowerRightCorner.Y += 1; | ||
195 | |||
196 | if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2) | ||
197 | ReferenceRect.LowerRightCorner.X += 1; | ||
198 | } | ||
199 | else | ||
200 | UseReferenceRect = false; | ||
201 | } | ||
202 | |||
203 | //! Updates the internal cursor position | ||
204 | void updateInternalCursorPosition(int x,int y) | ||
205 | { | ||
206 | CursorPos.X = x; | ||
207 | CursorPos.Y = y; | ||
208 | } | ||
209 | |||
210 | private: | ||
211 | |||
212 | core::position2d<s32> CursorPos; | ||
213 | core::dimension2d<s32> WindowSize; | ||
214 | core::dimension2d<float> InvWindowSize; | ||
215 | core::rect<s32> ReferenceRect; | ||
216 | CIrrDeviceMacOSX *Device; | ||
217 | bool IsVisible; | ||
218 | bool UseReferenceRect; | ||
219 | }; | ||
220 | |||
221 | bool createWindow(); | ||
222 | void initKeycodes(); | ||
223 | void storeMouseLocation(); | ||
224 | void postMouseEvent(void *event, irr::SEvent &ievent); | ||
225 | void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed); | ||
226 | void pollJoysticks(); | ||
227 | |||
228 | NSWindow *Window; | ||
229 | CGLContextObj CGLContext; | ||
230 | NSOpenGLContext *OGLContext; | ||
231 | NSBitmapImageRep *SoftwareDriverTarget; | ||
232 | std::map<int,int> KeyCodes; | ||
233 | int DeviceWidth; | ||
234 | int DeviceHeight; | ||
235 | int ScreenWidth; | ||
236 | int ScreenHeight; | ||
237 | u32 MouseButtonStates; | ||
238 | u32 SoftwareRendererType; | ||
239 | bool IsFullscreen; | ||
240 | bool IsActive; | ||
241 | bool IsShiftDown; | ||
242 | bool IsControlDown; | ||
243 | bool IsResizable; | ||
244 | }; | ||
245 | |||
246 | |||
247 | } // end namespace irr | ||
248 | |||
249 | #endif // _IRR_COMPILE_WITH_OSX_DEVICE_ | ||
250 | #endif // __C_IRR_DEVICE_MACOSX_H_INCLUDED__ | ||
251 | |||