Independent scroll/zoom in Preview window (part of issue #407)

This commit is contained in:
David Capello 2015-02-10 12:59:43 -03:00
parent 5f78fbe354
commit 22f35ab249
15 changed files with 452 additions and 163 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -171,15 +171,18 @@
<part id="sunken_mini_focused" x="16" y="80" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" /> <part id="sunken_mini_focused" x="16" y="80" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" />
<part id="window" x="0" y="0" w1="3" w2="7" w3="3" h1="15" h2="4" h3="5" /> <part id="window" x="0" y="0" w1="3" w2="7" w3="3" h1="15" h2="4" h3="5" />
<part id="menu" x="0" y="96" w1="3" w2="10" w3="3" h1="3" h2="9" h3="4" /> <part id="menu" x="0" y="96" w1="3" w2="10" w3="3" h1="3" h2="9" h3="4" />
<part id="window_close_button_normal" x="16" y= "0" w="9" h="11" /> <part id="window_close_button_normal" x="16" y="0" w="9" h="11" />
<part id="window_close_button_hot" x="16" y="16" w="9" h="11" /> <part id="window_close_button_hot" x="25" y="0" w="9" h="11" />
<part id="window_close_button_selected" x="16" y="32" w="9" h="11" /> <part id="window_close_button_selected" x="34" y="0" w="9" h="11" />
<part id="window_play_button_normal" x="25" y= "0" w="9" h="11" /> <part id="window_play_button_normal" x="16" y="11" w="9" h="11" />
<part id="window_play_button_hot" x="25" y="16" w="9" h="11" /> <part id="window_play_button_hot" x="25" y="11" w="9" h="11" />
<part id="window_play_button_selected" x="25" y="32" w="9" h="11" /> <part id="window_play_button_selected" x="34" y="11" w="9" h="11" />
<part id="window_stop_button_normal" x="34" y= "0" w="9" h="11" /> <part id="window_stop_button_normal" x="16" y="22" w="9" h="11" />
<part id="window_stop_button_hot" x="34" y="16" w="9" h="11" /> <part id="window_stop_button_hot" x="25" y="22" w="9" h="11" />
<part id="window_stop_button_selected" x="34" y="32" w="9" h="11" /> <part id="window_stop_button_selected" x="34" y="22" w="9" h="11" />
<part id="window_center_button_normal" x="16" y="33" w="9" h="11" />
<part id="window_center_button_hot" x="25" y="33" w="9" h="11" />
<part id="window_center_button_selected" x="34" y="33" w="9" h="11" />
<part id="slider_full" x="0" y="144" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" /> <part id="slider_full" x="0" y="144" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" />
<part id="slider_empty" x="16" y="144" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" /> <part id="slider_empty" x="16" y="144" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" />
<part id="slider_full_focused" x="0" y="160" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" /> <part id="slider_full_focused" x="0" y="160" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" />

View File

@ -280,10 +280,12 @@ add_library(app-lib
ui/editor/editor_view.cpp ui/editor/editor_view.cpp
ui/editor/moving_cel_state.cpp ui/editor/moving_cel_state.cpp
ui/editor/moving_pixels_state.cpp ui/editor/moving_pixels_state.cpp
ui/editor/navigate_state.cpp
ui/editor/pixels_movement.cpp ui/editor/pixels_movement.cpp
ui/editor/scrolling_state.cpp ui/editor/scrolling_state.cpp
ui/editor/select_box_state.cpp ui/editor/select_box_state.cpp
ui/editor/standby_state.cpp ui/editor/standby_state.cpp
ui/editor/state_with_wheel_behavior.cpp
ui/editor/tool_loop_impl.cpp ui/editor/tool_loop_impl.cpp
ui/editor/transform_handles.cpp ui/editor/transform_handles.cpp
ui/editor/zooming_state.cpp ui/editor/zooming_state.cpp

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2013 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -47,8 +47,7 @@ using namespace ui;
class AppEditor : public Editor, class AppEditor : public Editor,
public EditorObserver, public EditorObserver,
public EditorCustomizationDelegate public EditorCustomizationDelegate {
{
public: public:
AppEditor(Document* document) : Editor(document) { AppEditor(Document* document) : Editor(document) {
addObserver(this); addObserver(this);
@ -150,14 +149,36 @@ private:
}; };
class PreviewEditor : public Editor,
public EditorObserver {
public:
PreviewEditor(Document* document)
: Editor(document, Editor::kShowOutside) // Don't show grid/mask in preview preview
{
addObserver(this);
}
~PreviewEditor() {
removeObserver(this);
}
private:
void onScrollChanged(Editor* editor) override {
if (hasCapture()) {
// TODO create a signal
App::instance()->getMainWindow()->getPreviewEditor()->uncheckCenterButton();
}
}
};
DocumentView::DocumentView(Document* document, Type type) DocumentView::DocumentView(Document* document, Type type)
: Box(JI_VERTICAL) : Box(JI_VERTICAL)
, m_document(document) , m_document(document)
, m_view(new EditorView(type == Normal ? EditorView::CurrentEditorMode: , m_view(new EditorView(type == Normal ? EditorView::CurrentEditorMode:
EditorView::AlwaysSelected)) EditorView::AlwaysSelected))
, m_editor(type == Normal ? , m_editor((type == Normal ?
new AppEditor(document): (Editor*)new AppEditor(document):
new Editor(document, Editor::kShowOutside)) // Don't show grid/mask in preview preview (Editor*)new PreviewEditor(document)))
{ {
addChild(m_view); addChild(m_view);

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2013 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -41,7 +41,7 @@ namespace app {
public: public:
enum Type { enum Type {
Normal, Normal,
Mini Preview
}; };
DocumentView(Document* document, Type type); DocumentView(Document* document, Type type);

View File

@ -0,0 +1,75 @@
/* 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 as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/editor/navigate_state.h"
#include "app/ui/editor/editor.h"
#include "app/ui/editor/scrolling_state.h"
namespace app {
using namespace ui;
NavigateState::NavigateState()
{
}
bool NavigateState::onMouseDown(Editor* editor, MouseMessage* msg)
{
if (editor->hasCapture())
return true;
// UIContext* context = UIContext::instance();
// // When an editor is clicked the current view is changed.
// context->setActiveView(editor->getDocumentView());
// Start scroll loop
EditorStatePtr newState(new ScrollingState());
editor->setState(newState);
newState->onMouseDown(editor, msg);
return true;
}
bool NavigateState::onMouseUp(Editor* editor, MouseMessage* msg)
{
editor->releaseMouse();
return true;
}
bool NavigateState::onMouseMove(Editor* editor, MouseMessage* msg)
{
editor->moveDrawingCursor();
editor->updateStatusBar();
return true;
}
bool NavigateState::onKeyDown(Editor* editor, KeyMessage* msg)
{
return false;
}
bool NavigateState::onKeyUp(Editor* editor, KeyMessage* msg)
{
return false;
}
} // namespace app

View File

@ -0,0 +1,39 @@
/* 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 as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_UI_EDITOR_NAVIGATE_STATE_H_INCLUDED
#define APP_UI_EDITOR_NAVIGATE_STATE_H_INCLUDED
#pragma once
#include "app/ui/editor/state_with_wheel_behavior.h"
namespace app {
class NavigateState : public StateWithWheelBehavior {
public:
NavigateState();
virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override;
virtual bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override;
};
} // namespace app
#endif

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2013 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -32,7 +32,6 @@
#include "app/tools/ink.h" #include "app/tools/ink.h"
#include "app/tools/pick_ink.h" #include "app/tools/pick_ink.h"
#include "app/tools/tool.h" #include "app/tools/tool.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/drawing_state.h" #include "app/ui/editor/drawing_state.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_customization_delegate.h" #include "app/ui/editor/editor_customization_delegate.h"
@ -61,14 +60,6 @@ namespace app {
using namespace ui; using namespace ui;
enum WHEEL_ACTION { WHEEL_NONE,
WHEEL_ZOOM,
WHEEL_VSCROLL,
WHEEL_HSCROLL,
WHEEL_FG,
WHEEL_BG,
WHEEL_FRAME };
static CursorType rotated_size_cursors[] = { static CursorType rotated_size_cursors[] = {
kSizeECursor, kSizeECursor,
kSizeNECursor, kSizeNECursor,
@ -302,129 +293,6 @@ bool StandbyState::onMouseMove(Editor* editor, MouseMessage* msg)
return true; return true;
} }
bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg)
{
int dz = msg->wheelDelta().x + msg->wheelDelta().y;
WHEEL_ACTION wheelAction = WHEEL_NONE;
bool scrollBigSteps = false;
// Alt+mouse wheel changes the fg/bg colors
if (msg->altPressed()) {
if (msg->shiftPressed())
wheelAction = WHEEL_BG;
else
wheelAction = WHEEL_FG;
}
// Normal behavior: mouse wheel zooms
else if (UIContext::instance()->settings()->getZoomWithScrollWheel()) {
if (msg->ctrlPressed())
wheelAction = WHEEL_FRAME;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_ZOOM;
}
// For laptops, it's convenient to that Ctrl+wheel zoom (because
// it's the "pinch" gesture).
else {
if (msg->ctrlPressed())
wheelAction = WHEEL_ZOOM;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_VSCROLL;
}
switch (wheelAction) {
case WHEEL_NONE:
// Do nothing
break;
case WHEEL_FG:
{
int newIndex = 0;
if (ColorBar::instance()->getFgColor().getType() == app::Color::IndexType) {
newIndex = ColorBar::instance()->getFgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255);
}
ColorBar::instance()->setFgColor(app::Color::fromIndex(newIndex));
}
break;
case WHEEL_BG:
{
int newIndex = 0;
if (ColorBar::instance()->getBgColor().getType() == app::Color::IndexType) {
newIndex = ColorBar::instance()->getBgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255);
}
ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex));
}
break;
case WHEEL_FRAME:
{
Command* command = CommandsModule::instance()->getCommandByName
((dz < 0) ? CommandId::GotoNextFrame:
CommandId::GotoPreviousFrame);
if (command)
UIContext::instance()->executeCommand(command, NULL);
}
break;
case WHEEL_ZOOM: {
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
render::Zoom zoom = editor->zoom();
if (dz < 0) {
while (dz++ < 0)
zoom.in();
}
else {
while (dz-- > 0)
zoom.out();
}
if (editor->zoom() != zoom) {
editor->setZoomAndCenterInMouse(zoom,
mouseMsg->position(), Editor::kDontCenterOnZoom);
}
break;
}
case WHEEL_HSCROLL:
case WHEEL_VSCROLL: {
View* view = View::getView(editor);
gfx::Rect vp = view->getViewportBounds();
gfx::Point delta(0, 0);
if (wheelAction == WHEEL_HSCROLL) {
delta.x = dz * vp.w;
}
else {
delta.y = dz * vp.h;
}
if (scrollBigSteps) {
delta /= 2;
}
else {
delta /= 10;
}
gfx::Point scroll = view->getViewScroll();
editor->hideDrawingCursor();
editor->setEditorScroll(scroll+delta, true);
editor->showDrawingCursor();
break;
}
}
return true;
}
bool StandbyState::onSetCursor(Editor* editor) bool StandbyState::onSetCursor(Editor* editor)
{ {
tools::Ink* ink = editor->getCurrentEditorInk(); tools::Ink* ink = editor->getCurrentEditorInk();

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2013 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,14 +21,14 @@
#pragma once #pragma once
#include "app/ui/editor/editor_decorator.h" #include "app/ui/editor/editor_decorator.h"
#include "app/ui/editor/editor_state.h"
#include "app/ui/editor/handle_type.h" #include "app/ui/editor/handle_type.h"
#include "app/ui/editor/state_with_wheel_behavior.h"
#include "gfx/transformation.h" #include "gfx/transformation.h"
namespace app { namespace app {
class TransformHandles; class TransformHandles;
class StandbyState : public EditorState { class StandbyState : public StateWithWheelBehavior {
public: public:
StandbyState(); StandbyState();
virtual ~StandbyState(); virtual ~StandbyState();
@ -38,7 +38,6 @@ namespace app {
virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override; virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onMouseWheel(Editor* editor, ui::MouseMessage* msg) override;
virtual bool onSetCursor(Editor* editor) override; virtual bool onSetCursor(Editor* editor) override;
virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override; virtual bool onKeyDown(Editor* editor, ui::KeyMessage* msg) override;
virtual bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override; virtual bool onKeyUp(Editor* editor, ui::KeyMessage* msg) override;

View File

@ -0,0 +1,167 @@
/* 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 as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/editor/state_with_wheel_behavior.h"
#include "app/commands/commands.h"
#include "app/settings/settings.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h"
#include "app/ui_context.h"
#include "ui/message.h"
namespace app {
using namespace ui;
enum WHEEL_ACTION { WHEEL_NONE,
WHEEL_ZOOM,
WHEEL_VSCROLL,
WHEEL_HSCROLL,
WHEEL_FG,
WHEEL_BG,
WHEEL_FRAME };
bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
{
int dz = msg->wheelDelta().x + msg->wheelDelta().y;
WHEEL_ACTION wheelAction = WHEEL_NONE;
bool scrollBigSteps = false;
// Alt+mouse wheel changes the fg/bg colors
if (msg->altPressed()) {
if (msg->shiftPressed())
wheelAction = WHEEL_BG;
else
wheelAction = WHEEL_FG;
}
// Normal behavior: mouse wheel zooms
else if (UIContext::instance()->settings()->getZoomWithScrollWheel()) {
if (msg->ctrlPressed())
wheelAction = WHEEL_FRAME;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_ZOOM;
}
// For laptops, it's convenient to that Ctrl+wheel zoom (because
// it's the "pinch" gesture).
else {
if (msg->ctrlPressed())
wheelAction = WHEEL_ZOOM;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
wheelAction = WHEEL_HSCROLL;
else
wheelAction = WHEEL_VSCROLL;
}
switch (wheelAction) {
case WHEEL_NONE:
// Do nothing
break;
case WHEEL_FG:
{
int newIndex = 0;
if (ColorBar::instance()->getFgColor().getType() == app::Color::IndexType) {
newIndex = ColorBar::instance()->getFgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255);
}
ColorBar::instance()->setFgColor(app::Color::fromIndex(newIndex));
}
break;
case WHEEL_BG:
{
int newIndex = 0;
if (ColorBar::instance()->getBgColor().getType() == app::Color::IndexType) {
newIndex = ColorBar::instance()->getBgColor().getIndex() + dz;
newIndex = MID(0, newIndex, 255);
}
ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex));
}
break;
case WHEEL_FRAME:
{
Command* command = CommandsModule::instance()->getCommandByName
((dz < 0) ? CommandId::GotoNextFrame:
CommandId::GotoPreviousFrame);
if (command)
UIContext::instance()->executeCommand(command, NULL);
}
break;
case WHEEL_ZOOM: {
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
render::Zoom zoom = editor->zoom();
if (dz < 0) {
while (dz++ < 0)
zoom.in();
}
else {
while (dz-- > 0)
zoom.out();
}
if (editor->zoom() != zoom) {
editor->setZoomAndCenterInMouse(zoom,
mouseMsg->position(), Editor::kDontCenterOnZoom);
}
break;
}
case WHEEL_HSCROLL:
case WHEEL_VSCROLL: {
View* view = View::getView(editor);
gfx::Rect vp = view->getViewportBounds();
gfx::Point delta(0, 0);
if (wheelAction == WHEEL_HSCROLL) {
delta.x = dz * vp.w;
}
else {
delta.y = dz * vp.h;
}
if (scrollBigSteps) {
delta /= 2;
}
else {
delta /= 10;
}
gfx::Point scroll = view->getViewScroll();
editor->hideDrawingCursor();
editor->setEditorScroll(scroll+delta, true);
editor->showDrawingCursor();
break;
}
}
return true;
}
} // namespace app

View File

@ -0,0 +1,34 @@
/* 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 as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef APP_UI_STATE_WITH_WHEEL_BEHAVIOR_H_INCLUDED
#define APP_UI_STATE_WITH_WHEEL_BEHAVIOR_H_INCLUDED
#pragma once
#include "app/ui/editor/editor_state.h"
namespace app {
class StateWithWheelBehavior : public EditorState {
public:
virtual bool onMouseWheel(Editor* editor, ui::MouseMessage* msg) override;
};
} // namespace app
#endif

View File

@ -31,14 +31,15 @@
#include "app/settings/settings.h" #include "app/settings/settings.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_view.h" #include "app/ui/editor/editor_view.h"
#include "app/ui/editor/navigate_state.h"
#include "app/ui/skin/skin_button.h" #include "app/ui/skin/skin_button.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
#include "app/ui/toolbar.h" #include "app/ui/toolbar.h"
#include "app/ui_context.h" #include "app/ui_context.h"
#include "base/bind.h" #include "base/bind.h"
#include "gfx/rect.h"
#include "doc/sprite.h" #include "doc/sprite.h"
#include "gfx/rect.h"
#include "ui/base.h" #include "ui/base.h"
#include "ui/button.h" #include "ui/button.h"
#include "ui/close_event.h" #include "ui/close_event.h"
@ -50,6 +51,52 @@ namespace app {
using namespace app::skin; using namespace app::skin;
using namespace ui; using namespace ui;
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);
}
};
class MiniPlayButton : public SkinButton<Button> { class MiniPlayButton : public SkinButton<Button> {
public: public:
MiniPlayButton() MiniPlayButton()
@ -92,8 +139,8 @@ protected:
rect.h = playSize.h; rect.h = playSize.h;
rect.offset(window->getBounds().x2() - 3*guiscale() rect.offset(window->getBounds().x2() - 3*guiscale()
- playSize.w - 1*guiscale() - closeSize.w, - playSize.w - 1*guiscale() - closeSize.w,
window->getBounds().y + 3*guiscale()); window->getBounds().y + 3*guiscale());
setBounds(rect); setBounds(rect);
} }
@ -117,6 +164,7 @@ private:
PreviewEditorWindow::PreviewEditorWindow() PreviewEditorWindow::PreviewEditorWindow()
: Window(WithTitleBar, "Preview") : Window(WithTitleBar, "Preview")
, m_docView(NULL) , m_docView(NULL)
, m_centerButton(new MiniCenterButton())
, m_playButton(new MiniPlayButton()) , m_playButton(new MiniPlayButton())
, m_playTimer(10) , m_playTimer(10)
, m_pingPongForward(true) , m_pingPongForward(true)
@ -127,7 +175,10 @@ PreviewEditorWindow::PreviewEditorWindow()
m_isEnabled = get_config_bool("MiniEditor", "Enabled", true); m_isEnabled = get_config_bool("MiniEditor", "Enabled", true);
m_centerButton->Click.connect(Bind<void>(&PreviewEditorWindow::onCenterClicked, this));
m_playButton->Click.connect(Bind<void>(&PreviewEditorWindow::onPlayClicked, this)); m_playButton->Click.connect(Bind<void>(&PreviewEditorWindow::onPlayClicked, this));
addChild(m_centerButton);
addChild(m_playButton); addChild(m_playButton);
m_playTimer.Tick.connect(&PreviewEditorWindow::onPlaybackTick, this); m_playTimer.Tick.connect(&PreviewEditorWindow::onPlaybackTick, this);
@ -203,6 +254,15 @@ void PreviewEditorWindow::onWindowResize()
updateUsingEditor(view->getEditor()); updateUsingEditor(view->getEditor());
} }
void PreviewEditorWindow::onCenterClicked()
{
if (m_centerButton->isSelected()) {
DocumentView* view = UIContext::instance()->activeView();
if (view)
updateUsingEditor(view->getEditor());
}
}
void PreviewEditorWindow::onPlayClicked() void PreviewEditorWindow::onPlayClicked()
{ {
if (m_playButton->isPlaying()) { if (m_playButton->isPlaying()) {
@ -236,25 +296,35 @@ void PreviewEditorWindow::updateUsingEditor(Editor* editor)
openWindow(); openWindow();
gfx::Rect visibleBounds = editor->getVisibleSpriteBounds(); gfx::Rect visibleBounds = editor->getVisibleSpriteBounds();
gfx::Point pt = visibleBounds.getCenter(); gfx::Point centerPoint = visibleBounds.getCenter();
bool center = (m_centerButton->isSelected());
// Set the same location as in the given editor. // Set the same location as in the given editor.
if (!miniEditor || miniEditor->document() != document) { if (!miniEditor || miniEditor->document() != document) {
delete m_docView; delete m_docView;
m_docView = new DocumentView(document, DocumentView::Mini); // MiniEditorDocumentView(document, this); m_docView = new DocumentView(document, DocumentView::Preview);
addChild(m_docView); addChild(m_docView);
miniEditor = m_docView->getEditor(); miniEditor = m_docView->getEditor();
miniEditor->setZoom(render::Zoom(1, 1)); miniEditor->setZoom(render::Zoom(1, 1));
miniEditor->setState(EditorStatePtr(new EditorState)); miniEditor->setState(EditorStatePtr(new NavigateState));
layout(); layout();
center = true;
} }
miniEditor->centerInSpritePoint(pt); if (center)
miniEditor->centerInSpritePoint(centerPoint);
miniEditor->setLayer(editor->layer()); miniEditor->setLayer(editor->layer());
miniEditor->setFrame(editor->frame()); miniEditor->setFrame(editor->frame());
} }
void PreviewEditorWindow::uncheckCenterButton()
{
if (m_centerButton->isSelected())
m_centerButton->setSelected(false);
}
void PreviewEditorWindow::hideWindow() void PreviewEditorWindow::hideWindow()
{ {
delete m_docView; delete m_docView;

View File

@ -25,6 +25,7 @@
#include "ui/window.h" #include "ui/window.h"
namespace app { namespace app {
class MiniCenterButton;
class MiniPlayButton; class MiniPlayButton;
class PreviewEditorWindow : public ui::Window { class PreviewEditorWindow : public ui::Window {
@ -36,6 +37,7 @@ namespace app {
void setPreviewEnabled(bool state); void setPreviewEnabled(bool state);
void updateUsingEditor(Editor* editor); void updateUsingEditor(Editor* editor);
void uncheckCenterButton();
protected: protected:
bool onProcessMessage(ui::Message* msg) override; bool onProcessMessage(ui::Message* msg) override;
@ -43,12 +45,14 @@ namespace app {
void onWindowResize() override; void onWindowResize() override;
private: private:
void onCenterClicked();
void onPlayClicked(); void onPlayClicked();
void onPlaybackTick(); void onPlaybackTick();
void hideWindow(); void hideWindow();
bool m_isEnabled; bool m_isEnabled;
DocumentView* m_docView; DocumentView* m_docView;
MiniCenterButton* m_centerButton;
MiniPlayButton* m_playButton; MiniPlayButton* m_playButton;
ui::Timer m_playTimer; ui::Timer m_playTimer;

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2013 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -71,6 +71,10 @@ namespace app {
PART_WINDOW_STOP_BUTTON_HOT, PART_WINDOW_STOP_BUTTON_HOT,
PART_WINDOW_STOP_BUTTON_SELECTED, PART_WINDOW_STOP_BUTTON_SELECTED,
PART_WINDOW_CENTER_BUTTON_NORMAL,
PART_WINDOW_CENTER_BUTTON_HOT,
PART_WINDOW_CENTER_BUTTON_SELECTED,
SKIN_PART_NESW(PART_SLIDER_FULL), SKIN_PART_NESW(PART_SLIDER_FULL),
SKIN_PART_NESW(PART_SLIDER_EMPTY), SKIN_PART_NESW(PART_SLIDER_EMPTY),
SKIN_PART_NESW(PART_SLIDER_FULL_FOCUSED), SKIN_PART_NESW(PART_SLIDER_FULL_FOCUSED),

View File

@ -1,5 +1,5 @@
/* Aseprite /* Aseprite
* Copyright (C) 2001-2014 David Capello * Copyright (C) 2001-2015 David Capello
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -188,6 +188,9 @@ SkinTheme::SkinTheme()
sheet_mapping["window_stop_button_normal"] = PART_WINDOW_STOP_BUTTON_NORMAL; sheet_mapping["window_stop_button_normal"] = PART_WINDOW_STOP_BUTTON_NORMAL;
sheet_mapping["window_stop_button_hot"] = PART_WINDOW_STOP_BUTTON_HOT; sheet_mapping["window_stop_button_hot"] = PART_WINDOW_STOP_BUTTON_HOT;
sheet_mapping["window_stop_button_selected"] = PART_WINDOW_STOP_BUTTON_SELECTED; sheet_mapping["window_stop_button_selected"] = PART_WINDOW_STOP_BUTTON_SELECTED;
sheet_mapping["window_center_button_normal"] = PART_WINDOW_CENTER_BUTTON_NORMAL;
sheet_mapping["window_center_button_hot"] = PART_WINDOW_CENTER_BUTTON_HOT;
sheet_mapping["window_center_button_selected"] = PART_WINDOW_CENTER_BUTTON_SELECTED;
sheet_mapping["slider_full"] = PART_SLIDER_FULL_NW; sheet_mapping["slider_full"] = PART_SLIDER_FULL_NW;
sheet_mapping["slider_empty"] = PART_SLIDER_EMPTY_NW; sheet_mapping["slider_empty"] = PART_SLIDER_EMPTY_NW;
sheet_mapping["slider_full_focused"] = PART_SLIDER_FULL_FOCUSED_NW; sheet_mapping["slider_full_focused"] = PART_SLIDER_FULL_FOCUSED_NW;