summaryrefslogtreecommitdiff
path: root/src/testApp.cpp
blob: 5a182483fd1064b2f1742f7d065ae7009aa4550a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#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)


*/
editorWindow::~editorWindow(){
	cout << "editor window destroyed" << endl;

}
void editorWindow::setup(){
    ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0,  600, 600, OF_WINDOW);
	win->setWindowTitle("editor");
	win->addListener(this);
	selected=false;
	text.push_back(string(""));
}
void editorWindow::draw(){

    for (int i=0;i<text.size();i++) {
        ofDrawBitmapString(text[i],10,15+(i*12));
    }
    //draw blinking cursor
    /*
    not trivial if we deal with 1 string with /ns in
    we have to scan the file for /ns every time we display the blinking cursor
    is easier with vectors?
    the difficulty here is that its messy to remember row/column
    can we even get the height of a string formatted block
    shorter strings make inserting quicker
    could have a single string and maintain a vector representing line breaks- however inserting a char meansn having to manipulate the entire vector
    with a vector of strings and then row/column insertion point its prob better
    */
    if (selected) {
        //draw selection
    }
    else {
        //draw insertion point
        if ((ofGetElapsedTimeMillis()/300)%2) {
            ofRect((insertionPoint.column*8)+10,(insertionPoint.row*12)+5,2,10);
        }
    }

}
/*
	#define OF_KEY_LEFT			(100 | OF_KEY_MODIFIER)
	#define OF_KEY_UP			(101 | OF_KEY_MODIFIER)
	#define OF_KEY_RIGHT		(102 | OF_KEY_MODIFIER)
	#define OF_KEY_DOWN			(103 | OF_KEY_MODIFIER)
	#define OF_KEY_PAGE_UP		(104 | OF_KEY_MODIFIER)
	#define OF_KEY_PAGE_DOWN	(105 | OF_KEY_MODIFIER)
	#define OF_KEY_HOME			(106 | OF_KEY_MODIFIER)
	#define OF_KEY_END			(107 | OF_KEY_MODIFIER)
	#define OF_KEY_INSERT
*/
void editorWindow::keyPressed(int key){
    printf("%i\n",key);
    switch (key) {
        case OF_KEY_RETURN:
            text.push_back(string(""));
            insertionPoint.row=text.size()-1;
            insertionPoint.column=0;
            break;
        case OF_KEY_LEFT:
            printf("left\n");
            insertionPoint.column--;
            if (insertionPoint.column<0) {
                if (insertionPoint.row>0) {
                    insertionPoint.row--;
                    insertionPoint.column=text[insertionPoint.row].size();
                }
                else insertionPoint.column=0;
            }
            break;
        case OF_KEY_UP:
            printf("up\n");
            if (insertionPoint.row>0) {
                insertionPoint.row--;
                insertionPoint.column=min(insertionPoint.column,(int)text[insertionPoint.row].size());
            }
            break;
        case OF_KEY_RIGHT:
            printf("right\n");
            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 OF_KEY_DOWN:
            printf("down\n");
            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;
            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){

}