aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-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.h660
1 files changed, 330 insertions, 330 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h
index 8052182..79d7e15 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CIrrDeviceConsole.h
@@ -1,330 +1,330 @@
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#ifndef __C_IRR_DEVICE_CONSOLE_H_INCLUDED__ 5#ifndef __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
6#define __C_IRR_DEVICE_CONSOLE_H_INCLUDED__ 6#define __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
7 7
8#include "IrrCompileConfig.h" 8#include "IrrCompileConfig.h"
9#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_ 9#ifdef _IRR_COMPILE_WITH_CONSOLE_DEVICE_
10 10
11//#define _IRR_USE_CONSOLE_FONT_ 11//#define _IRR_USE_CONSOLE_FONT_
12 12
13#include "SIrrCreationParameters.h" 13#include "SIrrCreationParameters.h"
14#include "CIrrDeviceStub.h" 14#include "CIrrDeviceStub.h"
15#include "IImagePresenter.h" 15#include "IImagePresenter.h"
16// for console font 16// for console font
17#include "IGUIFont.h" 17#include "IGUIFont.h"
18 18
19#ifdef _IRR_WINDOWS_API_ 19#ifdef _IRR_WINDOWS_API_
20#define WIN32_LEAN_AND_MEAN 20#define WIN32_LEAN_AND_MEAN
21#if !defined(_IRR_XBOX_PLATFORM_) 21#if !defined(_IRR_XBOX_PLATFORM_)
22 #include <windows.h> 22 #include <windows.h>
23#endif 23#endif
24#if(_WIN32_WINNT >= 0x0500) 24#if(_WIN32_WINNT >= 0x0500)
25#define _IRR_WINDOWS_NT_CONSOLE_ 25#define _IRR_WINDOWS_NT_CONSOLE_
26#endif 26#endif
27#else 27#else
28#include <time.h> 28#include <time.h>
29#endif 29#endif
30 30
31// for now we assume all other terminal types are VT100 31// for now we assume all other terminal types are VT100
32#ifndef _IRR_WINDOWS_NT_CONSOLE_ 32#ifndef _IRR_WINDOWS_NT_CONSOLE_
33#define _IRR_VT100_CONSOLE_ 33#define _IRR_VT100_CONSOLE_
34#endif 34#endif
35 35
36namespace irr 36namespace irr
37{ 37{
38 38
39 class CIrrDeviceConsole : public CIrrDeviceStub, video::IImagePresenter 39 class CIrrDeviceConsole : public CIrrDeviceStub, video::IImagePresenter
40 { 40 {
41 public: 41 public:
42 42
43 //! constructor 43 //! constructor
44 CIrrDeviceConsole(const SIrrlichtCreationParameters& params); 44 CIrrDeviceConsole(const SIrrlichtCreationParameters& params);
45 45
46 //! destructor 46 //! destructor
47 virtual ~CIrrDeviceConsole(); 47 virtual ~CIrrDeviceConsole();
48 48
49 //! runs the device. Returns false if device wants to be deleted 49 //! runs the device. Returns false if device wants to be deleted
50 virtual bool run(); 50 virtual bool run();
51 51
52 //! Cause the device to temporarily pause execution and let other processes to run 52 //! Cause the device to temporarily pause execution and let other processes to run
53 // This should bring down processor usage without major performance loss for Irrlicht 53 // This should bring down processor usage without major performance loss for Irrlicht
54 virtual void yield(); 54 virtual void yield();
55 55
56 //! Pause execution and let other processes to run for a specified amount of time. 56 //! Pause execution and let other processes to run for a specified amount of time.
57 virtual void sleep(u32 timeMs, bool pauseTimer); 57 virtual void sleep(u32 timeMs, bool pauseTimer);
58 58
59 //! sets the caption of the window 59 //! sets the caption of the window
60 virtual void setWindowCaption(const wchar_t* text); 60 virtual void setWindowCaption(const wchar_t* text);
61 61
62 //! returns if window is active. if not, nothing need to be drawn 62 //! returns if window is active. if not, nothing need to be drawn
63 virtual bool isWindowActive() const; 63 virtual bool isWindowActive() const;
64 64
65 //! returns if window has focus 65 //! returns if window has focus
66 virtual bool isWindowFocused() const; 66 virtual bool isWindowFocused() const;
67 67
68 //! returns if window is minimized 68 //! returns if window is minimized
69 virtual bool isWindowMinimized() const; 69 virtual bool isWindowMinimized() const;
70 70
71 //! presents a surface in the client area 71 //! presents a surface in the client area
72 virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0); 72 virtual bool present(video::IImage* surface, void* windowId=0, core::rect<s32>* src=0);
73 73
74 //! notifies the device that it should close itself 74 //! notifies the device that it should close itself
75 virtual void closeDevice(); 75 virtual void closeDevice();
76 76
77 //! Sets if the window should be resizable in windowed mode. 77 //! Sets if the window should be resizable in windowed mode.
78 virtual void setResizable(bool resize=false); 78 virtual void setResizable(bool resize=false);
79 79
80 //! Minimizes the window. 80 //! Minimizes the window.
81 virtual void minimizeWindow(); 81 virtual void minimizeWindow();
82 82
83 //! Maximizes the window. 83 //! Maximizes the window.
84 virtual void maximizeWindow(); 84 virtual void maximizeWindow();
85 85
86 //! Restores the window size. 86 //! Restores the window size.
87 virtual void restoreWindow(); 87 virtual void restoreWindow();
88 88
89 //! Get the device type 89 //! Get the device type
90 virtual E_DEVICE_TYPE getType() const 90 virtual E_DEVICE_TYPE getType() const
91 { 91 {
92 return EIDT_CONSOLE; 92 return EIDT_CONSOLE;
93 } 93 }
94 94
95 void addPostPresentText(s16 X, s16 Y, const wchar_t *text); 95 void addPostPresentText(s16 X, s16 Y, const wchar_t *text);
96 96
97 //! Implementation of the win32 console mouse cursor 97 //! Implementation of the win32 console mouse cursor
98 class CCursorControl : public gui::ICursorControl 98 class CCursorControl : public gui::ICursorControl
99 { 99 {
100 public: 100 public:
101 101
102 CCursorControl(const core::dimension2d<u32>& wsize) 102 CCursorControl(const core::dimension2d<u32>& wsize)
103 : WindowSize(wsize), InvWindowSize(0.0f, 0.0f), IsVisible(true), UseReferenceRect(false) 103 : WindowSize(wsize), InvWindowSize(0.0f, 0.0f), IsVisible(true), UseReferenceRect(false)
104 { 104 {
105 if (WindowSize.Width!=0) 105 if (WindowSize.Width!=0)
106 InvWindowSize.Width = 1.0f / WindowSize.Width; 106 InvWindowSize.Width = 1.0f / WindowSize.Width;
107 107
108 if (WindowSize.Height!=0) 108 if (WindowSize.Height!=0)
109 InvWindowSize.Height = 1.0f / WindowSize.Height; 109 InvWindowSize.Height = 1.0f / WindowSize.Height;
110 } 110 }
111 111
112 //! Changes the visible state of the mouse cursor. 112 //! Changes the visible state of the mouse cursor.
113 virtual void setVisible(bool visible) 113 virtual void setVisible(bool visible)
114 { 114 {
115 if(visible != IsVisible) 115 if(visible != IsVisible)
116 { 116 {
117 IsVisible = visible; 117 IsVisible = visible;
118 setPosition(CursorPos.X, CursorPos.Y); 118 setPosition(CursorPos.X, CursorPos.Y);
119 } 119 }
120 } 120 }
121 121
122 //! Returns if the cursor is currently visible. 122 //! Returns if the cursor is currently visible.
123 virtual bool isVisible() const 123 virtual bool isVisible() const
124 { 124 {
125 return IsVisible; 125 return IsVisible;
126 } 126 }
127 127
128 //! Sets the new position of the cursor. 128 //! Sets the new position of the cursor.
129 virtual void setPosition(const core::position2d<f32> &pos) 129 virtual void setPosition(const core::position2d<f32> &pos)
130 { 130 {
131 setPosition(pos.X, pos.Y); 131 setPosition(pos.X, pos.Y);
132 } 132 }
133 133
134 //! Sets the new position of the cursor. 134 //! Sets the new position of the cursor.
135 virtual void setPosition(f32 x, f32 y) 135 virtual void setPosition(f32 x, f32 y)
136 { 136 {
137 if (!UseReferenceRect) 137 if (!UseReferenceRect)
138 setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height)); 138 setPosition((s32)(x*WindowSize.Width), (s32)(y*WindowSize.Height));
139 else 139 else
140 setPosition((s32)(x*ReferenceRect.getWidth()), (s32)(y*ReferenceRect.getHeight())); 140 setPosition((s32)(x*ReferenceRect.getWidth()), (s32)(y*ReferenceRect.getHeight()));
141 } 141 }
142 142
143 //! Sets the new position of the cursor. 143 //! Sets the new position of the cursor.
144 virtual void setPosition(const core::position2d<s32> &pos) 144 virtual void setPosition(const core::position2d<s32> &pos)
145 { 145 {
146 setPosition(pos.X, pos.Y); 146 setPosition(pos.X, pos.Y);
147 } 147 }
148 148
149 //! Sets the new position of the cursor. 149 //! Sets the new position of the cursor.
150 virtual void setPosition(s32 x, s32 y) 150 virtual void setPosition(s32 x, s32 y)
151 { 151 {
152 setInternalCursorPosition(core::position2di(x,y)); 152 setInternalCursorPosition(core::position2di(x,y));
153 } 153 }
154 154
155 //! Returns the current position of the mouse cursor. 155 //! Returns the current position of the mouse cursor.
156 virtual const core::position2d<s32>& getPosition() 156 virtual const core::position2d<s32>& getPosition()
157 { 157 {
158 return CursorPos; 158 return CursorPos;
159 } 159 }
160 160
161 //! Returns the current position of the mouse cursor. 161 //! Returns the current position of the mouse cursor.
162 virtual core::position2d<f32> getRelativePosition() 162 virtual core::position2d<f32> getRelativePosition()
163 { 163 {
164 if (!UseReferenceRect) 164 if (!UseReferenceRect)
165 { 165 {
166 return core::position2d<f32>(CursorPos.X * InvWindowSize.Width, 166 return core::position2d<f32>(CursorPos.X * InvWindowSize.Width,
167 CursorPos.Y * InvWindowSize.Height); 167 CursorPos.Y * InvWindowSize.Height);
168 } 168 }
169 169
170 return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(), 170 return core::position2d<f32>(CursorPos.X / (f32)ReferenceRect.getWidth(),
171 CursorPos.Y / (f32)ReferenceRect.getHeight()); 171 CursorPos.Y / (f32)ReferenceRect.getHeight());
172 } 172 }
173 173
174 //! Sets an absolute reference rect for calculating the cursor position. 174 //! Sets an absolute reference rect for calculating the cursor position.
175 virtual void setReferenceRect(core::rect<s32>* rect=0) 175 virtual void setReferenceRect(core::rect<s32>* rect=0)
176 { 176 {
177 if (rect) 177 if (rect)
178 { 178 {
179 ReferenceRect = *rect; 179 ReferenceRect = *rect;
180 UseReferenceRect = true; 180 UseReferenceRect = true;
181 181
182 // prevent division through zero and uneven sizes 182 // prevent division through zero and uneven sizes
183 183
184 if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2) 184 if (!ReferenceRect.getHeight() || ReferenceRect.getHeight()%2)
185 ReferenceRect.LowerRightCorner.Y += 1; 185 ReferenceRect.LowerRightCorner.Y += 1;
186 186
187 if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2) 187 if (!ReferenceRect.getWidth() || ReferenceRect.getWidth()%2)
188 ReferenceRect.LowerRightCorner.X += 1; 188 ReferenceRect.LowerRightCorner.X += 1;
189 } 189 }
190 else 190 else
191 UseReferenceRect = false; 191 UseReferenceRect = false;
192 } 192 }
193 193
194 194
195 //! Updates the internal cursor position 195 //! Updates the internal cursor position
196 void setInternalCursorPosition(const core::position2di &pos) 196 void setInternalCursorPosition(const core::position2di &pos)
197 { 197 {
198 CursorPos = pos; 198 CursorPos = pos;
199 199
200 if (UseReferenceRect) 200 if (UseReferenceRect)
201 CursorPos -= ReferenceRect.UpperLeftCorner; 201 CursorPos -= ReferenceRect.UpperLeftCorner;
202 } 202 }
203 203
204 private: 204 private:
205 205
206 core::position2d<s32> CursorPos; 206 core::position2d<s32> CursorPos;
207 core::dimension2d<u32> WindowSize; 207 core::dimension2d<u32> WindowSize;
208 core::dimension2d<f32> InvWindowSize; 208 core::dimension2d<f32> InvWindowSize;
209 bool IsVisible, 209 bool IsVisible,
210 UseReferenceRect; 210 UseReferenceRect;
211 core::rect<s32> ReferenceRect; 211 core::rect<s32> ReferenceRect;
212 }; 212 };
213 213
214 private: 214 private:
215 215
216 //! Set the position of the text caret 216 //! Set the position of the text caret
217 void setTextCursorPos(s16 x, s16 y); 217 void setTextCursorPos(s16 x, s16 y);
218 218
219 // text to be added after drawing the screen 219 // text to be added after drawing the screen
220 struct SPostPresentText 220 struct SPostPresentText
221 { 221 {
222 core::position2d<s16> Pos; 222 core::position2d<s16> Pos;
223 core::stringc Text; 223 core::stringc Text;
224 }; 224 };
225 225
226 bool IsWindowFocused; 226 bool IsWindowFocused;
227 227
228 core::array<core::stringc> OutputBuffer; 228 core::array<core::stringc> OutputBuffer;
229 gui::IGUIFont *ConsoleFont; 229 gui::IGUIFont *ConsoleFont;
230 core::array<SPostPresentText> Text; 230 core::array<SPostPresentText> Text;
231 231
232 FILE *OutFile; 232 FILE *OutFile;
233 233
234#ifdef _IRR_WINDOWS_NT_CONSOLE_ 234#ifdef _IRR_WINDOWS_NT_CONSOLE_
235 HANDLE WindowsSTDIn, WindowsSTDOut; 235 HANDLE WindowsSTDIn, WindowsSTDOut;
236 u32 MouseButtonStates; 236 u32 MouseButtonStates;
237#endif 237#endif
238 }; 238 };
239 239
240#ifdef _IRR_USE_CONSOLE_FONT_ 240#ifdef _IRR_USE_CONSOLE_FONT_
241 241
242namespace gui 242namespace gui
243{ 243{
244 class CGUIConsoleFont : public IGUIFont 244 class CGUIConsoleFont : public IGUIFont
245 { 245 {
246 public: 246 public:
247 247
248 CGUIConsoleFont(CIrrDeviceConsole* device) : Device(device) { } 248 CGUIConsoleFont(CIrrDeviceConsole* device) : Device(device) { }
249 249
250 //! Draws some text and clips it to the specified rectangle if wanted. 250 //! Draws some text and clips it to the specified rectangle if wanted.
251 virtual void draw(const wchar_t* text, const core::rect<s32>& position, 251 virtual void draw(const wchar_t* text, const core::rect<s32>& position,
252 video::SColor color, bool hcenter=false, bool vcenter=false, 252 video::SColor color, bool hcenter=false, bool vcenter=false,
253 const core::rect<s32>* clip=0) 253 const core::rect<s32>* clip=0)
254 { 254 {
255 core::rect<s32> Area = clip ? *clip : position; 255 core::rect<s32> Area = clip ? *clip : position;
256 256
257 if (Area.UpperLeftCorner.X < 0) 257 if (Area.UpperLeftCorner.X < 0)
258 Area.UpperLeftCorner.X = 0; 258 Area.UpperLeftCorner.X = 0;
259 259
260 if (Area.UpperLeftCorner.Y < 0) 260 if (Area.UpperLeftCorner.Y < 0)
261 Area.UpperLeftCorner.Y = 0; 261 Area.UpperLeftCorner.Y = 0;
262 262
263 core::position2d<s16> pos; 263 core::position2d<s16> pos;
264 264
265 // centre vertically 265 // centre vertically
266 pos.Y = vcenter ? (position.UpperLeftCorner.Y + position.LowerRightCorner.Y) / 2 : position.UpperLeftCorner.Y; 266 pos.Y = vcenter ? (position.UpperLeftCorner.Y + position.LowerRightCorner.Y) / 2 : position.UpperLeftCorner.Y;
267 267
268 // nothing to display? 268 // nothing to display?
269 if (pos.Y < Area.UpperLeftCorner.Y || pos.Y > Area.LowerRightCorner.Y) 269 if (pos.Y < Area.UpperLeftCorner.Y || pos.Y > Area.LowerRightCorner.Y)
270 return; 270 return;
271 271
272 tempText = text; 272 tempText = text;
273 273
274 // centre horizontally 274 // centre horizontally
275 pos.X = hcenter ? position.getCenter().X - ( tempText.size() / 2) : position.UpperLeftCorner.X; 275 pos.X = hcenter ? position.getCenter().X - ( tempText.size() / 2) : position.UpperLeftCorner.X;
276 276
277 // clip 277 // clip
278 u32 xlclip = 0, 278 u32 xlclip = 0,
279 xrclip = 0; 279 xrclip = 0;
280 280
281 // get right clip 281 // get right clip
282 if (pos.X + (s32)tempText.size() > Area.LowerRightCorner.X) 282 if (pos.X + (s32)tempText.size() > Area.LowerRightCorner.X)
283 xrclip = Area.LowerRightCorner.X - pos.X; 283 xrclip = Area.LowerRightCorner.X - pos.X;
284 284
285 // get left clip 285 // get left clip
286 if (pos.X < Area.UpperLeftCorner.X) 286 if (pos.X < Area.UpperLeftCorner.X)
287 xlclip = Area.UpperLeftCorner.X - pos.X; 287 xlclip = Area.UpperLeftCorner.X - pos.X;
288 288
289 // totally clipped? 289 // totally clipped?
290 if ((s32)tempText.size() - xlclip - xrclip < 0) 290 if ((s32)tempText.size() - xlclip - xrclip < 0)
291 return; 291 return;
292 292
293 // null terminate the string 293 // null terminate the string
294 if (xrclip > 0) 294 if (xrclip > 0)
295 tempText[xrclip] = L'\0'; 295 tempText[xrclip] = L'\0';
296 296
297 Device->addPostPresentText(pos.X + xlclip, pos.Y, &(tempText.c_str()[xlclip])); 297 Device->addPostPresentText(pos.X + xlclip, pos.Y, &(tempText.c_str()[xlclip]));
298 } 298 }
299 299
300 //! Calculates the dimension of some text. 300 //! Calculates the dimension of some text.
301 virtual core::dimension2d<u32> getDimension(const wchar_t* text) const 301 virtual core::dimension2d<u32> getDimension(const wchar_t* text) const
302 { 302 {
303 return core::dimension2d<u32>(wcslen(text),1); 303 return core::dimension2d<u32>(wcslen(text),1);
304 } 304 }
305 305
306 //! Calculates the index of the character in the text which is on a specific position. 306 //! Calculates the index of the character in the text which is on a specific position.
307 virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const { return pixel_x; }; 307 virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const { return pixel_x; };
308 308
309 //! No kerning 309 //! No kerning
310 virtual void setKerningWidth (s32 kerning) { } 310 virtual void setKerningWidth (s32 kerning) { }
311 virtual void setKerningHeight (s32 kerning) { } 311 virtual void setKerningHeight (s32 kerning) { }
312 virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const {return 0;} 312 virtual s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const {return 0;}
313 virtual s32 getKerningHeight() const { return 0;} 313 virtual s32 getKerningHeight() const { return 0;}
314 virtual void setInvisibleCharacters( const wchar_t *s ) { } 314 virtual void setInvisibleCharacters( const wchar_t *s ) { }
315 // I guess this is an OS specific font 315 // I guess this is an OS specific font
316 virtual EGUI_FONT_TYPE getType() const { return EGFT_OS; } 316 virtual EGUI_FONT_TYPE getType() const { return EGFT_OS; }
317 private: 317 private:
318 CIrrDeviceConsole* Device; 318 CIrrDeviceConsole* Device;
319 core::stringw tempText; 319 core::stringw tempText;
320 }; 320 };
321 321
322} // end namespace gui 322} // end namespace gui
323 323
324#endif // _IRR_USE_CONSOLE_FONT_ 324#endif // _IRR_USE_CONSOLE_FONT_
325 325
326} // end namespace irr 326} // end namespace irr
327 327
328#endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_ 328#endif // _IRR_COMPILE_WITH_CONSOLE_DEVICE_
329#endif // __C_IRR_DEVICE_CONSOLE_H_INCLUDED__ 329#endif // __C_IRR_DEVICE_CONSOLE_H_INCLUDED__
330 330