show current stage in loadingscren.
This commit is contained in:
parent
e6c58dcc1a
commit
53e527acc7
3 changed files with 39 additions and 21 deletions
|
@ -102,8 +102,10 @@
|
|||
border_size = 5
|
||||
horizontal_alignment = "center"
|
||||
vertical_alignment = "center"
|
||||
horizontal_grow = "true"
|
||||
|
||||
[label]
|
||||
text_alignment = "center"
|
||||
definition = "default_large"
|
||||
id = "status"
|
||||
label = _ "Loading..."
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "gui/widgets/window.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/core/timer.hpp"
|
||||
#include "gui/auxiliary/find_widget.hpp"
|
||||
|
||||
#include "video.hpp"
|
||||
#include "cursor.hpp"
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -34,8 +36,10 @@ tloadscreen::tloadscreen(boost::function<void()> f)
|
|||
, work_(f)
|
||||
, worker_()
|
||||
, cursor_setter_()
|
||||
, current_stage(NULL)
|
||||
, current_stage_(NULL)
|
||||
, current_visible_stage_(NULL)
|
||||
{
|
||||
current_load = this;
|
||||
}
|
||||
void tloadscreen::show(CVideo& video)
|
||||
{
|
||||
|
@ -73,6 +77,7 @@ void tloadscreen::pre_show(twindow& window)
|
|||
worker_.reset(new boost::thread(work_));
|
||||
timer_id_ = add_timer(100, boost::bind(&tloadscreen::timer_callback, this, boost::ref(window)), true);
|
||||
cursor_setter_.reset(new cursor::setter(cursor::WAIT));
|
||||
progress_stage_label_ = &find_widget<tlabel>(&window, "status", false);
|
||||
}
|
||||
|
||||
void tloadscreen::post_show(twindow& /*window*/)
|
||||
|
@ -89,10 +94,8 @@ void tloadscreen::progress(const char* stage)
|
|||
}
|
||||
// Currently this is a no-op stub
|
||||
if(stage) {
|
||||
// TODO: Update displayed stage
|
||||
current_load->current_stage = stage;
|
||||
current_load->current_stage_ = stage;
|
||||
}
|
||||
// TODO: Indicate progress somehow
|
||||
}
|
||||
|
||||
tloadscreen* tloadscreen::current_load = NULL;
|
||||
|
@ -101,8 +104,29 @@ void tloadscreen::timer_callback(twindow& window)
|
|||
{
|
||||
if (!worker_ || worker_->timed_join(boost::posix_time::milliseconds(0))) {
|
||||
window.close();
|
||||
}
|
||||
if (current_stage_ != current_visible_stage_)
|
||||
{
|
||||
current_visible_stage_ = current_stage_;
|
||||
progress_stage_label_->set_label(current_visible_stage_);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
tloadscreen::~tloadscreen()
|
||||
{
|
||||
close();
|
||||
current_load = NULL;
|
||||
}
|
||||
|
||||
void tloadscreen::display(CVideo& video, boost::function<void()> f)
|
||||
{
|
||||
if (current_load || video.faked()) {
|
||||
f();
|
||||
}
|
||||
else {
|
||||
tloadscreen(f).show(video);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "gui/widgets/label.hpp"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
@ -38,22 +39,10 @@ public:
|
|||
|
||||
tloadscreen(boost::function<void()> f);
|
||||
|
||||
~tloadscreen()
|
||||
{
|
||||
close();
|
||||
}
|
||||
~tloadscreen();
|
||||
|
||||
static void display(CVideo& video, boost::function<void()> f) {
|
||||
static bool already_shown = false;
|
||||
if (already_shown) {
|
||||
f();
|
||||
}
|
||||
else {
|
||||
already_shown = true;
|
||||
tloadscreen(f).show(video);
|
||||
already_shown = false;
|
||||
}
|
||||
}
|
||||
static void display(CVideo& video, boost::function<void()> f);
|
||||
static bool displaying() { return current_load != NULL; }
|
||||
|
||||
void show(CVideo& video);
|
||||
|
||||
|
@ -66,7 +55,6 @@ public:
|
|||
* when the window is not shown.
|
||||
*/
|
||||
void close();
|
||||
|
||||
private:
|
||||
twindow* window_;
|
||||
size_t timer_id_;
|
||||
|
@ -86,8 +74,12 @@ private:
|
|||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
|
||||
tlabel* progress_stage_label_;
|
||||
static tloadscreen* current_load;
|
||||
const char* current_stage;
|
||||
|
||||
//Note we cannot use std::strings here unless we we explicitly use mutexes.
|
||||
const char* current_stage_;
|
||||
const char* current_visible_stage_;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
|
Loading…
Add table
Reference in a new issue