4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include "Screen/SingleWindow.hpp"
28 #include "Screen/ButtonWindow.hpp"
29 #include "Screen/BufferCanvas.hpp"
32 #include "Screen/WindowCanvas.hpp"
40 class TestWindow
: public SingleWindow
{
42 ButtonWindow buffer_button
;
44 ButtonWindow close_button
;
66 void Create(PixelSize size
) {
67 SingleWindow::Create(_T("RunCanvas"), size
);
69 PixelRect rc
= GetClientRect();
71 PixelRect button_rc
= rc
;
72 button_rc
.bottom
-= 5;
73 button_rc
.top
= button_rc
.bottom
- 25;
77 button_rc
.right
= button_rc
.left
+ 65;
79 buffer_button
.Create(*this, _T("Buffer"), ID_BUFFER
, button_rc
);
80 buffer_button
.SetFont(normal_font
);
83 button_rc
.right
= rc
.right
- 5;
84 button_rc
.left
= button_rc
.right
- 65;
86 close_button
.Create(*this, _T("Close"), ID_CLOSE
, button_rc
);
87 close_button
.SetFont(normal_font
);
91 void paint(Canvas
&canvas
) {
92 canvas
.SelectHollowBrush();
93 canvas
.SelectBlackPen();
95 Brush
red_brush(COLOR_RED
);
97 const PixelRect rc
= GetClientRect();
98 const int width
= rc
.right
- rc
.left
;
99 const int height
= rc
.bottom
- rc
.top
;
100 const int hmiddle
= (rc
.left
+ rc
.right
) / 2;
101 const int vmiddle
= (rc
.top
+ rc
.bottom
) / 2;
103 RasterPoint p1
[3] = {
105 { (width
* 2) / 3, -100 },
106 { hmiddle
, height
* 2 },
109 RasterPoint p2
[3] = {
111 { width
* 10, -3000 },
118 canvas
.DrawSegment(hmiddle
, vmiddle
,
119 min(width
, height
) / 3,
120 Angle::Zero(), Angle::Degrees(90),
122 label
= _T("segment 0-90 horizon=false");
126 canvas
.DrawSegment(hmiddle
, vmiddle
,
127 min(width
, height
) / 3,
128 Angle::Degrees(45), Angle::Degrees(180),
130 label
= _T("segment 45-180 horizon=true");
134 canvas
.DrawCircle(hmiddle
, vmiddle
,
135 min(width
, height
) / 3);
136 label
= _T("circle");
142 rc
.left
= hmiddle
- 50;
143 rc
.top
= vmiddle
- 20;
144 rc
.right
= hmiddle
+ 50;
145 rc
.bottom
= vmiddle
+ 20;
146 canvas
.DrawButton(rc
, page
== 4);
148 ? _T("button down=true") : _T("button down=false");
152 canvas
.Select(red_brush
);
153 canvas
.DrawPolygon(p1
, 3);
154 label
= _T("big polygon");
158 canvas
.Select(red_brush
);
159 canvas
.DrawPolygon(p2
, 3);
160 label
= _T("huge polygon");
164 canvas
.SetTextColor(Color(0, 0, 128));
165 canvas
.SetBackgroundTransparent();
166 canvas
.Select(normal_font
);
167 canvas
.DrawText(5, 5, label
);
168 #ifndef ENABLE_OPENGL
169 canvas
.DrawText(5, 25,
170 buffered
? _T("buffered") : _T("not buffered"));
175 #ifndef ENABLE_OPENGL
187 virtual bool OnMouseDown(PixelScalar x
, PixelScalar y
) override
{
188 if (SingleWindow::OnMouseDown(x
, y
))
191 page
= (page
+ 1) % 7;
196 virtual bool OnCommand(unsigned id
, unsigned code
) override
{
202 #ifndef ENABLE_OPENGL
204 buffered
= !buffered
;
206 WindowCanvas
canvas(*this);
207 buffer
.Create(canvas
, canvas
.GetSize());
215 return SingleWindow::OnCommand(id
, code
);
218 virtual void OnPaint(Canvas
&canvas
) override
{
219 #ifndef ENABLE_OPENGL
225 #ifndef ENABLE_OPENGL
230 SingleWindow::OnPaint(canvas
);
238 window
.Create({250, 250});
241 window
.RunEventLoop();