class Core::GUI::Scrollbar

Attributes

h[R]
sh[RW]

Public Class Methods

new(x, y, w, h) click to toggle source
Calls superclass method Core::GUI::Element::new
# File lib/gui/base.rb, line 239
def initialize(x, y, w, h)
  super
  @bg = Core.sprite("gui/scrollbar_background")
  @scroller = Core.sprite("gui/scroller")
  @held = false
  @sy = @y
  @sh = 48
end

Public Instance Methods

draw() click to toggle source
# File lib/gui/base.rb, line 269
def draw
  @bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z + 14, @w/@bg.width, @h/@bg.height.to_f)
  @scroller.draw(@x+@xoff, @sy+@yoff, Core::GUI_Z + 15, 1, @sh/@scroller.height.to_f)
end
offset() click to toggle source
# File lib/gui/base.rb, line 247
def offset
  return ((@sy-@y)/((@y)-(@y+@h-@sh)+1))*-100
end
update() click to toggle source
# File lib/gui/base.rb, line 250
def update
  x = Core.window.mouse_x
  y = Core.window.mouse_y
  if Core.inside?(x, y, @x, @sy, @x+@w, @sy+@sh) and Core.window.button_down?(MsLeft) and !@held
    @held = true
    @offset = @sy-y
  end
  if @held
    @sy = y + @offset
    if @sy < @y
      @sy = @y
    elsif @sy+@sh > @y+@h
      @sy = @y+@h-@sh-1
    end
    if !Core.window.button_down?(MsLeft)
      @held = false
    end
  end
end