mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-17 13:20:45 +00:00
Avoid div by zero by preventing entering/returning a grid bounds w/zero width/height (fix #4146, #4597)
This commit is contained in:
parent
4df11ac1e3
commit
712d84e44e
@ -114,6 +114,16 @@ void GridSettingsCommand::onExecute(Context* context)
|
||||
window.gridY()->setTextf("%d", bounds.y);
|
||||
window.gridW()->setTextf("%d", bounds.w);
|
||||
window.gridH()->setTextf("%d", bounds.h);
|
||||
window.gridW()->Leave.connect([&window]{
|
||||
// Prevent entering a width lesser than 1
|
||||
if (window.gridW()->textInt() <= 0)
|
||||
window.gridW()->setText("1");
|
||||
});
|
||||
window.gridH()->Leave.connect([&window]{
|
||||
// Prevent entering a height lesser than 1
|
||||
if (window.gridH()->textInt() <= 0)
|
||||
window.gridH()->setText("1");
|
||||
});
|
||||
window.openWindowInForeground();
|
||||
|
||||
if (window.closer() == window.ok()) {
|
||||
|
@ -320,6 +320,18 @@ public:
|
||||
}
|
||||
cursorColorType()->Change.connect([this]{ onCursorColorType(); });
|
||||
|
||||
// Grid
|
||||
gridW()->Leave.connect([this] {
|
||||
// Prevent entering a width lesser than 1
|
||||
if (gridW()->textInt() <= 0)
|
||||
gridW()->setText("1");
|
||||
});
|
||||
gridH()->Leave.connect([this] {
|
||||
// Prevent entering a height lesser than 1
|
||||
if (gridH()->textInt() <= 0)
|
||||
gridH()->setText("1");
|
||||
});
|
||||
|
||||
// Brush preview
|
||||
brushPreview()->setSelectedItemIndex(
|
||||
(int)m_pref.cursor.brushPreview());
|
||||
|
@ -35,6 +35,8 @@ bool ExprEntry::onProcessMessage(ui::Message* msg)
|
||||
onFormatExprFocusLeave(buf);
|
||||
if (text() != buf)
|
||||
setText(buf);
|
||||
|
||||
Leave();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ namespace app {
|
||||
int decimals() const { return m_decimals; }
|
||||
void setDecimals(int decimals) { m_decimals = decimals; }
|
||||
|
||||
// Signals
|
||||
obs::signal<void()> Leave;
|
||||
|
||||
protected:
|
||||
bool onProcessMessage(ui::Message* msg) override;
|
||||
void onChange() override;
|
||||
|
@ -49,6 +49,11 @@ gfx::Rect Sprite::DefaultGridBounds()
|
||||
void Sprite::SetDefaultGridBounds(const gfx::Rect& defGridBounds)
|
||||
{
|
||||
g_defaultGridBounds = defGridBounds;
|
||||
// Prevent setting an empty grid bounds
|
||||
if (g_defaultGridBounds.w <= 0)
|
||||
g_defaultGridBounds.w = 1;
|
||||
if (g_defaultGridBounds.h <= 0)
|
||||
g_defaultGridBounds.h = 1;
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -127,7 +127,14 @@ namespace doc {
|
||||
static void SetDefaultRgbMapAlgorithm(const RgbMapAlgorithm mapAlgo);
|
||||
|
||||
const gfx::Rect& gridBounds() const { return m_gridBounds; }
|
||||
void setGridBounds(const gfx::Rect& rc) { m_gridBounds = rc; }
|
||||
void setGridBounds(const gfx::Rect& rc) {
|
||||
m_gridBounds = rc;
|
||||
// Prevent setting an empty grid bounds
|
||||
if (m_gridBounds.w <= 0)
|
||||
m_gridBounds.w = 1;
|
||||
if (m_gridBounds.h <= 0)
|
||||
m_gridBounds.h = 1;
|
||||
}
|
||||
|
||||
virtual int getMemSize() const override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user