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.
25 * This program demonstrates the OZRenderer library. It
26 * shows a list of shapes, and draws the selected shape on the right.
30 #define ENABLE_DIALOG_LOOK
33 #include "Screen/SingleWindow.hpp"
34 #include "Screen/ButtonWindow.hpp"
35 #include "Screen/BufferCanvas.hpp"
36 #include "Look/AirspaceLook.hpp"
37 #include "Look/TaskLook.hpp"
38 #include "Form/List.hpp"
39 #include "InfoBoxes/InfoBoxLayout.hpp"
40 #include "Renderer/OZRenderer.hpp"
41 #include "Engine/Task/ObservationZones/LineSectorZone.hpp"
42 #include "Engine/Task/ObservationZones/KeyholeZone.hpp"
43 #include "Engine/Task/ObservationZones/AnnularSectorZone.hpp"
44 #include "Engine/Task/ObservationZones/Boundary.hpp"
45 #include "Projection/Projection.hpp"
46 #include "Renderer/AirspaceRendererSettings.hpp"
52 static const TCHAR
*const oz_type_names
[NUM_OZ_TYPES
] = {
59 _T("BGA Fixed Course"),
60 _T("BGA Enhanced Option"),
63 _T("Symmetric quadrant"),
67 static GeoPoint
location(Angle::Degrees(7.7061111111111114),
68 Angle::Degrees(51.051944444444445));
70 static GeoPoint
previous(Angle::Degrees(10.6),
73 static GeoPoint
next(Angle::Degrees(10.2),
74 Angle::Degrees(51.4));
76 static AirspaceRendererSettings airspace_renderer_settings
;
78 class OZWindow
: public PaintWindow
{
80 ObservationZonePoint
*oz
;
81 Projection projection
;
84 OZWindow(const TaskLook
&task_look
, const AirspaceLook
&airspace_look
)
85 :roz(task_look
, airspace_look
, airspace_renderer_settings
), oz(NULL
) {
86 projection
.SetGeoLocation(location
);
87 set_shape(ObservationZone::Shape::LINE
);
94 void set_shape(ObservationZone::Shape shape
) {
95 if (oz
!= NULL
&& shape
== oz
->GetShape())
104 case ObservationZone::Shape::LINE
:
105 oz
= new LineSectorZone(location
, 2 * radius
);
108 case ObservationZone::Shape::CYLINDER
:
109 oz
= new CylinderZone(location
, radius
);
112 case ObservationZone::Shape::MAT_CYLINDER
:
113 oz
= CylinderZone::CreateMatCylinderZone(location
);
116 case ObservationZone::Shape::SECTOR
:
117 oz
= new SectorZone(location
, radius
,
118 Angle::Degrees(0), Angle::Degrees(70));
121 case ObservationZone::Shape::ANNULAR_SECTOR
:
122 oz
= new AnnularSectorZone(location
, radius
,
123 Angle::Degrees(0), Angle::Degrees(70),
127 case ObservationZone::Shape::FAI_SECTOR
:
128 oz
= SymmetricSectorZone::CreateFAISectorZone(location
);
131 case ObservationZone::Shape::CUSTOM_KEYHOLE
:
132 oz
= KeyholeZone::CreateCustomKeyholeZone(location
, fixed(10000),
133 Angle::QuarterCircle());
136 case ObservationZone::Shape::DAEC_KEYHOLE
:
137 oz
= KeyholeZone::CreateDAeCKeyholeZone(location
);
140 case ObservationZone::Shape::BGAFIXEDCOURSE
:
141 oz
= KeyholeZone::CreateBGAFixedCourseZone(location
);
144 case ObservationZone::Shape::BGAENHANCEDOPTION
:
145 oz
= KeyholeZone::CreateBGAEnhancedOptionZone(location
);
148 case ObservationZone::Shape::BGA_START
:
149 oz
= KeyholeZone::CreateBGAStartSectorZone(location
);
152 case ObservationZone::Shape::SYMMETRIC_QUADRANT
:
153 oz
= new SymmetricSectorZone(location
);
158 oz
->SetLegs(&previous
, &next
);
165 virtual void OnPaint(Canvas
&canvas
) override
;
167 virtual void OnResize(PixelSize new_size
) override
{
168 PaintWindow::OnResize(new_size
);
169 projection
.SetScale(fixed(new_size
.cx
) / 21000);
170 projection
.SetScreenOrigin(new_size
.cx
/ 2, new_size
.cy
/ 2);
175 OZWindow::OnPaint(Canvas
&canvas
)
181 const int offset
= 0;
183 roz
.Draw(canvas
, OZRenderer::LAYER_SHADE
, projection
, *oz
, offset
);
184 roz
.Draw(canvas
, OZRenderer::LAYER_INACTIVE
, projection
, *oz
, offset
);
185 roz
.Draw(canvas
, OZRenderer::LAYER_ACTIVE
, projection
, *oz
, offset
);
187 /* debugging for ObservationZone::GetBoundary() */
188 Pen
pen(1, COLOR_RED
);
190 const OZBoundary boundary
= oz
->GetBoundary();
191 for (auto i
= boundary
.begin(), end
= boundary
.end(); i
!= end
; ++i
) {
192 RasterPoint p
= projection
.GeoToScreen(*i
);
193 canvas
.DrawLine(p
.x
- 3, p
.y
- 3, p
.x
+ 3, p
.y
+ 3);
194 canvas
.DrawLine(p
.x
+ 3, p
.y
- 3, p
.x
- 3, p
.y
+ 3);
198 class TestWindow
: public SingleWindow
,
199 ListItemRenderer
, ListCursorHandler
{
200 ButtonWindow close_button
;
201 ListControl
*type_list
;
210 TestWindow(const TaskLook
&task_look
, const AirspaceLook
&airspace_look
)
211 :type_list(NULL
), oz(task_look
, airspace_look
) {}
216 void Create(const DialogLook
&look
, PixelSize size
) {
217 SingleWindow::Create(_T("RunRenderOZ"), size
);
219 const PixelRect rc
= GetClientRect();
221 WindowStyle with_border
;
222 with_border
.Border();
224 PixelRect oz_rc
= rc
;
225 oz_rc
.left
= oz_rc
.right
/ 2;
226 oz
.Create(*this, oz_rc
, with_border
);
228 const PixelRect
list_rc(0, 0, rc
.right
/ 2, rc
.bottom
- 30);
230 type_list
= new ListControl(*this, look
, list_rc
,
233 type_list
->SetItemRenderer(this);
234 type_list
->SetCursorHandler(this);
235 type_list
->SetLength(NUM_OZ_TYPES
);
237 PixelRect button_rc
= rc
;
238 button_rc
.right
= (rc
.left
+ rc
.right
) / 2;
239 button_rc
.top
= button_rc
.bottom
- 30;
240 close_button
.Create(*this, _T("Close"), ID_CLOSE
, button_rc
);
242 oz
.set_shape(ObservationZone::Shape::LINE
);
244 type_list
->SetFocus();
248 virtual bool OnCommand(unsigned id
, unsigned code
) override
{
255 return SingleWindow::OnCommand(id
, code
);
258 /* virtual methods from ListItemRenderer */
259 virtual void OnPaintItem(Canvas
&canvas
, const PixelRect rc
,
260 unsigned idx
) override
{
261 canvas
.DrawText(rc
.left
+ 2, rc
.top
+ 2, oz_type_names
[idx
]);
264 /* virtual methods from ListCursorHandler */
265 virtual void OnCursorMoved(unsigned idx
) override
{
266 assert(idx
< NUM_OZ_TYPES
);
268 oz
.set_shape((ObservationZone::Shape
)idx
);
275 airspace_renderer_settings
.SetDefaults();
277 TaskLook
*task_look
= new TaskLook();
278 task_look
->Initialise();
280 AirspaceLook
*airspace_look
= new AirspaceLook();
281 airspace_look
->Initialise(airspace_renderer_settings
, normal_font
);
283 TestWindow
window(*task_look
, *airspace_look
);
284 window
.Create(*dialog_look
, {480, 480});
287 window
.RunEventLoop();
289 delete airspace_look
;