render cursor on y axis
This commit is contained in:
81
edit.jai
81
edit.jai
@@ -12,6 +12,11 @@ window_height := 600;
|
|||||||
|
|
||||||
first_line := 0;
|
first_line := 0;
|
||||||
|
|
||||||
|
cursor_x := 0;
|
||||||
|
cursor_y := 0;
|
||||||
|
|
||||||
|
White :: Vector4.{1, 1, 1, 1};
|
||||||
|
|
||||||
main :: () {
|
main :: () {
|
||||||
args := get_command_line_arguments();
|
args := get_command_line_arguments();
|
||||||
assert(args.count == 2, "The file name must be passed as a CLI argument");
|
assert(args.count == 2, "The file name must be passed as a CLI argument");
|
||||||
@@ -38,20 +43,7 @@ main :: () {
|
|||||||
|
|
||||||
Input.update_window_events();
|
Input.update_window_events();
|
||||||
|
|
||||||
for Input.get_window_resizes() {
|
handle_window_resizes(window);
|
||||||
Simp.update_window(it.window);
|
|
||||||
if it.window == window {
|
|
||||||
should_reinit := (it.width != window_width) || (it.height != window_height);
|
|
||||||
|
|
||||||
window_width = it.width;
|
|
||||||
window_height = it.height;
|
|
||||||
|
|
||||||
if should_reinit {
|
|
||||||
my_init_fonts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for event : Input.events_this_frame {
|
for event : Input.events_this_frame {
|
||||||
if event.type == .QUIT {
|
if event.type == .QUIT {
|
||||||
@@ -62,6 +54,11 @@ main :: () {
|
|||||||
if event.type == .KEYBOARD && event.key_pressed {
|
if event.type == .KEYBOARD && event.key_pressed {
|
||||||
if event.key_code == {
|
if event.key_code == {
|
||||||
case .ESCAPE; should_quit = true;
|
case .ESCAPE; should_quit = true;
|
||||||
|
|
||||||
|
case .ARROW_UP; #through;
|
||||||
|
case .ARROW_DOWN; #through;
|
||||||
|
case .ARROW_LEFT; #through;
|
||||||
|
case .ARROW_RIGHT; handle_arrow(event.key_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,14 +79,64 @@ main :: () {
|
|||||||
render_edit_buffer :: () {
|
render_edit_buffer :: () {
|
||||||
num_lines_in_screen := window_height / line_height - 1;
|
num_lines_in_screen := window_height / line_height - 1;
|
||||||
viewable_lines := array_view(lines, first_line, num_lines_in_screen);
|
viewable_lines := array_view(lines, first_line, num_lines_in_screen);
|
||||||
Simp.set_shader_for_text();
|
|
||||||
color :: Vector4.{1, 1, 1, 1};
|
|
||||||
for line_buffer: viewable_lines {
|
for line_buffer: viewable_lines {
|
||||||
|
Simp.set_shader_for_text();
|
||||||
|
|
||||||
line := builder_to_line(*line_buffer);
|
line := builder_to_line(*line_buffer);
|
||||||
|
|
||||||
Simp.prepare_text(my_font, line);
|
Simp.prepare_text(my_font, line);
|
||||||
Simp.draw_prepared_text(my_font, 5, window_height - (it_index + 1) * line_height, color);
|
top_of_line := window_height - (it_index + 1) * line_height;
|
||||||
|
Simp.draw_prepared_text(my_font, 5, top_of_line, White);
|
||||||
|
|
||||||
|
if it_index == cursor_y {
|
||||||
|
Simp.set_shader_for_color();
|
||||||
|
Simp.immediate_quad(
|
||||||
|
5., cast(float) top_of_line + line_height,
|
||||||
|
6., cast(float) top_of_line,
|
||||||
|
White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_window_resizes :: (window: Window_Type) {
|
||||||
|
for Input.get_window_resizes() {
|
||||||
|
Simp.update_window(it.window);
|
||||||
|
if it.window == window {
|
||||||
|
should_reinit := (it.width != window_width) || (it.height != window_height);
|
||||||
|
|
||||||
|
window_width = it.width;
|
||||||
|
window_height = it.height;
|
||||||
|
|
||||||
|
if should_reinit {
|
||||||
|
my_init_fonts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_arrow :: (key_code: Input.Key_Code) {
|
||||||
|
num_lines_in_screen := window_height / line_height - 1;
|
||||||
|
viewable_lines := array_view(lines, first_line, num_lines_in_screen);
|
||||||
|
|
||||||
|
max_chars := 30;
|
||||||
|
|
||||||
|
if key_code == {
|
||||||
|
case .ARROW_UP;
|
||||||
|
cursor_y = ifx cursor_y == 0
|
||||||
|
then 0
|
||||||
|
else cursor_y - 1;
|
||||||
|
case .ARROW_DOWN;
|
||||||
|
cursor_y = ifx cursor_y == viewable_lines.count
|
||||||
|
then viewable_lines.count
|
||||||
|
else cursor_y + 1;
|
||||||
|
case .ARROW_LEFT;
|
||||||
|
cursor_x = ifx cursor_x == 0
|
||||||
|
then 0
|
||||||
|
else cursor_x - 1;
|
||||||
|
case .ARROW_RIGHT;
|
||||||
|
cursor_y = ifx cursor_x == max_chars
|
||||||
|
then max_chars
|
||||||
|
else cursor_x + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user