Class: Cura::Cursor

Inherits:
Object
  • Object
show all
Includes:
Attributes::HasApplication, Attributes::HasCoordinates, Attributes::HasInitialize
Defined in:
lib/cura/cursor.rb

Overview

The text cursor controller.

Should only ever have one single Cursor instance at one time. TODO: Rename Cursor::Text, need Cursor::Mouse

Instance Attribute Summary

Attributes included from Attributes::HasApplication

#application

Instance Method Summary collapse

Methods included from Attributes::HasCoordinates

#x, #x=, #y, #y=

Methods included from Attributes::HasAttributes

included, #update_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Cursor

Returns a new instance of Cursor.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
# File 'lib/cura/cursor.rb', line 19

def initialize(attributes={})
  @hidden = true
  
  super
  
  raise ArgumentError, "application must be set" if application.nil?
end

Instance Method Details

#hidden=(value) ⇒ Boolean

Set if the cursor is hidden.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/cura/cursor.rb', line 38

def hidden=(value)
  value = !!value
  
  @hidden = value
end

#hidden?Boolean

Check if the cursor is hidden.

Returns:

  • (Boolean)


30
31
32
# File 'lib/cura/cursor.rb', line 30

def hidden?
  !!@hidden
end

#hideCursor

Hide the cursor.

Returns:



56
57
58
59
60
# File 'lib/cura/cursor.rb', line 56

def hide
  @hidden = true
  
  self
end

#showCursor

Show the cursor.

Returns:



47
48
49
50
51
# File 'lib/cura/cursor.rb', line 47

def show
  @hidden = false
  
  self
end

#updateCursor

Draw (set) the cursor.

Returns:



65
66
67
68
69
70
71
72
73
# File 'lib/cura/cursor.rb', line 65

def update # TODO: Refactor for speed, this can't be effecient
  if @hidden
    application.adapter.hide_cursor
  else
    application.adapter.set_cursor(@x, @y)
  end
  
  self
end