mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-27 06:35:16 +00:00
Keep 9-slice borders fixed while scaling bounds
Scaling 9-slice bounds will keep the border size (determined by the sub-slices surrounding the center sub-slice) fixed.
This commit is contained in:
parent
d88c22386d
commit
8e904761f1
@ -412,8 +412,12 @@ bool MovingSliceState::onMouseMove(Editor* editor, MouseMessage* msg)
|
||||
|
||||
if (m_hit.type() == EditorHit::SliceCenter)
|
||||
key.setCenter(rc);
|
||||
else
|
||||
else {
|
||||
key.setBounds(rc);
|
||||
if (item.isNineSlice()) {
|
||||
key.setBorder(item.border());
|
||||
}
|
||||
}
|
||||
|
||||
// Update the slice key
|
||||
item.slice->insert(m_frame, key);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "doc/selected_layers.h"
|
||||
#include "doc/selected_objects.h"
|
||||
#include "doc/slice.h"
|
||||
#include "gfx/border.h"
|
||||
|
||||
namespace app {
|
||||
class Editor;
|
||||
@ -192,6 +193,21 @@ namespace app {
|
||||
: std::make_shared<SingleSlice>(this, image));
|
||||
content.push_back(ssc);
|
||||
}
|
||||
|
||||
bool isNineSlice() const { return oldKey.hasCenter(); }
|
||||
|
||||
// If this item manages a 9-slice key, returns the border surrounding the
|
||||
// center rectangle of the SliceKey. Otherwise returns an empty border.
|
||||
gfx::Border border() const {
|
||||
gfx::Border border;
|
||||
if (isNineSlice()) {
|
||||
border = gfx::Border(oldKey.center().x,
|
||||
oldKey.center().y,
|
||||
oldKey.bounds().w-oldKey.center().x2(),
|
||||
oldKey.bounds().h-oldKey.center().y2());
|
||||
}
|
||||
return border;
|
||||
}
|
||||
};
|
||||
|
||||
// Initializes the content of the Items. So each item will contain the
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "doc/frame.h"
|
||||
#include "doc/keyframes.h"
|
||||
#include "doc/with_user_data.h"
|
||||
#include "gfx/border.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
|
||||
@ -41,6 +42,12 @@ namespace doc {
|
||||
void setBounds(const gfx::Rect& bounds) { m_bounds = bounds; }
|
||||
void setCenter(const gfx::Rect& center) { m_center = center; }
|
||||
void setPivot(const gfx::Point& pivot) { m_pivot = pivot; }
|
||||
void setBorder(const gfx::Border& border) {
|
||||
m_center.x = border.left();
|
||||
m_center.y = border.top();
|
||||
m_center.w = m_bounds.w - border.width();
|
||||
m_center.h = m_bounds.h - border.height();
|
||||
}
|
||||
|
||||
private:
|
||||
gfx::Rect m_bounds;
|
||||
|
Loading…
x
Reference in New Issue
Block a user