|
|
@@ -9,10 +9,7 @@
|
|
|
#include "vec2.h"
|
|
|
#include "window.h"
|
|
|
|
|
|
-struct buffer {
|
|
|
- DA_DEF_STRUCT_ITEM(char, data);
|
|
|
- uint64_t cur;
|
|
|
-};
|
|
|
+#include "buffer.h"
|
|
|
|
|
|
struct app {
|
|
|
struct window win;
|
|
|
@@ -35,7 +32,6 @@ void app_render_char(struct app app, const char c, struct vec2 pos,
|
|
|
void app_render_text(struct app app, const char *text, size_t text_size,
|
|
|
struct vec2 pos, uint32_t color, double scale);
|
|
|
|
|
|
-#define IMP
|
|
|
#if defined(APP_IMP) || defined(IMP)
|
|
|
|
|
|
#define UNHEX_COLOR(hex) \
|
|
|
@@ -52,7 +48,8 @@ app_create(const char *win_title)
|
|
|
struct app app = {
|
|
|
.win = window_create(win_title),
|
|
|
.rdr = NULL,
|
|
|
- .running = true
|
|
|
+ .running = true,
|
|
|
+ .buf = buffer_create()
|
|
|
};
|
|
|
|
|
|
app.rdr = SDL_CreateRenderer(app.win.ptr, -1, SDL_RENDERER_ACCELERATED);
|
|
|
@@ -63,6 +60,7 @@ app_create(const char *win_title)
|
|
|
}
|
|
|
SCP(app.rdr);
|
|
|
|
|
|
+
|
|
|
return app;
|
|
|
}
|
|
|
|
|
|
@@ -117,6 +115,9 @@ app_render_text(struct app app, const char *text, size_t text_size,
|
|
|
for ( ; i < text_size; ++i ) {
|
|
|
c = text[i];
|
|
|
if ( c == '\n' ) {
|
|
|
+ if ( i == app.buf.cur ) {
|
|
|
+ app_render_cursor_in_pos(app, pen, 0xFF00FFFF);
|
|
|
+ }
|
|
|
pen.x = pos.x;
|
|
|
pen.y += (double) (app.font.ch_h * scale);
|
|
|
continue;
|
|
|
@@ -146,9 +147,11 @@ app_render_cursor_in_pos(struct app app, struct vec2 pos, uint32_t color)
|
|
|
SCE(SDL_RenderFillRect(app.rdr, &rect));
|
|
|
|
|
|
if ( app.buf.cur < app.buf.data.size ) {
|
|
|
+ char c = app.buf.data.items[app.buf.cur];
|
|
|
+ if ( c == '\n' ) return ;
|
|
|
+
|
|
|
uint32_t old_color = app_get_text_color(app);
|
|
|
app_set_text_color(app, ((~color) | 0xFF));
|
|
|
- char c = app.buf.data.items[app.buf.cur];
|
|
|
app_render_char(app, c, pos, app.font.scale);
|
|
|
app_set_text_color(app, old_color);
|
|
|
}
|