summaryrefslogtreecommitdiff
path: root/honey/window.lua
blob: fa777d02f18f80dbd9e3269077c47d6d4bbc60f6 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
local module = {}
local glfw = honey.glfw
setmetatable(module, {__index=_G})
setfenv(1, module)


Window = {}
Window.__index = Window


function Window.new(_, width, height, title, monitor, share)
	local monitor = monitor or glfw.monitor_NULL
	local share = share or glfw.window_NULL

	local self = {}
	setmetatable(self, Window)

	self.win = glfw.CreateWindow(width, height, title, monitor, share)
	self.__gc = honey.util.gc_canary(function()
		glfw.DestroyWindow(self.win)
	end)

	return self
end
setmetatable(Window, {__call=Window.new})


function Window.shouldClose(self)
	return glfw.WindowShouldClose(self.win) == glfw.TRUE
end
function Window.setShouldClose(self, state)
	glfw.SetWindowShouldClose(self.win, state)
end


function Window.setTitle(self, title)
	glfw.SetWindowTitle(self.win, title)
end


function Window.getPos(self)
	return glfw.GetWindowPos(self.win)
end
function Window.setPos(self, x, y)
	glfw.SetWindowPos(self.win, x, y)
end


function Window.getSize(self)
	return glfw.GetWindowSize(self.win)
end
function Window.setSizeLimits(self, minwidth, minheight, maxwidth, maxheight)
	glfw.SetWindowSizeLimits(self.win, minwidth, minheight, maxwidth, maxheight)
end
function Window.setAspectRatio(self, numerator, denominator)
	glfw.SetWindowAspectRatio(self.win, numerator, denominator)
end
function Window.setSize(self, width, height)
	glfw.SetWindowSize(self.win, width, height)
end


function Window.getFramebufferSize(self)
	return glfw.GetFramebufferSize(self.win)
end
function Window.getFrameSize(self)
	return glfw.GetWindowFrameSize(self.win)
end

function Window.getContentScale(self)
	return glfw.GetWindowContentScale(self.win)
end


function Window.getOpacity(self)
	return glfw.GetWindowOpacity(self.win)
end
function Window.setOpacity(self, opacity)
	return glfw.SetWindowOpacity(self.win, opacity)
end


function Window.iconify(self)
	return glfw.IconityWindow(self.win)
end
function Window.restore(self)
	return glfw.RestoreWindow(self.win)
end
function Window.maximize(self)
	return glfw.MaximizeWindow(self.win)
end
function Window.show(self)
	return glfw.ShowWindow(self.win)
end
function Window.hide(self)
	return glfw.HideWindow(self.win)
end
function Window.focus(self)
	return glfw.FocusWindow(self.win)
end
function Window.requestAttention(self)
	return glfw.RequestWindowAttention(self.win)
end


function Window.getMonitor(self)
	return glfw.GetWindowMonitor(self.win)
end
function Window.setMonitor(self, monitor, xpos, ypos, width, height, refreshRate)
	return glfw.SetWindowMonitor(self.win, monitor, xpos, ypos, width, height, refreshRate)
end


function Window.getAttrib(self, attrib)
	return glfw.GetWindowAttrib(self.win, attrib)
end
function Window.setAttrib(self, attrib, value)
	return glfw.SetWindowAttrib(self.win, attrib, value)
end


function Window.setPositionCallback(self, cb)
	return glfw.SetWindowPosCallback(self.win, cb)
end
function Window.setSizeCallback(self, cb)
	return glfw.SetWindowSizeCallback(self.win, cb)
end
function Window.setCloseCallback(self, cb)
	return glfw.SetWindowCloseCallback(self.win, cb)
end
function Window.setRefreshCallback(self, cb)
	return glfw.SetWindowRefreshCallback(self.win, cb)
end
function Window.setFocusCallback(self, cb)
	return glfw.SetWindowFocusCallback(self.win, cb)
end
function Window.setIconifyCallback(self, cb)
	return glfw.SetWindowIconifyCallback(self.win, cb)
end
function Window.setMaximizeCallback(self, cb)
	return glfw.SetWindowIconifyCallback(self.win, cb)
end
function Window.setFramebufferSizeCallback(self, cb)
	return glfw.SetFramebufferSizeCallback(self.win, cb)
end
function Window.setContentScaleCallback(self, cb)
	return glfw.SetContentScaleCallback(self.win, cb)
end

function Window.setKeyCallback(self, cb)
	return glfw.SetKeyCallback(self.win, cb)
end


function Window.swapBuffers(self)
	glfw.SwapBuffers(self.win)
end


return module.Window