Created
January 7, 2015 09:59
-
-
Save simongeilfus/db9dee222d67cceed285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/AppNative.h" | |
#include "cinder/app/RendererGl.h" | |
#include "cinder/gl/gl.h" | |
#include "cinder/gl/TextureFont.h" | |
using namespace ci; | |
using namespace ci::app; | |
using namespace std; | |
class CinderProjectApp : public AppNative { | |
public: | |
void setup() override; | |
void keyDown( KeyEvent event ) override; | |
void draw() override; | |
gl::TextureFontRef mTexFont; | |
}; | |
void CinderProjectApp::setup() | |
{ | |
disableFrameRate(); | |
mTexFont = gl::TextureFont::create( Font( "Helvetica", 12 ) ); | |
getWindow()->setTitle( "Window_" + to_string( getNumWindows() ) ); | |
} | |
void CinderProjectApp::keyDown( KeyEvent event ) | |
{ | |
size_t windows = getNumWindows(); | |
switch ( event.getCode() ) { | |
case KeyEvent::KEY_a: | |
if( !event.isShiftDown() ){ | |
createWindow()->setTitle( "Window_" + to_string( getNumWindows() ) ); | |
} | |
else { | |
auto x = getDisplay()->getWidth() / getWindowWidth(); | |
for( int i = 0; i < 10; i++ ){ | |
auto w = createWindow(); | |
w->setPos( vec2( i % x, i / x ) * vec2( getWindowSize() ) ); | |
w->setTitle( "Window_" + to_string( getNumWindows() ) ); | |
} | |
} | |
break; | |
case KeyEvent::KEY_b: | |
if( !event.isShiftDown() ){ | |
for( size_t window = 0; window < windows; window ++ ){ | |
auto w = getWindowIndex( window ); | |
w->setBorderless( !w->isBorderless() ); | |
} | |
} | |
else { | |
auto x = getDisplay()->getWidth() / getWindowWidth(); | |
for( int i = 0; i < 10; i++ ){ | |
auto w = createWindow( Window::Format().borderless() ); | |
w->setPos( vec2( i % x, i / x ) * vec2( getWindowSize() ) ); | |
w->setTitle( "Window_" + to_string( getNumWindows() ) ); | |
} | |
} | |
break; | |
case KeyEvent::KEY_f: | |
for( size_t window = 0; window < windows; window ++ ){ | |
auto w = getWindowIndex( window ); | |
w->setFullScreen( !w->isFullScreen() ); | |
} | |
break; | |
case KeyEvent::KEY_h: | |
for( size_t window = 1; window < windows; window ++ ){ | |
auto w = getWindowIndex( window ); | |
if( w->isHidden() ) w->show(); | |
else w->hide(); | |
} | |
break; | |
case KeyEvent::KEY_c: | |
vec2 center = getDisplay() ? vec2( getDisplay()->getSize() / 2 - getWindowSize() / 2 ) | |
: vec2( 640 / 360 ); | |
for( size_t window = 1; window < windows; window ++ ){ | |
auto w = getWindowIndex( window ); | |
if( w ) w->setPos( center ); | |
} | |
break; | |
} | |
} | |
void CinderProjectApp::draw() | |
{ | |
gl::clear( Color( 0, 0, 0 ) ); | |
if( gl::isVerticalSyncEnabled() ) gl::enableVerticalSync( false ); | |
gl::enableAlphaBlending( mTexFont->isPremultiplied() ); | |
mTexFont->drawString( to_string( (int) getAverageFps() ), vec2( 10, 20 ) ); | |
} | |
CINDER_APP_NATIVE( CinderProjectApp, RendererGl( RendererGl::Options().msaa(0) ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment