42 | function HUDFrameElement:createComponents(hudAtlasPath, baseX, baseY, width, height) |
43 | -- get pixel sizes so that frame lines are always at least a screen pixel thick |
44 | local refPixelX, refPixelY = 1 / g_referenceScreenWidth, 1 / g_referenceScreenHeight |
45 | local screenPixelX, screenPixelY = 1 / g_screenWidth, 1 / g_screenHeight |
46 | local onePixelX, onePixelY = math.max(refPixelX, screenPixelX), math.max(refPixelY, screenPixelY) |
47 | |
48 | -- top line |
49 | local posX, posY = baseX, baseY + self:getHeight() |
50 | local frameWidth, frameHeight = getNormalizedScreenValues(HUDFrameElement.THICKNESS.FRAME, HUDFrameElement.THICKNESS.FRAME) |
51 | local pixelsX, pixelsY = math.ceil(frameWidth / onePixelX), math.ceil(frameHeight / onePixelY) |
52 | self.frameWidth, self.frameHeight = pixelsX * onePixelX, pixelsY * onePixelY |
53 | |
54 | local lineOverlay = Overlay:new(hudAtlasPath, posX, posY, width, self.frameHeight) |
55 | lineOverlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
56 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
57 | |
58 | local lineElement = HUDElement:new(lineOverlay) |
59 | self.topLine = lineElement |
60 | self:addChild(lineElement) |
61 | |
62 | -- side lines |
63 | posX, posY = baseX, baseY + self.frameHeight |
64 | lineOverlay = Overlay:new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight) |
65 | lineOverlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
66 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
67 | |
68 | lineElement = HUDElement:new(lineOverlay) |
69 | self.leftLine = lineElement |
70 | self:addChild(lineElement) |
71 | |
72 | posX, posY = baseX + width - self.frameWidth, baseY + self.frameHeight |
73 | lineOverlay = Overlay:new(hudAtlasPath, posX, posY, self.frameWidth, height - self.frameHeight) |
74 | lineOverlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
75 | lineOverlay:setColor(unpack(HUDFrameElement.COLOR.FRAME)) |
76 | |
77 | lineElement = HUDElement:new(lineOverlay) |
78 | self.rightLine = lineElement |
79 | self:addChild(lineElement) |
80 | |
81 | -- bottom bar |
82 | local _, barHeight = getNormalizedScreenValues(0, HUDFrameElement.THICKNESS.BAR) |
83 | pixelsY = math.ceil(barHeight / onePixelY) |
84 | local barOverlay = Overlay:new(hudAtlasPath, baseX, baseY, width, pixelsY * onePixelY) |
85 | barOverlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
86 | barOverlay:setColor(unpack(HUDFrameElement.COLOR.BAR)) |
87 | |
88 | local barElement = HUDElement:new(barOverlay) |
89 | self.bottomBar = barElement |
90 | self:addChild(barElement) |
91 | end |
23 | function HUDFrameElement:new(hudAtlasPath, posX, posY, width, height, parent) |
24 | local backgroundOverlay = Overlay:new(hudAtlasPath, posX, posY, width, height) |
25 | backgroundOverlay:setUVs(getNormalizedUVs(HUDElement.UV.FILL)) |
26 | backgroundOverlay:setColor(0, 0, 0, 0) -- default invisible |
27 | local self = HUDFrameElement:superClass().new(HUDFrameElement_mt, backgroundOverlay, parent) |
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 | |
35 | self:createComponents(hudAtlasPath, posX, posY, width, height) |
36 | |
37 | return self |
38 | end |
96 | function HUDFrameElement:setDimension(width, height) |
97 | HUDFrameElement:superClass().setDimension(self, width, height) |
98 | |
99 | self.topLine:setDimension(width, nil) |
100 | self.leftLine:setDimension(nil, height) |
101 | self.rightLine:setDimension(nil, height) |
102 | self.bottomBar:setDimension(width, nil) |
103 | |
104 | local x, y = self:getPosition() |
105 | self.topLine:setPosition(nil, y + self:getHeight()) |
106 | self.rightLine:setPosition(x + self:getWidth() - self.frameWidth, nil) |
107 | end |