Browse Source

Merge branch 'fix-replace-ofxUI' into develop

master
Krisjanis Rijnieks 11 years ago
parent
commit
41b261e971
  1. 2
      README.md
  2. 2
      example/addons.make
  3. 62
      src/ofxSourcesEditor.cpp
  4. 9
      src/ofxSourcesEditor.h
  5. 188
      src/ui/ofxRadioList.cpp
  6. 46
      src/ui/ofxRadioList.h

2
README.md

@ -14,7 +14,7 @@ Development
As the projects gets a bit more popular, I see that people want to add missing features. I have a whole bunch of features that I want to add in future releases, but right now I'm trying to understand how to keep it more or less organized. As the projects gets a bit more popular, I see that people want to add missing features. I have a whole bunch of features that I want to add in future releases, but right now I'm trying to understand how to keep it more or less organized.
Currently I have decided to use [A successful Git branching model](http://nvie.com/posts/a-successful-git) by [Vincent Driessen](https://twitter.com/nvie), so read this article and I do not doubt that it will help you with other Git related projects. Currently I have decided to use [A successful Git branching model](http://nvie.com/posts/a-successful-git-branching-model/) by [Vincent Driessen](https://twitter.com/nvie), so read this article and I do not doubt that it will help you with other Git related projects.
I'm still working on boosting my understanding about the issue tracking system on GitHub, I believe that it would be the best way how to keep new feature requests and bugfixes organized. I'm still working on boosting my understanding about the issue tracking system on GitHub, I believe that it would be the best way how to keep new feature requests and bugfixes organized.

2
example/addons.make

@ -1,3 +1,3 @@
ofxPiMapper ofxPiMapper
ofxUI ofxGui
ofxXmlSettings ofxXmlSettings

62
src/ofxSourcesEditor.cpp

@ -28,9 +28,7 @@ void ofxSourcesEditor::unregisterAppEvents()
void ofxSourcesEditor::setup(ofEventArgs& args) void ofxSourcesEditor::setup(ofEventArgs& args)
{ {
gui = new ofxUICanvas(); gui = new ofxRadioList();
gui->disable();
gui->disableAppDrawCallback();
// read directory contents // read directory contents
ofDirectory imgDir; ofDirectory imgDir;
@ -44,15 +42,18 @@ void ofxSourcesEditor::setup(ofEventArgs& args)
vnames.push_back(imgDir.getName(i)); vnames.push_back(imgDir.getName(i));
} }
gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); gui->setup("Images", vnames);
ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); gui->setPosition(20, 20);
radio->activateToggle("image0.png"); ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent);
ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent);
} }
void ofxSourcesEditor::draw() void ofxSourcesEditor::draw()
{ {
// Don't draw if there is no source selected
if ( surfaceManager->getSelectedSurface() == NULL ) {
return;
}
gui->draw(); gui->draw();
} }
@ -73,6 +74,12 @@ void ofxSourcesEditor::disable()
void ofxSourcesEditor::enable() void ofxSourcesEditor::enable()
{ {
// Don't enable if there is no surface selected
if ( surfaceManager->getSelectedSurface() == NULL ) {
cout << "No surface selected. Not enable()ing source list." << endl;
return;
}
gui->enable(); gui->enable();
} }
@ -83,29 +90,14 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager)
void ofxSourcesEditor::selectImageSourceRadioButton(string name) void ofxSourcesEditor::selectImageSourceRadioButton(string name)
{ {
vector<ofxUIWidget*> widgets = gui->getWidgets();
// find radio list item
ofxUIRadio* radio;
for ( int i=0; i<widgets.size(); i++ ) {
int widgetKind = widgets[i]->getKind();
if ( widgetKind == OFX_UI_WIDGET_RADIO ){
radio = (ofxUIRadio*)widgets[i];
break;
}
}
if (name == "none") { if (name == "none") {
ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive(); gui->unselectAll();
if ( toggle != NULL ) {
toggle->setValue(false);
}
return; return;
} else { } else {
for ( int i=0; i<widgets.size(); i++ ) { int i;
string widgetName = widgets[i]->getName(); for (i = 0; i < gui->size(); i++) {
if ( name == widgetName ) { if (gui->getItemName(i) == name) {
radio->activateToggle(name); gui->selectItem(i);
return; return;
} }
} }
@ -126,24 +118,14 @@ ofTexture* ofxSourcesEditor::getTexture(int index)
return &images[index]->getTextureReference(); return &images[index]->getTextureReference();
} }
void ofxSourcesEditor::guiEvent(ofxUIEventArgs &e) void ofxSourcesEditor::guiEvent(string &imageName)
{ {
string name = e.widget->getName(); string name = imageName;
int kind = e.widget->getKind();
if(kind == OFX_UI_WIDGET_TOGGLE){
ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
cout << name << "\t value: " << toggle->getValue() << endl;
}
if ( surfaceManager->getSelectedSurface() == NULL ) { if ( surfaceManager->getSelectedSurface() == NULL ) {
return; return;
} }
if (name == "images") {
return;
}
stringstream ss; stringstream ss;
ss << defImgDir << name; ss << defImgDir << name;
cout << "attempt to load image: " << ss.str() << endl; cout << "attempt to load image: " << ss.str() << endl;

9
src/ofxSourcesEditor.h

@ -3,8 +3,8 @@
#include "ofGraphics.h" #include "ofGraphics.h"
#include "ofEvents.h" #include "ofEvents.h"
#include "ofxUI.h"
#include "ofxSurfaceManager.h" #include "ofxSurfaceManager.h"
#include "ofxRadioList.h"
#define DEFAULT_IMAGES_DIR "sources/images/"; #define DEFAULT_IMAGES_DIR "sources/images/";
@ -30,14 +30,11 @@ public:
private: private:
ofxSurfaceManager* surfaceManager; ofxSurfaceManager* surfaceManager;
ofxRadioList* gui;
string defImgDir; string defImgDir;
ofxUICanvas *gui; void guiEvent(string &imageName);
void guiEvent(ofxUIEventArgs &e);
vector<ofImage*> images; vector<ofImage*> images;
vector<string> imageNames; vector<string> imageNames;
//ofxPanel imgSrcPanel;
//void onSourceSelect(bool& value);
}; };
#endif #endif

188
src/ui/ofxRadioList.cpp

@ -0,0 +1,188 @@
#include "ofxRadioList.h"
ofxRadioList::ofxRadioList()
{
storedTitle = "";
storedSelectedItem = 0;
}
ofxRadioList::ofxRadioList(vector<string> &labels)
{
ofxRadioList();
setup(labels);
}
ofxRadioList::ofxRadioList(string title, vector<string> &labels)
{
ofxRadioList();
setup(title, labels);
}
ofxRadioList::~ofxRadioList()
{
clear();
}
void ofxRadioList::setup(vector<string> &labels)
{
// Copy incomming labels for later use
storedLabels = labels;
// Create toggles with labels from the labels arg
int i;
for (i = 0; i < labels.size(); i++) {
ofxToggle* toggle = new ofxToggle();
toggle->setup(false);
toggle->setName(labels[i]);
toggle->addListener(this, &ofxRadioList::onToggleClicked);
guiGroup.add(toggle);
}
cout << "num items: " << guiGroup.getNumControls() << endl;
}
void ofxRadioList::setup(string title, vector<string> &labels)
{
// Store title for later use
storedTitle = title;
guiGroup.setName(title);
setup(labels);
}
void ofxRadioList::draw()
{
guiGroup.draw();
}
void ofxRadioList::setTitle(string title)
{
storedTitle = title;
guiGroup.setName(title);
}
void ofxRadioList::setPosition(ofPoint p)
{
guiGroup.setPosition(p);
}
void ofxRadioList::setPosition(float x, float y)
{
guiGroup.setPosition(x, y);
}
void ofxRadioList::selectItem(int index)
{
if (index >= guiGroup.getNumControls()) {
return;
}
unselectAll();
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(index));
toggle->removeListener(this, &ofxRadioList::onToggleClicked);
*toggle = true; // Select the specific radio button
toggle->addListener(this, &ofxRadioList::onToggleClicked);
string name = toggle->getName();
ofNotifyEvent(radioSelectedEvent, name, this);
storedSelectedItem = index;
}
void ofxRadioList::enable()
{
if (guiGroup.getNumControls() >= 0) {
clear();
}
// Rebuild everyting
setup(storedTitle, storedLabels);
// Select the stored selected item without throwing an event
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(storedSelectedItem));
toggle->removeListener(this, &ofxRadioList::onToggleClicked);
*toggle = true;
toggle->addListener(this, &ofxRadioList::onToggleClicked);
cout << "num items after enable: " << guiGroup.getNumControls() << endl;
}
void ofxRadioList::disable()
{
// Just remove everything
clear();
}
void ofxRadioList::clear()
{
int i;
for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
toggle->removeListener(this, &ofxRadioList::onToggleClicked);
delete toggle;
}
guiGroup.clear();
}
void ofxRadioList::unselectAll()
{
int i;
for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
ofParameter<bool>* paramPtr = static_cast<ofParameter<bool>*>(&toggle->getParameter());
toggle->removeListener(this, &ofxRadioList::onToggleClicked);
*toggle = false;
toggle->addListener(this, &ofxRadioList::onToggleClicked);
}
}
ofPoint ofxRadioList::getPosition()
{
return guiGroup.getPosition();
}
float ofxRadioList::getWidth()
{
return guiGroup.getWidth();
}
float ofxRadioList::getHeight()
{
return guiGroup.getHeight();
}
string ofxRadioList::getTitle()
{
return guiGroup.getName();
}
string ofxRadioList::getItemName(int index)
{
if (index >= guiGroup.getNumControls()) {
return "";
}
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(index));
return toggle->getName();
}
int ofxRadioList::size()
{
return guiGroup.getNumControls();
}
void ofxRadioList::onToggleClicked(bool &toggleValue)
{
unselectAll();
// Search for the actual toggle triggering the event
int i;
for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
ofParameter<bool>* paramPtr = static_cast<ofParameter<bool>*>(&toggle->getParameter());
if (&(paramPtr->get()) == &toggleValue) {
selectItem(i);
break;
}
}
}

