class RbSDL2::Palette::PalettePointer

Public Class Methods

==(other) click to toggle source
# File lib/rb_sdl2/palette.rb, line 37
def ==(other)
  other.respond_to?(:to_ptr) && to_ptr == other.to_ptr
end
[](*color) click to toggle source
# File lib/rb_sdl2/palette.rb, line 14
def [](*color)
  plt = new(color.length)
  color.each.with_index { |c, nth| plt[nth] = c }
  plt
end
[]=(nth, color) click to toggle source

color 引数には 3要素以上の配列であること。4要素目以降は無視される。 color 引数は内部で splat する。これに対応していれば配列以外のオブジェクトでもよい。 パレットのカラーが描画に使われるときはアルファ値は無視されて不透明(SDL_ALPHA_OPAQUE)として扱わられる。 パレットのカラーは作成時に全て [255, 255, 255, 255] で埋められている。

# File lib/rb_sdl2/palette.rb, line 50
def []=(nth, color)
  raise ArgumentError if nth < 0 || length <= nth
  c = ::SDL2::SDL_Color.new
  c[:r], c[:g], c[:b] = color
  err = ::SDL2.SDL_SetPaletteColors(self, c, nth, 1)
  raise RbSDL2Error if err < 0
end
each(= length.times { |nth| yield(self[nth]) }) click to toggle source
# File lib/rb_sdl2/palette.rb, line 58
def each = length.times { |nth| yield(self[nth]) }

def inspect
  "#<#{self.class.name} ptr=#{to_ptr.inspect} colors=#{length} version=#{version}>"
end

def length = @st[:ncolors]

alias size length

def to_a = to_enum.to_a

def to_ptr = @st.to_ptr

def version = @st[:version
entity_class(= ::SDL2::SDL_Palette) click to toggle source
# File lib/rb_sdl2/palette.rb, line 9
  def entity_class = ::SDL2::SDL_Palette
end
initialize(ptr) click to toggle source
# File lib/rb_sdl2/palette.rb, line 33
def initialize(ptr)
  @st = ::SDL2::SDL_Palette.new(ptr)
end
inspect() click to toggle source
# File lib/rb_sdl2/palette.rb, line 60
def inspect
  "#<#{self.class.name} ptr=#{to_ptr.inspect} colors=#{length} version=#{version}>"
end
length(= @st[:ncolors]) click to toggle source
# File lib/rb_sdl2/palette.rb, line 64
def length = @st[:ncolors]

alias size length

def to_a = to_enum.to_a

def to_ptr = @st.to_ptr

def version = @st[:version]
new(num_colors) click to toggle source
Calls superclass method
# File lib/rb_sdl2/palette.rb, line 20
def new(num_colors)
  ptr = PalettePointer.new(::SDL2.SDL_AllocPalette(num_colors))
  raise RbSDL2Error if ptr.null?
  super(ptr)
end
release(ptr) click to toggle source
# File lib/rb_sdl2/palette.rb, line 7
    def release(ptr) = ::SDL2.SDL_FreePalette(ptr)

    def entity_class = ::SDL2::SDL_Palette
  end
end
to_a(= to_enum.to_a) click to toggle source
# File lib/rb_sdl2/palette.rb, line 68
  def to_a = to_enum.to_a

  def to_ptr = @st.to_ptr

  def version = @st[:version]
end
to_ptr(ptr) click to toggle source
# File lib/rb_sdl2/palette.rb, line 26
def to_ptr(ptr)
  obj = allocate
  obj.__send__(:initialize, PalettePointer.to_ptr(ptr))
  obj
end
version(= @st[:version]) click to toggle source
# File lib/rb_sdl2/palette.rb, line 72
  def version = @st[:version]
end