Class: Rubygoo::GosuAppAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygoo/adapters/gosu_app_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, main_window) ⇒ GosuAppAdapter

Returns a new instance of GosuAppAdapter.



486
487
488
489
490
491
492
# File 'lib/rubygoo/adapters/gosu_app_adapter.rb', line 486

def initialize(app,main_window)
  @app = app
  @main_window = main_window

  @last_mouse_x = 0
  @last_mouse_y = 0
end

Instance Method Details

#button_down(id) ⇒ Object

TODO convert keys?!?



509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/rubygoo/adapters/gosu_app_adapter.rb', line 509

def button_down(id)
  case id
  when MsLeft
    @app.on_event GooEvent.new(:mouse_down, { 
      :x => @main_window.mouse_x, :y => @main_window.mouse_y, 
      :button => MOUSE_LEFT})
  else
    # assume it's a key
    # where do I get the mods? ie shift,alt,ctrl
    # where do I get the string rep of the char?
    mods = []
    mods << K_LALT if @main_window.button_down? KbLeftAlt
    mods << K_RALT if @main_window.button_down? KbRightAlt
    mods << K_LCTRL if @main_window.button_down? KbLeftControl
    mods << K_RCTRL if @main_window.button_down? KbRightControl
    left_shift = @main_window.button_down? KbLeftShift
    right_shift = @main_window.button_down? KbRightShift
    mods << K_LSHIFT if left_shift
    mods << K_RSHIFT if right_shift

    button_string = @main_window.button_id_to_char(id)
    button_string ||= "?"

    button_string.upcase! if left_shift or right_shift

    @app.on_event GooEvent.new(:key_pressed, { 
      :key => id, :mods => mods, :string => button_string})
  end
end

#button_up(id) ⇒ Object



539
540
541
542
543
544
545
546
# File 'lib/rubygoo/adapters/gosu_app_adapter.rb', line 539

def button_up(id)
  case id
  when MsLeft
    @app.on_event GooEvent.new(:mouse_up, { 
      :x => @main_window.mouse_x, :y => @main_window.mouse_y, 
      :button => MOUSE_LEFT})
  end
end

#draw(target) ⇒ Object



504
505
506
# File 'lib/rubygoo/adapters/gosu_app_adapter.rb', line 504

def draw(target)
  @app.draw target
end

#update(time) ⇒ Object



494
495
496
497
498
499
500
501
502
# File 'lib/rubygoo/adapters/gosu_app_adapter.rb', line 494

def update(time)
  x = @main_window.mouse_x
  y = @main_window.mouse_y
  if x != @last_mouse_x or y != @last_mouse_y
    @app.on_event GooEvent.new(:mouse_motion, { 
      :x => x, :y => y})
  end
  @app.update time
end