-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout.lua
More file actions
55 lines (49 loc) · 1.75 KB
/
layout.lua
File metadata and controls
55 lines (49 loc) · 1.75 KB
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
local Theme = require("theme")
local Layout = {}
local MENU_BTN_W = 200
local MENU_BTN_H = 50
-- Returns board geometry for the current window size.
-- Fields: squareSize, boardSize, boardX, boardY
function Layout.getBoard(windowWidth, windowHeight)
local squareSize = math.min(
(windowHeight - 2 * Theme.borderSize - 2 * Theme.uiHeight) / 8,
(windowWidth - 2 * Theme.borderSize) / 8
)
local boardSize = squareSize * 8
return {
squareSize = squareSize,
boardSize = boardSize,
boardX = (windowWidth - boardSize) / 2,
boardY = (windowHeight - boardSize) / 2 + Theme.uiHeight / 2,
}
end
-- Returns menu/options button layout for the current window size.
-- Fields: w, h, x, playY, optionsY, exitY, returnY
function Layout.getMenuButtons(windowWidth, windowHeight)
return {
w = MENU_BTN_W,
h = MENU_BTN_H,
x = (windowWidth - MENU_BTN_W) / 2,
playY = windowHeight / 2 - MENU_BTN_H - 10,
optionsY = windowHeight / 2,
exitY = windowHeight / 2 + MENU_BTN_H + 10,
returnY = windowHeight / 2 + MENU_BTN_H + 10,
}
end
-- Returns the resign button rect in game screen coordinates.
-- Fields: x, y, w, h
function Layout.getResignButton(boardX, boardY, boardSize)
local buttonWidth = 100
return {
x = boardX + boardSize - buttonWidth,
y = boardY + boardSize + Theme.borderSize / 2 + 30,
w = buttonWidth,
h = 30,
}
end
-- Point-in-rect hit test helper used by all screens.
function Layout.hit(pointX, pointY, rectX, rectY, rectWidth, rectHeight)
return pointX >= rectX and pointX <= rectX + rectWidth
and pointY >= rectY and pointY <= rectY + rectHeight
end
return Layout