Method: RbSDL2::Window.shaped

Defined in:
lib/rb_sdl2/window/window.rb

.shaped(title = "", x = nil, y = nil, w = nil, h = nil, flags: nil, alpha_test: nil, color_key: nil, shape:, **opts) ⇒ Object

w, h は nil の場合は shape に与えられたサーフェィスの w, h を使用する。flags は常に borderless: true, fullscreen: false, resizable: false が設定される。shape には Surface のインスタンス・オブジェクトを与える。作成されたウィンドウは透明である。表示内容は作成後に描画する必要がある。ウィンドウへの操作を扱いたければ HitTest コールバックを設定しコールバック側で処理を行う必要がある。

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rb_sdl2/window/window.rb', line 31

def shaped(title = "", x = nil, y = nil, w = nil, h = nil, flags: nil,
           alpha_test: nil, color_key: nil, shape:, **opts)
  size = [w || shape.w, h || shape.h]
  # w, h は形状マスクのサイズに合わせる必要がある。
  ptr = ::SDL.CreateShapedWindow(SDL.str_to_sdl(title), 0, 0, *size,
                                 flags || State.to_flags(**opts))
  raise RbSDL2Error if ptr.null?
  to_ptr(ptr).tap do |obj|
    obj.shape_set(shape, alpha_test: alpha_test, color_key: color_key)
    obj.size = size
    # CreateShapedWindow は引数 x, y を無視する。そして x = -1000, y = -1000 に強制する。
    # 位置の再指定を行いアプリケーションの意図した位置に表示する。
    obj.position = [x || SDL_WINDOWPOS_CENTERED_MASK, y || SDL_WINDOWPOS_CENTERED_MASK]
  end
end