Class: GTK::Inputs

Inherits:
Object show all
Defined in:
dragon/inputs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInputs

Returns a new instance of Inputs.


673
674
675
676
677
678
679
680
681
682
# File 'dragon/inputs.rb', line 673

def initialize
  @controllers = [Controller.new, Controller.new]
  @keyboard = Keyboard.new
  @mouse = Mouse.new
  @touch = {}
  @finger_one = nil
  @finger_two = nil
  @text = []
  @http_requests = []
end

Instance Attribute Details

#controllersController[] (readonly)

A list of all controllers.

Returns:


651
652
653
# File 'dragon/inputs.rb', line 651

def controllers
  @controllers
end

#finger_oneObject

Returns the value of attribute finger_one


668
669
670
# File 'dragon/inputs.rb', line 668

def finger_one
  @finger_one
end

#finger_twoObject

Returns the value of attribute finger_two


668
669
670
# File 'dragon/inputs.rb', line 668

def finger_two
  @finger_two
end

#historyObject

Returns the value of attribute history


671
672
673
# File 'dragon/inputs.rb', line 671

def history
  @history
end

#http_requestsHTTPRequest[]

Returns:

  • (HTTPRequest[])

663
664
665
# File 'dragon/inputs.rb', line 663

def http_requests
  @http_requests
end

#keyboardKeyboard (readonly)

Returns:


655
656
657
# File 'dragon/inputs.rb', line 655

def keyboard
  @keyboard
end

#mouseMouse (readonly)

Returns:


659
660
661
# File 'dragon/inputs.rb', line 659

def mouse
  @mouse
end

#textObject

Returns the value of attribute text


671
672
673
# File 'dragon/inputs.rb', line 671

def text
  @text
end

#touchFingerTouch (readonly)

Returns:


667
668
669
# File 'dragon/inputs.rb', line 667

def touch
  @touch
end

Instance Method Details

#clearvoid

This method returns an undefined value.

Clears all inputs.


752
753
754
755
756
757
758
759
760
# File 'dragon/inputs.rb', line 752

def clear
  @mouse.clear
  @keyboard.clear
  @controllers.each(&:clear)
  @touch.clear
  @http_requests.clear
  @finger_one = nil
  @finger_two = nil
end

#clickFloat

Returns the coordinates of the last click.

Returns:


730
731
732
733
# File 'dragon/inputs.rb', line 730

def click
  return nil unless @mouse.click
  return @mouse.click.point
end

#controller_oneController

The first controller.

Returns:


738
739
740
# File 'dragon/inputs.rb', line 738

def controller_one
  @controllers[0]
end

#controller_twoController

The second controller.

Returns:


745
746
747
# File 'dragon/inputs.rb', line 745

def controller_two
  @controllers[1]
end

#directional_vectorObject


704
705
706
707
# File 'dragon/inputs.rb', line 704

def directional_vector
  keyboard.directional_vector ||
    (controller_one && controller_one.directional_vector)
end

#downObject


689
690
691
692
# File 'dragon/inputs.rb', line 689

def down
  keyboard.down ||
    (controller_one && controller_one.down)
end

#leftObject


694
695
696
697
# File 'dragon/inputs.rb', line 694

def left
  keyboard.left ||
    (controller_one && controller_one.left)
end

#left_rightInteger

Returns a signal indicating right (`1`), left (`-1`), or neither ('0').

Returns:


712
713
714
715
716
# File 'dragon/inputs.rb', line 712

def left_right
  return -1 if self.left
  return  1 if self.right
  return  0
end

#rightObject


699
700
701
702
# File 'dragon/inputs.rb', line 699

def right
  keyboard.right ||
    (controller_one && controller_one.right)
end

#serializeHash

Returns:

  • (Hash)

763
764
765
766
767
768
769
770
771
# File 'dragon/inputs.rb', line 763

def serialize
  {
    controller_one: controller_one.serialize,
    controller_two: controller_two.serialize,
    keyboard: keyboard.serialize,
    mouse: mouse.serialize,
    text: text.serialize
  }
end

#upObject


684
685
686
687
# File 'dragon/inputs.rb', line 684

def up
  keyboard.up ||
    (controller_one && controller_one.up)
end

#up_downInteger

Returns a signal indicating up (`1`), down (`-1`), or neither ('0').

Returns:


721
722
723
724
725
# File 'dragon/inputs.rb', line 721

def up_down
  return  1 if self.up
  return -1 if self.down
  return  0
end