Class: Fidgit::DialogState Abstract

Inherits:
GuiState show all
Defined in:
lib/fidgit/states/dialog_state.rb

Overview

This class is abstract.

A modal dialog.

Direct Known Subclasses

FileDialog, MessageDialog

Constant Summary collapse

DEFAULT_BACKGROUND_COLOR =
Gosu::Color.rgb(75, 75, 75)
DEFAULT_BORDER_COLOR =
Gosu::Color.rgb(255, 255, 255)
DEFAULT_SHADOW_COLOR =
Gosu::Color.rgba(0, 0, 0, 100)
DEFAULT_SHADOW_OFFSET =
8

Constants inherited from GuiState

GuiState::PIXEL_IMAGE

Instance Attribute Summary

Attributes inherited from GuiState

#container, #focus

Instance Method Summary collapse

Methods inherited from GuiState

#clear, clear, #cursor, #distance, #draw_frame, #draw_rect, #file_dialog, #finalize, #flush, #hide_menu, #menu, #message, #setup, #show_menu, #t, #tool_tip_delay, #unset_mouse_over, #update, #write_tree

Constructor Details

#initialize(options = {}) ⇒ DialogState

Returns a new instance of DialogState.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fidgit/states/dialog_state.rb', line 11

def initialize(options = {})
  # @option options [Gosu::Color] :shadow_color (transparent black) Color of the shadow.
  # @option options [Gosu::Color] :shadow_offset (8) Distance shadow is offset to bottom and left.
  # @option options [Gosu::Color] :shadow_full (false) Shadow fills whole screen. Ignores :shadow_offset option if true.
  options = {
    shadow_color: DEFAULT_SHADOW_COLOR,
    shadow_offset: DEFAULT_SHADOW_OFFSET,
    shadow_full: false,
  }.merge! options

  @shadow_color = options[:shadow_color].dup
  @shadow_offset = options[:shadow_offset]
  @shadow_full = options[:shadow_full]

  super()
end

Instance Method Details

#drawObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fidgit/states/dialog_state.rb', line 28

def draw
  $window.game_state_manager.previous_game_state.draw # Keep the underlying state being shown.
  $window.flush

  if @shadow_full
    draw_rect 0, 0, $window.width, $window.height, -Float::INFINITY, @shadow_color
  elsif @shadow_offset > 0
    dialog = container[0]
    draw_rect dialog.x + @shadow_offset, dialog.y + @shadow_offset, dialog.width, dialog.height, -Float::INFINITY, @shadow_color
  end

  super
end

#hideObject



47
48
49
50
# File 'lib/fidgit/states/dialog_state.rb', line 47

def hide
  $window.game_state_manager.pop(setup: false) if $window.game_state_manager.current == self
  nil
end

#showObject



42
43
44
45
# File 'lib/fidgit/states/dialog_state.rb', line 42

def show
  $window.game_state_manager.push(self, finalize: false) unless $window.game_state_manager.game_states.include? self
  nil
end