2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/context_access.h"
|
2015-04-07 13:29:33 +08:00
|
|
|
#include "app/document_access.h"
|
2014-08-25 06:59:12 +08:00
|
|
|
#include "app/document_range.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/modules/gfx.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
|
|
|
#include "app/settings/settings.h"
|
|
|
|
#include "app/tools/tool.h"
|
2015-04-07 13:29:33 +08:00
|
|
|
#include "app/ui/button_set.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/color_button.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
2014-10-29 22:58:03 +08:00
|
|
|
#include "app/ui/keyboard_shortcuts.h"
|
2014-08-25 06:59:12 +08:00
|
|
|
#include "app/ui/main_window.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
#include "app/ui/status_bar.h"
|
2014-08-25 06:59:12 +08:00
|
|
|
#include "app/ui/timeline.h"
|
2015-04-10 22:21:37 +08:00
|
|
|
#include "app/ui/toolbar.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui_context.h"
|
2014-08-25 06:59:12 +08:00
|
|
|
#include "app/util/range_utils.h"
|
2010-09-27 02:59:32 +08:00
|
|
|
#include "base/bind.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/cel.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/sprite.h"
|
2015-04-07 13:29:33 +08:00
|
|
|
#include "gfx/size.h"
|
2014-06-23 05:53:14 +08:00
|
|
|
#include "she/font.h"
|
|
|
|
#include "she/surface.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-03-24 22:50:00 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
using namespace app::skin;
|
2010-09-26 03:22:32 +08:00
|
|
|
using namespace gfx;
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
2014-10-21 09:21:31 +08:00
|
|
|
using namespace doc;
|
2010-09-26 03:22:32 +08:00
|
|
|
|
2014-04-14 00:51:28 +08:00
|
|
|
static const char* kStatusBarText = "status_bar_text";
|
|
|
|
static const char* kStatusBarFace = "status_bar_face";
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class StatusBar::CustomizedTipWindow : public ui::TipWindow {
|
2012-06-16 10:37:59 +08:00
|
|
|
public:
|
|
|
|
CustomizedTipWindow(const char* text)
|
2012-06-18 09:02:54 +08:00
|
|
|
: ui::TipWindow(text)
|
2012-06-16 10:37:59 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInterval(int msecs)
|
|
|
|
{
|
|
|
|
if (!m_timer)
|
2012-07-06 12:06:00 +08:00
|
|
|
m_timer.reset(new ui::Timer(msecs, this));
|
2012-06-16 10:37:59 +08:00
|
|
|
else
|
|
|
|
m_timer->setInterval(msecs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void startTimer()
|
|
|
|
{
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onProcessMessage(Message* msg);
|
|
|
|
|
|
|
|
private:
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<ui::Timer> m_timer;
|
2012-06-16 10:37:59 +08:00
|
|
|
};
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
static WidgetType statusbar_type()
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
{
|
2013-04-04 09:07:24 +08:00
|
|
|
static WidgetType type = kGenericWidget;
|
|
|
|
if (type == kGenericWidget)
|
|
|
|
type = register_widget_type();
|
2010-03-29 11:00:25 +08:00
|
|
|
return type;
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
}
|
|
|
|
|
2012-01-10 08:18:32 +08:00
|
|
|
// This widget is used to show the current frame.
|
|
|
|
class GotoFrameEntry : public Entry {
|
|
|
|
public:
|
|
|
|
GotoFrameEntry() : Entry(4, "") {
|
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
bool onProcessMessage(Message* msg) override {
|
2013-07-29 08:17:07 +08:00
|
|
|
switch (msg->type()) {
|
2012-01-10 08:18:32 +08:00
|
|
|
// When the mouse enter in this entry, it got the focus and the
|
|
|
|
// text is automatically selected.
|
2013-04-05 08:53:29 +08:00
|
|
|
case kMouseEnterMessage:
|
2012-01-10 08:18:32 +08:00
|
|
|
requestFocus();
|
|
|
|
selectText(0, -1);
|
|
|
|
break;
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
case kKeyDownMessage: {
|
|
|
|
KeyMessage* keymsg = static_cast<KeyMessage*>(msg);
|
|
|
|
KeyScancode scancode = keymsg->scancode();
|
2015-02-12 23:16:25 +08:00
|
|
|
|
2015-05-05 20:47:05 +08:00
|
|
|
if (hasFocus() &&
|
|
|
|
(scancode == kKeyEnter || // TODO customizable keys
|
|
|
|
scancode == kKeyEnterPad)) {
|
2012-01-10 08:18:32 +08:00
|
|
|
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::GotoFrame);
|
|
|
|
Params params;
|
2013-10-15 06:58:11 +08:00
|
|
|
int frame = getTextInt();
|
2012-01-10 08:18:32 +08:00
|
|
|
if (frame > 0) {
|
2013-10-15 06:58:11 +08:00
|
|
|
params.set("frame", getText().c_str());
|
2015-03-12 02:40:22 +08:00
|
|
|
UIContext::instance()->executeCommand(cmd, params);
|
2012-01-10 08:18:32 +08:00
|
|
|
}
|
|
|
|
// Select the text again
|
|
|
|
selectText(0, -1);
|
|
|
|
return true; // Key used.
|
|
|
|
}
|
|
|
|
break;
|
2013-07-29 08:17:07 +08:00
|
|
|
}
|
2012-01-10 08:18:32 +08:00
|
|
|
}
|
|
|
|
return Entry::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar* StatusBar::m_instance = NULL;
|
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
StatusBar::StatusBar()
|
|
|
|
: Widget(statusbar_type())
|
2013-01-07 01:45:43 +08:00
|
|
|
, m_color(app::Color::fromMask())
|
2015-04-17 00:14:39 +08:00
|
|
|
, m_hasDoc(false)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-07-10 00:20:58 +08:00
|
|
|
m_instance = this;
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
setDoubleBuffered(true);
|
|
|
|
|
2014-04-14 00:51:28 +08:00
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
|
|
|
setBgColor(theme->getColorById(kStatusBarFace));
|
|
|
|
|
2012-04-06 06:00:19 +08:00
|
|
|
this->setFocusStop(true);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
m_timeout = 0;
|
2010-04-24 12:06:30 +08:00
|
|
|
m_state = SHOW_TEXT;
|
2010-03-29 11:00:25 +08:00
|
|
|
m_tipwindow = NULL;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-08-12 08:48:12 +08:00
|
|
|
// The extra pixel in left and right borders are necessary so
|
|
|
|
// m_commandsBox and m_movePixelsBox do not overlap the upper-left
|
2013-12-30 08:12:23 +08:00
|
|
|
// and upper-right pixels drawn in onPaint() event (see putpixels)
|
2014-11-26 09:33:45 +08:00
|
|
|
setBorder(gfx::Border(1*guiscale(), 0, 1*guiscale(), 0));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-08-12 08:48:12 +08:00
|
|
|
// Construct the commands box
|
|
|
|
{
|
2011-01-25 06:48:09 +08:00
|
|
|
Box* box1 = new Box(JI_HORIZONTAL);
|
2012-01-10 08:18:32 +08:00
|
|
|
Box* box4 = new Box(JI_HORIZONTAL);
|
2015-04-07 22:15:28 +08:00
|
|
|
|
|
|
|
m_frameLabel = new Label("Frame:");
|
2012-01-10 08:18:32 +08:00
|
|
|
m_currentFrame = new GotoFrameEntry();
|
|
|
|
m_newFrame = new Button("+");
|
|
|
|
m_newFrame->Click.connect(Bind<void>(&StatusBar::newFrame, this));
|
2015-04-07 22:15:28 +08:00
|
|
|
m_slider = new Slider(0, 255, 255);
|
2010-08-12 08:48:12 +08:00
|
|
|
|
2012-01-10 08:18:32 +08:00
|
|
|
setup_mini_look(m_currentFrame);
|
|
|
|
setup_mini_look(m_newFrame);
|
2015-04-07 21:48:04 +08:00
|
|
|
setup_mini_look(m_slider);
|
2010-08-12 08:48:12 +08:00
|
|
|
|
2015-04-17 00:07:14 +08:00
|
|
|
m_slider->Change.connect(Bind<void>(&StatusBar::onCelOpacityChange, this));
|
2014-09-01 01:17:49 +08:00
|
|
|
m_slider->setMinSize(gfx::Size(ui::display_w()/5, 0));
|
2010-08-12 08:48:12 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
box1->setBorder(gfx::Border(2, 1, 2, 2)*guiscale());
|
2010-08-12 08:48:12 +08:00
|
|
|
|
2012-01-10 08:18:32 +08:00
|
|
|
box4->addChild(m_currentFrame);
|
|
|
|
box4->addChild(m_newFrame);
|
|
|
|
|
2015-04-07 22:15:28 +08:00
|
|
|
box1->addChild(m_frameLabel);
|
2012-01-10 08:18:32 +08:00
|
|
|
box1->addChild(box4);
|
2011-03-30 08:35:17 +08:00
|
|
|
box1->addChild(m_slider);
|
2010-08-12 08:48:12 +08:00
|
|
|
|
|
|
|
m_commandsBox = box1;
|
2015-04-07 12:21:31 +08:00
|
|
|
addChild(m_commandsBox);
|
|
|
|
m_commandsBox->setVisible(false);
|
2010-08-12 08:48:12 +08:00
|
|
|
}
|
2010-03-22 08:30:50 +08:00
|
|
|
|
2015-04-07 22:15:45 +08:00
|
|
|
// Tooltips manager
|
|
|
|
TooltipManager* tooltipManager = new TooltipManager();
|
|
|
|
addChild(tooltipManager);
|
2015-04-10 22:23:21 +08:00
|
|
|
tooltipManager->addTooltipFor(m_currentFrame, "Current Frame", JI_BOTTOM);
|
2015-04-07 22:15:45 +08:00
|
|
|
tooltipManager->addTooltipFor(m_slider, "Cel Opacity", JI_BOTTOM);
|
|
|
|
|
2010-07-24 07:01:52 +08:00
|
|
|
App::instance()->CurrentToolChange.connect(&StatusBar::onCurrentToolChange, this);
|
2010-03-29 11:00:25 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
StatusBar::~StatusBar()
|
|
|
|
{
|
2012-01-06 06:45:03 +08:00
|
|
|
delete m_tipwindow; // widget
|
2011-07-27 10:25:02 +08:00
|
|
|
delete m_commandsBox;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
void StatusBar::onCurrentToolChange()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2010-07-04 23:03:14 +08:00
|
|
|
if (isVisible()) {
|
2014-07-29 11:53:24 +08:00
|
|
|
tools::Tool* currentTool = UIContext::instance()->settings()->getCurrentTool();
|
2010-04-24 12:55:51 +08:00
|
|
|
if (currentTool) {
|
2011-04-02 21:47:03 +08:00
|
|
|
showTool(500, currentTool);
|
|
|
|
setTextf("%s Selected", currentTool->getText().c_str());
|
2010-04-24 12:55:51 +08:00
|
|
|
}
|
2010-03-29 11:00:25 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2010-06-11 10:58:48 +08:00
|
|
|
void StatusBar::clearText()
|
|
|
|
{
|
|
|
|
setStatusText(1, "");
|
|
|
|
}
|
|
|
|
|
2010-04-24 12:06:30 +08:00
|
|
|
bool StatusBar::setStatusText(int msecs, const char *format, ...)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-08-19 02:22:23 +08:00
|
|
|
// TODO this call should be in an observer of the "current frame" property changes.
|
2015-04-07 13:29:33 +08:00
|
|
|
updateCurrentFrame(current_editor);
|
2012-01-10 08:18:32 +08:00
|
|
|
|
2014-09-01 01:17:49 +08:00
|
|
|
if ((ui::clock() > m_timeout) || (msecs > 0)) {
|
2012-01-06 06:45:03 +08:00
|
|
|
char buf[256]; // TODO warning buffer overflow
|
2007-09-19 07:57:02 +08:00
|
|
|
va_list ap;
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
va_start(ap, format);
|
|
|
|
vsprintf(buf, format, ap);
|
|
|
|
va_end(ap);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2014-09-01 01:17:49 +08:00
|
|
|
m_timeout = ui::clock() + msecs;
|
2010-04-24 12:06:30 +08:00
|
|
|
m_state = SHOW_TEXT;
|
|
|
|
|
2011-07-27 10:25:02 +08:00
|
|
|
setText(buf);
|
|
|
|
invalidate();
|
2010-04-24 12:06:30 +08:00
|
|
|
|
|
|
|
return true;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2010-04-24 12:06:30 +08:00
|
|
|
else
|
|
|
|
return false;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
void StatusBar::showTip(int msecs, const char *format, ...)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-01-06 06:45:03 +08:00
|
|
|
char buf[256]; // TODO warning buffer overflow
|
2008-03-23 02:43:56 +08:00
|
|
|
va_list ap;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
vsprintf(buf, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
if (m_tipwindow == NULL) {
|
2012-06-16 10:37:59 +08:00
|
|
|
m_tipwindow = new CustomizedTipWindow(buf);
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
else {
|
2010-03-29 11:00:25 +08:00
|
|
|
m_tipwindow->setText(buf);
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
m_tipwindow->setInterval(msecs);
|
|
|
|
|
2010-07-04 23:03:14 +08:00
|
|
|
if (m_tipwindow->isVisible())
|
2010-03-29 11:00:25 +08:00
|
|
|
m_tipwindow->closeWindow(NULL);
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2012-07-09 10:24:42 +08:00
|
|
|
m_tipwindow->openWindow();
|
2013-01-11 23:43:25 +08:00
|
|
|
m_tipwindow->remapWindow();
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2013-10-26 23:50:55 +08:00
|
|
|
x = getBounds().x2() - m_tipwindow->getBounds().w;
|
|
|
|
y = getBounds().y - m_tipwindow->getBounds().h;
|
2013-01-11 23:43:25 +08:00
|
|
|
m_tipwindow->positionWindow(x, y);
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
m_tipwindow->startTimer();
|
2010-03-31 10:38:52 +08:00
|
|
|
|
|
|
|
// Set the text in status-bar (with inmediate timeout)
|
2014-09-01 01:17:49 +08:00
|
|
|
m_timeout = ui::clock();
|
2011-07-27 10:25:02 +08:00
|
|
|
setText(buf);
|
|
|
|
invalidate();
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
void StatusBar::showColor(int msecs, const char* text, const app::Color& color, int alpha)
|
2008-03-23 02:43:56 +08:00
|
|
|
{
|
2010-04-24 12:06:30 +08:00
|
|
|
if (setStatusText(msecs, text)) {
|
|
|
|
m_state = SHOW_COLOR;
|
|
|
|
m_color = color;
|
|
|
|
m_alpha = alpha;
|
|
|
|
}
|
2008-03-01 03:29:49 +08:00
|
|
|
}
|
|
|
|
|
2011-04-02 21:47:03 +08:00
|
|
|
void StatusBar::showTool(int msecs, tools::Tool* tool)
|
2010-04-24 12:55:51 +08:00
|
|
|
{
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(tool != NULL);
|
2010-04-24 12:55:51 +08:00
|
|
|
|
|
|
|
// Tool name
|
|
|
|
std::string text = tool->getText();
|
|
|
|
|
|
|
|
// Tool shortcut
|
2014-10-29 22:58:03 +08:00
|
|
|
Key* key = KeyboardShortcuts::instance()->tool(tool);
|
|
|
|
if (key && !key->accels().empty()) {
|
2010-04-24 12:55:51 +08:00
|
|
|
text += ", Shortcut: ";
|
2014-10-29 22:58:03 +08:00
|
|
|
text += key->accels().front().toString();
|
2010-04-24 12:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set text
|
|
|
|
if (setStatusText(msecs, text.c_str())) {
|
|
|
|
// Show tool
|
|
|
|
m_state = SHOW_TOOL;
|
|
|
|
m_tool = tool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-29 11:00:25 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// StatusBar message handler
|
2008-05-06 23:22:57 +08:00
|
|
|
|
2013-05-12 04:56:27 +08:00
|
|
|
void StatusBar::onResize(ResizeEvent& ev)
|
|
|
|
{
|
|
|
|
setBoundsQuietly(ev.getBounds());
|
|
|
|
|
2015-04-07 21:48:04 +08:00
|
|
|
Border border = getBorder();
|
2013-05-12 04:56:27 +08:00
|
|
|
Rect rc = ev.getBounds();
|
2015-04-10 22:21:37 +08:00
|
|
|
bool frameControls = (rc.w > 300*ui::guiscale());
|
2015-04-07 21:48:04 +08:00
|
|
|
|
2015-04-10 22:21:37 +08:00
|
|
|
if (frameControls) {
|
|
|
|
m_slider->setVisible(rc.w > 400*ui::guiscale());
|
|
|
|
int prefWidth = m_commandsBox->getPreferredSize().w;
|
|
|
|
int toolBarWidth = ToolBar::instance()->getPreferredSize().w;
|
2015-04-07 21:48:04 +08:00
|
|
|
|
2015-04-10 22:21:37 +08:00
|
|
|
rc.x += rc.w - prefWidth - border.right() - toolBarWidth;
|
|
|
|
rc.w = prefWidth;
|
|
|
|
|
2015-04-17 00:14:39 +08:00
|
|
|
m_commandsBox->setVisible(true && m_hasDoc);
|
2015-04-10 22:21:37 +08:00
|
|
|
m_commandsBox->setBounds(rc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_commandsBox->setVisible(false);
|
2013-05-12 04:56:27 +08:00
|
|
|
}
|
|
|
|
|
2012-09-27 05:34:52 +08:00
|
|
|
void StatusBar::onPreferredSize(PreferredSizeEvent& ev)
|
|
|
|
{
|
2014-11-26 09:33:45 +08:00
|
|
|
int s = 4*guiscale() + getTextHeight() + 4*guiscale();
|
2012-09-27 05:34:52 +08:00
|
|
|
ev.setPreferredSize(Size(s, s));
|
|
|
|
}
|
|
|
|
|
2013-12-30 08:12:23 +08:00
|
|
|
void StatusBar::onPaint(ui::PaintEvent& ev)
|
|
|
|
{
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color textColor = theme->getColorById(kStatusBarText);
|
2013-12-30 08:12:23 +08:00
|
|
|
Rect rc = getClientBounds();
|
|
|
|
Graphics* g = ev.getGraphics();
|
|
|
|
|
2014-04-14 00:51:28 +08:00
|
|
|
g->fillRect(getBgColor(), rc);
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
rc.shrink(Border(2, 1, 2, 2)*guiscale());
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
int x = rc.x + 4*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
|
|
|
|
// Color
|
|
|
|
if (m_state == SHOW_COLOR) {
|
|
|
|
// Draw eyedropper icon
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* icon = theme->get_toolicon("eyedropper");
|
2013-12-30 08:12:23 +08:00
|
|
|
if (icon) {
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
|
2014-11-26 09:33:45 +08:00
|
|
|
x += icon->width() + 4*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw color
|
2014-11-26 09:33:45 +08:00
|
|
|
draw_color_button(g, gfx::Rect(x, rc.y, 32*guiscale(), rc.h),
|
2014-06-02 05:15:11 +08:00
|
|
|
m_color, false, false);
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
x += (32+4)*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
|
|
|
|
// Draw color description
|
|
|
|
std::string str = m_color.toHumanReadableString(app_get_current_pixel_format(),
|
|
|
|
app::Color::LongHumanReadableString);
|
|
|
|
if (m_alpha < 255) {
|
2014-06-23 05:53:14 +08:00
|
|
|
char buf[256];
|
2015-04-07 07:11:41 +08:00
|
|
|
sprintf(buf, " \xCE\xB1%d", m_alpha);
|
2013-12-30 08:12:23 +08:00
|
|
|
str += buf;
|
|
|
|
}
|
|
|
|
|
2014-06-27 09:14:39 +08:00
|
|
|
g->drawString(str, textColor, ColorNone,
|
2014-06-23 05:53:14 +08:00
|
|
|
gfx::Point(x, rc.y + rc.h/2 - getFont()->height()/2));
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
x += getFont()->textLength(str.c_str()) + 4*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Show tool
|
|
|
|
if (m_state == SHOW_TOOL) {
|
|
|
|
// Draw eyedropper icon
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* icon = theme->get_toolicon(m_tool->getId().c_str());
|
2013-12-30 08:12:23 +08:00
|
|
|
if (icon) {
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
|
2014-11-26 09:33:45 +08:00
|
|
|
x += icon->width() + 4*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status bar text
|
2014-03-22 06:45:35 +08:00
|
|
|
if (getTextLength() > 0) {
|
2014-06-27 09:14:39 +08:00
|
|
|
g->drawString(getText(), textColor, ColorNone,
|
2014-06-23 05:53:14 +08:00
|
|
|
gfx::Point(x, rc.y + rc.h/2 - getFont()->height()/2));
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
x += getFont()->textLength(getText().c_str()) + 4*guiscale();
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
2015-04-07 12:21:31 +08:00
|
|
|
}
|
2013-12-30 08:12:23 +08:00
|
|
|
|
2015-04-07 13:29:33 +08:00
|
|
|
void StatusBar::updateUsingEditor(Editor* editor)
|
2015-04-07 12:21:31 +08:00
|
|
|
{
|
2015-04-07 13:29:33 +08:00
|
|
|
updateFromDocument(editor);
|
|
|
|
updateCurrentFrame(editor);
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 10:37:59 +08:00
|
|
|
bool StatusBar::CustomizedTipWindow::onProcessMessage(Message* msg)
|
2008-03-23 02:43:56 +08:00
|
|
|
{
|
2013-07-29 08:17:07 +08:00
|
|
|
switch (msg->type()) {
|
2008-03-23 02:43:56 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kTimerMessage:
|
2012-06-16 10:37:59 +08:00
|
|
|
closeWindow(NULL);
|
2008-03-23 02:43:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
return ui::TipWindow::onProcessMessage(msg);
|
2008-03-23 02:43:56 +08:00
|
|
|
}
|
|
|
|
|
2015-04-17 00:07:14 +08:00
|
|
|
void StatusBar::onCelOpacityChange()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-06-11 23:11:11 +08:00
|
|
|
try {
|
2015-04-15 20:59:36 +08:00
|
|
|
ContextWriter writer(UIContext::instance(), 500);
|
2013-03-12 07:29:45 +08:00
|
|
|
|
2014-08-25 06:59:12 +08:00
|
|
|
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
|
|
|
|
if (range.enabled()) {
|
2015-02-09 22:40:43 +08:00
|
|
|
for (Cel* cel : get_unique_cels(writer.sprite(), range))
|
2015-04-17 00:07:14 +08:00
|
|
|
cel->setOpacity(m_slider->getValue());
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2014-08-25 06:59:12 +08:00
|
|
|
else {
|
|
|
|
Cel* cel = writer.cel();
|
|
|
|
if (cel) {
|
|
|
|
// Update the opacity
|
2015-04-17 00:07:14 +08:00
|
|
|
cel->setOpacity(m_slider->getValue());
|
2014-08-25 06:59:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the editors
|
|
|
|
update_screen_for_document(writer.document());
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2011-03-23 08:11:25 +08:00
|
|
|
catch (LockedDocumentException&) {
|
2009-06-11 23:11:11 +08:00
|
|
|
// do nothing
|
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2015-04-07 13:29:33 +08:00
|
|
|
void StatusBar::updateFromDocument(Editor* editor)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-06-11 23:11:11 +08:00
|
|
|
try {
|
2015-04-07 13:29:33 +08:00
|
|
|
if (editor && editor->document()) {
|
2015-04-10 22:10:42 +08:00
|
|
|
const DocumentReader reader(editor->document(), 100);
|
2015-04-17 00:14:39 +08:00
|
|
|
m_hasDoc = true;
|
2015-04-07 12:21:31 +08:00
|
|
|
m_commandsBox->setVisible(true);
|
|
|
|
|
|
|
|
// Cel opacity
|
|
|
|
const Cel* cel;
|
2015-04-07 13:29:33 +08:00
|
|
|
if (editor->sprite()->supportAlpha() &&
|
|
|
|
editor->layer() &&
|
|
|
|
editor->layer()->isImage() &&
|
|
|
|
!editor->layer()->isBackground() &&
|
|
|
|
(cel = editor->layer()->cel(editor->frame()))) {
|
2015-04-07 12:21:31 +08:00
|
|
|
m_slider->setValue(MID(0, cel->opacity(), 255));
|
|
|
|
m_slider->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_slider->setValue(255);
|
|
|
|
m_slider->setEnabled(false);
|
|
|
|
}
|
2009-06-11 23:11:11 +08:00
|
|
|
}
|
|
|
|
else {
|
2015-04-17 00:14:39 +08:00
|
|
|
m_hasDoc = false;
|
2015-04-07 12:21:31 +08:00
|
|
|
m_commandsBox->setVisible(false);
|
2009-06-11 23:11:11 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2015-04-17 00:14:39 +08:00
|
|
|
catch (const LockedDocumentException&) {
|
2010-07-04 02:26:27 +08:00
|
|
|
m_slider->setEnabled(false);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-10 08:18:32 +08:00
|
|
|
|
2015-04-07 13:29:33 +08:00
|
|
|
void StatusBar::updateCurrentFrame(Editor* editor)
|
2012-01-10 08:18:32 +08:00
|
|
|
{
|
2015-04-07 13:29:33 +08:00
|
|
|
if (editor && editor->sprite())
|
|
|
|
m_currentFrame->setTextf("%d", editor->frame()+1);
|
|
|
|
}
|
|
|
|
|
2012-01-10 08:18:32 +08:00
|
|
|
void StatusBar::newFrame()
|
|
|
|
{
|
|
|
|
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::NewFrame);
|
|
|
|
UIContext::instance()->executeCommand(cmd);
|
2015-04-07 13:29:33 +08:00
|
|
|
updateCurrentFrame(current_editor);
|
2012-01-10 08:18:32 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|