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