Class: GTK::Keyboard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DirectionalInputHelperMethods

#directional_vector, included, #left_right, #method_missing, #up_down

Constructor Details

#initializeKeyboard

Returns a new instance of Keyboard.


358
359
360
361
362
363
# File 'dragon/inputs.rb', line 358

def initialize
  @key_up      = KeyboardKeys.new
  @key_held    = KeyboardKeys.new
  @key_down    = KeyboardKeys.new
  @has_focus   = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GTK::DirectionalInputHelperMethods

Instance Attribute Details

#has_focusBoolean

Returns:

  • (Boolean)

356
357
358
# File 'dragon/inputs.rb', line 356

def has_focus
  @has_focus
end

#key_downKeyboardKeys

Returns:


352
353
354
# File 'dragon/inputs.rb', line 352

def key_down
  @key_down
end

#key_heldKeyboardKeys

Returns:


348
349
350
# File 'dragon/inputs.rb', line 348

def key_held
  @key_held
end

#key_upKeyboardKeys

Returns:


344
345
346
# File 'dragon/inputs.rb', line 344

def key_up
  @key_up
end

Instance Method Details

#clearvoid

This method returns an undefined value.

Clear all current key presses.


400
401
402
403
404
# File 'dragon/inputs.rb', line 400

def clear
  @key_up.clear
  @key_held.clear
  @key_down.clear
end

#downBoolean

The down arrow or “s” was pressed.

Returns:

  • (Boolean)

393
394
395
# File 'dragon/inputs.rb', line 393

def down
  @key_up.down || @key_held.down || s
end

#keyObject Also known as: keys


421
422
423
424
425
426
427
428
# File 'dragon/inputs.rb', line 421

def key
  {
    down: @key_down.truthy_keys,
    held: @key_held.truthy_keys,
    down_or_held: (@key_down.truthy_keys + @key_held.truthy_keys).uniq,
    up: @key_up.truthy_keys,
  }
end

#leftBoolean

The left arrow or “a” was pressed.

Returns:

  • (Boolean)

372
373
374
# File 'dragon/inputs.rb', line 372

def left
  @key_up.left || @key_held.left || a
end

#pObject


365
366
367
# File 'dragon/inputs.rb', line 365

def p
  @key_down.p || @key_held.p
end

#rightBoolean

The right arrow or “d” was pressed.

Returns:

  • (Boolean)

379
380
381
# File 'dragon/inputs.rb', line 379

def right
  @key_up.right || @key_held.right || d
end

#serializeObject Also known as: inspect


406
407
408
409
410
411
412
413
# File 'dragon/inputs.rb', line 406

def serialize
  {
    key_up: @key_up.serialize,
    key_held: @key_held.serialize,
    key_down: @key_down.serialize,
    has_focus: @has_focus
  }
end

#to_sString

Returns:


417
418
419
# File 'dragon/inputs.rb', line 417

def to_s
  serialize.to_s
end

#upBoolean

The up arrow or “w” was pressed.

Returns:

  • (Boolean)

386
387
388
# File 'dragon/inputs.rb', line 386

def up
  @key_up.up || @key_held.up || w
end