unknown download size, windows case

This commit is contained in:
David Rose 2009-12-09 19:14:15 +00:00
parent ff93698ce6
commit 0537384149
2 changed files with 46 additions and 6 deletions

View File

@ -39,9 +39,13 @@ P3DWinSplashWindow(P3DInstance *inst, bool make_visible) :
_bar_brush = NULL;
_thread_running = false;
_install_progress = 0.0;
_progress_known = true;
_received_data = 0;
_drawn_bstate = BS_hidden;
_drawn_progress = 0.0;
_drawn_progress_known = true;
_drawn_received_data = 0;
_focus_seq = 0;
_request_focus_tick = 0;
@ -180,6 +184,8 @@ set_install_progress(double install_progress,
bool is_progress_known, size_t received_data) {
ACQUIRE_LOCK(_install_lock);
_install_progress = install_progress;
_progress_known = is_progress_known;
_received_data = received_data;
RELEASE_LOCK(_install_lock);
if (_thread_id != 0) {
@ -361,9 +367,23 @@ thread_run() {
InvalidateRect(_hwnd, NULL, TRUE);
}
if (_drawn_progress != _install_progress) {
// Also redraw when the progress bar changes.
bool needs_update_progress = false;
if (_progress_known != _drawn_progress_known) {
needs_update_progress = true;
} else if (_progress_known) {
if (_install_progress != _drawn_progress) {
needs_update_progress = true;
}
} else {
if (_received_data != _drawn_received_data) {
needs_update_progress = true;
}
}
if (needs_update_progress) {
_drawn_progress = _install_progress;
// Also redraw when the progress bar changes.
_drawn_progress_known = _progress_known;
_drawn_received_data = _received_data;
InvalidateRect(_hwnd, NULL, TRUE);
}
@ -673,7 +693,7 @@ paint_window(HDC dc) {
// Draw the progress bar. We don't draw this bar at all unless we
// have nonzero progress.
if (_drawn_progress != 0.0) {
if (!_drawn_progress_known || _drawn_progress != 0.0) {
paint_progress_bar(bdc);
}
@ -777,9 +797,25 @@ paint_progress_bar(HDC dc) {
FillRect(dc, &bar_rect, _bg_brush);
// Draw the interior of the progress bar in blue (or the bar color).
int progress_width = (int)((bar_width - 2) * _drawn_progress + 0.5);
if (progress_width != 0) {
RECT prog_rect = { bar_x, bar_y, bar_x + progress_width, bar_y + bar_height };
if (_drawn_progress_known) {
int progress_width = (int)(bar_width * _drawn_progress + 0.5);
if (progress_width != 0) {
RECT prog_rect = { bar_x, bar_y, bar_x + progress_width, bar_y + bar_height };
FillRect(dc, &prog_rect, _bar_brush);
}
} else {
// Progress is unknown. Draw a moving block, not a progress bar
// filling up.
int block_width = (int)(bar_width * 0.1 + 0.5);
int block_travel = bar_width - block_width;
int progress = (int)(_received_data * _unknown_progress_rate);
progress = progress % (block_travel * 2);
if (progress > block_travel) {
progress = block_travel * 2 - progress;
}
RECT prog_rect = { bar_x + progress, bar_y,
bar_x + progress + block_width, bar_y + bar_height };
FillRect(dc, &prog_rect, _bar_brush);
}

View File

@ -91,11 +91,15 @@ private:
bool _got_install;
string _install_label;
double _install_progress;
bool _progress_known;
size_t _received_data;
LOCK _install_lock;
ButtonState _drawn_bstate;
string _drawn_label;
double _drawn_progress;
bool _drawn_progress_known;
size_t _drawn_received_data;
int _focus_seq;
int _request_focus_tick;