Advertisement
LeonMMS

BigIcon

Dec 13th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.79 KB | None | 0 0
  1. class BigIcon < Control
  2.  
  3.   def initialize(win, x, y, icon_index, tip_text = '', &block)
  4.     win ? super(win, x, y, 48, 48) : create_background(x, y)
  5.     @icon_index = icon_index
  6.     @tip_text = tip_text
  7.     @block = block
  8.     @back.opacity = 160
  9.     refresh
  10.     create_tool_tip
  11.   end
  12.  
  13.   def create_background(x, y)
  14.     @back = Sprite.new
  15.     @back.bitmap = Bitmap.new(48, 48)
  16.     @back.x = x
  17.     @back.y = y
  18.     @back.z = 50
  19.     @enable = true
  20.     @win = nil
  21.   end
  22.  
  23.   def create_tool_tip
  24.     return if @tip_text.empty?
  25.     @tool_tip = Sprite.new
  26.     @tool_tip.bitmap = Bitmap.new(text_width(@tip_text) + 8, line_height)
  27.     @tool_tip.bitmap.fill_rect(@tool_tip.bitmap.rect, Color.new(0, 0, 0, 160))
  28.     @tool_tip.bitmap.draw_text(@tool_tip.bitmap.rect, @tip_text, 1)
  29.     @tool_tip.z = @back.z + 1
  30.     @tool_tip.visible = false
  31.   end
  32.  
  33.   def dispose
  34.     super
  35.     if @tool_tip
  36.       @tool_tip.bitmap.dispose
  37.       @tool_tip.dispose
  38.     end
  39.   end
  40.  
  41.   def visible=(visible)
  42.     super
  43.     @tool_tip.visible = false if @tool_tip
  44.   end
  45.  
  46.   def refresh
  47.     bitmap = Cache.system('BigIconset')
  48.     rect = Rect.new(@icon_index % 16 * 48, @icon_index / 16 * 48, 48, 48)
  49.     @back.bitmap.blt(0, 0, bitmap, rect)
  50.   end
  51.  
  52.   def update
  53.     @win ? super : update_trigger
  54.     @back.opacity = in_area? && !dragging ? 255 : 160
  55.     update_tool_tip
  56.   end
  57.  
  58.   def update_tool_tip
  59.     return unless @tool_tip && visible
  60.     @tool_tip.visible = @back.opacity == 255
  61.     if @tool_tip.visible
  62.       @tool_tip.x = Mouse.x + 18 + @tool_tip.bitmap.width > Graphics.width ? Graphics.width - @tool_tip.bitmap.width :  Mouse.x + 18
  63.       @tool_tip.y = Mouse.y + 18 + @tool_tip.bitmap.height > Graphics.height ? Graphics.height - @tool_tip.bitmap.height : Mouse.y + 18
  64.     end
  65.   end
  66.  
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement