Class: Ruby2D::BitmapText
- Inherits:
-
Object
- Object
- Ruby2D::BitmapText
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/bitmap_text.rb
Overview
Text drawn with the built-in bitmap font (no TTF file needed)
Constant Summary
Constants included from Interactive
Interactive::OBJECT_EVENTS, Interactive::OBJECT_EVENT_FILTER_PREDICATES
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#rotate ⇒ Object
Returns the value of attribute rotate.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
#color, #height, #padding_bottom, #padding_left, #padding_right, #padding_top, #visible, #width, #x_align, #y_align, #z
Instance Method Summary collapse
-
#_render_scene ⇒ Object
Scene-graph draw hook (see Renderable#_render_scene):
renderwith no overrides, minus its keyword handling — a zero-arg call into a keyword-heavyrenderstill pays microseconds of keyword setup on wasm mruby. -
#initialize(content, x: 0, y: 0, z: 0, scale: 3, rotate: 0, rx: nil, ry: nil, color: nil, colour: nil, opacity: nil, add: true, visible: true) ⇒ BitmapText
constructor
Create a bitmap text object.
-
#render(x: nil, y: nil, scale: nil, rotate: nil, color: nil, colour: nil, opacity: nil) ⇒ Object
Render the text.
-
#rx ⇒ Object
Get the rotation center x coordinate (defaults to the text's center).
-
#rx=(val) ⇒ Object
Set the rotation center x coordinate.
-
#ry ⇒ Object
Get the rotation center y coordinate.
-
#ry=(val) ⇒ Object
Set the rotation center y coordinate.
Methods included from Renderable
#_alignment_anchor_dx, #_alignment_anchor_dy, #_apply_padding, #_extract_alignment, #_point_in_polygon?, #_point_on_segment?, #_require_numeric_position, #_resolve_alignment, #_unrotate, #_validate_dimensions, #add, #colour=, #contains?, flatten_color, flatten_per_vertex, flatten_points, flatten_resolved_color, #hide, #opacity, #opacity=, #padding=, #remove, resolve_color_or_default, resolve_single_color, #show
Methods included from Interactive
#_fire_event, #interactive?, #off, #on
Constructor Details
#initialize(content, x: 0, y: 0, z: 0, scale: 3, rotate: 0, rx: nil, ry: nil, color: nil, colour: nil, opacity: nil, add: true, visible: true) ⇒ BitmapText
Create a bitmap text object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby2d/bitmap_text.rb', line 43 def initialize(content, x: 0, y: 0, z: 0, scale: 3, rotate: 0, rx: nil, ry: nil, color: nil, colour: nil, opacity: nil, add: true, visible: true) self.x = x self.y = y @z = z @rotate = rotate @_user_rx = rx @_user_ry = ry @content = content.to_s @scale = validate_scale(scale) self.color = color || colour || 'white' self.opacity = opacity unless opacity.nil? Ext.bitmap_text_create(self) @visible = visible self.add if add end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/ruby2d/bitmap_text.rb', line 8 def content @content end |
#rotate ⇒ Object
Returns the value of attribute rotate.
9 10 11 |
# File 'lib/ruby2d/bitmap_text.rb', line 9 def rotate @rotate end |
#scale ⇒ Object
Returns the value of attribute scale.
8 9 10 |
# File 'lib/ruby2d/bitmap_text.rb', line 8 def scale @scale end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/ruby2d/bitmap_text.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/ruby2d/bitmap_text.rb', line 8 def y @y end |
Instance Method Details
#_render_scene ⇒ Object
Scene-graph draw hook (see Renderable#_render_scene): render with no
overrides, minus its keyword handling — a zero-arg call into a
keyword-heavy render still pays microseconds of keyword setup on wasm
mruby.
127 128 129 |
# File 'lib/ruby2d/bitmap_text.rb', line 127 def _render_scene Ext.bitmap_text_draw(self, rx, ry) end |
#render(x: nil, y: nil, scale: nil, rotate: nil, color: nil, colour: nil, opacity: nil) ⇒ Object
Render the text. Called with overrides for one-shot rendering inside a
render block; with no arguments it draws the same frame the scene graph
does (delegating to _render_scene).
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ruby2d/bitmap_text.rb', line 88 def render(x: nil, y: nil, scale: nil, rotate: nil, color: nil, colour: nil, opacity: nil) if x.nil? && y.nil? && scale.nil? && rotate.nil? && color.nil? && colour.nil? && opacity.nil? return _render_scene end Window.render_ready_check saved_x, saved_y = @x, @y saved_scale = @scale saved_rotate = @rotate saved_color = @color @x = x if x @y = y if y @scale = validate_scale(scale) if scale @rotate = rotate if rotate c = color || colour if c || opacity @color = c ? Color.new(c) : Color.new(saved_color) @color.opacity = opacity if opacity end begin Ext.bitmap_text_draw(self, rx, ry) ensure @x, @y = saved_x, saved_y @scale = saved_scale @rotate = saved_rotate @color = saved_color end end |
#rx ⇒ Object
Get the rotation center x coordinate (defaults to the text's center)
23 24 25 |
# File 'lib/ruby2d/bitmap_text.rb', line 23 def rx @_user_rx.nil? ? @x + @width / 2.0 : @_user_rx end |
#rx=(val) ⇒ Object
Set the rotation center x coordinate
33 34 35 |
# File 'lib/ruby2d/bitmap_text.rb', line 33 def rx=(val) @_user_rx = val end |
#ry ⇒ Object
Get the rotation center y coordinate
28 29 30 |
# File 'lib/ruby2d/bitmap_text.rb', line 28 def ry @_user_ry.nil? ? @y + @height / 2.0 : @_user_ry end |
#ry=(val) ⇒ Object
Set the rotation center y coordinate
38 39 40 |
# File 'lib/ruby2d/bitmap_text.rb', line 38 def ry=(val) @_user_ry = val end |