CirclingWind: eliminate attributes min_vector, max_vector
[xcsoar.git] / src / ProgressWindow.cpp
blobdb4a29fedee3d27848f07819c82b288348caa3f6
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.
24 #include "ProgressWindow.hpp"
25 #include "Screen/VirtualCanvas.hpp"
26 #include "resource.h"
28 ProgressWindow::ProgressWindow(ContainerWindow &parent)
29 :background_color(COLOR_WHITE),
30 background_brush(background_color),
31 position(0)
33 PixelRect rc = parent.GetClientRect();
34 WindowStyle style;
35 style.Hide();
36 Create(parent, rc, style);
38 UPixelScalar width = rc.right - rc.left, height = rc.bottom - rc.top;
40 // Load progress bar background
41 bitmap_progress_border.Load(IDB_PROGRESSBORDER);
43 // Determine text height
44 #ifndef USE_GDI
45 font.Load(_T("Droid Sans"), 12);
46 text_height = font.GetHeight();
47 #else
48 VirtualCanvas canvas({1, 1});
49 text_height = canvas.GetFontHeight();
50 #endif
52 // Make progress bar height proportional to window height
53 UPixelScalar progress_height = height / 20;
54 UPixelScalar progress_horizontal_border = progress_height / 2;
55 progress_border_height = progress_height * 2;
57 // Initialize message text field
58 PixelRect message_rc = rc;
59 message_rc.bottom -= progress_border_height + height / 48;
60 message_rc.top = message_rc.bottom - text_height;
61 TextWindowStyle message_style;
62 message_style.center();
63 message.Create(*this, NULL, message_rc, message_style);
65 #ifndef USE_GDI
66 message.SetFont(font);
67 #endif
69 // Initialize progress bar
70 PixelRect pb_rc;
71 pb_rc.left = progress_horizontal_border;
72 pb_rc.right = pb_rc.left + width - progress_height;
73 pb_rc.top = height - progress_border_height + progress_horizontal_border;
74 pb_rc.bottom = pb_rc.top + progress_height;
75 ProgressBarStyle pb_style;
76 progress_bar.Create(*this, pb_rc, pb_style);
78 message.InstallWndProc(); // needed for OnChildColor()
80 // Set progress bar step size and range
81 SetRange(0, 1000);
82 SetStep(50);
84 // Show dialog
85 ShowOnTop();
88 void
89 ProgressWindow::SetMessage(const TCHAR *text)
91 AssertNoneLocked();
92 AssertThread();
94 message.set_text(text);
97 void
98 ProgressWindow::SetRange(unsigned min_value, unsigned max_value)
100 progress_bar.SetRange(min_value, max_value);
103 void
104 ProgressWindow::SetStep(unsigned size)
106 progress_bar.SetStep(size);
109 void
110 ProgressWindow::SetValue(unsigned value)
112 AssertNoneLocked();
113 AssertThread();
115 if (value == position)
116 return;
118 position = value;
119 progress_bar.SetValue(value);
122 void
123 ProgressWindow::Step()
125 progress_bar.Step();
128 void
129 ProgressWindow::OnResize(PixelSize new_size)
131 ContainerWindow::OnResize(new_size);
133 // Make progress bar height proportional to window height
134 UPixelScalar progress_height = new_size.cy / 20;
135 UPixelScalar progress_horizontal_border = progress_height / 2;
136 progress_border_height = progress_height * 2;
138 if (message.IsDefined())
139 message.Move(0,
140 new_size.cy - progress_border_height - text_height - (new_size.cy / 48),
141 new_size.cx, text_height);
143 if (progress_bar.IsDefined())
144 progress_bar.Move(progress_horizontal_border,
145 new_size.cy - progress_border_height + progress_horizontal_border,
146 new_size.cx - progress_height,
147 progress_height);
149 Invalidate();
152 void
153 ProgressWindow::OnPaint(Canvas &canvas)
155 canvas.Clear(background_color);
157 // Determine window size
158 const UPixelScalar window_width = canvas.GetWidth();
159 const UPixelScalar window_height = canvas.GetHeight();
161 PixelRect logo_rect;
162 logo_rect.left = 0;
163 logo_rect.top = 0;
164 logo_rect.right = window_width;
165 logo_rect.bottom = window_height - progress_border_height;
166 logo.draw(canvas, logo_rect);
168 // Draw progress bar background
169 canvas.Stretch(0, (window_height - progress_border_height),
170 window_width, progress_border_height,
171 bitmap_progress_border);
173 ContainerWindow::OnPaint(canvas);
176 #ifdef USE_GDI
178 const Brush *
179 ProgressWindow::OnChildColor(Window &window, Canvas &canvas)
181 canvas.SetTextColor(COLOR_BLACK);
182 canvas.SetBackgroundColor(background_color);
183 return &background_brush;
186 #endif