From adf18dfb18ec1d1773c66c74beebb61dbdb87b27 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 28 Nov 2011 16:38:14 -0300 Subject: [PATCH] Fix problems specifying the box bounds in "Import Sprite Sheet" using text-entries (fix issue #52). --- src/commands/cmd_import_sprite_sheet.cpp | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/commands/cmd_import_sprite_sheet.cpp b/src/commands/cmd_import_sprite_sheet.cpp index be2454245..6497f2c72 100644 --- a/src/commands/cmd_import_sprite_sheet.cpp +++ b/src/commands/cmd_import_sprite_sheet.cpp @@ -88,6 +88,11 @@ public: m_grid.addChildInCell(hbox1, 4, 1, 0); } + m_x.EntryChange.connect(Bind(&ImportSpriteSheetFrame::onEntriesChange, this)); + m_y.EntryChange.connect(Bind(&ImportSpriteSheetFrame::onEntriesChange, this)); + m_width.EntryChange.connect(Bind(&ImportSpriteSheetFrame::onEntriesChange, this)); + m_height.EntryChange.connect(Bind(&ImportSpriteSheetFrame::onEntriesChange, this)); + m_selectFile.Click.connect(&ImportSpriteSheetFrame::onSelectFile, this); m_selectFile.DropDownClick.connect(&ImportSpriteSheetFrame::onDropDown, this); m_import.Click.connect(Bind(&ImportSpriteSheetFrame::onImport, this)); @@ -230,6 +235,31 @@ protected: closeWindow(NULL); } + gfx::Rect getRectFromEntries() const + { + int w = m_width.getTextInt(); + int h = m_height.getTextInt(); + + return gfx::Rect(m_x.getTextInt(), + m_y.getTextInt(), + std::max(1, w), + std::max(1, h)); + } + + void onEntriesChange() + { + m_rect = getRectFromEntries(); + + // Redraw new rulers position + if (m_editor) { + EditorStatePtr state = m_editor->getState(); + if (SelectBoxState* boxState = dynamic_cast(state.get())) { + boxState->setBoxBounds(m_rect); + m_editor->invalidate(); + } + } + } + virtual void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE { Frame::onBroadcastMouseMessage(targets); @@ -273,7 +303,7 @@ private: releaseEditor(); if (m_document && !m_editor) { - m_rect = gfx::Rect(0, 0, 16, 16); + m_rect = getRectFromEntries(); m_editor = current_editor; EditorStatePtr newState(new SelectBoxState(this, m_rect,