Status bar widget converted to C++ StatusBar class.

This commit is contained in:
David Capello 2010-03-29 00:00:25 -03:00
parent 0119922613
commit bea59d7280
25 changed files with 275 additions and 277 deletions

View File

@ -100,7 +100,7 @@ static Widget* box_toolbar = NULL; /* box where the tools bar is */
static Widget* box_statusbar = NULL; /* box where the status bar is */
static Widget* box_tabsbar = NULL; /* box where the tabs bar is */
static Widget* menubar = NULL; /* the menu bar widget */
static Widget* statusbar = NULL; /* the status bar widget */
static StatusBar* statusbar = NULL; /* the status bar widget */
static Widget* colorbar = NULL; /* the color bar widget */
static Widget* toolbar = NULL; /* the tool bar widget */
static Widget* tabsbar = NULL; /* the tabs bar widget */
@ -172,7 +172,7 @@ int App::run()
box_tabsbar = jwidget_find_name(top_window, "tabsbar");
menubar = jmenubar_new();
statusbar = statusbar_new();
statusbar = new StatusBar();
colorbar = colorbar_new(box_colorbar->getAlign());
toolbar = toolbar_new();
tabsbar = tabs_new(tabsbar_select_callback);
@ -434,15 +434,15 @@ int app_get_current_image_type()
Frame* app_get_top_window() { return top_window; }
Widget* app_get_menubar() { return menubar; }
Widget* app_get_statusbar() { return statusbar; }
StatusBar* app_get_statusbar() { return statusbar; }
Widget* app_get_colorbar() { return colorbar; }
Widget* app_get_toolbar() { return toolbar; }
Widget* app_get_tabsbar() { return tabsbar; }
void app_default_statusbar_message()
{
statusbar_set_text(app_get_statusbar(), 250,
"%s %s | %s", PACKAGE, VERSION, COPYRIGHT);
app_get_statusbar()
->setStatusText(250, "%s %s | %s", PACKAGE, VERSION, COPYRIGHT);
}
int app_get_fg_color(Sprite *sprite)

View File

@ -30,6 +30,7 @@ class LegacyModules;
class Params;
class Sprite;
class ToolBox;
class StatusBar;
class App
{
@ -68,7 +69,7 @@ int app_get_current_image_type();
Frame* app_get_top_window();
Widget* app_get_menubar();
Widget* app_get_statusbar();
StatusBar* app_get_statusbar();
Widget* app_get_colorbar();
Widget* app_get_toolbar();
Widget* app_get_tabsbar();

View File

@ -24,6 +24,7 @@
#include "app.h"
#include "core/cfg.h"
#include "modules/gui.h"
#include "widgets/statebar.h"
class AdvancedModeCommand : public Command
{

View File

@ -157,8 +157,9 @@ try_again:;
// Destroy the sprite (locking it as writer)
{
CurrentSpriteWriter sprite(context);
statusbar_set_text(app_get_statusbar(), 0, "Sprite '%s' closed.",
get_filename(sprite->filename));
app_get_statusbar()
->setStatusText(0, "Sprite '%s' closed.",
get_filename(sprite->filename));
sprite.destroy();
}
return true;

View File

@ -373,11 +373,12 @@ static bool brush_type_change_hook(JWidget widget, void *data)
jwidget_dirty((JWidget)data);
statusbar_set_text(app_get_statusbar(), 250,
"Pen shape: %s",
type == PEN_TYPE_CIRCLE ? "Circle":
type == PEN_TYPE_SQUARE ? "Square":
type == PEN_TYPE_LINE ? "Line": "Unknown");
app_get_statusbar()
->setStatusText(250,
"Pen shape: %s",
type == PEN_TYPE_CIRCLE ? "Circle":
type == PEN_TYPE_SQUARE ? "Square":
type == PEN_TYPE_LINE ? "Line": "Unknown");
return true;
}

View File

@ -71,9 +71,9 @@ void GotoPreviousLayerCommand::execute(Context* context)
update_screen_for_sprite(sprite);
current_editor->editor_update_statusbar_for_standby();
statusbar_show_tip(app_get_statusbar(), 1000,
_("Layer `%s' selected"),
sprite->layer->get_name().c_str());
app_get_statusbar()
->showTip(1000, _("Layer `%s' selected"),
sprite->layer->get_name().c_str());
}
//////////////////////////////////////////////////////////////////////
@ -119,9 +119,9 @@ void GotoNextLayerCommand::execute(Context* context)
update_screen_for_sprite(sprite);
current_editor->editor_update_statusbar_for_standby();
statusbar_show_tip(app_get_statusbar(), 1000,
_("Layer `%s' selected"),
sprite->layer->get_name().c_str());
app_get_statusbar()
->showTip(1000, _("Layer `%s' selected"),
sprite->layer->get_name().c_str());
}
//////////////////////////////////////////////////////////////////////

