Render and text system changes (minor)

This commit is contained in:
Mewrry the Kitty 2025-11-30 21:01:10 -06:00
parent 70f888196f
commit 9d8ce4394b

37
main.rb
View file

@ -263,7 +263,7 @@ end
class HexagonTerminalWindow < Gosu::Window class HexagonTerminalWindow < Gosu::Window
def initialize(width, height, fullscreen) def initialize(width, height, options={})
# Window # Window
super super
self.caption = "Hexagon Terminal" self.caption = "Hexagon Terminal"
@ -277,11 +277,10 @@ class HexagonTerminalWindow < Gosu::Window
recalculate_hexagons recalculate_hexagons
# State # State
@cursor_pos = [0, 1] # row-1, col-1 @cursor_pos = [0, 0] # row minus 1, col minus 1
@input_buffer = "" @input_buffer = ""
@output_buffer = "." @output_buffer = "Hello, world!"
@active_styling = TextProps.new(@font) @active_styling = TextProps.new(@font)
@do_redraw = true
self.text_input = Gosu::TextInput.new self.text_input = Gosu::TextInput.new
@old_text = [0,'',0] @old_text = [0,'',0]
@ -309,10 +308,6 @@ class HexagonTerminalWindow < Gosu::Window
end end
end end
def needs_redraw?
return @do_redraw
end
def update def update
hbgdb = $hex_bgs.debug_get_stats hbgdb = $hex_bgs.debug_get_stats
# puts "ids: #{hbgdb['i']}" # puts "ids: #{hbgdb['i']}"
@ -321,7 +316,6 @@ class HexagonTerminalWindow < Gosu::Window
if @output_buffer.length > 0 if @output_buffer.length > 0
render_output render_output
@do_redraw = true
end end
new_text = [ new_text = [
self.text_input.selection_start, self.text_input.selection_start,
@ -334,6 +328,7 @@ class HexagonTerminalWindow < Gosu::Window
new_text[1], new_text[1],
new_text[2] new_text[2]
] ]
@output_buffer += new_text[1]
out = ''+new_text[1] out = ''+new_text[1]
if new_text[0]<new_text[2] if new_text[0]<new_text[2]
out.insert(new_text[2],"\x1b[m|") out.insert(new_text[2],"\x1b[m|")
@ -356,7 +351,6 @@ class HexagonTerminalWindow < Gosu::Window
end end
def draw def draw
@do_redraw = false
# Draw the background (clears the screen) # Draw the background (clears the screen)
Gosu::draw_rect( Gosu::draw_rect(
0, 0, @width, @height, $bg_color, 0 0, 0, @width, @height, $bg_color, 0
@ -374,22 +368,14 @@ class HexagonTerminalWindow < Gosu::Window
# into the hex grid # into the hex grid
@output_buffer.each_char.with_index do |char, i| @output_buffer.each_char.with_index do |char, i|
if @escape_mode
handle_escape_char(char)
end
case char case char
when "\n" when "\n"
@cursor_pos[0] += 1 @cursor_pos[0] += 1
@cursor_pos[1] = 0 @cursor_pos[1] = 0
when "\x1b" # ESC
@escape_mode = true
@escape_buffer = ""
next
else else
@hexes[@cursor_pos[0]][@cursor_pos[1]].char = char @hexes[@cursor_pos[0]][@cursor_pos[1]].char = char
@cursor_pos[1] += 1 @cursor_pos[1] += 1
end end
if @cursor_pos[1] >= @hexes[0].length if @cursor_pos[1] >= @hexes[0].length
@cursor_pos[0] += 1 @cursor_pos[0] += 1
@cursor_pos[1] = 0 @cursor_pos[1] = 0
@ -399,8 +385,7 @@ class HexagonTerminalWindow < Gosu::Window
scroll_with_new_line scroll_with_new_line
end end
end end
@do_redraw = true @output_buffer = ""
# @output_buffer = ""
end end
def scroll_with_new_line def scroll_with_new_line
@ -433,13 +418,15 @@ class HexagonTerminalWindow < Gosu::Window
@next_row_is_shifted = !@next_row_is_shifted @next_row_is_shifted = !@next_row_is_shifted
end end
def handle_escape_char(char)
@escape_buffer += @output_buffer[0]
@output_buffer = @output_buffer[1..-1]
end
end end
$hex_bgs = HexEditXref_BgGrphStore.new $hex_bgs = HexEditXref_BgGrphStore.new
recalculate_hexagons recalculate_hexagons
window = HexagonTerminalWindow.new(800, 600, false) FPS = 20.0
window = HexagonTerminalWindow.new(800, 600, {
:resizable => true,
:fullscreen => false,
:borderless => false,
:update_interval => (1000/FPS) # 1000ms (1s) cut into FPS pieces
})
window.show window.show