Module: RbSDL2::Window::Shape
- Included in:
- RbSDL2::Window
- Defined in:
- lib/rb_sdl2/window/shape.rb
Instance Method Summary collapse
- #alpha_test ⇒ Object
- #alpha_test? ⇒ Boolean
- #color_key ⇒ Object
- #color_key? ⇒ Boolean
- #reverse_alpha_test? ⇒ Boolean
-
#shape_set(surface, alpha_test: nil, color_key: nil) ⇒ Object
サーフェスにアルファ―チャンネルが含まれていない場合、color_key オプションを与える必要がある。 形状マスクの設定を行う。ウィンドウの描画域は透明なピクセルで埋められている。 このメソッド呼び出しの成功後にウィンドウのサーフェスへ描画を行う必要がある。 描画方法はウィンドウのサーフェスまたはレンダラーのどちらを使用してもよい。.
- #shaped? ⇒ Boolean
Instance Method Details
#alpha_test ⇒ Object
18 19 20 |
# File 'lib/rb_sdl2/window/shape.rb', line 18 def alpha_test shape_mode[:parameters][:binarizationCutoff] unless shaped? && color_key? end |
#alpha_test? ⇒ Boolean
22 23 24 25 |
# File 'lib/rb_sdl2/window/shape.rb', line 22 def alpha_test? shaped? && [::SDL2::ShapeModeBinarizeAlpha, ::SDL2::ShapeModeDefault].include?(shape_mode[:mode]) end |
#color_key ⇒ Object
27 28 29 |
# File 'lib/rb_sdl2/window/shape.rb', line 27 def color_key shape_mode[:parameters][:colorKey].values if shaped? && color_key? end |
#color_key? ⇒ Boolean
31 32 33 |
# File 'lib/rb_sdl2/window/shape.rb', line 31 def color_key? shaped? && ::SDL2::ShapeModeColorKey == shape_mode[:mode] end |
#reverse_alpha_test? ⇒ Boolean
35 36 37 |
# File 'lib/rb_sdl2/window/shape.rb', line 35 def reverse_alpha_test? shaped? && ::SDL2::ShapeModeReverseBinarizeAlpha == shape_mode[:mode] end |
#shape_set(surface, alpha_test: nil, color_key: nil) ⇒ Object
サーフェスにアルファ―チャンネルが含まれていない場合、color_key オプションを与える必要がある。形状マスクの設定を行う。ウィンドウの描画域は透明なピクセルで埋められている。このメソッド呼び出しの成功後にウィンドウのサーフェスへ描画を行う必要がある。描画方法はウィンドウのサーフェスまたはレンダラーのどちらを使用してもよい。
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rb_sdl2/window/shape.rb', line 43 def shape_set(surface, alpha_test: nil, color_key: nil) mode = ::SDL2::SDL_WindowShapeMode.new.tap do |st| st[:mode] = if color_key st[:parameters][:colorKey].tap { |c| c[:r], c[:g], c[:b] = color_key } ::SDL2::ShapeModeColorKey elsif alpha_test&.>= 0 st[:parameters][:binarizationCutoff] = alpha_test ::SDL2::ShapeModeBinarizeAlpha elsif alpha_test&.< 0 st[:parameters][:binarizationCutoff] = alpha_test.abs ::SDL2::ShapeModeReverseBinarizeAlpha else ::SDL2::ShapeModeDefault end end err = ::SDL2.SDL_SetWindowShape(self, surface, mode) # SDL_SetWindowShape は SDL_WINDOW_LACKS_SHAPE を返すことはない。 if err == ::SDL2::SDL_NONSHAPEABLE_WINDOW raise RbSDL2Error, "unshaped window" elsif err == ::SDL2::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
73 |
# File 'lib/rb_sdl2/window/shape.rb', line 73 def shaped? = ::SDL2.SDL_IsShapedWindow(self) == ::SDL2::SDL_TRUE |