Permalink
Browse files

drawing menu with a font

  • Loading branch information...
1 parent 62e1dbc commit bafee2685b326f8699a0ec616f64cb12bd5dda25 damian committed Apr 13, 2012
@@ -12,6 +12,7 @@
28d113b94b2437937ec1a8885bb9803c /* tinyxmlparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93fa7d544754488b1c9440d921b2aa7d /* tinyxmlparser.cpp */; };
2D6325E91535ADAC008B799B /* Binocular.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D6325E71535ADAC008B799B /* Binocular.cpp */; };
2D6325EC1535ADD2008B799B /* BinocularMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D6325EA1535ADD2008B799B /* BinocularMenu.cpp */; };
+ 2D6CC0121537451700B37D5F /* CommandlineParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D6CC0101537451700B37D5F /* CommandlineParser.cpp */; };
2D700B70152DEAC8004EC85B /* Detector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D700B0D152DEAC7004EC85B /* Detector.cpp */; };
2D700B71152DEAC8004EC85B /* ofxFern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D700B10152DEAC7004EC85B /* ofxFern.cpp */; };
2D700B72152DEAC8004EC85B /* cv_fast_10.cc in Sources */ = {isa = PBXBuildFile; fileRef = 2D700B13152DEAC7004EC85B /* cv_fast_10.cc */; };
@@ -142,6 +143,8 @@
2D6325E81535ADAC008B799B /* Binocular.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Binocular.h; sourceTree = "<group>"; };
2D6325EA1535ADD2008B799B /* BinocularMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BinocularMenu.cpp; sourceTree = "<group>"; };
2D6325EB1535ADD2008B799B /* BinocularMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BinocularMenu.h; sourceTree = "<group>"; };
+ 2D6CC0101537451700B37D5F /* CommandlineParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandlineParser.cpp; path = app/CommandlineParser.cpp; sourceTree = "<group>"; };
+ 2D6CC0111537451700B37D5F /* CommandlineParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandlineParser.h; path = app/CommandlineParser.h; sourceTree = "<group>"; };
2D700B0B152DEAC7004EC85B /* artvert_constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = artvert_constants.h; sourceTree = "<group>"; };
2D700B0D152DEAC7004EC85B /* Detector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Detector.cpp; sourceTree = "<group>"; };
2D700B0E152DEAC7004EC85B /* Detector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Detector.h; sourceTree = "<group>"; };
@@ -835,8 +838,8 @@
E4B69E1C0A3A1BDC003C02F2 /* src */ = {
isa = PBXGroup;
children = (
- 2DD111131535A15C00D16042 /* binocular */,
2D700B09152DEAC7004EC85B /* TheArtvertiserCommon */,
+ 2DD111131535A15C00D16042 /* binocular */,
E4B69E1D0A3A1BDC003C02F2 /* main.cpp */,
be9dd360f550b0df4d357e7bd03dbc87 /* app */,
c4f2d5fdc5ff4af7685f5c8aab43a2a6 /* ArtvertiserApp.cpp */,
@@ -900,6 +903,8 @@
e5d7c8562a58919cef5534a9a3caf149 /* OnlineArtverts.h */,
bd8a7f57ebdc7cb0dc9016d13051a739 /* TakeAPhoto.cpp */,
c75c0ead26eb23dfae68f387f0e7fe30 /* TakeAPhoto.h */,
+ 2D6CC0101537451700B37D5F /* CommandlineParser.cpp */,
+ 2D6CC0111537451700B37D5F /* CommandlineParser.h */,
);
name = app;
sourceTree = "<group>";
@@ -1139,6 +1144,7 @@
2DD111161535A15C00D16042 /* BinocularButtons.cpp in Sources */,
2D6325E91535ADAC008B799B /* Binocular.cpp in Sources */,
2D6325EC1535ADD2008B799B /* BinocularMenu.cpp in Sources */,
+ 2D6CC0121537451700B37D5F /* CommandlineParser.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -24,16 +24,16 @@
#include "PersistanceEngine.h"
#include "Label.h"
#include "Binocular.h"
+#include "CommandlineParser.h"
//void ofSoundShutdown(){};
int camW = 640;
int camH = 480;
//static const string SERVER_URL = "http://192.168.1.134:8888";
-static const string SERVER_URL = "http://localhost:8888";
-
-static const bool RUNNING_ON_BINOCULARS = true;
+//static const string SERVER_URL = "http://localhost:8888";
+static const string SERVER_URL = "http://192.168.1.4:8888";
//--------------------------------------------------------------
void ArtvertiserApp::setup(){
@@ -66,10 +66,12 @@ void ArtvertiserApp::setup(){
ofSetOrientation(OF_ORIENTATION_90_LEFT);
#endif
- bool runningOnBinoculars = RUNNING_ON_BINOCULARS;
+ bool runningOnBinoculars = CommandlineParser::get()->isRunningOnBinoculars();
if ( runningOnBinoculars )
{
Binocular::get()->setup( true );
+// ofAddListener( Binocular::get()->getArtvertSelectedEvent(), this, &ArtvertiserApp::artvertSelected );
+
}
grabber.setDeviceID(0);
@@ -122,9 +124,9 @@ void ArtvertiserApp::setup(){
ofAddListener(menu.cameraPressedE,this,&ArtvertiserApp::cameraPressed);
ofAddListener(menu.downloadPressedE,this,&ArtvertiserApp::downloadPressed);
- ofAddListener(menu.artvertSelectedE,this,&ArtvertiserApp::advertSelected);
+ ofAddListener(menu.advertSelectedEvent,this,&ArtvertiserApp::advertSelected);
- ofAddListener(artvertInfo.artvertSelectedE,this,&ArtvertiserApp::artvertSelected);
+ ofAddListener(artvertInfo.artvertSelectedEvent,this,&ArtvertiserApp::artvertSelected);
ofAddListener(onlineArtverts.downloadedE,this,&ArtvertiserApp::gotAnalysis);
@@ -81,7 +81,7 @@
ofPtr<gui::IconCache> iconCache;
ofPtr<ofxGeoLocation> geo;
-
+
bool allocated;
bool refreshArtvert;
@@ -0,0 +1,57 @@
+//
+// CommandlineParser.cpp
+// TheArtvertiserAndroid
+//
+// Created by Damian Stewart on 12/04/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#include "CommandlineParser.h"
+
+CommandlineParser* CommandlineParser::get()
+{
+ static CommandlineParser* instance = NULL;
+ if ( instance == NULL )
+ instance = new CommandlineParser();
+ return instance;
+}
+
+
+
+void CommandlineParser::parse( int argc, char **argv )
+{
+ runningOnBinoculars = false;
+
+ int c;
+ while ((c = getopt (argc, argv, "b")) != -1)
+ {
+ switch (c)
+ {
+ case 'b':
+ runningOnBinoculars = true;
+ break;
+ /*
+ case 'b':
+ bflag = 1;
+ break;
+ case 'c':
+ cvalue = optarg;
+ break;
+ case '?':
+ if (optopt == 'c')
+ fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+ else if (isprint (optopt))
+ fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+ else
+ fprintf (stderr,
+ "Unknown option character `\\x%x'.\n",
+ optopt);
+ return 1;
+ */
+ default:
+ fprintf( stderr, "Option ignored: -%c\n", optopt );
+ break;
+ }
+ }
+
+}
@@ -0,0 +1,27 @@
+//
+// CommandlineParser.h
+// TheArtvertiserAndroid
+//
+// Created by Damian Stewart on 12/04/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#pragma once
+
+class CommandlineParser
+{
+public:
+
+ static CommandlineParser* get();
+
+ void parse( int argc, char** argv );
+
+
+ bool isRunningOnBinoculars() { return runningOnBinoculars; }
+
+private:
+
+ bool runningOnBinoculars;
+
+};
+
@@ -9,30 +9,115 @@
#include "BinocularMenu.h"
#include "BinocularButtons.h"
#include "ofMain.h"
+#include "Artvert.h"
+
+static const float FONT_SIZE = 32.0f;
+
void BinocularMenu::setup( BinocularButtons& buttons )
{
ofAddListener( buttons.redButton, this, &BinocularMenu::redButtonPressed );
ofAddListener( buttons.blueButton, this, &BinocularMenu::blueButtonPressed );
ofAddListener( buttons.greenButton, this, &BinocularMenu::greenButtonPressed );
ofAddListener( buttons.redAndBlueButtons, this, &BinocularMenu::redAndBlueButtonPressed );
+
+ ofAddListener( ofEvents().update, this, &BinocularMenu::update );
+ ofAddListener( ofEvents().draw, this, &BinocularMenu::draw );
+
+
+ font.loadFont( "fonts/Delicious-Roman.otf", FONT_SIZE );
+
+ selectionIndex = 0;
+
+}
+
+void BinocularMenu::update( ofEventArgs& args )
+{
+
+}
+
+void BinocularMenu::draw( ofEventArgs& args )
+{
+ if ( showing )
+ {
+
+ float fontSize = FONT_SIZE;
+ float hGap = 4;
+ float lineHeight = fontSize+hGap;
+
+ // offset to keey the selection on-screen
+ float yOffset = FONT_SIZE + max(selectionIndex-5,0)*lineHeight;
+
+ ofSetColor( ofColor::black );
+
+ for ( int i=0; i<artverts.size(); i++)
+ {
+ string description = artverts[i].getDescription();
+
+ ofSetColor( ofColor::white );
+ font.drawString( ofToString( i+1 )+description, 10, i*lineHeight + yOffset );
+ ofSetColor( ofColor::black );
+ font.drawString( ofToString( i+1 )+description, 11, i*lineHeight + yOffset + 1 );
+ if ( i == selectionIndex )
+ {
+ ofSetColor( ofColor::white );
+ font.drawString( ofToString( i+1 )+description, 12, i*lineHeight + yOffset + 2 );
+ }
+ }
+
+
+ }
+}
+
+
+void BinocularMenu::updateArtvertList()
+{
+ /// fetch list of artverts from persistence engine and update descriptions and UIDs
+ artverts = Artvert::listAll();
}
void BinocularMenu::redButtonPressed( bool& tf )
{
- if ( tf )
- ofLog( OF_LOG_NOTICE, "red" );
+ if ( tf && showing )
+ {
+ selectionIndex--;
+ if ( selectionIndex<0 )
+ selectionIndex = artverts.size()-1;
+ }
}
+
void BinocularMenu::greenButtonPressed( bool& tf )
{
if ( tf )
- ofLog( OF_LOG_NOTICE, "green" );
+ {
+ if ( !showing )
+ {
+ updateArtvertList();
+ showing = true;
+ }
+ else
+ {
+ // tell listeners that a selection was made
+ if ( selectionIndex < artverts.size() )
+ {
+ string selectedUID = artverts[selectionIndex].getUID();
+ ofLog( OF_LOG_NOTICE, "ofNotifyEvent( artvertSelected, artverts[selectionIndex]. " );
+ }
+ showing = false;
+ }
+ }
}
+
void BinocularMenu::blueButtonPressed( bool& tf )
{
- if ( tf )
- ofLog( OF_LOG_NOTICE, "blue" );
+ if ( tf && showing )
+ {
+ selectionIndex++;
+ if ( selectionIndex>=artverts.size() )
+ selectionIndex = 0;
+ }
}
+
void BinocularMenu::redAndBlueButtonPressed( bool& tf )
{
if ( tf )
@@ -10,18 +10,39 @@
#include "ofMain.h"
#include "BinocularButtons.h"
+#include "IconCache.h"
+#include "Artvert.h"
+#include "ArtvertInfo.h"
class BinocularMenu
{
public:
void setup( BinocularButtons& buttons );
-private:
+ ofEvent<ofFile> artvertSelected;
+
+private:
+ void update( ofEventArgs& args );
+ void draw( ofEventArgs& args );
+
+ void updateArtvertList();
+
void redButtonPressed( bool& tf );
void greenButtonPressed( bool& tf );
void blueButtonPressed( bool& tf );
void redAndBlueButtonPressed( bool& tf );
+
+
+
+ bool showing;
+ int selectionIndex;
+
+ vector<Artvert> artverts;
+ ofTrueTypeFont font;
+
+ gui::IconCache iconCache;
+
};
View
@@ -28,9 +28,13 @@
#include "ofAppGlutWindow.h"
#endif
+#include "CommandlineParser.h"
-int main(){
+int main( int argc, char** argv ){
+
+ CommandlineParser::get()->parse( argc, argv );
+
#ifdef TARGET_ANDROID
ofPtr<ofAppAndroidWindow> window (new ofAppAndroidWindow);
#else

0 comments on commit bafee26

Please sign in to comment.