mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-04 13:59:46 +00:00
Replace StatusBar progress bars with a slider/progress bar in ui::Alert
This commit is contained in:
parent
7a3c0a1eed
commit
c571eafdd0
@ -16,7 +16,6 @@
|
||||
#include "app/modules/editors.h"
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/ui/editor/editor.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "base/thread.h"
|
||||
@ -64,7 +63,6 @@ private:
|
||||
bool m_cancelled; // Was the effect cancelled by the user?
|
||||
bool m_abort; // An exception was thrown
|
||||
ui::Timer m_timer; // Monitoring timer to update the progress-bar
|
||||
Progress* m_progressBar; // The progress-bar.
|
||||
AlertPtr m_alertWindow; // Alert for the user to cancel the filter-progress if he wants.
|
||||
std::string m_error;
|
||||
};
|
||||
@ -80,10 +78,9 @@ FilterWorker::FilterWorker(FilterManagerImpl* filterMgr)
|
||||
m_cancelled = false;
|
||||
m_abort = false;
|
||||
|
||||
m_progressBar = StatusBar::instance()->addProgress();
|
||||
|
||||
m_alertWindow = ui::Alert::create(PACKAGE
|
||||
"<<Applying effect...||&Cancel");
|
||||
m_alertWindow->addProgress();
|
||||
|
||||
m_timer.Tick.connect(&FilterWorker::onMonitoringTick, this);
|
||||
m_timer.start();
|
||||
@ -93,8 +90,6 @@ FilterWorker::~FilterWorker()
|
||||
{
|
||||
if (m_alertWindow)
|
||||
m_alertWindow->closeWindow(NULL);
|
||||
|
||||
delete m_progressBar;
|
||||
}
|
||||
|
||||
void FilterWorker::run()
|
||||
@ -173,8 +168,8 @@ void FilterWorker::onMonitoringTick()
|
||||
{
|
||||
scoped_lock lock(m_mutex);
|
||||
|
||||
if (m_progressBar)
|
||||
m_progressBar->setPos(m_pos);
|
||||
if (m_alertWindow)
|
||||
m_alertWindow->setProgress(m_pos);
|
||||
|
||||
if (m_done || m_abort)
|
||||
m_alertWindow->closeWindow(NULL);
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "app/job.h"
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/scoped_lock.h"
|
||||
#include "base/thread.h"
|
||||
@ -28,7 +27,6 @@ Job::Job(const char* jobName)
|
||||
{
|
||||
m_mutex = NULL;
|
||||
m_thread = NULL;
|
||||
m_progress = NULL;
|
||||
m_last_progress = 0.0;
|
||||
m_done_flag = false;
|
||||
m_canceled_flag = false;
|
||||
@ -36,8 +34,8 @@ Job::Job(const char* jobName)
|
||||
m_mutex = new base::mutex();
|
||||
|
||||
if (App::instance()->isGui()) {
|
||||
m_progress = StatusBar::instance()->addProgress();
|
||||
m_alert_window = ui::Alert::create("%s<<Working...||&Cancel", jobName);
|
||||
m_alert_window->addProgress();
|
||||
|
||||
m_timer.reset(new ui::Timer(kMonitoringPeriod, m_alert_window.get()));
|
||||
m_timer->Tick.connect(&Job::onMonitoringTick, this);
|
||||
@ -53,9 +51,6 @@ Job::~Job()
|
||||
|
||||
if (m_alert_window)
|
||||
m_alert_window->closeWindow(NULL);
|
||||
|
||||
if (m_progress)
|
||||
delete m_progress;
|
||||
}
|
||||
|
||||
if (m_mutex)
|
||||
@ -107,7 +102,7 @@ void Job::onMonitoringTick()
|
||||
base::scoped_lock hold(*m_mutex);
|
||||
|
||||
// update progress
|
||||
m_progress->setPos(m_last_progress);
|
||||
m_alert_window->setProgress(m_last_progress);
|
||||
|
||||
// is job done? we can close the monitor
|
||||
if (m_done_flag || m_canceled_flag) {
|
||||
|
@ -200,9 +200,6 @@ StatusBar::StatusBar()
|
||||
|
||||
StatusBar::~StatusBar()
|
||||
{
|
||||
for (Progress* bar : m_progress)
|
||||
delete bar;
|
||||
|
||||
delete m_tipwindow; // widget
|
||||
delete m_commandsBox;
|
||||
}
|
||||
@ -316,55 +313,6 @@ void StatusBar::showTool(int msecs, tools::Tool* tool)
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Progress bars stuff
|
||||
|
||||
Progress* StatusBar::addProgress()
|
||||
{
|
||||
Progress* progress = new Progress(this);
|
||||
m_progress.push_back(progress);
|
||||
invalidate();
|
||||
return progress;
|
||||
}
|
||||
|
||||
void StatusBar::removeProgress(Progress* progress)
|
||||
{
|
||||
ASSERT(progress->m_statusbar == this);
|
||||
|
||||
ProgressList::iterator it = std::find(m_progress.begin(), m_progress.end(), progress);
|
||||
ASSERT(it != m_progress.end());
|
||||
|
||||
m_progress.erase(it);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
Progress::Progress(StatusBar* statusbar)
|
||||
: m_statusbar(statusbar)
|
||||
, m_pos(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
Progress::~Progress()
|
||||
{
|
||||
if (m_statusbar) {
|
||||
m_statusbar->removeProgress(this);
|
||||
m_statusbar = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Progress::setPos(double pos)
|
||||
{
|
||||
if (m_pos != pos) {
|
||||
m_pos = pos;
|
||||
m_statusbar->invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
double Progress::getPos() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// StatusBar message handler
|
||||
|
||||
@ -453,22 +401,6 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
|
||||
|
||||
x += getFont()->textLength(getText().c_str()) + 4*guiscale();
|
||||
}
|
||||
|
||||
// Draw progress bar
|
||||
if (!m_progress.empty()) {
|
||||
int width = 64;
|
||||
int x = rc.x2() - (width+4);
|
||||
|
||||
for (ProgressList::iterator it = m_progress.begin(); it != m_progress.end(); ++it) {
|
||||
Progress* progress = *it;
|
||||
|
||||
theme->paintProgressBar(g,
|
||||
gfx::Rect(x, rc.y, width, rc.h),
|
||||
progress->getPos());
|
||||
|
||||
x -= width+4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StatusBar::updateUsingEditor(Editor* editor)
|
||||
|
@ -36,21 +36,6 @@ namespace app {
|
||||
class Tool;
|
||||
}
|
||||
|
||||
class Progress {
|
||||
friend class StatusBar;
|
||||
|
||||
public:
|
||||
~Progress();
|
||||
void setPos(double pos);
|
||||
double getPos() const;
|
||||
|
||||
private:
|
||||
Progress();
|
||||
Progress(StatusBar* statusbar);
|
||||
StatusBar* m_statusbar;
|
||||
double m_pos;
|
||||
};
|
||||
|
||||
class StatusBar : public ui::Widget {
|
||||
static StatusBar* m_instance;
|
||||
public:
|
||||
@ -68,10 +53,6 @@ namespace app {
|
||||
|
||||
void updateUsingEditor(Editor* editor);
|
||||
|
||||
// Methods to add and remove progress bars
|
||||
Progress* addProgress();
|
||||
void removeProgress(Progress* progress);
|
||||
|
||||
protected:
|
||||
void onResize(ui::ResizeEvent& ev) override;
|
||||
void onPreferredSize(ui::PreferredSizeEvent& ev) override;
|
||||
@ -85,8 +66,6 @@ namespace app {
|
||||
|
||||
enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL };
|
||||
|
||||
typedef std::vector<Progress*> ProgressList;
|
||||
|
||||
int m_timeout;
|
||||
State m_state;
|
||||
|
||||
@ -97,9 +76,6 @@ namespace app {
|
||||
Color m_color;
|
||||
int m_alpha;
|
||||
|
||||
// Progress bar
|
||||
ProgressList m_progress;
|
||||
|
||||
// Box of main commands
|
||||
ui::Widget* m_commandsBox;
|
||||
ui::Label* m_frameLabel;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
// Copyright (C) 2001-2013, 2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -40,6 +40,7 @@
|
||||
#include "ui/grid.h"
|
||||
#include "ui/label.h"
|
||||
#include "ui/separator.h"
|
||||
#include "ui/slider.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
#include <cstdarg>
|
||||
@ -49,10 +50,26 @@ namespace ui {
|
||||
|
||||
Alert::Alert()
|
||||
: Window(WithTitleBar)
|
||||
, m_progress(nullptr)
|
||||
, m_progressPlaceholder(nullptr)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void Alert::addProgress()
|
||||
{
|
||||
ASSERT(!m_progress);
|
||||
m_progress = new Slider(0, 100, 0);
|
||||
m_progressPlaceholder->addChild(m_progress);
|
||||
m_progressPlaceholder->setVisible(true);
|
||||
}
|
||||
|
||||
void Alert::setProgress(double progress)
|
||||
{
|
||||
ASSERT(m_progress);
|
||||
m_progress->setValue(int(MID(0.0, progress * 100.0, 100.0)));
|
||||
}
|
||||
|
||||
AlertPtr Alert::create(const char* format, ...)
|
||||
{
|
||||
char buf[4096]; // TODO warning buffer overflow
|
||||
@ -194,11 +211,13 @@ void Alert::processString(char* buf, std::vector<Widget*>& labels, std::vector<W
|
||||
// Pseudo separators (only to fill blank space)
|
||||
box4 = new Box(0);
|
||||
box5 = new Box(0);
|
||||
m_progressPlaceholder = new Box(0);
|
||||
|
||||
box4->setExpansive(true);
|
||||
box5->setExpansive(true);
|
||||
box4->noBorderNoChildSpacing();
|
||||
box5->noBorderNoChildSpacing();
|
||||
m_progressPlaceholder->noBorderNoChildSpacing();
|
||||
|
||||
// Setup parent <-> children relationship
|
||||
|
||||
@ -206,6 +225,7 @@ void Alert::processString(char* buf, std::vector<Widget*>& labels, std::vector<W
|
||||
|
||||
box1->addChild(box4); // Filler
|
||||
box1->addChild(box2); // Labels
|
||||
box1->addChild(m_progressPlaceholder);
|
||||
box1->addChild(box5); // Filler
|
||||
box1->addChild(grid); // Buttons
|
||||
|
||||
|
@ -13,6 +13,9 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Box;
|
||||
class Slider;
|
||||
|
||||
class Alert;
|
||||
typedef base::SharedPtr<Alert> AlertPtr;
|
||||
|
||||
@ -20,11 +23,17 @@ namespace ui {
|
||||
public:
|
||||
Alert();
|
||||
|
||||
void addProgress();
|
||||
void setProgress(double progress);
|
||||
|
||||
static AlertPtr create(const char* format, ...);
|
||||
static int show(const char* format, ...);
|
||||
|
||||
private:
|
||||
void processString(char* buf, std::vector<Widget*>& labels, std::vector<Widget*>& buttons);
|
||||
|
||||
Slider* m_progress;
|
||||
Box* m_progressPlaceholder;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
Loading…
Reference in New Issue
Block a user