|
1 | 1 | //! @file |
2 | 2 | //! This is the main file of the project, containing the main event loop and renderer |
3 | 3 |
|
4 | | -#define SDL_MAIN_HANDLED //done prereleaase |
| 4 | +#define SDL_MAIN_HANDLED //reformat code and fix highlighting bugs!!! |
5 | 5 | //create constexpr for columnwidth and columnheight |
6 | 6 | #include <SDL2-2.0.12/include/SDL.h> |
7 | 7 | #include <immer-0.6.2/immer/flex_vector.hpp> |
@@ -46,8 +46,6 @@ char unshiftLetter(char key); |
46 | 46 | //! better::edit1 initialises a text editor the size of the window passed by its pointer. |
47 | 47 | //! It also reads in the file into its own text buffer, and contains the event loop for that text edit. |
48 | 48 |
|
49 | | -better::Text tab(better::Text text); |
50 | | - |
51 | 49 | better::Text mouseMotion(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor); |
52 | 50 |
|
53 | 51 | better::Text keyDown(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor); |
@@ -84,7 +82,7 @@ bool operator!=(better::Text lhs, better::Text rhs); |
84 | 82 |
|
85 | 83 | } |
86 | 84 |
|
87 | | -int main(int argc, char* argv[]) { |
| 85 | +int WinMain(int argc, char* argv[]) { |
88 | 86 | SDL_SetMainReady(); |
89 | 87 | SDL_Init(SDL_INIT_VIDEO); |
90 | 88 |
|
@@ -328,7 +326,23 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su |
328 | 326 | } |
329 | 327 | else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) { |
330 | 328 | text.highlightStart = text.highlightEnd; |
331 | | - return better::newLine(text); |
| 329 | + std::vector<better::Text> texts {text}; //fix scrolling here for newline near bottom of text |
| 330 | + |
| 331 | + if((text.cursor.column - 1 > -1) && ((text.textEdit[text.cursor.row][text.cursor.column - 1] == '{' && text.textEdit[text.cursor.row][text.cursor.column] == '}') || (text.textEdit[text.cursor.row][text.cursor.column - 1] == '(' && text.textEdit[text.cursor.row][text.cursor.column] == ')'))) { |
| 332 | + if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) { |
| 333 | + texts.back().topLineNumber += 3; |
| 334 | + } |
| 335 | + texts.push_back(better::newLine(better::newLine(texts.back()))); |
| 336 | + texts.push_back(better::verticalNav(texts.back(),SDL_SCANCODE_UP, better::textHeight(), better::textWidth())); |
| 337 | + texts.push_back(better::tab(texts.back())); |
| 338 | + } |
| 339 | + else { |
| 340 | + if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) { |
| 341 | + texts.back().topLineNumber += 1; |
| 342 | + } |
| 343 | + texts.push_back(better::newLine(texts.back())); |
| 344 | + } |
| 345 | + return texts.back(); |
332 | 346 | } |
333 | 347 |
|
334 | 348 | else if(event.key.keysym.scancode == SDL_SCANCODE_TAB) { |
@@ -358,7 +372,7 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su |
358 | 372 | if(text.data.isCaps) { |
359 | 373 | key = better::shiftLetter(key); |
360 | 374 | } |
361 | | - if(text.data.isScroll) { |
| 375 | + if(text.data.isScroll) { //change this |
362 | 376 | text.topLineNumber = text.cursor.row; |
363 | 377 | text.topColumnNumber = 0; |
364 | 378 | } |
@@ -535,10 +549,6 @@ better::Text better::mouseMotion(better::Text text, SDL_Event event, SDL_Surface |
535 | 549 | return text; |
536 | 550 | } |
537 | 551 |
|
538 | | -better::Text better::tab(better::Text text) { |
539 | | - return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' '); |
540 | | -} |
541 | | - |
542 | 552 | void better::quitApp(SDL_Cursor* cursor, SDL_Surface* surface, SDL_Window* window) { |
543 | 553 | SDL_FreeCursor(cursor); |
544 | 554 | SDL_FreeSurface(surface); |
|
0 commit comments