46
src/ui/ofxRadioList.h

@ -0,0 +1,46 @@
#pragma once
#include "ofGraphics.h"
#include "ofxGuiGroup.h"
#include "ofxToggle.h"
#include "ofxLabel.h"
class ofxRadioList
{
public:
ofxRadioList();
ofxRadioList(vector<string> &labels);
ofxRadioList(string title, vector<string> &labels);
~ofxRadioList();
void setup(vector<string> &labels);
void setup(string title, vector<string> &labels);
void draw();
void setTitle(string title);
void setPosition(ofPoint p);
void setPosition(float x, float y);
void selectItem(int index);
void enable();
void disable();
void clear();
void unselectAll();
ofPoint getPosition();
float getWidth();
float getHeight();
string getTitle();
string getItemName(int index);
int size();
// This event notifies about a toggle being selected and passes it's name to the listeners.
// Use ofAddListener(ofxRadioListInstance.radioSelectedEvent, listenerClassPtr, &listenerClass::listenerMethod)
// to listen to this. Listner method void listenerMethod(string & radioName)
ofEvent<string> radioSelectedEvent;
private:
vector<string> storedLabels;
string storedTitle;
ofxGuiGroup guiGroup;
int storedSelectedItem;
void onToggleClicked(bool &toggleValue);
};
Loading…
Cancel
Save