Class: SpriteKit::TreeRenderer

Inherits:
Object
  • Object
show all
Defined in:
mygame/lib/sprite_kit/tree_renderer.rb

Defined Under Namespace

Classes: Row

Constant Summary collapse

INDENT_SIZE =
20
ROW_HEIGHT =
24
FONT_SIZE =
14
ICON_SIZE =
16
COLOR_BG =

Colors

{ r: 30,  g: 30,  b: 40,  a: 255 }
COLOR_HOVER =
{ r: 60,  g: 60,  b: 80,  a: 200 }
COLOR_SELECTED =
{ r: 80,  g: 80,  b: 120, a: 220 }
COLOR_CURSOR =
{ r: 130, g: 180, b: 255, a: 255 }
COLOR_TEXT =
{ r: 220, g: 220, b: 220, a: 255 }
COLOR_DIR_ICON =
{ r: 255, g: 200, b: 80,  a: 255 }
COLOR_FILE_ICON =
{ r: 140, g: 200, b: 255, a: 255 }

Instance Method Summary collapse

Constructor Details

#initialize(tree, state: {}) ⇒ TreeRenderer

Returns a new instance of TreeRenderer.



17
18
19
20
21
22
23
# File 'mygame/lib/sprite_kit/tree_renderer.rb', line 17

def initialize(tree, state: {})
  @collapsed     = {}
  @tree          = tree
  @state         = state
  @scroll_offset = 0
  @selected_idx  = 0
end

Instance Method Details

#render(args, offset_x: 0, offset_y: 0, width: nil) ⇒ Object

Call this from your tick, passing args

Parameters:

  • width (Integer, nil) (defaults to: nil) —

    defaults to the rest of the screen after offset_x.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'mygame/lib/sprite_kit/tree_renderer.rb', line 27

def render(args, offset_x: 0, offset_y: 0, width: nil)
  @args  = args
  @width = width || args.grid.w - offset_x
  @mouse = args.inputs.mouse
  @rows  = []

  collect_rows(@tree.root_node, depth: 0)

  handle_scroll(args)
  handle_keyboard(args)

  panel_h = Grid.h

  @primitives = []
  @primitives << {
    x: offset_x, y: args.grid.h - panel_h,
    w: @width, h: panel_h,
    path: :solid,
    **COLOR_BG
  }

  @rows.each_with_index do |row, i|
    y = args.grid.h - ROW_HEIGHT * (i + 1) + offset_y + @scroll_offset
    next if y + ROW_HEIGHT < 0 || y > args.grid.h
    render_row(@primitives, row, i, y, offset_x: offset_x)
  end

  @primitives
end