Skip to content

Commit

Permalink
consolidate cursor positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiekircher committed Nov 6, 2011
1 parent 8939093 commit 8227904
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
54 changes: 28 additions & 26 deletions lib/vimcity/vim_city_game.rb
Expand Up @@ -27,6 +27,7 @@ def initialize
@width = @main_window.width

@insert_mode = false
@current_building = nil

@map = Map.new(@main_buffer)

Expand Down Expand Up @@ -110,9 +111,9 @@ def init_city

def init_cursor
@cursor = [" "] #use an array for area cursors
c = VIM::evaluate("getpos('.')")
@last_chars = cache_area(@main_buffer, c[1], 1, c[2], 1)
print_area_to_buffer(@main_buffer, c[1], c[2], @cursor)
c = get_cursor_pos
@last_chars = cache_area(@main_buffer, c[0], 1, c[1], 1)
print_area_to_buffer(@main_buffer, c[0], c[1], @cursor)
end

def update_status_bar
Expand All @@ -125,37 +126,37 @@ def update_status_bar
end

def update_cursor(x,y)
c = VIM::evaluate("getpos('.')")
c = get_cursor_pos

cursor_height = @cursor.size
cursor_width = @cursor.first.size

print_area_to_buffer(@main_buffer, c[1], c[2], @last_chars)
print_area_to_buffer(@main_buffer, c[0], c[1], @last_chars)

c[1] += y
c[1] = 1 if c[1] < 1
c[1] = @map.height+1 if c[1] >= @map.height+1
c[0] += y
c[0] = 1 if c[0] < 1
c[0] = @map.height+1 if c[0] >= @map.height+1

c[2] += x
c[2] = @map.offset if c[2] < @map.offset
c[2] = @map.width-(@map.offset-1) if c[2] >= (@map.width+@map.offset)
c[1] += x
c[1] = @map.offset if c[1] < @map.offset
c[1] = @map.width-(@map.offset-0) if c[1] >= (@map.width+@map.offset)

VIM::evaluate("cursor(#{c[1]},#{c[2]})")
set_cursor_pos(c[0], c[1])

@last_char = cache_area(@main_buffer,
c[1], cursor_height,
c[2], cursor_width)
print_area_to_buffer(@main_buffer, c[1], c[2], @cursor)
c[0], cursor_height,
c[1], cursor_width)
print_area_to_buffer(@main_buffer, c[0], c[1], @cursor)
end

def reset_cursor
c = VIM::evaluate("getpos('.')")
print_area_to_buffer(@main_buffer, c[1], c[2], @last_chars)
c = get_cursor_pos
print_area_to_buffer(@main_buffer, c[0], c[1], @last_chars)
@last_chars = cache_area(@main_buffer,
c[1], 1,
c[2], 1)
c[0], 1,
c[1], 1)
@cursor = [" "]
print_area_to_buffer(@main_buffer, c[1], c[2], @cursor)
print_area_to_buffer(@main_buffer, c[0], c[1], @cursor)

return
end
Expand Down Expand Up @@ -221,15 +222,16 @@ def building_menu
quit

#c = VIM::Window.current.cursor
c = VIM::evaluate("getpos('.')")
print_area_to_buffer(@main_buffer, c[1], c[2], @last_chars)
c = get_cursor_pos
print_area_to_buffer(@main_buffer, c[0], c[1], @last_chars)
@last_chars = cache_area(@main_buffer,
c[1], building.height,
c[2], building.width)
@cursor = building.symbol if building
print_area_to_buffer(@main_buffer, c[1], c[2], @cursor)
c[0], building.height,
c[1], building.width)
@cursor = building.symbol
print_area_to_buffer(@main_buffer, c[0], c[1], @cursor)

@insert_mode = true
@current_building = building
return
else
break
Expand Down
8 changes: 8 additions & 0 deletions lib/vimcity/vim_wrapper.rb
@@ -1,5 +1,13 @@
module VimWrapper

def get_cursor_pos
return VIM::evaluate("getpos('.')")[1,2]
end

def set_cursor_pos(y,x)
return VIM::evaluate("cursor(#{y},#{x})")
end

def redraw
VIM::command("redraw")
end
Expand Down

0 comments on commit 8227904

Please sign in to comment.