Method: MiniGL::ImageFont#initialize
- Defined in:
- lib/minigl/text.rb
#initialize(img_path, chars, widths, height, space_width, global = true, ext = '.png', retro = nil) ⇒ ImageFont
Creates an ImageFont.
Parameters:
- img_path
-
Identifier of an image fitting the description in the class documentation, as used in
Res.img. - chars
-
A string containing all characters that will be present in the image, in the same order as they appear in the image. Do not include white space.
- widths
-
An integer representing the width of the chars in pixels, if this is a fixed width font, or an array containing the width of each char, in the same order as they appear in the
charsstring. - height
-
The height of the lines in the image (see description above).
- space_width
-
The width of the white space character in this font.
- global
-
Parameter that will be passed to
Res.imgwhen loading the image. - ext
-
Parameter that will be passed to
Res.imgwhen loading the image. - retro
-
Parameter that will be passed to
Res.imgwhen loading the image.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/minigl/text.rb', line 32 def initialize(img_path, chars, widths, height, space_width, global = true, ext = '.png', retro = nil) retro = Res.retro_images if retro.nil? img = Res.img(img_path, global, false, ext, retro) @chars = chars @images = [] @height = height @space_width = space_width wa = widths.is_a?(Array) if wa && widths.length != chars.length raise 'Wrong widths array size!' end x = y = 0 (0...chars.length).each do |i| @images.push(img.subimage(x, y, wa ? widths[i] : widths, height)) new_x = x + (wa ? widths[i] : widths) if i < chars.length - 1 && new_x + (wa ? widths[i+1] : widths) > img.width x = 0 y += height else x = new_x end end end |