1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "GUI/Console.h"
26 #include "Interface.h"
28 #include "ScriptEngine.h"
31 Console::Console(void)
36 Buffer
= ( unsigned char * ) malloc( max
);
38 for(size_t i
=0;i
<HISTORY_SIZE
;i
++) {
39 History
[i
] = ( unsigned char * ) malloc( max
);
48 Console::~Console(void)
51 for (size_t i
=0;i
<HISTORY_SIZE
;i
++) {
54 Video
*video
= core
->GetVideoDriver();
56 gamedata
->FreePalette( palette
);
57 video
->FreeSprite( Cursor
);
60 /** Draws the Console on the Output Display */
61 void Console::Draw(unsigned short x
, unsigned short y
)
64 core
->GetVideoDriver()->BlitSprite( Back
, 0, y
, true );
67 0x00, 0x00, 0x00, 0xff
69 Region
r( x
+ XPos
, y
+ YPos
, Width
, Height
);
70 core
->GetVideoDriver()->DrawRect( r
, black
);
71 font
->Print( r
, Buffer
, palette
,
72 IE_FONT_ALIGN_LEFT
| IE_FONT_ALIGN_MIDDLE
, true, NULL
,
73 Cursor
, CurPos
, true );
76 void Console::SetFont(Font
* f
)
83 void Console::SetCursor(Sprite2D
* cur
)
90 void Console::SetBackGround(Sprite2D
* back
)
92 //if 'back' is NULL then no BackGround will be drawn
95 /** Sets the Text of the current control */
96 int Console::SetText(const char* string
, int /*pos*/)
98 strncpy( ( char * ) Buffer
, string
, max
);
101 /** Key Press Event */
102 void Console::OnKeyPress(unsigned char Key
, unsigned short /*Mod*/)
105 size_t len
= strlen( ( char* ) Buffer
);
107 for (size_t i
= len
; i
> CurPos
; i
--) {
108 Buffer
[i
] = Buffer
[i
- 1];
110 Buffer
[CurPos
++] = Key
;
115 /** Special Key Press */
116 void Console::OnSpecialKeyPress(unsigned char Key
)
123 size_t len
= strlen( ( const char * ) Buffer
);
124 for (size_t i
= CurPos
; i
< len
; i
++) {
125 Buffer
[i
- 1] = Buffer
[i
];
135 CurPos
= (unsigned short) strlen( (const char * ) Buffer
);
148 len
= strlen( ( const char * ) Buffer
);
154 len
= strlen( ( const char * ) Buffer
);
156 for (size_t i
= CurPos
; i
< len
; i
++) {
157 Buffer
[i
] = Buffer
[i
+ 1];
162 core
->GetGUIScriptEngine()->ExecString( ( char* ) Buffer
);
173 void Console::HistoryBack()
176 if (HistPos
< HistMax
-1 && Buffer
[0]) {
179 memcpy(Buffer
, History
[HistPos
], max
);
180 CurPos
= (unsigned short) strlen ((const char *) Buffer
);
184 void Console::HistoryForward()
193 memcpy(Buffer
, History
[HistPos
], max
);
194 CurPos
= (unsigned short) strlen ((const char *) Buffer
);
197 void Console::HistoryAdd(bool force
)
201 if (!force
&& !Buffer
[0])
203 for (i
=0;i
<HistMax
;i
++) {
204 if (!strnicmp((const char *) History
[i
],(const char *) Buffer
,max
) )
208 for (i
=HISTORY_SIZE
-1; i
>0; i
--) {
209 memcpy(History
[i
], History
[i
-1], max
);
212 memcpy(History
[0], Buffer
, max
);
213 if (HistMax
<HISTORY_SIZE
) {
218 bool Console::SetEvent(int /*eventType*/, EventHandler
/*handler*/)