diff options
| author | Comment <tim@gray.(none)> | 2012-12-27 16:22:17 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2012-12-27 16:22:17 +0000 |
| commit | f855d3ba224c878dae5ef02688b7c0b8630b1348 (patch) | |
| tree | 217af2fe1fd38b1822fa7133a7d57152991da5c0 /src | |
| parent | 1a4a66963e5899a973bbcd20f2101d75765987a9 (diff) | |
mouse selection nearly
Diffstat (limited to 'src')
| -rwxr-xr-x | src/testApp.cpp | 46 | ||||
| -rwxr-xr-x | src/testApp.h | 6 |
2 files changed, 47 insertions, 5 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 2147e71..0cffe26 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -42,6 +42,8 @@ void editorWindow::setup(){ text.push_back(string("")); } void editorWindow::draw(){ + ofDisableAlphaBlending(); + ofSetColor(255,255,255); for (int i=0;i<text.size();i++) { ofDrawBitmapString(text[i],10,15+(i*12)); } @@ -57,7 +59,22 @@ void editorWindow::draw(){ with a vector of strings and then row/column insertion point its prob better */ if (selected) { + ofEnableAlphaBlending(); + ofSetColor(0,128,255,160); //draw selection + if (selectionStart.row==selectionEnd.row) { + ofRect((selectionStart.column*8)+10,(selectionStart.row*12)+5,(selectionEnd.column-selectionStart.column)*8,12); + } + else if (selectionStart.row<selectionEnd.row) { + ofRect((selectionStart.column*8)+10,(selectionStart.row*12)+5,(text[selectionStart.row].size()-selectionStart.column)*8,12); + for (int i=selectionStart.row+1;i<selectionEnd.row;i++) { + ofRect(10,(i*12)+5,(text[i].size())*8,12); + } + ofRect(10,(selectionEnd.row*12)+5,(selectionEnd.column)*8,12); + } + else if (selectionStart.row>selectionEnd.row) { + } + ofDisableAlphaBlending(); } else { //draw insertion point @@ -115,7 +132,7 @@ void editorWindow::keyPressed(int key){ insertionPoint.row++; insertionPoint.column=0; break; - case 267: //OF_KEY_LEFT is wrong? + case 267: //OF_KEY_LEFT in fenster insertionPoint.column--; if (insertionPoint.column<0) { if (insertionPoint.row>0) { @@ -125,13 +142,13 @@ void editorWindow::keyPressed(int key){ else insertionPoint.column=0; } break; - case 269: //OF_KEY_UP is wrong? + case 269: //OF_KEY_UP in fenster if (insertionPoint.row>0) { insertionPoint.row--; insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size()); } break; - case 268: //OF_KEY_RIGHT is wrong? + case 268: //OF_KEY_RIGHT in fenster insertionPoint.column++; if (insertionPoint.column>text[insertionPoint.row].size()) { if (text.size()>insertionPoint.column) { @@ -141,7 +158,7 @@ void editorWindow::keyPressed(int key){ else insertionPoint.column--; } break; - case 270: //OF_KEY_DOWN is wrong? + case 270: //OF_KEY_DOWN in fenster if (insertionPoint.row<text.size()) { insertionPoint.row++; insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size()); @@ -157,6 +174,27 @@ void editorWindow::keyPressed(int key){ void editorWindow::keyReleased(int key){ //key repeat? } +void editorWindow::mousePressed(int x, int y, int button){ + selected=false; + clickX=x; + clickY=y; +} +void editorWindow::mouseReleased(int x, int y, int button){ + if (clickX=x&&clickY==y) { + insertionPoint=clickPos(x,y); + } +} +void editorWindow::mouseDragged(int x, int y, int button){ + selected=true; + selectionStart=clickPos(clickX,clickY); + selectionEnd=clickPos(x,y); +} +texPt editorWindow::clickPos(int x,int y) { + texPt t; + t.row=min((int)text.size()-1,(y-5)/12); + t.column=min((int)text[insertionPoint.row].size(),(x-10)/8); + return t; +} //-------------------------------------------------------------- void testApp::setup(){ diff --git a/src/testApp.h b/src/testApp.h index 6c7ccf2..dde4502 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -29,7 +29,6 @@ class testApp : public ofxFensterListener { void gotMessage(ofMessage msg); editorWindow *editorWin; - }; class editorWindow: public ofxFensterListener{ @@ -39,11 +38,16 @@ class editorWindow: public ofxFensterListener{ void draw(); void keyPressed(int key); void keyReleased(int key); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseDragged(int x, int y, int button); + texPt clickPos(int x,int y); private: vector<string> text; texPt insertionPoint; texPt selectionStart; texPt selectionEnd; bool selected; + int clickX,clickY; }; |
