mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Added drop down list box, specialization for color editor; todo: proper positioning & sizing, redrawing the arrow button
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@91 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -9,3 +9,5 @@
|
||||
#include <gui/value/choice.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Choice) {}
|
||||
|
||||
+139
-1
@@ -7,5 +7,143 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/value/color.hpp>
|
||||
#include <gui/drop_down_list.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <wx/colordlg.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
DECLARE_TYPEOF_COLLECTION(ColorField::ChoiceP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownColorList
|
||||
|
||||
// A drop down list of color choices
|
||||
class DropDownColorList : public DropDownList {
|
||||
public:
|
||||
DropDownColorList(Window* parent, ColorValueEditor& cve);
|
||||
|
||||
protected:
|
||||
virtual size_t itemCount() const;
|
||||
virtual bool lineBelow(size_t item) const;
|
||||
virtual String itemText(size_t item) const;
|
||||
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
|
||||
|
||||
virtual void select(size_t item);
|
||||
virtual size_t selection() const;
|
||||
|
||||
private:
|
||||
ColorValueEditor& cve;
|
||||
mutable Color default_color;
|
||||
|
||||
inline const ColorField& field() const { return cve.field(); }
|
||||
// // default, custom item
|
||||
bool hasDefault() const { return field().default_script; }
|
||||
bool hasCustom() const { return field().allow_custom; }
|
||||
};
|
||||
|
||||
|
||||
DropDownColorList::DropDownColorList(Window* parent, ColorValueEditor& cve)
|
||||
: DropDownList(parent, false, &cve)
|
||||
, cve(cve)
|
||||
{
|
||||
icon_size.width = 25;
|
||||
if (item_size.height < 16) {
|
||||
text_offset = (16 - item_size.height) / 2;
|
||||
item_size.height = 16;
|
||||
}
|
||||
}
|
||||
|
||||
size_t DropDownColorList::itemCount() const {
|
||||
return cve.field().choices.size() + hasDefault() + hasCustom();
|
||||
}
|
||||
bool DropDownColorList::lineBelow(size_t item) const {
|
||||
return (item == 0 && hasDefault()) // below default item
|
||||
|| (item == itemCount() - 2 && hasCustom()); // above custom item
|
||||
}
|
||||
String DropDownColorList::itemText(size_t item) const {
|
||||
if (item == 0 && hasDefault()) {
|
||||
return field().default_name;
|
||||
} else if (item == itemCount()-1 && hasCustom()) {
|
||||
return _("Custom...");
|
||||
} else {
|
||||
return field().choices[item - hasDefault()]->name;
|
||||
}
|
||||
}
|
||||
|
||||
void DropDownColorList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const {
|
||||
Color col;
|
||||
if (item == 0 && hasDefault()) { // default
|
||||
col = default_color;
|
||||
} else if (item == itemCount()-1 && hasCustom()) { // custom color
|
||||
col = cve.value().value();
|
||||
} else {
|
||||
col = field().choices[item - hasDefault()]->color;
|
||||
}
|
||||
// draw a rectangle with the right color
|
||||
dc.SetPen(wxSystemSettings::GetColour(selected ? wxSYS_COLOUR_HIGHLIGHTTEXT : wxSYS_COLOUR_WINDOWTEXT));
|
||||
dc.SetBrush(col);
|
||||
dc.DrawRectangle(x+1, y+1, icon_size.width-2, item_size.height-2);
|
||||
}
|
||||
|
||||
size_t DropDownColorList::selection() const {
|
||||
// find selected color
|
||||
size_t selection = hasCustom() ? itemCount() - 1 : NO_SELECTION;
|
||||
size_t i = 0;
|
||||
FOR_EACH_CONST(c, field().choices) {
|
||||
if (c->color == cve.value().value()) {
|
||||
selection = i + hasDefault();
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// has default item?
|
||||
if (hasDefault() && cve.value().value.isDefault()) {
|
||||
// default is selected
|
||||
default_color = cve.value().value();
|
||||
return 0;
|
||||
} else if (hasDefault()) {
|
||||
// evaluate script to find default color
|
||||
default_color = *field().default_script.invoke(cve.viewer.getContext());
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
void DropDownColorList::select(size_t item) {
|
||||
if (item == 0 && hasDefault()) {
|
||||
cve.change( Defaultable<Color>());
|
||||
} else if (item == itemCount() - 1 && hasCustom()) {
|
||||
cve.changeCustom();
|
||||
} else {
|
||||
cve.change(field().choices[item - hasDefault()]->color);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ColorValueEditor
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Color)
|
||||
, drop_down(new DropDownColorList(&editor(), *this))
|
||||
{}
|
||||
|
||||
void ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
drop_down->onMouseInParent(ev, !nativeLook());
|
||||
}
|
||||
void ColorValueEditor::onChar(wxKeyEvent& ev) {
|
||||
drop_down->onCharInParent(ev);
|
||||
}
|
||||
void ColorValueEditor::onLoseFocus() {
|
||||
drop_down->hide(false);
|
||||
}
|
||||
|
||||
void ColorValueEditor::drawSelection(RotatedDC& dc) {
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), style().getRect().grow(1), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ColorValueEditor::determineSize() {
|
||||
style().height = 20;
|
||||
}
|
||||
|
||||
void ColorValueEditor::change(const Defaultable<Color>& c) {
|
||||
// getSet().actions.add(new ColorChangeAction(value(), c));
|
||||
}
|
||||
void ColorValueEditor::changeCustom() {
|
||||
Color c = wxGetColourFromUser(0, value().value());
|
||||
if (c.Ok()) change(c);
|
||||
}
|
||||
|
||||
@@ -13,12 +13,30 @@
|
||||
#include <gui/value/editor.hpp>
|
||||
#include <render/value/color.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(DropDownList);
|
||||
|
||||
// ----------------------------------------------------------------------------- : ColorValueEditor
|
||||
|
||||
/// An editor 'control' for editing ColorValues
|
||||
class ColorValueEditor : public ColorValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Color);
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual void onChar(wxKeyEvent& ev);
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void drawSelection(RotatedDC& dc);
|
||||
virtual void determineSize();
|
||||
|
||||
private:
|
||||
DropDownListP drop_down;
|
||||
friend class DropDownColorList;
|
||||
/// Change the color
|
||||
void change(const Defaultable<Color>& c);
|
||||
/// Change to a custom color
|
||||
void changeCustom();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -109,9 +109,7 @@ class ValueEditor {
|
||||
// ----------------------------------------------------------------------------- : Utility
|
||||
|
||||
#define DECLARE_VALUE_EDITOR(Type) \
|
||||
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
|
||||
: Type##ValueViewer(parent, style) \
|
||||
{} \
|
||||
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
|
||||
virtual ValueEditor* getEditor() { return this; } \
|
||||
private: \
|
||||
inline DataEditor& editor() const { \
|
||||
@@ -119,5 +117,9 @@ class ValueEditor {
|
||||
} \
|
||||
public:
|
||||
|
||||
#define IMPLEMENT_VALUE_EDITOR(Type) \
|
||||
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
|
||||
: Type##ValueViewer(parent, style)
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
#include <gui/value/image.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Image) {}
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
#include <gui/value/multiple_choice.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(MultipleChoice) {}
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
#include <gui/value/symbol.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Symbol) {}
|
||||
|
||||
@@ -9,3 +9,5 @@
|
||||
#include <gui/value/text.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Text) {}
|
||||
|
||||
Reference in New Issue
Block a user