Class: AuthorEngine::Palette

Inherits:
Object
  • Object
show all
Includes:
AuthorEngine::Part::Colors, Support
Defined in:
lib/author_engine/palette.rb

Constant Summary

Constants included from AuthorEngine::Part::Colors

AuthorEngine::Part::Colors::COLORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AuthorEngine::Part::Colors

#black, #blue, #brown, #dark_blue, #dark_gray, #dark_green, #dark_purple, #green, #indigo, #light_gray, #orange, #peach, #pink, #red, #rgb, #white, #xml_color, #yellow

Methods included from Support

#code_editor, #mouse_over?, #sprite_editor, #window

Constructor Details

#initialize(x:, y:, size: 8) ⇒ Palette

Returns a new instance of Palette.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/author_engine/palette.rb', line 7

def initialize(x:, y:, size: 8)
  @x_padding = window.scale_x
  @y_padding = window.scale_y

  @size = (size * @y_padding)
  @slot_width = 8

  set_origin(x, y)

  @color_set = [
    [
      black,
      dark_blue,
      dark_purple,
      dark_green
    ],
    [
      brown,
      dark_gray,
      light_gray,
      white
    ],
    [
      red,
      orange,
      yellow,
      green
    ],
    [
      blue,
      indigo,
      pink,
      peach
    ]
  ]
  @active_set = 0
  @active_color = nil
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/author_engine/palette.rb', line 6

def height
  @height
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/author_engine/palette.rb', line 6

def width
  @width
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/author_engine/palette.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/author_engine/palette.rb', line 6

def y
  @y
end

Instance Method Details

#button_up(id) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/author_engine/palette.rb', line 75

def button_up(id)
  if id == Gosu::MsLeft
    @color_set.each_with_index do |row, i|
      row.each_with_index do |color, x|
        if window.mouse_x.between?(@x+(x*@size), @x+(x*@size) + @size)
          if window.mouse_y.between?(@y + (@size*i), @y + (@size*i) + @size)
            @active_color = color
          end
        end
      end
    end
  end
end

#colorObject



46
47
48
# File 'lib/author_engine/palette.rb', line 46

def color
  @active_color
end

#drawObject



66
67
68
69
70
# File 'lib/author_engine/palette.rb', line 66

def draw
  Gosu.draw_rect(@x-window.square_scale, @y-window.square_scale, @width + (window.square_scale*2), @height + (window.square_scale*2), light_gray)
  draw_colors
  hightlight_active_color
end

#draw_colorsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/author_engine/palette.rb', line 89

def draw_colors
  @color_set.each_with_index do |row, i|
    row.each_with_index do |color, x|
      z = color == @active_color ? 100 : 7
      Gosu.draw_rect(
        @x+(x*@size), @y+(@size*i),
        @size, @size,
        color,
        z
      )
    end
  end
end

#hightlight_active_colorObject



103
104
105
106
107
108
109
110
111
112
# File 'lib/author_engine/palette.rb', line 103

def hightlight_active_color
  @color_set.each_with_index do |row, i|
    row.each_with_index do |color, x|
      if color == @active_color
        Gosu.draw_rect(@x+(x*@size)-window.square_scale, (@y+(@size*i))-window.square_scale, @size+(window.square_scale*2), @size+(window.square_scale*2), Gosu::Color.rgba(255,255,255, 200), 8)
        break
      end
    end
  end
end

#set_origin(x, y) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/author_engine/palette.rb', line 50

def set_origin(x, y)
  _x = x
  _y = y

  if x == :center
    _x = window.width/2 - (@slot_width*@size)/2
  end
  if y == :bottom
    _y = window.height - ((@size*2)+@y_padding)
  end

  @x, @y = _x, _y
  @width  = 4 * @size
  @height = 4 * @size
end

#updateObject



72
73
# File 'lib/author_engine/palette.rb', line 72

def update
end