Class: RUtilAnts::GUI::ImageListManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rUtilAnts/GUI.rb

Overview

The class that assigns dynamically images to a given TreeCtrl items

Instance Method Summary collapse

Constructor Details

#initialize(ioImageList, iWidth, iHeight) ⇒ ImageListManager

Constructor

Parameters
  • ioImageList (Wx::ImageList): The image list this manager will handle

  • iWidth (Integer): The images width

  • iHeight (Integer): The images height



16
17
18
19
20
21
22
23
24
# File 'lib/rUtilAnts/GUI.rb', line 16

def initialize(ioImageList, iWidth, iHeight)
  @ImageList = ioImageList
  # TODO (WxRuby): Get the size directly from ioImageList (get_size does not work)
  @Width = iWidth
  @Height = iHeight
  # The internal map of image IDs => indexes
  # map< Object, Integer >
  @Id2Idx = {}
end

Instance Method Details

#getImageIndex(iID) ⇒ Object

Get the image index for a given image ID

Parameters
  • iID (Object): Id of the image

  • CodeBlock: The code that will be called if the image ID is unknown. This code has to return a Wx::Bitmap object, representing the bitmap for the given image ID.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rUtilAnts/GUI.rb', line 31

def getImageIndex(iID)
  if (@Id2Idx[iID] == nil)
    # Bitmap unknown.
    # First create it.
    lBitmap = yield
    # Then check if we need to resize it
    lBitmap = getResizedBitmap(lBitmap, @Width, @Height)
    # Then add it to the image list, and register it
    @Id2Idx[iID] = @ImageList.add(lBitmap)
  end

  return @Id2Idx[iID]
end