Render and text system changes (minor)
This commit is contained in:
parent
70f888196f
commit
9d8ce4394b
1 changed files with 12 additions and 25 deletions
37
main.rb
37
main.rb
|
|
@ -263,7 +263,7 @@ end
|
|||
|
||||
|
||||
class HexagonTerminalWindow < Gosu::Window
|
||||
def initialize(width, height, fullscreen)
|
||||
def initialize(width, height, options={})
|
||||
# Window
|
||||
super
|
||||
self.caption = "Hexagon Terminal"
|
||||
|
|
@ -277,11 +277,10 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
recalculate_hexagons
|
||||
|
||||
# State
|
||||
@cursor_pos = [0, 1] # row-1, col-1
|
||||
@cursor_pos = [0, 0] # row minus 1, col minus 1
|
||||
@input_buffer = ""
|
||||
@output_buffer = "."
|
||||
@output_buffer = "Hello, world!"
|
||||
@active_styling = TextProps.new(@font)
|
||||
@do_redraw = true
|
||||
self.text_input = Gosu::TextInput.new
|
||||
@old_text = [0,'',0]
|
||||
|
||||
|
|
@ -309,10 +308,6 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
end
|
||||
|
||||
def needs_redraw?
|
||||
return @do_redraw
|
||||
end
|
||||
|
||||
def update
|
||||
hbgdb = $hex_bgs.debug_get_stats
|
||||
# puts "ids: #{hbgdb['i']}"
|
||||
|
|
@ -321,7 +316,6 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
|
||||
if @output_buffer.length > 0
|
||||
render_output
|
||||
@do_redraw = true
|
||||
end
|
||||
new_text = [
|
||||
self.text_input.selection_start,
|
||||
|
|
@ -334,6 +328,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
new_text[1],
|
||||
new_text[2]
|
||||
]
|
||||
@output_buffer += new_text[1]
|
||||
out = ''+new_text[1]
|
||||
if new_text[0]<new_text[2]
|
||||
out.insert(new_text[2],"\x1b[m|")
|
||||
|
|
@ -356,7 +351,6 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
end
|
||||
|
||||
def draw
|
||||
@do_redraw = false
|
||||
# Draw the background (clears the screen)
|
||||
Gosu::draw_rect(
|
||||
0, 0, @width, @height, $bg_color, 0
|
||||
|
|
@ -374,22 +368,14 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
# into the hex grid
|
||||
|
||||
@output_buffer.each_char.with_index do |char, i|
|
||||
if @escape_mode
|
||||
handle_escape_char(char)
|
||||
end
|
||||
case char
|
||||
when "\n"
|
||||
@cursor_pos[0] += 1
|
||||
@cursor_pos[1] = 0
|
||||
when "\x1b" # ESC
|
||||
@escape_mode = true
|
||||
@escape_buffer = ""
|
||||
next
|
||||
else
|
||||
@hexes[@cursor_pos[0]][@cursor_pos[1]].char = char
|
||||
@cursor_pos[1] += 1
|
||||
end
|
||||
|
||||
if @cursor_pos[1] >= @hexes[0].length
|
||||
@cursor_pos[0] += 1
|
||||
@cursor_pos[1] = 0
|
||||
|
|
@ -399,8 +385,7 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
scroll_with_new_line
|
||||
end
|
||||
end
|
||||
@do_redraw = true
|
||||
# @output_buffer = ""
|
||||
@output_buffer = ""
|
||||
end
|
||||
|
||||
def scroll_with_new_line
|
||||
|
|
@ -433,13 +418,15 @@ class HexagonTerminalWindow < Gosu::Window
|
|||
@next_row_is_shifted = !@next_row_is_shifted
|
||||
end
|
||||
|
||||
def handle_escape_char(char)
|
||||
@escape_buffer += @output_buffer[0]
|
||||
@output_buffer = @output_buffer[1..-1]
|
||||
end
|
||||
end
|
||||
|
||||
$hex_bgs = HexEditXref_BgGrphStore.new
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue