My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
#include "Console.h"

NAMESPACE_UPP

void Console::Paint(Draw& w)
{
SystemDraw& sw = (SystemDraw&) w;
Size sz = GetSize();
sw.alpha = 100.f;
w.DrawRect(sz, Black);
w.DrawRect(0, 0, sz.cx, 1, Yellow);
w.DrawRect(sz.cx - 1, 1, 1, sz.cy - 1, Yellow);
w.DrawRect(0, 1, 1, sz.cy, Yellow);
w.DrawRect(1, sz.cy - 1, sz.cx - 2, 1, Yellow);
//DrawFrame(w, sz, Yellow);
//w.DrawImage(sz.cx - 18, sz.cy - 21, WinGlImg::ResizeMarker());
w.DrawRect(1, sz.cy - 22, sz.cx - 2, 1, Yellow);
w.Clip(5, 5, sz.cx - 10, sz.cy - 5 - 21);
sw.alpha = 255.f;
int y = 5;
int ty = Draw::GetStdFontCy() + 2;
for(int i = 0; i < fixedText.GetCount(); i++)
{
w.DrawText(5, y, fixedText[i].text, StdFont(), fixedText[i].ink);
y += ty;
}

if(fixedText.GetCount() > 0 && floatText.GetCount() > 0)
{
sw.alpha = 150.f;
w.DrawRect(5, y, sz.cx - 10, 1, Yellow);
y += 2;
sw.alpha = 255.f;
}

int lines = (sz.cy - y - 22) / ty;
int n = fceil(sb.GetPos() / double(ty));
int maxn = min(n + lines, currLine);

while(n < maxn)
{
LineInfo& lf = floatText[n];
w.DrawText(5, y, lf.text, StdFont(), lf.ink);
y += ty;
++n;
}

w.End();
}

void Console::Log(int line, const char* text, Color ink)
{
LineInfo& lf = fixedText.GetAdd(line);
lf.ink = ink;
lf.text = text;
}

void Console::Log(const char* text, Color ink)
{
bool isend = sb.IsEnd();

if(++currLine >= maxLine)
{
currLine = maxLine;
for(int i = 0; i < maxLine - 1; i++)
floatText[i] = floatText[i + 1];
}

int ty = Draw::GetStdFontCy() + 2;
int total = currLine * ty;
int fcnt = fixedText.GetCount();
sb.SetTotal(total + 5 + 22);

if(isend)
sb.GoEnd();

LineInfo& lf = floatText[currLine - 1];
lf.ink = ink;
lf.text = text;
}

void Console::LeftDown(Point p, dword keys)
{
SetCapture();
pos = p;
rs = GetSize();
tl = GetScreenRect().TopLeft();
Size sz = GetSize();
resize = p.x > sz.cx - 18 && p.y > sz.cy - 18;
}

void Console::LeftUp(Point p, dword keys)
{
ReleaseCapture();
}

void Console::MouseMove(Point p, dword keys)
{
if(HasCapture())
{
Rect r = GetRect();
bool isend = sb.IsEnd();
if(resize)
{
tl = Point(p.x - pos.x, p.y - pos.y);
SetConsoleRect(r.left, r.top, max(2, rs.cx + tl.x), max(2, rs.cy + tl.y));
}
else
{
tl += Point(p.x - pos.x, p.y - pos.y);
SetConsoleRect(tl.x, tl.y, r.Width(), r.Height());
}
if(isend)
sb.GoEnd();
}
}

void Console::Layout()
{
}

void Console::SetConsoleRect(int x, int y, int cx, int cy)
{
int width = cx < 0 ? 300 : cx;
int height = cy < 0 ? 5 + 5 + (Draw::GetStdFontCy() + 2) * 30 + 3 : cy;
SetRect(x, y, width, height);
}

void Console::SetLines(int lines)
{
maxLine = lines;
floatText.SetCount(lines);
}

void Console::Init(Ctrl& parent)
{
if(!init)
return;
init = false;
this->parent = &parent;
SetConsoleRect(parent.GetSize().cx - 5 - 300, 5);
sb.SetFrameSize(5, false).SetAlign(AlignedFrame::RIGHT);
Show();
}

void Console::Show(bool b)
{
if(IsOpen())
{
if(!b)
Close();
}
else
{
if(b)
PopUp(parent, true, false);
}
}

void Console::Clear()
{
currLine = 0;
sb.Clear();
}

Console::Console() : init(true), resize(false)
{
Add(sb.RightPos(2, 7).VSizePos(2, 22));
Add(clear.LeftPos(2, 50).BottomPos(2, 18));
clear.SetLabel("Clear");
//clear.bg = Yellow;
//clear.alpha = 150.f;
clear <<= THISBACK(Clear);
SetLines(3000);
currLine = 0;
scrollLine = 0;
}

END_UPP_NAMESPACE

Change log

r4188 by unodgs on Nov 22, 2011   Diff
WinGL: Added automatic atlas textures,
fixed some bugs
Go to: 
Project members, sign in to write a code review

Older revisions

r3915 by unodgs on Sep 26, 2011   Diff
Rainbow: WinGL..
All revisions of this file

File info

Size: 3387 bytes, 179 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting