Debian Codegraph @

plugins/dm.stimresponse/EffectArgumentItem.cpp

raw
1 #include "EffectArgumentItem.h"
2
3 #include "string/convert.h"
4
5 #include <wx/textctrl.h>
6 #include <wx/stattext.h>
7 #include <wx/choice.h>
8 #include <wx/combobox.h>
9 #include <wx/checkbox.h>
10 #include <wx/bmpcbox.h>
11
12 #include "wxutil/ChoiceHelper.h"
13
14 #include "StimTypes.h"
15
16 EffectArgumentItem::EffectArgumentItem(wxWindow* parent,
17 ResponseEffect::Argument& arg) :
18 _arg(arg)
19 {
20 // Create the label
21 _label = new wxStaticText(parent, wxID_ANY, _arg.title + ":");
22 _label->SetToolTip(arg.desc);
23
24 // Create the description widget
25 _descBox = new wxStaticText(parent, wxID_ANY, "?");
26 _descBox->SetFont(_descBox->GetFont().Bold());
27 _descBox->SetToolTip(arg.desc);
28 }
29
30 // Retrieve the label widget
31 wxWindow* EffectArgumentItem::getLabelWidget()
32 {
33 return _label;
34 }
35
36 wxWindow* EffectArgumentItem::getHelpWidget()
37 {
38 return _descBox;
39 }
40
41 void EffectArgumentItem::save()
42 {
43 // Save the value to the effect
44 _arg.value = getValue();
45 }
46
47 // StringArgument
48 StringArgument::StringArgument(wxWindow* parent, ResponseEffect::Argument& arg) :
49 EffectArgumentItem(parent, arg)
50 {
51 _entry = new wxTextCtrl(parent, wxID_ANY);
52 _entry->SetValue(arg.value);
53 }
54
55 wxWindow* StringArgument::getEditWidget()
56 {
57 return _entry;
58 }
59
60 std::string StringArgument::getValue()
61 {
62 return _entry->GetValue().ToStdString();
63 }
64
65 // Boolean argument
66 BooleanArgument::BooleanArgument(wxWindow* parent, ResponseEffect::Argument& arg) :
67 EffectArgumentItem(parent, arg)
68 {
69 _checkButton = new wxCheckBox(parent, wxID_ANY, arg.title);
70 _checkButton->SetValue(!arg.value.empty());
71 }
72
73 wxWindow* BooleanArgument::getEditWidget()
74 {
75 return _checkButton;
76 }
77
78 std::string BooleanArgument::getValue()
79 {
80 return _checkButton->GetValue() ? "1" : "";
81 }
82
83 // Entity Argument
84 EntityArgument::EntityArgument(
85 wxWindow* parent,
86 ResponseEffect::Argument& arg,
87 const wxArrayString& entityChoices) :
88 EffectArgumentItem(parent, arg)
89 {
90 // Create a combo box entry with the given entity list
91 _comboBox = new wxComboBox(parent, wxID_ANY);
92 _comboBox->Append(entityChoices);
93
94 _comboBox->SetValue(arg.value);
95 }
96
97 std::string EntityArgument::getValue()
98 {
99 return _comboBox->GetValue().ToStdString();
100 }
101
102 wxWindow* EntityArgument::getEditWidget()
103 {
104 return _comboBox;
105 }
106
107 // StimType Argument
108 StimTypeArgument::StimTypeArgument(wxWindow* parent,
109 ResponseEffect::Argument& arg,
110 const StimTypes& stimTypes) :
111 EffectArgumentItem(parent, arg),
112 _stimTypes(stimTypes)
113 {
114 #ifdef USE_BMP_COMBO_BOX
115 _comboBox = new wxBitmapComboBox(parent, wxID_ANY);
116 #else
117 _comboBox = new wxComboBox(parent, wxID_ANY);
118 #endif
119 _stimTypes.populateComboBox(_comboBox);
120
121 StimType stimType = _stimTypes.get(string::convert<int>(arg.value));
122
123 wxutil::ChoiceHelper::SelectComboItemByStoredString(_comboBox, stimType.name);
124 }
125
126 std::string StimTypeArgument::getValue()
127 {
128 // The effect argument stores the stim type ID as value
129 if (_comboBox->GetSelection() != wxNOT_FOUND)
130 {
131 wxClientData* data = _comboBox->GetClientObject(_comboBox->GetSelection());
132
133 if (data == NULL) return "";
134
135 wxStringClientData* nameStr = dynamic_cast<wxStringClientData*>(data);
136
137 int id = _stimTypes.getIdForName(nameStr->GetData().ToStdString());
138
139 if (id == -1) return "";
140
141 return string::to_string(id);
142 }
143
144 return "";
145 }
146
147 wxWindow* StimTypeArgument::getEditWidget()
148 {
149 return _comboBox;
150 }