fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosAdded a hint on startup that tells you 'esc' opens the settings menu. (Cleared in 6 seconds or when pressing escape) Added tooltips to explain what each setting does.a193294

v2.1.1a
4.3 KiB162 linesraw
1local graphics = love.graphics
2
3local clear = graphics.clear
4local setColor = graphics.setColor
5local getColor = graphics.getColor
6local setBackgroundColor = graphics.setBackgroundColor
7local getBackgroundColor = graphics.getBackgroundColor
8
9-- Love2D changed color values to be 0-1
10-- Allow 0-255 values again..
11function graphics.clear(r,g,b,a,...)
12	if type(r) == "table" then
13		r, g, b, a = r.r, r.g, r.b, r.a
14	else
15		r, g, b, a = r or 255, g or 255, b or 255, a or 255
16	end
17	clear(r/255,g/255,b/255,a/255,...)
18end
19
20-- Love2D changed color values to be 0-1
21-- Allow 0-255 values again..
22function graphics.setColor(r,g,b,a)
23	if type(r) == "table" then
24		r, g, b, a = r.r, r.g, r.b, r.a
25	else
26		r, g, b, a = r or 255, g or 255, b or 255, a or 255
27	end
28	setColor(r/255,g/255,b/255,a/255)
29end
30
31function graphics.getColor()
32	local r,g,b,a = getColor()
33	return r*255, g*255, b*255, a*255
34end
35
36-- Love2D changed color values to be 0-1
37-- Allow 0-255 values again..
38function graphics.setBackgroundColor(r,g,b,a)
39	if type(r) == "table" then
40		r, g, b, a = r.r, r.g, r.b, r.a
41	else
42		r, g, b, a = r or 255, g or 255, b or 255, a or 255
43	end
44	setBackgroundColor(r/255,g/255,b/255,a/255)
45end
46
47function graphics.getBackgroundColor()
48	local r,g,b,a = getBackgroundColor()
49	return r*255, g*255, b*255, a*255
50end
51
52-- Draw an image using width and height in pixels
53-- OriginX and OriginY should be between 0 and 1
54-- An origin of 0.5, 0.5 would be the center
55function graphics.easyDraw(obj, x, y, rotation, width, height, originX, originY, ...)
56	if not obj then return end
57
58	local objW, objH = obj:getWidth(), obj:getHeight()
59
60	rotation = rotation or 0
61	width = width or objW
62	height = height or objH
63	originX = originX or 0
64	originY = originY or 0
65
66	local scaledW = width / objW
67	local scaledH = height / objH
68	graphics.draw(obj, x, y, rotation, scaledW, scaledH, objW * originX, objH * originY, ...)
69end
70
71--applies a transformation that maps 
72--  0,0 => ox, oy
73--  1,0 => xx, xy
74--  0,1 => yx, yy
75-- via love.graphics.translate, .rotate and .scale
76
77local sqrt = math.sqrt
78local atan2 = math.atan2
79local acos = math.acos
80local tan = math.tan
81local cos = math.cos
82local sin = math.sin
83
84function graphics.transform(ox, oy, xx, xy, yx, yy)
85
86	local ex, ey, fx,fy = xx-ox, xy-oy, yx-ox, yy-oy
87	if ex*fy<ey*fx then ex,ey,fx,fy=fx,fy,ex,ey end
88	local e,f = math.sqrt(ex*ex+ey*ey), math.sqrt(fx*fx+fy*fy)
89
90	ex,ey = ex/e, ey/e
91	fx,fy = fx/f, fy/f
92
93	local desiredOrientation=math.atan2(ey+fy,ex+fx)
94	local desiredAngle=math.acos(ex*fx+ey*fy)/2
95	local z=math.tan(desiredAngle)
96	local distortion=math.sqrt((1+z*z)/2)
97
98	graphics.translate(ox, oy)
99	graphics.rotate(desiredOrientation)
100	graphics.scale(1, z)
101	graphics.rotate(-math.pi/4)
102	graphics.scale(e/distortion,f/distortion)
103
104end
105
106function graphics.innerRectangle(x, y, w, h, ...)
107	local lw = graphics.getLineWidth()
108
109	x = x + lw/2
110	y = y + lw/2
111	w = w - lw
112	h = h - lw
113
114	graphics.rectangle("line", x, y, w, h, ...)
115end
116
117-- Draw a rectangle to fit AROUND the width and height
118function graphics.outlineRectangle(x, y, w, h, ...)
119	local lw = graphics.getLineWidth()
120
121	x = x - lw/2
122	y = y - lw/2
123	w = w + lw
124	h = h + lw
125
126	graphics.rectangle("line", x, y, w, h, ...)
127end
128
129function graphics.textOutlinef(text, width, x, y, ...)
130	local steps = width * 2 / 3
131	if steps < 1 then steps = 1 end
132
133	for _x = -width, width, steps do
134		for _y = -width, width, steps do
135			graphics.printf(text, x + _x, y + _y, ...)
136		end
137	end
138end
139
140function graphics.textOutline(text, width, x, y, ...)
141	local steps = width * 2 / 3
142	if steps < 1 then steps = 1 end
143
144	for _x = -width, width, steps do
145		for _y = -width, width, steps do
146			graphics.print(text, x + _x, y + _y, ...)
147		end
148	end
149end
150
151function graphics.roundRect(x, y, width, height, radius)
152	--RECTANGLES
153	graphics.rectangle("fill", x + radius, y, width-2*radius, height )
154	graphics.rectangle("fill", x, y + radius, radius, height - (radius * 2))
155	graphics.rectangle("fill", x + (width - radius), y + radius, radius, height - (radius * 2))
156	
157	--ARCS
158	graphics.arc("fill", x + radius, y + radius, radius, math.rad(-180), math.rad(-90))
159	graphics.arc("fill", x + width - radius , y + radius, radius, math.rad(-90), math.rad(0))
160	graphics.arc("fill", x + radius, y + height - radius, radius, math.rad(-180), math.rad(-270))
161	graphics.arc("fill", x + width - radius , y + height - radius, radius, math.rad(0), math.rad(90))
162end