diff options
Diffstat (limited to 'lib/camera/wrappers/text_wrapper.rb')
| -rw-r--r-- | lib/camera/wrappers/text_wrapper.rb | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/camera/wrappers/text_wrapper.rb b/lib/camera/wrappers/text_wrapper.rb index 56b35ed..ad96881 100644 --- a/lib/camera/wrappers/text_wrapper.rb +++ b/lib/camera/wrappers/text_wrapper.rb @@ -3,19 +3,31 @@ module Camera # Wraps existing variables as well as adding new methods # so that it can be handled by the Camera Module + # TODO: note that text could not be resized at the current iteration + # of Ruby2D so the math needs to be changed compensate for this. + # When Ruby2D gets updated to allow text resizing the math will need + # to be corrected again(see image_wrapper.rb for reference, that has + # math that allows for resizing) module TextWrapped + @center = false + # Recalculates real coordiantes # Use after changing variables def redraw angle = Camera.angle * (Math::PI / 180) half_width = Window.width * 0.5 half_height = Window.height * 0.5 - offset_x = x + (width / 2) - offset_y = y + (height / 2) + if center + offset_y = y + (Camera.zoom / 2) + offset_x = x + (Camera.zoom / 2) + else + offset_x = x + (width / Camera.zoom / 2) + offset_y = y + (height / Camera.zoom / 2) + end @x = (((offset_x - Camera.x) * Math.cos(angle)) - ((offset_y - Camera.y) * Math.sin(angle))) \ - * Camera.zoom + half_width - (width * Camera.zoom / 2) + * Camera.zoom + half_width - (width / 2) @y = (((offset_x - Camera.x) * Math.sin(angle)) + ((offset_y - Camera.y) * Math.cos(angle))) \ - * Camera.zoom + half_height - (height * Camera.zoom / 2) + * Camera.zoom + half_height - (height / 2) @rotate = rotate + Camera.angle @size = size * Camera.zoom end @@ -60,5 +72,13 @@ module Camera def size=(size) @virtual_size = size end + + def center + @center + end + + def center=(center) + @center = center + end end end |
