LUADOC - Farming Simulator 22

Script v1_7_1_0

Engine v1_7_1_0

Foundation Reference

ClearElement

Description
Display element for images. Used layers: "image" for the display image.
XML Configuration Parameters
GuiElement#offsetstring [optional] Position offset of the displayed image relative to this element's origin in reference resolution, defaults to [0, 0]. Format: "[x]px [y]px".
GuiElement#focuseOffsetstring [optional] Position offset of the displayed image when it's focused, pressed, highlighted or selected. Works like #offset.

Functions

applyBitmapAspectScale

Description
Definition
applyBitmapAspectScale()
Code
73function ClearElement:applyBitmapAspectScale()
74 local xScale, yScale = self:getAspectScale()
75
76 self.offset[1] = self.offset[1] * xScale
77 self.focusedOffset[1] = self.focusedOffset[1] * xScale
78
79 self.offset[2] = self.offset[2] * yScale
80 self.focusedOffset[2] = self.focusedOffset[2] * yScale
81end

applyScreenAlignment

Description
Definition
applyScreenAlignment()
Code
85function ClearElement:applyScreenAlignment()
86 self:applyBitmapAspectScale()
87
88 ClearElement:superClass().applyScreenAlignment(self)
89end

canReceiveFocus

Description
Definition
canReceiveFocus()
Code
134function ClearElement:canReceiveFocus()
135 if not self.visible or #self.elements < 1 then
136 return false
137 end
138 -- element can only receive focus if all sub elements are ready to receive focus
139 for _, v in ipairs(self.elements) do
140 if (not v:canReceiveFocus()) then
141 return false
142 end
143 end
144 return true
145end

copyAttributes

Description
Definition
copyAttributes()
Code
63function ClearElement:copyAttributes(src)
64 ClearElement:superClass().copyAttributes(self, src)
65
66 GuiOverlay.copyOverlay(self.overlay, src.overlay)
67 self.offset = table.copy(src.offset)
68 self.focusedOffset = table.copy(src.focusedOffset)
69end

delete

Description
Definition
delete()
Code
31function ClearElement:delete()
32 GuiOverlay.deleteOverlay(self.overlay)
33
34 ClearElement:superClass().delete(self)
35end

draw

Description
Definition
draw()
Code
124function ClearElement:draw(clipX1, clipY1, clipX2, clipY2)
125 local xOffset, yOffset = self:getOffset()
126
127 clearOverlayArea(self.absPosition[1]+xOffset, self.absPosition[2]+yOffset, self.size[1], self.size[2], self.overlay.rotation, self.size[1]/2, self.size[2]/2)
128
129 ClearElement:superClass().draw(self, clipX1, clipY1, clipX2, clipY2)
130end

getFocusTarget

Description
Definition
getFocusTarget()
Code
149function ClearElement:getFocusTarget()
150 local _, firstElement = next(self.elements)
151 if firstElement then
152 return firstElement
153 end
154 return self
155end

getOffset

Description
Definition
getOffset()
Code
104function ClearElement:getOffset()
105 local xOffset, yOffset = self.offset[1], self.offset[2]
106 local state = self:getOverlayState()
107 if state == GuiOverlay.STATE_FOCUSED or state == GuiOverlay.STATE_PRESSED or state == GuiOverlay.STATE_SELECTED or GuiOverlay.STATE_HIGHLIGHTED then
108 xOffset = self.focusedOffset[1]
109 yOffset = self.focusedOffset[2]
110 end
111 return xOffset, yOffset
112end

loadFromXML

Description
Definition
loadFromXML()
Code
39function ClearElement:loadFromXML(xmlFile, key)
40 ClearElement:superClass().loadFromXML(self, xmlFile, key)
41
42 GuiOverlay.loadOverlay(self, self.overlay, "clear", self.imageSize, nil, xmlFile, key)
43 self.focusedOffset = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#focusedOffset"), self.outputSize, self.focusedOffset)
44 self.offset = GuiUtils.getNormalizedValues(getXMLString(xmlFile, key.."#offset"), self.outputSize, self.offset)
45end

loadProfile

Description
Definition
loadProfile()
Code
49function ClearElement:loadProfile(profile, applyProfile)
50 ClearElement:superClass().loadProfile(self, profile, applyProfile)
51
52 GuiOverlay.loadOverlay(self, self.overlay, "clear", self.imageSize, profile, nil, nil)
53 self.offset = GuiUtils.getNormalizedValues(profile:getValue("offset"), self.outputSize, self.offset)
54 self.focusedOffset = GuiUtils.getNormalizedValues(profile:getValue("focusedOffset"), self.outputSize, {self.offset[1], self.offset[2]})
55
56 if applyProfile then
57 self:applyBitmapAspectScale()
58 end
59end

new

Description
Definition
new()
Code
20function ClearElement.new(target, custom_mt)
21 local self = GuiElement.new(target, custom_mt or BitmapElement_mt)
22
23 self.offset = {0,0}
24 self.focusedOffset = {0,0}
25 self.overlay = {}
26 return self
27end

setDisabled

Description
Definition
setDisabled()
Code
93function ClearElement:setDisabled(disabled, doNotUpdateChildren)
94 ClearElement:superClass().setDisabled(self, disabled, doNotUpdateChildren)
95 if disabled then
96 self:setOverlayState(GuiOverlay.STATE_DISABLED)
97 else
98 self:setOverlayState(GuiOverlay.STATE_NORMAL)
99 end
100end

setImageRotation

Description
Set this element's image overlay's rotation.
Definition
setImageRotation(float rotation)
Arguments
floatrotationRotation in radians
Code
118function ClearElement:setImageRotation(rotation)
119 self.overlay.rotation = rotation
120end