mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
make windows more consistent with mac, linux
This commit is contained in:
parent
93d5012ebe
commit
0543ab899a
@ -30,12 +30,13 @@ P3DWinSplashWindow(P3DInstance *inst) :
|
|||||||
_thread = NULL;
|
_thread = NULL;
|
||||||
_thread_id = 0;
|
_thread_id = 0;
|
||||||
_hwnd = NULL;
|
_hwnd = NULL;
|
||||||
_progress_bar = NULL;
|
_blue_brush = NULL;
|
||||||
_text_label = NULL;
|
|
||||||
_thread_running = false;
|
_thread_running = false;
|
||||||
_install_label_changed = false;
|
|
||||||
_install_progress = 0.0;
|
_install_progress = 0.0;
|
||||||
|
|
||||||
|
_drawn_bstate = BS_hidden;
|
||||||
|
_drawn_progress = 0.0;
|
||||||
|
|
||||||
INIT_LOCK(_install_lock);
|
INIT_LOCK(_install_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +128,6 @@ set_install_label(const string &install_label) {
|
|||||||
ACQUIRE_LOCK(_install_lock);
|
ACQUIRE_LOCK(_install_lock);
|
||||||
if (_install_label != install_label) {
|
if (_install_label != install_label) {
|
||||||
_install_label = install_label;
|
_install_label = install_label;
|
||||||
_install_label_changed = true;
|
|
||||||
}
|
}
|
||||||
RELEASE_LOCK(_install_lock);
|
RELEASE_LOCK(_install_lock);
|
||||||
|
|
||||||
@ -277,8 +277,6 @@ void P3DWinSplashWindow::
|
|||||||
thread_run() {
|
thread_run() {
|
||||||
make_window();
|
make_window();
|
||||||
|
|
||||||
double last_progress = -1.0;
|
|
||||||
|
|
||||||
MSG msg;
|
MSG msg;
|
||||||
int retval;
|
int retval;
|
||||||
retval = GetMessage(&msg, NULL, 0, 0);
|
retval = GetMessage(&msg, NULL, 0, 0);
|
||||||
@ -291,17 +289,23 @@ thread_run() {
|
|||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
|
|
||||||
ACQUIRE_LOCK(_install_lock);
|
ACQUIRE_LOCK(_install_lock);
|
||||||
double install_progress = _install_progress;
|
|
||||||
|
|
||||||
update_image(_background_image);
|
update_image(_background_image);
|
||||||
update_image(_button_ready_image);
|
update_image(_button_ready_image);
|
||||||
update_image(_button_rollover_image);
|
update_image(_button_rollover_image);
|
||||||
update_image(_button_click_image);
|
update_image(_button_click_image);
|
||||||
|
|
||||||
if (_install_label_changed && _progress_bar != NULL) {
|
if (_drawn_label != _install_label) {
|
||||||
update_install_label(_install_label);
|
// The label has changed. Redraw.
|
||||||
|
_drawn_label = _install_label;
|
||||||
|
InvalidateRect(_hwnd, NULL, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_drawn_progress != _install_progress) {
|
||||||
|
_drawn_progress = _install_progress;
|
||||||
|
// Also redraw when the progress bar changes.
|
||||||
|
InvalidateRect(_hwnd, NULL, TRUE);
|
||||||
}
|
}
|
||||||
_install_label_changed = false;
|
|
||||||
|
|
||||||
if (_drawn_bstate != _bstate) {
|
if (_drawn_bstate != _bstate) {
|
||||||
// The button has changed state. Redraw it.
|
// The button has changed state. Redraw it.
|
||||||
@ -310,23 +314,6 @@ thread_run() {
|
|||||||
}
|
}
|
||||||
RELEASE_LOCK(_install_lock);
|
RELEASE_LOCK(_install_lock);
|
||||||
|
|
||||||
if (install_progress != last_progress) {
|
|
||||||
int progress = (int)(install_progress * 100.0);
|
|
||||||
if (_progress_bar == NULL) {
|
|
||||||
// Is it time to create the progress bar?
|
|
||||||
if (progress != 0) {
|
|
||||||
make_progress_bar();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Update the progress bar. We do this only within the
|
|
||||||
// thread, to ensure we don't get a race condition when
|
|
||||||
// starting or closing the thread.
|
|
||||||
SendMessage(_progress_bar, PBM_SETPOS, progress, 0);
|
|
||||||
|
|
||||||
last_progress = install_progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
retval = GetMessage(&msg, NULL, 0, 0);
|
retval = GetMessage(&msg, NULL, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,47 +392,12 @@ make_window() {
|
|||||||
}
|
}
|
||||||
SetWindowLongPtr(_hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
SetWindowLongPtr(_hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||||
ShowWindow(_hwnd, SW_SHOWNORMAL);
|
ShowWindow(_hwnd, SW_SHOWNORMAL);
|
||||||
|
|
||||||
|
_blue_brush = CreateSolidBrush(RGB(108, 165, 224));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
/*
|
||||||
// Function: P3DWinSplashWindow::make_progress_bar
|
|
||||||
// Access: Private
|
|
||||||
// Description: Creates the progress bar and label. Runs
|
|
||||||
// within the sub-thread. This is done a few seconds
|
|
||||||
// after the main window is created, to give us a chance
|
|
||||||
// to launch quickly without bothering the user.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
void P3DWinSplashWindow::
|
|
||||||
make_progress_bar() {
|
|
||||||
if (_progress_bar != NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ACQUIRE_LOCK(_install_lock);
|
|
||||||
string install_label = _install_label;
|
|
||||||
double install_progress = _install_progress;
|
|
||||||
_install_label_changed = false;
|
|
||||||
RELEASE_LOCK(_install_lock);
|
|
||||||
|
|
||||||
HINSTANCE application = GetModuleHandle(NULL);
|
|
||||||
DWORD window_style =
|
|
||||||
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
|
||||||
|
|
||||||
int bar_x, bar_y, bar_width, bar_height;
|
|
||||||
get_bar_placement(bar_x, bar_y, bar_width, bar_height);
|
|
||||||
|
|
||||||
_progress_bar =
|
|
||||||
CreateWindowEx(0, PROGRESS_CLASS, "", window_style,
|
|
||||||
bar_x, bar_y, bar_width, bar_height,
|
|
||||||
_hwnd, NULL, application, 0);
|
|
||||||
SendMessage(_progress_bar, PBM_SETPOS, (int)(install_progress * 100.0), 0);
|
|
||||||
ShowWindow(_progress_bar, SW_SHOWNORMAL);
|
|
||||||
|
|
||||||
update_install_label(install_label);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DWinSplashWindow::update_install_label
|
// Function: P3DWinSplashWindow::update_install_label
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -494,6 +446,7 @@ update_install_label(const string &install_label) {
|
|||||||
_hwnd, NULL, application, 0);
|
_hwnd, NULL, application, 0);
|
||||||
ShowWindow(_text_label, SW_SHOWNORMAL);
|
ShowWindow(_text_label, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DWinSplashWindow::update_image
|
// Function: P3DWinSplashWindow::update_image
|
||||||
@ -616,6 +569,11 @@ close_window() {
|
|||||||
_hwnd = NULL;
|
_hwnd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_blue_brush != NULL) {
|
||||||
|
DeleteObject(_blue_brush);
|
||||||
|
_blue_brush = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
_background_image.dump_image();
|
_background_image.dump_image();
|
||||||
_button_ready_image.dump_image();
|
_button_ready_image.dump_image();
|
||||||
_button_rollover_image.dump_image();
|
_button_rollover_image.dump_image();
|
||||||
@ -647,7 +605,7 @@ paint_window(HDC dc) {
|
|||||||
SelectObject(bdc, buffer);
|
SelectObject(bdc, buffer);
|
||||||
|
|
||||||
// Start by painting the background color.
|
// Start by painting the background color.
|
||||||
FillRect(bdc, &rect, WHITE_BRUSH);
|
FillRect(bdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
||||||
|
|
||||||
// Then paint the background image on top of that.
|
// Then paint the background image on top of that.
|
||||||
paint_image(bdc, _background_image);
|
paint_image(bdc, _background_image);
|
||||||
@ -671,6 +629,12 @@ paint_window(HDC dc) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the progress bar. We don't draw this bar at all unless we
|
||||||
|
// have nonzero progress.
|
||||||
|
if (_drawn_progress != 0.0) {
|
||||||
|
paint_progress_bar(bdc);
|
||||||
|
}
|
||||||
|
|
||||||
// Now blit the buffer to the window.
|
// Now blit the buffer to the window.
|
||||||
BitBlt(dc, 0, 0, _win_width, _win_height, bdc, 0, 0, SRCCOPY);
|
BitBlt(dc, 0, 0, _win_width, _win_height, bdc, 0, 0, SRCCOPY);
|
||||||
|
|
||||||
@ -738,6 +702,60 @@ paint_image(HDC dc, const WinImageData &image) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: P3DWinSplashWindow::paint_progress_bar
|
||||||
|
// Access: Private
|
||||||
|
// Description: Draws the progress bar and the label within the
|
||||||
|
// window.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void P3DWinSplashWindow::
|
||||||
|
paint_progress_bar(HDC dc) {
|
||||||
|
int bar_x, bar_y, bar_width, bar_height;
|
||||||
|
get_bar_placement(bar_x, bar_y, bar_width, bar_height);
|
||||||
|
|
||||||
|
RECT bar_rect = { bar_x, bar_y, bar_x + bar_width, bar_y + bar_height };
|
||||||
|
|
||||||
|
// Clear the entire progress bar to white.
|
||||||
|
FillRect(dc, &bar_rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
||||||
|
|
||||||
|
// Draw the interior of the progress bar in blue.
|
||||||
|
int progress_width = (int)((bar_width - 2) * _drawn_progress);
|
||||||
|
if (progress_width != 0) {
|
||||||
|
RECT prog_rect = { bar_x, bar_y, bar_x + progress_width, bar_y + bar_height };
|
||||||
|
FillRect(dc, &prog_rect, _blue_brush);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now draw a black border around the progress bar.
|
||||||
|
FrameRect(dc, &bar_rect, (HBRUSH)GetStockObject(BLACK_BRUSH));
|
||||||
|
|
||||||
|
if (!_drawn_label.empty()) {
|
||||||
|
// Now draw the install_label right above it.
|
||||||
|
|
||||||
|
const char *text = _drawn_label.c_str();
|
||||||
|
HFONT font = (HFONT)GetStockObject(ANSI_VAR_FONT);
|
||||||
|
|
||||||
|
// Measure the text, for centering.
|
||||||
|
SelectObject(dc, font);
|
||||||
|
SIZE text_size;
|
||||||
|
GetTextExtentPoint32(dc, text, strlen(text), &text_size);
|
||||||
|
|
||||||
|
int text_width = text_size.cx;
|
||||||
|
int text_height = text_size.cy;
|
||||||
|
int text_x = (_win_width - text_width) / 2;
|
||||||
|
int text_y = bar_y - (int)(text_height * 1.5);
|
||||||
|
|
||||||
|
// Clear the rectangle behind the text to white.
|
||||||
|
RECT text_rect = { text_x - 2, text_y - 2, text_x + text_width + 4, text_y + text_height + 4 };
|
||||||
|
|
||||||
|
FillRect(dc, &text_rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
||||||
|
|
||||||
|
// And finally, draw the text.
|
||||||
|
SetBkColor(dc, 0x00ffffff);
|
||||||
|
DrawText(dc, text, -1, &text_rect,
|
||||||
|
DT_VCENTER | DT_CENTER | DT_SINGLELINE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: P3DWinSplashWindow::window_proc
|
// Function: P3DWinSplashWindow::window_proc
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -766,6 +784,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
/*
|
||||||
case WM_DRAWITEM:
|
case WM_DRAWITEM:
|
||||||
// Draw a text label placed within the window.
|
// Draw a text label placed within the window.
|
||||||
{
|
{
|
||||||
@ -784,6 +803,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
|||||||
DT_VCENTER | DT_CENTER | DT_SINGLELINE);
|
DT_VCENTER | DT_CENTER | DT_SINGLELINE);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
*/
|
||||||
|
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
set_mouse_data(LOWORD(lparam), HIWORD(lparam), _mouse_down);
|
set_mouse_data(LOWORD(lparam), HIWORD(lparam), _mouse_down);
|
||||||
|
@ -58,13 +58,12 @@ private:
|
|||||||
static DWORD WINAPI win_thread_run(LPVOID data);
|
static DWORD WINAPI win_thread_run(LPVOID data);
|
||||||
|
|
||||||
void make_window();
|
void make_window();
|
||||||
void make_progress_bar();
|
|
||||||
void update_install_label(const string &install_label);
|
|
||||||
void update_image(WinImageData &image);
|
void update_image(WinImageData &image);
|
||||||
void close_window();
|
void close_window();
|
||||||
|
|
||||||
void paint_window(HDC dc);
|
void paint_window(HDC dc);
|
||||||
bool paint_image(HDC dc, const WinImageData &image);
|
bool paint_image(HDC dc, const WinImageData &image);
|
||||||
|
void paint_progress_bar(HDC dc);
|
||||||
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
||||||
static LONG WINAPI st_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
static LONG WINAPI st_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
||||||
|
|
||||||
@ -86,20 +85,20 @@ private:
|
|||||||
WinImageData _button_click_image;
|
WinImageData _button_click_image;
|
||||||
|
|
||||||
bool _got_install;
|
bool _got_install;
|
||||||
bool _install_label_changed;
|
|
||||||
string _install_label;
|
string _install_label;
|
||||||
double _install_progress;
|
double _install_progress;
|
||||||
ButtonState _drawn_bstate;
|
|
||||||
LOCK _install_lock;
|
LOCK _install_lock;
|
||||||
|
|
||||||
|
ButtonState _drawn_bstate;
|
||||||
|
string _drawn_label;
|
||||||
|
double _drawn_progress;
|
||||||
|
|
||||||
bool _thread_continue;
|
bool _thread_continue;
|
||||||
bool _thread_running;
|
bool _thread_running;
|
||||||
HANDLE _thread;
|
HANDLE _thread;
|
||||||
DWORD _thread_id;
|
DWORD _thread_id;
|
||||||
HWND _hwnd;
|
HWND _hwnd;
|
||||||
|
HBRUSH _blue_brush;
|
||||||
HWND _progress_bar;
|
|
||||||
HWND _text_label;
|
|
||||||
|
|
||||||
static bool _registered_window_class;
|
static bool _registered_window_class;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user