Skip to content

Commit

Permalink
Added the event to trigger keyboard event in testApp. Still messy, bu…
Browse files Browse the repository at this point in the history
…t working.
  • Loading branch information
jeffcrouse committed Nov 10, 2010
1 parent 9837ff9 commit 28a2dd8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 43 deletions.
27 changes: 22 additions & 5 deletions example/softKeyboardExample/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

//--------------------------------------------------------------
void testApp::setup(){
ofSetFrameRate(24);

vagRounded.loadFont("vag.ttf", 32);

keyboard.setup( this, OFXSK_LAYOUT_KEYBOARD_FULL );

sprintf(eventString, "framerate: %f", ofGetFrameRate());
}

//--------------------------------------------------------------
Expand All @@ -13,18 +19,29 @@ void testApp::update(){
//--------------------------------------------------------------
void testApp::draw(){

keyboard.draw(100, 100);
keyboard.draw(100, 350);

float w = vagRounded.stringWidth(eventString);
float h = vagRounded.stringHeight(eventString);

ofSetColor(0xffffff);
vagRounded.drawString(eventString, 98,198);

ofSetColor(255,122,220);
vagRounded.drawString(eventString, 100,200);

}

//--------------------------------------------------------------
void testApp::keyPressed(int key){

void testApp::keyPressed(int key) {

sprintf(eventString, "keyPressed = %c (ASCII %i)", key, key);
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

void testApp::keyReleased(int key) {

sprintf(eventString, "keyReleased = %c (ASCII %i)", key, key);
}

//--------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions example/softKeyboardExample/src/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class testApp : public ofBaseApp{
void windowResized(int w, int h);

ofxSoftKeyboard keyboard;

ofTrueTypeFont vagRounded;
char eventString[255];
};

#endif
31 changes: 26 additions & 5 deletions src/ofxSoftKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
*/

#include "ofxSoftKey.h"
#include "testApp.h"


#pragma mark CONSTRUCTORS

//--------------------------------------------------------------
ofxSoftKey::ofxSoftKey(char _key) {
ofxSoftKey::ofxSoftKey(char _key, testApp* _testapp) {

testapp = _testapp;

setKey(_key);
setPos(0, 0);
setSize(40, 40);

textColor = 0x000000;;
Expand All @@ -29,8 +33,10 @@ ofxSoftKey::ofxSoftKey(char _key) {
enableKeyEvents();

padding = new int[4];
setPadding(5, 5, 5, 5);
}

#pragma mark PADDING

//--------------------------------------------------------------
void ofxSoftKey::setPadding(int top, int right, int bottom, int left) {
Expand All @@ -40,6 +46,16 @@ void ofxSoftKey::setPadding(int top, int right, int bottom, int left) {
padding[PADDING_LEFT] = left;
}

//--------------------------------------------------------------
void ofxSoftKey::padLeft(int left) {
padding[PADDING_LEFT] += left;
}

//--------------------------------------------------------------
void ofxSoftKey::padRight(int right) {
padding[PADDING_RIGHT] += right;
}

#pragma mark APP EVENTS


Expand Down Expand Up @@ -115,7 +131,7 @@ ofxSoftKey &ofxSoftKey::setBorderColor(int c) {

//--------------------------------------------------------------
void ofxSoftKey::onRollOver(int x, int y) {

cout << "over!" << endl;
}

//--------------------------------------------------------------
Expand All @@ -141,11 +157,15 @@ void ofxSoftKey::onDragOutside(int x, int y, int button) {
//--------------------------------------------------------------
void ofxSoftKey::onPress(int x, int y, int button) {

testapp->keyPressed((int)key);
//ofNotifyEvent(ofEvents.keyPressed, (int)key, testapp);
}

//--------------------------------------------------------------
void ofxSoftKey::onRelease(int x, int y, int button) {


testapp->keyReleased((int)key);
//ofNotifyEvent(ofEvents.keyReleased, (int)key, testapp));
}

//--------------------------------------------------------------
Expand All @@ -158,10 +178,11 @@ void ofxSoftKey::onReleaseOutside(int x, int y, int button) {

//--------------------------------------------------------------
void ofxSoftKey::keyPressed( int key ) {

}

//--------------------------------------------------------------
void ofxSoftKey::keyReleased( int key ) {


}
7 changes: 5 additions & 2 deletions src/ofxSoftKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
#include "ofMain.h"
#include "ofxMSAInteractiveObject.h"


class testApp;
class ofxSoftKey : public ofxMSAInteractiveObject {
public:

bool isLastInRow;
int* padding;

ofxSoftKey(char key);
ofxSoftKey(char key, testApp* testapp);

void setPadding(int top, int right, int bottom, int left);
void padLeft(int left);
void padRight(int right);

ofxSoftKey& setKey(const char key);
ofxSoftKey& setTextColor(int c);
Expand All @@ -54,6 +56,7 @@ class ofxSoftKey : public ofxMSAInteractiveObject {

protected:

testApp* testapp;
char key;
int textColor, textBGColor, borderColor, hoverColor, clickColor;

Expand Down
57 changes: 29 additions & 28 deletions src/ofxSoftKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
#include "ofxSoftKeyboard.h"

ofxSoftKeyboard::ofxSoftKeyboard() {

padding = 10;
setLayout(OFXSK_LAYOUT_KEYBOARD_FULL);

}

//--------------------------------------------------------------
ofxSoftKeyboard::~ofxSoftKeyboard() {

// TO DO: delete keys
for(int i=0; i<keys.size(); i++) {
//delete keys[i];
delete keys[i];
}
}

//--------------------------------------------------------------
void ofxSoftKeyboard::setup( testApp* _testapp, int layout ) {

testapp = _testapp;
setLayout(layout);
}


//--------------------------------------------------------------
void ofxSoftKeyboard::setLayout(int layout) {

Expand All @@ -38,8 +42,8 @@ void ofxSoftKeyboard::setLayout(int layout) {
break;
case OFXSK_LAYOUT_KEYBOARD_FULL:
addKey('q'); addKey('w'); addKey('e'); addKey('r'); addKey('t'); addKey('y'); addKey('u'); addKey('i'); addKey('o'); addKey('p'); addKey('['); addKey(']'); newRow();
addPadding(0,0,0,10); addKey('a'); addKey('s'); addKey('d'); addKey('f'); addKey('g'); addKey('h'); addKey('j'); addKey('k'); addKey('l'); addKey(';'); addKey('\''); addKey(OF_KEY_RETURN); newRow();
addPadding(0,0,0,20); addKey('z'); addKey('x'); addKey('c'); addKey('v'); addKey('b'); addKey('n'); addKey('m'); addKey(','); addKey('.'); addKey('/'); newRow();
addKey('a')->padLeft(10); addKey('s'); addKey('d'); addKey('f'); addKey('g'); addKey('h'); addKey('j'); addKey('k'); addKey('l'); addKey(';'); addKey('\''); newRow();
addKey('z')->padLeft(20); addKey('x'); addKey('c'); addKey('v'); addKey('b'); addKey('n'); addKey('m'); addKey(','); addKey('.'); addKey('/'); newRow();
break;
}
}
Expand All @@ -50,43 +54,40 @@ void ofxSoftKeyboard::reset() {
}

//--------------------------------------------------------------
ofxSoftKey& ofxSoftKeyboard::addKey(char c) {
ofxSoftKey* ofxSoftKeyboard::addKey(char c) {

keys.push_back( ofxSoftKey(c) );
keys.back().setPadding(padding, padding, padding, padding);
ofxSoftKey* key = new ofxSoftKey(c, testapp );
key->setPadding(10,10,10,10);
keys.push_back( key );
return keys.back();
}

//--------------------------------------------------------------
void ofxSoftKeyboard::newRow() {

keys.back().isLastInRow = true;
}

//--------------------------------------------------------------
void ofxSoftKeyboard::addPadding(int top, int right, int bottom, int left) {

keys.back().setPadding(padding+top, padding+right, padding+bottom, padding+left);
keys.back()->isLastInRow = true;
}

//--------------------------------------------------------------
void ofxSoftKeyboard::draw(float x, float y) {

int j=0;
int xpos = x;
int ypos = y;

for(int i=0; i<keys.size(); i++)
{
keys[i].setPos(xpos, ypos);
keys[i].draw();
if(keys[i].isLastInRow ) {
j++;
xpos = x;
ypos += keys[i].height+ keys[i].padding[PADDING_BOTTOM];
xpos += keys[i]->padding[PADDING_LEFT];

keys[i]->setPos(xpos, ypos);
keys[i]->draw();

if(keys[i]->isLastInRow) {

xpos = x;
ypos += keys[i]->height + keys[i]->padding[PADDING_BOTTOM];

} else {
xpos += keys[i].width;
xpos += keys[i]->width + keys[i]->padding[PADDING_RIGHT];
}

xpos += keys[i].padding[PADDING_RIGHT];
}
}
10 changes: 7 additions & 3 deletions src/ofxSoftKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
#define OFXSK_LAYOUT_KEYPAD 1
#define OFXSK_LAYOUT_KEYBOARD_FULL 2

class testApp;

class ofxSoftKeyboard {
public:
ofxSoftKeyboard();
~ofxSoftKeyboard();

void setup( testApp* testapp, int layout );
void setLayout(int layout);
void addPadding(int top, int right, int bottom, int left);
void reset();
void draw(float x, float y);
ofxSoftKey& addKey(char c);
ofxSoftKey* addKey(char c);
void newRow();


protected:

int padding;
vector<ofxSoftKey> keys;
testApp* testapp;
vector<ofxSoftKey*> keys;

};

#endif

0 comments on commit 28a2dd8

Please sign in to comment.