Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SimpleGUI/include/SimpleGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class SimpleGUI {
};
public:
SimpleGUI(App* app);
~SimpleGUI();
bool isSelected() { return selectedControl != NULL; }
Control* getSelectedControl() { return selectedControl; };
std::vector<Control*>& getControls() { return controls; }

bool onMouseDown(MouseEvent event);
Expand All @@ -97,6 +99,8 @@ class SimpleGUI {

bool isEnabled();
void setEnabled(bool state);
void removeControl( Control* controlToRemove );


FloatVarControl* addParam(const std::string& paramName, float* var, float min=0, float max=1, float defaultValue = 0);
IntVarControl* addParam(const std::string& paramName, int* var, int min=0, int max=1, int defaultValue = 0);
Expand Down
50 changes: 40 additions & 10 deletions SimpleGUI/src/SimpleGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ SimpleGUI::SimpleGUI(App* app) {
init(app);
enabled = true;
}

SimpleGUI::~SimpleGUI() {
std::cout << "Removing gui " << std::endl;
selectedControl = NULL;
ci::app::App::get()->unregisterMouseDown( cbMouseDown );
ci::app::App::get()->unregisterMouseUp( cbMouseUp );
ci::app::App::get()->unregisterMouseDrag( cbMouseDrag );
}

void SimpleGUI::init(App* app) {
textFont = Font(loadResource("pf_tempesta_seven.ttf"), 8);
Expand Down Expand Up @@ -133,14 +141,26 @@ PanelControl* SimpleGUI::addPanel() {
controls.push_back(control);
return control;
}

void SimpleGUI::removeControl( Control* controlToRemove ) {
std::vector<Control*>::iterator it = controls.begin();
while( it!= controls.end() ) {
Control* control = *it;
if( control == controlToRemove ) {
controls.erase( it );
return;
}
++it;
}
}

void SimpleGUI::draw() {
if (!enabled) return;

gl::pushMatrices();
gl::setMatricesWindow(getWindowSize());
gl::disableDepthRead();
gl::disableDepthWrite();
gl::disableDepthRead();
gl::disableDepthWrite();
gl::enableAlphaBlending();

Vec2f position = Vec2f(spacing, spacing);
Expand Down Expand Up @@ -242,13 +262,17 @@ bool SimpleGUI::onMouseDown(MouseEvent event) {

std::vector<Control*>::iterator it = controls.begin();
while(it != controls.end()) {
Control* control = *it++;
if (control->activeArea.contains(event.getPos())) {
selectedControl = control;
selectedControl->onMouseDown(event);
return true;
Control* control = *it;
if(control) {
if (control->activeArea.contains(event.getPos())) {
selectedControl = control;
selectedControl->onMouseDown(event);
return true;
}
}
it++;
}

return false;
}

Expand Down Expand Up @@ -302,6 +326,8 @@ Control* SimpleGUI::getControlByName(const std::string& name) {
return NULL;
}



//-----------------------------------------------------------------------------

Control::Control() {
Expand Down Expand Up @@ -358,7 +384,9 @@ Vec2f FloatVarControl::draw(Vec2f pos) {
(pos + SimpleGUI::labelSize + SimpleGUI::sliderSize + SimpleGUI::padding*2).y)
);

gl::drawString(name, pos, SimpleGUI::textColor, SimpleGUI::textFont);
std::stringstream ss;
ss << name << " " << *this->var;
gl::drawString(ss.str(), pos, SimpleGUI::textColor, SimpleGUI::textFont);

gl::color(SimpleGUI::darkColor);
gl::drawSolidRect(activeArea);
Expand Down Expand Up @@ -435,8 +463,10 @@ Vec2f IntVarControl::draw(Vec2f pos) {
(pos + SimpleGUI::sliderSize + SimpleGUI::padding).x,
(pos + SimpleGUI::labelSize + SimpleGUI::sliderSize + SimpleGUI::padding*2).y)
);

gl::drawString(name, pos, SimpleGUI::textColor, SimpleGUI::textFont);

std::stringstream ss;
ss << name << " " << *this->var;
gl::drawString(ss.str(),pos, SimpleGUI::textColor, SimpleGUI::textFont);

gl::color(SimpleGUI::darkColor);
gl::drawSolidRect(activeArea);
Expand Down