mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 21:44:22 +00:00
Now when an entry box in "Canvas Size" is modified, the rulers are moved.
This commit is contained in:
parent
312cab0902
commit
ef4ce8a7f2
@ -19,6 +19,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "app/color_utils.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "commands/command.h"
|
||||
#include "document_wrappers.h"
|
||||
@ -35,6 +36,9 @@
|
||||
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
// Disable warning about usage of "this" in initializer list.
|
||||
#pragma warning(disable:4355)
|
||||
|
||||
// Frame used to show canvas parameters.
|
||||
class CanvasSizeFrame : public Frame
|
||||
, public SelectTileDelegate
|
||||
@ -44,8 +48,9 @@ public:
|
||||
: Frame(false, "Canvas Size")
|
||||
, m_editor(current_editor)
|
||||
, m_rect(-left, -top,
|
||||
current_editor->getSprite()->getWidth() + right,
|
||||
current_editor->getSprite()->getHeight() + bottom)
|
||||
current_editor->getSprite()->getWidth() + left + right,
|
||||
current_editor->getSprite()->getHeight() + top + bottom)
|
||||
, m_selectTileState(new SelectTileState(this, m_rect))
|
||||
{
|
||||
m_mainBox = load_widget("canvas_size.xml", "main_box");
|
||||
get_widgets(m_mainBox,
|
||||
@ -62,7 +67,12 @@ public:
|
||||
m_top->setTextf("%d", top);
|
||||
m_bottom->setTextf("%d", bottom);
|
||||
|
||||
m_editor->setDefaultState(EditorStatePtr(new SelectTileState(this, m_rect)));
|
||||
m_left ->EntryChange.connect(Bind<void>(&CanvasSizeFrame::onEntriesChange, this));
|
||||
m_right ->EntryChange.connect(Bind<void>(&CanvasSizeFrame::onEntriesChange, this));
|
||||
m_top ->EntryChange.connect(Bind<void>(&CanvasSizeFrame::onEntriesChange, this));
|
||||
m_bottom->EntryChange.connect(Bind<void>(&CanvasSizeFrame::onEntriesChange, this));
|
||||
|
||||
m_editor->setDefaultState(m_selectTileState);
|
||||
}
|
||||
|
||||
~CanvasSizeFrame()
|
||||
@ -77,6 +87,7 @@ public:
|
||||
int getTop() const { return m_top->getTextInt(); }
|
||||
int getBottom() const { return m_bottom->getTextInt(); }
|
||||
|
||||
protected:
|
||||
// SelectTileDelegate impleentation
|
||||
virtual void onChangeRectangle(const gfx::Rect& rect) OVERRIDE
|
||||
{
|
||||
@ -88,7 +99,21 @@ public:
|
||||
m_bottom->setTextf("%d", (m_rect.y + m_rect.h) - current_editor->getSprite()->getHeight());
|
||||
}
|
||||
|
||||
protected:
|
||||
void onEntriesChange()
|
||||
{
|
||||
int left = getLeft();
|
||||
int top = getTop();
|
||||
|
||||
m_rect = gfx::Rect(-left, -top,
|
||||
m_editor->getSprite()->getWidth() + left + getRight(),
|
||||
m_editor->getSprite()->getHeight() + top + getBottom());
|
||||
|
||||
static_cast<SelectTileState*>(m_selectTileState.get())->setBoxBounds(m_rect);
|
||||
|
||||
// Redraw new rulers position
|
||||
m_editor->invalidate();
|
||||
}
|
||||
|
||||
virtual void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE
|
||||
{
|
||||
Frame::onBroadcastMouseMessage(targets);
|
||||
@ -100,12 +125,13 @@ protected:
|
||||
private:
|
||||
Editor* m_editor;
|
||||
Widget* m_mainBox;
|
||||
Widget* m_left;
|
||||
Widget* m_right;
|
||||
Widget* m_top;
|
||||
Widget* m_bottom;
|
||||
Entry* m_left;
|
||||
Entry* m_right;
|
||||
Entry* m_top;
|
||||
Entry* m_bottom;
|
||||
Widget* m_ok;
|
||||
gfx::Rect m_rect;
|
||||
EditorStatePtr m_selectTileState;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -35,10 +35,24 @@ SelectTileState::SelectTileState(SelectTileDelegate* delegate, const gfx::Rect&
|
||||
, m_rulers(4)
|
||||
, m_movingRuler(-1)
|
||||
{
|
||||
m_rulers[H1] = Ruler(Ruler::Horizontal, rc.y);
|
||||
m_rulers[H2] = Ruler(Ruler::Horizontal, rc.y+rc.h);
|
||||
m_rulers[V1] = Ruler(Ruler::Vertical, rc.x);
|
||||
m_rulers[V2] = Ruler(Ruler::Vertical, rc.x+rc.w);
|
||||
setBoxBounds(rc);
|
||||
}
|
||||
|
||||
gfx::Rect SelectTileState::getBoxBounds() const
|
||||
{
|
||||
int x1 = std::min(m_rulers[V1].getPosition(), m_rulers[V2].getPosition());
|
||||
int y1 = std::min(m_rulers[H1].getPosition(), m_rulers[H2].getPosition());
|
||||
int x2 = std::max(m_rulers[V1].getPosition(), m_rulers[V2].getPosition());
|
||||
int y2 = std::max(m_rulers[H1].getPosition(), m_rulers[H2].getPosition());
|
||||
return gfx::Rect(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
void SelectTileState::setBoxBounds(const gfx::Rect& box)
|
||||
{
|
||||
m_rulers[H1] = Ruler(Ruler::Horizontal, box.y);
|
||||
m_rulers[H2] = Ruler(Ruler::Horizontal, box.y+box.h);
|
||||
m_rulers[V1] = Ruler(Ruler::Vertical, box.x);
|
||||
m_rulers[V2] = Ruler(Ruler::Vertical, box.x+box.w);
|
||||
}
|
||||
|
||||
bool SelectTileState::onMouseDown(Editor* editor, Message* msg)
|
||||
@ -165,15 +179,6 @@ void SelectTileState::postRenderDecorator(EditorPostRender* render)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gfx::Rect SelectTileState::getBoxBounds() const
|
||||
{
|
||||
int x1 = std::min(m_rulers[V1].getPosition(), m_rulers[V2].getPosition());
|
||||
int y1 = std::min(m_rulers[H1].getPosition(), m_rulers[H2].getPosition());
|
||||
int x2 = std::max(m_rulers[V1].getPosition(), m_rulers[V2].getPosition());
|
||||
int y2 = std::max(m_rulers[H1].getPosition(), m_rulers[H2].getPosition());
|
||||
return gfx::Rect(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
bool SelectTileState::touchRuler(Editor* editor, Ruler& ruler, int x, int y)
|
||||
{
|
||||
|
@ -41,6 +41,10 @@ class SelectTileState : public StandbyState
|
||||
public:
|
||||
SelectTileState(SelectTileDelegate* delegate, const gfx::Rect& rc);
|
||||
|
||||
// Returns the bounding box arranged by the rulers.
|
||||
gfx::Rect getBoxBounds() const;
|
||||
void setBoxBounds(const gfx::Rect& rc);
|
||||
|
||||
// EditorState overrides
|
||||
virtual bool onMouseDown(Editor* editor, Message* msg) OVERRIDE;
|
||||
virtual bool onMouseUp(Editor* editor, Message* msg) OVERRIDE;
|
||||
@ -59,9 +63,6 @@ public:
|
||||
private:
|
||||
typedef std::vector<Ruler> Rulers;
|
||||
|
||||
// Returns the bounding box arranged by the rulers.
|
||||
gfx::Rect getBoxBounds() const;
|
||||
|
||||
// Returns true if the position screen position (x, y) is touching
|
||||
// the given ruler.
|
||||
bool touchRuler(Editor* editor, Ruler& ruler, int x, int y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user