Skip to content

Commit

Permalink
Merge pull request #24 from Vovkiv/v3004
Browse files Browse the repository at this point in the history
V3004
  • Loading branch information
Vovkiv authored Oct 2, 2024
2 parents 99a8fe4 + b5fad86 commit cc922ff
Show file tree
Hide file tree
Showing 15 changed files with 904 additions and 170 deletions.
33 changes: 16 additions & 17 deletions demo/resolution_solution.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local rs = {
_URL = "https://github.com/Vovkiv/resolution_solution",
-- All functionality of this library documented here.
_DOCUMENTATION = "https://github.com/Vovkiv/resolution_solution/blob/main/resolution_solution_documentation.pdf",
_VERSION = 3003,
_VERSION = 3004,
-- love2d version for which this library designed.
_LOVE = 11.5,
_DESCRIPTION = "Yet another scaling library.",
Expand Down Expand Up @@ -43,7 +43,7 @@ For more information, please refer to <https://unlicense.org>

rs.scale_mode = 1

-- Magic numbers for scaling mode.
-- Constants for scaling modes.
rs.ASPECT_MODE = 1
rs.STRETCH_MODE = 2
rs.PIXEL_PERFECT_MODE = 3
Expand Down Expand Up @@ -80,7 +80,7 @@ rs.game_zone = {
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 3
--- scale_mode = rs.PIXEL_PERFECT_MODE
--- })
--- ```
---@param options table?
Expand Down Expand Up @@ -139,7 +139,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -174,7 +174,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -210,7 +210,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -297,7 +297,7 @@ end
-- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -443,7 +443,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -540,7 +540,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -605,7 +605,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -673,6 +673,7 @@ end
--- This function is a wrapper for love.window.setMode() that should be used with this library. See
--- the Love2d wiki page for information about love.window.setMode():
--- https://love2d.org/wiki/love.window.setMode
--- The reason for this, is that love.window.setMode won't trigger love.resize callback.
---
--- **For advanced users:**
--- ```lua
Expand All @@ -685,16 +686,14 @@ end
--- ```lua
--- -- Basic usage.
--- rs = require("resolution_solution")
--- rs.conf({game_width = 800, game_height = 600, scale_mode = 3})
--- rs.conf({game_width = 800, game_height = 600, scale_mode = rs.PIXEL_PERFECT_MODE})
--- rs.setMode(rs.get_game_size(), select(3, love.window.getMode()))
-- -- Done, now we initialized game with 800x600 game size and resized window to be same as game width and height.
--- ```
---@param width number
---@param height number
---@param flags table
rs.setMode = function(width, height, flags)
-- Wrapper for love.window.setMode()

local okay, errorMessage = pcall(love.window.setMode, width, height, flags)
if not okay then
error(".setMode: Error: " .. errorMessage, 2)
Expand All @@ -705,6 +704,7 @@ end

