45 | function HUDFrameElement:createComponents(hudAtlasPath, baseX, baseY, width, height) |
46 | -- get pixel sizes so that frame lines are always at least a screen pixel thick |
47 | local refPixelX, refPixelY = 1 / g_referenceScreenWidth, 1 / g_referenceScreenHeight |
48 | local screenPixelX, screenPixelY = 1 / g_screenWidth, 1 / g_screenHeight |
49 | local onePixelX, onePixelY = math.max(refPixelX, screenPixelX), math.max(refPixelY, screenPixelY) |
50 | |
51 | -- top line |
52 | local posX, posY = baseX, baseY + self:getHeight() |
53 | local frameWidth, frameHeight = getNormalizedScreenValues(self.frameThickness, self.frameThickness) |
54 | local pixelsX, pixelsY = math.ceil(frameWidth / onePixelX), math.ceil(frameHeight / onePixelY) |
55 | self.frameWidth, self.frameHeight = pixelsX * onePixelX, pixelsY * onePixelY |
56 | |
57 | local lineOverlay = Overlay.new(hudAtlasPath, posX, posY - self.frameHeight, width, self.frameHeight) |
58 | lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL)) |
59 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
60 | |
61 | local lineElement = HUDElement.new(lineOverlay) |
62 | self.topLine = lineElement |
63 | self:addChild(lineElement) |
64 | |
65 | -- side lines |
66 | posX, posY = baseX, baseY + self.frameHeight |
67 | lineOverlay = Overlay.new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight * 2) |
68 | lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL)) |
69 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
70 | |
71 | lineElement = HUDElement.new(lineOverlay) |
72 | self.leftLine = lineElement |
73 | self:addChild(lineElement) |
74 | |
75 | posX, posY = baseX + width - self.frameWidth, baseY + self.frameHeight |
76 | lineOverlay = Overlay.new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight * 2) |
77 | lineOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL)) |
78 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
79 | |
80 | lineElement = HUDElement.new(lineOverlay) |
81 | self.rightLine = lineElement |
82 | self:addChild(lineElement) |
83 | |
84 | -- bottom bar |
85 | local barSize = self.barThickness |
86 | local barColor = HUDFrameElement.COLOR.BAR |
87 | if not self.showBar then |
88 | barSize = self.frameThickness |
89 | barColor = HUDFrameElement.COLOR.FRAME |
90 | end |
91 | |
92 | local _, barHeight = getNormalizedScreenValues(0, barSize) |
93 | pixelsY = math.ceil(barHeight / onePixelY) |
94 | local barOverlay = Overlay.new(hudAtlasPath, baseX, baseY, width, pixelsY * onePixelY) |
95 | barOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL)) |
96 | barOverlay:setColor(unpack(barColor)) |
97 | |
98 | local barElement = HUDElement.new(barOverlay) |
99 | self.bottomBar = barElement |
100 | self:addChild(barElement) |
101 | end |
23 | function HUDFrameElement.new(hudAtlasPath, posX, posY, width, height, parent, showBar, frameThickness, barThickness) |
24 | local backgroundOverlay = Overlay.new(hudAtlasPath, posX, posY, width, height) |
25 | backgroundOverlay:setUVs(GuiUtils.getUVs(HUDElement.UV.FILL)) |
26 | backgroundOverlay:setColor(0, 0, 0, 0) -- default invisible |
27 | local self = HUDElement.new(backgroundOverlay, parent, HUDFrameElement_mt) |
28 | |
29 | self.topLine = nil |
30 | self.leftLine = nil |
31 | self.rightLine = nil |
32 | self.bottomBar = nil |
33 | self.frameWidth, self.frameHeight = 0, 0 |
34 | self.showBar = Utils.getNoNil(showBar, true) |
35 | self.frameThickness = frameThickness or HUDFrameElement.THICKNESS.FRAME |
36 | self.barThickness = barThickness or HUDFrameElement.THICKNESS.BAR |
37 | |
38 | self:createComponents(hudAtlasPath, posX, posY, width, height) |
39 | |
40 | return self |
41 | end |
106 | function HUDFrameElement:setDimension(width, height) |
107 | HUDFrameElement:superClass().setDimension(self, width, height) |
108 | |
109 | local lineHeight = nil |
110 | if height ~= nil then |
111 | lineHeight = height - self.frameHeight * 2 |
112 | end |
113 | |
114 | self.topLine:setDimension(width, nil) |
115 | self.leftLine:setDimension(nil, lineHeight) |
116 | self.rightLine:setDimension(nil, lineHeight) |
117 | self.bottomBar:setDimension(width, nil) |
118 | |
119 | local x, y = self:getPosition() |
120 | self.topLine:setPosition(nil, y + self:getHeight() - self.frameHeight) |
121 | self.rightLine:setPosition(x + self:getWidth() - self.frameWidth, nil) |
122 | end |