Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ static Cursor_Renderer cr = {0};

void render_editor_into_tgb(SDL_Window *window, Tile_Glyph_Buffer *tgb, Editor *editor)
{
{
const Vec2f cursor_pos =
vec2f((float) editor->cursor_col * FONT_CHAR_WIDTH * FONT_SCALE,
(float) (-(int)editor->cursor_row) * FONT_CHAR_HEIGHT * FONT_SCALE);

camera_vel = vec2f_mul(
vec2f_sub(cursor_pos, camera_pos),
vec2fs(2.0f));

camera_pos = vec2f_add(camera_pos, vec2f_mul(camera_vel, vec2fs(DELTA_TIME)));
}

{
int w, h;
SDL_GetWindowSize(window, &w, &h);
Expand Down Expand Up @@ -148,23 +160,33 @@ void render_editor_into_fgb(SDL_Window *window, Free_Glyph_Buffer *fgb, Cursor_R
free_glyph_buffer_draw(fgb);
}

Vec2f cursor_pos = vec2fs(0.0f);
{
cursor_pos.y = -(float) editor->cursor_row * FREE_GLYPH_FONT_SIZE;

if (editor->cursor_row < editor->size) {
Line *line = &editor->lines[editor->cursor_row];
cursor_pos.x = free_glyph_buffer_cursor_pos(fgb, line->chars, line->size, vec2f(0.0, cursor_pos.y), editor->cursor_col);
}
}

cursor_renderer_use(cr);
{
glUniform2f(cr->resolution_uniform, (float) w, (float) h);
glUniform1f(cr->time_uniform, (float) SDL_GetTicks() / 1000.0f);
glUniform2f(cr->camera_uniform, camera_pos.x, camera_pos.y);
glUniform1f(cr->height_uniform, FREE_GLYPH_FONT_SIZE);

float y = -(float) editor->cursor_row * FREE_GLYPH_FONT_SIZE;
cursor_renderer_move_to(cr, cursor_pos);
cursor_renderer_draw();
}

float x = 0.0f;
if (editor->cursor_row < editor->size) {
Line *line = &editor->lines[editor->cursor_row];
x = free_glyph_buffer_cursor_pos(fgb, line->chars, line->size, vec2f(0.0, y), editor->cursor_col);
}
{
camera_vel = vec2f_mul(
vec2f_sub(cursor_pos, camera_pos),
vec2fs(2.0f));

cursor_renderer_move_to(cr, vec2f(x, y));
cursor_renderer_draw();
camera_pos = vec2f_add(camera_pos, vec2f_mul(camera_vel, vec2fs(DELTA_TIME)));
}
}

Expand Down Expand Up @@ -372,24 +394,6 @@ int main(int argc, char **argv)
#endif
}
break;

case SDL_MOUSEBUTTONDOWN: {
const Vec2f mouse_pos = vec2f((float) event.button.x, (float) event.button.y);
switch(event.button.button) {
case SDL_BUTTON_LEFT: {
const Vec2f click_pos =
vec2f_add(mouse_pos, vec2f_sub(vec2f(camera_pos.x, -camera_pos.y + FONT_CHAR_HEIGHT * FONT_SCALE),
vec2f_mul(window_size(window), vec2fs(0.5f))));

if(click_pos.x > 0.0f && click_pos.y > 0.0f) {
editor.cursor_col = (size_t) floorf(click_pos.x / ((float) FONT_CHAR_WIDTH * FONT_SCALE));
editor.cursor_row = (size_t) floorf(click_pos.y / ((float) FONT_CHAR_HEIGHT * FONT_SCALE));
}
}
break;
}
}
break;
}
}

Expand All @@ -400,18 +404,6 @@ int main(int argc, char **argv)
glViewport(0, 0, w, h);
}

{
const Vec2f cursor_pos =
vec2f((float) editor.cursor_col * FONT_CHAR_WIDTH * FONT_SCALE,
(float) (-(int)editor.cursor_row) * FONT_CHAR_HEIGHT * FONT_SCALE);

camera_vel = vec2f_mul(
vec2f_sub(cursor_pos, camera_pos),
vec2fs(2.0f));

camera_pos = vec2f_add(camera_pos, vec2f_mul(camera_vel, vec2fs(DELTA_TIME)));
}

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

Expand Down