From 81983407d30bdf547e494755d8a2651980115efc Mon Sep 17 00:00:00 2001 From: twanvl Date: Mon, 2 Jul 2007 13:37:55 +0000 Subject: [PATCH] Multiple choice choices can be drawn as radio buttons instead of check boxes git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@463 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field/choice.cpp | 10 ++++++++-- src/data/field/choice.hpp | 7 +++++++ src/gui/util.cpp | 21 +++++++++++++++++++++ src/gui/util.hpp | 3 +++ src/gui/value/multiple_choice.cpp | 8 +++++++- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/data/field/choice.cpp b/src/data/field/choice.cpp index 8f8215eb..8bc2984c 100644 --- a/src/data/field/choice.cpp +++ b/src/data/field/choice.cpp @@ -49,11 +49,11 @@ IMPLEMENT_REFLECTION(ChoiceField) { ChoiceField::Choice::Choice() : first_id(0) - , line_below(false), enabled(true) + , line_below(false), enabled(true), type(CHOICE_TYPE_CHECK) {} ChoiceField::Choice::Choice(const String& name) : name(name), first_id(0) - , line_below(false), enabled(true) + , line_below(false), enabled(true), type(CHOICE_TYPE_CHECK) {} @@ -139,6 +139,11 @@ String ChoiceField::Choice::choiceNameNice(int id) const { } +IMPLEMENT_REFLECTION_ENUM(ChoiceChoiceType) { + VALUE_N("check", CHOICE_TYPE_CHECK); + VALUE_N("radio", CHOICE_TYPE_RADIO); +} + IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { if (isGroup() || line_below || enabled.isScripted() || (tag.reading() && tag.isComplex())) { // complex values are groups @@ -147,6 +152,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(ChoiceField::Choice) { REFLECT(choices); REFLECT(line_below); REFLECT(enabled); + REFLECT(type); } else { REFLECT_NAMELESS(name); } diff --git a/src/data/field/choice.hpp b/src/data/field/choice.hpp index b5ace5b2..09e6631f 100644 --- a/src/data/field/choice.hpp +++ b/src/data/field/choice.hpp @@ -46,6 +46,12 @@ class ChoiceField : public Field { DECLARE_REFLECTION(); }; + +enum ChoiceChoiceType { + CHOICE_TYPE_CHECK, + CHOICE_TYPE_RADIO +}; + /// An item that can be chosen for this field class ChoiceField::Choice : public IntrusivePtrBase { public: @@ -57,6 +63,7 @@ class ChoiceField::Choice : public IntrusivePtrBase { vector choices; ///< Choices and sub groups in this group bool line_below; ///< Show a line after this item? Scriptable enabled; ///< Is this item enabled? + ChoiceChoiceType type; ///< How should this item be shown, only for multiple choice fields /// First item-id in this group (can be the default item) /** Item-ids are consecutive integers, a group uses all ids [first_id..lastId()). * The top level group has first_id 0. diff --git a/src/gui/util.cpp b/src/gui/util.cpp index 60c71263..cd675112 100644 --- a/src/gui/util.cpp +++ b/src/gui/util.cpp @@ -214,3 +214,24 @@ void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool e dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); } + +void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled) { + #if wxUSE_UXTHEME && defined(__WXMSW__) + // TODO: Windows version? + #endif + // portable version + #if 1 + // circle drawing on windows looks absolutely horrible + // so use rounded rectangles instead + dc.SetPen(wxSystemSettings::GetColour(enabled ? wxSYS_COLOUR_WINDOWTEXT: wxSYS_COLOUR_GRAYTEXT)); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + //dc.DrawEllipse(rect.x, rect.y, rect.width, rect.height); + dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, rect.width*0.5-1); + if (checked) { + dc.SetBrush(wxSystemSettings::GetColour(enabled ? wxSYS_COLOUR_WINDOWTEXT: wxSYS_COLOUR_GRAYTEXT)); + dc.SetPen(*wxTRANSPARENT_PEN); + //dc.DrawEllipse(rect.x+2,rect.y+2,rect.width-4,rect.height-4); + dc.DrawRoundedRectangle(rect.x+3, rect.y+3, rect.width-6, rect.height-6, rect.width*0.5-4); + } + #endif +} diff --git a/src/gui/util.hpp b/src/gui/util.hpp index 392d4313..829c2262 100644 --- a/src/gui/util.hpp +++ b/src/gui/util.hpp @@ -63,5 +63,8 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active); /// Draws a check box void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true); +/// Draws a radio button +void draw_radiobox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true); + // ----------------------------------------------------------------------------- : EOF #endif diff --git a/src/gui/value/multiple_choice.cpp b/src/gui/value/multiple_choice.cpp index eabbafa1..4d893528 100644 --- a/src/gui/value/multiple_choice.cpp +++ b/src/gui/value/multiple_choice.cpp @@ -45,9 +45,11 @@ void DropDownMultipleChoiceList::select(size_t item) { void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const { // is this item active/checked? bool active = false; + bool radio = false; if (!isFieldDefault(item)) { ChoiceField::ChoiceP choice = getChoice(item); active = dynamic_cast(cve).active[choice->first_id]; + radio = choice->type == CHOICE_TYPE_RADIO; } else { active = dynamic_cast(cve).value().value.isDefault(); } @@ -56,7 +58,11 @@ void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, boo dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); dc.DrawRectangle(x,y,16,16); wxRect rect = RealRect(x+2,y+2,12,12); - draw_checkbox(nullptr, dc, rect, active, itemEnabled(item)); + if (radio) { + draw_radiobox(nullptr, dc, rect, active, itemEnabled(item)); + } else { + draw_checkbox(nullptr, dc, rect, active, itemEnabled(item)); + } // draw icon DropDownChoiceListBase::drawIcon(dc, x + 16, y, item, selected); }