aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/lua/skia.lua
blob: e15e122703190092f61b9f9b6c744a1130c29017 (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
-- Experimental helpers for skia --

function string.startsWith(String,Start)
   return string.sub(String,1,string.len(Start))==Start
end

function string.endsWith(String,End)
   return End=='' or string.sub(String,-string.len(End))==End
end


Sk = {}

function Sk.isFinite(x)
    return x * 0 == 0
end

-------------------------------------------------------------------------------

Sk.Rect = { left = 0, top = 0, right = 0, bottom = 0 }
Sk.Rect.__index = Sk.Rect

function Sk.Rect.new(l, t, r, b)
    local rect
    if r then
        -- 4 arguments
        rect = { left = l, top = t, right = r, bottom = b }
    elseif l then
        -- 2 arguments
        rect = { right = l, bottom = t }
    else
        -- 0 arguments
        rect = {}
    end
    setmetatable(rect, Sk.Rect)
    return rect;
end

function Sk.Rect:width()
    return self.right - self.left
end

function Sk.Rect:height()
    return self.bottom - self.top
end

function Sk.Rect:isEmpty()
    return self:width() <= 0 or self:height() <= 0
end

function Sk.Rect:isFinite()
    local value = self.left * 0
    value = value * self.top
    value = value * self.right
    value = value * self.bottom
    return 0 == value
end

function Sk.Rect:setEmpty()
    self.left = 0
    self.top = 0
    self.right = 0
    self.bottom = 0
end

function Sk.Rect:set(l, t, r, b)
    self.left = l
    self.top = t
    self.right = r
    self.bottom = b
end

function Sk.Rect:offset(dx, dy)
    dy = dy or dx

    self.left = self.left + dx
    self.top = self.top + dy
    self.right = self.right + dx
    self.bottom = self.bottom + dy
end

function Sk.Rect:inset(dx, dy)
    dy = dy or dx

    self.left = self.left + dx
    self.top = self.top + dy
    self.right = self.right - dx
    self.bottom = self.bottom - dy
end

-------------------------------------------------------------------------------