/
console.ec
317 lines (286 loc) · 8.04 KB
/
console.ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/****************************************************************************
ECERE Runtime Library
Copyright (c) 2001-2008 Jerome Jacovella-St-Louis
All Rights Reserved.
console.ec - Console Dialog
****************************************************************************/
import "ecere"
#include <stdarg.h>
class Console : Window
{
EditBox log
{
this,
readOnly = true;
multiLine = true;
textHorzScroll = true;
textVertScroll = true;
autoEmpty = true;
maxNumLines = 256;
};
EditBox commandBox
{
this, textHorzScroll = true; size.h = editHeight, anchor = { left = 0, right = 0, bottom = 0 };
};
virtual bool ProcessCommand(char * command);
Bitmap bitmap;
OldList commands;
Item command;
bool doneLooping;
char currentCommand[256];
int movement;
bool moving;
int actualHeight;
double pos;
double lastTime;
int currentAlpha;
bool shown;
int separatorHeight;
int editHeight;
int referenceHeight;
float speed;
int alpha;
char * version;
Point verLROffset;
Color logTextColor;
char * bmpFile;
Color editBackColor;
Color editTextColor;
alpha = 255;
Timer timer
{
this, delay = 0.05;
bool DelayExpired()
{
double realTime, diffTime;
realTime = GetTime();
diffTime = realTime - lastTime;
/* CONSOLE MOVEMENT */
if(shown && moving)
{
int movement = (int)(diffTime * (movement * speed));
if(movement)
{
pos += movement;
pos = Max(pos, -size.h);
pos = Min(pos, 0);
if(pos == -size.h && movement == -1)
{
// eWindow_Hide(window, true, false);
moving = false;
shown = false;
}
else if(moving)
Move(position.x, (int)pos, clientSize.w, clientSize.h);
if(!pos && movement == 1)
moving = false;
// Set up transparency color
if(size.h)
currentAlpha = (((int)pos + size.h) * alpha / size.h);
log.foreground = (logTextColor & 0xFFFFFF) | (currentAlpha << 24);
if(alpha)
{
commandBox.foreground = (editTextColor & 0xFFFFFF) | ((currentAlpha * 255 / alpha) << 24);
}
commandBox.background = (editBackColor & 0xFFFFFF) | (currentAlpha << 24);
lastTime = realTime;
}
}
return true;
}
};
bool OnCreate()
{
if(speed)
timer.Start();
commands.Clear();
commands.circ = true;
movement = 1;
doneLooping = true;
if(!referenceHeight)
referenceHeight = 768;
log.anchor = { left = 0, top = 0, right = 0, bottom = editHeight + separatorHeight* 768/referenceHeight };
return true;
}
bool OnPostCreate()
{
if(referenceHeight)
{
// h = height * 768 / referenceHeight;
// Set up transparency color
currentAlpha = (((int)pos + size.h) * alpha / size.h);
}
else
referenceHeight = 768;
if(editHeight)
commandBox.size.h = editHeight;
log.background = 0;
log.foreground = (logTextColor & 0xFFFFFF) | (currentAlpha << 24);
if(alpha)
commandBox.foreground = (editTextColor & 0xFFFFFF) | ((currentAlpha * 255 / alpha) << 24);
commandBox.background = (editBackColor & 0xFFFFFF) | (currentAlpha << 24);
return true;
}
void OnDestroy()
{
commands.Free(null);
}
bool OnLoadGraphics()
{
if(bmpFile)
bitmap.Load(bmpFile, null, displaySystem);
return true;
}
void OnUnloadGraphics()
{
bitmap.Free();
}
void OnRedraw(Surface surface)
{
surface.SetForeground(white);
if(bitmap)
surface.Stretch(bitmap, 0, 0, 0, 0, clientSize.w, clientSize.h, bitmap.width, bitmap.height);
if(referenceHeight)
{
surface.SetForeground((logTextColor & 0xFFFFFF) | (currentAlpha << 24));
if(version)
surface.WriteTextf(
clientSize.w - verLROffset.x * 768 / referenceHeight,
clientSize.h - verLROffset.y * 768 / referenceHeight,
version);
}
}
bool OnKeyDown(Key key, unichar ch)
{
switch((SmartKey)key)
{
case tilde:
Toggle();
return false;
case enter:
{
Item string;
char * lineBuffer;
char * buffer;
// Process Command in command edit box here
lineBuffer = commandBox.line.text;
if(lineBuffer && lineBuffer[0])
{
string = (Item)new0 byte[sizeof(class Item) + strlen(lineBuffer) + 1];
if(string)
{
commands.Add(string);
buffer = (char *) ((byte *) string + sizeof(class Item));
strcpy(buffer, lineBuffer);
command = commands.first;
doneLooping = true;
}
log.End();
if(log.numLines > 1 || log.line.count)
log.PutCh('\n');
log.PutS(" > ");
log.PutS(lineBuffer);
if(ProcessCommand)
{
if(ProcessCommand(lineBuffer))
return false;
}
if(commandBox)
commandBox.Clear();
}
break;
}
}
return true;
}
bool OnKeyHit(Key key, unichar ch)
{
char * lineBuffer = commandBox.line.text;
char * buffer;
switch((SmartKey)key)
{
case pageDown:
log.PageDown();
return true;
case pageUp:
log.PageUp();
return false;
case up:
if(command)
{
buffer = (char *) ((byte *) command + sizeof(class Item));
if(strcmp(buffer, lineBuffer))
{
strcpy(currentCommand, lineBuffer);
}
if(command == commands.first && !doneLooping)
{
doneLooping = true;
commandBox.Clear();
commandBox.PutS(currentCommand);
}
else
{
doneLooping = false;
command = command.prev;
commandBox.Clear();
commandBox.PutS(((byte *) command) + sizeof(class Item));
}
}
return false;
case down:
if(command)
{
buffer = (char *) ((byte *) command + sizeof(class Item));
if(strcmp(buffer, lineBuffer))
{
strcpy(currentCommand, lineBuffer);
}
if(command == commands.last && !doneLooping)
{
doneLooping = true;
commandBox.Clear();
commandBox.PutS(currentCommand);
}
else
{
doneLooping = false;
command = command.next;
commandBox.Clear();
commandBox.PutS(((byte *) command) + sizeof(class Item));
}
}
return false;
case tilde:
return false;
/* case F6:
return false;*/
}
return true;
}
void Toggle()
{
if(this)
{
movement = -movement;
moving = true;
shown = true;
SetState(normal, true, 0);
commandBox.Activate();
lastTime = GetTime();
}
}
void Log(char * format, ...)
{
if(this)
{
char text[MAX_F_STRING];
va_list args;
va_start(args, format);
vsprintf(text, format, args);
log.End();
log.PutS(text);
va_end(args);
}
}
};