Class: RbSDL2::MessageBox::MessageBoxData
- Inherits:
-
Object
- Object
- RbSDL2::MessageBox::MessageBoxData
- Defined in:
- lib/rb_sdl2/message_box.rb
Instance Method Summary collapse
-
#initialize(buttons: nil, colors: nil, escape_key: nil, level: nil, message: nil, return_key: nil, title: nil, window: nil) ⇒ MessageBoxData
constructor
A new instance of MessageBoxData.
- #to_ptr ⇒ Object
Constructor Details
#initialize(buttons: nil, colors: nil, escape_key: nil, level: nil, message: nil, return_key: nil, title: nil, window: nil) ⇒ MessageBoxData
Returns a new instance of MessageBoxData.
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 45 46 47 |
# File 'lib/rb_sdl2/message_box.rb', line 15 def initialize(buttons: nil, colors: nil, escape_key: nil, level: nil, message: nil, return_key: nil, title: nil, window: nil) @st = ::SDL2::SDL_MessageBoxData.new.tap do |data| = * data[:numbuttons] = = .length data[:buttons] = @buttons = .nonzero? && MessageBoxButtonDataArray.new().tap do |data_ary| @button_texts = [] .times do |idx| st, (text, *) = data_ary[idx], [idx] st[:buttonid] = idx st[:flags] = case idx when escape_key then ::SDL2::SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT when return_key then ::SDL2::SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT else 0 end st[:text] = @button_texts[idx] = ::FFI::MemoryPointer.from_string(text.to_s.encode(Encoding::UTF_8)) end end data[:colorScheme] = @color_scheme = colors && ::SDL2::SDL_MessageBoxColorScheme.new.tap do |st| # r, g, b, a 形式だった場合にエラーを出さない。 st[:colors].each.with_index { |c, i| c[:r], c[:g], c[:b] = colors[i] } end data[:flags] = MessageBoxFlags.to_num(level) data[:message] = @message = ::FFI::MemoryPointer.from_string(.to_s.encode(Encoding::UTF_8)) data[:title] = @title = ::FFI::MemoryPointer.from_string(title.to_s.encode(Encoding::UTF_8)) data[:window] = window end end |
Instance Method Details
#to_ptr ⇒ Object
49 |
# File 'lib/rb_sdl2/message_box.rb', line 49 def to_ptr = @st.to_ptr |