Class: Hemi::Render::Font
Constant Summary collapse
- ALLOWED_MODES =
%i[solid blended shaded].freeze
- FONT_FILE_PATTERN =
/([\w-]*)_([\d]*)/.freeze
Constants inherited from Texture
Texture::ERR__INVALID_POSITION
Class Attribute Summary collapse
-
.fonts ⇒ Object
readonly
Returns the value of attribute fonts.
Instance Attribute Summary collapse
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#font_path ⇒ Object
readonly
Returns the value of attribute font_path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Texture
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name_size) ⇒ Font
constructor
A new instance of Font.
- #render(text, position: nil, mode: :blended) ⇒ Object
Methods inherited from Texture
Constructor Details
#initialize(name_size) ⇒ Font
Returns a new instance of Font.
14 15 16 17 18 19 20 21 22 |
# File 'lib/hemi/render/font.rb', line 14 def initialize(name_size) name, size = *name_size.to_s.scan(FONT_FILE_PATTERN).flatten @font_path = "assets/fonts/#{name}.ttf" @font = SDL2::TTF.open(font_path, size.to_i) Font.register(name_size, self) rescue SDL2::Error => _e raise ArgumentError, format(ERR__FONT_NOT_FOUND, font_path) end |
Class Attribute Details
.fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
34 35 36 |
# File 'lib/hemi/render/font.rb', line 34 def fonts @fonts end |
Instance Attribute Details
#font ⇒ Object (readonly)
Returns the value of attribute font.
24 25 26 |
# File 'lib/hemi/render/font.rb', line 24 def font @font end |
#font_path ⇒ Object (readonly)
Returns the value of attribute font_path.
24 25 26 |
# File 'lib/hemi/render/font.rb', line 24 def font_path @font_path end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
24 25 26 |
# File 'lib/hemi/render/font.rb', line 24 def size @size end |
Class Method Details
.bucket ⇒ Object
36 37 38 |
# File 'lib/hemi/render/font.rb', line 36 def bucket :fonts end |
Instance Method Details
#render(text, position: nil, mode: :blended) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/hemi/render/font.rb', line 26 def render(text, position: nil, mode: :blended) @texture = Hemi::Render::Window .renderer .create_texture_from(surface(text, mode: mode)) Hemi::Render::Window.renderer.copy(texture, nil, rectangle(position: position)) end |