Class: Patience::EventHandler::Drag

Inherits:
Object
  • Object
show all
Includes:
Processable
Defined in:
lib/patience/event_handlers/drag.rb

Overview

Patience::EventHandler::Drag provides drag objects, that serves for moving cards in the window.

areas = { :tableau => Tableau.new }
cursor.drag = EventHandler::Drag.new(cursor)
cursor.drag.move(mouse_pos) if cursor.movable?

Instance Attribute Summary

Attributes included from Processable

#area, #card, #pile

Instance Method Summary collapse

Methods included from Processable

#detect_in, #find_area_in, #find_card_in, #find_pile_in, #foundation?, #nothing?, #pick_up, #something?, #stock?, #tableau?, #to_a, #to_h, #waste?

Constructor Details

#initialize(cursor) ⇒ Drag

Returns a new instance of Drag.



15
16
17
18
19
# File 'lib/patience/event_handlers/drag.rb', line 15

def initialize(cursor)
  @card = cursor.card
  @tail_cards = cursor.cards
  @offset = cursor.offset
end

Instance Method Details

#draggable?Boolean

Returns true if there is a card to drag and this card is turned to its face. Otherwise, returns false.

Returns:

  • (Boolean)


30
31
32
# File 'lib/patience/event_handlers/drag.rb', line 30

def draggable?
  card.not.nil? and card.face_up?
end

#move(mouse_pos) ⇒ Object

Changes position of the card’s sprite, considering the offset.



22
23
24
25
26
# File 'lib/patience/event_handlers/drag.rb', line 22

def move(mouse_pos)
  @tail_cards.keys.each_with_index do |card, i|
    card.pos = mouse_pos + @offset + [0, i*19]
  end
end