diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/testApp.cpp | 109 | ||||
| -rwxr-xr-x | src/testApp.h | 8 |
2 files changed, 68 insertions, 49 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index babc8e7..b2f35e2 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,33 +1,11 @@ #include "testApp.h" //-------------------------------------------------------------- - -/* - -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 - -set box size - draw scrollbar & set scrollpoint - drag to scroll - -load & save - -architecture :- text editor in a box or a window? - -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); + ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 400, 400, OF_WINDOW); win->setWindowTitle("editor"); win->addListener(this); selected=false; @@ -36,15 +14,22 @@ void editorWindow::setup(){ output=""; windowResized(400,400); insX=2;insY=2; + scrollY=false;scrollX=false; + scrollPosY=0;scrollPosX=0; + scrollSelY=scrollSelX=false; } -void editorWindow::windowResized(int _w, int _h){ - w=_w;h=_h; - screen.allocate(w-insX-4,h-insY-4); +void editorWindow::screenResize(){ + w=ofGetWidth();h=ofGetHeight(); + screen.allocate(w-(insX*2)-(scrollY?15:0),h-(insY*2)-(scrollX?15:0)); printf("editor window resized to %ix%i\n",w,h); changed=true; } void editorWindow::draw(){ - if (w!=ofGetWidth()||h!=ofGetHeight()) windowResized(ofGetWidth(),ofGetHeight()); + bool sY=(((text.size()*12)+(insY*2))>h); + if (sY!=scrollY||w!=ofGetWidth()||h!=ofGetHeight()) { + scrollY=sY; + screenResize(); + } if (changed) drawScreen(); ofSetColor(255,255,255); screen.draw(insX,insY); @@ -54,6 +39,22 @@ void editorWindow::draw(){ ofRect((insertionPoint.column*8)+insX,(insertionPoint.row*12)+insY,2,10); } } + if (scrollY) { + if (scrollX) { + ofLine(0,h-15,w-15,h-15); + ofLine(w-15,0,w-15,h-15); + } + else ofLine(w-15,0,w-15,h); + } + else if (scrollX) ofLine(0,h-15,w,h-15); + if (scrollY) { + float yBarSize=(((float)h-(insX*2)-15)/(text.size()*12))*((float)h-(insX*2)-15); + float yBarPos=2; //+ actual scroll amount + if (scrollSelY) ofFill(); + else ofNoFill(); + ofRect(w-12,yBarPos,11,yBarSize); + ofFill(); + } } void editorWindow::drawScreen(){ screen.begin(); @@ -184,30 +185,44 @@ void editorWindow::keyReleased(int key){ //key repeat? } void editorWindow::mousePressed(int x, int y, int button){ - selected=false; - clickX=x; - clickY=y; - changed=true; + clickX=x; + clickY=y; + if (scrollY&&x>(h-16)) { + scrollSelY=true; + } + else { + selected=false; + changed=true; + } } void editorWindow::mouseReleased(int x, int y, int button){ - if (clickX=x&&clickY==y) { - insertionPoint=clickPos(x,y); - } - changed=true; + if (scrollSelY) { + scrollSelY=false; + } + else { + if (clickX=x&&clickY==y) { + insertionPoint=clickPos(x,y); + } + changed=true; + } } void editorWindow::mouseDragged(int x, int y, int button){ - texPt c1=clickPos(clickX,clickY); - texPt c2=clickPos(x,y); - if ((c1.row==c2.row&&c2.column>c1.column)||c2.row>c1.row) { - selectionStart=c1; - selectionEnd=c2; - } - else { - selectionStart=c2; - selectionEnd=c1; - } - if (selectionStart.row!=selectionEnd.row||selectionStart.column!=selectionEnd.column) selected=true; - changed=true; + if (scrollSelY) { + } + else { + texPt c1=clickPos(clickX,clickY); + texPt c2=clickPos(x,y); + if ((c1.row==c2.row&&c2.column>c1.column)||c2.row>c1.row) { + selectionStart=c1; + selectionEnd=c2; + } + else { + selectionStart=c2; + selectionEnd=c1; + } + if (selectionStart.row!=selectionEnd.row||selectionStart.column!=selectionEnd.column) selected=true; + changed=true; + } } texPt editorWindow::clickPos(int x,int y) { texPt t; diff --git a/src/testApp.h b/src/testApp.h index 30dc033..b51e215 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -40,12 +40,15 @@ class editorWindow: public ofxFensterListener{ void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseDragged(int x, int y, int button); - void windowResized(int w, int h); //doesn't seem to work normally string getText(); private: - void drawScreen(); int w,h; + bool scrollY,scrollX; + int scrollPosY,scrollPosX; + bool scrollSelY,scrollSelX; ofFbo screen; + void drawScreen(); + void screenResize(); texPt clickPos(int x,int y); int clickX,clickY; void setClipboard(string text); @@ -53,6 +56,7 @@ class editorWindow: public ofxFensterListener{ void insertText(string text); void deleteSelection(); vector<string> text; + int maxLineLength; int insX,insY; texPt insertionPoint; texPt selectionStart; |
