My favorites
▼
|
Sign in
upp-mirror
U++ is the C++ development platform
Project Home
Downloads
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
reference
/
Framebuffer
/
TopFrame.cpp
r5017
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
#include "Fb.h"
#ifdef GUI_FB
NAMESPACE_UPP
#define LLOG(x) // LOG(x)
#define LDUMP(x) //DDUMP(x)
TopWindowFrame::TopWindowFrame()
{
close.SetImage(FBImg::close());
close.EdgeStyle();
Add(close);
maximize.SetImage(FBImg::maximize());
maximize.EdgeStyle();
Add(maximize);
maximize <<= THISBACK(ToggleMaximize);
maximized = false;
sizeable = false;
holding = false;
}
void TopWindowFrame::SyncRect()
{
if(maximized) {
Size sz = framebuffer.GetSize();
if(GetRect().GetSize() != sz)
SetRect(sz);
}
}
void TopWindowFrame::Maximize()
{
if(!maximized && maximize.IsShown()) {
maximized = true;
overlapped = GetRect();
SetRect(framebuffer.GetSize());
maximize.SetImage(FBImg::overlap());
}
}
void TopWindowFrame::Overlap()
{
if(maximized && maximize.IsShown()) {
maximized = false;
SetRect(overlapped);
maximize.SetImage(FBImg::maximize());
}
}
void TopWindowFrame::ToggleMaximize()
{
if(maximized)
Overlap();
else
Maximize();
}
Rect TopWindowFrame::Margins() const
{
return maximized ? Rect(0, 0, 0, 0) : ChMargins(FBImg::border());
}
void TopWindowFrame::Paint(Draw& w)
{
Size sz = GetSize();
Rect m = Margins();
int c = GetStdFontCy() + 4;
ChPaintEdge(w, sz, FBImg::border());
ChPaint(w, m.left, m.top, sz.cx - m.left - m.right, GetStdFontCy() + 4,
window->IsForeground() ? FBImg::title() : FBImg::bgtitle());
int tx = m.left + 2;
int tcx = sz.cx - m.left - m.right - 4 - c * (close.IsShown() + maximize.IsShown());
if(!IsNull(icon)) {
Image h = icon;
if(h.GetWidth() > c || h.GetHeight() > c)
h = Rescale(h, GetFitSize(h.GetSize(), Size(c)));
w.DrawImage(tx, m.top + 2, h);
tx += c;
tcx -= c;
}
DrawTextEllipsis(w, tx, m.top + 2, tcx, title, "..", StdFont(), SColorHighlightText());
}
void TopWindowFrame::Layout()
{
Size sz = GetSize();
Rect m = Margins();
int c = GetStdFontCy() + 4;
int x = sz.cx - m.right;
if(close.IsShown())
close.SetRect(x -= c, m.top, c, c);
if(maximize.IsShown())
maximize.SetRect(x -= c, m.top, c, c);
}
Rect TopWindowFrame::GetClient() const
{
Rect r = GetRect();
Rect m = Margins();
r.left += m.left;
r.right -= m.right;
r.top += m.top;
r.bottom -= m.bottom;
r.top += GetStdFontCy() + 4;
return r;
}
Rect TopWindowFrame::ComputeClient(Rect r)
{
Rect m = Margins();
r.left -= m.left;
r.right += m.right;
r.top -= m.top;
r.bottom += m.bottom;
r.top -= GetStdFontCy() + 4;
return r;
}
void TopWindowFrame::SetClient(Rect r)
{
SetRect(ComputeClient(r));
}
Point TopWindowFrame::GetDragMode(Point p)
{
Size sz = GetSize();
Rect m = ChMargins(FBImg::border());
Point dir;
dir.y = p.y < m.top ? -1 : p.y > sz.cy - m.top ? 1 : 0;
dir.x = p.x < m.left ? -1 : p.x > sz.cx - m.right ? 1 : 0;
return dir;
}
void TopWindowFrame::StartDrag()
{
if(maximized)
return;
if(!sizeable && (dir.x || dir.y))
return;
if(FullWindowDrag) {
SetCapture();
startrect = GetRect();
startpos = GetMousePos();
}
else {
Rect r = GetScreenRect();
RectTracker tr(*this);
tr.SetCursorImage(GetDragImage(dir))
.MaxRect(framebuffer.GetSize())
.MinSize(ComputeClient(minsize).GetSize())
.Pattern(DRAWDRAGRECT_DASHED | DRAWDRAGRECT_SCREEN)
.Width(2)
.Animation();
PaintLock++;
r = tr.Track(r, dir.x < 0 ? ALIGN_LEFT : dir.x > 0 ? ALIGN_RIGHT : ALIGN_CENTER,
dir.y < 0 ? ALIGN_TOP : dir.y > 0 ? ALIGN_BOTTOM : ALIGN_CENTER);
PaintLock--;
SetRect(r);
}
LLOG("START DRAG ---------------");
}
void TopWindowFrame::GripResize()
{
dir = Point(1, 1);
StartDrag();
}
void TopWindowFrame::LeftDown(Point p, dword keyflags)
{
dir = GetDragMode(p);
if(dir.x || dir.y || FullWindowDrag)
StartDrag();
else {
SetCapture();
holding = true;
hold.Set(GetKbdDelay() / 3, THISBACK(Hold));
}
}
void TopWindowFrame::CancelMode()
{
holding = false;
}
void TopWindowFrame::LeftUp(Point p, dword keyflags)
{
holding = false;
}
void TopWindowFrame::Hold()
{
if(HasCapture()) {
if(HasMouse() && GetMouseLeft() && holding)
StartDrag();
ReleaseCapture();
holding = false;
}
}
void TopWindowFrame::LeftHold(Point p, dword keyflags)
{
if(HasCapture() || FullWindowDrag)
return;
dir = GetDragMode(p);
if(!dir.x && !dir.y)
StartDrag();
}
void TopWindowFrame::LeftDouble(Point p, dword keyflags)
{
ToggleMaximize();
IgnoreMouseUp();
}
void TopWindowFrame::MouseMove(Point, dword)
{
LDUMP(HasWndCapture());
LDUMP(HasCapture());
if(!HasCapture() || holding)
return;
Size msz = ComputeClient(minsize).GetSize();
Point p = GetMousePos() - startpos;
Rect r = startrect;
if(dir.x == -1)
r.left = min(r.left + p.x, startrect.right - msz.cx);
if(dir.x == 1)
r.right = max(r.right + p.x, startrect.left + msz.cx);
if(dir.y == -1)
r.top = min(r.top + p.y, startrect.bottom - msz.cy);
if(dir.y == 1)
r.bottom = max(r.bottom + p.y, startrect.top + msz.cy);
if(dir.y == 0 && dir.x == 0)
r.Offset(p);
SetRect(r);
}
Image TopWindowFrame::GetDragImage(Point dir)
{
static Image (*im[9])() = {
Image::SizeTopLeft, Image::SizeLeft, Image::SizeBottomLeft,
Image::SizeTop, Image::Arrow, Image::SizeBottom,
Image::SizeTopRight, Image::SizeRight, Image::SizeBottomRight,
};
return (*im[(dir.x + 1) * 3 + (dir.y + 1)])();
}
Image TopWindowFrame::CursorImage(Point p, dword)
{
if(!sizeable)
return Image::Arrow();
return GetDragImage(HasCapture() ? dir : GetDragMode(p));
}
END_UPP_NAMESPACE
#endif
Show details
Hide details
Change log
r4176
by cxl on Nov 16, 2011
Diff
.reference: Rainbow example (RM #158)
Go to:
/trunk/reference/Framebuffer
...nk/reference/Framebuffer/After.h
...erence/Framebuffer/ChSysInit.cpp
...k/reference/Framebuffer/Clip.cpp
...k/reference/Framebuffer/Ctrl.cpp
/trunk/reference/Framebuffer/Ctrl.h
...nk/reference/Framebuffer/DnD.cpp
...k/reference/Framebuffer/Draw.cpp
.../reference/Framebuffer/Event.cpp
/trunk/reference/Framebuffer/FB.iml
/trunk/reference/Framebuffer/Fb.h
...erence/Framebuffer/Framebuffer.h
...ence/Framebuffer/Framebuffer.upp
/trunk/reference/Framebuffer/Gui.h
.../reference/Framebuffer/Image.cpp
...nk/reference/Framebuffer/Top.cpp
/trunk/reference/Framebuffer/Top.h
...ference/Framebuffer/TopFrame.cpp
...k/reference/Framebuffer/Util.cpp
...nk/reference/Framebuffer/Wnd.cpp
/trunk/reference/Framebuffer/init
/trunk/reference/LinuxFb
/trunk/reference/LinuxFb/Keys.h
/trunk/reference/LinuxFb/LinuxFb.h
...nk/reference/LinuxFb/LinuxFb.upp
...reference/LinuxFb/LinuxFbLocal.h
/trunk/reference/LinuxFb/Local.h
/trunk/reference/LinuxFb/Proc.cpp
/trunk/reference/LinuxFb/Win.cpp
/trunk/reference/LinuxFb/init
/trunk/reference/LinuxFb/keymap.cpp
.../reference/LinuxFb/vgakeyboard.h
/trunk/reference/UWord_FB
/trunk/reference/UWord_FB/UWord.cpp
/trunk/reference/UWord_FB/UWord.iml
.../reference/UWord_FB/UWord_FB.upp
/trunk/reference/UWord_FB/icon.ico
/trunk/reference/UWord_FB/init
/trunk/reference/WinFb
/trunk/reference/WinFb/Keys.h
/trunk/reference/WinFb/Local.h
/trunk/reference/WinFb/Proc.cpp
/trunk/reference/WinFb/Win.cpp
/trunk/reference/WinFb/WinFb.h
/trunk/reference/WinFb/WinFb.upp
/trunk/reference/WinFb/init
/trunk/reference/guiplatform.h
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 5666 bytes, 259 lines
View raw file
Powered by
Google Project Hosting