| 1 |
#include "CustomClockedComponentEditor.h" |
| 2 |
#include "../SpecifierType.h" |
| 3 |
#include "../Component.h" |
| 4 |
|
| 5 |
#include "i18n.h" |
| 6 |
|
| 7 |
#include <wx/spinctrl.h> |
| 8 |
#include <wx/textctrl.h> |
| 9 |
#include <wx/stattext.h> |
| 10 |
|
| 11 |
namespace objectives |
| 12 |
{ |
| 13 |
|
| 14 |
namespace ce |
| 15 |
{ |
| 16 |
|
| 17 |
// Registration helper, will register this editor in the factory |
| 18 |
CustomClockedComponentEditor::RegHelper CustomClockedComponentEditor::regHelper; |
| 19 |
|
| 20 |
// Constructor |
| 21 |
CustomClockedComponentEditor::CustomClockedComponentEditor(wxWindow* parent, Component& component) : |
| 22 |
ComponentEditorBase(parent), |
| 23 |
_component(&component), |
| 24 |
_scriptFunction(new wxTextCtrl(_panel, wxID_ANY)) |
| 25 |
{ |
| 26 |
_scriptFunction->Bind(wxEVT_TEXT, [&] (wxCommandEvent& ev) { writeToComponent(); }); |
| 27 |
|
| 28 |
_interval = new wxSpinCtrlDouble(_panel, wxID_ANY); |
| 29 |
_interval->SetValue(1); |
| 30 |
_interval->SetRange(0, 65535); |
| 31 |
_interval->SetIncrement(0.1); |
| 32 |
_interval->SetDigits(1); |
| 33 |
_interval->Bind(wxEVT_SPINCTRLDOUBLE, [&] (wxSpinDoubleEvent& ev) { writeToComponent(); }); |
| 34 |
|
| 35 |
// Main vbox |
| 36 |
wxStaticText* label = new wxStaticText(_panel, wxID_ANY, _("Script Function:")); |
| 37 |
label->SetFont(label->GetFont().Bold()); |
| 38 |
|
| 39 |
_panel->GetSizer()->Add(label, 0, wxBOTTOM, 6); |
| 40 |
_panel->GetSizer()->Add(_scriptFunction, 0, wxBOTTOM | wxEXPAND, 6); |
| 41 |
|
| 42 |
label = new wxStaticText(_panel, wxID_ANY, _("Clock interval:")); |
| 43 |
label->SetFont(label->GetFont().Bold()); |
| 44 |
_panel->GetSizer()->Add(label, 0, wxBOTTOM, 6); |
| 45 |
|
| 46 |
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL); |
| 47 |
hbox->Add(_interval, 0, wxEXPAND | wxRIGHT, 6); |
| 48 |
hbox->Add(new wxStaticText(_panel, wxID_ANY, _("seconds:")), 0, wxEXPAND); |
| 49 |
|
| 50 |
_panel->GetSizer()->Add(hbox, 0, wxBOTTOM | wxEXPAND, 6); |
| 51 |
|
| 52 |
// Load the initial values into the boxes |
| 53 |
_scriptFunction->SetValue(component.getArgument(0)); |
| 54 |
|
| 55 |
float interval = component.getClockInterval(); |
| 56 |
_interval->SetValue(interval >= 0 ? interval : 1.0); |
| 57 |
} |
| 58 |
|
| 59 |
// Write to component |
| 60 |
void CustomClockedComponentEditor::writeToComponent() const |
| 61 |
{ |
| 62 |
if (!_active) return; // still under construction |
| 63 |
|
| 64 |
assert(_component); |
| 65 |
|
| 66 |
_component->clearArguments(); |
| 67 |
_component->setArgument(0, _scriptFunction->GetValue().ToStdString()); |
| 68 |
_component->setClockInterval(static_cast<float>(_interval->GetValue())); |
| 69 |
} |
| 70 |
|
| 71 |
} // namespace ce |
| 72 |
|
| 73 |
} // namespace objectives |