From 6ccf44bef51071f768638a7be25389e58283d97e Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Thu, 21 Sep 2023 23:34:38 +0700 Subject: [PATCH] Get typing mostly working --- fide.todo | 43 +++++++++++++++++++++++++++++++++++++++++++ main.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 85 insertions(+), 10 deletions(-) create mode 100644 fide.todo diff --git a/fide.todo b/fide.todo new file mode 100644 index 0000000..0e6f9f0 --- /dev/null +++ b/fide.todo @@ -0,0 +1,43 @@ +#-*- mode: org -*- +#+TODO: TODO | DONE +#+STARTUP: show2levels + + +* DONE Create SDL hello world +* DONE Research which data structure to use (ext/rope.h) +* DONE Figure out how to render text in SDL (font texture atlas) +* DONE Insert text into rope from keyboard presses +* DONE Render rope +* DONE Handle colors and font texture blitting +* DONE Get backspace working +* TODO Scale text with C-+ and C-- +* TODO Read a file from disk and display it +* TODO Create a cursor +* TODO Add basic keybinding system +* TODO Move cursor with arrow keys +* TODO Save file +* TODO Render each line in a different color +To help figuring out how to color things for syntax highlighting +* TODO Install treesitter package +* TODO Color different parts of the buffer based on AST +* TODO Create vertical/horizontal window splits +* TODO Make splits resizable +* TODO Buffer lists per pane +* TODO Pane owned sub-panes +* TODO Promote or demote panes as sub-panes +* TODO Pinnable/dedicated buffers +Panes and their sub-panes can have buffers pinned to them that require a +keybinding to override. +* TODO Custom buffer and pane variables +* TODO Floating splits +* TODO Buffers tags/ids +* TODO Pane attributes that modify it's behavior +- [ ] Pinnable +- [ ] Toggleable +- [ ] Overtake? +- [ ] Popup +* TODO Narrowing/widening +* TODO Read-only mode +* TODO Implement key chording +* TODO Implement modal editing modes +* TODO Keymap layering stack diff --git a/main.cpp b/main.cpp index c3441ae..d140c2b 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,9 @@ #include #include #include +#include +using namespace __gnu_cxx; using namespace std; //Screen dimension constants @@ -38,8 +40,8 @@ void render_char(char key, int row, int col, SDL_Renderer* renderer, SDL_Texture dstrect.x = col; dstrect.y = row; - dstrect.w = 80; - dstrect.h = 80; + dstrect.w = 30; + dstrect.h = 30; SDL_Rect srcrect = get_srcrect(key); SDL_RenderCopy(renderer, font, &srcrect, &dstrect); @@ -116,17 +118,35 @@ int main(int argc, char *argv[]) { int keyPressed = -1; int rowCurr = 0; int colCurr = 0; - string text = "Some text"; + float scale = 50; + rope buffer; while (quit == false) { while (SDL_PollEvent( &e)) { if (e.type == SDL_QUIT) { quit = true; - } - else if (e.type == SDL_KEYDOWN) { + } else if (e.type == SDL_KEYDOWN) { char key = e.key.keysym.sym; - if (key >= (char)'!' || key <= (char)'~') { - keyPressed = key; + char mod = e.key.keysym.mod; + if (key == '\r') { + buffer.push_back('\n'); } + if (key == '-' && mod & KMOD_LCTRL) { + cout << "Minu" << endl; + } + if (key == '=' && mod & KMOD_LCTRL) { + cout << "Ploos" << endl; + } + if (key >= (char)'!' || key <= (char)'~') { + // keyPressed = key; + buffer.push_back(key); + } + if (key == SDLK_BACKSPACE) { + if (buffer.size() >= 2) { + buffer.pop_back(); + buffer.pop_back(); + } + } + cout << key << endl; // switch (e.key.keysym.sym) { // case SDLK_ // } @@ -134,11 +154,23 @@ int main(int argc, char *argv[]) { } // SDL_FillRect( screenSurface, NULL, rgbMap); SDL_RenderClear(renderer); - SDL_SetTextureColorMod(fontTexture, 0xFF, 0, 0); - for (int i = 0; i < 10; i++) { - render_char(text[i], rowCurr, colCurr++ * 50, renderer, fontTexture); + SDL_SetTextureColorMod(fontTexture, 0x0, 0, 0); + rope::iterator it; + for (it = buffer.mutable_begin(); it != buffer.mutable_end(); it++) { + if (*it == '\n') { + rowCurr += 1; + colCurr = 0; + continue; + } + if (*it == '\r') { + continue; + } + if (*it >= (char)'!' || *it <= (char)'~') { + render_char(*it, rowCurr * 70, colCurr++ * 50, renderer, fontTexture); + } } colCurr = 0; + rowCurr = 0; // Draw(keyPressed, renderer, fontTexture); SDL_RenderPresent(renderer); }