-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscreen.lua
104 lines (80 loc) · 3.24 KB
/
screen.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--[[
#########################################################################
# #
# screen.lua #
# #
# LOVE abstract screen helper #
# #
# Copyright 2011 Josh Bothun #
# http://minornine.com #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License <http://www.gnu.org/licenses/> for #
# more details. #
# #
#########################################################################
--]]
local w, h, f, v, a = love and love.graphics and love.graphics.getMode and love.graphics.getMode()
local screen = {
-- Represents the dimensions of the game screen (as opposed to resolution)
width = w,
height = h,
-- Scale boundaries
min_scale = 1,
max_scale = 100,
-- Screen scaling mode. Supported modes:
-- "fixed": Scale the game screen by the largest integer fitting inside resolution, clipping extra screen space (Default)
-- "stretched": Stretch the game screen to the resolution
mode = 'fixed',
}
-- Override settings
function screen.setSize(w, h)
screen.setWidth(w)
screen.setHeight(h)
end
function screen.setWidth(w)
screen.width = w
end
function screen.setHeight(h)
screen.height = h
end
function screen.setMinScale(s)
screen.min_scale = s
end
function screen.setMaxScale(s)
screen.max_scale = s
end
function screen.setMode(mode)
screen.mode = mode
end
-- Get the dimensions of the game screen
function screen.getSize()
return screen.getWidth(), screen.getHeight()
end
function screen.getWidth()
return screen.width
end
function screen.getHeight()
return screen.height
end
-- Apply screen transformations, this should wrap all your drawing code
function screen.apply()
local res_w, res_h = love.graphics.getMode()
local scale = math.min(math.floor(res_w / screen.width), math.floor(res_h / screen.height))
love.graphics.push()
love.graphics.translate((res_w % (screen.width * scale)) / 2, (res_h % (screen.height * scale)) / 2)
love.graphics.scale(scale)
end
function screen.revert()
love.graphics.pop()
end
-- Export
leaf.screen = screen