View File

@ -94,7 +94,7 @@ protected:
settings->getSnapToGrid() ? _("On"):
_("Off"));
statusbar_set_text(app_get_statusbar(), 250, buf);
app_get_statusbar()->setStatusText(250, buf);
}
};

View File

@ -77,10 +77,10 @@ void NewFrameCommand::execute(Context* context)
undoable.commit();
}
update_screen_for_sprite(sprite);
statusbar_show_tip(app_get_statusbar(), 1000,
_("New frame %d/%d"),
sprite->frame+1,
sprite->frames);
app_get_statusbar()
->showTip(1000, _("New frame %d/%d"),
sprite->frame+1,
sprite->frames);
}
//////////////////////////////////////////////////////////////////////

View File

@ -87,8 +87,7 @@ void NewLayerCommand::execute(Context* context)
update_screen_for_sprite(sprite);
app_get_statusbar()->dirty();
statusbar_show_tip(app_get_statusbar(), 1000,
_("Layer `%s' created"), name);
app_get_statusbar()->showTip(1000, _("Layer `%s' created"), name);
}
}

View File

@ -97,7 +97,7 @@ static void monitor_openfile_bg(void* _data)
FileOp* fop = (FileOp*)data->fop;
if (data->progress)
progress_update(data->progress, fop_get_progress(fop));
data->progress->setPos(fop_get_progress(fop));
// Is done? ...ok, now the sprite is in the main thread only...
if (fop_is_done(fop))
@ -165,7 +165,7 @@ void OpenFileCommand::execute(Context* context)
OpenFileData* data = new OpenFileData;
data->fop = fop;
data->progress = progress_new(app_get_statusbar());
data->progress = app_get_statusbar()->addProgress();
data->thread = thread;
data->alert_window = jalert_new(PACKAGE
"<<Loading file:<<%s||&Cancel",
@ -203,7 +203,7 @@ void OpenFileCommand::execute(Context* context)
unrecent = true;
}
progress_free(data->progress);
delete data->progress;
jwidget_free(data->alert_window);
fop_free(fop);
delete data;

View File

@ -109,7 +109,7 @@ void PreviewCommand::preview_sprite(Context* context, int flags)
bmp = create_bitmap(sprite->w, sprite->h);
if (bmp) {
/* print a informative text */
statusbar_set_text(app_get_statusbar(), 1, _("Rendering..."));
app_get_statusbar()->setStatusText(1, _("Rendering..."));
jwidget_flush_redraw(app_get_statusbar());
jmanager_dispatch_messages(ji_get_default_manager());

View File

@ -56,9 +56,9 @@ void RedoCommand::execute(Context* context)
{
CurrentSpriteWriter sprite(context);
statusbar_show_tip(app_get_statusbar(), 1000,
_("Redid %s"),
undo_get_next_redo_label(sprite->undo));
app_get_statusbar()
->showTip(1000, _("Redid %s"),
undo_get_next_redo_label(sprite->undo));
undo_do_redo(sprite->undo);
sprite_generate_mask_boundaries(sprite);

View File

@ -68,11 +68,12 @@ void RefreshCommand::execute(Context* context)
{
PROCESS_MEMORY_COUNTERS pmc;
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
statusbar_show_tip(app_get_statusbar(), 1000,
"Current memory: %.16g KB (%lu)\n"
"Peak of memory: %.16g KB (%lu)",
pmc.WorkingSetSize / 1024.0, pmc.WorkingSetSize,
pmc.PeakWorkingSetSize / 1024.0, pmc.PeakWorkingSetSize);
app_get_statusbar()
->showTip(1000,
"Current memory: %.16g KB (%lu)\n"
"Peak of memory: %.16g KB (%lu)",
pmc.WorkingSetSize / 1024.0, pmc.WorkingSetSize,
pmc.PeakWorkingSetSize / 1024.0, pmc.PeakWorkingSetSize);
}
}
#endif

View File

@ -74,9 +74,9 @@ void RemoveLayerCommand::execute(Context* context)
update_screen_for_sprite(sprite);
app_get_statusbar()->dirty();
statusbar_show_tip(app_get_statusbar(), 1000,
_("Layer `%s' removed"),
layer_name.c_str());
app_get_statusbar()
->showTip(1000, _("Layer `%s' removed"),
layer_name.c_str());
}
//////////////////////////////////////////////////////////////////////

