mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
MultipleChoiceValueEditor: implemented drop down list
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@252 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -7,12 +7,83 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/value/multiple_choice.hpp>
|
||||
#include <gui/thumbnail_thread.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownMultipleChoiceList
|
||||
|
||||
/// A drop down list of color choices
|
||||
class DropDownMultipleChoiceList : public DropDownChoiceListBase {
|
||||
public:
|
||||
DropDownMultipleChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group);
|
||||
|
||||
protected:
|
||||
virtual void select(size_t item);
|
||||
virtual size_t selection() const;
|
||||
virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const;
|
||||
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
|
||||
};
|
||||
|
||||
DropDownMultipleChoiceList::DropDownMultipleChoiceList
|
||||
(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group)
|
||||
: DropDownChoiceListBase(parent, is_submenu, cve, group)
|
||||
{
|
||||
icon_size.width += 16;
|
||||
}
|
||||
|
||||
void DropDownMultipleChoiceList::select(size_t item) {
|
||||
if (isFieldDefault(item)) {
|
||||
// should not happen
|
||||
} else {
|
||||
ChoiceField::ChoiceP choice = getChoice(item);
|
||||
dynamic_cast<MultipleChoiceValueEditor&>(cve).toggle(choice->first_id);
|
||||
}
|
||||
}
|
||||
|
||||
void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const {
|
||||
// is this item active?
|
||||
bool active = false;
|
||||
if (!isFieldDefault(item)) {
|
||||
ChoiceField::ChoiceP choice = getChoice(item);
|
||||
active = dynamic_cast<MultipleChoiceValueEditor&>(cve).active[choice->first_id];
|
||||
}
|
||||
// draw checkbox
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
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);
|
||||
// draw icon
|
||||
DropDownChoiceListBase::drawIcon(dc, x + 16, y, item, selected);
|
||||
}
|
||||
|
||||
size_t DropDownMultipleChoiceList::selection() const {
|
||||
// we need thumbnail images soon
|
||||
const_cast<DropDownMultipleChoiceList*>(this)->generateThumbnailImages();
|
||||
// we don't know the selection
|
||||
return NO_SELECTION;
|
||||
}
|
||||
|
||||
DropDownList* DropDownMultipleChoiceList::createSubMenu(ChoiceField::ChoiceP group) const {
|
||||
return new DropDownMultipleChoiceList(const_cast<DropDownMultipleChoiceList*>(this), true, cve, group);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceValueEditor
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(MultipleChoice) {}
|
||||
|
||||
MultipleChoiceValueEditor::~MultipleChoiceValueEditor() {
|
||||
thumbnail_thread.abort(this);
|
||||
}
|
||||
|
||||
DropDownList& MultipleChoiceValueEditor::initDropDown() {
|
||||
if (!drop_down) {
|
||||
drop_down.reset(new DropDownMultipleChoiceList(&editor(), false, *this, field().choices));
|
||||
}
|
||||
return *drop_down;
|
||||
}
|
||||
|
||||
void MultipleChoiceValueEditor::determineSize(bool force_fit) {
|
||||
if (!nativeLook()) return;
|
||||
// item height
|
||||
@@ -24,7 +95,7 @@ void MultipleChoiceValueEditor::determineSize(bool force_fit) {
|
||||
|
||||
bool MultipleChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
// find item under cursor
|
||||
if (style().render_style && RENDER_CHECKLIST) {
|
||||
if (style().render_style & RENDER_CHECKLIST) {
|
||||
int id = (pos.y - style().top) / item_height;
|
||||
int end = field().choices->lastId();
|
||||
if (id >= 0 && id < end) {
|
||||
@@ -32,10 +103,39 @@ bool MultipleChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& e
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
// open a drop down menu
|
||||
return initDropDown().onMouseInParent(ev, style().popup_style == POPUP_DROPDOWN_IN_PLACE && !nativeLook());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool MultipleChoiceValueEditor::onChar(wxKeyEvent& ev) {
|
||||
if (style().render_style & RENDER_CHECKLIST) {
|
||||
// todo;
|
||||
return false;
|
||||
} else {
|
||||
return initDropDown().onCharInParent(ev);
|
||||
}
|
||||
}
|
||||
void MultipleChoiceValueEditor::onLoseFocus() {
|
||||
if (drop_down) drop_down->hide(false);
|
||||
}
|
||||
|
||||
void MultipleChoiceValueEditor::onValueChange() {
|
||||
MultipleChoiceValueViewer::onValueChange();
|
||||
// determine active values
|
||||
active.clear();
|
||||
vector<String> selected;
|
||||
value().get(selected);
|
||||
vector<String>::iterator select_it = selected.begin();
|
||||
// for each choice...
|
||||
int end = field().choices->lastId();
|
||||
for (int i = 0 ; i < end ; ++i) {
|
||||
String choice = field().choices->choiceName(i);
|
||||
bool is_active = select_it != selected.end() && *select_it == choice;
|
||||
if (is_active) select_it++;
|
||||
active.push_back(is_active);
|
||||
}
|
||||
}
|
||||
|
||||
void MultipleChoiceValueEditor::toggle(int id) {
|
||||
String new_value;
|
||||
|
||||
Reference in New Issue
Block a user