summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ext/ruby2d/ruby2d.c20
-rw-r--r--lib/ruby2d/window.rb3
2 files changed, 23 insertions, 0 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 32b8ab0..52b852a 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -276,6 +276,24 @@ static VALUE ruby2d_show(VALUE s) {
flags = flags | S2D_HIGHDPI;
}
+ // Check viewport size and set
+
+ int viewport_width;
+ VALUE vp_w = rb_iv_get(self, "@viewport_width");
+ if (vp_w == Qnil) {
+ viewport_width = width;
+ } else {
+ viewport_width = NUM2INT(vp_w);
+ }
+
+ int viewport_height;
+ VALUE vp_h = rb_iv_get(self, "@viewport_height");
+ if (vp_h == Qnil) {
+ viewport_height = height;
+ } else {
+ viewport_height = NUM2INT(vp_h);
+ }
+
window = S2D_CreateWindow(
title, width, height, update, render, flags
);
@@ -283,6 +301,8 @@ static VALUE ruby2d_show(VALUE s) {
window->on_key = on_key;
window->on_key_down = on_key_down;
window->on_controller = on_controller;
+ window->viewport.width = viewport_width;
+ window->viewport.height = viewport_height;
S2D_Show(window);
diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb
index 63b0d12..811b950 100644
--- a/lib/ruby2d/window.rb
+++ b/lib/ruby2d/window.rb
@@ -6,6 +6,7 @@ module Ruby2D
def initialize(width: 640, height: 480, title: "Ruby 2D", fps: 60, vsync: true)
@width, @height, @title = width, height, title
+ @viewport_width, @viewport_height = nil, nil
@background = Color.new([0.0, 0.0, 0.0, 1.0])
@resizable = false
@mouse_x = @mouse_y = 0
@@ -36,6 +37,8 @@ module Ruby2D
@title = opts[:title] || @title
@width = opts[:width] || @width
@height = opts[:height] || @height
+ @viewport_width = opts[:viewport_width] || @viewport_width
+ @viewport_height = opts[:viewport_height] || @viewport_height
@resizable = opts[:resizable] || @resizable
@borderless = opts[:borderless] || @borderless
@fullscreen = opts[:fullscreen] || @fullscreen