#include "testApp.h" //-------------------------------------------------------------- /* text editor functionality: keep text as 1 string? or as a vector of strings? prob faster to use a vector of strings for display makes it more awkward for selections? keep track of which line/char to start and end alternative - go through text and seperate into lines either by width or by /n every time it changes keep a display copy with /n's inserted? alternative - just have a horizontal scroll bar (contextual) maybe draw into an FBO in order to put a window in a window method to retreive text as a single string with \n's special key functions including ENTER, BACKSPACE, DELETE, ARROW KEYS drawing functionality: make line breaks (easier with mono font) set box size - draw scrollbar & set scrollpoint - drag to scroll insertion point/ selection - set with mouse - get and set clipboard (ofxFensterManager.h) vector insert a problem performance wise? you need to use an iterator to insert into a vector anyway- may as well use a list */ editorWindow::~editorWindow(){ cout << "editor window destroyed" << endl; } void editorWindow::setup(){ ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 400, 400, OF_WINDOW); win->setWindowTitle("editor"); win->addListener(this); selected=false; text.push_back(string("")); } void editorWindow::draw(){ for (int i=0;i::iterator i; string t; int l; switch (key) { case OF_KEY_RETURN: for (i=text.begin(),l=0;l<=insertionPoint.row;i++,l++) {} t=text[insertionPoint.row].substr(insertionPoint.column); text[insertionPoint.row].erase(insertionPoint.column); text.insert(i,t); insertionPoint.row++; insertionPoint.column=0; break; case 267: //OF_KEY_LEFT is wrong? insertionPoint.column--; if (insertionPoint.column<0) { if (insertionPoint.row>0) { insertionPoint.row--; insertionPoint.column=text[insertionPoint.row].size(); } else insertionPoint.column=0; } break; case 269: //OF_KEY_UP is wrong? if (insertionPoint.row>0) { insertionPoint.row--; insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size()); } break; case 268: //OF_KEY_RIGHT is wrong? insertionPoint.column++; if (insertionPoint.column>text[insertionPoint.row].size()) { if (text.size()>insertionPoint.column) { insertionPoint.row++; insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size()); } else insertionPoint.column--; } break; case 270: //OF_KEY_DOWN is wrong? if (text.size()>insertionPoint.row) { insertionPoint.row++; insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size()); } break; default: //char buf[2]; //sprintf(buf,"%c",key); //text[insertionPoint.row]+=buf; text[insertionPoint.row].insert(insertionPoint.column,1,(char)key); insertionPoint.column++; } } void editorWindow::keyReleased(int key){ //key repeat? } //-------------------------------------------------------------- void testApp::setup(){ ofBackground(0); ofSetColor(255); editorWin=new editorWindow(); editorWin->setup(); } //-------------------------------------------------------------- void testApp::update(){ } //-------------------------------------------------------------- void testApp::draw(){ } //-------------------------------------------------------------- void testApp::keyPressed(int key){ } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ }