diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp | 954 |
1 files changed, 477 insertions, 477 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp index 53892ee..8f913b3 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp +++ b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.cpp | |||
@@ -1,477 +1,477 @@ | |||
1 | // Copyright (C) 2009-2012 Gaz Davidson | 1 | // Copyright (C) 2009-2012 Gaz Davidson |
2 | // This file is part of the "Irrlicht Engine". | 2 | // This file is part of the "Irrlicht Engine". |
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | 3 | // For conditions of distribution and use, see copyright notice in irrlicht.h |
4 | 4 | ||
5 | #include "CIrrDeviceConsole.h" | 5 | #include "CIrrDeviceConsole.h" |
6 | 6 | ||
7 | #ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ | 7 | #ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ |
8 | 8 | ||
9 | #include "os.h" | 9 | #include "os.h" |
10 | #include "IGUISkin.h" | 10 | #include "IGUISkin.h" |
11 | #include "IGUIEnvironment.h" | 11 | #include "IGUIEnvironment.h" |
12 | 12 | ||
13 | // to close the device on terminate signal | 13 | // to close the device on terminate signal |
14 | irr::CIrrDeviceConsole *DeviceToClose; | 14 | irr::CIrrDeviceConsole *DeviceToClose; |
15 | 15 | ||
16 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 16 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
17 | // Callback for Windows | 17 | // Callback for Windows |
18 | BOOL WINAPI ConsoleHandler(DWORD CEvent) | 18 | BOOL WINAPI ConsoleHandler(DWORD CEvent) |
19 | { | 19 | { |
20 | switch(CEvent) | 20 | switch(CEvent) |
21 | { | 21 | { |
22 | case CTRL_C_EVENT: | 22 | case CTRL_C_EVENT: |
23 | irr::os::Printer::log("Closing console device", "CTRL+C"); | 23 | irr::os::Printer::log("Closing console device", "CTRL+C"); |
24 | break; | 24 | break; |
25 | case CTRL_BREAK_EVENT: | 25 | case CTRL_BREAK_EVENT: |
26 | irr::os::Printer::log("Closing console device", "CTRL+Break"); | 26 | irr::os::Printer::log("Closing console device", "CTRL+Break"); |
27 | break; | 27 | break; |
28 | case CTRL_CLOSE_EVENT: | 28 | case CTRL_CLOSE_EVENT: |
29 | irr::os::Printer::log("Closing console device", "User closed console"); | 29 | irr::os::Printer::log("Closing console device", "User closed console"); |
30 | break; | 30 | break; |
31 | case CTRL_LOGOFF_EVENT: | 31 | case CTRL_LOGOFF_EVENT: |
32 | irr::os::Printer::log("Closing console device", "User is logging off"); | 32 | irr::os::Printer::log("Closing console device", "User is logging off"); |
33 | break; | 33 | break; |
34 | case CTRL_SHUTDOWN_EVENT: | 34 | case CTRL_SHUTDOWN_EVENT: |
35 | irr::os::Printer::log("Closing console device", "Computer shutting down"); | 35 | irr::os::Printer::log("Closing console device", "Computer shutting down"); |
36 | break; | 36 | break; |
37 | } | 37 | } |
38 | DeviceToClose->closeDevice(); | 38 | DeviceToClose->closeDevice(); |
39 | return TRUE; | 39 | return TRUE; |
40 | } | 40 | } |
41 | #elif defined(_IRR_POSIX_API_) | 41 | #elif defined(_IRR_POSIX_API_) |
42 | // sigterm handler | 42 | // sigterm handler |
43 | #include <signal.h> | 43 | #include <signal.h> |
44 | 44 | ||
45 | void sighandler(int sig) | 45 | void sighandler(int sig) |
46 | { | 46 | { |
47 | irr::core::stringc code = "Signal "; | 47 | irr::core::stringc code = "Signal "; |
48 | code += sig; | 48 | code += sig; |
49 | code += " received"; | 49 | code += " received"; |
50 | irr::os::Printer::log("Closing console device", code.c_str()); | 50 | irr::os::Printer::log("Closing console device", code.c_str()); |
51 | 51 | ||
52 | DeviceToClose->closeDevice(); | 52 | DeviceToClose->closeDevice(); |
53 | } | 53 | } |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | namespace irr | 56 | namespace irr |
57 | { | 57 | { |
58 | 58 | ||
59 | const c8 ASCIIArtChars[] = " .,'~:;!+>=icopjtJY56SB8XDQKHNWM"; //MWNHKQDX8BS65YJtjpoci=+>!;:~',. "; | 59 | const c8 ASCIIArtChars[] = " .,'~:;!+>=icopjtJY56SB8XDQKHNWM"; //MWNHKQDX8BS65YJtjpoci=+>!;:~',. "; |
60 | const u16 ASCIIArtCharsCount = 32; | 60 | const u16 ASCIIArtCharsCount = 32; |
61 | 61 | ||
62 | //const c8 ASCIIArtChars[] = " \xb0\xb1\xf9\xb2\xdb"; | 62 | //const c8 ASCIIArtChars[] = " \xb0\xb1\xf9\xb2\xdb"; |
63 | //const u16 ASCIIArtCharsCount = 5; | 63 | //const u16 ASCIIArtCharsCount = 5; |
64 | 64 | ||
65 | //! constructor | 65 | //! constructor |
66 | CIrrDeviceConsole::CIrrDeviceConsole(const SIrrlichtCreationParameters& params) | 66 | CIrrDeviceConsole::CIrrDeviceConsole(const SIrrlichtCreationParameters& params) |
67 | : CIrrDeviceStub(params), IsWindowFocused(true), ConsoleFont(0), OutFile(stdout) | 67 | : CIrrDeviceStub(params), IsWindowFocused(true), ConsoleFont(0), OutFile(stdout) |
68 | { | 68 | { |
69 | DeviceToClose = this; | 69 | DeviceToClose = this; |
70 | 70 | ||
71 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 71 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
72 | MouseButtonStates = 0; | 72 | MouseButtonStates = 0; |
73 | 73 | ||
74 | WindowsSTDIn = GetStdHandle(STD_INPUT_HANDLE); | 74 | WindowsSTDIn = GetStdHandle(STD_INPUT_HANDLE); |
75 | WindowsSTDOut = GetStdHandle(STD_OUTPUT_HANDLE); | 75 | WindowsSTDOut = GetStdHandle(STD_OUTPUT_HANDLE); |
76 | PCOORD Dimensions = 0; | 76 | PCOORD Dimensions = 0; |
77 | 77 | ||
78 | if (CreationParams.Fullscreen) | 78 | if (CreationParams.Fullscreen) |
79 | { | 79 | { |
80 | // Some mingw versions lack this define, so avoid it in case it does not exist | 80 | // Some mingw versions lack this define, so avoid it in case it does not exist |
81 | #if (_WIN32_WINNT >= 0x0501) && defined(CONSOLE_FULLSCREEN_MODE) | 81 | #if (_WIN32_WINNT >= 0x0501) && defined(CONSOLE_FULLSCREEN_MODE) |
82 | if (SetConsoleDisplayMode(WindowsSTDOut, CONSOLE_FULLSCREEN_MODE, Dimensions)) | 82 | if (SetConsoleDisplayMode(WindowsSTDOut, CONSOLE_FULLSCREEN_MODE, Dimensions)) |
83 | { | 83 | { |
84 | CreationParams.WindowSize.Width = Dimensions->X; | 84 | CreationParams.WindowSize.Width = Dimensions->X; |
85 | CreationParams.WindowSize.Width = Dimensions->Y; | 85 | CreationParams.WindowSize.Width = Dimensions->Y; |
86 | } | 86 | } |
87 | #endif | 87 | #endif |
88 | } | 88 | } |
89 | else | 89 | else |
90 | { | 90 | { |
91 | COORD ConsoleSize; | 91 | COORD ConsoleSize; |
92 | ConsoleSize.X = CreationParams.WindowSize.Width; | 92 | ConsoleSize.X = CreationParams.WindowSize.Width; |
93 | ConsoleSize.X = CreationParams.WindowSize.Height; | 93 | ConsoleSize.X = CreationParams.WindowSize.Height; |
94 | SetConsoleScreenBufferSize(WindowsSTDOut, ConsoleSize); | 94 | SetConsoleScreenBufferSize(WindowsSTDOut, ConsoleSize); |
95 | } | 95 | } |
96 | 96 | ||
97 | // catch windows close/break signals | 97 | // catch windows close/break signals |
98 | SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE); | 98 | SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE); |
99 | 99 | ||
100 | #elif defined(_IRR_POSIX_API_) | 100 | #elif defined(_IRR_POSIX_API_) |
101 | // catch other signals | 101 | // catch other signals |
102 | signal(SIGABRT, &sighandler); | 102 | signal(SIGABRT, &sighandler); |
103 | signal(SIGTERM, &sighandler); | 103 | signal(SIGTERM, &sighandler); |
104 | signal(SIGINT, &sighandler); | 104 | signal(SIGINT, &sighandler); |
105 | 105 | ||
106 | // set output stream | 106 | // set output stream |
107 | if (params.WindowId) | 107 | if (params.WindowId) |
108 | OutFile = (FILE*)(params.WindowId); | 108 | OutFile = (FILE*)(params.WindowId); |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | #ifdef _IRR_VT100_CONSOLE_ | 111 | #ifdef _IRR_VT100_CONSOLE_ |
112 | // reset terminal | 112 | // reset terminal |
113 | fprintf(OutFile, "%cc", 27); | 113 | fprintf(OutFile, "%cc", 27); |
114 | // disable line wrapping | 114 | // disable line wrapping |
115 | fprintf(OutFile, "%c[7l", 27); | 115 | fprintf(OutFile, "%c[7l", 27); |
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | switch (params.DriverType) | 118 | switch (params.DriverType) |
119 | { | 119 | { |
120 | case video::EDT_SOFTWARE: | 120 | case video::EDT_SOFTWARE: |
121 | #ifdef _IRR_COMPILE_WITH_SOFTWARE_ | 121 | #ifdef _IRR_COMPILE_WITH_SOFTWARE_ |
122 | VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); | 122 | VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); |
123 | #else | 123 | #else |
124 | os::Printer::log("Software driver was not compiled in.", ELL_ERROR); | 124 | os::Printer::log("Software driver was not compiled in.", ELL_ERROR); |
125 | #endif | 125 | #endif |
126 | break; | 126 | break; |
127 | 127 | ||
128 | case video::EDT_BURNINGSVIDEO: | 128 | case video::EDT_BURNINGSVIDEO: |
129 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ | 129 | #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ |
130 | VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this); | 130 | VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this); |
131 | #else | 131 | #else |
132 | os::Printer::log("Burning's Video driver was not compiled in.", ELL_ERROR); | 132 | os::Printer::log("Burning's Video driver was not compiled in.", ELL_ERROR); |
133 | #endif | 133 | #endif |
134 | break; | 134 | break; |
135 | 135 | ||
136 | case video::EDT_DIRECT3D8: | 136 | case video::EDT_DIRECT3D8: |
137 | case video::EDT_DIRECT3D9: | 137 | case video::EDT_DIRECT3D9: |
138 | case video::EDT_OPENGL: | 138 | case video::EDT_OPENGL: |
139 | os::Printer::log("The console device cannot use hardware drivers yet.", ELL_ERROR); | 139 | os::Printer::log("The console device cannot use hardware drivers yet.", ELL_ERROR); |
140 | break; | 140 | break; |
141 | case video::EDT_NULL: | 141 | case video::EDT_NULL: |
142 | VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); | 142 | VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); |
143 | break; | 143 | break; |
144 | default: | 144 | default: |
145 | break; | 145 | break; |
146 | } | 146 | } |
147 | 147 | ||
148 | // set up output buffer | 148 | // set up output buffer |
149 | for (u32 y=0; y<CreationParams.WindowSize.Height; ++y) | 149 | for (u32 y=0; y<CreationParams.WindowSize.Height; ++y) |
150 | { | 150 | { |
151 | core::stringc str; | 151 | core::stringc str; |
152 | str.reserve(CreationParams.WindowSize.Width); | 152 | str.reserve(CreationParams.WindowSize.Width); |
153 | for (u32 x=0; x<CreationParams.WindowSize.Width; ++x) | 153 | for (u32 x=0; x<CreationParams.WindowSize.Width; ++x) |
154 | str += " "; | 154 | str += " "; |
155 | OutputBuffer.push_back(str); | 155 | OutputBuffer.push_back(str); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 159 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
160 | CursorControl = new CCursorControl(CreationParams.WindowSize); | 160 | CursorControl = new CCursorControl(CreationParams.WindowSize); |
161 | #endif | 161 | #endif |
162 | 162 | ||
163 | if (VideoDriver) | 163 | if (VideoDriver) |
164 | { | 164 | { |
165 | createGUIAndScene(); | 165 | createGUIAndScene(); |
166 | #ifdef _IRR_USE_CONSOLE_FONT_ | 166 | #ifdef _IRR_USE_CONSOLE_FONT_ |
167 | if (GUIEnvironment) | 167 | if (GUIEnvironment) |
168 | { | 168 | { |
169 | ConsoleFont = new gui::CGUIConsoleFont(this); | 169 | ConsoleFont = new gui::CGUIConsoleFont(this); |
170 | gui::IGUISkin *skin = GUIEnvironment->getSkin(); | 170 | gui::IGUISkin *skin = GUIEnvironment->getSkin(); |
171 | if (skin) | 171 | if (skin) |
172 | { | 172 | { |
173 | for (u32 i=0; i < gui::EGDF_COUNT; ++i) | 173 | for (u32 i=0; i < gui::EGDF_COUNT; ++i) |
174 | skin->setFont(ConsoleFont, gui::EGUI_DEFAULT_FONT(i)); | 174 | skin->setFont(ConsoleFont, gui::EGUI_DEFAULT_FONT(i)); |
175 | } | 175 | } |
176 | } | 176 | } |
177 | #endif | 177 | #endif |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | //! destructor | 181 | //! destructor |
182 | CIrrDeviceConsole::~CIrrDeviceConsole() | 182 | CIrrDeviceConsole::~CIrrDeviceConsole() |
183 | { | 183 | { |
184 | // GUI and scene are dropped in the stub | 184 | // GUI and scene are dropped in the stub |
185 | if (CursorControl) | 185 | if (CursorControl) |
186 | { | 186 | { |
187 | CursorControl->drop(); | 187 | CursorControl->drop(); |
188 | CursorControl = 0; | 188 | CursorControl = 0; |
189 | } | 189 | } |
190 | if (ConsoleFont) | 190 | if (ConsoleFont) |
191 | { | 191 | { |
192 | ConsoleFont->drop(); | 192 | ConsoleFont->drop(); |
193 | ConsoleFont = 0; | 193 | ConsoleFont = 0; |
194 | } | 194 | } |
195 | #ifdef _IRR_VT100_CONSOLE_ | 195 | #ifdef _IRR_VT100_CONSOLE_ |
196 | // reset terminal | 196 | // reset terminal |
197 | fprintf(OutFile, "%cc", 27); | 197 | fprintf(OutFile, "%cc", 27); |
198 | #endif | 198 | #endif |
199 | } | 199 | } |
200 | 200 | ||
201 | //! runs the device. Returns false if device wants to be deleted | 201 | //! runs the device. Returns false if device wants to be deleted |
202 | bool CIrrDeviceConsole::run() | 202 | bool CIrrDeviceConsole::run() |
203 | { | 203 | { |
204 | // increment timer | 204 | // increment timer |
205 | os::Timer::tick(); | 205 | os::Timer::tick(); |
206 | 206 | ||
207 | // process Windows console input | 207 | // process Windows console input |
208 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 208 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
209 | 209 | ||
210 | INPUT_RECORD in; | 210 | INPUT_RECORD in; |
211 | DWORD oldMode; | 211 | DWORD oldMode; |
212 | DWORD count, waste; | 212 | DWORD count, waste; |
213 | 213 | ||
214 | // get old input mode | 214 | // get old input mode |
215 | GetConsoleMode(WindowsSTDIn, &oldMode); | 215 | GetConsoleMode(WindowsSTDIn, &oldMode); |
216 | SetConsoleMode(WindowsSTDIn, ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT); | 216 | SetConsoleMode(WindowsSTDIn, ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT); |
217 | 217 | ||
218 | GetNumberOfConsoleInputEvents(WindowsSTDIn, &count); | 218 | GetNumberOfConsoleInputEvents(WindowsSTDIn, &count); |
219 | 219 | ||
220 | // read keyboard and mouse input | 220 | // read keyboard and mouse input |
221 | while (count) | 221 | while (count) |
222 | { | 222 | { |
223 | ReadConsoleInput(WindowsSTDIn, &in, 1, &waste ); | 223 | ReadConsoleInput(WindowsSTDIn, &in, 1, &waste ); |
224 | switch(in.EventType) | 224 | switch(in.EventType) |
225 | { | 225 | { |
226 | case KEY_EVENT: | 226 | case KEY_EVENT: |
227 | { | 227 | { |
228 | SEvent e; | 228 | SEvent e; |
229 | e.EventType = EET_KEY_INPUT_EVENT; | 229 | e.EventType = EET_KEY_INPUT_EVENT; |
230 | e.KeyInput.PressedDown = (in.Event.KeyEvent.bKeyDown == TRUE); | 230 | e.KeyInput.PressedDown = (in.Event.KeyEvent.bKeyDown == TRUE); |
231 | e.KeyInput.Control = (in.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0; | 231 | e.KeyInput.Control = (in.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0; |
232 | e.KeyInput.Shift = (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) != 0; | 232 | e.KeyInput.Shift = (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) != 0; |
233 | e.KeyInput.Key = EKEY_CODE(in.Event.KeyEvent.wVirtualKeyCode); | 233 | e.KeyInput.Key = EKEY_CODE(in.Event.KeyEvent.wVirtualKeyCode); |
234 | e.KeyInput.Char = in.Event.KeyEvent.uChar.UnicodeChar; | 234 | e.KeyInput.Char = in.Event.KeyEvent.uChar.UnicodeChar; |
235 | postEventFromUser(e); | 235 | postEventFromUser(e); |
236 | break; | 236 | break; |
237 | } | 237 | } |
238 | case MOUSE_EVENT: | 238 | case MOUSE_EVENT: |
239 | { | 239 | { |
240 | SEvent e; | 240 | SEvent e; |
241 | e.EventType = EET_MOUSE_INPUT_EVENT; | 241 | e.EventType = EET_MOUSE_INPUT_EVENT; |
242 | e.MouseInput.X = in.Event.MouseEvent.dwMousePosition.X; | 242 | e.MouseInput.X = in.Event.MouseEvent.dwMousePosition.X; |
243 | e.MouseInput.Y = in.Event.MouseEvent.dwMousePosition.Y; | 243 | e.MouseInput.Y = in.Event.MouseEvent.dwMousePosition.Y; |
244 | e.MouseInput.Wheel = 0.f; | 244 | e.MouseInput.Wheel = 0.f; |
245 | e.MouseInput.ButtonStates = | 245 | e.MouseInput.ButtonStates = |
246 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) ? EMBSM_LEFT : 0 ) | | 246 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) ? EMBSM_LEFT : 0 ) | |
247 | ( (in.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED) ? EMBSM_RIGHT : 0 ) | | 247 | ( (in.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED) ? EMBSM_RIGHT : 0 ) | |
248 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED) ? EMBSM_MIDDLE : 0 ) | | 248 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_2ND_BUTTON_PRESSED) ? EMBSM_MIDDLE : 0 ) | |
249 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_3RD_BUTTON_PRESSED) ? EMBSM_EXTRA1 : 0 ) | | 249 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_3RD_BUTTON_PRESSED) ? EMBSM_EXTRA1 : 0 ) | |
250 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_4TH_BUTTON_PRESSED) ? EMBSM_EXTRA2 : 0 ); | 250 | ( (in.Event.MouseEvent.dwButtonState & FROM_LEFT_4TH_BUTTON_PRESSED) ? EMBSM_EXTRA2 : 0 ); |
251 | 251 | ||
252 | if (in.Event.MouseEvent.dwEventFlags & MOUSE_MOVED) | 252 | if (in.Event.MouseEvent.dwEventFlags & MOUSE_MOVED) |
253 | { | 253 | { |
254 | CursorControl->setPosition(core::position2di(e.MouseInput.X, e.MouseInput.Y)); | 254 | CursorControl->setPosition(core::position2di(e.MouseInput.X, e.MouseInput.Y)); |
255 | 255 | ||
256 | // create mouse moved event | 256 | // create mouse moved event |
257 | e.MouseInput.Event = EMIE_MOUSE_MOVED; | 257 | e.MouseInput.Event = EMIE_MOUSE_MOVED; |
258 | postEventFromUser(e); | 258 | postEventFromUser(e); |
259 | } | 259 | } |
260 | 260 | ||
261 | if (in.Event.MouseEvent.dwEventFlags & MOUSE_WHEELED) | 261 | if (in.Event.MouseEvent.dwEventFlags & MOUSE_WHEELED) |
262 | { | 262 | { |
263 | e.MouseInput.Event = EMIE_MOUSE_WHEEL; | 263 | e.MouseInput.Event = EMIE_MOUSE_WHEEL; |
264 | e.MouseInput.Wheel = (in.Event.MouseEvent.dwButtonState & 0xFF000000) ? -1.0f : 1.0f; | 264 | e.MouseInput.Wheel = (in.Event.MouseEvent.dwButtonState & 0xFF000000) ? -1.0f : 1.0f; |
265 | postEventFromUser(e); | 265 | postEventFromUser(e); |
266 | } | 266 | } |
267 | 267 | ||
268 | if ( (MouseButtonStates & EMBSM_LEFT) != (e.MouseInput.ButtonStates & EMBSM_LEFT) ) | 268 | if ( (MouseButtonStates & EMBSM_LEFT) != (e.MouseInput.ButtonStates & EMBSM_LEFT) ) |
269 | { | 269 | { |
270 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_LEFT) ? EMIE_LMOUSE_PRESSED_DOWN : EMIE_LMOUSE_LEFT_UP; | 270 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_LEFT) ? EMIE_LMOUSE_PRESSED_DOWN : EMIE_LMOUSE_LEFT_UP; |
271 | postEventFromUser(e); | 271 | postEventFromUser(e); |
272 | } | 272 | } |
273 | 273 | ||
274 | if ( (MouseButtonStates & EMBSM_RIGHT) != (e.MouseInput.ButtonStates & EMBSM_RIGHT) ) | 274 | if ( (MouseButtonStates & EMBSM_RIGHT) != (e.MouseInput.ButtonStates & EMBSM_RIGHT) ) |
275 | { | 275 | { |
276 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_RIGHT) ? EMIE_RMOUSE_PRESSED_DOWN : EMIE_RMOUSE_LEFT_UP; | 276 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_RIGHT) ? EMIE_RMOUSE_PRESSED_DOWN : EMIE_RMOUSE_LEFT_UP; |
277 | postEventFromUser(e); | 277 | postEventFromUser(e); |
278 | } | 278 | } |
279 | 279 | ||
280 | if ( (MouseButtonStates & EMBSM_MIDDLE) != (e.MouseInput.ButtonStates & EMBSM_MIDDLE) ) | 280 | if ( (MouseButtonStates & EMBSM_MIDDLE) != (e.MouseInput.ButtonStates & EMBSM_MIDDLE) ) |
281 | { | 281 | { |
282 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_MIDDLE) ? EMIE_MMOUSE_PRESSED_DOWN : EMIE_MMOUSE_LEFT_UP; | 282 | e.MouseInput.Event = (e.MouseInput.ButtonStates & EMBSM_MIDDLE) ? EMIE_MMOUSE_PRESSED_DOWN : EMIE_MMOUSE_LEFT_UP; |
283 | postEventFromUser(e); | 283 | postEventFromUser(e); |
284 | } | 284 | } |
285 | 285 | ||
286 | // save current button states | 286 | // save current button states |
287 | MouseButtonStates = e.MouseInput.ButtonStates; | 287 | MouseButtonStates = e.MouseInput.ButtonStates; |
288 | 288 | ||
289 | break; | 289 | break; |
290 | } | 290 | } |
291 | case WINDOW_BUFFER_SIZE_EVENT: | 291 | case WINDOW_BUFFER_SIZE_EVENT: |
292 | VideoDriver->OnResize( | 292 | VideoDriver->OnResize( |
293 | core::dimension2d<u32>(in.Event.WindowBufferSizeEvent.dwSize.X, | 293 | core::dimension2d<u32>(in.Event.WindowBufferSizeEvent.dwSize.X, |
294 | in.Event.WindowBufferSizeEvent.dwSize.Y)); | 294 | in.Event.WindowBufferSizeEvent.dwSize.Y)); |
295 | break; | 295 | break; |
296 | case FOCUS_EVENT: | 296 | case FOCUS_EVENT: |
297 | IsWindowFocused = (in.Event.FocusEvent.bSetFocus == TRUE); | 297 | IsWindowFocused = (in.Event.FocusEvent.bSetFocus == TRUE); |
298 | break; | 298 | break; |
299 | default: | 299 | default: |
300 | break; | 300 | break; |
301 | } | 301 | } |
302 | GetNumberOfConsoleInputEvents(WindowsSTDIn, &count); | 302 | GetNumberOfConsoleInputEvents(WindowsSTDIn, &count); |
303 | } | 303 | } |
304 | 304 | ||
305 | // set input mode | 305 | // set input mode |
306 | SetConsoleMode(WindowsSTDIn, oldMode); | 306 | SetConsoleMode(WindowsSTDIn, oldMode); |
307 | #else | 307 | #else |
308 | // todo: keyboard input from terminal in raw mode | 308 | // todo: keyboard input from terminal in raw mode |
309 | #endif | 309 | #endif |
310 | 310 | ||
311 | return !Close; | 311 | return !Close; |
312 | } | 312 | } |
313 | 313 | ||
314 | //! Cause the device to temporarily pause execution and let other processes to run | 314 | //! Cause the device to temporarily pause execution and let other processes to run |
315 | // This should bring down processor usage without major performance loss for Irrlicht | 315 | // This should bring down processor usage without major performance loss for Irrlicht |
316 | void CIrrDeviceConsole::yield() | 316 | void CIrrDeviceConsole::yield() |
317 | { | 317 | { |
318 | #ifdef _IRR_WINDOWS_API_ | 318 | #ifdef _IRR_WINDOWS_API_ |
319 | Sleep(1); | 319 | Sleep(1); |
320 | #else | 320 | #else |
321 | struct timespec ts = {0,0}; | 321 | struct timespec ts = {0,0}; |
322 | nanosleep(&ts, NULL); | 322 | nanosleep(&ts, NULL); |
323 | #endif | 323 | #endif |
324 | } | 324 | } |
325 | 325 | ||
326 | //! Pause execution and let other processes to run for a specified amount of time. | 326 | //! Pause execution and let other processes to run for a specified amount of time. |
327 | void CIrrDeviceConsole::sleep(u32 timeMs, bool pauseTimer) | 327 | void CIrrDeviceConsole::sleep(u32 timeMs, bool pauseTimer) |
328 | { | 328 | { |
329 | const bool wasStopped = Timer ? Timer->isStopped() : true; | 329 | const bool wasStopped = Timer ? Timer->isStopped() : true; |
330 | 330 | ||
331 | #ifdef _IRR_WINDOWS_API_ | 331 | #ifdef _IRR_WINDOWS_API_ |
332 | Sleep(timeMs); | 332 | Sleep(timeMs); |
333 | #else | 333 | #else |
334 | struct timespec ts; | 334 | struct timespec ts; |
335 | ts.tv_sec = (time_t) (timeMs / 1000); | 335 | ts.tv_sec = (time_t) (timeMs / 1000); |
336 | ts.tv_nsec = (long) (timeMs % 1000) * 1000000; | 336 | ts.tv_nsec = (long) (timeMs % 1000) * 1000000; |
337 | 337 | ||
338 | if (pauseTimer && !wasStopped) | 338 | if (pauseTimer && !wasStopped) |
339 | Timer->stop(); | 339 | Timer->stop(); |
340 | 340 | ||
341 | nanosleep(&ts, NULL); | 341 | nanosleep(&ts, NULL); |
342 | #endif | 342 | #endif |
343 | 343 | ||
344 | if (pauseTimer && !wasStopped) | 344 | if (pauseTimer && !wasStopped) |
345 | Timer->start(); | 345 | Timer->start(); |
346 | } | 346 | } |
347 | 347 | ||
348 | //! sets the caption of the window | 348 | //! sets the caption of the window |
349 | void CIrrDeviceConsole::setWindowCaption(const wchar_t* text) | 349 | void CIrrDeviceConsole::setWindowCaption(const wchar_t* text) |
350 | { | 350 | { |
351 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 351 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
352 | SetConsoleTitleW(text); | 352 | SetConsoleTitleW(text); |
353 | #endif | 353 | #endif |
354 | } | 354 | } |
355 | 355 | ||
356 | //! returns if window is active. if not, nothing need to be drawn | 356 | //! returns if window is active. if not, nothing need to be drawn |
357 | bool CIrrDeviceConsole::isWindowActive() const | 357 | bool CIrrDeviceConsole::isWindowActive() const |
358 | { | 358 | { |
359 | // there is no window, but we always assume it is active | 359 | // there is no window, but we always assume it is active |
360 | return true; | 360 | return true; |
361 | } | 361 | } |
362 | 362 | ||
363 | //! returns if window has focus | 363 | //! returns if window has focus |
364 | bool CIrrDeviceConsole::isWindowFocused() const | 364 | bool CIrrDeviceConsole::isWindowFocused() const |
365 | { | 365 | { |
366 | return IsWindowFocused; | 366 | return IsWindowFocused; |
367 | } | 367 | } |
368 | 368 | ||
369 | //! returns if window is minimized | 369 | //! returns if window is minimized |
370 | bool CIrrDeviceConsole::isWindowMinimized() const | 370 | bool CIrrDeviceConsole::isWindowMinimized() const |
371 | { | 371 | { |
372 | return false; | 372 | return false; |
373 | } | 373 | } |
374 | 374 | ||
375 | //! presents a surface in the client area | 375 | //! presents a surface in the client area |
376 | bool CIrrDeviceConsole::present(video::IImage* surface, void* windowId, core::rect<s32>* src) | 376 | bool CIrrDeviceConsole::present(video::IImage* surface, void* windowId, core::rect<s32>* src) |
377 | { | 377 | { |
378 | 378 | ||
379 | if (surface) | 379 | if (surface) |
380 | { | 380 | { |
381 | for (u32 y=0; y < surface->getDimension().Height; ++y) | 381 | for (u32 y=0; y < surface->getDimension().Height; ++y) |
382 | { | 382 | { |
383 | for (u32 x=0; x< surface->getDimension().Width; ++x) | 383 | for (u32 x=0; x< surface->getDimension().Width; ++x) |
384 | { | 384 | { |
385 | // get average pixel | 385 | // get average pixel |
386 | u32 avg = surface->getPixel(x,y).getAverage() * (ASCIIArtCharsCount-1); | 386 | u32 avg = surface->getPixel(x,y).getAverage() * (ASCIIArtCharsCount-1); |
387 | avg /= 255; | 387 | avg /= 255; |
388 | OutputBuffer[y] [x] = ASCIIArtChars[avg]; | 388 | OutputBuffer[y] [x] = ASCIIArtChars[avg]; |
389 | } | 389 | } |
390 | } | 390 | } |
391 | } | 391 | } |
392 | #ifdef _IRR_USE_CONSOLE_FONT_ | 392 | #ifdef _IRR_USE_CONSOLE_FONT_ |
393 | for (u32 i=0; i< Text.size(); ++i) | 393 | for (u32 i=0; i< Text.size(); ++i) |
394 | { | 394 | { |
395 | s32 y = Text[i].Pos.Y; | 395 | s32 y = Text[i].Pos.Y; |
396 | 396 | ||
397 | if ( y < (s32)OutputBuffer.size() && y > 0) | 397 | if ( y < (s32)OutputBuffer.size() && y > 0) |
398 | for (u32 c=0; c < Text[i].Text.size() && c + Text[i].Pos.X < OutputBuffer[y].size(); ++c) | 398 | for (u32 c=0; c < Text[i].Text.size() && c + Text[i].Pos.X < OutputBuffer[y].size(); ++c) |
399 | //if (Text[i].Text[c] != ' ') | 399 | //if (Text[i].Text[c] != ' ') |
400 | OutputBuffer[y] [c+Text[i].Pos.X] = Text[i].Text[c]; | 400 | OutputBuffer[y] [c+Text[i].Pos.X] = Text[i].Text[c]; |
401 | } | 401 | } |
402 | Text.clear(); | 402 | Text.clear(); |
403 | #endif | 403 | #endif |
404 | 404 | ||
405 | // draw output | 405 | // draw output |
406 | for (u32 y=0; y<OutputBuffer.size(); ++y) | 406 | for (u32 y=0; y<OutputBuffer.size(); ++y) |
407 | { | 407 | { |
408 | setTextCursorPos(0,y); | 408 | setTextCursorPos(0,y); |
409 | fprintf(OutFile, "%s", OutputBuffer[y].c_str()); | 409 | fprintf(OutFile, "%s", OutputBuffer[y].c_str()); |
410 | } | 410 | } |
411 | return surface != 0; | 411 | return surface != 0; |
412 | } | 412 | } |
413 | 413 | ||
414 | //! notifies the device that it should close itself | 414 | //! notifies the device that it should close itself |
415 | void CIrrDeviceConsole::closeDevice() | 415 | void CIrrDeviceConsole::closeDevice() |
416 | { | 416 | { |
417 | // return false next time we run() | 417 | // return false next time we run() |
418 | Close = true; | 418 | Close = true; |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | //! Sets if the window should be resizable in windowed mode. | 422 | //! Sets if the window should be resizable in windowed mode. |
423 | void CIrrDeviceConsole::setResizable(bool resize) | 423 | void CIrrDeviceConsole::setResizable(bool resize) |
424 | { | 424 | { |
425 | // do nothing | 425 | // do nothing |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | //! Minimize the window. | 429 | //! Minimize the window. |
430 | void CIrrDeviceConsole::minimizeWindow() | 430 | void CIrrDeviceConsole::minimizeWindow() |
431 | { | 431 | { |
432 | // do nothing | 432 | // do nothing |
433 | } | 433 | } |
434 | 434 | ||
435 | 435 | ||
436 | //! Maximize window | 436 | //! Maximize window |
437 | void CIrrDeviceConsole::maximizeWindow() | 437 | void CIrrDeviceConsole::maximizeWindow() |
438 | { | 438 | { |
439 | // do nothing | 439 | // do nothing |
440 | } | 440 | } |
441 | 441 | ||
442 | 442 | ||
443 | //! Restore original window size | 443 | //! Restore original window size |
444 | void CIrrDeviceConsole::restoreWindow() | 444 | void CIrrDeviceConsole::restoreWindow() |
445 | { | 445 | { |
446 | // do nothing | 446 | // do nothing |
447 | } | 447 | } |
448 | 448 | ||
449 | 449 | ||
450 | void CIrrDeviceConsole::setTextCursorPos(s16 x, s16 y) | 450 | void CIrrDeviceConsole::setTextCursorPos(s16 x, s16 y) |
451 | { | 451 | { |
452 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ | 452 | #ifdef _IRR_WINDOWS_NT_CONSOLE_ |
453 | // move WinNT cursor | 453 | // move WinNT cursor |
454 | COORD Position; | 454 | COORD Position; |
455 | Position.X = x; | 455 | Position.X = x; |
456 | Position.Y = y; | 456 | Position.Y = y; |
457 | SetConsoleCursorPosition(WindowsSTDOut, Position); | 457 | SetConsoleCursorPosition(WindowsSTDOut, Position); |
458 | #elif defined(_IRR_VT100_CONSOLE_) | 458 | #elif defined(_IRR_VT100_CONSOLE_) |
459 | // send escape code | 459 | // send escape code |
460 | fprintf(OutFile, "%c[%d;%dH", 27, y, x); | 460 | fprintf(OutFile, "%c[%d;%dH", 27, y, x); |
461 | #else | 461 | #else |
462 | // not implemented | 462 | // not implemented |
463 | #endif | 463 | #endif |
464 | } | 464 | } |
465 | 465 | ||
466 | void CIrrDeviceConsole::addPostPresentText(s16 X, s16 Y, const wchar_t *text) | 466 | void CIrrDeviceConsole::addPostPresentText(s16 X, s16 Y, const wchar_t *text) |
467 | { | 467 | { |
468 | SPostPresentText p; | 468 | SPostPresentText p; |
469 | p.Text = text; | 469 | p.Text = text; |
470 | p.Pos.X = X; | 470 | p.Pos.X = X; |
471 | p.Pos.Y = Y; | 471 | p.Pos.Y = Y; |
472 | Text.push_back(p); | 472 | Text.push_back(p); |
473 | } | 473 | } |
474 | 474 | ||
475 | } // end namespace irr | 475 | } // end namespace irr |
476 | 476 | ||
477 | #endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_ | 477 | #endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_ |