Improvements to the X11 splash window: now shows a nice progress bar.

This commit is contained in:
rdb 2009-07-09 15:55:43 +00:00
parent 460ea92667
commit e7ebf32905
2 changed files with 38 additions and 25 deletions

View File

@ -18,10 +18,10 @@
#include <time.h> #include <time.h>
// Sleeps for a millisecond. // Sleeps for a short time.
#define MILLISLEEP() \ #define MILLISLEEP() \
timespec ts; \ timespec ts; \
ts.tv_sec = 0; ts.tv_nsec = 1000000; \ ts.tv_sec = 0; ts.tv_nsec = 100000; \
nanosleep(&ts, NULL); nanosleep(&ts, NULL);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -37,6 +37,8 @@ P3DX11SplashWindow(P3DInstance *inst) :
_display = None; _display = None;
_window = None; _window = None;
_screen = 0; _screen = 0;
_width = 0;
_height = 0;
_graphics_context = None; _graphics_context = None;
_thread_running = false; _thread_running = false;
_got_install = false; _got_install = false;
@ -178,20 +180,28 @@ thread_run() {
bool override = true, have_event = false; bool override = true, have_event = false;
string prev_label; string prev_label;
double prev_progress;
while (_thread_continue) { while (_thread_continue) {
have_event = XCheckTypedWindowEvent(_display, _window, Expose, &event); have_event = XCheckTypedWindowEvent(_display, _window, Expose, &event)
|| XCheckTypedWindowEvent(_display, _window, GraphicsExpose, &event);
ACQUIRE_LOCK(_install_lock); ACQUIRE_LOCK(_install_lock);
double install_progress = _install_progress; double install_progress = _install_progress;
if (have_event || _install_label != prev_label) { if (have_event || _install_label != prev_label) {
redraw(_install_label, install_progress); redraw(_install_label);
override = false; override = false;
} }
if (_install_progress != prev_progress) {
XFillRectangle(_display, _window, _graphics_context, 12, _height - 18,
install_progress * (_width - 24), 7);
}
prev_label = _install_label; prev_label = _install_label;
RELEASE_LOCK(_install_lock); RELEASE_LOCK(_install_lock);
prev_progress = install_progress;
MILLISLEEP();
} }
close_window(); close_window();
@ -204,11 +214,13 @@ thread_run() {
// Description: Redraws the window. // Description: Redraws the window.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DX11SplashWindow:: void P3DX11SplashWindow::
redraw(string label, double progress) { redraw(string label) {
if (_graphics_context == NULL) return; if (_graphics_context == NULL) return;
XClearWindow(_display, _window); XClearWindow(_display, _window);
XDrawString(_display, _window, _graphics_context, 10, 20, label.c_str(), label.size()); XDrawString(_display, _window, _graphics_context, _width / 2 - label.size() * 3,
_height - 30, label.c_str(), label.size());
XDrawRectangle(_display, _window, _graphics_context, 10, _height - 20, _width - 20, 10);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -219,27 +231,29 @@ redraw(string label, double progress) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void P3DX11SplashWindow:: void P3DX11SplashWindow::
make_window() { make_window() {
int x = 0; int x = _wparams.get_win_x();
int y = 0; int y = _wparams.get_win_y();
if (_wparams.get_win_x() != 0 && _wparams.get_win_y() != 0) {
x = _wparams.get_win_x();
y = _wparams.get_win_y();
}
int width = 320; _width = 320;
int height = 240; _height = 240;
if (_wparams.get_win_width() != 0 && _wparams.get_win_height() != 0) { if (_wparams.get_win_width() != 0 && _wparams.get_win_height() != 0) {
width = _wparams.get_win_width(); _width = _wparams.get_win_width();
height = _wparams.get_win_height(); _height = _wparams.get_win_height();
} }
Window parent = 0; Window parent = 0;
_display = (Display*) _wparams.get_parent_window()._xdisplay;
_own_display = false; // Hum, if we use the display provided by the browser,
if (_display == 0) { // it causes a crash in some browsers when you make an Xlib
// call with the plugin window minimized.
// So I kept XOpenDisplay until we have a better workaround.
//_display = (Display*) _wparams.get_parent_window()._xdisplay;
//_own_display = false;
//if (_display == 0) {
_display = XOpenDisplay(NULL); _display = XOpenDisplay(NULL);
_own_display = true; _own_display = true;
} //}
_screen = DefaultScreen(_display); _screen = DefaultScreen(_display);
if (_wparams.get_window_type() == P3D_WT_embedded) { if (_wparams.get_window_type() == P3D_WT_embedded) {
@ -252,11 +266,10 @@ make_window() {
assert(_display != NULL); assert(_display != NULL);
assert(parent != None); assert(parent != None);
_window = XCreateSimpleWindow(_display, parent, x, y, width, height, 0, 0, -1); _window = XCreateSimpleWindow(_display, parent, x, y, _width, _height, 0, 0, -1);
XMapWindow(_display, _window); XMapWindow(_display, _window);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: P3DX11SplashWindow::setup_gc // Function: P3DX11SplashWindow::setup_gc
// Access: Private // Access: Private
@ -274,7 +287,6 @@ setup_gc() {
_install_label_changed = false; _install_label_changed = false;
RELEASE_LOCK(_install_lock); RELEASE_LOCK(_install_lock);
XFontStruct* fs = XLoadQueryFont(_display, "6x13"); XFontStruct* fs = XLoadQueryFont(_display, "6x13");
XGCValues gcval; XGCValues gcval;
gcval.font = fs->fid; gcval.font = fs->fid;

View File

@ -49,12 +49,14 @@ private:
void thread_run(); void thread_run();
THREAD_CALLBACK_DECLARATION(P3DX11SplashWindow, thread_run); THREAD_CALLBACK_DECLARATION(P3DX11SplashWindow, thread_run);
void redraw(string label, double progress); void redraw(string label);
void make_window(); void make_window();
void setup_gc(); void setup_gc();
void close_window(); void close_window();
private: private:
int _width, _height;
bool _own_display; bool _own_display;
bool _got_install; bool _got_install;
bool _image_filename_changed; bool _image_filename_changed;
@ -75,7 +77,6 @@ private:
THREAD _thread; THREAD _thread;
Window _window; Window _window;
int _bitmap_width, _bitmap_height;
}; };
#endif // HAVE_X11 #endif // HAVE_X11