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
|
/*
* ConsoleView.cpp
*
* Created on: Jan 31, 2012
* Author: Simon
*/
#include "ConsoleView.h"
#include "interface/Keys.h"
ConsoleView::ConsoleView():
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, 150)),
commandField(NULL)
{
class CommandHighlighter: public ui::TextboxAction
{
ConsoleView * v;
public:
CommandHighlighter(ConsoleView * v_) { v = v_; }
void TextChangedCallback(ui::Textbox * sender)
{
sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
}
};
commandField = new ui::Textbox(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "");
commandField->SetAlignment(AlignLeft, AlignBottom);
commandField->SetActionCallback(new CommandHighlighter(this));
AddComponent(commandField);
FocusComponent(commandField);
commandField->SetBorder(false);
}
void ConsoleView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
switch(key)
{
case '`':
c->CloseConsole();
break;
case KEY_RETURN:
case KEY_ENTER:
c->EvaluateCommand(commandField->GetText());
commandField->SetText("");
break;
case KEY_DOWN:
c->NextCommand();
break;
case KEY_UP:
c->PreviousCommand();
break;
}
}
void ConsoleView::NotifyPreviousCommandsChanged(ConsoleModel * sender)
{
for(int i = 0; i < commandList.size(); i++)
{
RemoveComponent(commandList[i]);
delete commandList[i];
}
commandList.clear();
std::deque<ConsoleCommand> commands = sender->GetPreviousCommands();
int currentY = Size.Y - 32;
if(commands.size())
for(int i = commands.size()-1; i >= 0; i--)
{
if(currentY <= 0)
break;
ui::Label * tempLabel = new ui::Label(ui::Point(Size.X/2, currentY), ui::Point(Size.X/2, 16), commands[i].ReturnValue);
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
commandList.push_back(tempLabel);
AddComponent(tempLabel);
tempLabel = new ui::Label(ui::Point(0, currentY), ui::Point(Size.X/2, 16), commands[i].Command);
tempLabel->SetAlignment(AlignLeft, AlignMiddle);
commandList.push_back(tempLabel);
AddComponent(tempLabel);
currentY-=16;
}
}
void ConsoleView::NotifyCurrentCommandChanged(ConsoleModel * sender)
{
commandField->SetText(sender->GetCurrentCommand().Command);
}
void ConsoleView::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 0, 0, 0, 110);
g->blend_line(Position.X, Position.Y+Size.Y-16, Position.X+Size.X, Position.Y+Size.Y-16, 255, 255, 255, 160);
g->blend_line(Position.X, Position.Y+Size.Y, Position.X+Size.X, Position.Y+Size.Y, 255, 255, 255, 200);
}
ConsoleView::~ConsoleView() {
}
|