diff --git a/src/Core/datatypes.cpp b/src/Core/datatypes.cpp index dd63fe0..475f4ad 100644 --- a/src/Core/datatypes.cpp +++ b/src/Core/datatypes.cpp @@ -2,7 +2,6 @@ //! This file contains all of the user defined structs used throughout the project //constexpr for textheight and textwidth, edit conditionals, get rid of ternaries #include "datatypes.hpp" -#include better::Text better::updateText(better::Text textEdit, char newChar) { const int textHeight {60}; @@ -55,6 +54,7 @@ better::Text better::newLine(better::Text textEdit) { //create cases for the fol bool endOfText {textEdit.cursor.row == textEdit.textEdit.size() - 1 ? true : false}; bool textSizeRightSize {textEdit.textEdit.size() > (textHeight - 1) ? true : false}; //if end of text make sure to not just append a new row + better::Text newText {endOfText ? textEdit.textEdit.set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)).push_back(textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)) : textEdit.textEdit.insert(textEdit.cursor.row + 1, textEdit.textEdit[textEdit.cursor.row].drop(textEdit.cursor.column)).set(textEdit.cursor.row, textEdit.textEdit[textEdit.cursor.row].take(textEdit.cursor.column)), {textEdit.cursor.row + 1, 0}, {{false,false,false,false},textEdit.data.isShift,textEdit.data.isCaps,textEdit.data.isScroll,textEdit.data.isCtrl,textEdit.data.clearHistory,-1,textEdit.data.menu,textEdit.data.filename}, endOfText ? (textSizeRightSize ? textEdit.topLineNumber + 1 : 0) : textEdit.topLineNumber, 0, textEdit.highlightStart, textEdit.highlightEnd}; //insert newline unless at bottom int prevIndent {better::getPreviousIndentLevel(textEdit, textEdit.cursor.row)}; texts.push_back(newText); @@ -105,6 +105,9 @@ int better::getPreviousIndentLevel(better::Text text, int row) { break; } } - return notSpace; + return notSpace; } +better::Text better::tab(better::Text text) { + return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' '); +} diff --git a/src/Core/datatypes.hpp b/src/Core/datatypes.hpp index 64dabf3..37d522f 100644 --- a/src/Core/datatypes.hpp +++ b/src/Core/datatypes.hpp @@ -11,6 +11,14 @@ namespace better { +constexpr int textWidth() { + return 150; +} + +constexpr int textHeight() { + return 60; +} + struct Cursor { //store the line number and column number of the cursor int row; int column; @@ -51,6 +59,7 @@ better::charMapArr makeCharMapArr(::Uint8 charArray[16]); better::Text updateText(better::Text textEdit, char newChar); better::Text backspace(better::Text textEdit); better::Text newLine(better::Text textEdit); +better::Text tab(better::Text text); Uint8 getRed(Uint32 color); Uint8 getGreen(Uint32 color); diff --git a/src/Core/fileUtils.cpp b/src/Core/fileUtils.cpp index 86c5d07..96e4763 100644 --- a/src/Core/fileUtils.cpp +++ b/src/Core/fileUtils.cpp @@ -2,7 +2,6 @@ //! This file handles all of the file stream functionality of the program #include "fileUtils.hpp" -#include int better::saveFile(immer::flex_vector> contents, std::string filename) { std::string buffer {""}; diff --git a/src/Core/main.cpp b/src/Core/main.cpp index 97746bb..5be96ba 100644 --- a/src/Core/main.cpp +++ b/src/Core/main.cpp @@ -1,7 +1,7 @@ //! @file //! This is the main file of the project, containing the main event loop and renderer -#define SDL_MAIN_HANDLED //done prereleaase +#define SDL_MAIN_HANDLED //reformat code and fix highlighting bugs!!! //create constexpr for columnwidth and columnheight #include #include @@ -46,8 +46,6 @@ char unshiftLetter(char key); //! better::edit1 initialises a text editor the size of the window passed by its pointer. //! It also reads in the file into its own text buffer, and contains the event loop for that text edit. -better::Text tab(better::Text text); - better::Text mouseMotion(better::Text text, SDL_Event event, SDL_Surface* surface, SDL_Cursor* guiCursor); 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); } -int main(int argc, char* argv[]) { +int WinMain(int argc, char* argv[]) { SDL_SetMainReady(); SDL_Init(SDL_INIT_VIDEO); @@ -328,7 +326,23 @@ better::Text better::keyDown(better::Text text, SDL_Event event, SDL_Surface* su } else if(event.key.keysym.scancode == SDL_SCANCODE_RETURN) { text.highlightStart = text.highlightEnd; - return better::newLine(text); + std::vector texts {text}; //fix scrolling here for newline near bottom of text + + 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] == ')'))) { + if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) { + texts.back().topLineNumber += 3; + } + texts.push_back(better::newLine(better::newLine(texts.back()))); + texts.push_back(better::verticalNav(texts.back(),SDL_SCANCODE_UP, better::textHeight(), better::textWidth())); + texts.push_back(better::tab(texts.back())); + } + else { + if(texts.back().cursor.row != texts.back().textEdit.size() - 1 && texts.back().cursor.row >= texts.back().topLineNumber + better::textHeight() - 2) { + texts.back().topLineNumber += 1; + } + texts.push_back(better::newLine(texts.back())); + } + return texts.back(); } 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 if(text.data.isCaps) { key = better::shiftLetter(key); } - if(text.data.isScroll) { + if(text.data.isScroll) { //change this text.topLineNumber = text.cursor.row; text.topColumnNumber = 0; } @@ -535,10 +549,6 @@ better::Text better::mouseMotion(better::Text text, SDL_Event event, SDL_Surface return text; } -better::Text better::tab(better::Text text) { - return better::updateText(better::updateText(better::updateText(better::updateText(text,' '),' '),' '),' '); -} - void better::quitApp(SDL_Cursor* cursor, SDL_Surface* surface, SDL_Window* window) { SDL_FreeCursor(cursor); SDL_FreeSurface(surface); diff --git a/src/Core/makefile b/src/Core/makefile index 38d4977..5f2529f 100644 --- a/src/Core/makefile +++ b/src/Core/makefile @@ -1,2 +1,2 @@ main: main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp - clang++ -O3 -std=c++20 -o BetterCode.exe main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp -m64 -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/detail/rbts/" -lC:/Users/TFran/VisionCode/src/Libs/SDL2main -lC:/Users/TFran/VisionCode/src/Libs/SDL2 + clang++ -O3 -mwindows -std=c++20 -o BetterCode.exe main.cpp datatypes.cpp fileUtils.cpp renderchars.cpp menubar.cpp -m64 -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/" -I"C:/Program Files/LLVM/lib/clang/11.0.0/include/immer-0.6.2/immer/detail/rbts/" -lC:/Users/TFran/VisionCode/src/Libs/SDL2main -lC:/Users/TFran/VisionCode/src/Libs/SDL2