Class: Font
- Inherits:
-
Object
- Object
- Font
- 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
-
.load(path, size: 32, char_count: 100) ⇒ Font
Loads the font from the specified path.
Instance Method Summary collapse
-
#draw(text, position: Vector2::ZERO, size: 32, padding: 0, colour: BLACK) ⇒ nil
Draws the text at the given position, size, padding, and colour.
- #filter=(val) ⇒ Integer
-
#initialize(base_size, glyph_count, glyph_padding) ⇒ Font
constructor
Creates a new instance of Font.
-
#measure(text, size: 32, padding: 0) ⇒ Vector2
Returns the size of the text.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
-
#to_image(text, size: 32, padding: 0, colour: BLACK) ⇒ Image
Creates an image from the font.
-
#unload ⇒ nil
Unloads the font from memory.
Constructor Details
Instance Attribute Details
#base_size ⇒ Integer
4 5 6 |
# File 'src/ruby/models/font.rb', line 4 def base_size @base_size end |
#glyph_count ⇒ Integer
4 5 6 |
# File 'src/ruby/models/font.rb', line 4 def glyph_count @glyph_count end |
#glyph_padding ⇒ Integer
4 5 6 |
# File 'src/ruby/models/font.rb', line 4 def glyph_padding @glyph_padding end |
#texture ⇒ Integer (readonly)
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
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
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
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
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_h ⇒ Hash
Return the object represented by a 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
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 |
#unload ⇒ nil
Unloads the font from memory
30 31 32 |
# File 'src/ruby/models/font.rb', line 30 def unload unload_font(self) end |