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"
28 ProgressWindow::ProgressWindow(ContainerWindow
&parent
)
29 :background_color(COLOR_WHITE
),
30 background_brush(background_color
),
33 PixelRect rc
= parent
.GetClientRect();
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
45 font
.Load(_T("Droid Sans"), 12);
46 text_height
= font
.GetHeight();
48 VirtualCanvas
canvas({1, 1});
49 text_height
= canvas
.GetFontHeight();
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
);
66 message
.SetFont(font
);
69 // Initialize progress bar
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
89 ProgressWindow::SetMessage(const TCHAR
*text
)
94 message
.set_text(text
);
98 ProgressWindow::SetRange(unsigned min_value
, unsigned max_value
)
100 progress_bar
.SetRange(min_value
, max_value
);
104 ProgressWindow::SetStep(unsigned size
)
106 progress_bar
.SetStep(size
);
110 ProgressWindow::SetValue(unsigned value
)
115 if (value
== position
)
119 progress_bar
.SetValue(value
);
123 ProgressWindow::Step()
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())
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
,
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();
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
);
179 ProgressWindow::OnChildColor(Window
&window
, Canvas
&canvas
)
181 canvas
.SetTextColor(COLOR_BLACK
);
182 canvas
.SetBackgroundColor(background_color
);
183 return &background_brush
;