summaryrefslogtreecommitdiffhomepage
path: root/dragon
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-05-18 03:39:26 -0400
committerrealtradam <[email protected]>2021-05-18 03:39:26 -0400
commit2f845281f133849256b57bb08fd3e9ae57600784 (patch)
treec365e3bdad7e831a1a51baac5ffd5b8361b70069 /dragon
parent8a29791f01d8b7d88bf9d53522e1fd9051564945 (diff)
downloaddragonruby-game-toolkit-contrib-2f845281f133849256b57bb08fd3e9ae57600784.tar.gz
dragonruby-game-toolkit-contrib-2f845281f133849256b57bb08fd3e9ae57600784.zip
Added support for top left origin
Diffstat (limited to 'dragon')
-rw-r--r--dragon/grid.rb40
1 files changed, 34 insertions, 6 deletions
diff --git a/dragon/grid.rb b/dragon/grid.rb
index c2a6a43..dd36df7 100644
--- a/dragon/grid.rb
+++ b/dragon/grid.rb
@@ -2,15 +2,20 @@
# Copyright 2019 DragonRuby LLC
# MIT License
# grid.rb has been released under MIT (*only this file*).
+# Contributors outside of DragonRuby who also hold Copyright: _Tradam
module GTK
class Grid
include Serialize
- SCREEN_Y_DIRECTION = -1.0
+
+ # Returns which direction y is positive in. Negative means upward.
+ #
+ # @return [Float] `-1.0` or `1.0`
+ attr_accessor :screen_y_direction
# The coordinate system currently in use.
#
- # @return [Symbol] `:bottom_left` or `:center`
+ # @return [Symbol] `:bottom_left`, `:center` or `:top_left`
attr_accessor :name
# Returns the "x" coordinate indicating the bottom of the screen.
@@ -84,14 +89,14 @@ module GTK
#
# @return [Float]
def transform_y y
- @origin_y + y * SCREEN_Y_DIRECTION
+ @origin_y + y * screen_y_direction
end
# Returns `y` minus the origin "y".
#
# @return [Float]
def untransform_y y
- @origin_y + y * SCREEN_Y_DIRECTION
+ @origin_y + y * screen_y_direction
end
def ffi_draw
@@ -121,7 +126,8 @@ module GTK
@center_y = @runtime.logical_height.half
@rect = [@left, @bottom, @runtime.logical_width, @runtime.logical_height].rect
@center = [@center_x, @center_y].point
- @ffi_draw.set_grid @origin_x, @origin_y, SCREEN_Y_DIRECTION
+ @screen_y_direction = -1.0
+ @ffi_draw.set_grid @origin_x, @origin_y, @screen_y_direction
end
# Sets the rendering coordinate system to have its origin in the center.
@@ -141,7 +147,29 @@ module GTK
@center_y = 0.0
@rect = [@left, @bottom, @runtime.logical_width, @runtime.logical_height].rect
@center = [@center_x, @center_y].point
- @ffi_draw.set_grid @origin_x, @origin_y, SCREEN_Y_DIRECTION
+ @screen_y_direction = -1.0
+ @ffi_draw.set_grid @origin_x, @origin_y, @screen_y_direction
+ end
+
+ # Sets the rendering coordinate system to have its origin in the top left.
+ #
+ # @return [void]
+ # @gtk
+ def origin_top_left!
+ return if @name == :top_left
+ @name = :top_left
+ @origin_x = 0.0
+ @origin_y = 0.0
+ @left = 0.0
+ @right = @runtime.logical_width
+ @top = 0.0
+ @bottom = @runtime.logical_height
+ @center_x = @runtime.logical_width.half
+ @center_y = @runtime.logical_height.half
+ @rect = [@left, @runtime.logical_height, @runtime.logical_width, @top].rect
+ @center = [@center_x, @center_y].point
+ @screen_y_direction = 1.0
+ @ffi_draw.set_grid @origin_x, @origin_y, @screen_y_direction
end
# The logical width used for rendering.