--- This function is a wrapper for love.window.updateMode() that should be used with this library.
--- See the Love2d wiki page for information about love.window.updateMode(): https://love2d.org/wiki/love.window.updateMode
--- The reason for this, is that love.window.updateMode won't trigger love.resize callback.
---
--- **For advanced users:**
--- ```lua
Expand All @@ -720,7 +720,8 @@ end
--- rs.conf({
--- game_width = 800,
--- game_height = 600,
--- scale_mode = 3})
--- scale_mode = rs.PIXEL_PERFECT_MODE
--- })
--- -- We want to create game with 800x600 resolution
--- -- But we also want to change window size to be same as game.
--- -- To achieve this, we can do...
Expand All @@ -732,8 +733,6 @@ end
---@param height number
---@param flags table
rs.updateMode = function(width, height, flags)
-- Wrapper for love.window.updateMode()

local okay, errorMessage = pcall(love.window.updateMode, width, height, flags)
if not okay then
error(".updateMode: Error: " .. errorMessage, 2)
Expand All @@ -742,4 +741,4 @@ rs.updateMode = function(width, height, flags)
rs.resize()
end

return rs
return rs
33 changes: 16 additions & 17 deletions examples/basic_setup_with_canvas/resolution_solution.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local rs = {
_URL = "https://github.com/Vovkiv/resolution_solution",
-- All functionality of this library documented here.
_DOCUMENTATION = "https://github.com/Vovkiv/resolution_solution/blob/main/resolution_solution_documentation.pdf",
_VERSION = 3003,
_VERSION = 3004,
-- love2d version for which this library designed.
_LOVE = 11.5,
_DESCRIPTION = "Yet another scaling library.",
Expand Down Expand Up @@ -43,7 +43,7 @@ For more information, please refer to <https://unlicense.org>

rs.scale_mode = 1

-- Magic numbers for scaling mode.
-- Constants for scaling modes.
rs.ASPECT_MODE = 1
rs.STRETCH_MODE = 2
rs.PIXEL_PERFECT_MODE = 3
Expand Down Expand Up @@ -80,7 +80,7 @@ rs.game_zone = {
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 3
--- scale_mode = rs.PIXEL_PERFECT_MODE
--- })
--- ```
---@param options table?
Expand Down Expand Up @@ -139,7 +139,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -174,7 +174,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -210,7 +210,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -297,7 +297,7 @@ end
-- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -443,7 +443,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -540,7 +540,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -605,7 +605,7 @@ end
--- rs.conf({
--- game_width = 640,
--- game_height = 480,
--- scale_mode = 1
--- scale_mode = rs.ASPECT_MODE
--- })
--- love.graphics.setBackgroundColor(0.3, 0.5, 1)
--- rs.setMode(rs.game_width, rs.game_height, {resizable = true})
Expand Down Expand Up @@ -673,6 +673,7 @@ end
--- This function is a wrapper for love.window.setMode() that should be used with this library. See
--- the Love2d wiki page for information about love.window.setMode():
--- https://love2d.org/wiki/love.window.setMode
--- The reason for this, is that love.window.setMode won't trigger love.resize callback.
---
--- **For advanced users:**
--- ```lua
Expand All @@ -685,16 +686,14 @@ end
--- ```lua
--- -- Basic usage.
--- rs = require("resolution_solution")
--- rs.conf({game_width = 800, game_height = 600, scale_mode = 3})
--- rs.conf({game_width = 800, game_height = 600, scale_mode = rs.PIXEL_PERFECT_MODE})
--- rs.setMode(rs.get_game_size(), select(3, love.window.getMode()))
-- -- Done, now we initialized game with 800x600 game size and resized window to be same as game width and height.
--- ```
---@param width number
---@param height number
---@param flags table
rs.setMode = function(width, height, flags)
-- Wrapper for love.window.setMode()

local okay, errorMessage = pcall(love.window.setMode, width, height, flags)
if not okay then
error(".setMode: Error: " .. errorMessage, 2)
Expand All @@ -705,6 +704,7 @@ end

--- This function is a wrapper for love.window.updateMode() that should be used with this library.
--- See the Love2d wiki page for information about love.window.updateMode(): https://love2d.org/wiki/love.window.updateMode
--- The reason for this, is that love.window.updateMode won't trigger love.resize callback.
---
--- **For advanced users:**
--- ```lua
Expand All @@ -720,7 +720,8 @@ end
--- rs.conf({
--- game_width = 800,
--- game_height = 600,
--- scale_mode = 3})
--- scale_mode = rs.PIXEL_PERFECT_MODE
--- })
--- -- We want to create game with 800x600 resolution
--- -- But we also want to change window size to be same as game.
--- -- To achieve this, we can do...
Expand All @@ -732,8 +733,6 @@ end
---@param height number
---@param flags table
rs.updateMode = function(width, height, flags)
-- Wrapper for love.window.updateMode()

local okay, errorMessage = pcall(love.window.updateMode, width, height, flags)
if not okay then
error(".updateMode: Error: " .. errorMessage, 2)
Expand All @@ -742,4 +741,4 @@ rs.updateMode = function(width, height, flags)
rs.resize()
end

return rs
return rs
Loading

0 comments on commit cc922ff

Please sign in to comment.