Class: Font

Inherits:
Object
  • Object
show all
Defined in:
src/ruby/models/font.rb,
mrb_doc/models/font.rb

Overview

The Font class is used for displaying TTF fonts

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_size, glyph_count, glyph_padding) ⇒ Font

Creates a new instance of Font

Parameters:

  • base_size (Integer)
  • glyph_count (Integer)
  • glyph_padding (Integer)


7
8
9
10
11
# File 'mrb_doc/models/font.rb', line 7

def initialize(base_size, glyph_count, glyph_padding)
  # mrb_Font_initialize
  # src/mruby_integration/models/font.cpp
  Font.new
end

Instance Attribute Details

#base_sizeInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/font.rb', line 4

def base_size
  @base_size
end

#glyph_countInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/font.rb', line 4

def glyph_count
  @glyph_count
end

#glyph_paddingInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/font.rb', line 4

def glyph_padding
  @glyph_padding
end

#textureInteger (readonly)

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/font.rb', line 4

def texture
  @texture
end

Class Method Details

.load(path, size: 32, char_count: 100) ⇒ Font

Loads the font from the specified path

Parameters:

  • path (String)
  • size (Integer) (defaults to: 32)
  • char_count (Integer) (defaults to: 100)

Returns:

Raises:



23
24
25
26
# File 'src/ruby/models/font.rb', line 23

def self.load(path, size: 32, char_count: 100)
  raise Font::NotFound.new("Could not find font at path \"#{path}\"") unless File.exist?(path)
  load_font_ex(path, size, char_count)
end

Instance Method Details

#draw(text, position: Vector2::ZERO, size: 32, padding: 0, colour: BLACK) ⇒ nil

Draws the text at the given position, size, padding, and colour

Parameters:

  • text (String)
  • position (Vector2) (defaults to: Vector2::ZERO)
  • size (Integer) (defaults to: 32)
  • padding (Integer) (defaults to: 0)
  • colour (Colour) (defaults to: BLACK)

Returns:

  • (nil)


41
42
43
# File 'src/ruby/models/font.rb', line 41

def draw(text, position: Vector2::ZERO, size: 32, padding: 0, colour: BLACK)
  draw_text_ex(self, text, position, size, padding, colour)
end

#filter=(val) ⇒ Integer

Sets the filtering and generates mipmaps for the Texture2D used behind the Font

Parameters:

Returns:

  • (Integer)


68
69
70
71
# File 'src/ruby/models/font.rb', line 68

def filter=(val)
  texture.generate_mipmaps
  texture.filter = val
end

#measure(text, size: 32, padding: 0) ⇒ Vector2

Returns the size of the text

Parameters:

  • text (String)
  • size (Integer) (defaults to: 32)
  • padding (Integer) (defaults to: 0)

Returns:

Raises:



51
52
53
# File 'src/ruby/models/font.rb', line 51

def measure(text, size: 32, padding: 0)
  measure_text_ex(self, text, size, padding)
end

#to_hHash

Return the object represented by a Hash

Returns:

  • (Hash)


8
9
10
11
12
13
14
15
# File 'src/ruby/models/font.rb', line 8

def to_h
  {
    base_size: base_size,
    glyph_count: glyph_count,
    glyph_padding: glyph_padding,
    texture: texture.to_h,
  }
end

#to_image(text, size: 32, padding: 0, colour: BLACK) ⇒ Image

Creates an image from the font

Parameters:

  • text (String)

    The text to put on the screen

  • size (Integer) (defaults to: 32)
  • padding (Integer) (defaults to: 0)
  • colour (Colour) (defaults to: BLACK)

Returns:



61
62
63
# File 'src/ruby/models/font.rb', line 61

def to_image(text, size: 32, padding: 0, colour: BLACK)
  image_text_ex(self, text, size, padding, colour)
end

#unloadnil

Unloads the font from memory

Returns:

  • (nil)


30
31
32
# File 'src/ruby/models/font.rb', line 30

def unload
  unload_font(self)
end