Class: Cura::Cursor

Inherits:
Object
  • Object
show all
Includes:
Attributes::HasApplication, Attributes::HasAttributes, 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)


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

def initialize(attributes={})
  @hidden = true

  super

  raise ArgumentError, "application must be set" if application.nil?
end

Instance Method Details

#hidden=Boolean

Set if the cursor is hidden.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


36
# File 'lib/cura/cursor.rb', line 36

attribute(:hidden, query: true)

#hidden?Boolean

Check if the cursor is hidden.

Returns:

  • (Boolean)


# File 'lib/cura/cursor.rb', line 26

#hideCursor

Hide the cursor.

Returns:



50
51
52
53
54
# File 'lib/cura/cursor.rb', line 50

def hide
  @hidden = true

  self
end

#showCursor

Show the cursor.

Returns:



41
42
43
44
45
# File 'lib/cura/cursor.rb', line 41

def show
  @hidden = false

  self
end

#updateCursor

Draw (set) the cursor.

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/cura/cursor.rb', line 59

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