Class: GGLib::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/mouse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(img, visible = true) ⇒ Cursor

Returns a new instance of Cursor.



5
6
7
8
9
10
# File 'lib/mouse.rb', line 5

def initialize(img,visible=true)
  @img=img
  @visible=visible
  @imgObj=Gosu::Image.new($window,img,true)
  @forced=false
end

Instance Attribute Details

#imgObject (readonly)

Returns the value of attribute img.



4
5
6
# File 'lib/mouse.rb', line 4

def img
  @img
end

#imgObjObject (readonly)

Returns the value of attribute imgObj.



4
5
6
# File 'lib/mouse.rb', line 4

def imgObj
  @imgObj
end

#visibleObject

Returns the value of attribute visible.



4
5
6
# File 'lib/mouse.rb', line 4

def visible
  @visible
end

Instance Method Details

#drawObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/mouse.rb', line 87

def draw
  if @rx
    $window.mouse_x = @x
  end
  if @ry
    $window.mouse_y = @oy
  end
  if @visible
    @imgObj.draw($window.mouse_x,$window.mouse_y,ZOrder::Cursor)
  end
end

#forceVisible(visible = true) ⇒ Object

Forces the cursor to adhere to the visibility specified by parameter visible. Subsequent calls to toggleVisible and visible= will have no effect. See also unforceVisible.



18
19
20
21
# File 'lib/mouse.rb', line 18

def forceVisible(visible=true)
  @forced=true
  @visible=visible
end

#moveTo(xp, yp) ⇒ Object

Sets the position of the cursor.



83
84
85
86
# File 'lib/mouse.rb', line 83

def moveTo(xp, yp)
  $window.mouse_x = xp
  $window.mouse_y = yp
end

#restrictX(restrict = true) ⇒ Object

Restricts mouse movement along the x axis.



37
38
39
40
41
42
# File 'lib/mouse.rb', line 37

def restrictX(restrict=true)
  @rx = restrict
  if @rx
    @ox = $window.mouse_x
  end
end

#restrictX?Boolean

Returns true if movement along the x axis is currently restricted, false otherwise.

Returns:

  • (Boolean)


59
60
61
# File 'lib/mouse.rb', line 59

def restrictX?
  return @rx
end

#restrictY(restrict = true) ⇒ Object

Restricts mouse movement along the y axis.



44
45
46
47
48
49
# File 'lib/mouse.rb', line 44

def restrictY(restrict=true)
  @ry = restrict
  if @ry
    @oy = $window.mouse_y
  end
end

#restrictY?Boolean

Returns true if movement along the y axis is currently restricted, false otherwise.

Returns:

  • (Boolean)


63
64
65
# File 'lib/mouse.rb', line 63

def restrictY?
  return @ry
end

#toggleVisibleObject

If the cursor is currently invisible, makes it visible. If the cursor is currently visible, makes it invisible. Subject to the constraints of forceVisible.



12
13
14
15
16
# File 'lib/mouse.rb', line 12

def toggleVisible
  if not @forced
    @visible=!@visible
  end
end

#unforceVisibleObject

Allows the cursor to be made invisible via toggleVisible or visible=.



23
24
25
# File 'lib/mouse.rb', line 23

def unforceVisible
  @forced=false
end

#unrestrictXObject

Stops restriction of mouse movement along the x axis.



51
52
53
# File 'lib/mouse.rb', line 51

def unrestrictX
  @rx = false
end

#unrestrictYObject

Stops restriction of mouse movement along the y axis.



55
56
57
# File 'lib/mouse.rb', line 55

def unrestrictY
  @ry = false
end

#visible?Boolean

Returns true if the cursor is currently visible, false otherwise.

Returns:

  • (Boolean)


27
28
29
# File 'lib/mouse.rb', line 27

def visible?
  return visible
end

#xObject

Returns the current x coordinate of the cursor.



67
68
69
# File 'lib/mouse.rb', line 67

def x
  return $window.mouse_x
end

#x=(val) ⇒ Object

Sets the current x coordinate of the cursor.



75
76
77
# File 'lib/mouse.rb', line 75

def x=(val)
  $window.mouse_x = val
end

#yObject

Returns the current y coordinate of the cursor.



71
72
73
# File 'lib/mouse.rb', line 71

def y
  return $window.mouse_y
end

#y=(val) ⇒ Object

Sets the current y coordinate of the cursor.



79
80
81
# File 'lib/mouse.rb', line 79

def y=(val)
  $window.mouse_y = val
end