From 01de02b9049a01fd50ce14d900bfcfa647347d44 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 2 Sep 2007 18:18:04 +0000 Subject: [PATCH] 'suffix' is no longer a safe global variable name in scripts; Drop down list for word lists stay open after clicking on a prefix choice. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@663 0fc631ac-6414-0410-93d0-97cfa31319b6 --- .../style | 6 ++--- src/gfx/resample_image.cpp | 3 --- src/gfx/rotate_image.cpp | 10 ++++++++ src/gui/drop_down_list.cpp | 18 +++++++++++-- src/gui/drop_down_list.hpp | 4 ++- src/gui/value/multiple_choice.cpp | 25 +------------------ src/gui/value/text.cpp | 10 +++++++- 7 files changed, 42 insertions(+), 34 deletions(-) diff --git a/data/magic-firepenguinmastertokens.mse-style/style b/data/magic-firepenguinmastertokens.mse-style/style index d1293512..6a634d57 100644 --- a/data/magic-firepenguinmastertokens.mse-style/style +++ b/data/magic-firepenguinmastertokens.mse-style/style @@ -18,13 +18,13 @@ init script: else "g" ) else input } - suffix := [card: "card.jpg", textbox: "textbox.png", typeline: "typeline.png"] - template := { green_template() + suffix[type] } + template_suffix := [card: "card.jpg", textbox: "textbox.png", typeline: "typeline.png"] + template := { green_template() + template_suffix[type] } land_template := { (if input == "a" then ( if styling.land_style == "grey" then "e" else "c" - ) else green_template()) + "l" + suffix[type] } + ) else green_template()) + "l" + template_suffix[type] } # Use the normal tap symbol mana_t := { diff --git a/src/gfx/resample_image.cpp b/src/gfx/resample_image.cpp index db8cf6c9..b4188115 100644 --- a/src/gfx/resample_image.cpp +++ b/src/gfx/resample_image.cpp @@ -202,9 +202,6 @@ void sharp_downsample(const Image& img_in, Image& img_out, int amount) { for (int y = 0 ; y < height ; ++y) { for (int x = 0 ; x < width ; ++x) { - if (x==150&&y==150) { - x=x;//break - } // Filter using a kernel of the form /* -1 -1 * -1 c c -1 diff --git a/src/gfx/rotate_image.cpp b/src/gfx/rotate_image.cpp index fa8f37e2..c151d846 100644 --- a/src/gfx/rotate_image.cpp +++ b/src/gfx/rotate_image.cpp @@ -90,3 +90,13 @@ Image rotate_image(const Image& image, int angle) { default: return image; } } + +/*Bitmap rotate_bitmap(const Bitmap& bitmap, int angle) { + switch (angle % 360) { + case 90: + case 180: + case 270: + default: return bitmap; + } +} +*/ diff --git a/src/gui/drop_down_list.cpp b/src/gui/drop_down_list.cpp index 258c92ab..e0394b14 100644 --- a/src/gui/drop_down_list.cpp +++ b/src/gui/drop_down_list.cpp @@ -66,6 +66,7 @@ DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer) , viewer(viewer) , hider (is_submenu ? nullptr : new DropDownHider(*this)) , hider2(is_submenu ? nullptr : new DropDownHider(*this)) + , close_on_mouse_out(false) { if (is_submenu) { parent_menu = &dynamic_cast(*GetParent()); @@ -148,9 +149,9 @@ void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) { void DropDownList::hide(bool event, bool allow_veto) { // hide? - bool keep_open = event && allow_veto && stayOpen(); + bool keep_open = event && allow_veto && stayOpen(selected_item); if (keep_open) { - Refresh(false); + close_on_mouse_out = true; } else { // hide root DropDownList* root = this; @@ -162,6 +163,7 @@ void DropDownList::hide(bool event, bool allow_veto) { // send event if (event && selected_item != NO_SELECTION && itemEnabled(selected_item)) { select(selected_item); + if (IsShown()) Refresh(false); } } @@ -343,6 +345,17 @@ void DropDownList::onMotion(wxMouseEvent& ev) { hideSubMenu(); } +void DropDownList::onMouseLeave(wxMouseEvent& ev) { + if (close_on_mouse_out) { + wxSize cs = GetClientSize(); + if (ev.GetX() < 0 || ev.GetY() < 0 || ev.GetX() >= cs.x || ev.GetY() >= cs.y) { + hide(false); // outside box; hide it + ev.Skip(); + return; + } + } +} + // ----------------------------------------------------------------------------- : DropDownList : Parent events bool DropDownList::onMouseInParent(wxMouseEvent& ev, bool open_in_place) { @@ -429,4 +442,5 @@ BEGIN_EVENT_TABLE(DropDownList,wxPopupWindow) EVT_LEFT_DOWN (DropDownList::onLeftDown) EVT_LEFT_UP (DropDownList::onLeftUp) EVT_MOTION (DropDownList::onMotion) + EVT_LEAVE_WINDOW (DropDownList::onMouseLeave) END_EVENT_TABLE () diff --git a/src/gui/drop_down_list.hpp b/src/gui/drop_down_list.hpp index 390b738f..a4e6cd07 100644 --- a/src/gui/drop_down_list.hpp +++ b/src/gui/drop_down_list.hpp @@ -58,7 +58,7 @@ class DropDownList : public wxPopupWindow { /// When the list is being opened, what should be selected? virtual size_t selection() const = 0; /** Should the list stay open after selecting something? */ - virtual bool stayOpen() const { return false; } + virtual bool stayOpen(size_t selection) const { return false; } // --------------------------------------------------- : Item information /// Number of items @@ -95,6 +95,7 @@ class DropDownList : public wxPopupWindow { DropDownList* parent_menu; ///< The parent menu, only applies to sub menus ValueViewer* viewer; ///< The parent viewer object (optional) DropDownHider* hider, *hider2; ///< Class to hide this window when we lose focus + bool close_on_mouse_out; ///< Was the list kept open after selecting a choice, if so, be eager to close it // --------------------------------------------------- : Events DECLARE_EVENT_TABLE(); @@ -103,6 +104,7 @@ class DropDownList : public wxPopupWindow { void onLeftDown(wxMouseEvent&); void onLeftUp (wxMouseEvent&); void onMotion(wxMouseEvent&); + void onMouseLeave(wxMouseEvent&); // --------------------------------------------------- : Privates diff --git a/src/gui/value/multiple_choice.cpp b/src/gui/value/multiple_choice.cpp index 2578d566..42072635 100644 --- a/src/gui/value/multiple_choice.cpp +++ b/src/gui/value/multiple_choice.cpp @@ -22,20 +22,14 @@ class DropDownMultipleChoiceList : public DropDownChoiceListBase { virtual void onShow(); virtual void select(size_t item); virtual size_t selection() const; - virtual bool stayOpen() const { return true; } + virtual bool stayOpen(size_t selection) const { return true; } virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const; virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const; - - virtual void onMouseLeave(wxMouseEvent&); - private: - DECLARE_EVENT_TABLE(); - bool kept_open; ///< Was the list kept open after selecting a choice, if so, be eager to close it }; DropDownMultipleChoiceList::DropDownMultipleChoiceList (Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group) : DropDownChoiceListBase(parent, is_submenu, cve, group) - , kept_open(false) { icon_size.width += 16; } @@ -50,7 +44,6 @@ void DropDownMultipleChoiceList::select(size_t item) { } // keep the box open DropDownChoiceListBase::onShow(); // update 'enabled' - kept_open = true; } void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const { @@ -82,7 +75,6 @@ void DropDownMultipleChoiceList::onShow() { DropDownChoiceListBase::onShow(); // we need thumbnail images soon const_cast(this)->generateThumbnailImages(); - kept_open = false; } size_t DropDownMultipleChoiceList::selection() const { @@ -93,21 +85,6 @@ DropDownList* DropDownMultipleChoiceList::createSubMenu(ChoiceField::ChoiceP gro return new DropDownMultipleChoiceList(const_cast(this), true, cve, group); } -void DropDownMultipleChoiceList::onMouseLeave(wxMouseEvent& ev) { - if (kept_open) { - wxSize cs = GetClientSize(); - if (ev.GetX() < 0 || ev.GetY() < 0 || ev.GetX() >= cs.x || ev.GetY() >= cs.y) { - hide(false); // outside box; hide it - ev.Skip(); - return; - } - } -} - -BEGIN_EVENT_TABLE(DropDownMultipleChoiceList, DropDownChoiceListBase) - EVT_LEAVE_WINDOW(DropDownMultipleChoiceList::onMouseLeave) -END_EVENT_TABLE() - // ----------------------------------------------------------------------------- : MultipleChoiceValueEditor IMPLEMENT_VALUE_EDITOR(MultipleChoice) {} diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index cc6e558b..8d95cdb7 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -131,6 +131,7 @@ class DropDownWordList : public DropDownList { virtual DropDownList* submenu(size_t item) const; virtual size_t selection() const; virtual void select(size_t item); + virtual bool stayOpen(size_t selection) const; private: TextValueEditor& tve; WordListPosP pos; @@ -280,7 +281,7 @@ void DropDownWordList::select(size_t item) { // determine new value String new_value; bool toggling_prefix = items[item].word->is_prefix; - for (size_t i = 0 ; i < words->words.size() ; ++i) { + for (size_t i = 0 ; i < items.size() ; ++i) { const DropDownWordListItem& it = items[i]; if (it.word->is_prefix) { if (it.active() != (i == item)) { @@ -298,6 +299,13 @@ void DropDownWordList::select(size_t item) { tve.fixSelection(TYPE_INDEX); tve.replaceSelection(escape(new_value), format_string(_ACTION_("change"), tve.field().name)); + // stay open? + if (IsShown()) selection(); // update 'enabled' +} + +bool DropDownWordList::stayOpen(size_t selection) const { + if (selection == NO_SELECTION) return false; + return items[selection].word->is_prefix; } void DropDownWordList::redrawArrowOnParent() {