#============================================================================== # ■ Window_Selectable #------------------------------------------------------------------------------ #  Credits to Selwyn #============================================================================== class Window_Selectable < Window_Base alias initialize_scrollbar initialize alias update_scrollbar update alias dispose_scrollbar dispose #-------------------------------------------------------------------------- # ● initialize #-------------------------------------------------------------------------- def initialize(x, y, width, height) initialize_scrollbar(x, y, width, height) @scrollbar = Sprite.new @scrollbar.x = x + self.width - 13 @scrollbar.y = y + 17 @scrollbar.z = 3001 @scrollback = Sprite.new bitmap = Bitmap.new(8, 448) bitmap.fill_rect(0, 0, 8, 448, Color.new(0, 0, 0)) @scrollback.bitmap = bitmap @scrollback.x = x + self.width - 14 @scrollback.y = y + 16 @scrollback.z = 3000 @scrollback.src_rect.set(0, 0, 8, self.height - 32) self.scrollbar = false end #-------------------------------------------------------------------------- # ● contents= #-------------------------------------------------------------------------- def contents=(contents) super(contents) unless self.contents.nil? height = (self.height-33)/(self.contents.height/(self.height-32).to_f) self.scrollbar = true if height > self.height - 34 self.scrollbar = false end y = self.top_row * (self.height - 34) / row_max rect = Rect.new(0, 0, 6, height) bmp = RPG::Cache.picture("scrollbar") rescue nil if bmp.nil? bmp = Bitmap.new(6, 480) color = self.windowskin.nil? ? Color.new(255, 255, 255) : self.windowskin.get_pixel(0, 0) bmp.fill_rect(0, 0, 6, 480, color) end @scrollbar.bitmap = bmp @scrollbar.src_rect.set(0, 0, 6, height) @scrollbar.y = y + self.y + 17 @scrollback.src_rect.set(0, 0, 8, self.height - 32) end end #-------------------------------------------------------------------------- # ● dispose #-------------------------------------------------------------------------- def dispose dispose_scrollbar if @scrollback.bitmap != nil @scrollback.bitmap.clear end @scrollbar.dispose @scrollback.dispose end #-------------------------------------------------------------------------- # ● scrollbar= #-------------------------------------------------------------------------- def scrollbar=(bool) @scrollbar.visible = bool @scrollback.visible = bool end #-------------------------------------------------------------------------- # ● update #-------------------------------------------------------------------------- def update update_scrollbar unless self.contents.nil? height = (self.height-33)/(self.contents.height/(self.height-32).to_f) self.scrollbar = true if height > self.height - 34 self.scrollbar = false end y = self.top_row * (self.height - 34) / row_max @scrollbar.src_rect.set(0, 0, 6, height) @scrollbar.y = y + self.y + 17 @scrollback.src_rect.set(0, 0, 8, self.height - 32) end end end