mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Working MultipleChoiceValueEditor for checklist style
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@228 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -52,10 +52,11 @@ class SimpleValueAction : public ValueAction {
|
||||
typename T::ValueType new_value;
|
||||
};
|
||||
|
||||
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, &ChoiceValue::value, true> (value, new_value); }
|
||||
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, &ColorValue::value, true> (value, new_value); }
|
||||
ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, &ImageValue::filename, false>(value, new_value); }
|
||||
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, &SymbolValue::filename, false>(value, new_value); }
|
||||
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, &ChoiceValue::value, true> (value, new_value); }
|
||||
ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<MultipleChoiceValue, &MultipleChoiceValue::value, false>(value, new_value); }
|
||||
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, &ColorValue::value, true> (value, new_value); }
|
||||
ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, &ImageValue::filename, false>(value, new_value); }
|
||||
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, &SymbolValue::filename, false>(value, new_value); }
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text
|
||||
|
||||
@@ -24,6 +24,7 @@ DECLARE_POINTER_TYPE(Value);
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
DECLARE_POINTER_TYPE(TextValue);
|
||||
DECLARE_POINTER_TYPE(ChoiceValue);
|
||||
DECLARE_POINTER_TYPE(MultipleChoiceValue);
|
||||
DECLARE_POINTER_TYPE(ColorValue);
|
||||
DECLARE_POINTER_TYPE(ImageValue);
|
||||
DECLARE_POINTER_TYPE(SymbolValue);
|
||||
@@ -43,10 +44,11 @@ class ValueAction : public Action {
|
||||
// ----------------------------------------------------------------------------- : Simple
|
||||
|
||||
/// Action that updates a Value to a new value
|
||||
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value);
|
||||
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value);
|
||||
ValueAction* value_action(const ImageValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value);
|
||||
ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value);
|
||||
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value);
|
||||
ValueAction* value_action(const ImageValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text
|
||||
|
||||
|
||||
+7
-5
@@ -200,12 +200,14 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active)
|
||||
}
|
||||
|
||||
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked) {
|
||||
// TODO: Windows version?
|
||||
// portable
|
||||
#if wxUSE_UXTHEME && defined(__WXMSW__)
|
||||
// TODO: Windows version?
|
||||
#endif
|
||||
// portable version
|
||||
if (checked) {
|
||||
dc.DrawCheckMark(wxRect(rect.x-1,rect.y-1,rect.width+2,rect.height+2));
|
||||
}
|
||||
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
|
||||
if (checked) {
|
||||
dc.DrawCheckMark(rect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/value/multiple_choice.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceValueEditor
|
||||
|
||||
@@ -14,7 +15,45 @@ IMPLEMENT_VALUE_EDITOR(MultipleChoice) {}
|
||||
|
||||
void MultipleChoiceValueEditor::determineSize(bool force_fit) {
|
||||
if (!nativeLook()) return;
|
||||
// item height
|
||||
item_height = 16;
|
||||
// height depends on number of items and item height
|
||||
int item_count = field().choices->lastId();
|
||||
style().height = item_count * 20;
|
||||
style().height = item_count * item_height;
|
||||
}
|
||||
|
||||
bool MultipleChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
// find item under cursor
|
||||
if (style().render_style && RENDER_CHECKLIST) {
|
||||
int id = (pos.y - style().top) / item_height;
|
||||
int end = field().choices->lastId();
|
||||
if (id >= 0 && id < end) {
|
||||
toggle(id);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MultipleChoiceValueEditor::toggle(int id) {
|
||||
String new_value;
|
||||
// old selection
|
||||
vector<String> selected;
|
||||
value().get(selected);
|
||||
vector<String>::iterator select_it = selected.begin();
|
||||
// copy selected choices to new value
|
||||
int end = field().choices->lastId();
|
||||
for (int i = 0 ; i < end ; ++i) {
|
||||
String choice = field().choices->choiceName(i);
|
||||
bool active = select_it != selected.end() && *select_it == choice;
|
||||
if (active) select_it++;
|
||||
if (active != (i == id)) {
|
||||
if (!new_value.empty()) new_value += _(", ");
|
||||
new_value += choice;
|
||||
}
|
||||
}
|
||||
// store value
|
||||
getSet().actions.add(value_action(valueP(), new_value));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ class MultipleChoiceValueEditor : public MultipleChoiceValueViewer, public Value
|
||||
DECLARE_VALUE_EDITOR(MultipleChoice);
|
||||
|
||||
virtual void determineSize(bool force_fit);
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev);
|
||||
private:
|
||||
/// Toggle a choice or on or off
|
||||
void toggle(int id);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -41,7 +41,7 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
|
||||
void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) {
|
||||
RealSize size;
|
||||
RealSize size; size.height = item_height;
|
||||
if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) {
|
||||
wxRect rect = dc.tr(RealRect(pos + RealSize(1,1), RealSize(12,12)));
|
||||
draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO
|
||||
@@ -60,7 +60,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize(choice));
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize_sentence(choice));
|
||||
RealSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
|
||||
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
|
||||
|
||||
@@ -18,9 +18,11 @@
|
||||
/// Viewer that displays a multiple choice value
|
||||
class MultipleChoiceValueViewer : public ValueViewer {
|
||||
public:
|
||||
DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style) {}
|
||||
DECLARE_VALUE_VIEWER(MultipleChoice) : ValueViewer(parent,style), item_height(0) {}
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
protected:
|
||||
double item_height; ///< Height of a single item, or 0 if non uniform
|
||||
private:
|
||||
void drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active = true);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user