Module: RbSDL2::Window::Shape

Included in:
RbSDL2::Window
Defined in:
lib/rb_sdl2/window/shape.rb

Defined Under Namespace

Classes: WindowShapeMode

Instance Method Summary collapse

Instance Method Details

#alpha_testObject



45
# File 'lib/rb_sdl2/window/shape.rb', line 45

def alpha_test = shaped? && alpha_test? ? shape_mode.alpha_test : nil

#alpha_test?Boolean

Returns:

  • (Boolean)


47
# File 'lib/rb_sdl2/window/shape.rb', line 47

def alpha_test? = shaped? && shape_mode.alpha_test?

#color_keyObject



49
# File 'lib/rb_sdl2/window/shape.rb', line 49

def color_key = shaped? && color_key? ? shape_mode.color_key : nil

#color_key?Boolean

Returns:

  • (Boolean)


51
# File 'lib/rb_sdl2/window/shape.rb', line 51

def color_key? = shaped? && shape_mode.color_key?

#reverse_alpha_test?Boolean

Returns:

  • (Boolean)


53
# File 'lib/rb_sdl2/window/shape.rb', line 53

def reverse_alpha_test? = shaped? && shape_mode.reverse_alpha_test?

#shape_set(surface, alpha_test: nil, color_key: nil) ⇒ Object

サーフェスにアルファ―チャンネルが含まれていない場合、color_key オプションを与える必要がある。 形状マスクの設定を行う。ウィンドウの描画域は透明なピクセルで埋められている。 このメソッド呼び出しの成功後にウィンドウのサーフェスへ描画を行う必要がある。 描画方法はウィンドウのサーフェスまたはレンダラーのどちらを使用してもよい。



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rb_sdl2/window/shape.rb', line 59

def shape_set(surface, alpha_test: nil, color_key: nil)
  shape = WindowShapeMode.new
  if color_key
    shape.mode = ::SDL::ShapeModeColorKey
    shape.color_key = color_key
  elsif alpha_test&.>= 0
    shape.mode = ::SDL::ShapeModeBinarizeAlpha
    shape.alpha_test = alpha_test
  elsif alpha_test&.< 0
    shape.mode = ::SDL::ShapeModeReverseBinarizeAlpha
    shape.alpha_test = alpha_test.abs
  else
    shape.mode = ::SDL::ShapeModeDefault
  end
  err = ::SDL.SetWindowShape(self, surface, shape)
  # SetWindowShape は WINDOW_LACKS_SHAPE を返すことはない。
  if err == ::SDL::NONSHAPEABLE_WINDOW
    raise RbSDL2Error, "unshaped window"
  elsif err == ::SDL::INVALID_SHAPE_ARGUMENT
    raise RbSDL2Error,
          "Invalid shape argument. \
The size of the window and the size of the surface do not match. \
Or the color key is not specified in the surface without alpha channel."
  elsif err < 0
    raise RbSDL2Error
  end
  surface
end

#shaped?Boolean

Returns:

  • (Boolean)


88
# File 'lib/rb_sdl2/window/shape.rb', line 88

def shaped? = ::SDL.IsShapedWindow(self) == ::SDL::TRUE