Get typing mostly working

This commit is contained in:
Joseph Ferano 2023-09-21 23:34:38 +07:00
parent 9d725d0b2f
commit 6ccf44bef5
2 changed files with 85 additions and 10 deletions

43
fide.todo Normal file
View File

@ -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

View File

@ -4,7 +4,9 @@
#include <SDL2/SDL_render.h>
#include <stdio.h>
#include <iostream>
#include <ext/rope>
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<char> 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<char>::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);
}