Skip to content

Instantly share code, notes, and snippets.

@andrewfb
Created April 8, 2013 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewfb/5338181 to your computer and use it in GitHub Desktop.
Save andrewfb/5338181 to your computer and use it in GitHub Desktop.
Demonstrates using params::InterfaceGl with multiple windows.
#include "cinder/app/AppBasic.h"
#include "cinder/Rand.h"
#include "cinder/params/params.h"
#include <list>
using namespace ci;
using namespace ci::app;
using namespace std;
// We'll create a new Cinder Application by deriving from the AppBasic class
class BasicAppMultiWindow : public AppBasic {
public:
void setup();
void createNewWindow();
void mouseDrag( MouseEvent event );
void keyDown( KeyEvent event );
void draw();
};
// The window-specific data for each window
class WindowData {
public:
WindowData( app::WindowRef win )
: mColor( Color( CM_HSV, randFloat(), 0.8f, 0.8f ) ) // a random color
{
mParams = params::InterfaceGl( win, "App parameters", toPixels( Vec2i( 200, 400 ) ) );
mParams.addParam( "Cube Color", &mColor, "" );
}
Color mColor;
list<Vec2f> mPoints; // the points drawn into this window
params::InterfaceGl mParams;
};
void BasicAppMultiWindow::setup()
{
// for the default window we need to provide an instance of WindowData
getWindow()->setUserData( new WindowData( getWindow() ) );
createNewWindow();
}
void BasicAppMultiWindow::createNewWindow()
{
app::WindowRef newWindow = createWindow( Window::Format().size( 400, 400 ) );
newWindow->setUserData( new WindowData( newWindow ) );
// for demonstration purposes, we'll connect a lambda unique to this window which fires on close
int uniqueId = getNumWindows();
newWindow->getSignalClose().connect(
[uniqueId,this] { this->console() << "You closed window #" << uniqueId << std::endl; }
);
}
void BasicAppMultiWindow::mouseDrag( MouseEvent event )
{
WindowData *data = getWindow()->getUserData<WindowData>();
// add this point to the list
data->mPoints.push_back( event.getPos() );
}
void BasicAppMultiWindow::keyDown( KeyEvent event )
{
if( event.getChar() == 'f' )
setFullScreen( ! isFullScreen() );
else if( event.getChar() == 'w' )
createNewWindow();
}
void BasicAppMultiWindow::draw()
{
gl::clear( Color( 0.1f, 0.1f, 0.15f ) );
WindowData *data = getWindow()->getUserData<WindowData>();
gl::color( data->mColor );
gl::begin( GL_LINE_STRIP );
for( auto pointIter = data->mPoints.begin(); pointIter != data->mPoints.end(); ++pointIter ) {
gl::vertex( *pointIter );
}
gl::end();
data->mParams.draw();
}
// This line tells Cinder to actually create the application
CINDER_APP_BASIC( BasicAppMultiWindow, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment