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.
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2013-01-21 05:40:37 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
#include "app/ui/preview_editor.h"
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2015-02-15 20:48:38 +08:00
|
|
|
#include "app/app.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/document.h"
|
|
|
|
#include "app/ini_file.h"
|
2015-03-10 00:57:16 +08:00
|
|
|
#include "app/loop_tag.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/modules/gui.h"
|
2015-02-15 20:48:38 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2014-04-27 03:05:29 +08:00
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/editor/editor_view.h"
|
2015-02-10 23:59:43 +08:00
|
|
|
#include "app/ui/editor/navigate_state.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/skin/skin_button.h"
|
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2014-04-27 03:05:29 +08:00
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
#include "app/ui/toolbar.h"
|
2014-05-18 08:27:44 +08:00
|
|
|
#include "app/ui_context.h"
|
2014-04-27 03:05:29 +08:00
|
|
|
#include "base/bind.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2015-02-10 23:59:43 +08:00
|
|
|
#include "gfx/rect.h"
|
2013-01-21 05:40:37 +08:00
|
|
|
#include "ui/base.h"
|
|
|
|
#include "ui/button.h"
|
|
|
|
#include "ui/close_event.h"
|
2013-01-21 08:58:16 +08:00
|
|
|
#include "ui/message.h"
|
2013-01-21 05:40:37 +08:00
|
|
|
#include "ui/system.h"
|
|
|
|
|
2015-03-10 00:57:16 +08:00
|
|
|
#include "doc/frame_tag.h"
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace app::skin;
|
|
|
|
using namespace ui;
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2015-02-10 23:59:43 +08:00
|
|
|
class MiniCenterButton : public SkinButton<CheckBox> {
|
|
|
|
public:
|
|
|
|
MiniCenterButton()
|
|
|
|
: SkinButton<CheckBox>(
|
|
|
|
PART_WINDOW_CENTER_BUTTON_NORMAL,
|
|
|
|
PART_WINDOW_CENTER_BUTTON_HOT,
|
|
|
|
PART_WINDOW_CENTER_BUTTON_SELECTED)
|
|
|
|
{
|
|
|
|
setup_bevels(this, 0, 0, 0, 0);
|
|
|
|
setDecorative(true);
|
|
|
|
setSelected(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onSetDecorativeWidgetBounds() override
|
|
|
|
{
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
Widget* window = getParent();
|
|
|
|
gfx::Rect rect(0, 0, 0, 0);
|
|
|
|
gfx::Size iconSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL);
|
|
|
|
gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL);
|
|
|
|
|
|
|
|
rect.w = iconSize.w;
|
|
|
|
rect.h = iconSize.h;
|
|
|
|
|
|
|
|
rect.offset(window->getBounds().x2() - 3*guiscale()
|
|
|
|
- iconSize.w - 1*guiscale()
|
|
|
|
- iconSize.w - 1*guiscale() - closeSize.w,
|
|
|
|
window->getBounds().y + 3*guiscale());
|
|
|
|
|
|
|
|
setBounds(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onProcessMessage(Message* msg) override
|
|
|
|
{
|
|
|
|
switch (msg->type()) {
|
|
|
|
|
|
|
|
case kSetCursorMessage:
|
|
|
|
ui::set_mouse_cursor(kArrowCursor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SkinButton<CheckBox>::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class MiniPlayButton : public SkinButton<Button> {
|
2013-01-21 08:58:16 +08:00
|
|
|
public:
|
|
|
|
MiniPlayButton()
|
|
|
|
: SkinButton<Button>(PART_WINDOW_PLAY_BUTTON_NORMAL,
|
|
|
|
PART_WINDOW_PLAY_BUTTON_HOT,
|
|
|
|
PART_WINDOW_PLAY_BUTTON_SELECTED)
|
|
|
|
, m_isPlaying(false)
|
|
|
|
{
|
|
|
|
setup_bevels(this, 0, 0, 0, 0);
|
|
|
|
setDecorative(true);
|
|
|
|
}
|
|
|
|
|
2015-04-07 03:12:28 +08:00
|
|
|
bool isPlaying() const { return m_isPlaying; }
|
2013-01-21 08:58:16 +08:00
|
|
|
|
2015-05-08 06:08:24 +08:00
|
|
|
Signal0<void> Popup;
|
|
|
|
|
2013-01-21 08:58:16 +08:00
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
void onClick(Event& ev) override
|
2013-01-21 08:58:16 +08:00
|
|
|
{
|
|
|
|
m_isPlaying = !m_isPlaying;
|
|
|
|
if (m_isPlaying)
|
|
|
|
setParts(PART_WINDOW_STOP_BUTTON_NORMAL,
|
|
|
|
PART_WINDOW_STOP_BUTTON_HOT,
|
|
|
|
PART_WINDOW_STOP_BUTTON_SELECTED);
|
|
|
|
else
|
|
|
|
setParts(PART_WINDOW_PLAY_BUTTON_NORMAL,
|
|
|
|
PART_WINDOW_PLAY_BUTTON_HOT,
|
|
|
|
PART_WINDOW_PLAY_BUTTON_SELECTED);
|
2013-03-12 09:27:13 +08:00
|
|
|
|
|
|
|
SkinButton<Button>::onClick(ev);
|
2013-01-21 08:58:16 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
void onSetDecorativeWidgetBounds() override
|
2013-01-21 08:58:16 +08:00
|
|
|
{
|
|
|
|
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
|
|
|
Widget* window = getParent();
|
2013-05-12 04:56:27 +08:00
|
|
|
gfx::Rect rect(0, 0, 0, 0);
|
2013-01-21 08:58:16 +08:00
|
|
|
gfx::Size playSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL);
|
|
|
|
gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL);
|
|
|
|
|
2013-05-12 04:56:27 +08:00
|
|
|
rect.w = playSize.w;
|
|
|
|
rect.h = playSize.h;
|
2013-01-21 08:58:16 +08:00
|
|
|
|
2014-11-26 09:33:45 +08:00
|
|
|
rect.offset(window->getBounds().x2() - 3*guiscale()
|
2015-02-10 23:59:43 +08:00
|
|
|
- playSize.w - 1*guiscale() - closeSize.w,
|
|
|
|
window->getBounds().y + 3*guiscale());
|
2013-01-21 08:58:16 +08:00
|
|
|
|
2013-05-12 04:56:27 +08:00
|
|
|
setBounds(rect);
|
2013-01-21 08:58:16 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
bool onProcessMessage(Message* msg) override
|
2013-01-21 08:58:16 +08:00
|
|
|
{
|
2013-07-29 08:17:07 +08:00
|
|
|
switch (msg->type()) {
|
2013-01-21 08:58:16 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kSetCursorMessage:
|
2014-11-26 08:30:56 +08:00
|
|
|
ui::set_mouse_cursor(kArrowCursor);
|
2013-01-21 08:58:16 +08:00
|
|
|
return true;
|
2015-05-08 06:08:24 +08:00
|
|
|
|
|
|
|
case kMouseUpMessage: {
|
|
|
|
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
|
|
|
if (mouseMsg->right()) {
|
|
|
|
if (hasCapture()) {
|
|
|
|
releaseMouse();
|
|
|
|
Popup();
|
|
|
|
|
|
|
|
setSelected(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-01-21 08:58:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return SkinButton<Button>::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_isPlaying;
|
|
|
|
};
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
PreviewEditorWindow::PreviewEditorWindow()
|
2015-02-10 20:07:04 +08:00
|
|
|
: Window(WithTitleBar, "Preview")
|
2013-01-21 05:40:37 +08:00
|
|
|
, m_docView(NULL)
|
2015-02-10 23:59:43 +08:00
|
|
|
, m_centerButton(new MiniCenterButton())
|
2013-01-21 08:58:16 +08:00
|
|
|
, m_playButton(new MiniPlayButton())
|
2015-03-10 00:57:16 +08:00
|
|
|
, m_refFrame(0)
|
2015-05-08 06:08:24 +08:00
|
|
|
, m_aniSpeed(1.0)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
child_spacing = 0;
|
|
|
|
setAutoRemap(false);
|
|
|
|
setWantFocus(false);
|
|
|
|
|
|
|
|
m_isEnabled = get_config_bool("MiniEditor", "Enabled", true);
|
2013-01-21 08:58:16 +08:00
|
|
|
|
2015-02-10 23:59:43 +08:00
|
|
|
m_centerButton->Click.connect(Bind<void>(&PreviewEditorWindow::onCenterClicked, this));
|
2015-02-10 20:38:07 +08:00
|
|
|
m_playButton->Click.connect(Bind<void>(&PreviewEditorWindow::onPlayClicked, this));
|
2015-05-08 06:08:24 +08:00
|
|
|
m_playButton->Popup.connect(Bind<void>(&PreviewEditorWindow::onPopupSpeed, this));
|
2015-02-10 23:59:43 +08:00
|
|
|
|
|
|
|
addChild(m_centerButton);
|
2013-01-21 08:58:16 +08:00
|
|
|
addChild(m_playButton);
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
PreviewEditorWindow::~PreviewEditorWindow()
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
set_config_bool("MiniEditor", "Enabled", m_isEnabled);
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::setPreviewEnabled(bool state)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
m_isEnabled = state;
|
|
|
|
|
|
|
|
updateUsingEditor(current_editor);
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
bool PreviewEditorWindow::onProcessMessage(ui::Message* msg)
|
2014-04-27 03:05:29 +08:00
|
|
|
{
|
|
|
|
switch (msg->type()) {
|
|
|
|
|
|
|
|
case kOpenMessage:
|
|
|
|
{
|
|
|
|
// Default bounds
|
2014-09-01 01:17:49 +08:00
|
|
|
int width = ui::display_w()/4;
|
|
|
|
int height = ui::display_h()/4;
|
2014-11-26 09:33:45 +08:00
|
|
|
int extra = 2*kEditorViewScrollbarWidth*guiscale();
|
2014-04-27 03:05:29 +08:00
|
|
|
setBounds(
|
|
|
|
gfx::Rect(
|
2014-09-01 01:17:49 +08:00
|
|
|
ui::display_w() - width - ToolBar::instance()->getBounds().w - extra,
|
|
|
|
ui::display_h() - height - StatusBar::instance()->getBounds().h - extra,
|
2014-04-27 03:05:29 +08:00
|
|
|
width, height));
|
|
|
|
|
|
|
|
load_window_pos(this, "MiniEditor");
|
2014-08-20 20:02:44 +08:00
|
|
|
invalidate();
|
2014-04-27 03:05:29 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kCloseMessage:
|
|
|
|
save_window_pos(this, "MiniEditor");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Window::onProcessMessage(msg);
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::onClose(ui::CloseEvent& ev)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
Button* closeButton = dynamic_cast<Button*>(ev.getSource());
|
|
|
|
if (closeButton != NULL &&
|
|
|
|
closeButton->getId() == SkinTheme::kThemeCloseButtonId) {
|
|
|
|
// Here we don't use "setMiniEditorEnabled" to change the state of
|
|
|
|
// "m_isEnabled" because we're coming from a close event of the
|
|
|
|
// window.
|
|
|
|
m_isEnabled = false;
|
|
|
|
|
|
|
|
// Redraw the tool bar because it shows the mini editor enabled
|
|
|
|
// state. TODO abstract this event
|
|
|
|
ToolBar::instance()->invalidate();
|
|
|
|
|
|
|
|
delete m_docView;
|
|
|
|
m_docView = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::onWindowResize()
|
2014-09-11 11:00:28 +08:00
|
|
|
{
|
|
|
|
Window::onWindowResize();
|
|
|
|
|
|
|
|
DocumentView* view = UIContext::instance()->activeView();
|
|
|
|
if (view)
|
|
|
|
updateUsingEditor(view->getEditor());
|
|
|
|
}
|
|
|
|
|
2015-02-10 23:59:43 +08:00
|
|
|
void PreviewEditorWindow::onCenterClicked()
|
|
|
|
{
|
|
|
|
if (m_centerButton->isSelected()) {
|
|
|
|
DocumentView* view = UIContext::instance()->activeView();
|
|
|
|
if (view)
|
|
|
|
updateUsingEditor(view->getEditor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::onPlayClicked()
|
2013-01-21 08:58:16 +08:00
|
|
|
{
|
2015-03-12 03:20:19 +08:00
|
|
|
Editor* miniEditor = (m_docView ? m_docView->getEditor(): nullptr);
|
2015-04-07 03:12:28 +08:00
|
|
|
if (!miniEditor || !miniEditor->document())
|
|
|
|
return;
|
2015-03-12 03:20:19 +08:00
|
|
|
|
2014-04-26 23:06:11 +08:00
|
|
|
if (m_playButton->isPlaying()) {
|
2015-04-07 03:12:28 +08:00
|
|
|
m_refFrame = miniEditor->frame();
|
|
|
|
miniEditor->play();
|
2014-04-26 23:06:11 +08:00
|
|
|
}
|
2015-04-07 03:12:28 +08:00
|
|
|
else
|
|
|
|
miniEditor->stop();
|
2013-01-21 08:58:16 +08:00
|
|
|
}
|
|
|
|
|
2015-05-08 06:08:24 +08:00
|
|
|
void PreviewEditorWindow::onPopupSpeed()
|
|
|
|
{
|
|
|
|
Editor* miniEditor = (m_docView ? m_docView->getEditor(): nullptr);
|
|
|
|
if (!miniEditor || !miniEditor->document())
|
|
|
|
return;
|
|
|
|
|
|
|
|
miniEditor->showAnimationSpeedMultiplierPopup();
|
|
|
|
m_aniSpeed = miniEditor->getAnimationSpeedMultiplier();
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::updateUsingEditor(Editor* editor)
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
if (!m_isEnabled || !editor) {
|
|
|
|
hideWindow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-07 03:12:28 +08:00
|
|
|
if (editor != current_editor)
|
|
|
|
return;
|
|
|
|
|
2014-07-30 12:28:15 +08:00
|
|
|
Document* document = editor->document();
|
2013-01-21 05:40:37 +08:00
|
|
|
Editor* miniEditor = (m_docView ? m_docView->getEditor(): NULL);
|
|
|
|
|
2014-04-14 01:29:54 +08:00
|
|
|
if (!isVisible())
|
|
|
|
openWindow();
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2014-04-14 01:29:54 +08:00
|
|
|
gfx::Rect visibleBounds = editor->getVisibleSpriteBounds();
|
2015-02-10 23:59:43 +08:00
|
|
|
gfx::Point centerPoint = visibleBounds.getCenter();
|
|
|
|
bool center = (m_centerButton->isSelected());
|
2014-04-14 01:29:54 +08:00
|
|
|
|
|
|
|
// Set the same location as in the given editor.
|
2014-07-30 12:28:15 +08:00
|
|
|
if (!miniEditor || miniEditor->document() != document) {
|
2014-04-14 01:29:54 +08:00
|
|
|
delete m_docView;
|
2015-02-10 23:59:43 +08:00
|
|
|
m_docView = new DocumentView(document, DocumentView::Preview);
|
2014-04-14 01:29:54 +08:00
|
|
|
addChild(m_docView);
|
|
|
|
|
|
|
|
miniEditor = m_docView->getEditor();
|
2014-12-28 22:06:11 +08:00
|
|
|
miniEditor->setZoom(render::Zoom(1, 1));
|
2015-04-07 03:12:28 +08:00
|
|
|
miniEditor->setLayer(editor->layer());
|
|
|
|
miniEditor->setFrame(editor->frame());
|
2015-02-10 23:59:43 +08:00
|
|
|
miniEditor->setState(EditorStatePtr(new NavigateState));
|
2015-05-08 06:08:24 +08:00
|
|
|
miniEditor->setAnimationSpeedMultiplier(m_aniSpeed);
|
2014-04-14 01:29:54 +08:00
|
|
|
layout();
|
2015-02-10 23:59:43 +08:00
|
|
|
center = true;
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
2014-04-14 01:29:54 +08:00
|
|
|
|
2015-02-10 23:59:43 +08:00
|
|
|
if (center)
|
|
|
|
miniEditor->centerInSpritePoint(centerPoint);
|
|
|
|
|
2015-04-07 03:12:28 +08:00
|
|
|
if (!m_playButton->isPlaying()) {
|
|
|
|
miniEditor->stop();
|
|
|
|
miniEditor->setLayer(editor->layer());
|
|
|
|
miniEditor->setFrame(editor->frame());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (miniEditor->isPlaying()) {
|
|
|
|
doc::FrameTag* tag = get_animation_tag(editor->sprite(), editor->frame());
|
|
|
|
doc::FrameTag* playingTag = get_animation_tag(editor->sprite(), m_refFrame);
|
|
|
|
if (tag != playingTag)
|
|
|
|
miniEditor->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!miniEditor->isPlaying())
|
|
|
|
miniEditor->setFrame(m_refFrame = editor->frame());
|
|
|
|
|
|
|
|
miniEditor->play();
|
|
|
|
}
|
2013-01-21 05:40:37 +08:00
|
|
|
}
|
|
|
|
|
2015-02-10 23:59:43 +08:00
|
|
|
void PreviewEditorWindow::uncheckCenterButton()
|
|
|
|
{
|
|
|
|
if (m_centerButton->isSelected())
|
|
|
|
m_centerButton->setSelected(false);
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:38:07 +08:00
|
|
|
void PreviewEditorWindow::hideWindow()
|
2013-01-21 05:40:37 +08:00
|
|
|
{
|
|
|
|
delete m_docView;
|
|
|
|
m_docView = NULL;
|
|
|
|
|
|
|
|
if (isVisible())
|
|
|
|
closeWindow(NULL);
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|