View File

@ -71,7 +71,7 @@ static void monitor_savefile_bg(void *_data)
FileOp *fop = (FileOp *)data->fop;
if (data->progress)
progress_update(data->progress, fop_get_progress(fop));
data->progress->setPos(fop_get_progress(fop));
if (fop_is_done(fop))
remove_gui_monitor(data->monitor);
@ -101,7 +101,7 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved)
SaveFileData* data = new SaveFileData;
data->fop = fop;
data->progress = progress_new(app_get_statusbar());
data->progress = app_get_statusbar()->addProgress();
data->thread = thread;
data->alert_window = jalert_new(PACKAGE
"<<Saving file:<<%s||&Cancel",
@ -132,12 +132,12 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved)
if (mark_as_saved)
sprite_mark_as_saved(sprite);
statusbar_set_text(app_get_statusbar(),
2000, "File %s, saved.",
get_filename(sprite->filename));
app_get_statusbar()
->setStatusText(2000, "File %s, saved.",
get_filename(sprite->filename));
}
progress_free(data->progress);
delete data->progress;
jwidget_free(data->alert_window);
fop_free(fop);
delete data;

View File

@ -56,9 +56,9 @@ void UndoCommand::execute(Context* context)
{
CurrentSpriteWriter sprite(context);
statusbar_show_tip(app_get_statusbar(), 1000,
_("Undid %s"),
undo_get_next_undo_label(sprite->undo));
app_get_statusbar()
->showTip(1000, _("Undid %s"),
undo_get_next_undo_label(sprite->undo));
undo_do_undo(sprite->undo);
sprite_generate_mask_boundaries(sprite);

View File

@ -125,7 +125,7 @@ static void monitor_effect_bg(void *_data)
}
if (data->progress)
progress_update(data->progress, pos);
data->progress->setPos(pos);
if (data->done)
remove_gui_monitor(data->monitor);
@ -162,7 +162,7 @@ void effect_apply_to_target_with_progressbar(Effect* effect)
data->pos = 0.0;
data->done = false;
data->cancelled = false;
data->progress = progress_new(app_get_statusbar());
data->progress = app_get_statusbar()->addProgress();
data->thread = jthread_new(effect_bg, data);
data->alert_window = jalert_new(PACKAGE
"<<Applying effect...||&Cancel");
@ -184,7 +184,7 @@ void effect_apply_to_target_with_progressbar(Effect* effect)
/* wait the `effect_bg' thread */
jthread_join(data->thread);
progress_free(data->progress);
delete data->progress;
jwidget_free(data->alert_window);
delete data;
}

View File

@ -45,7 +45,7 @@ Job::Job(const char* job_name)
m_canceled_flag = false;
m_mutex = new Mutex();
m_progress = progress_new(app_get_statusbar());
m_progress = app_get_statusbar()->addProgress();
m_monitor = add_gui_monitor(&Job::monitor_proc,
&Job::monitor_free,
(void*)this);
@ -70,7 +70,7 @@ Job::~Job()
jthread_join(m_thread);
if (m_progress)
progress_free(m_progress);
delete m_progress;
if (m_mutex)
delete m_mutex;
@ -117,7 +117,7 @@ void Job::on_monitor_tick()
ScopedLock hold(*m_mutex);
// update progress
progress_update(m_progress, m_last_progress);
m_progress->setPos(m_last_progress);
// is job done? we can close the monitor
if (m_done_flag)

View File

