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/MatCylinderZone.hpp"
43 #include "Engine/Task/ObservationZones/FAISectorZone.hpp"
44 #include "Engine/Task/ObservationZones/KeyholeZone.hpp"
45 #include "Engine/Task/ObservationZones/BGAFixedCourseZone.hpp"
46 #include "Engine/Task/ObservationZones/BGAEnhancedOptionZone.hpp"
47 #include "Engine/Task/ObservationZones/BGAStartSectorZone.hpp"
48 #include "Engine/Task/ObservationZones/AnnularSectorZone.hpp"
49 #include "Engine/Task/ObservationZones/Boundary.hpp"
50 #include "Projection/Projection.hpp"
51 #include "Renderer/AirspaceRendererSettings.hpp"
57 static const TCHAR
*const oz_type_names
[NUM_OZ_TYPES
] = {
64 _T("BGA Fixed Course"),
65 _T("BGA Enhanced Option"),
70 static GeoPoint
location(Angle::Degrees(7.7061111111111114),
71 Angle::Degrees(51.051944444444445));
73 static GeoPoint
previous(Angle::Degrees(10.6),
76 static GeoPoint
next(Angle::Degrees(10.2),
77 Angle::Degrees(51.4));
79 static AirspaceRendererSettings airspace_renderer_settings
;
81 class OZWindow
: public PaintWindow
{
83 ObservationZonePoint
*oz
;
84 Projection projection
;
87 OZWindow(const TaskLook
&task_look
, const AirspaceLook
&airspace_look
)
88 :roz(task_look
, airspace_look
, airspace_renderer_settings
), oz(NULL
) {
89 projection
.SetGeoLocation(location
);
90 set_shape(ObservationZonePoint::LINE
);
97 void set_shape(ObservationZonePoint::Shape shape
) {
98 if (oz
!= NULL
&& shape
== oz
->GetShape())
107 case ObservationZonePoint::LINE
:
108 oz
= new LineSectorZone(location
, 2 * radius
);
111 case ObservationZonePoint::CYLINDER
:
112 oz
= new CylinderZone(location
, radius
);
115 case ObservationZonePoint::MAT_CYLINDER
:
116 oz
= new MatCylinderZone(location
);
119 case ObservationZonePoint::SECTOR
:
120 oz
= new SectorZone(location
, radius
,
121 Angle::Degrees(0), Angle::Degrees(70));
124 case ObservationZonePoint::ANNULAR_SECTOR
:
125 oz
= new AnnularSectorZone(location
, radius
,
126 Angle::Degrees(0), Angle::Degrees(70),
130 case ObservationZonePoint::FAI_SECTOR
:
131 oz
= new FAISectorZone(location
);
134 case ObservationZonePoint::KEYHOLE
:
135 oz
= new KeyholeZone(location
);
138 case ObservationZonePoint::BGAFIXEDCOURSE
:
139 oz
= new BGAFixedCourseZone(location
);
142 case ObservationZonePoint::BGAENHANCEDOPTION
:
143 oz
= new BGAEnhancedOptionZone(location
);
146 case ObservationZonePoint::BGA_START
:
147 oz
= new BGAStartSectorZone(location
);
152 oz
->SetLegs(&previous
, &next
);
159 virtual void OnPaint(Canvas
&canvas
) override
;
161 virtual void OnResize(PixelSize new_size
) override
{
162 PaintWindow::OnResize(new_size
);
163 projection
.SetScale(fixed(new_size
.cx
) / 21000);
164 projection
.SetScreenOrigin(new_size
.cx
/ 2, new_size
.cy
/ 2);
169 OZWindow::OnPaint(Canvas
&canvas
)
175 const int offset
= 0;
177 roz
.Draw(canvas
, OZRenderer::LAYER_SHADE
, projection
, *oz
, offset
);
178 roz
.Draw(canvas
, OZRenderer::LAYER_INACTIVE
, projection
, *oz
, offset
);
179 roz
.Draw(canvas
, OZRenderer::LAYER_ACTIVE
, projection
, *oz
, offset
);
181 /* debugging for ObservationZone::GetBoundary() */
182 Pen
pen(1, COLOR_RED
);
184 const OZBoundary boundary
= oz
->GetBoundary();
185 for (auto i
= boundary
.begin(), end
= boundary
.end(); i
!= end
; ++i
) {
186 RasterPoint p
= projection
.GeoToScreen(*i
);
187 canvas
.DrawLine(p
.x
- 3, p
.y
- 3, p
.x
+ 3, p
.y
+ 3);
188 canvas
.DrawLine(p
.x
+ 3, p
.y
- 3, p
.x
- 3, p
.y
+ 3);
192 class TestWindow
: public SingleWindow
,
193 ListItemRenderer
, ListCursorHandler
{
194 ButtonWindow close_button
;
195 ListControl
*type_list
;
204 TestWindow(const TaskLook
&task_look
, const AirspaceLook
&airspace_look
)
205 :type_list(NULL
), oz(task_look
, airspace_look
) {}
210 void Create(const DialogLook
&look
, PixelSize size
) {
211 SingleWindow::Create(_T("RunRenderOZ"), size
);
213 const PixelRect rc
= GetClientRect();
215 WindowStyle with_border
;
216 with_border
.Border();
218 PixelRect oz_rc
= rc
;
219 oz_rc
.left
= oz_rc
.right
/ 2;
220 oz
.Create(*this, oz_rc
, with_border
);
222 const PixelRect
list_rc(0, 0, rc
.right
/ 2, rc
.bottom
- 30);
224 type_list
= new ListControl(*this, look
, list_rc
,
227 type_list
->SetItemRenderer(this);
228 type_list
->SetCursorHandler(this);
229 type_list
->SetLength(NUM_OZ_TYPES
);
231 PixelRect button_rc
= rc
;
232 button_rc
.right
= (rc
.left
+ rc
.right
) / 2;
233 button_rc
.top
= button_rc
.bottom
- 30;
234 close_button
.Create(*this, _T("Close"), ID_CLOSE
, button_rc
);
236 oz
.set_shape(ObservationZonePoint::LINE
);
238 type_list
->SetFocus();
242 virtual bool OnCommand(unsigned id
, unsigned code
) override
{
249 return SingleWindow::OnCommand(id
, code
);
252 /* virtual methods from ListItemRenderer */
253 virtual void OnPaintItem(Canvas
&canvas
, const PixelRect rc
,
254 unsigned idx
) override
{
255 canvas
.DrawText(rc
.left
+ 2, rc
.top
+ 2, oz_type_names
[idx
]);
258 /* virtual methods from ListCursorHandler */
259 virtual void OnCursorMoved(unsigned idx
) override
{
260 assert(idx
< NUM_OZ_TYPES
);
262 oz
.set_shape((ObservationZonePoint::Shape
)idx
);
269 airspace_renderer_settings
.SetDefaults();
271 TaskLook
*task_look
= new TaskLook();
272 task_look
->Initialise();
274 AirspaceLook
*airspace_look
= new AirspaceLook();
275 airspace_look
->Initialise(airspace_renderer_settings
);
277 TestWindow
window(*task_look
, *airspace_look
);
278 window
.Create(*dialog_look
, {480, 480});
281 window
.RunEventLoop();
283 delete airspace_look
;