Class: Core::GUI::Scrollbar

Inherits:
Element show all
Includes:
Gosu
Defined in:
lib/gui/base.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#w, #x, #xoff, #y, #yoff, #zoff

Instance Method Summary collapse

Methods inherited from Element

#remove?

Constructor Details

#initialize(x, y, w, h) ⇒ Scrollbar

Returns a new instance of Scrollbar.



239
240
241
242
243
244
245
246
# 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

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h.



238
239
240
# File 'lib/gui/base.rb', line 238

def h
  @h
end

#shObject

Returns the value of attribute sh.



237
238
239
# File 'lib/gui/base.rb', line 237

def sh
  @sh
end

Instance Method Details

#drawObject



269
270
271
272
# 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

#offsetObject



247
248
249
# File 'lib/gui/base.rb', line 247

def offset
  return ((@sy-@y)/((@y)-(@y+@h-@sh)+1))*-100
end

#updateObject



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# 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