TaskManager: remove GetStartState() and GetFinishState()
[xcsoar.git] / test / src / RunRenderOZ.cpp
blob42c51964e4b8371e395ff32690b1382dc8419b27
1 /*
2 Copyright_License {
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
32 #include "Main.hpp"
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"
53 enum {
54 NUM_OZ_TYPES = 10,
57 static const TCHAR *const oz_type_names[NUM_OZ_TYPES] = {
58 _T("Line"),
59 _T("Cylinder"),
60 _T("MAT Cylinder"),
61 _T("Sector"),
62 _T("FAI Sector"),
63 _T("Keyhole"),
64 _T("BGA Fixed Course"),
65 _T("BGA Enhanced Option"),
66 _T("BGA Start"),
67 _T("Annular sector"),
70 static GeoPoint location(Angle::Degrees(7.7061111111111114),
71 Angle::Degrees(51.051944444444445));
73 static GeoPoint previous(Angle::Degrees(10.6),
74 Angle::Degrees(49));
76 static GeoPoint next(Angle::Degrees(10.2),
77 Angle::Degrees(51.4));
79 static AirspaceRendererSettings airspace_renderer_settings;
81 class OZWindow : public PaintWindow {
82 OZRenderer roz;
83 ObservationZonePoint *oz;
84 Projection projection;
86 public:
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);
93 ~OZWindow() {
94 delete oz;
97 void set_shape(ObservationZonePoint::Shape shape) {
98 if (oz != NULL && shape == oz->GetShape())
99 return;
101 delete oz;
102 oz = NULL;
104 fixed radius(10000);
106 switch (shape) {
107 case ObservationZonePoint::LINE:
108 oz = new LineSectorZone(location, 2 * radius);
109 break;
111 case ObservationZonePoint::CYLINDER:
112 oz = new CylinderZone(location, radius);
113 break;
115 case ObservationZonePoint::MAT_CYLINDER:
116 oz = new MatCylinderZone(location);
117 break;
119 case ObservationZonePoint::SECTOR:
120 oz = new SectorZone(location, radius,
121 Angle::Degrees(0), Angle::Degrees(70));
122 break;
124 case ObservationZonePoint::ANNULAR_SECTOR:
125 oz = new AnnularSectorZone(location, radius,
126 Angle::Degrees(0), Angle::Degrees(70),
127 Half(radius));
128 break;
130 case ObservationZonePoint::FAI_SECTOR:
131 oz = new FAISectorZone(location);
132 break;
134 case ObservationZonePoint::KEYHOLE:
135 oz = new KeyholeZone(location);
136 break;
138 case ObservationZonePoint::BGAFIXEDCOURSE:
139 oz = new BGAFixedCourseZone(location);
140 break;
142 case ObservationZonePoint::BGAENHANCEDOPTION:
143 oz = new BGAEnhancedOptionZone(location);
144 break;
146 case ObservationZonePoint::BGA_START:
147 oz = new BGAStartSectorZone(location);
148 break;
151 if (oz != NULL)
152 oz->SetLegs(&previous, &next);
154 if (IsDefined())
155 Invalidate();
158 protected:
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);
168 void
169 OZWindow::OnPaint(Canvas &canvas)
171 canvas.ClearWhite();
172 if (oz == NULL)
173 return;
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);
183 canvas.Select(pen);
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;
196 OZWindow oz;
198 enum {
199 ID_START = 100,
200 ID_CLOSE
203 public:
204 TestWindow(const TaskLook &task_look, const AirspaceLook &airspace_look)
205 :type_list(NULL), oz(task_look, airspace_look) {}
206 ~TestWindow() {
207 delete type_list;
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,
225 with_border, 25);
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();
241 protected:
242 virtual bool OnCommand(unsigned id, unsigned code) override {
243 switch (id) {
244 case ID_CLOSE:
245 Close();
246 return true;
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);
266 static void
267 Main()
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});
280 window.Show();
281 window.RunEventLoop();
283 delete airspace_look;
284 delete task_look;