@ -25,7 +25,7 @@ namespace Vaca { class Mutex; }
class Frame;
struct Monitor;
struct Progress;
class Progress;
class Job
{

View File

@ -852,8 +852,8 @@ static void update_status_bar(Editor* editor, Image *image,
editor->screen_to_editor(x1, y1, &u1, &v1);
editor->screen_to_editor(x2, y2, &u2, &v2);
statusbar_set_text
(app_get_statusbar(), 0,
app_get_statusbar()->setStatusText
(0,
"Pos: %3d %3d Size: %3d %3d Orig: %3d %3d (%.02f%% %.02f%%) Angle: %3d",
u1, v1, u2-u1, v2-v1,
image->w, image->h,

View File

@ -197,8 +197,8 @@ int interactive_move_layer(int mode, bool use_undo, int (*callback)())
jwidget_dirty(editor);
/* update status bar */
statusbar_set_text
(app_get_statusbar(), 0,
app_get_statusbar()->setStatusText
(0,
"Pos %3d %3d Offset %3d %3d",
(int)cel->x,
(int)cel->y,

View File

@ -424,7 +424,7 @@ bool ColorBar::msg_proc(JMessage msg)
m_hot = HOTCOLOR_NONE;
dirty();
statusbar_set_text(app_get_statusbar(), 0, "");
app_get_statusbar()->setStatusText(0, "");
}
break;
@ -632,8 +632,6 @@ Rect ColorBar::getBgBounds() const
void ColorBar::updateStatusBar(color_t color, int msecs)
{
statusbar_show_color(app_get_statusbar(),
msecs,
app_get_current_image_type(),
color);
app_get_statusbar()
->showColor(msecs, app_get_current_image_type(), color);
}

View File

@ -627,9 +627,8 @@ void Editor::editor_update_statusbar_for_standby()
ustrcpy(buf, empty_string);
}
statusbar_set_text
(app_get_statusbar(), 0,
"%s %3d %3d (%s %3d %3d) [%s %d] %s",
app_get_statusbar()->setStatusText
(0, "%s %3d %3d (%s %3d %3d) [%s %d] %s",
_("Pos"), x, y,
_("Size"),
((m_sprite->mask->bitmap)?
@ -1048,9 +1047,8 @@ bool Editor::msg_proc(JMessage msg)
else if (m_state == EDITOR_STATE_MOVING_SCROLL) {
int x, y;
screen_to_editor(jmouse_x(0), jmouse_y(0), &x, &y);
statusbar_set_text
(app_get_statusbar(), 0,
"Pos %3d %3d (Size %3d %3d)", x, y,
app_get_statusbar()->setStatusText
(0, "Pos %3d %3d (Size %3d %3d)", x, y,
m_sprite->w, m_sprite->h);
}
}
@ -1726,7 +1724,7 @@ public:
void updateStatusBar(const char* text)
{
statusbar_set_text(app_get_statusbar(), 0, text);
app_get_statusbar()->setStatusText(0, text);
}
};

View File

@ -53,30 +53,26 @@ enum {
ACTION_LAST,
};
static bool statusbar_msg_proc(JWidget widget, JMessage msg);
static bool tipwindow_msg_proc(JWidget widget, JMessage msg);
static bool slider_change_hook(JWidget widget, void *data);
static void button_command(JWidget widget, void *data);
static void update_from_layer(StatusBar *statusbar);
static void on_current_tool_change(JWidget widget)
static int statusbar_type()
{
if (jwidget_is_visible(widget)) {
Tool* currentTool = UIContext::instance()->getSettings()->getCurrentTool();
if (currentTool)
statusbar_set_text(widget, 500, "%s selected",
currentTool->getText().c_str());
}
static int type = 0;
if (!type)
type = ji_register_widget_type();
return type;
}
JWidget statusbar_new()
StatusBar::StatusBar()
: Widget(statusbar_type())
{
#define BUTTON_NEW(name, text, data) \
{ \
(name) = jbutton_new(text); \
(name)->user_data[0] = statusbar; \
(name)->user_data[0] = this; \
setup_mini_look(name); \
jbutton_add_command_data((name), button_command, (void *)(data)); \
}
@ -87,97 +83,91 @@ JWidget statusbar_new()
add_gfxicon_to_button((name), (icon), JI_CENTER | JI_MIDDLE); \
}
Widget* widget = new Widget(statusbar_type());
StatusBar* statusbar = jnew(StatusBar, 1);
jwidget_focusrest(this, true);
jwidget_add_hook(widget, statusbar_type(),
statusbar_msg_proc, statusbar);
jwidget_focusrest(widget, true);
m_timeout = 0;
m_progress = jlist_new();
m_tipwindow = NULL;
{
JWidget box1, box2, box3;
// Construct the commands box
Widget* box1 = jbox_new(JI_HORIZONTAL);
Widget* box2 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
Widget* box3 = jbox_new(JI_HORIZONTAL);
m_slider = jslider_new(0, 255, 255);
statusbar->widget = widget;
statusbar->timeout = 0;
statusbar->progress = jlist_new();
statusbar->tipwindow = NULL;
setup_mini_look(m_slider);
/* construct the commands box */
box1 = jbox_new(JI_HORIZONTAL);
box2 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
box3 = jbox_new(JI_HORIZONTAL);
statusbar->slider = jslider_new(0, 255, 255);
ICON_NEW(m_b_first, GFX_ANI_FIRST, ACTION_FIRST);
ICON_NEW(m_b_prev, GFX_ANI_PREV, ACTION_PREV);
ICON_NEW(m_b_play, GFX_ANI_PLAY, ACTION_PLAY);
ICON_NEW(m_b_next, GFX_ANI_NEXT, ACTION_NEXT);
ICON_NEW(m_b_last, GFX_ANI_LAST, ACTION_LAST);
setup_mini_look(statusbar->slider);
HOOK(m_slider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0);
jwidget_set_min_size(m_slider, JI_SCREEN_W/5, 0);
ICON_NEW(statusbar->b_first, GFX_ANI_FIRST, ACTION_FIRST);
ICON_NEW(statusbar->b_prev, GFX_ANI_PREV, ACTION_PREV);
ICON_NEW(statusbar->b_play, GFX_ANI_PLAY, ACTION_PLAY);
ICON_NEW(statusbar->b_next, GFX_ANI_NEXT, ACTION_NEXT);
ICON_NEW(statusbar->b_last, GFX_ANI_LAST, ACTION_LAST);
jwidget_set_border(box1, 2*jguiscale(), 1*jguiscale(), 2*jguiscale(), 2*jguiscale());
jwidget_noborders(box2);
jwidget_noborders(box3);
jwidget_expansive(box3, true);
HOOK(statusbar->slider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0);
jwidget_set_min_size(statusbar->slider, JI_SCREEN_W/5, 0);
jwidget_add_child(box2, m_b_first);
jwidget_add_child(box2, m_b_prev);
jwidget_add_child(box2, m_b_play);
jwidget_add_child(box2, m_b_next);
jwidget_add_child(box2, m_b_last);
jwidget_set_border(box1, 2*jguiscale(), 1*jguiscale(), 2*jguiscale(), 2*jguiscale());
jwidget_noborders(box2);
jwidget_noborders(box3);
jwidget_expansive(box3, true);
jwidget_add_child(box1, box3);
jwidget_add_child(box1, box2);
jwidget_add_child(box1, m_slider);
jwidget_add_child(box2, statusbar->b_first);
jwidget_add_child(box2, statusbar->b_prev);
jwidget_add_child(box2, statusbar->b_play);
jwidget_add_child(box2, statusbar->b_next);
jwidget_add_child(box2, statusbar->b_last);
m_commands_box = box1;
jwidget_add_child(box1, box3);
jwidget_add_child(box1, box2);
jwidget_add_child(box1, statusbar->slider);
App::instance()->CurrentToolChange.connect(Vaca::Bind<void>(&StatusBar::onCurrentToolChange, this));
}
statusbar->commands_box = box1;
StatusBar::~StatusBar()
{
JLink link;
App::instance()->CurrentToolChange.connect(Vaca::Bind<void>(&on_current_tool_change, widget));
JI_LIST_FOR_EACH(m_progress, link) {
jfree(link->data);
}
jlist_free(m_progress);
return widget;
if (m_tipwindow != NULL)
jwidget_free(m_tipwindow);
}
int statusbar_type()
void StatusBar::onCurrentToolChange()
{
static int type = 0;
if (!type)
type = ji_register_widget_type();
return type;
if (jwidget_is_visible(this)) {
Tool* currentTool = UIContext::instance()->getSettings()->getCurrentTool();
if (currentTool)
this->setStatusText(500, "%s selected",
currentTool->getText().c_str());
}
}
StatusBar *statusbar_data(JWidget widget)
void StatusBar::setStatusText(int msecs, const char *format, ...)
{
return reinterpret_cast<StatusBar*>(jwidget_get_data(widget, statusbar_type()));
}
void statusbar_set_text(JWidget widget, int msecs, const char *format, ...)
{
StatusBar *statusbar = statusbar_data(widget);
if ((ji_clock > statusbar->timeout) || (msecs > 0)) {
char buf[256]; /* TODO warning buffer overflow */
if ((ji_clock > m_timeout) || (msecs > 0)) {
char buf[256]; // TODO warning buffer overflow
va_list ap;
va_start(ap, format);
vsprintf(buf, format, ap);
va_end(ap);
widget->setText(buf);
statusbar->timeout = ji_clock + msecs;
jwidget_dirty(widget);
this->setText(buf);
m_timeout = ji_clock + msecs;
this->dirty();
}
}
void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...)
void StatusBar::showTip(int msecs, const char *format, ...)
{
StatusBar *statusbar = statusbar_data(widget);
Frame* tipwindow = statusbar->tipwindow;
char buf[256]; /* TODO warning buffer overflow */
char buf[256]; // TODO warning buffer overflow
va_list ap;
int x, y;
@ -185,122 +175,120 @@ void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...)
vsprintf(buf, format, ap);
va_end(ap);
if (tipwindow == NULL) {
tipwindow = new TipWindow(buf);
tipwindow->user_data[0] = (void *)jmanager_add_timer(tipwindow, msecs);
tipwindow->user_data[1] = statusbar;
jwidget_add_hook(tipwindow, -1, tipwindow_msg_proc, NULL);
statusbar->tipwindow = tipwindow;
if (m_tipwindow == NULL) {
m_tipwindow = new TipWindow(buf);
m_tipwindow->user_data[0] = (void *)jmanager_add_timer(m_tipwindow, msecs);
m_tipwindow->user_data[1] = this;
jwidget_add_hook(m_tipwindow, -1, tipwindow_msg_proc, NULL);
}
else {
tipwindow->setText(buf);
m_tipwindow->setText(buf);
jmanager_set_timer_interval((size_t)tipwindow->user_data[0], msecs);
jmanager_set_timer_interval((size_t)m_tipwindow->user_data[0], msecs);
}
if (jwidget_is_visible(tipwindow))
tipwindow->closeWindow(NULL);
if (jwidget_is_visible(m_tipwindow))
m_tipwindow->closeWindow(NULL);
tipwindow->open_window();
tipwindow->remap_window();
m_tipwindow->open_window();
m_tipwindow->remap_window();
x = widget->rc->x2 - jrect_w(tipwindow->rc);
y = widget->rc->y1 - jrect_h(tipwindow->rc);
tipwindow->position_window(x, y);
x = this->rc->x2 - jrect_w(m_tipwindow->rc);
y = this->rc->y1 - jrect_h(m_tipwindow->rc);
m_tipwindow->position_window(x, y);
jmanager_start_timer((size_t)tipwindow->user_data[0]);
jmanager_start_timer((size_t)m_tipwindow->user_data[0]);
}
void statusbar_show_color(JWidget widget, int msecs, int imgtype, color_t color)
void StatusBar::showColor(int msecs, int imgtype, color_t color)
{
char buf[128]; // TODO warning buffer overflow
color_to_formalstring(imgtype, color, buf, sizeof(buf), true);
statusbar_set_text(widget, msecs, "%s %s", _("Color"), buf);
setStatusText(msecs, "%s %s", _("Color"), buf);
}
Progress *progress_new(JWidget widget)
//////////////////////////////////////////////////////////////////////
// Progress bars stuff
Progress* StatusBar::addProgress()
{
Progress *progress = jnew(Progress, 1);
if (!progress)
return NULL;
progress->statusbar = widget;
progress->pos = 0.0f;
jlist_append(statusbar_data(widget)->progress, progress);
jwidget_dirty(widget);
Progress* progress = new Progress(this);
jlist_append(m_progress, progress);
jwidget_dirty(this);
return progress;
}
void progress_free(Progress *progress)
void StatusBar::removeProgress(Progress* progress)
{
jlist_remove(statusbar_data(progress->statusbar)->progress,
progress);
jwidget_dirty(progress->statusbar);
assert(progress->m_statusbar == this);
jfree(progress);
jlist_remove(m_progress, progress);
jwidget_dirty(this);
}
void progress_update(Progress *progress, float progress_pos)
Progress::Progress(StatusBar* statusbar)
: m_statusbar(statusbar)
, m_pos(0.0f)
{
if (progress->pos != progress_pos) {
progress->pos = progress_pos;
jwidget_dirty(progress->statusbar);
}
Progress::~Progress()
{
if (m_statusbar) {
m_statusbar->removeProgress(this);
m_statusbar = NULL;
}
}
static bool statusbar_msg_proc(JWidget widget, JMessage msg)
void Progress::setPos(float pos)
{
StatusBar *statusbar = statusbar_data(widget);
if (m_pos != pos) {
m_pos = pos;
m_statusbar->dirty();
}
}
float Progress::getPos() const
{
return m_pos;
}
//////////////////////////////////////////////////////////////////////
// StatusBar message handler
bool StatusBar::msg_proc(JMessage msg)
{
switch (msg->type) {
case JM_DESTROY: {
JLink link;
JI_LIST_FOR_EACH(statusbar->progress, link) {
jfree(link->data);
}
jlist_free(statusbar->progress);
if (statusbar->tipwindow != NULL)
jwidget_free(statusbar->tipwindow);
jfree(statusbar);
break;
}
case JM_REQSIZE:
msg->reqsize.w = msg->reqsize.h =
4*jguiscale()
+ jwidget_get_text_height(widget)
+ jwidget_get_text_height(this)
+ 4*jguiscale();
return true;
case JM_SETPOS:
jrect_copy(widget->rc, &msg->setpos.rect);
jrect_copy(this->rc, &msg->setpos.rect);
{
JRect rc = jrect_new_copy(widget->rc);
JRect rc = jrect_new_copy(this->rc);
rc->x2 -= jrect_w(rc)/4 + 4*jguiscale();
jwidget_set_rect(statusbar->commands_box, rc);
jwidget_set_rect(m_commands_box, rc);
jrect_free(rc);
}
return true;
case JM_CLOSE:
if (!jwidget_has_child(widget, statusbar->commands_box)) {
if (!jwidget_has_child(this, m_commands_box)) {
/* append the "commands_box" to destroy it in the jwidget_free */
jwidget_add_child(widget, statusbar->commands_box);
jwidget_add_child(this, m_commands_box);
}
break;
case JM_DRAW: {
SkinneableTheme* theme = static_cast<SkinneableTheme*>(widget->theme);
SkinneableTheme* theme = static_cast<SkinneableTheme*>(this->theme);
int text_color = ji_color_foreground();
int face_color = ji_color_face();
JRect rc = jwidget_get_rect(widget);
JRect rc = jwidget_get_rect(this);
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
jrect_h(&msg->draw.rect));
jrect_displace(rc,
@ -315,15 +303,15 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
rc->y2 -= 2*jguiscale();
// Status bar text
if (widget->getText()) {
textout_ex(doublebuffer, widget->getFont(), widget->getText(),
if (this->getText()) {
textout_ex(doublebuffer, this->getFont(), this->getText(),
rc->x1+4*jguiscale(),
(rc->y1+rc->y2)/2-text_height(widget->getFont())/2,
(rc->y1+rc->y2)/2-text_height(this->getFont())/2,
text_color, -1);
}
// Draw progress bar
if (!jlist_empty(statusbar->progress)) {
if (!jlist_empty(m_progress)) {
int width = 64;
int y1, y2;
int x = rc->x2 - (width+4);
@ -332,12 +320,12 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
y1 = rc->y1;
y2 = rc->y2-1;
JI_LIST_FOR_EACH(statusbar->progress, link) {
JI_LIST_FOR_EACH(m_progress, link) {
Progress* progress = reinterpret_cast<Progress*>(link->data);
draw_progress_bar(doublebuffer,
x, y1, x+width-1, y2,
progress->pos);
progress->getPos());
x -= width+4;
}
@ -373,9 +361,9 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
}
usprintf(buf, "%d", c);
textout_centre_ex(doublebuffer, widget->getFont(), buf,
textout_centre_ex(doublebuffer, this->getFont(), buf,
(x1+x2)/2,
(rc->y1+rc->y2)/2-text_height(widget->getFont())/2,
(rc->y1+rc->y2)/2-text_height(this->getFont())/2,
hot ? theme->get_button_hot_text_color():
theme->get_button_normal_text_color(), -1);
}
@ -393,9 +381,9 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
ji_screen = old_ji_screen;
}
textout_centre_ex(doublebuffer, widget->getFont(), "No Sprite",
textout_centre_ex(doublebuffer, this->getFont(), "No Sprite",
(x1+x2)/2,
(rc->y1+rc->y2)/2-text_height(widget->getFont())/2,
(rc->y1+rc->y2)/2-text_height(this->getFont())/2,
theme->get_button_normal_text_color(), -1);
}
}
@ -416,38 +404,38 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
}
case JM_MOUSEENTER:
if (!jwidget_has_child(widget, statusbar->commands_box)) {
if (!jwidget_has_child(this, m_commands_box)) {
bool state = (UIContext::instance()->get_current_sprite() != NULL);
statusbar->b_first->setEnabled(state);
statusbar->b_prev->setEnabled(state);
statusbar->b_play->setEnabled(state);
statusbar->b_next->setEnabled(state);
statusbar->b_last->setEnabled(state);
m_b_first->setEnabled(state);
m_b_prev->setEnabled(state);
m_b_play->setEnabled(state);
m_b_next->setEnabled(state);
m_b_last->setEnabled(state);
update_from_layer(statusbar);
updateFromLayer();
jwidget_add_child(widget, statusbar->commands_box);
jwidget_dirty(widget);
jwidget_add_child(this, m_commands_box);
jwidget_dirty(this);
}
break;
case JM_MOUSELEAVE:
if (jwidget_has_child(widget, statusbar->commands_box)) {
if (jwidget_has_child(this, m_commands_box)) {
/* if we want restore the state-bar and the slider doesn't have
the capture... */
if (jmanager_get_capture() != statusbar->slider) {
if (jmanager_get_capture() != m_slider) {
/* exit from command mode */
jmanager_free_focus();
jwidget_remove_child(widget, statusbar->commands_box);
jwidget_dirty(widget);
jwidget_remove_child(this, m_commands_box);
jwidget_dirty(this);
}
}
break;
}
return false;
return Widget::msg_proc(msg);
}
static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
@ -507,7 +495,7 @@ static void button_command(JWidget widget, void *data)
UIContext::instance()->execute_command(cmd);
}
static void update_from_layer(StatusBar *statusbar)
void StatusBar::updateFromLayer()
{
try {
const CurrentSpriteReader sprite(UIContext::instance());
@ -519,16 +507,16 @@ static void update_from_layer(StatusBar *statusbar)
sprite->layer->is_image() &&
!sprite->layer->is_background() &&
(cel = ((LayerImage*)sprite->layer)->get_cel(sprite->frame))) {
jslider_set_value(statusbar->slider, MID(0, cel->opacity, 255));
jwidget_enable(statusbar->slider);
jslider_set_value(m_slider, MID(0, cel->opacity, 255));
jwidget_enable(m_slider);
}
else {
jslider_set_value(statusbar->slider, 255);
jwidget_disable(statusbar->slider);
jslider_set_value(m_slider, 255);
jwidget_disable(m_slider);
}
}
catch (locked_sprite_exception&) {
// disable all
jwidget_disable(statusbar->slider);
jwidget_disable(m_slider);
}
}

View File

@ -20,55 +20,65 @@
#define WIDGETS_STATEBAR_H_INCLUDED
#include "jinete/jbase.h"
#include "jinete/jwidget.h"
#include "core/color.h"
class Widget;
class Frame;
class StatusBar;
struct Progress
class Progress
{
Widget* statusbar;
float pos;
friend class StatusBar;
public:
~Progress();
void setPos(float pos);
float getPos() const;
private:
Progress();
Progress(StatusBar* statusbar);
StatusBar* m_statusbar;
float m_pos;
};
struct StatusBar
class StatusBar : public Widget
{
Widget* widget;
int timeout;
int m_timeout;
/* progress bar */
JList progress;
// Progress bar
JList m_progress;
/* box of main commands */
Widget* commands_box;
Widget* b_layer; /* layer button */
Widget* slider; /* opacity slider */
Widget* b_first; /* go to first frame */
Widget* b_prev; /* go to previous frame */
Widget* b_play; /* play animation */
Widget* b_next; /* go to next frame */
Widget* b_last; /* go to last frame */
// Box of main commands
Widget* m_commands_box;
Widget* m_slider; // Opacity slider
Widget* m_b_first; // Go to first frame
Widget* m_b_prev; // Go to previous frame
Widget* m_b_play; // Play animation
Widget* m_b_next; // Go to next frame
Widget* m_b_last; // Go to last frame
/* tip window */
Frame* tipwindow;
// Tip window
Frame* m_tipwindow;
public:
StatusBar();
~StatusBar();
void setStatusText(int msecs, const char *format, ...);
void showTip(int msecs, const char *format, ...);
void showColor(int msecs, int imgtype, color_t color);
Progress* addProgress();
void removeProgress(Progress* progress);
protected:
virtual bool msg_proc(JMessage msg);
private:
void onCurrentToolChange();
void updateFromLayer();
};
/* statusbar */
JWidget statusbar_new();
int statusbar_type();
StatusBar *statusbar_data(JWidget widget);
void statusbar_set_text(JWidget widget, int msecs, const char *format, ...);
void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...);
void statusbar_show_color(JWidget widget, int msecs, int imgtype, color_t color);
/* progress */
Progress *progress_new(JWidget widget);
void progress_free(Progress *progress);
void progress_update(Progress *progress, float progress_pos);
#endif