· 4 years ago · Dec 25, 2020, 03:06 PM
1-- Easy Graphical User Interface for CraftOS
2-- with interactive designer
3-- v.1, for CraftOS 1.8
4
5--multiple monitor support: this array stores the wrapped peripherals, monitor sizes and text scales
6monitors = {}
7terminalScreen = nil
8
9--GUI Elements Clickable
10--dynamic text boxes include rectangles by using an empty string and buttons (even checkboxes) by assigning an onClick Function
11dynamicTextBoxes = {}
12sliders = {}
13dropDownMenus = {}
14navigationMenus = {}
15colorPickers = {}
16
17--unclickable
18--progressBars can also be used as bar charts by assigning the bg color to one of its colors
19progressBars = {}
20coordinateSystems = {}
21pictures = {}
22
23elements = {}
24
25--For GUI Elements to be rendered, they need to be added to a screen. A screen can then be saved and rendered on any advanced device.
26screens = {}
27
28--PLEASE READ THIS ABOUT FILE SYSTEM
29--You might want to change the following value if you are not running EasyGUI in a root directory.
30--For example: if you put EasyGUI.lua in a folder called apis, change to: 'root = "/apis/"'
31root = "/"
32
33--1 = DEBUG, 2 = INFO, 3 = WARNING, 4 = ERROR, 5 = FATAL
34--PLEASE READ THIS ABOUT LOGGING!
35--WARNING level 1 results in extremely large files. Use only when debugging.
36--Level 2 can also be rather big. Leave it at 3 if everything works ok.
37--Keep in mind that the size of log file over time depends on the refresh rate used.
38--Note that by default one cc computer only has 1mb of storage, can be changed in computercraft.cfg.
39--If less than 1kb is available, log won't be written to anymore.
40writingLogLevel = 3
41
42--Designer/Editor colors.
43--If you don't like the default settings, change the colors here: default text color, default background color and an accent color.
44colorPalette = {colors.white,colors.black,colors.green}
45
46-------- Changelog
47
48--25/12/2020:
49-- Release Beta v.0.1
50-- All features that were planned at this point have now been implemented.
51-- It took roughly half a year. An intensive testing phase is about to begin.
52-------
53
54----------------------------------
55--Technical stuff starting. Enjoy.
56refreshTimerID = nil
57refreshRate = nil
58
59IDlist = {}
60startTime = os.clock()
61logFile = nil
62lastLogString = nil
63
64refreshFunction = nil
65processClickEventFunc = nil
66processEventFunc = nil
67
68args = {...}
69
70--color arrays
71colorsArrayStrToNum = {}
72colorsArrayStrToNum["0"] = colors.white
73colorsArrayStrToNum["1"] = colors.orange
74colorsArrayStrToNum["2"] = colors.magenta
75colorsArrayStrToNum["3"] = colors.lightBlue
76colorsArrayStrToNum["4"] = colors.yellow
77colorsArrayStrToNum["5"] = colors.lime
78colorsArrayStrToNum["6"] = colors.pink
79colorsArrayStrToNum["7"] = colors.gray
80colorsArrayStrToNum["8"] = colors.lightGray
81colorsArrayStrToNum["9"] = colors.cyan
82colorsArrayStrToNum["a"] = colors.purple
83colorsArrayStrToNum["b"] = colors.blue
84colorsArrayStrToNum["c"] = colors.brown
85colorsArrayStrToNum["d"] = colors.green
86colorsArrayStrToNum["e"] = colors.red
87colorsArrayStrToNum["f"] = colors.black
88
89colorsArrayNumToNum = {colors.white,colors.orange,colors.magenta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.gray,colors.lightGray,colors.cyan,colors.purple,colors.blue,colors.brown,colors.green,colors.red,colors.black}
90
91colorsArrayNumToString = {}
92colorsArrayNumToString[colors.white] = "0"
93colorsArrayNumToString[colors.orange] = "1"
94colorsArrayNumToString[colors.magenta] = "2"
95colorsArrayNumToString[colors.lightBlue] = "3"
96colorsArrayNumToString[colors.yellow] = "4"
97colorsArrayNumToString[colors.lime] = "5"
98colorsArrayNumToString[colors.pink] = "6"
99colorsArrayNumToString[colors.gray] = "7"
100colorsArrayNumToString[colors.lightGray] = "8"
101colorsArrayNumToString[colors.cyan] = "9"
102colorsArrayNumToString[colors.purple] = "a"
103colorsArrayNumToString[colors.blue] = "b"
104colorsArrayNumToString[colors.brown] = "c"
105colorsArrayNumToString[colors.green] = "d"
106colorsArrayNumToString[colors.red] = "e"
107colorsArrayNumToString[colors.black] = "f"
108
109--designer stuff
110designerMonitor = nil
111designerScreen = nil
112designerX = nil
113designerY = nil
114lastSave = nil
115saveTimerID = nil
116selectedPart = ""
117
118--hashes (md5)
119terminalID = "a8bcae0d70fdbf14c572156f8e31000a"
120
121initMonsSID = "cdac1a98818689af48db3b552851fc6f"
122initMonsSHeadingID = "890f2028b00a4579df6b48ad34d8a269"
123initMonsSLeftRectID = "ea24a45da7a8fbef8b236748907aa7fb"
124initMonsSTextID = "4900d0b145e8533b398b5e12dd7525e5"
125initMonsSPictureID = "694b8cec4ab3a26d01c68005ec8aa56c"
126initMonsSErrorID = "fb95b84d5b14a09ab93511fc6fb575f4"
127
128changeMonSID = "c737dc7d97748d8b40963a95a0dc7861"
129changeMonSDDMenuID = "d73a60583fc13ea25db201571bca7301"
130changeMonSApplyID = "c1eac4028ea88abba1e9fa2b5894a5ac"
131changeMonSScaleDDID = "0f76acbc91744387905e22aa7420e892"
132
133mainSID = "174e80d8ed22ac2287bf056b4e7c2c0a"
134mainSBorderID = "42adbd6df1cf676ed2cbf9040ff73d69"
135mainSButton1ID = "9d8692e9a7d29f1cea8ff0728b27ec15"
136mainSButton2ID = "9ce00dc655e34d3e4ade16daa7267a12"
137mainSButton3ID = "a79fa19cb268b702bcbcaccbbb7ce8d3"
138mainSHeadingID = "0ede5fa492669473d6f765e957967296"
139
140screensSID = "c00d2f1c0bc784e4d9bd67f800a0e702"
141screensSHeadingID = "04f609cb0bf336e33b5ac887858f8a81"
142screensSButton1ID = "aaa4cb31682f6968660ef882899b16b2"
143screensSButton2ID = "b10a959313edf31aa004faffcf905256"
144screensSButton3ID = "f2ca3bcbb6f6febcb3d73236ff285fb5"
145screensSDDMenuID = "a2f436771da5644c27a39d73b57fd29c"
146screensSMsgID = "b823cc4d92c1748967586c2878967248"
147
148elementsSID = "0ce4a8f25a81d19b9abf7cfcbd450a4d"
149elementsSHeadingID = "f34a17e23d41cffa1b9fbd6a33cd4f71"
150elementsSButton1ID = "c8a2c4a1a569bc97d659707bc42539fe"
151elementsSButton2ID = "650a9aef06bb8e99389773a9fd6ec2cd"
152elementsSDDMenu1ID = "bc9fc4bada884c28114d4bfb1783b8c7"
153elementsSDDMenu2ID = "030bbbca3d6cf0847f87feda6bf6a783"
154
155editorSID = "ba0832bc2dcb0adcf14b490ac6be2065"
156editorSElementID = nil
157editorSElementType = nil
158editorSElementX = nil
159editorSElementY = nil
160editorSRelocateButtonID = "ca5d5014d000faa233f4c58909e9ea21"
161editorSLastSaveID = "70461177a186553350dbb333d5b2cde2"
162editorSExitID = "99f1eb11c00f5c188844a7311c879bac"
163editorSUndoID = "0f7132a19e8760f425c2eef5b386cc61"
164editorSRedoID = "fe21a08c7dffa4717d24593f7fcd0a0e"
165editorSPropsID = "e46d61c144903147e4cb5f136a0fecb8"
166editorSPropsMenuID = "cbf856355edab7b830d36dec09857e0d"
167editorSDescID = "06431f84d6b74e6796e52341a882e9a5"
168editorSHideUIID = "ad4e5a2c6c8b4995893cec8cd4e2f219"
169editorSPropColorPickID = "25c276460958a39672b08d75baf86b4d"
170editorSPropResetButtonID = "6c04474a36beb72d7659bb0be1a07753"
171editorSPropDDMenuID = "0603d9ac23d75d560d24cf76b2321882"
172editorSPropDisplayID = "43c8ab35bc70361a89080b0e6c8d0dcc"
173editorSPropConsoleInputButtonID = "48066d14f326e44bc285eacea5953c53"
174editorSPropConsoleMsgID = "253177a56e1e679a671650ff660ac628"
175editorSPropColorsArrayDDID = "f786c674209bc58c63be21a9973a36a7"
176editorSPropStringArrayDDID = "873ab20d4a621beb75c4a288aafc4d9b"
177editorSPropNavMenuID = "1a8bf4cb11854ddc7070fa988b6bd061"
178editorSPropNavMenuHintID = "5e192f2543b2955606ea876e5a0f5061"
179editorSPropCSTableIndexDDID = "c0db47af6a31df0c8b5d6d93528e8789"
180editorSPropCSTableDDID = "285065eb94ad1d28cc4256b2ba90313e"
181editorSPropCSChangeID = "69280395cc41074df3a851bd35dae7eb"
182editorSPropCSRemoveID = "947a332a5fd6e2f12cdee783584d7b2f"
183editorSPropCSDesignsIndexDDID = "6cc418ef452522709716091a3fee13b4"
184editorSPropCSDesignsDDID = "dcf4b18661fa3189e028cc5b9e3bb091"
185editorSPropCSDesignsDisplayID = "a911bd54fc2a722273349b86b7ba7e5b"
186editorSPropPicEditButtonID = "d4baa6b9a4165cd060adf01ac06413c1"
187
188pictureESID = "8c62478c73d841127d5cfee2ca0057f5"
189pictureESCurrentX = 1
190pictureESCurrentY = 1
191pictureESButtonBackID = "2b0706da3b5d426fa94dc2f8296b3163"
192pictureESCoordsDisplayID = "badf495b60b2dfbf16a6505fc5a6abea"
193pictureESControlPicID = "8e30ae73df15a61c5031fbb303d0aacb"
194pictureESIndicatorID = "eedc3c41696a69f23da0afaa26966886"
195pictureESChangeID = "6fa7bc313ff09ed5ffe3a03eabd9f023"
196pictureESColorPick1ID = "b35a1604be58560bed010a10814b9e96"
197pictureESColorPick2ID = "f21f6272bc5b1fde77e1fae2b81a8cd2"
198pictureESUseDefault1ID = "544eede5770aab86e04abe55a69df30e"
199pictureESUseDefault2ID = "6ecb339249a0d6fc15345a3a9678d801"
200pictureESTransparentID = "2273d20c36018b7d17dc3c2986581939"
201
202newScreenSID = "4c87e69acef20548469e1739e668a0b2"
203newScreenSHeadingID = "d3b18e12b96639b9185abb60ba990ddb"
204newScreenSTextID = "8413e43f729eccce6ae5ec696b90dbda"
205newScreenSDDM1ID = "5febc01add087220c728a65579e148f3"
206newScreenSDDM2ID = "e5cc2beacfc426487c711c85deb2015d"
207newScreenSDDM3ID = "1f2fae049f3e7a22afd512769a7b171d"
208newScreenSResultID = "bbdc5855b127608208219ecc1a275978"
209newScreenSColor1ID = "d43e48d259cd4baa3c209f590f912cbf"
210newScreenSColor2ID = "0acbe4f69fa595fd123d03ad834cc50d"
211
212designerSID = nil
213designerSExitButtonID = "1d3b801e5d4f2c7226492cf2a66f9ebd"
214designerSHideUIID = "9818d56316ad57a0567c4076c26ae597"
215designerSControlPicID = "71e90f74303d96e10277d15591add23e"
216designerSSelectionID = "31cf20d5dd112d373b987ca97d7bec60"
217designerSAddID = "ebd3455e1d4cb26e3880b7ef5963ef55"
218designerSRemoveID = "2a2abf50f7ca26032ee56471ead9ed46"
219designerSIndicatorID = "61a218bc9eadf687b5218d580c99d1c7"
220designerSLastSaveID = "5d7d14cce74cf0f0506a47557b2c49b7"
221designerSSelection = ""
222designerSmaxX = nil
223designerSmaxY = nil
224designerSBox1ID = "d0dca4a2df75fbc538d26bf55f838068"
225designerSBox2ID = "dd5bd01b51b9dae60c4908954a25da05"
226designerSUndoID = "b690378913463294bc11c499bf032798"
227designerSRedoID = "25d97fd89146fa2a0378577fea852434"
228designerRefresh = false
229designerSButtonHeld = false
230
231undoRedoTable = {}
232undoRedoIndex = 0
233
234--property tables
235--width, height, content, variables, textColor, textAlignmentHorizontal, textAlignmentVertical, BGColor, borderColor, onActiveFunction, onInactiveFunction, onClickMode, activeDuration, activeContent, activeTextColor, activeBGColor, activeBorderColor, borderThickness, active, timerID, visible, enabled
236dynamicTextBoxProperties = {}
237dynamicTextBoxProperties["content"] = {}
238dynamicTextBoxProperties["content"]["input"] = "string"
239dynamicTextBoxProperties["content"]["essential"] = true
240dynamicTextBoxProperties["content"]["desc"] = "content (string): the text inside the dynamicTextBox. It automatically splits the text into different lines if necessary. Can also be an empty string."
241dynamicTextBoxProperties["content"]["default"] = "Your Text"
242
243dynamicTextBoxProperties["width"] = {}
244dynamicTextBoxProperties["width"]["input"] = "number"
245dynamicTextBoxProperties["width"]["essential"] = false
246dynamicTextBoxProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide (x) the element should be. If unused (nil) the dynamicTextBox will take the space the text requires, but never run over the edge of the screen."
247
248dynamicTextBoxProperties["height"] = {}
249dynamicTextBoxProperties["height"]["input"] = "number"
250dynamicTextBoxProperties["height"]["essential"] = false
251dynamicTextBoxProperties["height"]["desc"] = "height (non-decimal number in pixels): how broad (y) the element should be. If unused (nil) the dynamicTextBox will take the space the text requires, but never run over the edge of the screen."
252
253dynamicTextBoxProperties["variables"] = {}
254dynamicTextBoxProperties["variables"]["input"] = "manual"
255dynamicTextBoxProperties["variables"]["essential"] = false
256dynamicTextBoxProperties["variables"]["desc"] = "variables (table): can be used thus: variables[\"name\"] = retrieveVarFunc, then put &name somewhere in content. Can only be set manually. (EasyGUI.changeProperty(ID,\"variables\",table))"
257
258dynamicTextBoxProperties["textColor"] = {}
259dynamicTextBoxProperties["textColor"]["input"] = "color"
260dynamicTextBoxProperties["textColor"]["essential"] = false
261dynamicTextBoxProperties["textColor"]["desc"] = "textColor (color): color of the text inside the dynamicTextBox. If unused (nil) defaultTextColor of the screen will be used."
262
263dynamicTextBoxProperties["BGColor"] = {}
264dynamicTextBoxProperties["BGColor"]["input"] = "color"
265dynamicTextBoxProperties["BGColor"]["essential"] = false
266dynamicTextBoxProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dynamicTextBox. If unused (nil) defaultBGColor of the screen will be used."
267
268dynamicTextBoxProperties["borderColor"] = {}
269dynamicTextBoxProperties["borderColor"]["input"] = "color"
270dynamicTextBoxProperties["borderColor"]["essential"] = false
271dynamicTextBoxProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the dynamicTextBox. borderThickness needs to be greater than 0. If unused (nil) BGColor will be used."
272
273dynamicTextBoxProperties["activeContent"] = {}
274dynamicTextBoxProperties["activeContent"]["input"] = "string"
275dynamicTextBoxProperties["activeContent"]["essential"] = false
276dynamicTextBoxProperties["activeContent"]["desc"] = "activeContent (string): the text inside the dynamicTextBox if it's active. It automatically splits the text into different lines if necessary. Can also be an empty string. If unused (nil) will be content."
277
278dynamicTextBoxProperties["activeTextColor"] = {}
279dynamicTextBoxProperties["activeTextColor"]["input"] = "color"
280dynamicTextBoxProperties["activeTextColor"]["essential"] = false
281dynamicTextBoxProperties["activeTextColor"]["desc"] = "activeTextColor (color): color of the text inside the dynamicTextBox if it's active. If unused (nil) textColor will be used."
282
283dynamicTextBoxProperties["activeBGColor"] = {}
284dynamicTextBoxProperties["activeBGColor"]["input"] = "color"
285dynamicTextBoxProperties["activeBGColor"]["essential"] = false
286dynamicTextBoxProperties["activeBGColor"]["desc"] = "activeBGColor (color): color of background of the dynamicTextBox if it's active. If unused (nil) BGColor will be used."
287
288dynamicTextBoxProperties["activeBorderColor"] = {}
289dynamicTextBoxProperties["activeBorderColor"]["input"] = "color"
290dynamicTextBoxProperties["activeBorderColor"]["essential"] = false
291dynamicTextBoxProperties["activeBorderColor"]["desc"] = "activeBorderColor (color): color of the border of the dynamicTextBox if it's active. borderThickness needs to be greater then 0. If unused (nil) borderColor will be used."
292
293dynamicTextBoxProperties["textAlignmentHorizontal"] = {}
294dynamicTextBoxProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
295dynamicTextBoxProperties["textAlignmentHorizontal"]["essential"] = false
296dynamicTextBoxProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside the dynamicTextBox shall be placed horizontally. If unused (nil) defaults to center."
297
298dynamicTextBoxProperties["textAlignmentVertical"] = {}
299dynamicTextBoxProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
300dynamicTextBoxProperties["textAlignmentVertical"]["essential"] = false
301dynamicTextBoxProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside the dynamicTextBox shall be placed vertically. If unused (nil) defaults to center."
302
303dynamicTextBoxProperties["borderThickness"] = {}
304dynamicTextBoxProperties["borderThickness"]["input"] = "number"
305dynamicTextBoxProperties["borderThickness"]["essential"] = false
306dynamicTextBoxProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the dynamicTextBox shall be. If unused (nil) will be 0. (no border)"
307
308dynamicTextBoxProperties["onClickMode"] = {}
309dynamicTextBoxProperties["onClickMode"]["input"] = "DDM:flash:toggle"
310dynamicTextBoxProperties["onClickMode"]["essential"] = false
311dynamicTextBoxProperties["onClickMode"]["desc"] = "onClickMode (flash,toggle): whether the dynamicTextBox if clicked shall stay active until the next click (toggle) or turn inactive again after a specific amount of time. (flash) Also set activeDuration if using the second option."
312
313dynamicTextBoxProperties["activeDuration"] = {}
314dynamicTextBoxProperties["activeDuration"]["input"] = "decimal"
315dynamicTextBoxProperties["activeDuration"]["essential"] = false
316dynamicTextBoxProperties["activeDuration"]["desc"] = "activeDuration (decimal number in seconds): if onClickMode is set to flash, this value determines how long the dynamicTextBox stays active after clicked. Can only be as accurate as 1 in-game tick or 0.05s. If unused (nil) will be 0.05."
317
318dynamicTextBoxProperties["onActiveFunction"] = {}
319dynamicTextBoxProperties["onActiveFunction"]["input"] = "manual"
320dynamicTextBoxProperties["onActiveFunction"]["essential"] = false
321dynamicTextBoxProperties["onActiveFunction"]["desc"] = "onActiveFunction (function): to be called when the dynamicTextBox becomes active through a click. Can only be set manually. (EasyGUI.changeProperty(ID,\"onActiveFunction\",func)) Will be called with two arguments: ID of element (string), whether it's active (boolean)"
322
323dynamicTextBoxProperties["onInactiveFunction"] = {}
324dynamicTextBoxProperties["onInactiveFunction"]["input"] = "manual"
325dynamicTextBoxProperties["onInactiveFunction"]["essential"] = false
326dynamicTextBoxProperties["onInactiveFunction"]["desc"] = "onInactiveFunction (function): to be called when the dynamicTextBox becomes inactive through a click or when activeDuration has passed. Can only be set manually. (EasyGUI.changeProperty(ID,\"onInactiveFunction\",func)) Will be called with two arguments: ID of element (string), whether it's active (boolean)"
327
328--length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
329sliderProperties = {}
330sliderProperties["length"] = {}
331sliderProperties["length"]["input"] = "number"
332sliderProperties["length"]["essential"] = true
333sliderProperties["length"]["desc"] = "length (number): the maximum value the slider shall take on. Not necessarily the length in pixels, for more info see pixelsPerUnit."
334sliderProperties["length"]["default"] = 5
335
336sliderProperties["value"] = {}
337sliderProperties["value"]["input"] = "number"
338sliderProperties["value"]["essential"] = true
339sliderProperties["value"]["desc"] = "value (number): the default value the slider shall take on."
340sliderProperties["value"]["default"] = 1
341
342sliderProperties["broadness"] = {}
343sliderProperties["broadness"]["input"] = "number"
344sliderProperties["broadness"]["essential"] = false
345sliderProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the slider shall be. Perpendicular to slider orientation. If unused (nil) will be 1."
346
347sliderProperties["pixelsPerUnit"] = {}
348sliderProperties["pixelsPerUnit"]["input"] = "number"
349sliderProperties["pixelsPerUnit"]["essential"] = false
350sliderProperties["pixelsPerUnit"]["desc"] = "pixelsPerUnit (non-decimal number in pixels): how many pixels one unit of the slider shall take up. If unused (nil) will be 1."
351
352sliderProperties["orientation"] = {}
353sliderProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
354sliderProperties["orientation"]["essential"] = false
355sliderProperties["orientation"]["desc"] = "orientation (top-bottom,bottom-top,left-right,right-left): how the slider shall be oriented. 'start-end'. If unused (nil) will be left-right."
356
357sliderProperties["color"] = {}
358sliderProperties["color"]["input"] = "color"
359sliderProperties["color"]["essential"] = false
360sliderProperties["color"]["desc"] = "color (color): the color the bar of the slider shall take on. If unused (nil) will be the defaultTextColor of the screen."
361
362sliderProperties["BGColor"] = {}
363sliderProperties["BGColor"]["input"] = "color"
364sliderProperties["BGColor"]["essential"] = false
365sliderProperties["BGColor"]["desc"] = "BGColor (color): the background of the slider. If unused (nil) will be the defaultBGColor of the screen."
366
367sliderProperties["borderColor"] = {}
368sliderProperties["borderColor"]["input"] = "color"
369sliderProperties["borderColor"]["essential"] = false
370sliderProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the slider. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
371
372sliderProperties["borderThickness"] = {}
373sliderProperties["borderThickness"]["input"] = "number"
374sliderProperties["borderThickness"]["essential"] = false
375sliderProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the slider shall be. If unused (nil) will be 0. (no border)"
376
377sliderProperties["colorsArray"] = {}
378sliderProperties["colorsArray"]["input"] = "colorsArray"
379sliderProperties["colorsArray"]["essential"] = false
380sliderProperties["colorsArray"]["desc"] = "colorsArray (numerically-indexed table): this can be used if you want a different bar color for different values. Example: red for high values and green for low values."
381
382sliderProperties["mode"] = {}
383sliderProperties["mode"]["input"] = "DDM:fill:value"
384sliderProperties["mode"]["essential"] = false
385sliderProperties["mode"]["desc"] = "mode (fill,value): whether the slider shall be filled up to the current value (fill) or only display the current value (value). If unused (nil) will be fill."
386
387sliderProperties["textPosition"] = {}
388sliderProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
389sliderProperties["textPosition"]["essential"] = false
390sliderProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
391
392sliderProperties["textMargin"] = {}
393sliderProperties["textMargin"]["input"] = "number"
394sliderProperties["textMargin"]["essential"] = false
395sliderProperties["textMargin"]["desc"] = "textMargin (non-decimal number in pixels): determines how many pixels away from the slider the value will be placed. Requires textPosition to be set. If unused (nil) will be 0."
396
397sliderProperties["changeButtons"] = {}
398sliderProperties["changeButtons"]["input"] = "string"
399sliderProperties["changeButtons"]["essential"] = false
400sliderProperties["changeButtons"]["desc"] = "changeButtons (2 characters): if set draws an increment button with the first character and a decrement button with the second character. Example: '+-'"
401
402sliderProperties["onChangeFunction"] = {}
403sliderProperties["onChangeFunction"]["input"] = "manual"
404sliderProperties["onChangeFunction"]["essential"] = false
405sliderProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the value of the slider changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), current value (number)"
406
407--entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
408dropDownMenuProperties = {}
409dropDownMenuProperties["entries"] = {}
410dropDownMenuProperties["entries"]["input"] = "stringArray"
411dropDownMenuProperties["entries"]["essential"] = true
412dropDownMenuProperties["entries"]["desc"] = "entries (numerically indexed table): all entries of the dropDownMenu."
413dropDownMenuProperties["entries"]["default"] = {"Entry 1","Entry 2","Entry 3"}
414
415dropDownMenuProperties["selectionID"] = {}
416dropDownMenuProperties["selectionID"]["input"] = "number"
417dropDownMenuProperties["selectionID"]["essential"] = true
418dropDownMenuProperties["selectionID"]["desc"] = "selectionID (non-decimal number): by default selected entry of dropDownMenu."
419dropDownMenuProperties["selectionID"]["default"] = 1
420
421dropDownMenuProperties["width"] = {}
422dropDownMenuProperties["width"]["input"] = "number"
423dropDownMenuProperties["width"]["essential"] = false
424dropDownMenuProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide (x) the dropDownMenu shall be. Text will be shortened accordingly. If unused (nil) takes as much space as necessary but will not run over the edge of the screen."
425
426dropDownMenuProperties["expandedMaxHeight"] = {}
427dropDownMenuProperties["expandedMaxHeight"]["input"] = "number"
428dropDownMenuProperties["expandedMaxHeight"]["essential"] = false
429dropDownMenuProperties["expandedMaxHeight"]["desc"] = "expandedMaxHeight (non-decimal number in pixels): the maximum height of the dropDownMenu in its expanded state. Adds a scroll feature if necessary. If unused (nil) takes as much space as necessary but will not run over the edge of the screen."
430
431dropDownMenuProperties["textColor"] = {}
432dropDownMenuProperties["textColor"]["input"] = "color"
433dropDownMenuProperties["textColor"]["essential"] = false
434dropDownMenuProperties["textColor"]["desc"] = "textColor (color): color of the text of the entries. If unused (nil) defaultTextColor of the screen will be used."
435
436dropDownMenuProperties["BGColor"] = {}
437dropDownMenuProperties["BGColor"]["input"] = "color"
438dropDownMenuProperties["BGColor"]["essential"] = false
439dropDownMenuProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dropDownMenu. If unused (nil) defaultBGColor of the screen will be used."
440
441dropDownMenuProperties["borderColor"] = {}
442dropDownMenuProperties["borderColor"]["input"] = "color"
443dropDownMenuProperties["borderColor"]["essential"] = false
444dropDownMenuProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the dropDownMenu. borderThickness needs to be greater than 0. If unused (nil) BGColor will be used."
445
446dropDownMenuProperties["highlightTextColor"] = {}
447dropDownMenuProperties["highlightTextColor"]["input"] = "color"
448dropDownMenuProperties["highlightTextColor"]["essential"] = false
449dropDownMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of the highlighted entry. If unused (nil) textColor will be used."
450
451dropDownMenuProperties["highlightBGColor"] = {}
452dropDownMenuProperties["highlightBGColor"]["input"] = "color"
453dropDownMenuProperties["highlightBGColor"]["essential"] = false
454dropDownMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of background of the highlighted entry. If unused (nil) BGColor will be used."
455
456dropDownMenuProperties["buttonsColor"] = {}
457dropDownMenuProperties["buttonsColor"]["input"] = "color"
458dropDownMenuProperties["buttonsColor"]["essential"] = false
459dropDownMenuProperties["buttonsColor"]["desc"] = "buttonsColor (color): textColor of expand/collapse/scroll buttons. If unused (nil) textColor will be used."
460
461dropDownMenuProperties["buttonsBGColor"] = {}
462dropDownMenuProperties["buttonsBGColor"]["input"] = "color"
463dropDownMenuProperties["buttonsBGColor"]["essential"] = false
464dropDownMenuProperties["buttonsBGColor"]["desc"] = "buttonsBGColor (color): BGColor of expand/collapse/scroll buttons. If unused (nil) BGColor will be used."
465
466dropDownMenuProperties["borderThickness"] = {}
467dropDownMenuProperties["borderThickness"]["input"] = "number"
468dropDownMenuProperties["borderThickness"]["essential"] = false
469dropDownMenuProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the dropDownMenu shall be. If unused (nil) will be 0. (no border)"
470
471dropDownMenuProperties["onChangeFunction"] = {}
472dropDownMenuProperties["onChangeFunction"]["input"] = "manual"
473dropDownMenuProperties["onChangeFunction"]["essential"] = false
474dropDownMenuProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the dropDownMenu changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), current selection (number)"
475
476dropDownMenuProperties["onExpandFunction"] = {}
477dropDownMenuProperties["onExpandFunction"]["input"] = "manual"
478dropDownMenuProperties["onExpandFunction"]["essential"] = false
479dropDownMenuProperties["onExpandFunction"]["desc"] = "onExpandFunction (function): to be called if the dropDownMenu expands through a click event. Can only be set manually. (EasyGUI.ExpandProperty(ID,\"onExpandFunction\",func)) Will be called with two arguments: ID of element (string), whether it's expanded (boolean)"
480
481dropDownMenuProperties["onCollapseFunction"] = {}
482dropDownMenuProperties["onCollapseFunction"]["input"] = "manual"
483dropDownMenuProperties["onCollapseFunction"]["essential"] = false
484dropDownMenuProperties["onCollapseFunction"]["desc"] = "onCollapseFunction (function): to be called if the dropDownMenu collapses through a click event. Can only be set manually. (EasyGUI.CollapseProperty(ID,\"onCollapseFunction\",func)) Will be called with two arguments: ID of element (string), whether it's expanded (boolean)"
485
486--title,menuArray (text, submenu),titleTextColor,titleBGColor,titleTextColorExpanded,titleBGColorExpanded,textAlignmentHorizontal,textAlignmentVertical,entryWidth,entryHeight,entryTextColor,entryBGColor,borderColor,spaceBetweenEntries,borderThickness,highlightTextColor,highlightBGColor,expanded,highlightIDs,onChangeFunction,enabled,visible
487navigationMenuProperties = {}
488navigationMenuProperties["title"] = {}
489navigationMenuProperties["title"]["input"] = "string"
490navigationMenuProperties["title"]["essential"] = true
491navigationMenuProperties["title"]["desc"] = "title (string): the text of the title of the navigationMenu. Also displayed when the menu is collapsed."
492navigationMenuProperties["title"]["default"] = "Menu"
493
494navigationMenuProperties["menuArray"] = {}
495navigationMenuProperties["menuArray"]["input"] = "navMenuArray"
496navigationMenuProperties["menuArray"]["essential"] = true
497navigationMenuProperties["menuArray"]["desc"] = "menuArray (numerically indexed nested table): all entries of the navigationMenu with submenus if necessary. Structure: array[index]={[\"text\"]=\"text\",[\"submenu\"]=anotherMenuArray}"
498navigationMenuProperties["menuArray"]["default"] = {{["text"]="Entry 1"},{["text"]="Entry 2"},{["text"]="Entry 3"}}
499
500navigationMenuProperties["titleTextColor"] = {}
501navigationMenuProperties["titleTextColor"]["input"] = "color"
502navigationMenuProperties["titleTextColor"]["essential"] = false
503navigationMenuProperties["titleTextColor"]["desc"] = "titleTextColor (color): color of the text of title. If unused (nil) defaultTextColor of the screen will be used."
504
505navigationMenuProperties["titleBGColor"] = {}
506navigationMenuProperties["titleBGColor"]["input"] = "color"
507navigationMenuProperties["titleBGColor"]["essential"] = false
508navigationMenuProperties["titleBGColor"]["desc"] = "titleBGColor (color): color of the background of title. If unused (nil) defaultBGColor of the screen will be used."
509
510navigationMenuProperties["titleTextColorExpanded"] = {}
511navigationMenuProperties["titleTextColorExpanded"]["input"] = "color"
512navigationMenuProperties["titleTextColorExpanded"]["essential"] = false
513navigationMenuProperties["titleTextColorExpanded"]["desc"] = "titleTextColor (color): color of the text of title when menu is expanded. If unused (nil) titleTextColor will be used."
514
515navigationMenuProperties["titleBGColorExpanded"] = {}
516navigationMenuProperties["titleBGColorExpanded"]["input"] = "color"
517navigationMenuProperties["titleBGColorExpanded"]["essential"] = false
518navigationMenuProperties["titleBGColorExpanded"]["desc"] = "titleBGColor (color): color of the background of title when menu is expanded. If unused (nil) titleBGColor will be used."
519
520navigationMenuProperties["borderColor"] = {}
521navigationMenuProperties["borderColor"]["input"] = "color"
522navigationMenuProperties["borderColor"]["essential"] = false
523navigationMenuProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the navigationMenu. borderThickness needs to be greater than 0. If unused (nil) defaultBGColor of the screen will be used."
524
525navigationMenuProperties["entryTextColor"] = {}
526navigationMenuProperties["entryTextColor"]["input"] = "color"
527navigationMenuProperties["entryTextColor"]["essential"] = false
528navigationMenuProperties["entryTextColor"]["desc"] = "entryTextColor (color): color of the text of the entries of the expanded menu. If unused (nil) defaultTextColor of the screen will be used."
529
530navigationMenuProperties["entryBGColor"] = {}
531navigationMenuProperties["entryBGColor"]["input"] = "color"
532navigationMenuProperties["entryBGColor"]["essential"] = false
533navigationMenuProperties["entryBGColor"]["desc"] = "entryBGColor (color): color of the background of the entries of the expanded menu. If unused (nil) defaultBGColor of the screen will be used."
534
535navigationMenuProperties["highlightTextColor"] = {}
536navigationMenuProperties["highlightTextColor"]["input"] = "color"
537navigationMenuProperties["highlightTextColor"]["essential"] = false
538navigationMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of a highlighted entry of the expanded menu. If unused (nil) entryTextColor will be used."
539
540navigationMenuProperties["highlightBGColor"] = {}
541navigationMenuProperties["highlightBGColor"]["input"] = "color"
542navigationMenuProperties["highlightBGColor"]["essential"] = false
543navigationMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of the background of a highlighted entry of the expanded menu. If unused (nil) entryBGColor will be used."
544
545navigationMenuProperties["entryWidth"] = {}
546navigationMenuProperties["entryWidth"]["input"] = "number"
547navigationMenuProperties["entryWidth"]["essential"] = false
548navigationMenuProperties["entryWidth"]["desc"] = "entryWidth (non-decimal number in pixels): how wide (x) every entry shall be including submenus. If unused (nil) will take as much space as needed."
549
550navigationMenuProperties["entryHeight"] = {}
551navigationMenuProperties["entryHeight"]["input"] = "number"
552navigationMenuProperties["entryHeight"]["essential"] = false
553navigationMenuProperties["entryHeight"]["desc"] = "entryHeight (non-decimal number in pixels): how broad (y) every entry shall be including submenus. If unused (nil) will be 1."
554
555navigationMenuProperties["textAlignmentHorizontal"] = {}
556navigationMenuProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
557navigationMenuProperties["textAlignmentHorizontal"]["essential"] = false
558navigationMenuProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside every entry including submenus shall be placed horizontally. If unused (nil) defaults to center."
559
560navigationMenuProperties["textAlignmentVertical"] = {}
561navigationMenuProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
562navigationMenuProperties["textAlignmentVertical"]["essential"] = false
563navigationMenuProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside every entry including submenus shall be placed vertically. If unused (nil) defaults to center."
564
565navigationMenuProperties["borderThickness"] = {}
566navigationMenuProperties["borderThickness"]["input"] = "number"
567navigationMenuProperties["borderThickness"]["essential"] = false
568navigationMenuProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the navigationMenu shall be. If unused (nil) will be 0. (no border)"
569
570navigationMenuProperties["spaceBetweenEntries"] = {}
571navigationMenuProperties["spaceBetweenEntries"]["input"] = "number"
572navigationMenuProperties["spaceBetweenEntries"]["essential"] = false
573navigationMenuProperties["spaceBetweenEntries"]["desc"] = "spaceBetweenEntries (non-decimal number in pixels): broadness (y) of a line to be placed between entries for separation. If unused (nil) will be 0. (no spaces)"
574
575navigationMenuProperties["onChangeFunction"] = {}
576navigationMenuProperties["onChangeFunction"]["input"] = "manual"
577navigationMenuProperties["onChangeFunction"]["essential"] = false
578navigationMenuProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the navigationMenu changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), selections of all submenus before menu closed. (number array)"
579
580--selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
581colorPickerProperties = {}
582colorPickerProperties["selection"] = {}
583colorPickerProperties["selection"]["input"] = "color"
584colorPickerProperties["selection"]["essential"] = false
585colorPickerProperties["selection"]["desc"] = "selection (color): by default selected color."
586
587colorPickerProperties["borderColor"] = {}
588colorPickerProperties["borderColor"]["input"] = "color"
589colorPickerProperties["borderColor"]["essential"] = false
590colorPickerProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the colorPicker. borderThickness needs to be greater than 0. If unused (nil) defaultBGColor of the screen will be used."
591
592colorPickerProperties["borderThickness"] = {}
593colorPickerProperties["borderThickness"]["input"] = "number"
594colorPickerProperties["borderThickness"]["essential"] = false
595colorPickerProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the colorPicker shall be. If unused (nil) will be 0. (no border)"
596
597colorPickerProperties["colorWidth"] = {}
598colorPickerProperties["colorWidth"]["input"] = "number"
599colorPickerProperties["colorWidth"]["essential"] = false
600colorPickerProperties["colorWidth"]["desc"] = "colorWidth (non-decimal number in pixels): how wide (x) every color shall be. If unused (nil) will be 1."
601
602colorPickerProperties["colorHeight"] = {}
603colorPickerProperties["colorHeight"]["input"] = "number"
604colorPickerProperties["colorHeight"]["essential"] = false
605colorPickerProperties["colorHeight"]["desc"] = "colorHeight (non-decimal number in pixels): how broad (y) every color shall be. If unused (nil) will be 1."
606
607colorPickerProperties["selectionCharacter"] = {}
608colorPickerProperties["selectionCharacter"]["input"] = "string"
609colorPickerProperties["selectionCharacter"]["essential"] = false
610colorPickerProperties["selectionCharacter"]["desc"] = "selectionCharacter (1 character): the character which shall indicate the currently selected color. If unused will be X."
611
612colorPickerProperties["onChangeFunction"] = {}
613colorPickerProperties["onChangeFunction"]["input"] = "manual"
614colorPickerProperties["onChangeFunction"]["essential"] = false
615colorPickerProperties["onChangeFunction"]["desc"] = "onChangeFunction (function): to be called if the selection of the colorPicker changes through a click event. Can only be set manually. (EasyGUI.changeProperty(ID,\"onChangeFunction\",func)) Will be called with two arguments: ID of element (string), selected color. (color)"
616
617--length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
618progressBarProperties = {}
619progressBarProperties["length"] = {}
620progressBarProperties["length"]["input"] = "number"
621progressBarProperties["length"]["essential"] = true
622progressBarProperties["length"]["desc"] = "length (non-decimal number in pixels): the length of the progressBar."
623progressBarProperties["length"]["default"] = 5
624
625progressBarProperties["value"] = {}
626progressBarProperties["value"]["input"] = "number"
627progressBarProperties["value"]["essential"] = false
628progressBarProperties["value"]["desc"] = "value (non-decimal number): the default value the progressBar shall take on, either in percent or absolute, see valueType. Defaults to 0."
629
630progressBarProperties["valueType"] = {}
631progressBarProperties["valueType"]["input"] = "DDM:relative:absolute"
632progressBarProperties["valueType"]["essential"] = false
633progressBarProperties["valueType"]["desc"] = "valueType (relative,absolute): whether value shall be an absolute value or a percentage. Defaults to absolute."
634
635progressBarProperties["color"] = {}
636progressBarProperties["color"]["input"] = "color"
637progressBarProperties["color"]["essential"] = false
638progressBarProperties["color"]["desc"] = "color (color): the color the bar of the progressBar shall take on. If unused (nil) will be the defaultTextColor of the screen."
639
640progressBarProperties["BGColor"] = {}
641progressBarProperties["BGColor"]["input"] = "color"
642progressBarProperties["BGColor"]["essential"] = false
643progressBarProperties["BGColor"]["desc"] = "BGColor (color): the background of the progressBar. If unused (nil) will be the defaultBGColor of the screen."
644
645progressBarProperties["borderColor"] = {}
646progressBarProperties["borderColor"]["input"] = "color"
647progressBarProperties["borderColor"]["essential"] = false
648progressBarProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the progressBar. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
649
650progressBarProperties["borderThickness"] = {}
651progressBarProperties["borderThickness"]["input"] = "number"
652progressBarProperties["borderThickness"]["essential"] = false
653progressBarProperties["borderThickness"]["desc"] = "borderThickness (non-decimal number in pixels): how thick the border of the progressBar shall be. If unused (nil) will be 0. (no border)"
654
655progressBarProperties["colorsArray"] = {}
656progressBarProperties["colorsArray"]["input"] = "colorsArray"
657progressBarProperties["colorsArray"]["essential"] = false
658progressBarProperties["colorsArray"]["desc"] = "colorsArray (numerically-indexed table): this can be used if you want a different bar color for different values. Example: red for high values and green for low values."
659
660progressBarProperties["broadness"] = {}
661progressBarProperties["broadness"]["input"] = "number"
662progressBarProperties["broadness"]["essential"] = false
663progressBarProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the progressBar shall be. Perpendicular to progressBar orientation. If unused (nil) will be 1."
664
665progressBarProperties["orientation"] = {}
666progressBarProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
667progressBarProperties["orientation"]["essential"] = false
668progressBarProperties["orientation"]["desc"] = "orientation (top-bottom,bottom-top,left-right,right-left): how the progressBar shall be oriented. 'start-end'. If unused (nil) will be left-right."
669
670progressBarProperties["textPosition"] = {}
671progressBarProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
672progressBarProperties["textPosition"]["essential"] = false
673progressBarProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
674
675progressBarProperties["textMargin"] = {}
676progressBarProperties["textMargin"]["input"] = "number"
677progressBarProperties["textMargin"]["essential"] = false
678progressBarProperties["textMargin"]["desc"] = "textMargin (non-decimal number in pixels): determines how many pixels away from the progressBar the value will be placed. Requires textPosition to be set. If unused (nil) will be 0."
679
680--width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepX,stepY
681coordinateSystemProperties = {}
682coordinateSystemProperties["width"] = {}
683coordinateSystemProperties["width"]["input"] = "number"
684coordinateSystemProperties["width"]["essential"] = true
685coordinateSystemProperties["width"]["desc"] = "width (non-decimal number in pixels): how long the x axis shall be."
686coordinateSystemProperties["width"]["default"] = 10
687
688coordinateSystemProperties["height"] = {}
689coordinateSystemProperties["height"]["input"] = "number"
690coordinateSystemProperties["height"]["essential"] = true
691coordinateSystemProperties["height"]["desc"] = "height (non-decimal number in pixels): how long the y axis shall be."
692coordinateSystemProperties["height"]["default"] = 10
693
694coordinateSystemProperties["graphTables"] = {}
695coordinateSystemProperties["graphTables"]["input"] = "CSTable"
696coordinateSystemProperties["graphTables"]["essential"] = false
697coordinateSystemProperties["graphTables"]["desc"] = "graphTables (numerically-indexed nested table) all graphs to be displayed. Structure: array[index]={[x]=y}"
698
699coordinateSystemProperties["graphDesigns"] = {}
700coordinateSystemProperties["graphDesigns"]["input"] = "CSDesignsTable"
701coordinateSystemProperties["graphDesigns"]["essential"] = false
702coordinateSystemProperties["graphDesigns"]["desc"] = "graphDesigns (numerically-indexed nested table): each graph can have a different display character, color and background color, stored in this table. Structure: array[index]={[\"character\"]=\"x\",[\"color\"]=color,[\"BGColor\"]=BGColor}"
703
704coordinateSystemProperties["numbersColor"] = {}
705coordinateSystemProperties["numbersColor"]["input"] = "color"
706coordinateSystemProperties["numbersColor"]["essential"] = false
707coordinateSystemProperties["numbersColor"]["desc"] = "numbersColor (color): color of the numbers next to the axes. If unused (nil) will be defaultTextColor of the screen."
708
709coordinateSystemProperties["axesColor"] = {}
710coordinateSystemProperties["axesColor"]["input"] = "color"
711coordinateSystemProperties["axesColor"]["essential"] = false
712coordinateSystemProperties["axesColor"]["desc"] = "axesColor (color): color of the axes. If unused (nil) will be defaultTextColor of the screen."
713
714coordinateSystemProperties["unitsPerPixelX"] = {}
715coordinateSystemProperties["unitsPerPixelX"]["input"] = "decimal"
716coordinateSystemProperties["unitsPerPixelX"]["essential"] = false
717coordinateSystemProperties["unitsPerPixelX"]["desc"] = "unitsPerPixelX (decimal number): how many units one pixel equals on the x axis. If unused (nil) will be 1."
718
719coordinateSystemProperties["unitsPerPixelY"] = {}
720coordinateSystemProperties["unitsPerPixelY"]["input"] = "decimal"
721coordinateSystemProperties["unitsPerPixelY"]["essential"] = false
722coordinateSystemProperties["unitsPerPixelY"]["desc"] = "unitsPerPixelY (decimal number): how many units one pixel equals on the y axis. If unused (nil) will be 1."
723
724coordinateSystemProperties["labelX"] = {}
725coordinateSystemProperties["labelX"]["input"] = "string"
726coordinateSystemProperties["labelX"]["essential"] = false
727coordinateSystemProperties["labelX"]["desc"] = "labelX (string): label of the x axis to be placed next to it. If unused (nil) will be X."
728
729coordinateSystemProperties["labelY"] = {}
730coordinateSystemProperties["labelY"]["input"] = "string"
731coordinateSystemProperties["labelY"]["essential"] = false
732coordinateSystemProperties["labelY"]["desc"] = "labelY (string): label of the y axis to be placed next to it. If unused (nil) will be Y."
733
734coordinateSystemProperties["startX"] = {}
735coordinateSystemProperties["startX"]["input"] = "decimal"
736coordinateSystemProperties["startX"]["essential"] = false
737coordinateSystemProperties["startX"]["desc"] = "startX (decimal number): what x coordinate shall be at the origin of the system. If unused (nil) will be 0."
738
739coordinateSystemProperties["startY"] = {}
740coordinateSystemProperties["startY"]["input"] = "decimal"
741coordinateSystemProperties["startY"]["essential"] = false
742coordinateSystemProperties["startY"]["desc"] = "startY (decimal number): what y coordinate shall be at the origin of the system. If unused (nil) will be 0."
743
744coordinateSystemProperties["stepX"] = {}
745coordinateSystemProperties["stepX"]["input"] = "number"
746coordinateSystemProperties["stepX"]["essential"] = false
747coordinateSystemProperties["stepX"]["desc"] = "stepX (non-decimal number in pixels): every how many pixels a number label shall be placed next to the x axis. If unused (nil) will be as small as possible while maintaining 1 pixel space."
748
749coordinateSystemProperties["stepY"] = {}
750coordinateSystemProperties["stepY"]["input"] = "number"
751coordinateSystemProperties["stepY"]["essential"] = false
752coordinateSystemProperties["stepY"]["desc"] = "stepY (non-decimal number in pixels): every how many pixels a number label shall be placed next to the y axis. If unused (nil) will be as small as possible while maintaining 1 pixel space."
753
754--linesArray
755pictureProperties = {}
756pictureProperties["linesArray"] = {}
757pictureProperties["linesArray"]["input"] = "picArray"
758pictureProperties["linesArray"]["essential"] = true
759pictureProperties["linesArray"]["desc"] = "linesArray (numerically indexed string table) this array defines the whole picture. One entry equals one line. Colors are defined with one character 0-f. String structure: \";\"=transparent pixel, \"color;\"=pixel without character, \"color:bgcolor:character;\"=pixel with character."
760pictureProperties["linesArray"]["default"] = {"#;#;#;#;#;#;#;#;#;#;","#;*:#:Y;*:#:o;*:#:u;*:#:r;#;*:#:P;*:#:i;*:#:c;#;","#;#;#;#;#;#;#;#;#;#;"}
761
762pictureProperties["width"] = {}
763pictureProperties["width"]["input"] = "number"
764pictureProperties["width"]["essential"] = true
765pictureProperties["width"]["desc"] = "width (non-decimal number in pixels): how wide the picture shall be. Even if more information is stored in linesArray, will not overrun this property."
766pictureProperties["width"]["default"] = 10
767
768pictureProperties["height"] = {}
769pictureProperties["height"]["input"] = "number"
770pictureProperties["height"]["essential"] = true
771pictureProperties["height"]["desc"] = "height (non-decimal number in pixels): how high the picture shall be. Even if more information is stored in linesArray, will not overrun this property."
772pictureProperties["height"]["default"] = 3
773
774--elementProperties
775elementProperties = {}
776elementProperties["dynTextBox"] = dynamicTextBoxProperties
777elementProperties["slider"] = sliderProperties
778elementProperties["dropDownMenu"] = dropDownMenuProperties
779elementProperties["navMenu"] = navigationMenuProperties
780elementProperties["colorPicker"] = colorPickerProperties
781elementProperties["progressBar"] = progressBarProperties
782elementProperties["coordsSystem"] = coordinateSystemProperties
783elementProperties["picture"] = pictureProperties
784
785elements = {}
786elements["dynTextBox"] = dynamicTextBoxes
787elements["slider"] = sliders
788elements["dropDownMenu"] = dropDownMenus
789elements["navMenu"] = navigationMenus
790elements["colorPicker"] = colorPickers
791elements["progressBar"] = progressBars
792elements["coordsSystem"] = coordinateSystems
793elements["picture"] = pictures
794
795--string to boolean
796function toBool(var)
797 if type(var)=="string" then
798 if var=="true" then
799 return true
800 else
801 return false
802 end
803 end
804end
805
806--this is used to avoid ID conflicts
807function trackID(ID)
808 ID = string.lower(ID)
809 local found = false
810 for i,current in ipairs(IDlist) do
811 if current==ID then
812 found = true
813 break
814 end
815 end
816 if found then
817 writeToLog("Potential ID conflict: "..ID..". Ignore if designer.",3)
818 else
819 if ID~=nil then
820 table.insert(IDlist,ID)
821 writeToLog("ID "..ID.." added to list.",1)
822 else
823 writeToLog("ID can't be nil!",4)
824 return false
825 end
826 end
827 return not found
828end
829
830function IDExists(ID)
831 ID = string.lower(ID)
832 for i,current in ipairs(IDlist) do
833 if ID==current then
834 return true
835 end
836 end
837 return false
838end
839
840--function to turn a percentage into an absolute coordinate
841function relX(perc,screenID)
842 if math.floor(((screens[screenID]["sizeX"])/100)*perc)>0 then
843 return math.floor(((screens[screenID]["sizeX"])/100)*perc+0.5)
844 else
845 return 1
846 end
847end
848
849function relY(perc,screenID)
850 if math.floor(((screens[screenID]["sizeY"])/100)*perc)>0 then
851 return math.floor(((screens[screenID]["sizeY"])/100)*perc+0.5)
852 else
853 return 1
854 end
855end
856
857--writeToLog function with 5 different levels and time since program start
858function writeToLog(text,level)
859 local levels = {"DEBUG","INFO","WARNING","ERROR","FATAL"}
860 if level == nil then
861 level = 2
862 end
863 if level>=writingLogLevel then
864 if fs.getFreeSpace(fs.combine(root,"EasyGUI/"))>1000 then
865 local timeNumber = os.clock() - startTime
866 local hours = 0
867 local minutes = 0
868 local seconds = 0
869 local milliseconds = 0
870 while timeNumber>=3600 do
871 hours = hours + 1
872 timeNumber = timeNumber - 3600
873 end
874 while timeNumber>=60 do
875 minutes = minutes + 1
876 timeNumber = timeNumber - 60
877 end
878 seconds = timeNumber
879
880 local hours = tostring(hours)
881 local minutes = tostring(minutes)
882 local seconds = tostring(seconds)
883 if string.len(hours)==1 then
884 hours = "0"..hours
885 end
886 if string.len(minutes)==1 then
887 minutes = "0"..minutes
888 end
889 if lastLogString~="[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text then
890 logFile.writeLine("[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text)
891 logFile.flush()
892 lastLogString = "[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text
893 end
894 end
895 end
896end
897
898--save and load functions from here:
899--monitors,screens,dynamicTextBoxes,sliders,dropDownMenus,navigationMenus,colorPickers,progressBars,coordinateSystem,picture
900
901function saveMonitors()
902 writeToLog("Saving monitors to monitors.xml...",2)
903 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
904 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
905 end
906 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"a")
907 stream.writeLine("<monitors>")
908
909 local atLeastOne = false
910 for sMonitor,data in pairs(monitors) do
911 writeToLog("Saving monitor "..sMonitor.." to monitors.xml...",1)
912 atLeastOne = true
913 stream.writeLine("\t<monitor>")
914 stream.writeLine("\t\t<name>"..sMonitor.."</name>")
915 writeToLog("Saving side "..data["side"]..".",1)
916 stream.writeLine("\t\t<side>"..data["side"].."</side>")
917 writeToLog("Saving networkID "..data["networkID"]..".",1)
918 stream.writeLine("\t\t<networkID>"..data["networkID"].."</networkID>")
919 stream.writeLine("\t</monitor>")
920 writeToLog("Done saving monitor "..sMonitor.." to monitors.xml.",1)
921 end
922
923 stream.writeLine("</monitors>")
924 stream.close()
925 if not atLeastOne then
926 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
927 writeToLog("Did not find any monitors to save. Deleted monitors.xml.",2)
928 else
929 writeToLog("Done saving monitors to monitors.xml.",2)
930 end
931end
932
933function loadMonitors()
934 writeToLog("Loading monitors from monitors.xml...",2)
935 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"r")
936
937 local line = stream.readLine()
938 local mon = nil
939 local atLeastOne = false
940 while line~=nil do
941 if string.match(line,"<monitor>") then
942 if mon==nil then
943 mon = {}
944 writeToLog("Reading new monitor tag...",1)
945 else
946 writeToLog("Found monitor tag even though previous monitor tag was not closed. Did someone mess around with the xml?",4)
947 mon = {}
948 end
949 end
950 if string.match(line,"<name>") and string.match(line,"</name>") then
951 a,start = string.find(line,"<name>")
952 sEnd,b = string.find(line,"</name>")
953 name = string.sub(line,start+1,sEnd-1)
954 if mon~=nil then
955 writeToLog("Reading monitor name: "..name,1)
956 mon["name"] = name
957 else
958 writeToLog("Found name tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
959 end
960 end
961 if string.match(line,"<side>") and string.match(line,"</side>") then
962 a,start = string.find(line,"<side>")
963 sEnd,b = string.find(line,"</side>")
964 side = string.sub(line,start+1,sEnd-1)
965 if mon~=nil then
966 writeToLog("Reading monitor side: "..side,1)
967 mon["side"] = side
968 else
969 writeToLog("Found side tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
970 end
971 end
972 if string.match(line,"<networkID>") and string.match(line,"</networkID>") then
973 a,start = string.find(line,"<networkID>")
974 sEnd,b = string.find(line,"</networkID>")
975 networkID = string.sub(line,start+1,sEnd-1)
976 if mon~=nil then
977 writeToLog("Reading monitor networkID: "..networkID,1)
978 mon["networkID"] = networkID
979 else
980 writeToLog("Found networkID tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
981 end
982 end
983 if string.match(line,"</monitor>") then
984 if mon~=nil then
985 name = mon["name"]
986 mon["name"] = nil
987 if mon["side"]~=nil and mon["networkID"]~=nil then
988 monitors[name] = mon
989 trackID(name)
990 if mon["networkID"]=="NONE" then
991 monitors[name]["peripheral"] = peripheral.wrap(mon["side"])
992 if monitors[name]["peripheral"]==nil then
993 monitors[name]=nil
994 writeToLog("A saved monitor is missing. Reinitializing search.",4)
995 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
996 findMonitors()
997 saveMonitors()
998 break
999 else
1000 atLeastOne = true
1001 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
1002 end
1003 else
1004 monitors[name]["peripheral"] = peripheral.wrap(mon["networkID"])
1005 if monitors[name]["peripheral"]==nil then
1006 monitors[name]=nil
1007 writeToLog("A saved monitor is missing. Reinitializing search.",4)
1008 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
1009 findMonitors()
1010 saveMonitors()
1011 break
1012 else
1013 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
1014 atLeastOne = true
1015 end
1016 end
1017 else
1018 writeToLog("Information for monitor "..name.." is faulty. Did someone mess around with the xml?",4)
1019 end
1020 mon = nil
1021 else
1022 writeToLog("Found monitor closing tag even though it was not opened. Did someone mess around with the xml?",4)
1023 end
1024 end
1025
1026 line = stream.readLine()
1027 end
1028
1029 if atLeastOne then
1030 writeToLog("Done loading monitors from monitors.xml.",2)
1031 else
1032 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
1033 writeToLog("Did not find any monitors to load. Deleted monitors.xml.",2)
1034 end
1035 stream.close()
1036end
1037
1038function saveScreen(ID)
1039 if screens[ID]~=nil then
1040 writeToLog("Saving screen "..ID.."...",2)
1041 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1042 fs.delete(fs.combine(root,"EasyGUI/screens/"..ID..".xml"))
1043 end
1044
1045 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"a")
1046
1047 local data = screens[ID]
1048
1049 handle.writeLine("<screen>")
1050 saveProp(handle,"sizeX",data)
1051 saveProp(handle,"sizeY",data)
1052 saveProp(handle,"defaultTextColor",data)
1053 saveProp(handle,"defaultBGColor",data)
1054
1055 handle.writeLine("\t<elements>")
1056 for i,element in ipairs(data["elements"]) do
1057 if string.len(element["ID"])<32 then
1058 handle.writeLine("\t\t<element>")
1059 handle.writeLine("\t\t\t<type>"..element["type"].."</type>")
1060 handle.writeLine("\t\t\t<ID>"..element["ID"].."</ID>")
1061 handle.writeLine("\t\t\t<x>"..element["x"].."</x>")
1062 handle.writeLine("\t\t\t<y>"..element["y"].."</y>")
1063 saveElement(element["ID"],element["type"])
1064 handle.writeLine("\t\t</element>")
1065 end
1066 end
1067 handle.writeLine("\t</elements>")
1068
1069 handle.writeLine("</screen>")
1070 handle.close()
1071 writeToLog("Done saving screen "..ID..".",2)
1072 else
1073 writeToLog("Could not save screen "..ID.." because it was not found.",3)
1074 end
1075end
1076
1077function loadScreen(ID)
1078 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1079 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"r")
1080 local temp = {}
1081 local line = handle.readLine()
1082 while line~=nil do
1083 readPropNumber(line,"sizeX",temp)
1084 readPropNumber(line,"sizeY",temp)
1085 readPropNumber(line,"defaultTextColor",temp)
1086 readPropNumber(line,"defaultBGColor",temp)
1087 if string.match(line,"<elements>") then
1088 local temp2 = {}
1089 line = handle.readLine()
1090 while not string.match(line,"</elements>") do
1091 if string.match(line,"<element>") then
1092 local temp3 = {}
1093 line = handle.readLine()
1094 while not string.match(line,"</element>") do
1095 if string.match(line,"<type>") and string.match(line,"</type>") then
1096 a,start = string.find(line,"<type>")
1097 sEnd,b = string.find(line,"</type>")
1098 type_ = string.sub(line,start+1,sEnd-1)
1099 temp3["type"] = type_
1100 end
1101 if string.match(line,"<ID>") and string.match(line,"</ID>") then
1102 a,start = string.find(line,"<ID>")
1103 sEnd,b = string.find(line,"</ID>")
1104 ID_ = string.sub(line,start+1,sEnd-1)
1105 temp3["ID"] = ID_
1106 end
1107 if string.match(line,"<x>") and string.match(line,"</x>") then
1108 a,start = string.find(line,"<x>")
1109 sEnd,b = string.find(line,"</x>")
1110 x_ = string.sub(line,start+1,sEnd-1)
1111 temp3["x"] = tonumber(x_)
1112 end
1113 if string.match(line,"<y>") and string.match(line,"</y>") then
1114 a,start = string.find(line,"<y>")
1115 sEnd,b = string.find(line,"</y>")
1116 y_ = string.sub(line,start+1,sEnd-1)
1117 temp3["y"] = tonumber(y_)
1118 end
1119
1120 line = handle.readLine()
1121 end
1122 loadElement(temp3["ID"],temp3["type"])
1123 table.insert(temp2,temp3)
1124 end
1125 line = handle.readLine()
1126 end
1127 temp["elements"] = temp2
1128 end
1129 line = handle.readLine()
1130 end
1131 if temp["sizeX"]~=nil and temp["sizeY"]~=nil and temp["defaultTextColor"]~=nil and temp["defaultBGColor"]~=nil and temp["elements"]~=nil then
1132 temp["pixelMatrix"] = {}
1133 screens[ID] = temp
1134 trackID(ID)
1135 writeToLog("Succesfully loaded screen "..ID..".",2)
1136 else
1137 writeToLog("Information for screen "..ID.." is faulty. Did someone mess around with the xml?",4)
1138 end
1139 handle.close()
1140 else
1141 writeToLog("Could not load screen "..ID.." because the file was not found.",3)
1142 end
1143end
1144
1145function tryLoadAllScreens()
1146 if fs.exists(fs.combine(root,"/EasyGUI/screens/")) then
1147 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/screens/"))) do
1148 if string.sub(name,-4)==".xml" then
1149 if screens[string.sub(name,1,-5)]==nil then
1150 loadScreen(string.sub(name,1,-5))
1151 end
1152 end
1153 end
1154 end
1155end
1156
1157function tryLoadAllElements()
1158 for type_,data in pairs(elements) do
1159 if fs.exists(fs.combine(root,"/EasyGUI/"..type_.."/")) then
1160 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/"..type_.."/"))) do
1161 if string.sub(name,-4)==".xml" then
1162 if elements[type_][string.sub(name,1,-5)]==nil then
1163 loadElement(string.sub(name,1,-5),type_)
1164 end
1165 end
1166 end
1167 end
1168 end
1169end
1170
1171function saveProp(handle,prop,data)
1172 if data[prop]~=nil then
1173 handle.writeLine("\t<"..prop..">"..data[prop].."</"..prop..">")
1174 writeToLog("Saving "..prop.." "..data[prop]..".",1)
1175 end
1176end
1177
1178function readPropString(line,prop,temp)
1179 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1180 local a,start = string.find(line,"<"..prop..">")
1181 local sEnd,b = string.find(line,"</"..prop..">")
1182 local value = string.sub(line,start+1,sEnd-1)
1183 temp[prop] = value
1184 writeToLog("Reading "..prop..": "..value,1)
1185 end
1186end
1187
1188function readPropNumber(line,prop,temp)
1189 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1190 local a,start = string.find(line,"<"..prop..">")
1191 local sEnd,b = string.find(line,"</"..prop..">")
1192 local value = string.sub(line,start+1,sEnd-1)
1193 temp[prop] = tonumber(value)
1194 writeToLog("Reading "..prop..": "..value,1)
1195 end
1196end
1197
1198function saveArray(handle,prop,data)
1199 if data[prop]~=nil then
1200 handle.writeLine("\t<"..prop..">")
1201 writeToLog("Saving "..prop..".",1)
1202 for i,entry in ipairs(data[prop]) do
1203 handle.writeLine("\t\t<"..i..">"..entry.."</"..i..">")
1204 end
1205 handle.writeLine("\t</"..prop..">")
1206 end
1207end
1208
1209function readNumberArray(line,prop,temp,handle)
1210 if string.match(line,"<"..prop..">") then
1211 line = handle.readLine()
1212 local temp2 = {}
1213 while not (string.match(line,"</"..prop..">")) do
1214 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1215 local a,start = string.find(line,"<%d+>")
1216 local sEnd,b = string.find(line,"</%d+>")
1217 local currentValue = tonumber(string.sub(line,start+1,sEnd-1))
1218 local index = tonumber(string.sub(line,a+1,start-1))
1219 temp2[index] = currentValue
1220 end
1221
1222 line = handle.readLine()
1223 end
1224 temp[prop] = temp2
1225 writeToLog("Reading "..prop..".",1)
1226 end
1227end
1228
1229function readStringArray(line,prop,temp,handle)
1230 if string.match(line,"<"..prop..">") then
1231 line = handle.readLine()
1232 local temp2 = {}
1233 while not (string.match(line,"</"..prop..">")) do
1234 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1235 local a,start = string.find(line,"<%d+>")
1236 local sEnd,b = string.find(line,"</%d+>")
1237 local currentValue = (string.sub(line,start+1,sEnd-1))
1238 local index = tonumber(string.sub(line,a+1,start-1))
1239 temp2[index] = currentValue
1240 end
1241
1242 line = handle.readLine()
1243 end
1244 temp[prop] = temp2
1245 writeToLog("Reading "..prop..".",1)
1246 end
1247end
1248
1249--helper function for writing navMenu arrays (recursive)
1250function writeSubmenu(handle,array,level)
1251 local tabs = "\t\t"
1252 for i=1,level-1 do
1253 tabs = tabs.."\t\t"
1254 end
1255 for i,entry in ipairs(array) do
1256 handle.writeLine(tabs.."<"..i..">")
1257 handle.writeLine(tabs.."\t<text>"..entry["text"].."</text>")
1258 if entry["submenu"]~=nil then
1259 handle.writeLine(tabs.."\t<submenu>")
1260 writeSubmenu(handle,entry["submenu"],level+1)
1261 handle.writeLine(tabs.."\t</submenu>")
1262 end
1263 handle.writeLine(tabs.."</"..i..">")
1264 end
1265end
1266
1267function saveNavMenu(handle,prop,data)
1268 handle.writeLine("\t<"..prop..">")
1269 writeSubmenu(handle,data[prop],1)
1270 handle.writeLine("\t</"..prop..">")
1271end
1272
1273function readNavMenu(line,prop,temp,handle)
1274 if string.match(line,"<"..prop..">") then
1275 line = handle.readLine()
1276 local temp2 = {}
1277 local currentPos = {}
1278 local indexTagOpen = 0
1279 local submenuTagOpen = 0
1280 local currentIndex = nil
1281 while not string.match(line,"</"..prop..">") do
1282 if string.match(line,"<%d+>") then
1283 a,start = string.find(line,"<%d+>")
1284 sEnd,b = string.find(line,"</%d+>")
1285 index = tonumber(string.sub(line,a+1,start-1))
1286
1287 local currentArray = temp2
1288 for i=1,table.getn(currentPos) do
1289 currentArray = currentArray[currentPos[i]]
1290 end
1291
1292 currentIndex = index
1293 currentArray[currentIndex] = {}
1294 indexTagOpen = indexTagOpen + 1
1295 end
1296 if string.match(line,"</%d+>") then
1297 if indexTagOpen==0 then
1298 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1299 end
1300 currentIndex = nil
1301 indexTagOpen = indexTagOpen - 1
1302 end
1303 if string.match(line,"<text>") and string.match(line,"</text>") then
1304 a,start = string.find(line,"<text>")
1305 sEnd,b = string.find(line,"</text>")
1306 text = string.sub(line,start+1,sEnd-1)
1307 writeToLog("Reading text: "..text,1)
1308 if indexTagOpen==0 or currentIndex==nil then
1309 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1310 else
1311 local currentArray = temp2
1312 for i=1,table.getn(currentPos) do
1313 currentArray = currentArray[currentPos[i]]["submenu"]
1314 end
1315 currentArray[currentIndex] = {}
1316 currentArray[currentIndex]["text"] = text
1317 end
1318 end
1319 if string.match(line,"<submenu>") then
1320 if indexTagOpen==0 or currentIndex==nil then
1321 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1322 else
1323 local currentArray = temp2
1324 for i=1,table.getn(currentPos) do
1325 currentArray = currentArray[currentPos[i]]["submenu"]
1326 end
1327 table.insert(currentPos,currentIndex)
1328 currentArray[currentIndex]["submenu"] = {}
1329 end
1330 submenuTagOpen = submenuTagOpen + 1
1331 end
1332 if string.match(line,"</submenu>") then
1333 if submenuTagOpen == 0 then
1334 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1335 else
1336 currentPos[table.getn(currentPos)] = nil
1337 end
1338
1339 submenuTagOpen = submenuTagOpen - 1
1340 end
1341 line = handle.readLine()
1342 end
1343 if submenuTagOpen~=0 or indexTagOpen~=0 then
1344 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1345 else
1346 temp["menuArray"] = temp2
1347 end
1348 end
1349end
1350
1351function saveCSTable(handle,prop,data)
1352 if data[prop]~=nil then
1353 handle.writeLine("\t<"..prop..">")
1354 for i,currentTable in ipairs(data[prop]) do
1355 handle.writeLine("\t\t<"..i..">")
1356 for name,currentNumber in pairs(currentTable) do
1357 handle.writeLine("\t\t\t<"..name..">"..currentNumber.."</"..name..">")
1358 end
1359 handle.writeLine("\t\t</"..i..">")
1360 end
1361 handle.writeLine("\t</"..prop..">")
1362 end
1363end
1364
1365function saveCSDesignsTable(handle,prop,data)
1366 if data[prop]~=nil then
1367 handle.writeLine("\t<"..prop..">")
1368 for i,design in ipairs(data[prop]) do
1369 handle.writeLine("\t\t<"..i..">")
1370 if design["color"]~=nil then
1371 handle.writeLine("\t\t\t<color>"..design["color"].."</color>")
1372 end
1373 if design["BGColor"]~=nil then
1374 handle.writeLine("\t\t\t<BGColor>"..design["BGColor"].."</BGColor>")
1375 end
1376 if design["character"]~=nil then
1377 handle.writeLine("\t\t\t<character>"..design["character"].."</character>")
1378 end
1379 handle.writeLine("\t\t</"..i..">")
1380 end
1381 handle.writeLine("\t</"..prop..">")
1382 end
1383end
1384
1385function readCSTable(line,prop,temp,handle)
1386 if string.match(line,"<"..prop..">") then
1387 line = handle.readLine()
1388 local temp2 = {}
1389 local tableOpen = nil
1390 while not string.match(line,"</"..prop..">") do
1391 if string.match(line,"<[%d.-]+>") then
1392 a,start = string.find(line,"<[%d.-]+>")
1393 index = tonumber(string.sub(line,a+1,start-1))
1394 if tableOpen==nil then
1395 tableOpen = index
1396 temp2[tableOpen] = {}
1397 else
1398 if string.match(line,"</[%d.-]+>") then
1399 sEnd,b = string.find(line,"</[%d.-]+>")
1400 currentNumber = tonumber(string.sub(line,start+1,sEnd-1))
1401 temp2[tableOpen][index] = currentNumber
1402 end
1403 end
1404 else if string.match(line,"</[%d.-]+>") then
1405 tableOpen = nil
1406 end
1407 end
1408 line = handle.readLine()
1409 end
1410 temp[prop] = temp2
1411 end
1412end
1413
1414function readCSDesignsTable(line,prop,temp,handle)
1415 if string.match(line,"<"..prop..">") then
1416 line = handle.readLine()
1417 local temp2 = {}
1418 local tableOpen = nil
1419 while not string.match(line,"</"..prop..">") do
1420 if string.match(line,"<%d+>") then
1421 a,start = string.find(line,"<%d+>")
1422 index = tonumber(string.sub(line,a+1,start-1))
1423 if tableOpen==nil then
1424 tableOpen = index
1425 temp2[tableOpen] = {}
1426 else
1427 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1428 end
1429 end
1430 if string.match(line,"</%d+>") then
1431 tableOpen = nil
1432 end
1433 if string.match(line,"<color>") and string.match(line,"</color>") then
1434 a,start = string.find(line,"<color>")
1435 sEnd,b = string.find(line,"</color>")
1436 color = string.sub(line,start+1,sEnd-1)
1437 if tableOpen==nil then
1438 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1439 else
1440 temp2[tableOpen]["color"] = tonumber(color)
1441 end
1442 end
1443 if string.match(line,"<BGColor>") and string.match(line,"</BGColor>") then
1444 a,start = string.find(line,"<BGColor>")
1445 sEnd,b = string.find(line,"</BGColor>")
1446 BGColor = string.sub(line,start+1,sEnd-1)
1447 if tableOpen==nil then
1448 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1449 else
1450 temp2[tableOpen]["BGColor"] = tonumber(BGColor)
1451 end
1452 end
1453 if string.match(line,"<character>") and string.match(line,"</character>") then
1454 a,start = string.find(line,"<character>")
1455 sEnd,b = string.find(line,"</character>")
1456 character = string.sub(line,start+1,sEnd-1)
1457 if tableOpen==nil then
1458 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1459 else
1460 temp2[tableOpen]["character"] = character
1461 end
1462 end
1463 line = handle.readLine()
1464 end
1465 temp[prop] = temp2
1466 end
1467end
1468
1469function saveElement(ID,type_)
1470 if elements[type_][ID]~=nil then
1471 writeToLog("Saving "..type_.." "..ID.."...",2)
1472 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1473 fs.delete(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"))
1474 end
1475
1476 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"a")
1477
1478 local data = elements[type_][ID]
1479
1480 handle.writeLine("<"..type_..">")
1481
1482 for name,data2 in pairs(elementProperties[type_]) do
1483 if data2["input"]=="number" or data2["input"]=="string" or data2["input"]=="decimal" or data2["input"]=="color" or string.sub(data2["input"],1,3)=="DDM" then
1484 saveProp(handle,name,data)
1485 end
1486 if data2["input"]=="colorsArray" or data2["input"]=="stringArray" or data2["input"]=="picArray" then
1487 saveArray(handle,name,data)
1488 end
1489 if data2["input"]=="navMenuArray" then
1490 saveNavMenu(handle,name,data)
1491 end
1492 if data2["input"]=="CSTable" then
1493 saveCSTable(handle,name,data)
1494 end
1495 if data2["input"]=="CSDesignsTable" then
1496 saveCSDesignsTable(handle,name,data)
1497 end
1498 end
1499
1500 handle.writeLine("</"..type_..">")
1501 handle.close()
1502 writeToLog("Done saving "..type_.." "..ID..".",2)
1503 else
1504 writeToLog("Could not save "..type_.." "..ID.." because it was not found.",3)
1505 end
1506end
1507
1508function loadElement(ID,type_)
1509 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1510 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"r")
1511 local temp = {}
1512 local line = handle.readLine()
1513 while line~=nil do
1514 for name,data2 in pairs(elementProperties[type_]) do
1515 if data2["input"]=="number" or data2["input"]=="decimal" or data2["input"]=="color" then
1516 readPropNumber(line,name,temp)
1517 end
1518 if data2["input"]=="string" or string.sub(data2["input"],1,3)=="DDM" then
1519 readPropString(line,name,temp)
1520 end
1521 if data2["input"]=="stringArray" or data2["input"]=="picArray" then
1522 readStringArray(line,name,temp,handle)
1523 end
1524 if data2["input"]=="colorsArray" then
1525 readNumberArray(line,name,temp,handle)
1526 end
1527 if data2["input"]=="navMenuArray" then
1528 readNavMenu(line,name,temp,handle)
1529 end
1530 if data2["input"]=="CSTable" then
1531 readCSTable(line,name,temp,handle)
1532 end
1533 if data2["input"]=="CSDesignsTable" then
1534 readCSDesignsTable(line,name,temp,handle)
1535 end
1536 end
1537
1538 line = handle.readLine()
1539 end
1540 local valid = true
1541 for name,data2 in pairs(elementProperties[type_]) do
1542 if data2["essential"] then
1543 if temp[name]==nil then
1544 valid = false
1545 break
1546 end
1547 end
1548 end
1549 if valid then
1550 temp["visible"] = true
1551 temp["enabled"] = true
1552 temp["expanded"] = false
1553 elements[type_][ID] = temp
1554 trackID(ID)
1555 writeToLog("Succesfully loaded "..type_.." "..ID..".",2)
1556 else
1557 writeToLog("Information for "..type_.." "..ID.." is faulty. Did someone mess around with the xml?",4)
1558 end
1559 handle.close()
1560 else
1561 writeToLog("Could not load "..type_.." "..ID.." because the file was not found.",3)
1562 end
1563end
1564
1565--screens and pixel matrices from here
1566--this functions adds a screen
1567function addScreen(id,sizeX,sizeY,defaultTextColor,defaultBGColor)
1568 if trackID(id) then
1569 screens[id] = {}
1570 screens[id]["sizeX"] = sizeX
1571 screens[id]["sizeY"] = sizeY
1572 screens[id]["defaultTextColor"] = defaultTextColor
1573 screens[id]["defaultBGColor"] = defaultBGColor
1574 screens[id]["elements"] = {}
1575 screens[id]["pixelMatrix"] = {}
1576 writeToLog("Added screen "..id..".",2)
1577 else
1578 writeToLog("Did not add screen because of ID conflict.",3)
1579 end
1580end
1581
1582--this is an essential function which adds pixels to screen matrices accordingly
1583function writeToPixelMatrix(screenID,s,x,y,textColor,BGColor,elementID,elementType,sPart)
1584 if string.len(s)==1 then
1585 if x<=screens[screenID]["sizeX"] and y<=screens[screenID]["sizeY"] and x>=1 and y>=1 then
1586 writeToLog("Drawing "..sPart.." of "..elementType.." "..elementID..".",1)
1587 screens[screenID]["pixelMatrix"][x..":"..y] = {}
1588 screens[screenID]["pixelMatrix"][x..":"..y]["character"] = s
1589 screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] = textColor
1590 screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] = BGColor
1591 screens[screenID]["pixelMatrix"][x..":"..y]["elementID"] = elementID
1592 screens[screenID]["pixelMatrix"][x..":"..y]["elementType"] = elementType
1593 screens[screenID]["pixelMatrix"][x..":"..y]["part"] = sPart
1594 else
1595 writeToLog("Part "..sPart.." of "..elementType.." "..elementID.." tried to draw outside of screen "..screenID..".",3)
1596 end
1597 else
1598 for i=1,string.len(s) do
1599 writeToPixelMatrix(screenID,string.sub(s,i,i),x+i-1,y,textColor,BGColor,elementID,elementType,sPart)
1600 end
1601 end
1602end
1603
1604function fullRefresh()
1605 clearTerminal()
1606 clearMonitors()
1607 for name,data in pairs(screens) do
1608 screens[name]["pixelMatrix"] = {}
1609 end
1610 refresh()
1611end
1612
1613function restartTimer(nRefreshRate)
1614 if nRefreshRate~=nil then
1615 refreshRate = nRefreshRate
1616 refreshTimerID = os.startTimer(refreshRate)
1617 writeToLog("Restarting refresh timer with refreshRate "..refreshRate.." seconds.",1)
1618 end
1619end
1620
1621--this function adds an element to the screen
1622function addElementToScreen(elementID, screenID, x,y)
1623 if x==nil then
1624 x = 1
1625 end
1626 if y==nil then
1627 y = 1
1628 end
1629 if screens[screenID]~=nil then
1630 local elements = screens[screenID]["elements"]
1631 local element = {}
1632 local exists = false
1633
1634 for i,current in ipairs(elements) do
1635 if current["ID"]==elementID then
1636 exists = true
1637 end
1638 end
1639
1640 if not exists then
1641 if getType(elementID)~=nil then
1642 element["type"] = getType(elementID)
1643 element["ID"] = elementID
1644 element["x"] = x
1645 element["y"] = y
1646
1647 table.insert(elements, element)
1648 screens[screenID]["elements"] = elements
1649 writeToLog("Successfully added element "..elementID.." to screen "..screenID..".",2)
1650 else
1651 writeToLog("Could not add element to the screen. Element was not found or nil.",3)
1652 end
1653 else
1654 writeToLog("Did not add element to the screen because the element is already on that screen.",2)
1655 end
1656 else
1657 writeToLog("Could not add the element to the screen. Screen was not found or nil.",3)
1658 end
1659end
1660
1661function removeElementFromScreen(elementID,screenID)
1662 if screens[screenID]~=nil then
1663 for i,data in ipairs(screens[screenID]["elements"]) do
1664 if data["ID"]==elementID then
1665 table.remove(screens[screenID]["elements"],i)
1666 break
1667 end
1668 end
1669 else
1670 writeToLog("Could not remove the element from the screen. Screen was not found or nil.",3)
1671 end
1672end
1673
1674function changePos(elementID,screenID,x,y)
1675 if x==nil then
1676 x = 1
1677 end
1678 if y==nil then
1679 y = 1
1680 end
1681 if screens[screenID]~=nil then
1682 local elements = screens[screenID]["elements"]
1683 local found = false
1684
1685 for name,data in pairs(screens[screenID]["elements"]) do
1686 if data["ID"]==elementID then
1687 found = true
1688 data["x"] = x
1689 data["y"] = y
1690 break
1691 end
1692 end
1693
1694 if found then
1695 writeToLog("Successfully changed pos of element "..elementID.." on screen "..screenID..".",2)
1696 else
1697 writeToLog("Could not change pos of element. Element was not found or nil.",3)
1698 end
1699 else
1700 writeToLog("Could not change pos of element. Screen was not found or nil.",3)
1701 end
1702end
1703
1704function getPos(elementID,screenID)
1705 if screens[screenID]~=nil then
1706 local elements = screens[screenID]["elements"]
1707
1708 for name,data in pairs(screens[screenID]["elements"]) do
1709 if data["ID"]==elementID then
1710 return data["x"],data["y"]
1711 end
1712 end
1713 end
1714end
1715
1716--this function updates the pixel matrix of a certain screen
1717function updatePixelMatrix(screenID,str)
1718 writeToLog("Updating pixel matrix of screen "..screenID..".",2)
1719 --write elements to pixel matrix
1720 for i,element in ipairs(screens[screenID]["elements"]) do
1721 if str==nil or (string.len(element["ID"])>31 and str=="ONLYHASH") or (string.len(element["ID"])<32 and str=="ONLYNONHASH") then
1722 if elements[element["type"]][element["ID"]]["visible"] then
1723 writeToLog("Writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1724 success,msg = pcall(writeElementToPixelMatrix,screenID,element["ID"],element["x"],element["y"],element["type"])
1725 if success then
1726 writeToLog("Done writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1727 else
1728 writeToLog("There was an error writing "..element["type"].." "..element["ID"].." to pixel matrix. Error message: "..msg,4)
1729 end
1730 end
1731 end
1732 end
1733 writeToLog("Done updating pixel matrix.",2)
1734end
1735
1736function writeElementToPixelMatrix(screenID,ID,x,y,type_)
1737 if type_=="dynTextBox" then
1738 writeDynamicTextBoxToPixelMatrix(screenID,ID,x,y)
1739 end
1740 if type_=="slider" then
1741 writeSliderToPixelMatrix(screenID,ID,x,y)
1742 end
1743 if type_=="dropDownMenu" then
1744 writeDropDownMenuToPixelMatrix(screenID,ID,x,y)
1745 end
1746 if type_=="navMenu" then
1747 writeNavigationMenuToPixelMatrix(screenID,ID,x,y)
1748 end
1749 if type_=="colorPicker" then
1750 writeColorPickerToPixelMatrix(screenID,ID,x,y)
1751 end
1752 if type_=="progressBar" then
1753 writeProgressBarToPixelMatrix(screenID,ID,x,y)
1754 end
1755 if type_=="coordsSystem" then
1756 writeCoordinateSystemToPixelMatrix(screenID,ID,x,y)
1757 end
1758 if type_=="picture" then
1759 writePictureToPixelMatrix(screenID,ID,x,y)
1760 end
1761end
1762
1763function setScreenToRenderOnMon(screenID,monID,textScale,offsetX,offsetY)
1764 if offsetX ==nil then
1765 offsetX = 0
1766 end
1767 if offsetY ==nil then
1768 offsetY = 0
1769 end
1770 if monitors[monID]~=nil then
1771 if screens[screenID]~=nil then
1772 clearMonitor(monID)
1773 screens[screenID]["pixelMatrix"] = {}
1774 monitors[monID]["screen"] = screenID
1775 monitors[monID]["offsetX"] = offsetX
1776 monitors[monID]["offsetY"] = offsetY
1777 monitors[monID]["textScale"] = textScale
1778 writeToLog("Set screen "..screenID.." to be rendered on monitor "..monID..".",2)
1779 else
1780 writeToLog("Could not set screen to be rendered on monitor. Screen was not found or nil.",3)
1781 end
1782 else
1783 writeToLog("Could not set the screen to be rendered on monitor. Monitor was not found or nil.",3)
1784 end
1785end
1786
1787function setScreenToRenderOnTerminal(screenID)
1788 if screens[screenID]~=nil then
1789 clearTerminal()
1790 screens[screenID]["pixelMatrix"] = {}
1791 terminalScreen = screenID
1792 writeToLog("Set screen "..screenID.." to be rendered on terminal.")
1793 else
1794 terminalScreen = nil
1795 writeToLog("Could not set screen to be rendered on terminal. Screen was not found or nil.")
1796 end
1797end
1798
1799function setRefreshFunction(func)
1800 refreshFunction = func
1801 writeToLog("Changed refresh function.",2)
1802end
1803
1804function setProcessClickEventFunction(func)
1805 processClickEventFunc = func
1806 writeToLog("Changed processClickEvent function.",2)
1807end
1808
1809function setProcessEventFunction(func)
1810 processEventFunc = func
1811 writeToLog("Changed processEvent function.",2)
1812end
1813
1814function drawPixels(x,y,textColor,BGColor,str,monID)
1815 if monID~=nil then
1816 monitors[monID]["peripheral"].setBackgroundColor(BGColor)
1817 monitors[monID]["peripheral"].setTextColor(textColor)
1818 monitors[monID]["peripheral"].setCursorPos(x+monitors[monID]["offsetX"],y+monitors[monID]["offsetY"])
1819 monitors[monID]["peripheral"].write(str)
1820 else
1821 term.setBackgroundColor(BGColor)
1822 term.setTextColor(textColor)
1823 term.setCursorPos(x,y)
1824 term.write(str)
1825 end
1826end
1827
1828function drawOnMonitors(x,y,textColor,BGColor,str,monitorList)
1829 for i,monID in ipairs(monitorList) do
1830 if monID==terminalID then
1831 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str)
1832 else
1833 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str,monID)
1834 end
1835 if success then
1836 writeToLog("Drew "..str.." at "..x..":"..y..".",1)
1837 else
1838 writeToLog("There was an error drawing "..str.." at "..x..":"..y..". Error message: "..msg,4)
1839 end
1840 end
1841end
1842
1843function refresh()
1844 writeToLog("Refreshing all monitors...",2)
1845 local startTime = os.clock()
1846 for screenID,screenData in pairs(screens) do
1847 monitorList = {}
1848 for monID,data in pairs(monitors) do
1849 if screenID==data["screen"] then
1850 table.insert(monitorList,monID)
1851 end
1852 end
1853 if screenID==terminalScreen then
1854 table.insert(monitorList,terminalID)
1855 end
1856 if table.getn(monitorList)~=0 then
1857 --store previous pixels in this array
1858 local previousMatrix = {}
1859 for name,data in pairs(screens[screenID]["pixelMatrix"]) do
1860 previousMatrix[name] = data
1861 end
1862 screens[screenID]["pixelMatrix"] = {}
1863
1864 if designerRefresh then
1865 updatePixelMatrix(screenID,"ONLYNONHASH")
1866 screens[screenID]["sizeX"] = designerX
1867 screens[screenID]["sizeY"] = designerY
1868 updatePixelMatrix(screenID,"ONLYHASH")
1869 else
1870 updatePixelMatrix(screenID)
1871 end
1872
1873 writeToLog("Drawing pixels of screen "..screenID.." on monitors.",2)
1874 --render pixel matrix
1875 for y=1,screens[screenID]["sizeY"] do
1876 --this is a system which is performance optimized
1877 --instead of drawing each pixel separately, it collects all the pixels which use the same colors and writes it as a whole string
1878 local currStr = ""
1879 local currTextColor = nil
1880 local currBGColor = nil
1881 local currX = nil
1882 for x=1,screens[screenID]["sizeX"] do
1883 if screens[screenID]["pixelMatrix"][x..":"..y]~=nil then
1884 --only draw it if something changed about the pixel
1885 --performance
1886 local draw = true
1887 if previousMatrix[x..":"..y]~=nil then
1888 if previousMatrix[x..":"..y]["BGColor"]==screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] and previousMatrix[x..":"..y]["textColor"]==screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] and previousMatrix[x..":"..y]["character"]==screens[screenID]["pixelMatrix"][x..":"..y]["character"] then
1889 draw = false
1890 end
1891 else
1892 if screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]==screens[screenID]["defaultBGColor"] and screens[screenID]["pixelMatrix"][x..":"..y]["character"]==" " then
1893 draw = false
1894 end
1895 end
1896 if draw then
1897 if currTextColor==screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] and currBGColor==screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] then
1898 currStr = currStr ..screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1899 else
1900 if currStr~="" and currStr~=nil then
1901 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1902 end
1903 currStr = screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1904 currTextColor = screens[screenID]["pixelMatrix"][x..":"..y]["textColor"]
1905 currBGColor = screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]
1906 currX = x
1907 end
1908 else
1909 if currStr~="" and currStr~=nil then
1910 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1911 end
1912 currStr = ""
1913 currTextColor = nil
1914 currBGColor = nil
1915 currX = nil
1916 end
1917 previousMatrix[x..":"..y] = nil
1918 else
1919 if currStr~="" and currStr~=nil then
1920 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1921 end
1922 currStr = ""
1923 currTextColor = nil
1924 currBGColor = nil
1925 currX = nil
1926 end
1927 end
1928 if currStr~="" and currStr~=nil then
1929 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1930 end
1931 end
1932 writeToLog("Done drawing pixels of screen "..screenID.. " on monitors.",2)
1933
1934 --clean up using backup array. this procedure is necessary because clearing the monitor all the time (manually or with mon.clear()) creates too much lag with big screens
1935 --this is a clever way to increase performance
1936 writeToLog("Cleaning up monitors. (screen "..screenID..")",2)
1937 for y=1,screens[screenID]["sizeY"] do
1938 local str = ""
1939 local currX = nil
1940 for x=1,screens[screenID]["sizeX"] do
1941 if previousMatrix[x..":"..y]~=nil then
1942 if currX==nil then
1943 currX = x
1944 end
1945 str = str .." "
1946 else
1947 if str~="" then
1948 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
1949 end
1950 str = ""
1951 currX = nil
1952 end
1953 end
1954 if str~="" then
1955 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
1956 end
1957 end
1958 writeToLog("Done cleaning up monitors. (screen "..screenID..")",2)
1959
1960 if designerRefresh then
1961 screens[screenID]["sizeX"] = designerSmaxX
1962 screens[screenID]["sizeY"] = designerSmaxY
1963 end
1964 end
1965 end
1966 writeToLog("Done refreshing all monitors. Took "..(os.clock()-startTime).."seconds.",2)
1967end
1968
1969function clearMonitor(monID)
1970 local data = monitors[monID]
1971 if data["screen"]~=nil then
1972 local screenID = data["screen"]
1973 local offsetX = data["offsetX"]
1974 local offsetY = data["offsetY"]
1975 local textScale = data["textScale"]
1976 screens[screenID]["pixelMatrix"] = {}
1977 --check sizes
1978 monitors[monID]["peripheral"].setBackgroundColor(colors.black)
1979 monitors[monID]["peripheral"].clear()
1980 monX,monY = monitors[monID]["peripheral"].getSize()
1981 monitors[monID]["peripheral"].setTextScale(textScale)
1982 if (screens[screenID]["sizeX"] + offsetX)>monX or (screens[screenID]["sizeY"] + offsetY)>monY then
1983 writeToLog("Screen "..screenID.." cannot be displayed completely with given offset and textScale.",3)
1984 end
1985 monitors[monID]["peripheral"].setBackgroundColor(screens[screenID]["defaultBGColor"])
1986 --custom clear
1987 writeToLog("Clearing monitor "..monID.."...",1)
1988 local s = ""
1989 for i=1,screens[screenID]["sizeX"] do
1990 s = s.." "
1991 end
1992 for i=1,screens[screenID]["sizeY"] do
1993 monitors[monID]["peripheral"].setCursorPos(offsetX+1,offsetY+i)
1994 monitors[monID]["peripheral"].write(s)
1995 end
1996 writeToLog("Done clearing monitor "..monID..".",2)
1997 end
1998end
1999
2000function clearMonitors()
2001 for monID,data in pairs(monitors) do
2002 clearMonitor(monID)
2003 end
2004end
2005
2006function clearTerminal()
2007 if terminalScreen~=nil then
2008 local screenID = terminalScreen
2009 screens[screenID]["pixelMatrix"] = {}
2010 --check sizes
2011 sizeX,sizeY = term.getSize()
2012 if (screens[screenID]["sizeX"])>sizeX or (screens[screenID]["sizeY"])>sizeY then
2013 writeToLog("Screen "..screenID.." cannot be displayed completely on terminal.",3)
2014 end
2015 term.setBackgroundColor(colors.black)
2016 term.clear()
2017 term.setBackgroundColor(screens[screenID]["defaultBGColor"])
2018 --custom clear
2019 writeToLog("Clearing terminal.",1)
2020 local s = ""
2021 for i=1,screens[screenID]["sizeX"] do
2022 s = s.." "
2023 end
2024 for i=1,screens[screenID]["sizeY"] do
2025 term.setCursorPos(1,i)
2026 term.write(s)
2027 end
2028 writeToLog("Done clearing terminal.",2)
2029 end
2030end
2031
2032function run(nRefreshRate)
2033 writeToLog("Starting program, clearing all monitors...")
2034 clearMonitors()
2035 clearTerminal()
2036 writeToLog("Done clearing all monitors.")
2037
2038 refresh()
2039 if nRefreshRate~=nil then
2040 refreshRate = nRefreshRate
2041 refreshTimerID = os.startTimer(refreshRate)
2042 writeToLog("Starting refresh timer with refreshRate "..refreshRate.." seconds.",1)
2043 end
2044 local running = true
2045 while running do
2046 event,var1,var2,var3,var4,var5 = os.pullEventRaw()
2047 writeToLog("Caught "..event.." event.",2)
2048 if event=="monitor_touch" then
2049 processClickEvent(var1,var2,var3)
2050 end
2051 if event=="timer" then
2052 processTimerEvent(var1)
2053 end
2054 if event=="monitor_resize" then
2055 fullRefresh()
2056 end
2057 if event=="mouse_click" then
2058 if var1==1 then
2059 processClickEvent(terminalID,var2,var3)
2060 end
2061 end
2062 if event=="mouse_drag" then
2063 processDragEvent(var2,var3)
2064 end
2065 if event=="mouse_scroll" then
2066 processScrollEvent(var1,var2,var3)
2067 end
2068 if event=="terminate" then
2069 writeToLog("User terminated. Exiting.",2)
2070 logFile.writeLine("")
2071 logFile.flush()
2072 for sMonitor,data in pairs(monitors) do
2073 data["peripheral"].setBackgroundColor(colors.black)
2074 data["peripheral"].clear()
2075 end
2076 term.setBackgroundColor(colors.black)
2077 term.setTextColor(colors.white)
2078 term.clear()
2079 term.setCursorPos(1,1)
2080 running = false
2081 end
2082 if event=="easygui_interrupt" then
2083 running = false
2084 end
2085 if processEventFunc~=nil then
2086 success,msg = pcall(processEventFunc,event,var1,var2,var3,var4,var5)
2087 if success then
2088 writeToLog("Successfully called processEventFunc.",2)
2089 else
2090 writeToLog("There was an error calling processEventFunc. Msg: "..msg)
2091 end
2092 end
2093 end
2094end
2095
2096function processScrollEvent(direction,x,y)
2097 if terminalScreen~=nil then
2098 local s = x..":"..y
2099 local screenID = terminalScreen
2100
2101 local data = screens[screenID]["pixelMatrix"][s]
2102 if data~=nil then
2103 local elementType = data["elementType"]
2104 local ID = data["elementID"]
2105 local part = data["part"]
2106
2107 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2108 if direction==-1 then
2109 if dropDownMenus[ID]["selectionID"]~=1 then
2110 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2111 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]-1
2112 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2113 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2114 if success then
2115 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2116 else
2117 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2118 end
2119 end
2120 refresh()
2121 end
2122 else
2123 if dropDownMenus[ID]["selectionID"]~=table.getn(dropDownMenus[ID]["entries"]) then
2124 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2125 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]+1
2126 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2127 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2128 if success then
2129 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2130 else
2131 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2132 end
2133 end
2134 refresh()
2135 end
2136 end
2137 end
2138
2139 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and dropDownMenus[ID]["expanded"] and (string.match(part,"entry") or string.match(part,"scroll")) then
2140 if dropDownMenus[ID]["scrollPositionIndex"]~=nil then
2141 if direction==-1 then
2142 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2143 writeToLog("Scrolled up dropDownMenu "..ID.." because of scroll event.",2)
2144 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2145 refresh()
2146 end
2147 else
2148 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2149 writeToLog("Scrolled down dropDownMenu "..ID.." because of scroll event.",2)
2150 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2151 refresh()
2152 end
2153 end
2154 end
2155 end
2156
2157 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2158 if direction==1 then
2159 if sliders[ID]["value"]~=sliders[ID]["length"] then
2160 sliders[ID]["value"] = sliders[ID]["value"] + 1
2161 writeToLog("Incremented value of slider "..ID.." because of scroll event.",2)
2162 if sliders[ID]["onChangeFunction"]~=nil then
2163 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2164 if success then
2165 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2166 else
2167 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2168 end
2169 end
2170 refresh()
2171 end
2172 else
2173 if sliders[ID]["value"]~=1 then
2174 sliders[ID]["value"] = sliders[ID]["value"] - 1
2175 writeToLog("Decremented value of slider "..ID.." because of scroll event.",2)
2176 if sliders[ID]["onChangeFunction"]~=nil then
2177 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2178 if success then
2179 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2180 else
2181 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2182 end
2183 end
2184 refresh()
2185 end
2186 end
2187 end
2188 end
2189 end
2190end
2191
2192function processDragEvent(x,y)
2193 if terminalScreen~=nil then
2194 local s = x..":"..y
2195 local screenID = terminalScreen
2196
2197 local data = screens[screenID]["pixelMatrix"][s]
2198 if data~=nil then
2199 local elementType = data["elementType"]
2200 local ID = data["elementID"]
2201 local part = data["part"]
2202
2203 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2204 processClickEvent(terminalID,x,y)
2205 end
2206 end
2207 end
2208end
2209
2210function processTimerEvent(timerID)
2211 writeToLog("Processing timerEvent with ID "..timerID.."...",2)
2212 if timerID==refreshTimerID then
2213 if refreshFunction~=nil then
2214 success,msg = pcall(refreshFunction)
2215 if success then
2216 writeToLog("Successfully called refresh function.",1)
2217 else
2218 writeToLog("There was an error calling the refresh function. Error message: "..msg,4)
2219 end
2220 end
2221 refresh()
2222 writeToLog("Restarting refresh timer.",2)
2223 refreshTimerID = os.startTimer(refreshRate)
2224 end
2225
2226 for name,data in pairs(dynamicTextBoxes) do
2227 if data["timerID"]==timerID then
2228 writeToLog("Processing timer of dynamicTextBox "..name..".",1)
2229 dynamicTextBoxes[name]["active"] = false
2230 dynamicTextBoxes[name]["timerID"] = nil
2231 if dynamicTextBoxes[name]["onInactiveFunction"]~=nil then
2232 success,msg = pcall(dynamicTextBoxes[name]["onInactiveFunction"],name,dynamicTextBoxes[name]["active"])
2233 if success then
2234 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..name..".",1)
2235 else
2236 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..name..". Error message: "..msg,4)
2237 end
2238 end
2239 refresh()
2240 end
2241 end
2242
2243 writeToLog("Done processing timerEvent with ID "..timerID..".",2)
2244end
2245
2246function processClickEvent(monitorName,x,y)
2247 writeToLog("Processing click event.",2)
2248 local monID
2249 for name,data in pairs(monitors) do
2250 if monitorName==data["networkID"] then
2251 monID = name
2252 break
2253 end
2254 if monitorName==data["side"] and data["networkID"]=="NONE" then
2255 monID = name
2256 break
2257 end
2258 end
2259 if (monitorName==terminalID and terminalScreen~=nil) or (monitors[monID]~=nil and monitors[monID]["screen"]~=nil) then
2260 local s = nil
2261 local screenID = nil
2262 if monitorName==terminalID then
2263 s = x..":"..y
2264 screenID = terminalScreen
2265 else
2266 s = x-monitors[monID]["offsetX"]..":"..y-monitors[monID]["offsetY"]
2267 screenID = monitors[monID]["screen"]
2268 end
2269
2270 local data = screens[screenID]["pixelMatrix"][s]
2271 if data~=nil then
2272 local elementType = data["elementType"]
2273 local ID = data["elementID"]
2274 local part = data["part"]
2275
2276 --button
2277 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="toggle" then
2278 dynamicTextBoxes[ID]["active"] = not dynamicTextBoxes[ID]["active"]
2279 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2280 if dynamicTextBoxes[ID]["active"] then
2281 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2282 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2283 if success then
2284 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2285 else
2286 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2287 end
2288 end
2289 end
2290 if not dynamicTextBoxes[ID]["active"] then
2291 if dynamicTextBoxes[ID]["onInactiveFunction"]~=nil then
2292 success,msg = pcall(dynamicTextBoxes[ID]["onInactiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2293 if success then
2294 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..ID..".",1)
2295 else
2296 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2297 end
2298 end
2299 end
2300 refresh()
2301 end
2302 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="flash" and not dynamicTextBoxes[ID]["active"] then
2303 dynamicTextBoxes[ID]["active"] = true
2304 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2305 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2306 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2307 if success then
2308 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2309 else
2310 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2311 end
2312 end
2313 refresh()
2314 if dynamicTextBoxes[ID]["activeDuration"]~=nil then
2315 writeToLog("Starting timer of dynamicTextBox "..ID..".",1)
2316 dynamicTextBoxes[ID]["timerID"] = os.startTimer(dynamicTextBoxes[ID]["activeDuration"])
2317 else
2318 writeToLog("Even though mode of dynamicTextBox "..ID.." is 'flash', activeDuration is not defined!",2)
2319 dynamicTextBoxes[ID]["timerID"] = os.startTimer(0)
2320 end
2321 end
2322
2323 --slider
2324 if elementType=="slider" and sliders[ID]["enabled"] then
2325 if part=="incrementButton" then
2326 if sliders[ID]["value"]~=sliders[ID]["length"] then
2327 sliders[ID]["value"] = sliders[ID]["value"] + 1
2328 writeToLog("Incremented value of slider "..ID.." because of click event.",2)
2329 if sliders[ID]["onChangeFunction"]~=nil then
2330 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2331 if success then
2332 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2333 else
2334 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2335 end
2336 end
2337 refresh()
2338 end
2339 end
2340 if part=="decrementButton" then
2341 if sliders[ID]["value"]~=1 then
2342 sliders[ID]["value"] = sliders[ID]["value"] - 1
2343 writeToLog("Decremented value of slider "..ID.." because of click event.",2)
2344 if sliders[ID]["onChangeFunction"]~=nil then
2345 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2346 if success then
2347 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2348 else
2349 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2350 end
2351 end
2352 refresh()
2353 end
2354 end
2355 if string.match(part,"bar") then
2356 local index = tonumber(string.sub(part,5))
2357 if index~=sliders[ID]["value"] then
2358 sliders[ID]["value"] = index
2359 writeToLog("Changed value of slider "..ID.." because of click event.",2)
2360 if sliders[ID]["onChangeFunction"]~=nil then
2361 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2362 if success then
2363 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2364 else
2365 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2366 end
2367 end
2368 refresh()
2369 end
2370 end
2371 end
2372
2373 --dropdownmenus
2374 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] then
2375 if part=="collapseButton" then
2376 dropDownMenus[ID]["expanded"] = false
2377 dropDownMenus[ID]["scrollPositionIndex"] = nil
2378 dropDownMenus[ID]["highlightID"] = nil
2379 writeToLog("Collapsed dropDownMenu "..ID.." because of click event.",2)
2380 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2381 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2382 if success then
2383 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2384 else
2385 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2386 end
2387 end
2388 refresh()
2389 end
2390 if (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2391 dropDownMenus[ID]["expanded"] = true
2392 writeToLog("Expanded dropDownMenu "..ID.." because of click event.",2)
2393 if dropDownMenus[ID]["onExpandFunction"]~=nil then
2394 success,msg = pcall(dropDownMenus[ID]["onExpandFunction"],ID,dropDownMenus[ID]["expanded"])
2395 if success then
2396 writeToLog("Successfully called onExpandFunction of dropDownMenu "..ID..".",1)
2397 else
2398 writeToLog("There was an error calling the onExpandFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2399 end
2400 end
2401 refresh()
2402 end
2403 if part=="scrollUpButton" then
2404 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2405 writeToLog("Scrolled up dropDownMenu "..ID.." because of click event.",2)
2406 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2407 refresh()
2408 end
2409 end
2410 if part=="scrollDownButton" then
2411 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2412 writeToLog("Scrolled down dropDownMenu "..ID.." because of click event.",2)
2413 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2414 refresh()
2415 end
2416 end
2417 if string.match(part,"entry") then
2418 local index = tonumber(string.sub(part,7))
2419 if index==dropDownMenus[ID]["highlightID"] then
2420 dropDownMenus[ID]["selectionID"] = index
2421 dropDownMenus[ID]["highlightID"] = nil
2422 dropDownMenus[ID]["scrollPositionIndex"] = nil
2423 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of click event.",2)
2424 dropDownMenus[ID]["expanded"] = false
2425 writeToLog("Collapsed dropDownMenu "..ID.." because of selection.",2)
2426 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2427 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2428 if success then
2429 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2430 else
2431 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2432 end
2433 end
2434
2435 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2436 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2437 if success then
2438 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2439 else
2440 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2441 end
2442 end
2443 refresh()
2444 else
2445 if dropDownMenus[ID]["highlightID"]~=index then
2446 dropDownMenus[ID]["highlightID"] = index
2447 writeToLog("Changed highlightID of dropDownMenu "..ID.." because of click event.",2)
2448 refresh()
2449 end
2450 end
2451 end
2452 end
2453
2454 --navMenus
2455 if elementType=="navigationMenu" and navigationMenus[ID]["enabled"] then
2456 if string.match(part,"title") then
2457 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2458 navigationMenus[ID]["highlightIDs"] = nil
2459 writeToLog("Expanded navMenu "..ID.." because of click event.",2)
2460 refresh()
2461 end
2462 if string.match(part,"entry") then
2463 local s = string.sub(part,7)
2464 local level = string.sub(s,1,string.find(s,":")-1)
2465 local entry = string.sub(s,string.find(s,":")+1)
2466 if tonumber(level)==1 then
2467 if navigationMenus[ID]["menuArray"][tonumber(entry)]["submenu"]~=nil then
2468 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2469 local i = 1
2470 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2471 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2472 i = i + 1
2473 end
2474 writeToLog("Opened submenu on level 2 for navMenu "..ID..".",2)
2475 else
2476 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2477 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2478 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2479 if navigationMenus[ID]["onChangeFunction"]~=nil then
2480 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2481 if success then
2482 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2483 else
2484 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2485 end
2486 end
2487 navigationMenus[ID]["highlightIDs"] = nil
2488 end
2489 else
2490 array = navigationMenus[ID]["menuArray"]
2491
2492 for i=1,tonumber(level)-1 do
2493 array = array[navigationMenus[ID]["highlightIDs"][i]]["submenu"]
2494 end
2495
2496 if array[tonumber(entry)]["submenu"]~=nil then
2497 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2498 local i = 1
2499 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2500 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2501 i = i + 1
2502 end
2503 writeToLog("Opened submenu on level "..(tonumber(level)+1).." for navMenu "..ID..".",2)
2504 else
2505 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2506 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2507 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2508 if navigationMenus[ID]["onChangeFunction"]~=nil then
2509 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2510 if success then
2511 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2512 else
2513 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2514 end
2515 end
2516 navigationMenus[ID]["highlightIDs"] = nil
2517 end
2518 end
2519 refresh()
2520 end
2521 end
2522
2523 --colorpicker
2524 if elementType=="colorPicker" and colorPickers[ID]["enabled"] then
2525 if part~="border" then
2526 if colorPickers[ID]["selection"]~=part then
2527 colorPickers[ID]["selection"] = part
2528 writeToLog("Changed selection of colorPicker "..ID.." because of clickEvent.",2)
2529 refresh()
2530 if colorPickers[ID]["onChangeFunction"]~=nil then
2531 success,msg = pcall(colorPickers[ID]["onChangeFunction"],ID,colorPickers[ID]["selection"])
2532 if success then
2533 writeToLog("Successfully called onChangeFunction of colorPicker "..ID..".",1)
2534 else
2535 writeToLog("There was an error calling onChangeFunction of colorPicker "..ID..". Error message: "..msg,4)
2536 end
2537 end
2538 end
2539 end
2540 end
2541
2542 if processClickEventFunc~=nil then
2543 success,msg = pcall(processClickEventFunc,elementType,ID,part)
2544 if success then
2545 writeToLog("Successfully called processClickEventFunction.",1)
2546 else
2547 writeToLog("There was an error calling the processClickEventFunction. Error message: "..msg,4)
2548 end
2549 end
2550 end
2551 end
2552 writeToLog("Done processing click event.",2)
2553end
2554
2555--function to change any property from any element
2556function changeProperty(ID, propName, propValue)
2557 if elements[getType(ID)]~=nil then
2558 if elements[getType(ID)][ID]~=nil then
2559 elements[getType(ID)][ID][propName] = propValue
2560 writeToLog("Changed property of element "..ID..".",2)
2561 else
2562 writeToLog("Could not change property of element "..ID..". Element was not found. ",3)
2563 end
2564 end
2565end
2566
2567--function to get any property from any element
2568function getProperty(ID, propName)
2569 if elements[getType(ID)]~=nil then
2570 if elements[getType(ID)][ID]~=nil then
2571 return elements[getType(ID)][ID][propName]
2572 end
2573 end
2574end
2575
2576function getType(elementID)
2577 for name,data in pairs(dynamicTextBoxes) do
2578 if elementID==name then
2579 return "dynTextBox"
2580 end
2581 end
2582
2583 for name,data in pairs(sliders) do
2584 if elementID==name then
2585 return "slider"
2586 end
2587 end
2588
2589 for name,data in pairs(dropDownMenus) do
2590 if elementID==name then
2591 return "dropDownMenu"
2592 end
2593 end
2594
2595 for name,data in pairs(navigationMenus) do
2596 if elementID==name then
2597 return "navMenu"
2598 end
2599 end
2600
2601 for name,data in pairs(colorPickers) do
2602 if elementID==name then
2603 return "colorPicker"
2604 end
2605 end
2606
2607 for name,data in pairs(progressBars) do
2608 if elementID==name then
2609 return "progressBar"
2610 end
2611 end
2612
2613 for name,data in pairs(coordinateSystems) do
2614 if elementID==name then
2615 return "coordsSystem"
2616 end
2617 end
2618
2619 for name,data in pairs(pictures) do
2620 if elementID==name then
2621 return "picture"
2622 end
2623 end
2624
2625 return ""
2626end
2627
2628--DynamicTextBoxes from here
2629--DynamicTextBoxes all properties: width, height, content, variables, textColor, textAlignmentHorizontal, textAlignmentVertical, BGColor, borderColor, onActiveFunction, onInactiveFunction, onClickMode, activeDuration, activeContent, activeTextColor, activeBGColor, activeBorderColor, borderThickness, active, timerID, visible, enabled
2630function addDynamicTextBox(id, content)
2631 if trackID(id) then
2632 dynamicTextBoxes[id] = {}
2633 dynamicTextBoxes[id]["content"] = content
2634 dynamicTextBoxes[id]["visible"] = true
2635 dynamicTextBoxes[id]["enabled"] = true
2636 writeToLog("Added dynamicTextBox "..id..".",2)
2637 else
2638 writeToLog("Did not add dynamicTextBox because of ID conflict.",3)
2639 end
2640end
2641
2642--internal function used to draw a dynamic text box on a monitor
2643function writeDynamicTextBoxToPixelMatrix(screenID,dynamicTextBoxID,x,y)
2644 local data = dynamicTextBoxes[dynamicTextBoxID]
2645
2646 local content
2647 local textLines = {}
2648 local nTextLines
2649 local textColor
2650 local BGColor
2651 local borderColor
2652 local borderThickness
2653 local textAlignmentHorizontal
2654 local textAlignmentVertical
2655
2656 --standard value for horizontal alignment is center
2657 if data["textAlignmentHorizontal"]~=nil then
2658 textAlignmentHorizontal = data["textAlignmentHorizontal"]
2659 else
2660 textAlignmentHorizontal = "center"
2661 end
2662
2663 --standard value for vertical alignment is center
2664 if data["textAlignmentVertical"]~=nil then
2665 textAlignmentVertical = data["textAlignmentVertical"]
2666 else
2667 textAlignmentVertical = "center"
2668 end
2669
2670 --if no borderThickness is specified, assign the variable a zero value
2671 if data["borderThickness"]~=nil then
2672 borderThickness = data["borderThickness"]
2673 else
2674 borderThickness = 0
2675 end
2676
2677 --take care of all of the colors
2678 --if the button is active, colors might be different
2679 if data["active"] then
2680 if data["activeContent"]~=nil then
2681 content = data["activeContent"]
2682 else
2683 content = data["content"]
2684 end
2685 if data["activeTextColor"]~=nil then
2686 textColor = data["activeTextColor"]
2687 else
2688 textColor = data["textColor"]
2689 end
2690 if data["activeBGColor"]~=nil then
2691 BGColor = data["activeBGColor"]
2692 else
2693 BGColor = data["BGColor"]
2694 end
2695 if data["activeBorderColor"]~=nil then
2696 borderColor = data["activeBorderColor"]
2697 else
2698 borderColor = data["borderColor"]
2699 end
2700 else
2701 content = data["content"]
2702 textColor = data["textColor"]
2703 BGColor = data["BGColor"]
2704 borderColor = data["borderColor"]
2705 end
2706
2707 --if no colors are specified, use default colors of the corresponding screen
2708 if BGColor==nil then
2709 BGColor = screens[screenID]["defaultBGColor"]
2710 end
2711 if textColor==nil then
2712 textColor = screens[screenID]["defaultTextColor"]
2713 end
2714
2715 --if no bordercolor is specified, use the background color
2716 if borderColor==nil then
2717 borderColor = BGColor
2718 end
2719
2720 --replace variable placeholder with values
2721 if data["variables"]~=nil then
2722 for name, variableData in pairs(data["variables"]) do
2723 if data["variables"][name]~=nil then
2724 if type(data["variables"][name])=="function" then
2725 success,text = pcall(data["variables"][name],dynamicTextBoxID,name)
2726 if success then
2727 content = string.gsub(content,"$"..name,text)
2728 else
2729 writeToLog("There was an error retrieving variable "..name.." for dynamicTextBox "..dynamicTextBoxID..". Error message: "..text,4)
2730 end
2731 else if type(data["variables"][name])=="string" or type(data["variables"][name])=="number" then
2732 content = string.gsub(content,"$"..name,data["variables"][name])
2733 end end
2734 end
2735 end
2736 end
2737
2738 local maxX
2739 local maxY
2740
2741 if data["width"]~=nil then
2742 --if a width is specified the following variable is the maxX value
2743 maxX = x + data["width"] - 1
2744 --check if the content fits in one line with the specified width
2745 if string.len(content)<=(data["width"] - borderThickness*2) then
2746 textLines[1] = content
2747 nTextLines = 1
2748 end
2749 --if it does not fit, text will be split down below
2750 else
2751 --check if it fits in one line, assuming maxX is the monitors sizeX
2752 if string.len(content)<=(screens[screenID]["sizeX"]-x+1-(borderThickness*2)) then
2753 textLines[1] = content
2754 nTextLines = 1
2755 maxX = x + string.len(content) + borderThickness*2 - 1
2756 else
2757 --if it does not fit, text will be split down below
2758 maxX = screens[screenID]["sizeX"]
2759 end
2760 end
2761
2762 --variable used to determine the space for text on the dynamicTextBox
2763 local spaceX = maxX - x + 1 - borderThickness*2
2764
2765 --split text into lines
2766 if nTextLines~=1 then
2767 local words = {}
2768 --find spaces in the content string and use string.sub accordingly to create a list of words only
2769 local index = string.find(content," ")
2770 if index~=nil then
2771 repeat
2772 --insert the word into the table
2773 table.insert(words,string.sub(content,1,index-1))
2774 --remove the content that is already dealt with
2775 content = string.sub(content,index+1)
2776 index = string.find(content," ")
2777 until index==nil
2778 table.insert(words,content)
2779 else
2780 --in this case the content is one word alone
2781 table.insert(words,content)
2782 end
2783
2784 --create lines out of the words
2785 local sBuffer = ""
2786 for i,word in ipairs(words) do
2787 --the line is complete under three conditions: buffer not empty, current word added would be too long, current word is not longer than spaceX
2788 --it is also complete when it has the same length as spaceX or one less (space at the end) and the buffer is not empty
2789 --if the current word is longer than spaceX anyway, it can start in the current line and break subsequently
2790 if sBuffer~="" and ((string.len(sBuffer.." "..word)>spaceX and string.len(word)<=spaceX) or string.len(sBuffer)>=spaceX-1) then
2791 table.insert(textLines,sBuffer)
2792 sBuffer = ""
2793 end
2794
2795 --split down too long words
2796 while string.len(word)>spaceX do
2797 if sBuffer == "" then
2798 --if the buffer is empty, simply insert the first 'spaceX' letters of the word
2799 table.insert(textLines,string.sub(word,1,spaceX))
2800 word = string.sub(word,spaceX+1)
2801 sBuffer = ""
2802 else
2803 --otherwise, add as many letters as still fit in the line (spaceX-lengthOfBuffer-space)
2804 table.insert(textLines,sBuffer.." "..string.sub(word,1,spaceX-string.len(sBuffer)-1))
2805 word = string.sub(word,spaceX-string.len(sBuffer)-1+1)
2806 sBuffer = ""
2807 end
2808 end
2809
2810 --add the word to the buffer accordingly
2811 if sBuffer=="" then
2812 sBuffer = word
2813 else
2814 sBuffer = sBuffer.." "..word
2815 end
2816 end
2817
2818 --there can be one bit left at the end if it was a too long word
2819 if sBuffer~="" then
2820 table.insert(textLines,sBuffer)
2821 end
2822
2823 nTextLines = table.getn(textLines)
2824 end
2825
2826 if data["height"]~=nil then
2827 --if a height is specified, calculate maxY in the following variable
2828 maxY = y + data["height"] - 1
2829 --check if the lines fit with the given height
2830 if nTextLines>(data["height"] - borderThickness*2) then
2831 --in this case they don't, therefore use as many lines as there is space
2832 nTextLines = data["height"] - borderThickness*2
2833 end
2834 else
2835 --no height is specified therefore calculate maxY with as many lines as needed
2836 maxY = y + nTextLines + borderThickness*2 - 1
2837 --check if maxY is now bigger than the actual monitor's maxY
2838 if maxY>screens[screenID]["sizeY"] then
2839 --in this case it is bigger therefore maxY needs to be adjusted as well as the number of textLines
2840 maxY = screens[screenID]["sizeY"]
2841 nTextLines = maxY - y + 1 - borderThickness*2
2842 end
2843 end
2844
2845 --calculate the space for the text in y direction to be used later on
2846 local spaceY = maxY - y + 1 - borderThickness*2
2847
2848 --start drawing
2849 --border
2850 for currentOffset=0,borderThickness-1 do
2851 --this draws two horizontal lines
2852 for currentX=(x+currentOffset),(maxX-currentOffset) do
2853 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2854 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2855 end
2856
2857 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
2858 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
2859 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2860 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2861 end
2862 end
2863
2864 --draw the BGColor, offset by the borderThickness
2865 for currentX=(x+borderThickness),(maxX-borderThickness) do
2866 for currentY=(y+borderThickness),(maxY-borderThickness) do
2867 writeToPixelMatrix(screenID," ",currentX,currentY,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","BG")
2868 end
2869 end
2870
2871 --draw the text
2872 --calculate vertical offset
2873 local startOffsetY
2874 if textAlignmentVertical=="center" then
2875 --if vertical alignment is center, calculate the corresponding offset
2876 startOffsetY = math.floor((spaceY-nTextLines)/2)
2877 else
2878 if textAlignmentVertical=="top" then
2879 --no offset for top alignment
2880 startOffsetY = 0
2881 else
2882 if textAlignmentVertical=="bottom" then
2883 --calculate offsetY if alignment is bottom
2884 startOffsetY = spaceY - nTextLines
2885 end
2886 end
2887 end
2888
2889 local startOffsetX = {}
2890 --deal with horizontal alignment, calculate an offset for each line
2891 if textAlignmentHorizontal=="right" then
2892 for i,line in ipairs(textLines) do
2893 --calculate number for right alignment
2894 startOffsetX[i] = spaceX-string.len(line)
2895 end
2896 else
2897 if textAlignmentHorizontal=="center" then
2898 for i,line in ipairs(textLines) do
2899 --calculate number for center horizontal alignment
2900 startOffsetX[i] = math.floor((spaceX-string.len(line))/2)
2901 end
2902 else
2903 for i,line in ipairs(textLines) do
2904 --no offset needed for left alignment
2905 startOffsetX[i] = 0
2906 end
2907 end
2908 end
2909
2910 --write text, offset by borderThickness
2911 for i=1,nTextLines do
2912 writeToPixelMatrix(screenID,textLines[i],x+borderThickness+startOffsetX[i],y+borderThickness+startOffsetY+i-1,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","text")
2913 end
2914end
2915
2916--Sliders from here
2917--Sliders all properties: length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
2918function addSlider(id,length, value)
2919 if trackID(id) then
2920 sliders[id] = {}
2921 sliders[id]["length"] = length
2922 sliders[id]["value"] = value
2923 sliders[id]["visible"] = true
2924 sliders[id]["enabled"] = true
2925 writeToLog("Added slider "..id..".",2)
2926 else
2927 writeToLog("Did not add slider because of ID conflict.",3)
2928 end
2929end
2930
2931--function which draws a slider in the pixel matrix
2932function writeSliderToPixelMatrix(screenID,sliderID,x,y)
2933 local data = sliders[sliderID]
2934
2935 local length = data["length"]
2936 local value = math.floor(tonumber(data["value"]))
2937 local broadness
2938 local orientation
2939 local pixelsPerUnit
2940 local color
2941 local colorsArray
2942 local textPosition = data["textPosition"]
2943 local textMargin
2944 local BGColor
2945 local borderColor
2946 local borderThickness
2947 local mode
2948 local changeButtons
2949
2950 --take care of all variable defaults
2951 if data["broadness"]~=nil then
2952 broadness = data["broadness"]
2953 else
2954 broadness = 1
2955 end
2956
2957 if data["orientation"]~=nil then
2958 orientation = data["orientation"]
2959 else
2960 orientation = "left-right"
2961 end
2962
2963 if data["pixelsPerUnit"]~=nil then
2964 pixelsPerUnit = data["pixelsPerUnit"]
2965 else
2966 pixelsPerUnit = 1
2967 end
2968
2969 if data["color"]~=nil then
2970 color = data["color"]
2971 else
2972 color = screens[screenID]["defaultTextColor"]
2973 end
2974
2975 if data["colorsArray"]~=nil then
2976 if data["colorsArray"][value]~=nil then
2977 color = data["colorsArray"][value]
2978 end
2979 end
2980
2981 if data["textMargin"]~=nil then
2982 textMargin = data["textMargin"]
2983 else
2984 textMargin = 0
2985 end
2986
2987 if data["BGColor"]~=nil then
2988 BGColor = data["BGColor"]
2989 else
2990 BGColor = screens[screenID]["defaultBGColor"]
2991 end
2992
2993 if data["borderColor"]~=nil then
2994 borderColor = data["borderColor"]
2995 else
2996 borderColor = BGColor
2997 end
2998
2999 if data["borderThickness"]~=nil then
3000 borderThickness = data["borderThickness"]
3001 else
3002 borderThickness = 0
3003 end
3004
3005 if data["mode"]~=nil then
3006 mode = data["mode"]
3007 else
3008 mode = "fill"
3009 end
3010
3011 changeButtons = data["changeButtons"]
3012
3013 local maxX
3014 local maxY
3015
3016 --calculate maxX and maxY based on the orientation of slider
3017 if orientation=="left-right" or orientation=="right-left" then
3018 maxX = x + borderThickness*2 + length*pixelsPerUnit - 1
3019 maxY = y + borderThickness*2 + broadness - 1
3020 else
3021 maxX = x + borderThickness*2 + broadness - 1
3022 maxY = y + borderThickness*2 + length*pixelsPerUnit - 1
3023 end
3024
3025 --start drawing
3026 --border
3027 for currentOffset=0,borderThickness-1 do
3028 --this draws two horizontal lines
3029 for currentX=(x+currentOffset),(maxX-currentOffset) do
3030 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,sliderID,"slider","border")
3031 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,sliderID,"slider","border")
3032 end
3033
3034 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3035 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3036 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3037 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3038 end
3039 end
3040
3041 --draw bar case horizontal
3042 if orientation=="left-right" or orientation=="right-left" then
3043 --this makes things easier
3044 local s = ""
3045 for i=1,pixelsPerUnit do
3046 s = s.." "
3047 end
3048 --loop for x coordinate (length)
3049 for i=1,length do
3050 --change color according to slider value
3051 --check mode
3052 local currentColor
3053 if mode=="fill" then
3054 if i<=value then
3055 currentColor = color
3056 else
3057 currentColor = BGColor
3058 end
3059 end
3060 if mode=="value" then
3061 if i==value then
3062 currentColor = color
3063 else
3064 currentColor = BGColor
3065 end
3066 end
3067 --loop for y coordinate (broadness)
3068 for currentY=y+borderThickness,maxY-borderThickness do
3069 --take pixelsPerUnit into account for calculations
3070 if orientation=="left-right" then
3071 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3072 end
3073 if orientation=="right-left" then
3074 writeToPixelMatrix(screenID,s,maxX-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3075 end
3076 end
3077 end
3078 else
3079 --this makes things easier
3080 local s = ""
3081 for i=1,broadness do
3082 s = s.." "
3083 end
3084 --draw bar case vertical
3085 --loop for y coordinate (length)
3086 for i=1,length do
3087 local currentColor
3088 if mode=="fill" then
3089 if i<=value then
3090 currentColor = color
3091 else
3092 currentColor = BGColor
3093 end
3094 end
3095 if mode=="value" then
3096 if i==value then
3097 currentColor = color
3098 else
3099 currentColor = BGColor
3100 end
3101 end
3102 --loop for x coordinate (broadness)
3103 for j=1,pixelsPerUnit do
3104 if orientation=="top-bottom" then
3105 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3106 end
3107 if orientation=="bottom-top" then
3108 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3109 end
3110 end
3111 end
3112 end
3113
3114 --this fixes rounding issue
3115 value = tostring(value)
3116 --draw text
3117 if textPosition~=nil then
3118 --calculations to center the text
3119 if textPosition=="right" then
3120 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3121 end
3122 if textPosition=="left" then
3123 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3124 end
3125 if textPosition=="top" then
3126 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3127 end
3128 if textPosition=="bottom" then
3129 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3130 end
3131 end
3132
3133 --if defined, draws an increment and decrement button according to slider orientation
3134 if changeButtons~=nil then
3135 if orientation=="left-right" then
3136 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3137 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3138 end
3139 if orientation=="right-left" then
3140 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3141 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3142 end
3143 if orientation=="bottom-top" then
3144 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3145 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3146 end
3147 if orientation=="top-bottom" then
3148 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3149 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3150 end
3151 end
3152end
3153
3154--Dropdownmenus from here
3155--All properties: entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
3156function addDropDownMenu(id,entries,selectionID)
3157 if trackID(id) then
3158 dropDownMenus[id] = {}
3159 dropDownMenus[id]["entries"] = entries
3160 dropDownMenus[id]["selectionID"] = selectionID
3161 dropDownMenus[id]["visible"] = true
3162 dropDownMenus[id]["enabled"] = true
3163 dropDownMenus[id]["expanded"] = false
3164 writeToLog("Added dropDownMenu "..id..".",2)
3165 else
3166 writeToLog("Did not add dropDownMenu because of ID conflict.",3)
3167 end
3168end
3169
3170function writeDropDownMenuToPixelMatrix(screenID,dropDownMenuID,x,y)
3171 local data = dropDownMenus[dropDownMenuID]
3172
3173 local entries = data["entries"]
3174 local selectionID = data["selectionID"]
3175 local expanded = data["expanded"]
3176 local width
3177 local textColor
3178 local BGColor
3179 local borderColor
3180 local borderThickness
3181 local highlightTextColor
3182 local highlightBGColor
3183 local highlightID = data["highlightID"]
3184 local scrollPositionIndex = data["scrollPositionIndex"]
3185 local buttonsColor
3186 local buttonsBGColor
3187
3188 --take care of the colors and set other default values
3189 if data["textColor"]~=nil then
3190 textColor = data["textColor"]
3191 else
3192 textColor = screens[screenID]["defaultTextColor"]
3193 end
3194
3195 if data["BGColor"]~=nil then
3196 BGColor = data["BGColor"]
3197 else
3198 BGColor = screens[screenID]["defaultBGColor"]
3199 end
3200
3201 if data["borderColor"]~=nil then
3202 borderColor = data["borderColor"]
3203 else
3204 borderColor = BGColor
3205 end
3206
3207 if data["borderThickness"]~=nil then
3208 borderThickness = data["borderThickness"]
3209 else
3210 borderThickness = 0
3211 end
3212
3213 if data["highlightTextColor"]~=nil then
3214 highlightTextColor = data["highlightTextColor"]
3215 else
3216 highlightTextColor = textColor
3217 end
3218
3219 if data["highlightBGColor"]~=nil then
3220 highlightBGColor = data["highlightBGColor"]
3221 else
3222 highlightBGColor = BGColor
3223 end
3224
3225 if data["buttonsColor"]~=nil then
3226 buttonsColor = data["buttonsColor"]
3227 else
3228 buttonsColor = textColor
3229 end
3230
3231 if data["buttonsBGColor"]~=nil then
3232 buttonsBGColor = data["buttonsBGColor"]
3233 else
3234 buttonsBGColor = BGColor
3235 end
3236
3237 --calculate greatestTextLength to later define a width if its not specified
3238 local greatestTextLength = 0
3239 for name,entry in pairs(entries) do
3240 if string.len(entry)>greatestTextLength then
3241 greatestTextLength = string.len(entry)
3242 end
3243 end
3244
3245 --fill this array with entries and manipulate later
3246 local shortenedEntries = {}
3247 for i,entry in ipairs(entries) do
3248 shortenedEntries[i] = entry
3249 end
3250 local nEntries = table.getn(entries)
3251 if data["width"]~=nil then
3252 width = data["width"]
3253 --two pixel space: one for v and one for a space (or space + scrollbar)
3254 if greatestTextLength>width-borderThickness*2-2 then
3255 --shorten entries if necessary
3256 for i,entry in ipairs(entries) do
3257 shortenedEntries[i] = string.sub(entry,1,width-borderThickness*2-2)
3258 end
3259 end
3260 else
3261 if greatestTextLength>screens[screenID]["sizeX"]-x-borderThickness*2+1-2 then
3262 --shorten entries if necessary
3263 for i,entry in ipairs(entries) do
3264 shortenedEntries[i] = string.sub(entry,1,screens[screenID]["sizeX"]-x-borderThickness*2+1-2)
3265 end
3266 width = screens[screenID]["sizeX"]-x+1
3267 else
3268 --as wide as it needs
3269 width = borderThickness*2+greatestTextLength + 2
3270 end
3271 end
3272
3273 local maxX = x + width - 1
3274
3275 --draw collapsed menu
3276 if not expanded then
3277 local maxY = y + borderThickness*2
3278 --start drawing
3279 --border
3280 for currentOffset=0,borderThickness-1 do
3281 --this draws two horizontal lines
3282 for currentX=(x+currentOffset),(maxX-currentOffset) do
3283 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3284 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3285 end
3286
3287 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3288 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3289 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3290 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3291 end
3292 end
3293
3294 --draw the BGColor, offset by the borderThickness
3295 for currentX=(x+borderThickness),(maxX-borderThickness) do
3296 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3297 end
3298
3299 --draw text
3300 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3301
3302 --draw v (expandbutton)
3303 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","expandButton")
3304 else
3305 --determine if a scrollbar is necessary
3306 local scrollBar
3307 local maxY
3308 if highlightID ==nil then
3309 highlightID = selectionID
3310 end
3311 dropDownMenus[dropDownMenuID]["highlightID"] = highlightID
3312 if data["expandedMaxHeight"]~=nil then
3313 local expandedMaxHeight = data["expandedMaxHeight"]
3314 --check if all entries fit with the given height
3315 if borderThickness*2 + 1 + nEntries > expandedMaxHeight then
3316 maxY = y+expandedMaxHeight-1
3317 scrollBar = true
3318 else
3319 --as wide as it needs
3320 maxY = y + borderThickness*2 + 1 + nEntries -1
3321 scrollBar = false
3322 end
3323 else
3324 --with no specified height, check if the full list would be greater than screen size
3325 if y + borderThickness*2 +1 + nEntries - 1>screens[screenID]["sizeY"] then
3326 maxY = screens[screenID]["sizeY"]
3327 scrollBar = true
3328 else
3329 maxY = y + borderThickness*2 + 1 + nEntries - 1
3330 scrollBar = false
3331 end
3332 end
3333
3334 --draw the BGColor, offset by the borderThickness
3335 for currentX=(x+borderThickness),(maxX-borderThickness) do
3336 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3337 end
3338
3339 --draw text
3340 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3341
3342 --draw v
3343 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","collapseButton")
3344
3345 --draw list without scrollbar
3346 if not scrollBar then
3347 --entries need to be spaced in order to fill the whole line
3348 local spacedEntries = {}
3349 for i,entry in ipairs(shortenedEntries) do
3350 local s = ""
3351 for j=1,width-borderThickness*2-string.len(entry) do
3352 s = s.." "
3353 end
3354 spacedEntries[i] = entry..s
3355 end
3356 for i,entry in ipairs(spacedEntries) do
3357 --change color accordingly
3358 local currentTextColor
3359 local currentBGColor
3360 if i==highlightID then
3361 currentTextColor = highlightTextColor
3362 currentBGColor = highlightBGColor
3363 else
3364 currentTextColor = textColor
3365 currentBGColor = BGColor
3366 end
3367 writeToPixelMatrix(screenID,entry,x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i)
3368 end
3369 else
3370 local spacedEntries = {}
3371 for i,entry in ipairs(shortenedEntries) do
3372 local s = ""
3373 --this time -1 because of scrollbar
3374 for j=1,width-borderThickness*2-string.len(entry)-1 do
3375 s = s.." "
3376 end
3377 spacedEntries[i] = entry..s
3378 end
3379 local spaceY = maxY-y+1-borderThickness*2-1
3380 dropDownMenus[dropDownMenuID]["spaceY"] = spaceY
3381 --set scrollposition if menu was just opened
3382 if scrollPositionIndex==nil then
3383 --make sure not to overrun
3384 if selectionID>nEntries-spaceY then
3385 scrollPositionIndex = nEntries-spaceY+1
3386 else
3387 scrollPositionIndex = selectionID
3388 end
3389
3390 --set for next time
3391 dropDownMenus[dropDownMenuID]["scrollPositionIndex"] = scrollPositionIndex
3392 end
3393
3394 for i=1,spaceY do
3395 local currentTextColor
3396 local currentBGColor
3397 if i+scrollPositionIndex-1==highlightID then
3398 currentTextColor = highlightTextColor
3399 currentBGColor = highlightBGColor
3400 else
3401 currentTextColor = textColor
3402 currentBGColor = BGColor
3403 end
3404
3405 --this is a workaround for a very special case where one dropDownMenu is displayed on different screens with different space
3406 if spacedEntries[i+scrollPositionIndex-1]==nil then
3407 maxY = y+borderThickness+i
3408 break
3409 else
3410 writeToPixelMatrix(screenID,spacedEntries[i+scrollPositionIndex-1],x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i+scrollPositionIndex-1)
3411 end
3412 end
3413
3414 --draw scrollbar buttons and bg
3415 local scrollBarX = maxX-1
3416 for currentY=y+borderThickness+1,maxY-1 do
3417 if currentY==y+borderThickness+1 then
3418 writeToPixelMatrix(screenID,"^",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollUpButton")
3419 else if currentY==maxY-1 then
3420 writeToPixelMatrix(screenID,"v",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollDownButton")
3421 else
3422 writeToPixelMatrix(screenID," ",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollBarBG")
3423 end
3424 end
3425 end
3426 end
3427
3428 --draw border
3429 for currentOffset=0,borderThickness-1 do
3430 --this draws two horizontal lines
3431 for currentX=(x+currentOffset),(maxX-currentOffset) do
3432 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3433 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3434 end
3435
3436 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3437 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3438 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3439 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3440 end
3441 end
3442 end
3443end
3444
3445--navMenus from here
3446-- all props: title,menuArray (text, submenu),titleTextColor,titleBGColor,titleTextColorExpanded,titleBGColorExpanded,textAlignmentHorizontal,textAlignmentVertical,entryWidth,entryHeight,entryTextColor,entryBGColor,borderColor,spaceBetweenEntries,borderThickness,highlightTextColor,highlightBGColor,expanded,highlightIDs,onChangeFunction,enabled,visible
3447function addNavigationMenu(id,title,menuArray)
3448 if trackID(id) then
3449 navigationMenus[id] = {}
3450 navigationMenus[id]["title"] = title
3451 navigationMenus[id]["menuArray"] = menuArray
3452 navigationMenus[id]["visible"] = true
3453 navigationMenus[id]["enabled"] = true
3454 navigationMenus[id]["expanded"] = false
3455 navigationMenus[id]["highlightIDs"] = nil
3456 writeToLog("Added navMenu "..id..".",2)
3457 else
3458 writeToLog("Did not add navMenu because of ID conflict.",3)
3459 end
3460end
3461
3462function writeNavigationMenuToPixelMatrix(screenID,navigationMenuID,x,y)
3463 local data = navigationMenus[navigationMenuID]
3464
3465 local title = data["title"]
3466 local menuArray = data["menuArray"]
3467 local expanded = data["expanded"]
3468 local entryWidth = data["entryWidth"]
3469 local entryHeight
3470 local titleTextColor
3471 local titleBGColor
3472 local titleTextColorExpanded
3473 local titleBGColorExpanded
3474 local entryTextColor
3475 local entryBGColor
3476 local borderColor
3477 local borderThickness
3478 local spaceBetweenEntries
3479 local highlightIDs = data["highlightIDs"]
3480 local highlightTextColor
3481 local highlightBGColor
3482 local expanded = data["expanded"]
3483 local textAlignmentHorizontal
3484 local textAlignmentVertical
3485
3486 --take care of the colors and set other default values
3487 if data["entryTextColor"]~=nil then
3488 entryTextColor = data["entryTextColor"]
3489 else
3490 entryTextColor = screens[screenID]["defaultTextColor"]
3491 end
3492
3493 if data["entryBGColor"]~=nil then
3494 entryBGColor = data["entryBGColor"]
3495 else
3496 entryBGColor = screens[screenID]["defaultBGColor"]
3497 end
3498
3499 if data["titleTextColor"]~=nil then
3500 titleTextColor = data["titleTextColor"]
3501 else
3502 titleTextColor = screens[screenID]["defaultTextColor"]
3503 end
3504
3505 if data["titleBGColor"]~=nil then
3506 titleBGColor = data["titleBGColor"]
3507 else
3508 titleBGColor = screens[screenID]["defaultBGColor"]
3509 end
3510
3511 if data["titleTextColorExpanded"]~=nil then
3512 titleTextColorExpanded = data["titleTextColorExpanded"]
3513 else
3514 titleTextColorExpanded = titleTextColor
3515 end
3516
3517 if data["titleBGColorExpanded"]~=nil then
3518 titleBGColorExpanded = data["titleBGColorExpanded"]
3519 else
3520 titleBGColorExpanded = titleBGColor
3521 end
3522
3523 if data["borderColor"]~=nil then
3524 borderColor = data["borderColor"]
3525 else
3526 borderColor = screens[screenID]["defaultBGColor"]
3527 end
3528
3529 if data["borderThickness"]~=nil then
3530 borderThickness = data["borderThickness"]
3531 else
3532 borderThickness = 0
3533 end
3534
3535 if data["spaceBetweenEntries"]~=nil then
3536 spaceBetweenEntries = data["spaceBetweenEntries"]
3537 else
3538 spaceBetweenEntries = 0
3539 end
3540
3541 if data["highlightTextColor"]~=nil then
3542 highlightTextColor = data["highlightTextColor"]
3543 else
3544 highlightTextColor = entryTextColor
3545 end
3546
3547 if data["highlightBGColor"]~=nil then
3548 highlightBGColor = data["highlightBGColor"]
3549 else
3550 highlightBGColor = entryBGColor
3551 end
3552
3553 if data["entryHeight"]~=nil then
3554 entryHeight = data["entryHeight"]
3555 else
3556 entryHeight = 1
3557 end
3558
3559 --standard value for horizontal alignment is center
3560 if data["textAlignmentHorizontal"]~=nil then
3561 textAlignmentHorizontal = data["textAlignmentHorizontal"]
3562 else
3563 textAlignmentHorizontal = "center"
3564 end
3565
3566 --standard value for vertical alignment is center
3567 if data["textAlignmentVertical"]~=nil then
3568 textAlignmentVertical = data["textAlignmentVertical"]
3569 else
3570 textAlignmentVertical = "center"
3571 end
3572
3573 local greatestRootTextLength = string.len(title)
3574 local rootEntryCount = 0
3575 for name,entry in pairs(menuArray) do
3576 rootEntryCount = rootEntryCount + 1
3577 if string.len(entry["text"])>greatestRootTextLength then
3578 greatestRootTextLength = string.len(entry["text"])
3579 end
3580 end
3581
3582 --fill this array with entries and manipulate later
3583 local nRootEntries = 0
3584 local shortenedEntries = {}
3585 for i,entry in ipairs(menuArray) do
3586 nRootEntries = nRootEntries + 1
3587 shortenedEntries[i] = entry
3588 end
3589
3590 local rootMaxX
3591 if entryWidth~=nil then
3592 rootMaxX = x+borderThickness*2+entryWidth-1
3593 --shorten text
3594 if greatestRootTextLength>entryWidth then
3595 title = string.sub(title,1,entryWidth)
3596 for i,entry in ipairs(shortenedEntries) do
3597 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3598 end
3599 end
3600 else
3601 rootMaxX = x+borderThickness*2+greatestRootTextLength-1
3602 entryWidth = greatestRootTextLength
3603 end
3604
3605 local currentTextColor
3606 local currentBGColor
3607
3608 if expanded then
3609 currentTextColor = titleTextColorExpanded
3610 currentBGColor = titleBGColorExpanded
3611 else
3612 currentTextColor = titleTextColor
3613 currentBGColor = titleBGColor
3614 end
3615
3616 --titleBG
3617 for currentX=(x+borderThickness),(rootMaxX-borderThickness) do
3618 for currentY=(y+borderThickness),(y+borderThickness+entryHeight-1) do
3619 writeToPixelMatrix(screenID," ",currentX,currentY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","titleBG")
3620 end
3621 end
3622
3623 local rootMaxY
3624 if not expanded then
3625 rootMaxY = y+borderThickness*2+entryHeight-1
3626 else
3627 rootMaxY = y+borderThickness*2+entryHeight+((entryHeight+spaceBetweenEntries)*rootEntryCount)-1
3628 end
3629
3630 --draw border
3631 for currentOffset=0,borderThickness-1 do
3632 --this draws two horizontal lines
3633 for currentX=(x+currentOffset),(rootMaxX-currentOffset) do
3634 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3635 writeToPixelMatrix(screenID," ",currentX,rootMaxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3636 end
3637
3638 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3639 for currentY=(y+currentOffset+1),(rootMaxY-currentOffset-1) do
3640 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3641 writeToPixelMatrix(screenID," ",rootMaxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3642 end
3643 end
3644
3645 --calculate vertical offset
3646 local startOffsetY
3647 if textAlignmentVertical=="center" then
3648 --if vertical alignment is center, calculate the corresponding offset
3649 startOffsetY = math.floor((entryHeight-1)/2)
3650 else
3651 if textAlignmentVertical=="top" then
3652 --no offset for top alignment
3653 startOffsetY = 0
3654 else
3655 if textAlignmentVertical=="bottom" then
3656 --calculate offsetY if alignment is bottom
3657 startOffsetY = entryHeight - 1
3658 end
3659 end
3660 end
3661
3662 local startOffsetX = 0
3663 --deal with horizontal alignment, calculate an offset
3664 if textAlignmentHorizontal=="right" then
3665 startOffsetX = entryWidth-string.len(title)
3666 else
3667 if textAlignmentHorizontal=="center" then
3668 --calculate number for center horizontal alignment
3669 startOffsetX = math.floor((entryWidth-string.len(title))/2)
3670 end
3671 end
3672
3673 --write title text
3674 writeToPixelMatrix(screenID,title,x+borderThickness+startOffsetX,y+borderThickness+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","title")
3675
3676 local nextY
3677 if expanded then
3678 -- this makes things easier
3679 local s = ""
3680 for i=1,entryWidth do
3681 s = s.." "
3682 end
3683 --draw entries
3684 for i=1,nRootEntries do
3685 for j=0,spaceBetweenEntries-1 do
3686 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3687 end
3688 local currentTextColor = entryTextColor
3689 local currentBGColor = entryBGColor
3690 if highlightIDs~=nil then
3691 if highlightIDs[1]==i then
3692 currentTextColor = highlightTextColor
3693 currentBGColor = highlightBGColor
3694 --for next submenu
3695 nextY = y+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))
3696 end
3697 end
3698 for j=0,entryHeight-1 do
3699 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3700 end
3701 --calculate vertical offset
3702 local startOffsetY
3703 if textAlignmentVertical=="center" then
3704 --if vertical alignment is center, calculate the corresponding offset
3705 startOffsetY = math.floor((entryHeight-1)/2)
3706 else
3707 if textAlignmentVertical=="top" then
3708 --no offset for top alignment
3709 startOffsetY = 0
3710 else
3711 if textAlignmentVertical=="bottom" then
3712 --calculate offsetY if alignment is bottom
3713 startOffsetY = entryHeight - 1
3714 end
3715 end
3716 end
3717
3718 local startOffsetX = 0
3719 --deal with horizontal alignment, calculate an offset
3720 if textAlignmentHorizontal=="right" then
3721 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3722 else
3723 if textAlignmentHorizontal=="center" then
3724 --calculate number for center horizontal alignment
3725 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3726 end
3727 end
3728
3729 --write title text
3730 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3731 end
3732
3733 --draw submenus
3734 if highlightIDs~=nil then
3735 --like this a lot of code is reused
3736 x = x + borderThickness + entryWidth
3737 y = nextY
3738 local subTable = menuArray[highlightIDs[1]]["submenu"]
3739 for k=1,table.getn(highlightIDs) do
3740 local greatestTextLength = 0
3741 local nEntries = 0
3742 for name,entry in pairs(subTable) do
3743 nEntries = nEntries + 1
3744 if string.len(entry["text"])>greatestTextLength then
3745 greatestTextLength = string.len(entry["text"])
3746 end
3747 end
3748
3749 --fill this array with entries and manipulate later
3750 local shortenedEntries = {}
3751 for i,entry in ipairs(subTable) do
3752 shortenedEntries[i] = entry
3753 end
3754
3755 entryWidth = data["entryWidth"]
3756 local maxX
3757 if entryWidth~=nil then
3758 maxX = x+borderThickness*2+entryWidth-1
3759 --shorten text
3760 if greatestTextLength>entryWidth then
3761 for i,entry in ipairs(shortenedEntries) do
3762 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3763 end
3764 end
3765 else
3766 maxX = x+borderThickness*2+greatestTextLength-1
3767 entryWidth = greatestTextLength
3768 end
3769
3770 -- this makes things easier
3771 local s = ""
3772 for i=1,entryWidth do
3773 s = s.." "
3774 end
3775
3776 local maxY = y + borderThickness*2 + (nEntries)*entryHeight + (nEntries-1)*spaceBetweenEntries - 1
3777
3778 --border
3779 for currentOffset=0,borderThickness-1 do
3780 --this draws two horizontal lines
3781 for currentX=(x+currentOffset),(maxX-currentOffset) do
3782 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3783 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3784 end
3785
3786 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3787 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3788 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3789 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3790 end
3791 end
3792
3793 for i=1,nEntries do
3794 if i~=nEntries then
3795 for j=0,spaceBetweenEntries-1 do
3796 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3797 end
3798 end
3799
3800 local currentTextColor = entryTextColor
3801 local currentBGColor = entryBGColor
3802 if highlightIDs[k+1]==i then
3803 currentTextColor = highlightTextColor
3804 currentBGColor = highlightBGColor
3805 nextY = y+((i-1)*(spaceBetweenEntries+entryHeight))
3806 end
3807 for j=0,entryHeight-1 do
3808 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3809 end
3810 --calculate vertical offset
3811 local startOffsetY
3812 if textAlignmentVertical=="center" then
3813 --if vertical alignment is center, calculate the corresponding offset
3814 startOffsetY = math.floor((entryHeight-1)/2)
3815 else
3816 if textAlignmentVertical=="top" then
3817 --no offset for top alignment
3818 startOffsetY = 0
3819 else
3820 if textAlignmentVertical=="bottom" then
3821 --calculate offsetY if alignment is bottom
3822 startOffsetY = entryHeight - 1
3823 end
3824 end
3825 end
3826
3827 local startOffsetX = 0
3828 --deal with horizontal alignment, calculate an offset
3829 if textAlignmentHorizontal=="right" then
3830 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3831 else
3832 if textAlignmentHorizontal=="center" then
3833 --calculate number for center horizontal alignment
3834 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3835 end
3836 end
3837
3838 --write title text
3839 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3840 end
3841
3842 if highlightIDs[k+1]~=nil then
3843 x = x + borderThickness + entryWidth
3844 y = nextY
3845 subTable = subTable[highlightIDs[k+1]]["submenu"]
3846 end
3847 end
3848 end
3849 end
3850end
3851
3852--colorPickers from here
3853--all props: selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
3854function addColorPicker(id,default)
3855 if trackID(id) then
3856 colorPickers[id] = {}
3857 colorPickers[id]["selection"] = default
3858 colorPickers[id]["visible"] = true
3859 colorPickers[id]["enabled"] = true
3860 writeToLog("Added colorPicker "..id..".",2)
3861 else
3862 writeToLog("Did not add colorPicker because of ID conflict.",3)
3863 end
3864end
3865
3866function writeColorPickerToPixelMatrix(screenID,colorPickerID,x,y)
3867 data = colorPickers[colorPickerID]
3868
3869 local selection = data["selection"]
3870 local colorWidth
3871 local colorHeight
3872 local borderColor
3873 local borderThickness
3874 local selectionCharacter
3875
3876 if data["colorWidth"]~=nil then
3877 colorWidth = data["colorWidth"]
3878 else
3879 colorWidth = 1
3880 end
3881
3882 if data["colorHeight"]~=nil then
3883 colorHeight = data["colorHeight"]
3884 else
3885 colorHeight = 1
3886 end
3887
3888 if data["borderColor"]~=nil then
3889 borderColor = data["borderColor"]
3890 else
3891 borderColor = screens[screenID]["defaultBGColor"]
3892 end
3893
3894 if data["borderThickness"]~=nil then
3895 borderThickness = data["borderThickness"]
3896 else
3897 borderThickness = 0
3898 end
3899
3900 if data["selectionCharacter"]~=nil then
3901 selectionCharacter = string.sub(data["selectionCharacter"],1,1)
3902 else
3903 selectionCharacter = "X"
3904 end
3905
3906 local maxX = x + borderThickness*2 + 4*colorWidth -1
3907 local maxY = y + borderThickness*2 + 4*colorHeight -1
3908
3909 --border
3910 for currentOffset=0,borderThickness-1 do
3911 --this draws two horizontal lines
3912 for currentX=(x+currentOffset),(maxX-currentOffset) do
3913 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
3914 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
3915 end
3916
3917 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3918 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3919 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
3920 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
3921 end
3922 end
3923
3924 for i=0,3 do
3925 for j=1,4 do
3926 local text = " "
3927 if selection==colorsArrayNumToNum[i*4+j] then
3928 text = selectionCharacter
3929 end
3930 local s = ""
3931 for h=1,colorWidth do
3932 s = s.. text
3933 end
3934
3935 for k=1,colorHeight do
3936 if selection==colors.black then
3937 writeToPixelMatrix(screenID,s,x+borderThickness+i*colorWidth,y+borderThickness+(j-1)*colorHeight+k-1,colors.white,colorsArrayNumToNum[i*4+j],colorPickerID,"colorPicker",colorsArrayNumToNum[i*4+j])
3938 else
3939 writeToPixelMatrix(screenID,s,x+borderThickness+i*colorWidth,y+borderThickness+(j-1)*colorHeight+k-1,colors.black,colorsArrayNumToNum[i*4+j],colorPickerID,"colorPicker",colorsArrayNumToNum[i*4+j])
3940 end
3941 end
3942 end
3943 end
3944end
3945
3946--Progressbars from here
3947-- all properties: length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
3948function addProgressBar(id,length)
3949 if trackID(id) then
3950 progressBars[id] = {}
3951 progressBars[id]["length"] = length
3952 progressBars[id]["visible"] = true
3953 writeToLog("Added progressBar "..id..".",2)
3954 else
3955 writeToLog("Did not add progressBar because of ID conflict.",3)
3956 end
3957end
3958
3959function writeProgressBarToPixelMatrix(screenID,progressBarID,x,y)
3960 data = progressBars[progressBarID]
3961
3962 local length = data["length"]
3963 local value = data["value"]
3964 local valueType
3965 local broadness
3966 local orientation
3967 local color
3968 local colorsArray
3969 local textPosition = data["textPosition"]
3970 local textMargin
3971 local BGColor
3972 local borderColor
3973 local borderThickness
3974
3975 --take care of all variable defaults
3976 if value==nil then
3977 value = 0
3978 end
3979
3980 if data["valueType"]~=nil then
3981 valueType = data["valueType"]
3982 else
3983 valueType = "absolute"
3984 end
3985
3986 local originalValue = value
3987 if valueType == "relative" then
3988 value = math.floor((length/100)*value)
3989 end
3990
3991 if data["broadness"]~=nil then
3992 broadness = data["broadness"]
3993 else
3994 broadness = 1
3995 end
3996
3997 if data["orientation"]~=nil then
3998 orientation = data["orientation"]
3999 else
4000 orientation = "left-right"
4001 end
4002
4003 if data["color"]~=nil then
4004 color = data["color"]
4005 else
4006 color = screens[screenID]["defaultTextColor"]
4007 end
4008
4009 if data["colorsArray"]~=nil then
4010 color = data["colorsArray"][value]
4011 end
4012
4013 if data["textMargin"]~=nil then
4014 textMargin = data["textMargin"]
4015 else
4016 textMargin = 0
4017 end
4018
4019 if data["BGColor"]~=nil then
4020 BGColor = data["BGColor"]
4021 else
4022 BGColor = screens[screenID]["defaultBGColor"]
4023 end
4024
4025 if data["borderColor"]~=nil then
4026 borderColor = data["borderColor"]
4027 else
4028 borderColor = color
4029 end
4030
4031 if data["borderThickness"]~=nil then
4032 borderThickness = data["borderThickness"]
4033 else
4034 borderThickness = 1
4035 end
4036
4037 local maxX
4038 local maxY
4039
4040 --calculate maxX and maxY based on the orientation of progressBar
4041 if orientation=="left-right" or orientation=="right-left" then
4042 maxX = x + borderThickness*2 + length - 1
4043 maxY = y + borderThickness*2 + broadness - 1
4044 else
4045 maxX = x + borderThickness*2 + broadness - 1
4046 maxY = y + borderThickness*2 + length - 1
4047 end
4048
4049 --start drawing
4050 --border
4051 for currentOffset=0,borderThickness-1 do
4052 --this draws two horizontal lines
4053 for currentX=(x+currentOffset),(maxX-currentOffset) do
4054 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,progressBarID,"progressBar","border")
4055 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,progressBarID,"progressBar","border")
4056 end
4057
4058 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
4059 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
4060 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4061 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4062 end
4063 end
4064
4065 --draw bar case horizontal
4066 if orientation=="left-right" or orientation=="right-left" then
4067 --this makes things easier
4068 local s = " "
4069
4070 --loop for x coordinate (length)
4071 for i=1,length do
4072 --change color according to slider value
4073 --check mode
4074 local currentColor
4075 if i<=value then
4076 currentColor = color
4077 else
4078 currentColor = BGColor
4079 end
4080 --loop for y coordinate (broadness)
4081 for currentY=y+borderThickness,maxY-borderThickness do
4082 --take pixelsPerUnit into account for calculations
4083 if orientation=="left-right" then
4084 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4085 end
4086 if orientation=="right-left" then
4087 writeToPixelMatrix(screenID,s,maxX-borderThickness-(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4088 end
4089 end
4090 end
4091 else
4092 --this makes things easier
4093 local s = ""
4094 for i=1,broadness do
4095 s = s.." "
4096 end
4097 --draw bar case vertical
4098 --loop for y coordinate (length)
4099 for i=1,length do
4100 local currentColor
4101 if i<=value then
4102 currentColor = color
4103 else
4104 currentColor = BGColor
4105 end
4106 if orientation=="top-bottom" then
4107 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4108 end
4109 if orientation=="bottom-top" then
4110 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4111 end
4112 end
4113 end
4114
4115 value = originalValue
4116 if valueType == "relative" then
4117 value = value .."%"
4118 end
4119 --draw text
4120 if textPosition~=nil then
4121 --calculations to center the text
4122 if textPosition=="right" then
4123 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4124 end
4125 if textPosition=="left" then
4126 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4127 end
4128 if textPosition=="top" then
4129 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4130 end
4131 if textPosition=="bottom" then
4132 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4133 end
4134 end
4135end
4136
4137--coordinateSystems from here
4138-- all props: width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepsX,stepsY
4139function addCoordinateSystem(id,width,height)
4140 if trackID(id) then
4141 coordinateSystems[id] = {}
4142 coordinateSystems[id]["width"] = width
4143 coordinateSystems[id]["height"] = height
4144 coordinateSystems[id]["visible"] = true
4145 writeToLog("Added coordinateSystem "..id..".",2)
4146 else
4147 writeToLog("Did not add coordinateSystem because of ID conflict.",3)
4148 end
4149end
4150
4151function writeCoordinateSystemToPixelMatrix(screenID,coordinateSystemID,x,y)
4152 data = coordinateSystems[coordinateSystemID]
4153
4154 local width = data["width"]
4155 local height = data["height"]
4156 local graphTables = data["graphTables"]
4157 local graphDesigns = data["graphDesigns"]
4158 local unitsPerPixelX
4159 local unitsPerPixelY
4160 local axesColor
4161 local numbersColor
4162 local labelX
4163 local labelY
4164 local startX
4165 local startY
4166 local numbersOffset
4167 local stepX = data["stepX"]
4168 local stepY
4169
4170 if data["stepY"]~=nil then
4171 stepY = data["stepY"]
4172 else
4173 stepY = 2
4174 end
4175
4176 if data["unitsPerPixelX"]~=nil then
4177 unitsPerPixelX = data["unitsPerPixelX"]
4178 else
4179 unitsPerPixelX = 1
4180 end
4181
4182 if data["unitsPerPixelY"]~=nil then
4183 unitsPerPixelY = data["unitsPerPixelY"]
4184 else
4185 unitsPerPixelY = 1
4186 end
4187
4188 if data["axesColor"]~=nil then
4189 axesColor = data["axesColor"]
4190 else
4191 axesColor = screens[screenID]["defaultTextColor"]
4192 end
4193
4194 if data["numbersColor"]~=nil then
4195 numbersColor = data["numbersColor"]
4196 else
4197 numbersColor = screens[screenID]["defaultTextColor"]
4198 end
4199
4200 if data["labelX"]~=nil then
4201 labelX = data["labelX"]
4202 else
4203 labelX = "X"
4204 end
4205
4206 if data["labelY"]~=nil then
4207 labelY = data["labelY"]
4208 else
4209 labelY = "Y"
4210 end
4211
4212 if data["startX"]~=nil then
4213 startX = data["startX"]
4214 else
4215 startX = 0
4216 end
4217
4218 if data["startY"]~=nil then
4219 startY = data["startY"]
4220 else
4221 startY = 0
4222 end
4223
4224 if data["numbersOffset"]~=nil then
4225 numbersOffset = data["numbersOffset"]
4226 else
4227 numbersOffset = 0
4228 end
4229
4230 --draw coordinateSystem
4231 --draw origin
4232 writeToPixelMatrix(screenID,"+",x,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisOrigin")
4233
4234 --draw start numbers around origin
4235 if startX == startY then
4236 writeToPixelMatrix(screenID,tostring(startX),x-string.len(startX)-numbersOffset,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginXY")
4237 else
4238 writeToPixelMatrix(screenID,tostring(startX),x-math.floor(string.len(startX)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginX")
4239 writeToPixelMatrix(screenID,tostring(startY),x-string.len(startY)-numbersOffset,y,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginY")
4240 end
4241
4242 --draw axes
4243 for i=1,width-2 do
4244 writeToPixelMatrix(screenID,"-",x+i,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4245 end
4246 writeToPixelMatrix(screenID,">",x+width-1,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisXEnd")
4247
4248 for i=1,height-2 do
4249 writeToPixelMatrix(screenID,"|",x,y-i,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4250 end
4251 writeToPixelMatrix(screenID,"^",x,y-height+1,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4252
4253 --draw numbers
4254 if stepX==nil then
4255 local greatestTextLength = string.len(startX)
4256 if string.len(startX + (width-1)*unitsPerPixelX)>greatestTextLength then
4257 greatestTextLength = string.len(startX + (width-1)*unitsPerPixelX)
4258 end
4259 stepX = greatestTextLength + 1
4260 end
4261
4262 local currentX = x+stepX
4263 local currentValue = startX+(stepX*unitsPerPixelX)
4264 local maxX = x + width-1
4265 while currentX<maxX do
4266 writeToPixelMatrix(screenID,"+",currentX,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4267
4268 writeToPixelMatrix(screenID,tostring(currentValue),currentX-math.floor(string.len(currentValue)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersX")
4269
4270 currentX = currentX + stepX
4271 currentValue = currentValue + (stepX*unitsPerPixelX)
4272 end
4273
4274 local currentY = y-stepY
4275 local currentValue = startY+(stepY*unitsPerPixelY)
4276 local maxY = y - height+1
4277 while currentY>maxY do
4278 writeToPixelMatrix(screenID,"+",x,currentY,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4279
4280 writeToPixelMatrix(screenID,tostring(currentValue),x-numbersOffset-string.len(currentValue),currentY,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersY")
4281
4282 currentY = currentY - stepY
4283 currentValue = currentValue + (stepY*unitsPerPixelY)
4284 end
4285
4286 --draw labels
4287 writeToPixelMatrix(screenID,labelX,x+width-math.floor(string.len(labelX)/2)-1,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelX")
4288 writeToPixelMatrix(screenID,labelY,x-string.len(labelY)-numbersOffset,y-height+1,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelY")
4289
4290 --draw graphs
4291 if graphTables~=nil then
4292 for i,graph in ipairs(graphTables) do
4293 local color = numbersColor
4294 local BGColor = screens[screenID]["defaultBGColor"]
4295 local character = "X"
4296 if graphDesigns~=nil then
4297 if graphDesigns[i]~=nil then
4298 if graphDesigns[i]["color"]~=nil then
4299 color = graphDesigns[i]["color"]
4300 end
4301 if graphDesigns[i]["BGColor"]~=nil then
4302 BGColor = graphDesigns[i]["BGColor"]
4303 end
4304 if graphDesigns[i]["character"]~=nil then
4305 character = graphDesigns[i]["character"]
4306 end
4307 end
4308 end
4309
4310 for currentX=x,maxX do
4311 if graph[((currentX-x)*unitsPerPixelX)+startX]~=nil then
4312 if y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5)>=y-height+1 and y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5)<=y then
4313 writeToPixelMatrix(screenID,character,currentX,y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5),color,BGColor,coordinateSystemID,"coordinateSystem","graph:"..i)
4314 end
4315 end
4316 end
4317 end
4318 end
4319end
4320
4321--pictures from here
4322-- all props: linesArray
4323function addPicture(id,width,height,linesArray)
4324 if trackID(id) then
4325 pictures[id] = {}
4326 pictures[id]["width"] = width
4327 pictures[id]["height"] = height
4328 pictures[id]["linesArray"] = linesArray
4329 pictures[id]["visible"] = true
4330 writeToLog("Added picture "..id..".",2)
4331 else
4332 writeToLog("Did not add picture because of ID conflict.",3)
4333 end
4334end
4335
4336function writePictureToPixelMatrix(screenID,pictureID,x,y)
4337 data = pictures[pictureID]
4338 colorsArrayStrToNum["*"]=screens[screenID]["defaultTextColor"]
4339 colorsArrayStrToNum["#"]=screens[screenID]["defaultBGColor"]
4340
4341 local linesArray = data["linesArray"]
4342 local width = data["width"]
4343 local height = data["height"]
4344
4345 for i=1,height do
4346 local j = 1
4347 local line = linesArray[i]
4348 local correct = true
4349 if line~=nil then
4350 while string.find(line,";")~=nil do
4351 local currentLetter = string.sub(line,1,string.find(line,";")-1)
4352 line = string.sub(line,string.find(line,";")+1)
4353
4354 if string.len(currentLetter)==5 and string.sub(currentLetter,2,2)==":" and string.sub(currentLetter,4,4)==":" then
4355 local textColor = string.sub(currentLetter,1,1)
4356 local BGColor = string.sub(currentLetter,3,3)
4357 local character = string.sub(currentLetter,5,5)
4358
4359 writeToPixelMatrix(screenID,character,x+j-1,y+i-1,colorsArrayStrToNum[textColor],colorsArrayStrToNum[BGColor],pictureID,"picture",j..":"..i)
4360 end
4361
4362 if string.len(currentLetter)==1 then
4363 writeToPixelMatrix(screenID," ",x+j-1,y+i-1,colorsArrayStrToNum[currentLetter],colorsArrayStrToNum[currentLetter],pictureID,"picture",j..":"..i)
4364 end
4365
4366 if j == width then correct = false break end
4367 j = j + 1
4368 end
4369 else
4370 linesArray[i] = ""
4371 end
4372 --correct mistakes
4373 if correct then
4374 for k=1,width-j+1 do
4375 linesArray[i] = linesArray[i].."#;"
4376 end
4377 end
4378 end
4379end
4380
4381--initalizing function searching for all monitors and adding them
4382function findMonitors()
4383 local nMonitorCount = 0
4384 monitors = {}
4385 writeToLog("Searching for monitors...",2)
4386
4387 setScreenToRenderOnTerminal(initMonsSID)
4388 refresh()
4389 local sides = {"front","back","left","right","top","bottom"}
4390 --search for monitors and modems
4391 for i,side in ipairs(sides) do
4392 --check if there is a monitor
4393 if peripheral.isPresent(side) then
4394 if peripheral.getType(side)=="monitor" then
4395 --check if monitor is advanced
4396 if peripheral.call(side,"isColor") then
4397 -- initialize monitor
4398 monitor = peripheral.wrap(side)
4399 monitor.setBackgroundColor(colors.red)
4400 monitor.clear()
4401 changeProperty(initMonsSTextID,"content","Advanced monitor number "..(nMonitorCount+1).." was found on side "..side..". It has turned completely red for your identification. Please give this monitor a unique ID!")
4402
4403 writeToLog("Found monitor on side "..side..".",2)
4404 local sID
4405 local success = false
4406 repeat
4407 refresh()
4408 local x,y = term.getSize()
4409 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4410 term.setTextColor(colorPalette[1])
4411 term.write(">")
4412 sID = read()
4413 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4414 for i=1,string.len(sID) do
4415 term.write(" ")
4416 end
4417 if sID=="" then
4418 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4419 refresh()
4420 else
4421 if trackID(sID) then
4422 success = true
4423 else
4424 changeProperty(initMonsSErrorID,"content","ID already taken!")
4425 refresh()
4426 end
4427 end
4428 until success==true
4429 monitors[sID] = {}
4430 monitors[sID]["peripheral"] = monitor
4431 monitors[sID]["side"] = side
4432 monitors[sID]["networkID"] = "NONE"
4433 monitor.setBackgroundColor(colors.black)
4434 monitor.clear()
4435 nMonitorCount = nMonitorCount + 1
4436 writeToLog("Added monitor "..sID.." to the system.",2)
4437 changeProperty(initMonsSErrorID,"content","")
4438 end
4439 else
4440 --check monitors connected via modems
4441 if peripheral.getType(side)=="modem" then
4442 local modem = peripheral.wrap(side)
4443 for i,sPeripheral in ipairs(modem.getNamesRemote()) do
4444 if string.match(sPeripheral,"monitor") then
4445 if modem.callRemote(sPeripheral,"isColor") then
4446 -- initialize monitor
4447 monitor = peripheral.wrap(sPeripheral)
4448 monitor.setBackgroundColor(colors.red)
4449 monitor.clear()
4450 changeProperty(initMonsSTextID,"content","Advanced monitor number "..(nMonitorCount+1).." was found via modem on side "..side..". It has turned red for your identification. Please give this monitor a unique ID!")
4451
4452 writeToLog("Found monitor on side "..side.." through modem.",2)
4453 local sID
4454 local success = false
4455 repeat
4456 refresh()
4457 local x,y = term.getSize()
4458 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4459 term.setTextColor(colorPalette[1])
4460 term.write(">")
4461 sID = read()
4462 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4463 for i=1,string.len(sID) do
4464 term.write(" ")
4465 end
4466 if sID=="" then
4467 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4468 refresh()
4469 else
4470 if trackID(sID) then
4471 success = true
4472 else
4473 changeProperty(initMonsSErrorID,"content","ID already taken!")
4474 refresh()
4475 end
4476 end
4477 until success==true
4478 monitors[sID] = {}
4479 monitors[sID]["peripheral"] = monitor
4480 monitors[sID]["side"] = side
4481 monitors[sID]["networkID"] = sPeripheral
4482 monitor.setBackgroundColor(colors.black)
4483 monitor.clear()
4484 nMonitorCount = nMonitorCount + 1
4485 writeToLog("Added monitor "..sID.." to the system.",2)
4486 changeProperty(initMonsSErrorID,"content","")
4487 end
4488 end
4489 end
4490 end
4491 end
4492 end
4493 end
4494
4495 if nMonitorCount == 0 then
4496 writeToLog("Did not find any advanced monitors.",2)
4497 else
4498 writeToLog("Found "..nMonitorCount.." monitors.",2)
4499 end
4500end
4501
4502function setupStuff()
4503 local x,y = term.getSize()
4504 addScreen(initMonsSID,x,y,colorPalette[1],colorPalette[2])
4505 addDynamicTextBox(initMonsSLeftRectID,"")
4506 changeProperty(initMonsSLeftRectID,"width",relX(20,initMonsSID))
4507 changeProperty(initMonsSLeftRectID,"height",relY(100,initMonsSID))
4508 changeProperty(initMonsSLeftRectID,"BGColor",colorPalette[3])
4509 addElementToScreen(initMonsSLeftRectID,initMonsSID,1,1)
4510
4511 addDynamicTextBox(initMonsSHeadingID,"EasyGUI Monitor Initialization")
4512 changeProperty(initMonsSHeadingID,"width",relX(80,initMonsSID))
4513 changeProperty(initMonsSHeadingID,"borderThickness",1)
4514 addElementToScreen(initMonsSHeadingID,initMonsSID,relX(20,initMonsSID)+1,1)
4515
4516 addDynamicTextBox(initMonsSTextID,"Searching for monitors...")
4517 changeProperty(initMonsSTextID,"width",relX(80,initMonsSID))
4518 changeProperty(initMonsSTextID,"borderThickness",1)
4519 addElementToScreen(initMonsSTextID,initMonsSID,relX(20,initMonsSID)+1,relY(30,initMonsSID))
4520
4521 local picArray = {}
4522 for i=1,y do
4523 if (i%3)==1 then
4524 table.insert(picArray,"*;;;")
4525 end
4526 if (i%3)==2 then
4527 table.insert(picArray,";*;;")
4528 end
4529 if (i%3)==0 then
4530 table.insert(picArray,";;*;")
4531 end
4532 end
4533 addPicture(initMonsSPictureID,3,y,picArray)
4534 addElementToScreen(initMonsSPictureID,initMonsSID,relX(10,initMonsSID)-1,1)
4535
4536 addDynamicTextBox(initMonsSErrorID,"")
4537 changeProperty(initMonsSErrorID,"width",relX(80,initMonsSID))
4538 changeProperty(initMonsSErrorID,"textColor",colors.red)
4539 addElementToScreen(initMonsSErrorID,initMonsSID,relX(20,initMonsSID)+1,y)
4540end
4541
4542function setDesignerScreen(ID)
4543 if designerMonitor==terminalID then
4544 setScreenToRenderOnTerminal(ID)
4545 else
4546 setScreenToRenderOnMon(ID,designerMonitor,tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]),0,0)
4547 end
4548end
4549
4550function transferDesigner()
4551 x,y = term.getSize()
4552 addScreen(changeMonSID,x,y,colorPalette[1],colorPalette[2])
4553 setScreenToRenderOnTerminal(changeMonSID)
4554 addElementToScreen(initMonsSLeftRectID,changeMonSID,1,1)
4555 addElementToScreen(initMonsSPictureID,changeMonSID,relX(10,changeMonSID)-1,1)
4556 changeProperty(initMonsSHeadingID,"content","EasyGUI Designer transfer")
4557 addElementToScreen(initMonsSHeadingID,changeMonSID,relX(20,changeMonSID)+1,1)
4558 changeProperty(initMonsSTextID,"content","Would you like to transfer the designer on a monitor?")
4559 addElementToScreen(initMonsSTextID,changeMonSID,relX(20,changeMonSID)+1,relY(30,changeMonSID))
4560
4561 local array = {"term"}
4562 for name,data in pairs(monitors) do
4563 table.insert(array,name)
4564 end
4565
4566 addDropDownMenu(changeMonSScaleDDID,{"0.5","1","1.5","2"},1)
4567 changeProperty(changeMonSScaleDDID,"borderThickness",1)
4568 changeProperty(changeMonSScaleDDID,"borderColor",colorPalette[3])
4569 changeProperty(changeMonSScaleDDID,"highlightTextColor",colorPalette[2])
4570 changeProperty(changeMonSScaleDDID,"highlightBGColor",colorPalette[1])
4571 changeProperty(changeMonSScaleDDID,"width",relX(40,changeMonSID)-2)
4572 addElementToScreen(changeMonSScaleDDID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)+2)
4573
4574 addDropDownMenu(changeMonSDDMenuID,array,1)
4575 changeProperty(changeMonSDDMenuID,"borderThickness",1)
4576 changeProperty(changeMonSDDMenuID,"borderColor",colorPalette[3])
4577 changeProperty(changeMonSDDMenuID,"highlightTextColor",colorPalette[2])
4578 changeProperty(changeMonSDDMenuID,"highlightBGColor",colorPalette[1])
4579 changeProperty(changeMonSDDMenuID,"width",relX(40,changeMonSID)-2)
4580 addElementToScreen(changeMonSDDMenuID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)-2)
4581
4582 addDynamicTextBox(changeMonSApplyID,"Apply")
4583 changeProperty(changeMonSApplyID,"width",relX(40,changeMonSID)-2)
4584 changeProperty(changeMonSApplyID,"textColor",colorPalette[3])
4585 changeProperty(changeMonSApplyID,"BGColor",colorPalette[1])
4586 changeProperty(changeMonSApplyID,"borderThickness",1)
4587 changeProperty(changeMonSApplyID,"onClickMode","flash")
4588 changeProperty(changeMonSApplyID,"onActiveFunction",function()
4589 os.queueEvent("easygui_interrupt") end)
4590 addElementToScreen(changeMonSApplyID,changeMonSID,relX(60,changeMonSID)+2,relY(70,changeMonSID))
4591
4592 run()
4593
4594 if getProperty(changeMonSDDMenuID,"selectionID")==1 then
4595 designerMonitor = terminalID
4596 else
4597 designerMonitor = array[getProperty(changeMonSDDMenuID,"selectionID")]
4598 end
4599end
4600
4601function onLoadScreensS()
4602 tryLoadAllScreens()
4603 local array = {}
4604 for name,data in pairs(screens) do
4605 if string.len(name)<32 then
4606 table.insert(array,name)
4607 end
4608 end
4609 if table.getn(array)~=0 then
4610 changeProperty(screensSDDMenuID,"entries",array)
4611 else
4612 changeProperty(screensSButton2ID,"visible",false)
4613 changeProperty(screensSDDMenuID,"visible",false)
4614 end
4615end
4616
4617function onLoadElementsS()
4618 tryLoadAllElements()
4619 local array = {}
4620 for name,data in pairs(elements) do
4621 for name2,data2 in pairs(elements[name]) do
4622 if string.len(name2)<32 then
4623 table.insert(array,name2)
4624 end
4625 end
4626 end
4627 if table.getn(array)~=0 then
4628 changeProperty(elementsSDDMenu2ID,"entries",array)
4629 else
4630 changeProperty(elementsSButton2ID,"visible",false)
4631 changeProperty(elementsSDDMenu2ID,"visible",false)
4632 end
4633end
4634
4635function newElement(type_)
4636 local ID = nil
4637
4638 changeProperty(elementsSButton1ID,"visible",false)
4639 changeProperty(elementsSButton2ID,"visible",false)
4640 changeProperty(elementsSDDMenu1ID,"visible",false)
4641 changeProperty(elementsSDDMenu2ID,"visible",false)
4642 changeProperty(screensSButton3ID,"visible",false)
4643 changeProperty(screensSMsgID,"visible",true)
4644 refresh()
4645 term.setTextColor(colorPalette[1])
4646 term.setBackgroundColor(colorPalette[2])
4647 term.clear()
4648 term.setCursorPos(1,1)
4649 print("Please enter an unique ID for the new element:")
4650 repeat
4651 local input = read()
4652 if input~="" and input~=nil then
4653 if string.len(input)<32 then
4654 if not IDExists(input) then
4655 ID = input
4656 else
4657 print("ID already taken!")
4658 end
4659 else
4660 print("Must be less than 32 characters!")
4661 end
4662 else
4663 print("Cannot be an empty string.")
4664 end
4665 until ID~=nil
4666
4667 changeProperty(elementsSButton1ID,"visible",true)
4668 changeProperty(elementsSButton2ID,"visible",true)
4669 changeProperty(elementsSDDMenu1ID,"visible",true)
4670 changeProperty(elementsSDDMenu2ID,"visible",true)
4671 changeProperty(screensSButton3ID,"visible",true)
4672 changeProperty(screensSMsgID,"visible",false)
4673 fullRefresh()
4674
4675 elements[type_][ID] = {["enabled"]=true,["visible"]=true,["expanded"]=false}
4676
4677 for name,data in pairs(elementProperties[type_]) do
4678 if data["essential"] then
4679 changeProperty(ID,name,data["default"])
4680 end
4681 end
4682 return ID,type_
4683end
4684
4685function startEditor(ID,type_)
4686 editorSElementID = ID
4687 editorSElementType = type_
4688 saveElement(editorSElementID,editorSElementType)
4689 lastSave = os.clock()
4690 saveTimerID = os.startTimer(180)
4691 setProcessEventFunction(processEditorEvents)
4692 term.setTextColor(colorPalette[1])
4693 term.setBackgroundColor(colorPalette[2])
4694 term.clear()
4695 term.setCursorPos(1,1)
4696 term.write("EasyGUI Editor running on monitor.")
4697 addScreen(editorSID,designerX,designerY,colorPalette[1],colorPalette[2])
4698 addElementToScreen(editorSElementID,editorSID,relX(20,editorSID),relY(20,editorSID))
4699 editorSElementX = relX(20,editorSID)
4700 editorSElementY = relY(20,editorSID)
4701 undoRedoTable = {}
4702 undoRedoIndex = 0
4703
4704 addDynamicTextBox(editorSRelocateButtonID,"<Relocate>")
4705 changeProperty(editorSRelocateButtonID,"onClickMode","toggle")
4706 changeProperty(editorSRelocateButtonID,"activeTextColor",colorPalette[2])
4707 changeProperty(editorSRelocateButtonID,"activeBGColor",colorPalette[1])
4708 changeProperty(editorSRelocateButtonID,"onActiveFunction",relocateOn)
4709 changeProperty(editorSRelocateButtonID,"onInactiveFunction",relocateOff)
4710 addElementToScreen(editorSRelocateButtonID,editorSID,1,1)
4711
4712 addDynamicTextBox(editorSLastSaveID,"Last save: $time min ago.")
4713 changeProperty(editorSLastSaveID,"variables",{["time"]=function () return math.floor((os.clock()-lastSave)/60) end})
4714 addElementToScreen(editorSLastSaveID,editorSID,designerX-9,1)
4715
4716 addDynamicTextBox(editorSExitID,"<Save&Exit>")
4717 changeProperty(editorSExitID,"onClickMode","flash")
4718 changeProperty(editorSExitID,"onActiveFunction",function() saveElement(editorSElementID,editorSElementType)
4719 lastSave = os.clock()
4720 removeElementFromScreen(editorSElementID,editorSID)
4721 removeElementFromScreen(editorSDescID,editorSID)
4722 removeElementFromScreen(editorSExitID,editorSID)
4723 removeElementFromScreen(editorSHideUIID,editorSID)
4724 removeElementFromScreen(editorSLastSaveID,editorSID)
4725 removeElementFromScreen(editorSPropColorPickID,editorSID)
4726 removeElementFromScreen(editorSPropsID,editorSID)
4727 removeElementFromScreen(editorSPropsMenuID,editorSID)
4728 removeElementFromScreen(editorSRedoID,editorSID)
4729 removeElementFromScreen(editorSRelocateButtonID,editorSID)
4730 removeElementFromScreen(editorSUndoID,editorSID)
4731 removeElementFromScreen(editorSPropResetButtonID,editorSID)
4732 removeElementFromScreen(editorSPropDDMenuID,editorSID)
4733 removeElementFromScreen(editorSPropDisplayID,editorSID)
4734 removeElementFromScreen(editorSPropConsoleInputButtonID,editorSID)
4735 removeElementFromScreen(editorSPropConsoleMsgID,editorSID)
4736 removeElementFromScreen(editorSPropColorsArrayDDID,editorSID)
4737 removeElementFromScreen(editorSPropStringArrayDDID,editorSID)
4738 removeElementFromScreen(editorSPropNavMenuID,editorSID)
4739 removeElementFromScreen(editorSPropNavMenuHintID,editorSID)
4740 removeElementFromScreen(editorSPropCSTableIndexDDID,editorSID)
4741 removeElementFromScreen(editorSPropCSTableDDID,editorSID)
4742 removeElementFromScreen(editorSPropCSChangeID,editorSID)
4743 removeElementFromScreen(editorSPropCSRemoveID,editorSID)
4744 removeElementFromScreen(editorSPropCSDesignsDDID,editorSID)
4745 removeElementFromScreen(editorSPropCSDesignsDisplayID,editorSID)
4746 removeElementFromScreen(editorSPropCSDesignsIndexDDID,editorSID)
4747 removeElementFromScreen(editorSPropPicEditButtonID,editorSID)
4748 setProcessEventFunction(nil)
4749 editorSElementID = nil
4750 setDesignerScreen(elementsSID)
4751 refresh() end)
4752 addElementToScreen(editorSExitID,editorSID,designerX-10,designerY)
4753
4754 addDynamicTextBox(editorSPropsID,"<Properties>")
4755 changeProperty(editorSPropsID,"onClickMode","toggle")
4756 changeProperty(editorSPropsID,"activeTextColor",colorPalette[2])
4757 changeProperty(editorSPropsID,"activeBGColor",colorPalette[1])
4758 changeProperty(editorSPropsID,"onActiveFunction",function() changeProperty(editorSPropsMenuID,"visible",true)
4759 changeProperty(editorSDescID,"visible",true)
4760 changeProperty(editorSExitID,"visible",false)
4761 changeProperty(editorSRelocateButtonID,"visible",false)
4762 changeProperty(editorSHideUIID,"visible",false)
4763 refreshPropsMenu()
4764 pcall(getProperty(editorSPropsMenuID,"onChangeFunction")) end)
4765 changeProperty(editorSPropsID,"onInactiveFunction",function() changeProperty(editorSPropsMenuID,"visible",false)
4766 changeProperty(editorSDescID,"visible",false)
4767 changeProperty(editorSRelocateButtonID,"visible",true)
4768 changeProperty(editorSHideUIID,"visible",true)
4769 changeProperty(editorSExitID,"visible",true)
4770 changeProperty(editorSPropColorPickID,"visible",false)
4771 changeProperty(editorSPropResetButtonID,"visible",false)
4772 changeProperty(editorSPropDisplayID,"visible",false)
4773 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
4774 changeProperty(editorSPropDDMenuID,"visible",false)
4775 changeProperty(editorSPropConsoleMsgID,"visible",false)
4776 changeProperty(editorSPropColorsArrayDDID,"visible",false)
4777 changeProperty(editorSPropStringArrayDDID,"visible",false)
4778 changeProperty(editorSPropNavMenuID,"visible",false)
4779 changeProperty(editorSPropNavMenuHintID,"visible",false)
4780 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
4781 changeProperty(editorSPropCSTableDDID,"visible",false)
4782 changeProperty(editorSPropCSChangeID,"visible",false)
4783 changeProperty(editorSPropCSRemoveID,"visible",false)
4784 changeProperty(editorSPropCSDesignsDDID,"visible",false)
4785 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
4786 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
4787 changeProperty(editorSPropPicEditButtonID,"visible",false) end)
4788 addElementToScreen(editorSPropsID,editorSID,1,designerY)
4789
4790 addDynamicTextBox(editorSUndoID,"<Undo>")
4791 changeProperty(editorSUndoID,"onClickMode","flash")
4792 changeProperty(editorSUndoID,"activeTextColor",colorPalette[2])
4793 changeProperty(editorSUndoID,"activeBGColor",colorPalette[1])
4794 changeProperty(editorSUndoID,"onActiveFunction",function()
4795 if undoRedoIndex~=0 then
4796 if type(undoRedoTable[undoRedoIndex]["undo"])=="function" then
4797 pcall(undoRedoTable[undoRedoIndex]["undo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
4798 if getProperty(editorSPropsID,"active") then
4799 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4800 end
4801 onPixelSelecChange()
4802 refresh()
4803 else
4804 changeProperty(editorSElementID,undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["undo"])
4805 if getProperty(editorSPropsID,"active") then
4806 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4807 end
4808 onPixelSelecChange()
4809 refresh()
4810 end
4811 undoRedoIndex = undoRedoIndex - 1
4812 end
4813 end)
4814 addElementToScreen(editorSUndoID,editorSID,relX(50,editorSID)-6,designerY)
4815
4816 addDynamicTextBox(editorSRedoID,"<Redo>")
4817 changeProperty(editorSRedoID,"onClickMode","flash")
4818 changeProperty(editorSRedoID,"activeTextColor",colorPalette[2])
4819 changeProperty(editorSRedoID,"activeBGColor",colorPalette[1])
4820 changeProperty(editorSRedoID,"onActiveFunction",function()
4821 if undoRedoIndex~=table.getn(undoRedoTable) then
4822 undoRedoIndex = undoRedoIndex + 1
4823 if type(undoRedoTable[undoRedoIndex]["redo"])=="function" then
4824 pcall(undoRedoTable[undoRedoIndex]["redo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
4825 if getProperty(editorSPropsID,"active") then
4826 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4827 end
4828 onPixelSelecChange()
4829 refresh()
4830 else
4831 changeProperty(editorSElementID,undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["redo"])
4832 if getProperty(editorSPropsID,"active") then
4833 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
4834 end
4835 onPixelSelecChange()
4836 refresh()
4837 end
4838 end
4839 end)
4840 addElementToScreen(editorSRedoID,editorSID,relX(50,editorSID)+1,designerY)
4841
4842 addDynamicTextBox(editorSDescID,nil)
4843 changeProperty(editorSDescID,"visible",false)
4844 changeProperty(editorSDescID,"height",designerY - 5)
4845 changeProperty(editorSDescID,"textAlignmentHorizontal","left")
4846 changeProperty(editorSDescID,"textAlignmentVertical","top")
4847 addElementToScreen(editorSDescID,editorSID,relX(50,editorSID)+1,4)
4848
4849 addDynamicTextBox(editorSPropResetButtonID,"Set default or unused")
4850 changeProperty(editorSPropResetButtonID,"BGColor",colorPalette[3])
4851 changeProperty(editorSPropResetButtonID,"textColor",colorPalette[2])
4852 changeProperty(editorSPropResetButtonID,"borderColor",colorPalette[1])
4853 changeProperty(editorSPropResetButtonID,"borderThickness",1)
4854 changeProperty(editorSPropResetButtonID,"width",relX(50,editorSID)-1)
4855 changeProperty(editorSPropResetButtonID,"onClickMode","flash")
4856 changeProperty(editorSPropResetButtonID,"activeBGColor",colorPalette[2])
4857 changeProperty(editorSPropResetButtonID,"activeTextColor",colorPalette[3])
4858 changeProperty(editorSPropResetButtonID,"visible",false)
4859 changeProperty(editorSPropResetButtonID,"onActiveFunction",function()
4860 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["essential"] then
4861 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "string" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "color" or string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
4862 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4863 else
4864 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "stringArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "picArray" then
4865 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4866 else
4867 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSTable" then
4868 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4869 else
4870 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSDesignsTable" then
4871 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSDesignsTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4872 else
4873 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "navMenuArray" then
4874 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4875 end
4876 end
4877 end
4878 end
4879 end
4880 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["default"])
4881 changeProperty(editorSPropStringArrayDDID,"selectionID",1)
4882 changeProperty(editorSPropStringArrayDDID,"entries",{"Entry 1","Entry 2","Entry 3","+add"})
4883 else
4884 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "string" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "color" or string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
4885 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),nil)
4886 else
4887 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "stringArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "picArray" then
4888 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
4889 else
4890 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSTable" then
4891 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
4892 else
4893 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "CSDesignsTable" then
4894 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfCSDesignsTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
4895 else
4896 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"] == "navMenuArray" then
4897 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))),nil)
4898 end
4899 end
4900 end
4901 end
4902 end
4903 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil)
4904 changeProperty(editorSPropDDMenuID,"selectionID",1)
4905 changeProperty(editorSPropColorPickID,"selection",nil)
4906 changeProperty(editorSPropColorsArrayDDID,"entries",{"Use"})
4907 changeProperty(editorSPropCSTableIndexDDID,"entries",{"Use"})
4908 changeProperty(editorSPropCSDesignsIndexDDID,"entries",{"Use"})
4909 changeProperty(editorSPropCSDesignsDDID,"visible",false)
4910 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
4911 changeProperty(editorSPropCSTableDDID,"visible",false)
4912 changeProperty(editorSPropColorsArrayDDID,"selectionID",1)
4913 changeProperty(editorSPropCSTableIndexDDID,"selectionID",1)
4914 changeProperty(editorSPropCSDesignsIndexDDID,"selectionID",1)
4915 changeProperty(editorSPropColorsArrayDDID,"expanded",false)
4916 changeProperty(editorSPropColorsArrayDDID,"highlightID",nil)
4917 changeProperty(editorSPropCSChangeID,"visible",false)
4918 changeProperty(editorSPropCSRemoveID,"visible",false)
4919 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
4920 changeProperty(editorSPropColorPickID,"visible",false)
4921 end
4922 end end)
4923 addElementToScreen(editorSPropResetButtonID,editorSID,1,designerY-4)
4924
4925 --input color
4926 addColorPicker(editorSPropColorPickID,nil)
4927 changeProperty(editorSPropColorPickID,"borderThickness",1)
4928 changeProperty(editorSPropColorPickID,"borderColor",colorPalette[3])
4929 changeProperty(editorSPropColorPickID,"visible",false)
4930 changeProperty(editorSPropColorPickID,"onChangeFunction", function(ID,selection)
4931 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="color" then
4932 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),selection)
4933 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),selection)
4934 end
4935 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" then
4936 --for colorsArray
4937 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var1 end,function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")],selection,getProperty(editorSPropColorsArrayDDID,"selectionID"))
4938 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")] = selection
4939 end
4940 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
4941 --for graphDesigns
4942 local string_ = ""
4943 if getProperty(editorSPropCSDesignsDDID,"selectionID")==1 then
4944 string_ = "color"
4945 else
4946 string_ = "BGColor"
4947 end
4948 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3,var4) getProperty(editorSElementID,prop)[var3][var4] = var1 end,function(prop,var1,var2,var3,var4) getProperty(editorSElementID,prop)[var3][var4] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")][string_],selection,getProperty(editorSPropCSDesignsIndexDDID,"selectionID"),string_)
4949 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")][string_] = selection
4950 end
4951 refresh()
4952 end)
4953 addElementToScreen(editorSPropColorPickID,editorSID,1,7)
4954
4955 --input ddmenu
4956 addDropDownMenu(editorSPropDDMenuID,nil,1)
4957 changeProperty(editorSPropDDMenuID,"selectionID",1)
4958 changeProperty(editorSPropDDMenuID,"borderThickness",1)
4959 changeProperty(editorSPropDDMenuID,"borderColor",colorPalette[3])
4960 changeProperty(editorSPropDDMenuID,"highlightTextColor",colorPalette[2])
4961 changeProperty(editorSPropDDMenuID,"highlightBGColor",colorPalette[1])
4962 changeProperty(editorSPropDDMenuID,"visible",false)
4963 changeProperty(editorSPropDDMenuID,"width",relX(50,editorSID)-1)
4964 changeProperty(editorSPropDDMenuID,"expandedMaxHeight",designerY-8)
4965 changeProperty(editorSPropDDMenuID,"onChangeFunction",function(ID,selection)
4966 if getProperty(editorSPropDDMenuID,"selectionID")==1 then
4967 changeProperty(editorSPropDDMenuID,"selectionID",2)
4968 end
4969 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),(getProperty(editorSPropDDMenuID,"entries")[getProperty(editorSPropDDMenuID,"selectionID")]))
4970 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),(getProperty(editorSPropDDMenuID,"entries")[getProperty(editorSPropDDMenuID,"selectionID")]))
4971 end)
4972 addElementToScreen(editorSPropDDMenuID,editorSID,1,7)
4973
4974 --input console (string,number,decimal)
4975 addDynamicTextBox(editorSPropDisplayID,"Current value: $value")
4976 changeProperty(editorSPropDisplayID,"width",relX(50,editorSID)-1)
4977 changeProperty(editorSPropDisplayID,"variables",{["value"]=function() return getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) or "nil" end})
4978 changeProperty(editorSPropDisplayID,"textAlignmentHorizontal","center")
4979 changeProperty(editorSPropDisplayID,"visible",false)
4980 addElementToScreen(editorSPropDisplayID,editorSID,1,7)
4981
4982 addDynamicTextBox(editorSPropConsoleInputButtonID,"Change")
4983 changeProperty(editorSPropConsoleInputButtonID,"BGColor",colorPalette[3])
4984 changeProperty(editorSPropConsoleInputButtonID,"textColor",colorPalette[2])
4985 changeProperty(editorSPropConsoleInputButtonID,"borderColor",colorPalette[1])
4986 changeProperty(editorSPropConsoleInputButtonID,"borderThickness",1)
4987 changeProperty(editorSPropConsoleInputButtonID,"width",relX(50,editorSID)-1)
4988 changeProperty(editorSPropConsoleInputButtonID,"onClickMode","flash")
4989 changeProperty(editorSPropConsoleInputButtonID,"activeBGColor",colorPalette[2])
4990 changeProperty(editorSPropConsoleInputButtonID,"activeTextColor",colorPalette[3])
4991 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
4992 changeProperty(editorSPropConsoleInputButtonID,"onActiveFunction",function()
4993 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]~="stringArray" then
4994 changeProperty(editorSPropsID,"visible",false)
4995 changeProperty(editorSPropsMenuID,"enabled",false)
4996 changeProperty(editorSUndoID,"visible",false)
4997 changeProperty(editorSRedoID,"visible",false)
4998 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
4999 changeProperty(editorSPropResetButtonID,"visible",false)
5000 changeProperty(editorSPropConsoleMsgID,"visible",true)
5001 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5002 changeProperty(editorSPropCSTableDDID,"enabled",false)
5003 refresh()
5004 term.setBackgroundColor(colorPalette[2])
5005 term.setTextColor(colorPalette[1])
5006 term.clear()
5007 term.setCursorPos(1,1)
5008 local valid = false
5009 repeat
5010 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..")")
5011 input = read()
5012 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="string" then
5013 valid = true
5014 end
5015 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" then
5016 if tonumber(input)~=nil then
5017 input = math.floor(tonumber(input))
5018 valid = true
5019 else
5020 print("Must be a number!")
5021 end
5022 end
5023 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" then
5024 if tonumber(input)~=nil then
5025 input = (tonumber(input))
5026 valid = true
5027 else
5028 print("Must be a number!")
5029 end
5030 end
5031 until valid
5032 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),input)
5033 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),input)
5034
5035 changeProperty(editorSPropsID,"visible",true)
5036 changeProperty(editorSPropsMenuID,"enabled",true)
5037 changeProperty(editorSUndoID,"visible",true)
5038 changeProperty(editorSRedoID,"visible",true)
5039 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5040 changeProperty(editorSPropResetButtonID,"visible",true)
5041 changeProperty(editorSPropConsoleMsgID,"visible",false)
5042 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5043 changeProperty(editorSPropCSTableDDID,"enabled",true)
5044 fullRefresh()
5045 else
5046 changeProperty(editorSPropsID,"visible",false)
5047 changeProperty(editorSPropsMenuID,"enabled",false)
5048 changeProperty(editorSUndoID,"visible",false)
5049 changeProperty(editorSRedoID,"visible",false)
5050 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5051 changeProperty(editorSPropResetButtonID,"visible",false)
5052 changeProperty(editorSPropConsoleMsgID,"visible",true)
5053 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5054 changeProperty(editorSPropCSTableDDID,"enabled",false)
5055 refresh()
5056 term.setBackgroundColor(colorPalette[2])
5057 term.setTextColor(colorPalette[1])
5058 term.clear()
5059 term.setCursorPos(1,1)
5060 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..") entry number "..getProperty(editorSPropStringArrayDDID,"selectionID")..". To remove this entry press enter.")
5061 input = read()
5062 if input~="" then
5063 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var1 end, function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]=var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries"))[getProperty(editorSPropsMenuID,"selectionID")])[getProperty(editorSPropStringArrayDDID,"selectionID")],input,getProperty(editorSPropStringArrayDDID,"selectionID"))
5064 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropStringArrayDDID,"selectionID")] = input
5065 getProperty(editorSPropStringArrayDDID,"entries")[getProperty(editorSPropStringArrayDDID,"selectionID")] = input
5066 else
5067 local old = copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5068 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),getProperty(editorSPropStringArrayDDID,"selectionID"))
5069 table.remove(getProperty(editorSPropStringArrayDDID,"entries"),getProperty(editorSPropStringArrayDDID,"selectionID"))
5070 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfSimpleArray(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5071 end
5072 changeProperty(editorSPropsID,"visible",true)
5073 changeProperty(editorSPropsMenuID,"enabled",true)
5074 changeProperty(editorSUndoID,"visible",true)
5075 changeProperty(editorSRedoID,"visible",true)
5076 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5077 changeProperty(editorSPropResetButtonID,"visible",true)
5078 changeProperty(editorSPropConsoleMsgID,"visible",false)
5079 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5080 changeProperty(editorSPropCSTableDDID,"enabled",true)
5081 fullRefresh()
5082 end
5083 end)
5084 addElementToScreen(editorSPropConsoleInputButtonID,editorSID,1,designerY-8)
5085
5086 addDynamicTextBox(editorSPropConsoleMsgID,"Please check term!")
5087 changeProperty(editorSPropConsoleMsgID,"borderThickness",1)
5088 changeProperty(editorSPropConsoleMsgID,"width",relX(50,editorSID)-1)
5089 changeProperty(editorSPropConsoleMsgID,"visible",false)
5090 addElementToScreen(editorSPropConsoleMsgID,editorSID,1,designerY-8)
5091
5092 --advanced types: colorsArray,stringArray,navMenuArray,CSTable,CSDesignsTable,picArray
5093
5094 --type colorsArray
5095 addDropDownMenu(editorSPropColorsArrayDDID,{"Use"},1)
5096 changeProperty(editorSPropColorsArrayDDID,"selectionID",1)
5097 changeProperty(editorSPropColorsArrayDDID,"expanded",false)
5098 changeProperty(editorSPropColorsArrayDDID,"highlightID",nil)
5099 changeProperty(editorSPropColorsArrayDDID,"borderThickness",1)
5100 changeProperty(editorSPropColorsArrayDDID,"borderColor",colorPalette[3])
5101 changeProperty(editorSPropColorsArrayDDID,"highlightTextColor",colorPalette[2])
5102 changeProperty(editorSPropColorsArrayDDID,"highlightBGColor",colorPalette[1])
5103 changeProperty(editorSPropColorsArrayDDID,"visible",false)
5104 changeProperty(editorSPropColorsArrayDDID,"expandedMaxHeight",designerY-8)
5105 changeProperty(editorSPropColorsArrayDDID,"onExpandFunction",function()
5106 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5107 local array = {}
5108 local entries = {}
5109 for i=1,getProperty(editorSElementID,"length") do
5110 array[i] = colors.white
5111 entries[i] = i
5112 end
5113 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfSimpleArray(array))
5114 changeProperty(editorSPropColorsArrayDDID,"entries",entries)
5115 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),array)
5116 end end)
5117 changeProperty(editorSPropColorsArrayDDID,"onChangeFunction",function(ID,selection)
5118 changeProperty(editorSPropColorPickID,"visible",true)
5119 changeProperty(editorSPropColorPickID,"selection",getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropColorsArrayDDID,"selectionID")])
5120 end)
5121 addElementToScreen(editorSPropColorsArrayDDID,editorSID,8,7)
5122
5123 --type stringArray
5124 addDropDownMenu(editorSPropStringArrayDDID,nil,1)
5125 changeProperty(editorSPropStringArrayDDID,"selectionID",1)
5126 changeProperty(editorSPropStringArrayDDID,"expanded",false)
5127 changeProperty(editorSPropStringArrayDDID,"highlightID",nil)
5128 changeProperty(editorSPropStringArrayDDID,"borderThickness",1)
5129 changeProperty(editorSPropStringArrayDDID,"borderColor",colorPalette[3])
5130 changeProperty(editorSPropStringArrayDDID,"highlightTextColor",colorPalette[2])
5131 changeProperty(editorSPropStringArrayDDID,"highlightBGColor",colorPalette[1])
5132 changeProperty(editorSPropStringArrayDDID,"visible",false)
5133 changeProperty(editorSPropStringArrayDDID,"expandedMaxHeight",designerY-8)
5134 changeProperty(editorSPropStringArrayDDID,"onChangeFunction",function(ID,selection)
5135 if selection==table.getn(getProperty(editorSPropStringArrayDDID,"entries")) then
5136 pcall(getProperty(editorSPropConsoleInputButtonID,"onActiveFunction"))
5137 table.insert(getProperty(editorSPropStringArrayDDID,"entries"),"+add")
5138 end
5139 end)
5140 addElementToScreen(editorSPropStringArrayDDID,editorSID,1,7)
5141
5142 --type navMenuArray
5143 addDynamicTextBox(editorSPropNavMenuHintID,"Click on any entry to change its text or add entries.")
5144 changeProperty(editorSPropNavMenuHintID,"width",relX(50,editorSID)-1)
5145 changeProperty(editorSPropNavMenuHintID,"visible",false)
5146 addElementToScreen(editorSPropNavMenuHintID,editorSID,1,designerY-8)
5147
5148 addNavigationMenu(editorSPropNavMenuID,"Entries",{})
5149 changeProperty(editorSPropNavMenuID,"expanded",false)
5150 changeProperty(editorSPropNavMenuID,"highlightIDs",nil)
5151 changeProperty(editorSPropNavMenuID,"borderColor",colorPalette[3])
5152 changeProperty(editorSPropNavMenuID,"textAlignmentHorizontal","left")
5153 changeProperty(editorSPropNavMenuID,"borderThickness",1)
5154 changeProperty(editorSPropNavMenuID,"visible",false)
5155 changeProperty(editorSPropNavMenuID,"onChangeFunction",function(ID,numbers)
5156 local temp = getProperty(editorSPropNavMenuID,"menuArray")
5157 local old = copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5158 for i=1,table.getn(numbers)-1 do
5159 temp = temp[numbers[i]]["submenu"]
5160 end
5161 if temp[numbers[table.getn(numbers)]]["text"] == "+add" then
5162 local offset = 0
5163 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5164 for i=1,table.getn(numbers)-1 do
5165 temp2 = temp2[numbers[i]-offset]["submenu"]
5166 offset = 1
5167 end
5168 temp2[numbers[table.getn(numbers)]-offset] = {}
5169 temp2[numbers[table.getn(numbers)]-offset]["text"] = "New"
5170 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5171 end
5172 if temp[numbers[table.getn(numbers)]]["text"] == "+add sub" then
5173 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5174 local offset = 0
5175 for i=1,table.getn(numbers)-2 do
5176 temp2 = temp2[numbers[i]-offset]["submenu"]
5177 offset = 1
5178 end
5179 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"] = {}
5180 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"][1] = {}
5181 temp2[numbers[table.getn(numbers)-1]-offset]["submenu"][1]["text"] = "New"
5182 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5183 end
5184 if temp[numbers[table.getn(numbers)]]["text"] == "<- edit" then
5185 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5186 local highlightIDsString = "entry"
5187 local offset = 0
5188 for i=1,table.getn(numbers)-2 do
5189 temp2 = temp2[numbers[i]-offset]["submenu"]
5190 highlightIDsString = highlightIDsString .. "-"..numbers[i]-offset
5191 offset = 1
5192 end
5193 highlightIDsString = highlightIDsString .. "-"..(numbers[table.getn(numbers)-1]-offset)
5194
5195 local input = "Entry"
5196 changeProperty(editorSPropNavMenuID,"enabled",false)
5197 changeProperty(editorSPropNavMenuHintID,"visible",false)
5198 changeProperty(editorSPropsID,"visible",false)
5199 changeProperty(editorSPropsMenuID,"enabled",false)
5200 changeProperty(editorSUndoID,"visible",false)
5201 changeProperty(editorSRedoID,"visible",false)
5202 changeProperty(editorSPropResetButtonID,"visible",false)
5203 changeProperty(editorSPropConsoleMsgID,"visible",true)
5204 refresh()
5205
5206 term.setBackgroundColor(colorPalette[2])
5207 term.setTextColor(colorPalette[1])
5208 term.clear()
5209 term.setCursorPos(1,1)
5210 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", "..highlightIDsString.." ) To remove entry press enter.")
5211 input = read()
5212
5213 if input~="" then
5214 temp2[numbers[table.getn(numbers)-1]-offset]["text"] = input
5215 else
5216 if not (temp2==getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) and numbers[1]==1) then
5217 temp2[numbers[table.getn(numbers)-1]-offset] = ""
5218 table.remove(temp2,numbers[table.getn(numbers)-1]-offset)
5219 end
5220
5221 local count = 0
5222 for name,data in pairs(temp2) do
5223 count = count + 1
5224 break
5225 end
5226
5227 if count==0 then
5228 local temp2 = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))
5229 local offset = 0
5230 for i=1,table.getn(numbers)-3 do
5231 if i~=1 then
5232 temp2 = temp2[numbers[i]-1]["submenu"]
5233 else
5234 temp2 = temp2[numbers[i]]["submenu"]
5235 end
5236 offset = 1
5237 end
5238 temp2[numbers[table.getn(numbers)-2]-offset]["submenu"] = nil
5239 end
5240 end
5241
5242 changeProperty(editorSPropNavMenuID,"enabled",true)
5243 changeProperty(editorSPropNavMenuHintID,"visible",true)
5244 changeProperty(editorSPropsID,"visible",true)
5245 changeProperty(editorSPropsMenuID,"enabled",true)
5246 changeProperty(editorSUndoID,"visible",true)
5247 changeProperty(editorSRedoID,"visible",true)
5248 changeProperty(editorSPropResetButtonID,"visible",true)
5249 changeProperty(editorSPropConsoleMsgID,"visible",false)
5250
5251 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5252 fullRefresh()
5253 end
5254 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5255 end)
5256 addElementToScreen(editorSPropNavMenuID,editorSID,1,7)
5257
5258 -- type CSTable
5259 addDynamicTextBox(editorSPropCSChangeID,"Change")
5260 changeProperty(editorSPropCSChangeID,"BGColor",colorPalette[3])
5261 changeProperty(editorSPropCSChangeID,"textColor",colorPalette[2])
5262 changeProperty(editorSPropCSChangeID,"borderColor",colorPalette[1])
5263 changeProperty(editorSPropCSChangeID,"borderThickness",1)
5264 changeProperty(editorSPropCSChangeID,"onClickMode","flash")
5265 changeProperty(editorSPropCSChangeID,"activeBGColor",colorPalette[2])
5266 changeProperty(editorSPropCSChangeID,"activeTextColor",colorPalette[3])
5267 changeProperty(editorSPropCSChangeID,"visible",false)
5268 changeProperty(editorSPropCSChangeID,"onActiveFunction",function()
5269 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSTable" then
5270 changeProperty(editorSPropsID,"visible",false)
5271 changeProperty(editorSPropsMenuID,"enabled",false)
5272 changeProperty(editorSUndoID,"visible",false)
5273 changeProperty(editorSRedoID,"visible",false)
5274 changeProperty(editorSPropResetButtonID,"visible",false)
5275 changeProperty(editorSPropConsoleMsgID,"visible",true)
5276 changeProperty(editorSPropCSChangeID,"visible",false)
5277 changeProperty(editorSPropCSRemoveID,"visible",false)
5278 changeProperty(editorSPropCSTableDDID,"enabled",false)
5279 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5280
5281 refresh()
5282
5283 term.setBackgroundColor(colorPalette[2])
5284 term.setTextColor(colorPalette[1])
5285 term.clear()
5286 term.setCursorPos(1,1)
5287
5288 local index = tonumber(string.sub(getProperty(editorSPropCSTableDDID,"entries")[getProperty(editorSPropCSTableDDID,"selectionID")],1,string.find(getProperty(editorSPropCSTableDDID,"entries")[getProperty(editorSPropCSTableDDID,"selectionID")],":")-1))
5289 local _string = "graph "..getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")].." coordinate x="..index
5290 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", ".._string..") To remove coordinate press enter.")
5291 print("Enter a new Y Coordinate:")
5292
5293 local input
5294 local valid = false
5295 repeat
5296 input = read()
5297 if input~="" then
5298 if tonumber(input)~=nil then
5299 input = (tonumber(input))
5300 valid = true
5301 else
5302 print("Must be a number!")
5303 end
5304 else
5305 valid = true
5306 end
5307 until valid
5308
5309 if input~="" then
5310 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3,var4,var5) getProperty(editorSElementID,prop)[var3][var4] = var1 end, function(prop,var1,var2,var3,var4,var5) getProperty(editorSElementID,prop)[var3][var4] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][index],input,tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")]),index)
5311 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][index] = input
5312 else
5313 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5314 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])],index)
5315 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5316 end
5317 changeProperty(editorSPropsID,"visible",true)
5318 changeProperty(editorSPropsMenuID,"enabled",true)
5319 changeProperty(editorSUndoID,"visible",true)
5320 changeProperty(editorSRedoID,"visible",true)
5321 changeProperty(editorSPropResetButtonID,"visible",true)
5322 changeProperty(editorSPropConsoleMsgID,"visible",false)
5323 changeProperty(editorSPropCSChangeID,"visible",true)
5324 changeProperty(editorSPropCSRemoveID,"visible",true)
5325 changeProperty(editorSPropCSTableDDID,"enabled",true)
5326 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5327 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5328 fullRefresh()
5329 end
5330 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
5331 changeProperty(editorSPropsID,"visible",false)
5332 changeProperty(editorSPropsMenuID,"enabled",false)
5333 changeProperty(editorSUndoID,"visible",false)
5334 changeProperty(editorSRedoID,"visible",false)
5335 changeProperty(editorSPropResetButtonID,"visible",false)
5336 changeProperty(editorSPropConsoleMsgID,"visible",true)
5337 changeProperty(editorSPropCSChangeID,"visible",false)
5338 changeProperty(editorSPropCSDesignsDDID,"enabled",false)
5339 changeProperty(editorSPropCSDesignsIndexDDID,"enabled",false)
5340
5341 refresh()
5342
5343 term.setBackgroundColor(colorPalette[2])
5344 term.setTextColor(colorPalette[1])
5345 term.clear()
5346 term.setCursorPos(1,1)
5347 print("Please enter a new value for property '"..(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]).."' ("..elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]..", graph number "..getProperty(editorSPropCSDesignsIndexDDID,"selectionID")..", character)")
5348
5349 local input = read()
5350
5351 if input~="" then
5352 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]["character"] = var1 end,function(prop,var1,var2,var3) getProperty(editorSElementID,prop)[var3]["character"] = var2 end,getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"],string.sub(input,1,1),getProperty(editorSPropCSDesignsIndexDDID,"selectionID"))
5353 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"] = string.sub(input,1,1)
5354 end
5355
5356 changeProperty(editorSPropsID,"visible",true)
5357 changeProperty(editorSPropsMenuID,"enabled",true)
5358 changeProperty(editorSUndoID,"visible",true)
5359 changeProperty(editorSRedoID,"visible",true)
5360 changeProperty(editorSPropResetButtonID,"visible",true)
5361 changeProperty(editorSPropConsoleMsgID,"visible",false)
5362 changeProperty(editorSPropCSChangeID,"visible",true)
5363 changeProperty(editorSPropCSDesignsDDID,"enabled",true)
5364 changeProperty(editorSPropCSDesignsIndexDDID,"enabled",true)
5365 pcall(getProperty(editorSPropsMenuID,"onChangeFunction"))
5366 fullRefresh()
5367 end
5368 end)
5369 addElementToScreen(editorSPropCSChangeID,editorSID,1,designerY-8)
5370
5371 addDynamicTextBox(editorSPropCSRemoveID,"Remove")
5372 changeProperty(editorSPropCSRemoveID,"BGColor",colorPalette[3])
5373 changeProperty(editorSPropCSRemoveID,"textColor",colorPalette[2])
5374 changeProperty(editorSPropCSRemoveID,"borderColor",colorPalette[1])
5375 changeProperty(editorSPropCSRemoveID,"borderThickness",1)
5376 changeProperty(editorSPropCSRemoveID,"onClickMode","flash")
5377 changeProperty(editorSPropCSRemoveID,"activeBGColor",colorPalette[2])
5378 changeProperty(editorSPropCSRemoveID,"activeTextColor",colorPalette[3])
5379 changeProperty(editorSPropCSRemoveID,"visible",false)
5380 changeProperty(editorSPropCSRemoveID,"onActiveFunction",function()
5381 if table.getn(getProperty(editorSPropCSTableIndexDDID,"entries"))>2 then
5382 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5383 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSTableIndexDDID,"selectionID")] = ""
5384 table.remove(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5385 table.remove(getProperty(editorSPropCSTableIndexDDID,"entries"),getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5386 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5387 changeProperty(editorSPropCSTableIndexDDID,"selectionID",getProperty(editorSPropCSTableIndexDDID,"selectionID")-1)
5388 pcall(getProperty(editorSPropCSTableIndexDDID,"onChangeFunction"),editorSPropCSTableIndexDDID,getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5389 end
5390 end)
5391 addElementToScreen(editorSPropCSRemoveID,editorSID,relX(50,editorSID)+1-9,designerY-8)
5392
5393 addDropDownMenu(editorSPropCSTableIndexDDID,{"Use"},1)
5394 changeProperty(editorSPropCSTableIndexDDID,"selectionID",1)
5395 changeProperty(editorSPropCSTableIndexDDID,"expanded",false)
5396 changeProperty(editorSPropCSTableIndexDDID,"highlightID",nil)
5397 changeProperty(editorSPropCSTableIndexDDID,"borderThickness",1)
5398 changeProperty(editorSPropCSTableIndexDDID,"borderColor",colorPalette[3])
5399 changeProperty(editorSPropCSTableIndexDDID,"highlightTextColor",colorPalette[2])
5400 changeProperty(editorSPropCSTableIndexDDID,"highlightBGColor",colorPalette[1])
5401 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
5402 changeProperty(editorSPropCSTableIndexDDID,"width",8)
5403 changeProperty(editorSPropCSTableIndexDDID,"expandedMaxHeight",designerY-8)
5404 changeProperty(editorSPropCSTableIndexDDID,"onExpandFunction",function(ID)
5405 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5406 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),{[1]={}})
5407 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5408 changeProperty(editorSPropCSTableDDID,"entries",{"+add"})
5409 changeProperty(editorSPropCSTableIndexDDID,"entries",{"1","+add"})
5410 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5411 changeProperty(editorSPropCSTableDDID,"visible",true)
5412 changeProperty(editorSPropCSChangeID,"visible",true)
5413 changeProperty(editorSPropCSRemoveID,"visible",true)
5414 end
5415 end)
5416 changeProperty(editorSPropCSTableIndexDDID,"onChangeFunction",function(ID,selection)
5417 if selection~=table.getn(getProperty(editorSPropCSTableIndexDDID,"entries")) then
5418 local array = {}
5419 for name,data in pairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[selection]) do
5420 table.insert(array,name..":"..data)
5421 end
5422 table.insert(array,"+add")
5423 changeProperty(editorSPropCSTableDDID,"entries",array)
5424 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5425 changeProperty(editorSPropCSTableDDID,"visible",true)
5426 changeProperty(editorSPropCSChangeID,"visible",true)
5427 changeProperty(editorSPropCSRemoveID,"visible",true)
5428 else
5429 local old = copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5430 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[selection] = {}
5431 getProperty(editorSPropCSTableIndexDDID,"entries")[selection] = ""..selection
5432 getProperty(editorSPropCSTableIndexDDID,"entries")[selection+1] = "+add"
5433 pcall(editorSPropCSTableIndexDDID,"onChangeFunction",ID,selection)
5434 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),old,copyOfCSTable(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))))
5435 end
5436 end)
5437 addElementToScreen(editorSPropCSTableIndexDDID,editorSID,relX(50,editorSID)+1-9,7)
5438
5439 addDropDownMenu(editorSPropCSTableDDID,{},1)
5440 changeProperty(editorSPropCSTableDDID,"selectionID",1)
5441 changeProperty(editorSPropCSTableDDID,"expanded",false)
5442 changeProperty(editorSPropCSTableDDID,"highlightID",nil)
5443 changeProperty(editorSPropCSTableDDID,"borderThickness",1)
5444 changeProperty(editorSPropCSTableDDID,"borderColor",colorPalette[3])
5445 changeProperty(editorSPropCSTableDDID,"highlightTextColor",colorPalette[2])
5446 changeProperty(editorSPropCSTableDDID,"highlightBGColor",colorPalette[1])
5447 changeProperty(editorSPropCSTableDDID,"visible",false)
5448 changeProperty(editorSPropCSTableDDID,"expandedMaxHeight",designerY-8)
5449 changeProperty(editorSPropCSTableDDID,"onChangeFunction",function(ID,selection)
5450 if selection==table.getn(getProperty(editorSPropCSTableDDID,"entries")) then
5451 changeProperty(editorSPropsID,"visible",false)
5452 changeProperty(editorSPropsMenuID,"enabled",false)
5453 changeProperty(editorSUndoID,"visible",false)
5454 changeProperty(editorSRedoID,"visible",false)
5455 changeProperty(editorSPropResetButtonID,"visible",false)
5456 changeProperty(editorSPropConsoleMsgID,"visible",true)
5457 changeProperty(editorSPropCSChangeID,"visible",false)
5458 changeProperty(editorSPropCSRemoveID,"visible",false)
5459 changeProperty(editorSPropCSTableDDID,"enabled",false)
5460 changeProperty(editorSPropCSTableIndexDDID,"enabled",false)
5461
5462 refresh()
5463
5464 term.setBackgroundColor(colorPalette[2])
5465 term.setTextColor(colorPalette[1])
5466 term.clear()
5467 term.setCursorPos(1,1)
5468 print("Enter a new x coordinate:")
5469
5470 local input
5471 local valid = false
5472 repeat
5473 input = read()
5474 if tonumber(input)~=nil then
5475 input = (tonumber(input))
5476 valid = true
5477 else
5478 print("Must be a number!")
5479 end
5480 until valid
5481
5482 getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[tonumber(getProperty(editorSPropCSTableIndexDDID,"entries")[getProperty(editorSPropCSTableIndexDDID,"selectionID")])][input] = 0
5483
5484 changeProperty(editorSPropsID,"visible",true)
5485 changeProperty(editorSPropsMenuID,"enabled",true)
5486 changeProperty(editorSUndoID,"visible",true)
5487 changeProperty(editorSRedoID,"visible",true)
5488 changeProperty(editorSPropResetButtonID,"visible",true)
5489 changeProperty(editorSPropConsoleMsgID,"visible",false)
5490 changeProperty(editorSPropCSChangeID,"visible",true)
5491 changeProperty(editorSPropCSRemoveID,"visible",true)
5492 changeProperty(editorSPropCSTableDDID,"enabled",true)
5493 changeProperty(editorSPropCSTableIndexDDID,"enabled",true)
5494
5495 getProperty(editorSPropCSTableDDID,"entries")[selection] = input..":0"
5496
5497 pcall(getProperty(editorSPropCSChangeID,"onActiveFunction"))
5498 end
5499 end)
5500 addElementToScreen(editorSPropCSTableDDID,editorSID,1,7)
5501
5502 --type CSDesigns
5503 addDropDownMenu(editorSPropCSDesignsIndexDDID,{"Use"})
5504 changeProperty(editorSPropCSDesignsIndexDDID,"selectionID",1)
5505 changeProperty(editorSPropCSDesignsIndexDDID,"expanded",false)
5506 changeProperty(editorSPropCSDesignsIndexDDID,"highlightID",nil)
5507 changeProperty(editorSPropCSDesignsIndexDDID,"borderThickness",1)
5508 changeProperty(editorSPropCSDesignsIndexDDID,"borderColor",colorPalette[3])
5509 changeProperty(editorSPropCSDesignsIndexDDID,"highlightTextColor",colorPalette[2])
5510 changeProperty(editorSPropCSDesignsIndexDDID,"highlightBGColor",colorPalette[1])
5511 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
5512 changeProperty(editorSPropCSDesignsIndexDDID,"width",8)
5513 changeProperty(editorSPropCSDesignsIndexDDID,"expandedMaxHeight",designerY-8)
5514 changeProperty(editorSPropCSDesignsIndexDDID,"onExpandFunction",function()
5515 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))==nil then
5516 local array = {}
5517 local array2 = {}
5518 for name,data in ipairs(getProperty(editorSElementID,"graphTables")) do
5519 array[name] = name..""
5520 array2[name] = {}
5521 end
5522 changeProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),array2)
5523 addToUndoRedoTable((getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]),nil,copyOfCSDesignsTable(array2))
5524 changeProperty(editorSPropCSDesignsIndexDDID,"entries",array)
5525 end
5526 end)
5527 changeProperty(editorSPropCSDesignsIndexDDID,"onChangeFunction",function(id,selection)
5528 changeProperty(editorSPropCSDesignsDDID,"visible",true)
5529 pcall(getProperty(editorSPropCSDesignsDDID,"onChangeFunction"))
5530 end)
5531 addElementToScreen(editorSPropCSDesignsIndexDDID,editorSID,relX(50,editorSID)+1-9,7)
5532
5533 addDropDownMenu(editorSPropCSDesignsDDID,{"color","BG","char"})
5534 changeProperty(editorSPropCSDesignsDDID,"selectionID",1)
5535 changeProperty(editorSPropCSDesignsDDID,"expanded",false)
5536 changeProperty(editorSPropCSDesignsDDID,"highlightID",nil)
5537 changeProperty(editorSPropCSDesignsDDID,"borderThickness",1)
5538 changeProperty(editorSPropCSDesignsDDID,"borderColor",colorPalette[3])
5539 changeProperty(editorSPropCSDesignsDDID,"highlightTextColor",colorPalette[2])
5540 changeProperty(editorSPropCSDesignsDDID,"highlightBGColor",colorPalette[1])
5541 changeProperty(editorSPropCSDesignsDDID,"visible",false)
5542 changeProperty(editorSPropCSDesignsDDID,"width",9)
5543 changeProperty(editorSPropCSDesignsDDID,"expandedMaxHeight",designerY-8)
5544 changeProperty(editorSPropCSDesignsDDID,"onChangeFunction",function(id,selection)
5545 if selection==nil then
5546 selection = getProperty(editorSPropCSDesignsDDID,"selectionID")
5547 end
5548 if selection~=3 then
5549 changeProperty(editorSPropCSChangeID,"visible",false)
5550 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5551 changeProperty(editorSPropColorPickID,"visible",true)
5552 local color = nil
5553 if selection==1 then
5554 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["color"]~=nil then
5555 color = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["color"]
5556 end
5557 else
5558 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["BGColor"]~=nil then
5559 color = getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["BGColor"]
5560 end
5561 end
5562 changeProperty(editorSPropColorPickID,"selection",color)
5563 else
5564 changeProperty(editorSPropCSChangeID,"visible",true)
5565 changeProperty(editorSPropCSDesignsDisplayID,"visible",true)
5566 changeProperty(editorSPropColorPickID,"visible",false)
5567 end
5568 end)
5569 addElementToScreen(editorSPropCSDesignsDDID,editorSID,relX(50,editorSID)+1-10,designerY-8)
5570
5571 addDynamicTextBox(editorSPropCSDesignsDisplayID,"Current char: $var")
5572 changeProperty(editorSPropCSDesignsDisplayID,"width",relX(50,editorSID)-1-9)
5573 changeProperty(editorSPropCSDesignsDisplayID,"variables",{["var"]=function() return getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))[getProperty(editorSPropCSDesignsIndexDDID,"selectionID")]["character"] or "nil" end})
5574 changeProperty(editorSPropCSDesignsDisplayID,"textAlignmentHorizontal","center")
5575 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5576 addElementToScreen(editorSPropCSDesignsDisplayID,editorSID,1,7)
5577
5578 --type linesArray
5579 addDynamicTextBox(editorSPropPicEditButtonID,"Edit")
5580 changeProperty(editorSPropPicEditButtonID,"BGColor",colorPalette[3])
5581 changeProperty(editorSPropPicEditButtonID,"textColor",colorPalette[2])
5582 changeProperty(editorSPropPicEditButtonID,"borderColor",colorPalette[1])
5583 changeProperty(editorSPropPicEditButtonID,"borderThickness",1)
5584 changeProperty(editorSPropPicEditButtonID,"onClickMode","flash")
5585 changeProperty(editorSPropPicEditButtonID,"width",relX(50,editorSID)-1)
5586 changeProperty(editorSPropPicEditButtonID,"activeBGColor",colorPalette[2])
5587 changeProperty(editorSPropPicEditButtonID,"activeTextColor",colorPalette[3])
5588 changeProperty(editorSPropPicEditButtonID,"visible",false)
5589 changeProperty(editorSPropPicEditButtonID,"onActiveFunction",function()
5590 addElementToScreen(editorSElementID,pictureESID,editorSElementX,editorSElementY)
5591 addElementToScreen(editorSUndoID,pictureESID,relX(50,editorSID)-6,designerY)
5592 addElementToScreen(editorSRedoID,pictureESID,relX(50,editorSID)+1,designerY)
5593 addElementToScreen(pictureESButtonBackID,pictureESID,1,designerY)
5594 addElementToScreen(pictureESCoordsDisplayID,pictureESID,designerX-11,designerY)
5595 addElementToScreen(pictureESControlPicID,pictureESID,designerX-5,designerY-5)
5596 addElementToScreen(pictureESIndicatorID,pictureESID,editorSElementX,editorSElementY)
5597 addElementToScreen(pictureESUseDefault2ID,pictureESID,designerX-8,designerY-7)
5598 addElementToScreen(pictureESColorPick2ID,pictureESID,designerX-5,designerY-11)
5599 addElementToScreen(pictureESUseDefault1ID,pictureESID,designerX-8,designerY-12)
5600 addElementToScreen(pictureESColorPick1ID,pictureESID,designerX-5,designerY-16)
5601 addElementToScreen(pictureESChangeID,pictureESID,designerX-7,designerY-18)
5602 addElementToScreen(pictureESTransparentID,pictureESID,designerX-12,designerY-1)
5603 pictureESCurrentX = 1
5604 pictureESCurrentY = 1
5605 setProcessClickEventFunction(function(type_,id,part)
5606 if id==editorSElementID then
5607 pictureESCurrentX = tonumber(string.sub(part,1,string.find(part,":")-1))
5608 pictureESCurrentY = tonumber(string.sub(part,string.find(part,":")+1))
5609 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5610 onPixelSelecChange()
5611 refresh()
5612 end
5613 if id==pictureESControlPicID then
5614 --y gets smaller
5615 if part=="3:1" then
5616 pictureESCurrentY = math.max(pictureESCurrentY-1,1)
5617 end
5618 --y gets bigger
5619 if part=="3:3" then
5620 pictureESCurrentY = math.min(pictureESCurrentY+1,getProperty(editorSElementID,"height"))
5621 end
5622 --x gets smaller
5623 if part=="1:2" then
5624 pictureESCurrentX = math.max(pictureESCurrentX-1,1)
5625 end
5626 --x gets bigger
5627 if part=="5:2" then
5628 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5629 end
5630 if part=="3:2" then
5631 changeProperty(pictureESIndicatorID,"visible",not getProperty(pictureESIndicatorID,"visible"))
5632 end
5633
5634 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5635 onPixelSelecChange()
5636 refresh()
5637 end
5638 end)
5639
5640 setProcessEventFunction(function(event,var1)
5641 if name=="timer" then
5642 if var1==saveTimerID then
5643 saveElement(editorSElementID,editorSElementType)
5644 saveTimerID = os.startTimer(180)
5645 lastSave = os.clock()
5646 end
5647 end
5648 if event=="key" then
5649 if var1==200 then
5650 pictureESCurrentY = math.max(pictureESCurrentY-1,1)
5651 end
5652 if var1==208 then
5653 pictureESCurrentY = math.min(pictureESCurrentY+1,getProperty(editorSElementID,"height"))
5654 end
5655 if var1==203 then
5656 pictureESCurrentX = math.max(pictureESCurrentX-1,1)
5657 end
5658 if var1==205 then
5659 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5660 end
5661 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5662 onPixelSelecChange()
5663 refresh()
5664 end
5665 if event=="char" then
5666 local new = var1
5667 local s = getPixelString()
5668 if string.len(s)==0 then
5669 writePixelString("*:#:"..new)
5670 end
5671 if string.len(s)==1 then
5672 writePixelString("*:"..s..":"..new)
5673 end
5674 if string.len(s)==5 then
5675 writePixelString(string.sub(s,1,4)..new)
5676 end
5677 pictureESCurrentX = math.min(pictureESCurrentX+1,getProperty(editorSElementID,"width"))
5678 changePos(pictureESIndicatorID,pictureESID,pictureESCurrentX+editorSElementX-1,pictureESCurrentY+editorSElementY-1)
5679 onPixelSelecChange()
5680 refresh()
5681 end
5682 if event=="paste" then
5683 for i=1,string.len(var1) do
5684 os.queueEvent("char",string.sub(var1,i,i))
5685 end
5686 end
5687 end)
5688
5689 setDesignerScreen(pictureESID)
5690 onPixelSelecChange()
5691 fullRefresh()
5692 end)
5693 addElementToScreen(editorSPropPicEditButtonID,editorSID,1,7)
5694
5695 addScreen(pictureESID,designerX,designerY,colorPalette[1],colorPalette[2])
5696 addDynamicTextBox(pictureESButtonBackID,"<Back>")
5697 changeProperty(pictureESButtonBackID,"onClickMode","flash")
5698 changeProperty(pictureESButtonBackID,"onActiveFunction",function()
5699 removeElementFromScreen(editorSElementID,pictureESID)
5700 removeElementFromScreen(editorSUndoID,pictureESID)
5701 removeElementFromScreen(editorSRedoID,pictureESID)
5702 removeElementFromScreen(pictureESButtonBackID,pictureESID)
5703 removeElementFromScreen(pictureESCoordsDisplayID,pictureESID)
5704 removeElementFromScreen(pictureESControlPicID,pictureESID)
5705 removeElementFromScreen(pictureESIndicatorID,pictureESID)
5706 removeElementFromScreen(pictureESColorPick2ID,pictureESID)
5707 removeElementFromScreen(pictureESUseDefault2ID,pictureESID)
5708 removeElementFromScreen(pictureESColorPick1ID,pictureESID)
5709 removeElementFromScreen(pictureESUseDefault1ID,pictureESID)
5710 removeElementFromScreen(pictureESTransparentID,pictureESID)
5711 removeElementFromScreen(pictureESChangeID,pictureESID)
5712 setProcessEventFunction(processEditorEvents)
5713 setProcessClickEventFunction(nil)
5714
5715 setDesignerScreen(editorSID)
5716 fullRefresh()
5717 end)
5718
5719 local c = colorsArrayNumToString[colorPalette[3]]
5720 addDynamicTextBox(pictureESCoordsDisplayID,"Pixel: $x:$y")
5721 changeProperty(pictureESCoordsDisplayID,"textAlignmentHorizontal","right")
5722 changeProperty(pictureESCoordsDisplayID,"width",12)
5723 changeProperty(pictureESCoordsDisplayID,"variables",{["x"]=function() return pictureESCurrentX end,["y"]=function() return pictureESCurrentY end})
5724
5725 addPicture(pictureESControlPicID,5,3,{";;*:#:^;;;","*:#:<;;"..c..":#:+;;*:#:>;",";;*:#:v;;;"})
5726 addDynamicTextBox(pictureESIndicatorID," ")
5727 changeProperty(pictureESIndicatorID,"BGColor",colorPalette[3])
5728
5729 addDynamicTextBox(pictureESUseDefault1ID,"<Default>")
5730 changeProperty(pictureESUseDefault1ID,"onClickMode","toggle")
5731 changeProperty(pictureESUseDefault1ID,"activeBGColor",colorPalette[1])
5732 changeProperty(pictureESUseDefault1ID,"activeTextColor",colorPalette[2])
5733 changeProperty(pictureESUseDefault1ID,"onActiveFunction",function()
5734 changeProperty(pictureESTransparentID,"active",false)
5735 changeProperty(pictureESColorPick1ID,"selection",nil)
5736 local s = getPixelString()
5737 if string.len(s)==0 then
5738 writePixelString("*:#: ")
5739 end
5740 if string.len(s)==1 then
5741 writePixelString("*:"..s..": ")
5742 end
5743 if string.len(s)==5 then
5744 writePixelString("*"..string.sub(s,2))
5745 end
5746 refresh()
5747 end)
5748 changeProperty(pictureESUseDefault1ID,"onInactiveFunction",function()
5749 changeProperty(pictureESUseDefault1ID,"active",true)
5750 refresh()
5751 end)
5752
5753 addDynamicTextBox(pictureESUseDefault2ID,"<Default>")
5754 changeProperty(pictureESUseDefault2ID,"onClickMode","toggle")
5755 changeProperty(pictureESUseDefault2ID,"activeBGColor",colorPalette[1])
5756 changeProperty(pictureESUseDefault2ID,"activeTextColor",colorPalette[2])
5757 changeProperty(pictureESUseDefault2ID,"onActiveFunction",function()
5758 changeProperty(pictureESTransparentID,"active",false)
5759 changeProperty(pictureESColorPick2ID,"selection",nil)
5760 local s = getPixelString()
5761 if string.len(s)==0 or string.len(s)==1 then
5762 writePixelString("#")
5763 end
5764 if string.len(s)==5 then
5765 writePixelString(string.sub(s,1,2).."#"..string.sub(s,4,5))
5766 end
5767 refresh()
5768 end)
5769 changeProperty(pictureESUseDefault2ID,"onInactiveFunction",function()
5770 changeProperty(pictureESUseDefault2ID,"active",true)
5771 refresh()
5772 end)
5773
5774 addColorPicker(pictureESColorPick1ID,nil)
5775 changeProperty(pictureESColorPick1ID,"onChangeFunction",function(ID,selection)
5776 changeProperty(pictureESUseDefault1ID,"active",false)
5777 changeProperty(pictureESTransparentID,"active",false)
5778 local s = getPixelString()
5779 if string.len(s)==0 then
5780 writePixelString(colorsArrayNumToString[selection]..":#: ")
5781 end
5782 if string.len(s)==1 then
5783 writePixelString(colorsArrayNumToString[selection]..":"..s..": ")
5784 end
5785 if string.len(s)==5 then
5786 writePixelString(colorsArrayNumToString[selection]..string.sub(s,2))
5787 end
5788 refresh()
5789 end)
5790
5791 addColorPicker(pictureESColorPick2ID,nil)
5792 changeProperty(pictureESColorPick2ID,"onChangeFunction",function(ID,selection)
5793 changeProperty(pictureESUseDefault2ID,"active",false)
5794 changeProperty(pictureESTransparentID,"active",false)
5795 local s = getPixelString()
5796 if string.len(s)==0 or string.len(s)==1 then
5797 writePixelString(colorsArrayNumToString[selection])
5798 end
5799 if string.len(s)==5 then
5800 writePixelString(string.sub(s,1,2)..colorsArrayNumToString[selection]..string.sub(s,4,5))
5801 end
5802 refresh()
5803 end)
5804
5805 addDynamicTextBox(pictureESChangeID,"Char: $c <Change>")
5806 changeProperty(pictureESChangeID,"onClickMode","flash")
5807 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
5808 changeProperty(pictureESChangeID,"onActiveFunction",function()
5809 changeProperty(pictureESChangeID,"content","Check term!")
5810
5811 term.setBackgroundColor(colorPalette[2])
5812 term.setTextColor(colorPalette[1])
5813 term.clear()
5814 term.setCursorPos(1,1)
5815
5816 print("Enter a new character for coordinate "..pictureESCurrentX..":"..pictureESCurrentY)
5817
5818 local new = read()
5819 if new=="" then new = " " end
5820 new = string.sub(new,1,1)
5821
5822 local s = getPixelString()
5823 if string.len(s)==0 then
5824 writePixelString("*:#:"..new)
5825 end
5826 if string.len(s)==1 then
5827 writePixelString("*:"..s..":"..new)
5828 end
5829 if string.len(s)==5 then
5830 writePixelString(string.sub(s,1,4)..new)
5831 end
5832
5833 changeProperty(pictureESChangeID,"content","Char: $c <Change>")
5834 onPixelSelecChange()
5835 fullRefresh()
5836 end)
5837
5838 addDynamicTextBox(pictureESTransparentID,"<Transparent>")
5839 changeProperty(pictureESTransparentID,"onClickMode","toggle")
5840 changeProperty(pictureESTransparentID,"activeBGColor",colorPalette[1])
5841 changeProperty(pictureESTransparentID,"activeTextColor",colorPalette[2])
5842 changeProperty(pictureESTransparentID,"onActiveFunction",function()
5843 writePixelString("")
5844 changeProperty(pictureESUseDefault1ID,"active",false)
5845 changeProperty(pictureESUseDefault2ID,"active",false)
5846 end)
5847 changeProperty(pictureESTransparentID,"onInactiveFunction",function()
5848 writePixelString("#")
5849 changeProperty(pictureESUseDefault1ID,"active",false)
5850 changeProperty(pictureESUseDefault2ID,"active",true)
5851 end)
5852
5853 addDropDownMenu(editorSPropsMenuID,nil,1)
5854 changeProperty(editorSPropsMenuID,"selectionID",1)
5855 changeProperty(editorSPropsMenuID,"expanded",false)
5856 changeProperty(editorSPropsMenuID,"highlightID",nil)
5857 changeProperty(editorSPropsMenuID,"borderThickness",1)
5858 changeProperty(editorSPropsMenuID,"borderColor",colorPalette[3])
5859 changeProperty(editorSPropsMenuID,"highlightTextColor",colorPalette[2])
5860 changeProperty(editorSPropsMenuID,"highlightBGColor",colorPalette[1])
5861 changeProperty(editorSPropsMenuID,"visible",false)
5862 changeProperty(editorSPropsMenuID,"width",relX(50,editorSID)-1)
5863 changeProperty(editorSPropsMenuID,"expandedMaxHeight",designerY-4)
5864 changeProperty(editorSPropsMenuID,"onChangeFunction",function() changeProperty(editorSDescID,"content",elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["desc"])
5865 changeProperty(editorSPropColorPickID,"visible",false)
5866 changeProperty(editorSPropDDMenuID,"visible",false)
5867 changeProperty(editorSPropDisplayID,"visible",false)
5868 changeProperty(editorSPropConsoleInputButtonID,"visible",false)
5869 changeProperty(editorSPropColorPickID,"selection",nil)
5870 changeProperty(editorSPropColorsArrayDDID,"visible",false)
5871 changeProperty(editorSPropStringArrayDDID,"visible",false)
5872 changeProperty(editorSPropNavMenuID,"visible",false)
5873 changeProperty(editorSPropNavMenuHintID,"visible",false)
5874 changeProperty(editorSPropCSTableIndexDDID,"visible",false)
5875 changeProperty(editorSPropCSTableDDID,"visible",false)
5876 changeProperty(editorSPropCSChangeID,"visible",false)
5877 changeProperty(editorSPropCSRemoveID,"visible",false)
5878 changeProperty(editorSPropCSDesignsDDID,"visible",false)
5879 changeProperty(editorSPropCSDesignsIndexDDID,"visible",false)
5880 changeProperty(editorSPropCSDesignsDisplayID,"visible",false)
5881 changeProperty(editorSPropPicEditButtonID,"visible",false)
5882
5883 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]~="manual" then
5884 changeProperty(editorSPropResetButtonID,"visible",true)
5885 else
5886 changeProperty(editorSPropResetButtonID,"visible",false)
5887 end
5888 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="color" then
5889 changeProperty(editorSPropColorPickID,"visible",true)
5890 changeProperty(editorSPropColorPickID,"selection",getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])))
5891 end
5892 if string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],1,3)=="DDM" then
5893 changeProperty(editorSPropDDMenuID,"visible",true)
5894 local array = {""}
5895 local menusS = string.sub(elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"],5)
5896 while string.find(menusS,":") do
5897 table.insert(array,string.sub(menusS,1,string.find(menusS,":")-1))
5898 menusS = string.sub(menusS,string.find(menusS,":")+1)
5899 end
5900 table.insert(array,menusS)
5901 changeProperty(editorSPropDDMenuID,"entries",array)
5902 changeProperty(editorSPropDDMenuID,"selectionID",1)
5903 for i,entry in ipairs(array) do
5904 if entry==getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])) then
5905 changeProperty(editorSPropDDMenuID,"selectionID",i)
5906 end
5907 end
5908 end
5909 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="number" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="decimal" or elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="string" then
5910 changeProperty(editorSPropDisplayID,"visible",true)
5911 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5912 end
5913 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="colorsArray" then
5914 changeProperty(editorSPropColorsArrayDDID,"visible",true)
5915 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
5916 local array = {}
5917 for i=1,table.getn(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
5918 array[i] = i
5919 end
5920 changeProperty(editorSPropColorsArrayDDID,"entries",array)
5921 pcall(getProperty(editorSPropColorsArrayDDID,"onChangeFunction"),editorSPropColorsArrayDDID,1)
5922 else
5923 changeProperty(editorSPropColorsArrayDDID,"entries",{"Use"})
5924 end
5925 end
5926 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="stringArray" then
5927 changeProperty(editorSPropStringArrayDDID,"visible",true)
5928 local array = {}
5929 for i,current in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
5930 table.insert(array,current)
5931 end
5932 table.insert(array,"+add")
5933 changeProperty(editorSPropStringArrayDDID,"entries",array)
5934 changeProperty(editorSPropConsoleInputButtonID,"visible",true)
5935 end
5936 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="navMenuArray" then
5937 changeProperty(editorSPropNavMenuID,"menuArray",prepNavMenu(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])),{}))
5938 changeProperty(editorSPropNavMenuID,"visible",true)
5939 changeProperty(editorSPropNavMenuID,"expanded",false)
5940 changeProperty(editorSPropNavMenuHintID,"visible",true)
5941 end
5942 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSTable" then
5943 changeProperty(editorSPropCSTableIndexDDID,"visible",true)
5944 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
5945 local array = {}
5946 for i,data in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
5947 array[i] = ""..i
5948 end
5949 table.insert(array,"+add")
5950 changeProperty(editorSPropCSTableIndexDDID,"entries",array)
5951 pcall(getProperty(editorSPropCSTableIndexDDID,"onChangeFunction"),editorSPropCSTableIndexDDID,getProperty(editorSPropCSTableIndexDDID,"selectionID"))
5952 else
5953 changeProperty(editorSPropCSTableIndexDDID,"entries",{"Use"})
5954 end
5955 end
5956 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="CSDesignsTable" then
5957 if getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))~=nil then
5958 local array = {}
5959 for i,data in ipairs(getProperty(editorSElementID,(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")]))) do
5960 array[i] = ""..i
5961 end
5962 changeProperty(editorSPropCSDesignsIndexDDID,"entries",array)
5963 changeProperty(editorSPropCSDesignsIndexDDID,"visible",true)
5964 pcall(getProperty(editorSPropCSDesignsIndexDDID,"onChangeFunction"))
5965 else
5966 if getProperty(editorSElementID,"graphTables")~=nil then
5967 changeProperty(editorSPropCSDesignsIndexDDID,"visible",true)
5968 changeProperty(editorSPropCSDesignsIndexDDID,"entries",{"Use"})
5969 end
5970 end
5971 end
5972 if elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["input"]=="picArray" then
5973 changeProperty(editorSPropPicEditButtonID,"visible",true)
5974 end
5975 end)
5976 addElementToScreen(editorSPropsMenuID,editorSID,1,3)
5977
5978 addDynamicTextBox(editorSHideUIID,"<Hide UI>")
5979 changeProperty(editorSHideUIID,"onClickMode","flash")
5980 changeProperty(editorSHideUIID,"activeDuration",3)
5981 changeProperty(editorSHideUIID,"onActiveFunction",function()
5982 changeProperty(editorSExitID,"visible",false)
5983 changeProperty(editorSPropsID,"visible",false)
5984 changeProperty(editorSUndoID,"visible",false)
5985 changeProperty(editorSRelocateButtonID,"visible",false)
5986 changeProperty(editorSLastSaveID,"visible",false)
5987 changeProperty(editorSRedoID,"visible",false)
5988 changeProperty(editorSHideUIID,"visible",false) end)
5989 changeProperty(editorSHideUIID,"onInactiveFunction",function()
5990 changeProperty(editorSExitID,"visible",true)
5991 changeProperty(editorSPropsID,"visible",true)
5992 changeProperty(editorSUndoID,"visible",true)
5993 changeProperty(editorSRelocateButtonID,"visible",true)
5994 changeProperty(editorSLastSaveID,"visible",true)
5995 changeProperty(editorSRedoID,"visible",true)
5996 changeProperty(editorSHideUIID,"visible",true) end)
5997 addElementToScreen(editorSHideUIID,editorSID,12,1)
5998
5999 setDesignerScreen(editorSID)
6000 refresh()
6001end
6002
6003function getPixelString(x_,y_)
6004 local x
6005 local y
6006 if x_==nil then x = pictureESCurrentX else x = x_ end
6007 if y_==nil then y = pictureESCurrentY else y = y_ end
6008 local s = getProperty(editorSElementID,"linesArray")[y]
6009 for i=1,x-1 do
6010 s = string.sub(s,string.find(s,";")+1)
6011 end
6012 return string.sub(s,1,string.find(s,";")-1)
6013end
6014
6015function writePixelString(new,x_,y_,bool)
6016 local x
6017 local y
6018 if x_==nil then x = pictureESCurrentX else x = x_ end
6019 if y_==nil then y = pictureESCurrentY else y = y_ end
6020 if not bool then
6021 addToUndoRedoTable("linesArray",function(prop,var1,var2,var3,var4) writePixelString(var1,var3,var4,true) end, function(prop,var1,var2,var3,var4) writePixelString(var2,var3,var4,true) end,getPixelString(x,y),new,x,y)
6022 end
6023 local s = getProperty(editorSElementID,"linesArray")[y]
6024 local count = 0
6025 for i=1,x-1 do
6026 count = count + string.find(s,";")
6027 s = string.sub(s,string.find(s,";")+1)
6028 end
6029 s = string.sub(s,string.find(s,";")+1)
6030 getProperty(editorSElementID,"linesArray")[y] = string.sub(getProperty(editorSElementID,"linesArray")[y],1,count) ..new..";"..s
6031end
6032
6033function onPixelSelecChange()
6034 if editorSElementType == "picture" then
6035 local s = getPixelString()
6036 if string.len(s)==0 then
6037 changeProperty(pictureESColorPick1ID,"selection",nil)
6038 changeProperty(pictureESColorPick2ID,"selection",nil)
6039 changeProperty(pictureESUseDefault1ID,"active",false)
6040 changeProperty(pictureESUseDefault2ID,"active",false)
6041 changeProperty(pictureESTransparentID,"active",true)
6042 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
6043 end
6044 if string.len(s)==1 then
6045 changeProperty(pictureESColorPick1ID,"selection",nil)
6046 changeProperty(pictureESUseDefault1ID,"active",false)
6047 changeProperty(pictureESTransparentID,"active",false)
6048 changeProperty(pictureESChangeID,"variables",{["c"]=function() return " " end})
6049
6050 if s =="#" then
6051 changeProperty(pictureESUseDefault2ID,"active",true)
6052 changeProperty(pictureESColorPick2ID,"selection",nil)
6053 else
6054 changeProperty(pictureESUseDefault2ID,"active",false)
6055 changeProperty(pictureESColorPick2ID,"selection",colorsArrayStrToNum[s])
6056 end
6057 end
6058 if string.len(s)==5 then
6059 changeProperty(pictureESTransparentID,"active",false)
6060 changeProperty(pictureESChangeID,"variables",{["c"]=function() return string.sub(s,5) end})
6061
6062 if string.sub(s,3,3) =="#" then
6063 changeProperty(pictureESUseDefault2ID,"active",true)
6064 changeProperty(pictureESColorPick2ID,"selection",nil)
6065 else
6066 changeProperty(pictureESUseDefault2ID,"active",false)
6067 changeProperty(pictureESColorPick2ID,"selection",colorsArrayStrToNum[string.sub(s,3,3)])
6068 end
6069
6070 if string.sub(s,1,1) =="*" then
6071 changeProperty(pictureESUseDefault1ID,"active",true)
6072 changeProperty(pictureESColorPick1ID,"selection",nil)
6073 else
6074 changeProperty(pictureESUseDefault1ID,"active",false)
6075 changeProperty(pictureESColorPick1ID,"selection",colorsArrayStrToNum[string.sub(s,1,1)])
6076 end
6077 end
6078 end
6079end
6080
6081function prepNavMenu(array,new,first)
6082 local number
6083 if first==1 then
6084 new[1]={["text"]="<- edit"}
6085 else
6086 first = 0
6087 end
6088 for i,data in ipairs(array) do
6089 new[i+first] = {["text"]=data["text"]}
6090 if data["submenu"]~=nil then
6091 new[i+first]["submenu"] = {}
6092 prepNavMenu(data["submenu"],new[i+first]["submenu"],1)
6093 else
6094 new[i+first]["submenu"] = {[1]={["text"]="<- edit"},[2]={["text"]="+add sub"}}
6095 end
6096 number = i+first
6097 end
6098 new[number+1] = {["text"]="+add"}
6099 return new
6100end
6101
6102function copyOfSimpleArray(old,new)
6103 if new==nil then new = {} end
6104 for i,data in ipairs(old) do
6105 new[i] = data
6106 end
6107 return new
6108end
6109
6110function copyOfCSTable(old,new)
6111 if new==nil then new = {} end
6112 for i,data in ipairs(old) do
6113 new[i] = {}
6114 for x,y in pairs(old[i]) do
6115 new[i][x] = y
6116 end
6117 end
6118 return new
6119end
6120
6121function copyOfCSDesignsTable(old,new)
6122 if new==nil then new = {} end
6123 for i,data in ipairs(old) do
6124 new[i] = {}
6125 new[i]["color"] = old[i]["color"]
6126 new[i]["BGColor"] = old[i]["BGColor"]
6127 new[i]["character"] = old[i]["character"]
6128 end
6129 return new
6130end
6131
6132function copyOfNavMenu(old,new)
6133 if new==nil then new = {} end
6134 for i,data in ipairs(old) do
6135 new[i] = {["text"]=data["text"]}
6136 if data["submenu"]~=nil then
6137 new[i]["submenu"] = {}
6138 copyOfNavMenu(data["submenu"],new[i]["submenu"])
6139 end
6140 end
6141 return new
6142end
6143
6144function refreshPropsMenu()
6145 local array = {}
6146 for name,data in pairs(elementProperties[editorSElementType]) do
6147 table.insert(array,name)
6148 end
6149 changeProperty(editorSPropsMenuID,"entries",array)
6150 changeProperty(editorSDescID,"content",elementProperties[editorSElementType][(getProperty(editorSPropsMenuID,"entries")[getProperty(editorSPropsMenuID,"selectionID")])]["desc"])
6151end
6152
6153function relocateOn()
6154 changeProperty(editorSElementID,"enabled",false)
6155 changeProperty(editorSExitID,"enabled",false)
6156 changeProperty(editorSPropsID,"enabled",false)
6157 changeProperty(editorSUndoID,"enabled",false)
6158 changeProperty(editorSRedoID,"enabled",false)
6159 changeProperty(editorSHideUIID,"enabled",false)
6160 setProcessEventFunction(relocate)
6161end
6162
6163function processEditorEvents(name,var1,var2,var3)
6164 if name=="timer" then
6165 if var1==saveTimerID then
6166 saveElement(editorSElementID,editorSElementType)
6167 saveTimerID = os.startTimer(180)
6168 lastSave = os.clock()
6169 end
6170 end
6171end
6172
6173function relocate(name,var1,var2,var3)
6174 if name=="timer" then
6175 if var1==saveTimerID then
6176 saveElement(editorSElementID,editorSElementType)
6177 saveTimerID = os.startTimer(180)
6178 lastSave = os.clock()
6179 end
6180 end
6181 if name=="monitor_touch" or name=="mouse_click" or name=="mouse_drag" then
6182 changePos(editorSElementID,editorSID,var2,var3)
6183 editorSElementX = var2
6184 editorSElementY = var3
6185 refresh()
6186 end
6187end
6188
6189function relocateOff()
6190 changeProperty(editorSElementID,"enabled",true)
6191 changeProperty(editorSExitID,"enabled",true)
6192 changeProperty(editorSPropsID,"enabled",true)
6193 changeProperty(editorSUndoID,"enabled",true)
6194 changeProperty(editorSRedoID,"enabled",true)
6195 changeProperty(editorSHideUIID,"enabled",true)
6196 setProcessEventFunction(processEditorEvents)
6197end
6198
6199function addToUndoRedoTable(prop,undo,redo,var1,var2,var3,var4,var5)
6200 local n = undoRedoIndex+1
6201 while undoRedoTable[n]~=nil do
6202 undoRedoTable[n]=nil
6203 n = n + 1
6204 end
6205 table.insert(undoRedoTable,{["prop"]=prop,["undo"]=undo,["redo"]=redo,["var1"]=var1,["var2"]=var2,["var3"]=var3,["var4"]=var4,["var5"]=var5})
6206 undoRedoIndex = table.getn(undoRedoTable)
6207end
6208
6209function startDesigner(ID)
6210 setDesignerScreen(ID)
6211 designerSID = ID
6212 designerSmaxX = screens[ID]["sizeX"]
6213 designerSmaxY = screens[ID]["sizeY"]
6214 designerSSelection = ""
6215 designerRefresh = true
6216 undoRedoTable = {}
6217 undoRedoIndex = 0
6218 lastSave = os.clock()
6219 saveTimerID = os.startTimer(180)
6220 setProcessEventFunction(function(name,var1,var2,var3,var4,var5)
6221 if name=="timer" and var1==saveTimerID then
6222 lastSave = os.clock()
6223 saveScreen(designerSID)
6224 saveTimerID = os.startTimer(180)
6225 end
6226 if name=="mouse_up" then
6227 designerSButtonHeld = false
6228 changeProperty(designerSIndicatorID,"BGColor",colorPalette[3])
6229 refresh()
6230 end
6231 if name=="mouse_drag" and designerSButtonHeld then
6232 if var2<=designerSmaxX and var3 <=designerSmaxY then
6233 local currX,currY = getPos(designerSIndicatorID,designerSID)
6234 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,var2,var3)
6235 changePos(designerSIndicatorID,designerSID,var2,var3)
6236 changePos(designerSSelection,designerSID,var2,var3)
6237 refresh()
6238 end
6239 end
6240 if name=="monitor_touch" then
6241 if var2<=designerSmaxX and var3 <=designerSmaxY and getProperty(designerSIndicatorID,"active") then
6242 local currX,currY = getPos(designerSIndicatorID,designerSID)
6243 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,var2,var3)
6244 changePos(designerSIndicatorID,designerSID,var2,var3)
6245 changePos(designerSSelection,designerSID,var2,var3)
6246 refresh()
6247 end
6248 end
6249 end)
6250
6251 if designerX>designerSmaxX then
6252 addDynamicTextBox(designerSBox1ID,"")
6253 changeProperty(designerSBox1ID,"BGColor",colorPalette[2])
6254 changeProperty(designerSBox1ID,"width",designerX-designerSmaxX)
6255 changeProperty(designerSBox1ID,"height",designerSmaxY)
6256 addElementToScreen(designerSBox1ID,designerSID,designerSmaxX+1,1)
6257 end
6258 if designerY>designerSmaxY then
6259 addDynamicTextBox(designerSBox2ID,"")
6260 changeProperty(designerSBox2ID,"BGColor",colorPalette[2])
6261 changeProperty(designerSBox2ID,"width",designerX)
6262 changeProperty(designerSBox2ID,"height",designerY-designerSmaxY)
6263 addElementToScreen(designerSBox2ID,designerSID,1,designerSmaxY+1)
6264 end
6265
6266 addDynamicTextBox(designerSExitButtonID,"<Save&Exit>")
6267 changeProperty(designerSExitButtonID,"onClickMode","flash")
6268 changeProperty(designerSExitButtonID,"textColor",colorPalette[1])
6269 changeProperty(designerSExitButtonID,"BGColor",colorPalette[2])
6270 changeProperty(designerSExitButtonID,"onActiveFunction",function()
6271 removeElementFromScreen(designerSLastSaveID,designerSID)
6272 removeElementFromScreen(designerSHideUIID,designerSID)
6273 removeElementFromScreen(designerSBox1ID,designerSID)
6274 removeElementFromScreen(designerSBox2ID,designerSID)
6275 removeElementFromScreen(designerSUndoID,designerSID)
6276 removeElementFromScreen(designerSRedoID,designerSID)
6277 removeElementFromScreen(designerSExitButtonID,designerSID)
6278 removeElementFromScreen(designerSAddID,designerSID)
6279 removeElementFromScreen(designerSRemoveID,designerSID)
6280 removeElementFromScreen(designerSSelectionID,designerSID)
6281 removeElementFromScreen(designerSControlPicID,designerSID)
6282 removeElementFromScreen(designerSIndicatorID,designerSID)
6283 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6284 changeProperty(elementsSDDMenu2ID,"onChangeFunction",nil)
6285 saveScreen(designerSID)
6286 designerSID = nil
6287 designerSSelection = ""
6288 lastSave = nil
6289 setDesignerScreen(screensSID)
6290 setProcessClickEventFunction(nil)
6291 setProcessEventFunction(nil)
6292 designerRefresh = false
6293 fullRefresh()
6294 end)
6295 addElementToScreen(designerSExitButtonID,designerSID,designerX-10,designerY)
6296
6297 addDynamicTextBox(designerSLastSaveID,"Last save: $time min ago.")
6298 changeProperty(designerSLastSaveID,"variables",{["time"]=function () return math.floor((os.clock()-lastSave)/60) end})
6299 changeProperty(designerSLastSaveID,"textColor",colorPalette[1])
6300 changeProperty(designerSLastSaveID,"BGColor",colorPalette[2])
6301 addElementToScreen(designerSLastSaveID,designerSID,designerX-9,1)
6302
6303 addDynamicTextBox(designerSHideUIID,"<Hide UI>")
6304 changeProperty(designerSHideUIID,"onClickMode","flash")
6305 changeProperty(designerSHideUIID,"activeDuration",3)
6306 changeProperty(designerSHideUIID,"textColor",colorPalette[1])
6307 changeProperty(designerSHideUIID,"BGColor",colorPalette[2])
6308 changeProperty(designerSHideUIID,"onActiveFunction",function()
6309 changeProperty(designerSLastSaveID,"visible",false)
6310 changeProperty(designerSIndicatorID,"visible",false)
6311 changeProperty(designerSUndoID,"visible",false)
6312 changeProperty(designerSRedoID,"visible",false)
6313 changeProperty(designerSAddID,"visible",false)
6314 changeProperty(designerSRemoveID,"visible",false)
6315 changeProperty(designerSSelectionID,"visible",false)
6316 changeProperty(designerSExitButtonID,"visible",false)
6317 changeProperty(designerSHideUIID,"visible",false)
6318 changeProperty(designerSControlPicID,"visible",false)
6319 end)
6320 changeProperty(designerSHideUIID,"onInactiveFunction",function()
6321 changeProperty(designerSLastSaveID,"visible",true)
6322 changeProperty(designerSUndoID,"visible",true)
6323 changeProperty(designerSRedoID,"visible",true)
6324 changeProperty(designerSAddID,"visible",true)
6325 changeProperty(designerSExitButtonID,"visible",true)
6326 changeProperty(designerSHideUIID,"visible",true) end)
6327 addElementToScreen(designerSHideUIID,designerSID,designerX-8,3)
6328
6329 addDynamicTextBox(designerSUndoID,"<Undo>")
6330 changeProperty(designerSUndoID,"onClickMode","flash")
6331 changeProperty(designerSUndoID,"textColor",colorPalette[1])
6332 changeProperty(designerSUndoID,"BGColor",colorPalette[2])
6333 changeProperty(designerSUndoID,"activeTextColor",colorPalette[2])
6334 changeProperty(designerSUndoID,"activeBGColor",colorPalette[1])
6335 changeProperty(designerSUndoID,"onActiveFunction",function()
6336 if undoRedoIndex~=0 then
6337 if type(undoRedoTable[undoRedoIndex]["undo"])=="function" then
6338 pcall(undoRedoTable[undoRedoIndex]["undo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
6339 refresh()
6340 end
6341 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6342 undoRedoIndex = undoRedoIndex - 1
6343 end
6344 end)
6345 screens[designerSID]["sizeX"] = designerX
6346 screens[designerSID]["sizeY"] = designerY
6347 addElementToScreen(designerSUndoID,designerSID,relX(50,designerSID)-6,designerY)
6348 screens[designerSID]["sizeX"] = designerSmaxX
6349 screens[designerSID]["sizeY"] = designerSmaxY
6350
6351 addDynamicTextBox(designerSRedoID,"<Redo>")
6352 changeProperty(designerSRedoID,"onClickMode","flash")
6353 changeProperty(designerSRedoID,"textColor",colorPalette[1])
6354 changeProperty(designerSRedoID,"BGColor",colorPalette[2])
6355 changeProperty(designerSRedoID,"activeTextColor",colorPalette[2])
6356 changeProperty(designerSRedoID,"activeBGColor",colorPalette[1])
6357 changeProperty(designerSRedoID,"onActiveFunction",function()
6358 if undoRedoIndex~=table.getn(undoRedoTable) then
6359 undoRedoIndex = undoRedoIndex + 1
6360 if type(undoRedoTable[undoRedoIndex]["redo"])=="function" then
6361 pcall(undoRedoTable[undoRedoIndex]["redo"],undoRedoTable[undoRedoIndex]["prop"],undoRedoTable[undoRedoIndex]["var1"],undoRedoTable[undoRedoIndex]["var2"],undoRedoTable[undoRedoIndex]["var3"],undoRedoTable[undoRedoIndex]["var4"],undoRedoTable[undoRedoIndex]["var5"])
6362 refresh()
6363 end
6364 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6365 end
6366 end)
6367 screens[designerSID]["sizeX"] = designerX
6368 screens[designerSID]["sizeY"] = designerY
6369 addElementToScreen(designerSRedoID,designerSID,relX(50,designerSID)+1,designerY)
6370 screens[designerSID]["sizeX"] = designerSmaxX
6371 screens[designerSID]["sizeY"] = designerSmaxY
6372
6373 onLoadElementsS()
6374 addDynamicTextBox(designerSAddID,"<Add>")
6375 changeProperty(designerSAddID,"onClickMode","toggle")
6376 changeProperty(designerSAddID,"textColor",colorPalette[1])
6377 changeProperty(designerSAddID,"BGColor",colorPalette[2])
6378 changeProperty(designerSAddID,"activeTextColor",colorPalette[2])
6379 changeProperty(designerSAddID,"activeBGColor",colorPalette[1])
6380 changeProperty(designerSAddID,"onActiveFunction",function()
6381 addElementToScreen(elementsSDDMenu2ID,designerSID,2,2)
6382 changeProperty(elementsSDDMenu2ID,"onChangeFunction",function()
6383 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6384 addElementToScreen(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],designerSID,1,1)
6385 addToUndoRedoTable(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],removeElementFromScreen,addElementToScreen,designerSID,1,1)
6386 changeProperty(designerSAddID,"active",false)
6387 end)
6388 end)
6389 changeProperty(designerSAddID,"onInactiveFunction",function()
6390 removeElementFromScreen(elementsSDDMenu2ID,designerSID)
6391 end)
6392 addElementToScreen(designerSAddID,designerSID,1,designerY)
6393
6394 addDynamicTextBox(designerSRemoveID,"<Remove>")
6395 changeProperty(designerSRemoveID,"onClickMode","flash")
6396 changeProperty(designerSRemoveID,"textColor",colorPalette[1])
6397 changeProperty(designerSRemoveID,"BGColor",colorPalette[2])
6398 changeProperty(designerSRemoveID,"activeTextColor",colorPalette[2])
6399 changeProperty(designerSRemoveID,"activeBGColor",colorPalette[1])
6400 changeProperty(designerSRemoveID,"visible",false)
6401 changeProperty(designerSRemoveID,"onActiveFunction",function()
6402 local x,y = getPos(designerSSelection,designerSID)
6403 addToUndoRedoTable(designerSSelection,addElementToScreen,removeElementFromScreen,designerSID,x,y)
6404 removeElementFromScreen(designerSSelection,designerSID)
6405 pcall(getProperty(designerSSelectionID,"onActiveFunction"))
6406 end)
6407 addElementToScreen(designerSRemoveID,designerSID,7,designerY)
6408
6409 local b = colorsArrayNumToString[colorPalette[2]]
6410 local t = colorsArrayNumToString[colorPalette[1]]
6411 local a = colorsArrayNumToString[colorPalette[3]]
6412 addPicture(designerSControlPicID,5,3,{""..b..";"..b..";"..t..":"..b..":^;"..b..";"..b..";",""..t..":"..b..":<;"..b..";"..a..":"..b..":o;"..b..";"..t..":"..b..":>;",""..b..";"..b..";"..t..":"..b..":v;"..b..";"..b..";"})
6413 changeProperty(designerSControlPicID,"visible",false)
6414 screens[designerSID]["sizeX"] = designerX
6415 screens[designerSID]["sizeY"] = designerY
6416 addElementToScreen(designerSControlPicID,designerSID,designerX-5,relY(50,designerSID))
6417 screens[designerSID]["sizeX"] = designerSmaxX
6418 screens[designerSID]["sizeY"] = designerSmaxY
6419
6420 addDynamicTextBox(designerSIndicatorID," ")
6421 changeProperty(designerSIndicatorID,"BGColor",colorPalette[3])
6422 addElementToScreen(designerSIndicatorID,designerSID,1,1)
6423 if designerMonitor==terminalID then
6424 changeProperty(designerSIndicatorID,"onClickMode","flash")
6425 changeProperty(designerSIndicatorID,"onActiveFunction",function()
6426 designerSButtonHeld = true
6427 changeProperty(designerSIndicatorID,"BGColor",colorPalette[1])
6428 refresh()
6429 end)
6430 else
6431 changeProperty(designerSIndicatorID,"onClickMode","toggle")
6432 changeProperty(designerSIndicatorID,"activeBGColor",colorPalette[1])
6433 end
6434 changeProperty(designerSIndicatorID,"visible",false)
6435
6436 addDynamicTextBox(designerSSelectionID,"$coords: $ele ($type):$part")
6437 changeProperty(designerSSelectionID,"textColor",colorPalette[1])
6438 changeProperty(designerSSelectionID,"BGColor",colorPalette[2])
6439 changeProperty(designerSSelectionID,"height",1)
6440 changeProperty(designerSSelectionID,"variables",{["ele"]=function() return designerSSelection end,["type"]=function() return getType(designerSSelection) end,["part"]="",["coords"]=function() local x,y = getPos(designerSSelection,designerSID) return x..":"..y end})
6441 changeProperty(designerSSelectionID,"visible",false)
6442 changeProperty(designerSSelectionID,"onClickMode","flash")
6443 changeProperty(designerSSelectionID,"onActiveFunction",function()
6444 designerSSelection = ""
6445 changeProperty(designerSIndicatorID,"visible",false)
6446 changeProperty(designerSControlPicID,"visible",false)
6447 changeProperty(designerSRemoveID,"visible",false)
6448 changeProperty(designerSSelectionID,"visible",false)
6449 end)
6450 addElementToScreen(designerSSelectionID,designerSID,1,designerY-1)
6451
6452 setProcessClickEventFunction(function(type_,ID,part)
6453 if string.len(ID)<32 then
6454 designerSSelection = ID
6455 local x,y = getPos(ID,designerSID)
6456 local b = colorsArrayNumToString[colorPalette[2]]
6457 local t = colorsArrayNumToString[colorPalette[1]]
6458 local a = colorsArrayNumToString[colorPalette[3]]
6459
6460 changePos(designerSIndicatorID,designerSID,x,y)
6461 changeProperty(designerSIndicatorID,"visible",true)
6462 changeProperty(designerSControlPicID,"visible",true)
6463 changeProperty(designerSRemoveID,"visible",true)
6464 changeProperty(designerSSelectionID,"visible",true)
6465 getProperty(designerSSelectionID,"variables")["part"] = part
6466 refresh()
6467 end
6468
6469 if ID==designerSControlPicID then
6470 if part=="3:1" then
6471 local currX,currY = getPos(designerSSelection,designerSID)
6472 local newY = math.max(1,currY-1)
6473 changePos(designerSIndicatorID,designerSID,currX,newY)
6474 changePos(designerSSelection,designerSID,currX,newY)
6475 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,currX,newY)
6476 end
6477 if part=="1:2" then
6478 local currX,currY = getPos(designerSSelection,designerSID)
6479 local newX = math.max(1,currX-1)
6480 changePos(designerSIndicatorID,designerSID,newX,currY)
6481 changePos(designerSSelection,designerSID,newX,currY)
6482 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,newX,currY)
6483 end
6484 if part=="5:2" then
6485 local currX,currY = getPos(designerSSelection,designerSID)
6486 local newX = math.min(designerSmaxX,currX+1)
6487 changePos(designerSIndicatorID,designerSID,newX,currY)
6488 changePos(designerSSelection,designerSID,newX,currY)
6489 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,newX,currY)
6490 end
6491 if part=="3:3" then
6492 local currX,currY = getPos(designerSSelection,designerSID)
6493 local newY = math.min(designerSmaxY,currY+1)
6494 changePos(designerSIndicatorID,designerSID,currX,newY)
6495 changePos(designerSSelection,designerSID,currX,newY)
6496 addToUndoRedoTable(designerSSelection,function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var1,var2) changePos(designerSIndicatorID,designerSID,var1,var2) end, function(prop,var1,var2,var3,var4) changePos(prop,designerSID,var3,var4) changePos(designerSIndicatorID,designerSID,var3,var4) end,currX,currY,currX,newY)
6497 end
6498 refresh()
6499 end
6500 end)
6501
6502 fullRefresh()
6503end
6504
6505--PROGRAM START
6506if not term.isColor() then
6507 error("EasyGUI is only supported on advanced computers. It's worth spending those gold ingots, trust me.")
6508end
6509term.clear()
6510term.setCursorPos(1,1)
6511
6512if fs.exists(fs.combine(root,"EasyGUI/log.txt")) then
6513 fs.delete(fs.combine(root,"EasyGUI/log.txt"))
6514end
6515logFile = fs.open(fs.combine(root,"EasyGUI/log.txt"),"a")
6516logFile.writeLine("--------------------------------")
6517logFile.writeLine("Log level: "..writingLogLevel)
6518
6519writeToLog("Starting Program. ",2)
6520
6521if shell~=nil then
6522 writeToLog("Loaded as program.",2)
6523 print("Welcome to EasyGUI Interactive Designer!")
6524 sleep(3)
6525 setupStuff()
6526 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6527 loadMonitors()
6528 else
6529 findMonitors()
6530 saveMonitors()
6531 end
6532 if monitors~={} then
6533 transferDesigner()
6534 end
6535 if designerMonitor==terminalID then
6536 designerX,designerY = term.getSize()
6537 else
6538 monitors[designerMonitor]["peripheral"].setTextScale(tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]))
6539 designerX,designerY = monitors[designerMonitor]["peripheral"].getSize()
6540 end
6541 --main program start
6542 addScreen(mainSID,designerX,designerY,colorPalette[1],colorPalette[2])
6543 setScreenToRenderOnTerminal(nil)
6544 term.setTextColor(colorPalette[1])
6545 term.setBackgroundColor(colorPalette[2])
6546 term.clear()
6547 term.setCursorPos(1,1)
6548 term.write("EasyGUI Designer running on monitor.")
6549 setDesignerScreen(mainSID)
6550 addDynamicTextBox(mainSBorderID,"")
6551 changeProperty(mainSBorderID,"borderThickness",1)
6552 changeProperty(mainSBorderID,"borderColor",colorPalette[3])
6553 changeProperty(mainSBorderID,"width",designerX)
6554 changeProperty(mainSBorderID,"height",designerY)
6555 addElementToScreen(mainSBorderID,mainSID,1,1)
6556
6557 addDynamicTextBox(mainSHeadingID,"EasyGUI Designer Main Menu")
6558 changeProperty(mainSHeadingID,"width",designerX-2)
6559 addElementToScreen(mainSHeadingID,mainSID,2,3)
6560
6561 addDynamicTextBox(mainSButton1ID,"Screens")
6562 changeProperty(mainSButton1ID,"BGColor",colorPalette[3])
6563 changeProperty(mainSButton1ID,"textColor",colorPalette[2])
6564 changeProperty(mainSButton1ID,"borderColor",colorPalette[1])
6565 changeProperty(mainSButton1ID,"width",relX(80,mainSID))
6566 changeProperty(mainSButton1ID,"height",relY(15,mainSID))
6567 changeProperty(mainSButton1ID,"borderThickness",1)
6568 changeProperty(mainSButton1ID,"onClickMode","flash")
6569 changeProperty(mainSButton1ID,"onActiveFunction",function() setDesignerScreen(screensSID)
6570 onLoadScreensS() end)
6571 addElementToScreen(mainSButton1ID,mainSID,relX(10,mainSID),relY(25,mainSID))
6572
6573 addDynamicTextBox(mainSButton2ID,"Elements")
6574 changeProperty(mainSButton2ID,"BGColor",colorPalette[3])
6575 changeProperty(mainSButton2ID,"textColor",colorPalette[2])
6576 changeProperty(mainSButton2ID,"borderColor",colorPalette[1])
6577 changeProperty(mainSButton2ID,"width",relX(80,mainSID))
6578 changeProperty(mainSButton2ID,"height",relY(15,mainSID))
6579 changeProperty(mainSButton2ID,"borderThickness",1)
6580 changeProperty(mainSButton2ID,"onClickMode","flash")
6581 changeProperty(mainSButton2ID,"onActiveFunction",function() setDesignerScreen(elementsSID)
6582 onLoadElementsS() end)
6583 addElementToScreen(mainSButton2ID,mainSID,relX(10,mainSID),relY(50,mainSID))
6584
6585 addDynamicTextBox(mainSButton3ID,"Exit")
6586 changeProperty(mainSButton3ID,"BGColor",colorPalette[3])
6587 changeProperty(mainSButton3ID,"textColor",colorPalette[2])
6588 changeProperty(mainSButton3ID,"borderColor",colorPalette[1])
6589 changeProperty(mainSButton3ID,"width",relX(80,mainSID))
6590 changeProperty(mainSButton3ID,"height",relY(15,mainSID))
6591 changeProperty(mainSButton3ID,"borderThickness",1)
6592 changeProperty(mainSButton3ID,"onClickMode","flash")
6593 changeProperty(mainSButton3ID,"onActiveFunction",function()
6594 os.queueEvent("terminate") end)
6595 addElementToScreen(mainSButton3ID,mainSID,relX(10,mainSID),relY(75,mainSID))
6596
6597 addScreen(screensSID,designerX,designerY,colorPalette[1],colorPalette[2])
6598 addDynamicTextBox(screensSHeadingID,"EasyGUI Designer Screens Menu")
6599 changeProperty(screensSHeadingID,"width",designerX-2)
6600 addElementToScreen(mainSBorderID,screensSID,1,1)
6601 addElementToScreen(screensSHeadingID,screensSID,2,3)
6602
6603 addScreen(newScreenSID,designerX,designerY,colorPalette[1],colorPalette[2])
6604 addElementToScreen(mainSBorderID,newScreenSID,1,1)
6605 addDynamicTextBox(newScreenSHeadingID,"EasyGUI Create new screen")
6606 changeProperty(newScreenSHeadingID,"width",designerX-2)
6607 addElementToScreen(newScreenSHeadingID,newScreenSID,2,3)
6608
6609 addDynamicTextBox(newScreenSTextID,"Please choose the size of the new screen.")
6610 changeProperty(newScreenSTextID,"width",designerX-2)
6611 addElementToScreen(newScreenSTextID,newScreenSID,2,5)
6612
6613 addColorPicker(newScreenSColor1ID,nil)
6614 addColorPicker(newScreenSColor2ID,nil)
6615 changeProperty(newScreenSColor1ID,"visible",false)
6616 changeProperty(newScreenSColor2ID,"visible",false)
6617 addElementToScreen(newScreenSColor1ID,newScreenSID,3,relY(40,newScreenSID))
6618 addElementToScreen(newScreenSColor2ID,newScreenSID,designerX-5,relY(40,newScreenSID))
6619
6620 addDynamicTextBox(newScreenSResultID,"Resulting size: $size <Continue>")
6621 changeProperty(newScreenSResultID,"width",designerX-2)
6622 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end})
6623 changeProperty(newScreenSResultID,"onClickMode","flash")
6624 changeProperty(newScreenSResultID,"onActiveFunction",function()
6625 if getProperty(newScreenSColor1ID,"visible") then
6626 if getProperty(newScreenSColor1ID,"selection")~=nil and getProperty(newScreenSColor2ID,"selection")~=nil then
6627 changeProperty(newScreenSDDM1ID,"visible",true)
6628 changeProperty(newScreenSColor1ID,"visible",false)
6629 changeProperty(newScreenSColor2ID,"visible",false)
6630 changeProperty(newScreenSTextID,"content","Please choose the size of the new screen.")
6631 changeProperty(newScreenSResultID,"content","Resulting size: $size <Continue>")
6632 refresh()
6633 term.setTextColor(colorPalette[1])
6634 term.setBackgroundColor(colorPalette[2])
6635 term.clear()
6636 term.setCursorPos(1,1)
6637 print("Please enter an unique ID for the new screen:")
6638 repeat
6639 local input = read()
6640 if input~="" and input~=nil then
6641 if string.len(input)<32 then
6642 if not IDExists(input) then
6643 ID = input
6644 else
6645 print("ID already taken!")
6646 end
6647 else
6648 print("Must be less than 32 characters!")
6649 end
6650 else
6651 print("Cannot be an empty string.")
6652 end
6653 until ID~=nil
6654
6655 local bool,s = pcall(getProperty(newScreenSResultID,"variables")["size"])
6656 local x = tonumber(string.sub(s,1,string.find(s,":")-1))
6657 local y = tonumber(string.sub(s,string.find(s,":")+1))
6658 addScreen(ID,x,y,getProperty(newScreenSColor1ID,"selection"),getProperty(newScreenSColor2ID,"selection"))
6659 saveScreen(ID)
6660 startDesigner(ID)
6661 end
6662 else
6663 changeProperty(newScreenSDDM1ID,"visible",false)
6664 changeProperty(newScreenSDDM2ID,"visible",false)
6665 changeProperty(newScreenSDDM3ID,"visible",false)
6666 changeProperty(newScreenSTextID,"content","[text] choose default colors [background]")
6667 changeProperty(newScreenSResultID,"content","<Continue>")
6668 changeProperty(newScreenSColor1ID,"visible",true)
6669 changeProperty(newScreenSColor2ID,"visible",true)
6670 refresh()
6671 end
6672 end)
6673 addElementToScreen(newScreenSResultID,newScreenSID,2,designerY-2)
6674
6675 local array = {}
6676 for name,data in pairs(monitors) do
6677 table.insert(array,name)
6678 end
6679 addDropDownMenu(newScreenSDDM2ID,array,1)
6680 changeProperty(newScreenSDDM2ID,"borderThickness",1)
6681 changeProperty(newScreenSDDM2ID,"borderColor",colorPalette[3])
6682 changeProperty(newScreenSDDM2ID,"highlightTextColor",colorPalette[2])
6683 changeProperty(newScreenSDDM2ID,"highlightBGColor",colorPalette[1])
6684 changeProperty(newScreenSDDM2ID,"visible",false)
6685 addElementToScreen(newScreenSDDM2ID,newScreenSID,relX(15,newScreenSID),relY(65,newScreenSID))
6686
6687 addDropDownMenu(newScreenSDDM3ID,{"0.5","1","1.5","2"},1)
6688 changeProperty(newScreenSDDM3ID,"borderThickness",1)
6689 changeProperty(newScreenSDDM3ID,"borderColor",colorPalette[3])
6690 changeProperty(newScreenSDDM3ID,"highlightTextColor",colorPalette[2])
6691 changeProperty(newScreenSDDM3ID,"highlightBGColor",colorPalette[1])
6692 changeProperty(newScreenSDDM3ID,"visible",false)
6693 addElementToScreen(newScreenSDDM3ID,newScreenSID,relX(60,newScreenSID),relY(65,newScreenSID))
6694
6695 addDropDownMenu(newScreenSDDM1ID,{"computer (51:19)","turtle (39:13)","pocket com (26:20)","monitor (variable)","custom"},1)
6696 changeProperty(newScreenSDDM1ID,"borderThickness",1)
6697 changeProperty(newScreenSDDM1ID,"borderColor",colorPalette[3])
6698 changeProperty(newScreenSDDM1ID,"highlightTextColor",colorPalette[2])
6699 changeProperty(newScreenSDDM1ID,"highlightBGColor",colorPalette[1])
6700 changeProperty(newScreenSDDM1ID,"onChangeFunction",function(ID,selec)
6701 if selec==4 then
6702 changeProperty(newScreenSDDM2ID,"visible",true)
6703 changeProperty(newScreenSDDM3ID,"visible",true)
6704 changeProperty(newScreenSResultID,"variables",{["size"]=function() monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].setTextScale(tonumber(getProperty(newScreenSDDM3ID,"entries")[getProperty(newScreenSDDM3ID,"selectionID")]))
6705 local a,b = monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].getSize()
6706 return a..":"..b end})
6707 refresh()
6708 else
6709 if selec==1 then
6710 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end })
6711 end
6712 if selec==2 then
6713 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "39:13" end })
6714 end
6715 if selec==3 then
6716 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "26:20" end })
6717 end
6718 if selec==5 then
6719 term.setBackgroundColor(colorPalette[2])
6720 term.setTextColor(colorPalette[1])
6721 term.clear()
6722 term.setCursorPos(1,1)
6723 print("Enter size X for new screen:")
6724 local a = read()
6725 print("Enter size Y for new screen:")
6726 local b = read()
6727 changeProperty(newScreenSResultID,"variables",{["size"]=function() return a..":"..b end })
6728 fullRefresh()
6729 end
6730 changeProperty(newScreenSDDM2ID,"visible",false)
6731 changeProperty(newScreenSDDM3ID,"visible",false)
6732 end
6733 end)
6734 addElementToScreen(newScreenSDDM1ID,newScreenSID,relX(15,newScreenSID),relY(35,newScreenSID))
6735
6736 addDynamicTextBox(screensSMsgID,"Please check term!")
6737 changeProperty(screensSMsgID,"width",relX(80,screensSID))
6738 changeProperty(screensSMsgID,"height",relY(15,screensSID))
6739 changeProperty(screensSMsgID,"borderThickness",1)
6740 changeProperty(screensSMsgID,"visible",false)
6741 addElementToScreen(screensSMsgID,screensSID,relX(10,screensSID),relY(25,screensSID))
6742
6743 addDynamicTextBox(screensSButton1ID,"New Screen")
6744 changeProperty(screensSButton1ID,"BGColor",colorPalette[3])
6745 changeProperty(screensSButton1ID,"textColor",colorPalette[2])
6746 changeProperty(screensSButton1ID,"borderColor",colorPalette[1])
6747 changeProperty(screensSButton1ID,"width",relX(80,screensSID))
6748 changeProperty(screensSButton1ID,"height",relY(15,screensSID))
6749 changeProperty(screensSButton1ID,"borderThickness",1)
6750 changeProperty(screensSButton1ID,"onClickMode","flash")
6751 changeProperty(screensSButton1ID,"onActiveFunction",function()
6752 setDesignerScreen(newScreenSID)
6753 fullRefresh()
6754 end)
6755 addElementToScreen(screensSButton1ID,screensSID,relX(10,screensSID),relY(25,screensSID))
6756
6757 addDynamicTextBox(screensSButton2ID,"Edit")
6758 changeProperty(screensSButton2ID,"BGColor",colorPalette[3])
6759 changeProperty(screensSButton2ID,"textColor",colorPalette[2])
6760 changeProperty(screensSButton2ID,"borderColor",colorPalette[1])
6761 changeProperty(screensSButton2ID,"width",relX(40,screensSID)-1)
6762 changeProperty(screensSButton2ID,"height",relY(15,screensSID))
6763 changeProperty(screensSButton2ID,"borderThickness",1)
6764 changeProperty(screensSButton2ID,"onClickMode","flash")
6765 changeProperty(screensSButton2ID,"onActiveFunction",function() startDesigner(getProperty(screensSDDMenuID,"entries")[getProperty(screensSDDMenuID,"selectionID")]) end)
6766 addElementToScreen(screensSButton2ID,screensSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,screensSID))
6767
6768 addDynamicTextBox(screensSButton3ID,"Back")
6769 changeProperty(screensSButton3ID,"BGColor",colorPalette[3])
6770 changeProperty(screensSButton3ID,"textColor",colorPalette[2])
6771 changeProperty(screensSButton3ID,"borderColor",colorPalette[1])
6772 changeProperty(screensSButton3ID,"width",relX(80,screensSID))
6773 changeProperty(screensSButton3ID,"height",relY(15,screensSID))
6774 changeProperty(screensSButton3ID,"borderThickness",1)
6775 changeProperty(screensSButton3ID,"onClickMode","flash")
6776 changeProperty(screensSButton3ID,"onActiveFunction",function() setDesignerScreen(mainSID) end)
6777 addElementToScreen(screensSButton3ID,screensSID,relX(10,screensSID),relY(75,screensSID))
6778
6779 addDropDownMenu(screensSDDMenuID,nil,1)
6780 changeProperty(screensSDDMenuID,"borderThickness",1)
6781 changeProperty(screensSDDMenuID,"borderColor",colorPalette[3])
6782 changeProperty(screensSDDMenuID,"highlightTextColor",colorPalette[2])
6783 changeProperty(screensSDDMenuID,"highlightBGColor",colorPalette[1])
6784 changeProperty(screensSDDMenuID,"width",relX(40,screensSID)-1)
6785 addElementToScreen(screensSDDMenuID,screensSID,relX(10,screensSID),relY(50,screensSID))
6786
6787 addScreen(elementsSID,designerX,designerY,colorPalette[1],colorPalette[2])
6788 addDynamicTextBox(elementsSHeadingID,"EasyGUI Designer Elements Menu")
6789 changeProperty(elementsSHeadingID,"width",designerX-2)
6790 addElementToScreen(mainSBorderID,elementsSID,1,1)
6791 addElementToScreen(elementsSHeadingID,elementsSID,2,3)
6792 addElementToScreen(screensSButton3ID,elementsSID,relX(10,screensSID),relY(75,screensSID))
6793
6794 addElementToScreen(screensSMsgID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6795
6796 local array = {"dynTextBox","slider","dropDownMenu","navMenu","colorPicker","progressBar","coordsSystem","picture"}
6797
6798 addDynamicTextBox(elementsSButton1ID,"Add")
6799 changeProperty(elementsSButton1ID,"BGColor",colorPalette[3])
6800 changeProperty(elementsSButton1ID,"textColor",colorPalette[2])
6801 changeProperty(elementsSButton1ID,"borderColor",colorPalette[1])
6802 changeProperty(elementsSButton1ID,"width",relX(40,elementsSID)-1)
6803 changeProperty(elementsSButton1ID,"height",relY(15,elementsSID))
6804 changeProperty(elementsSButton1ID,"borderThickness",1)
6805 changeProperty(elementsSButton1ID,"onClickMode","flash")
6806 changeProperty(elementsSButton1ID,"onActiveFunction",function() startEditor(newElement(array[getProperty(elementsSDDMenu1ID,"selectionID")])) end)
6807 addElementToScreen(elementsSButton1ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(25,elementsSID))
6808
6809 addDynamicTextBox(elementsSButton2ID,"Edit")
6810 changeProperty(elementsSButton2ID,"BGColor",colorPalette[3])
6811 changeProperty(elementsSButton2ID,"textColor",colorPalette[2])
6812 changeProperty(elementsSButton2ID,"borderColor",colorPalette[1])
6813 changeProperty(elementsSButton2ID,"width",relX(40,elementsSID)-1)
6814 changeProperty(elementsSButton2ID,"height",relY(15,elementsSID))
6815 changeProperty(elementsSButton2ID,"borderThickness",1)
6816 changeProperty(elementsSButton2ID,"onClickMode","flash")
6817 changeProperty(elementsSButton2ID,"onActiveFunction",function() startEditor(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],getType(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")])) end)
6818 addElementToScreen(elementsSButton2ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,elementsSID))
6819
6820 addDropDownMenu(elementsSDDMenu2ID,nil,1)
6821 changeProperty(elementsSDDMenu2ID,"borderThickness",1)
6822 changeProperty(elementsSDDMenu2ID,"borderColor",colorPalette[3])
6823 changeProperty(elementsSDDMenu2ID,"highlightTextColor",colorPalette[2])
6824 changeProperty(elementsSDDMenu2ID,"highlightBGColor",colorPalette[1])
6825 changeProperty(elementsSDDMenu2ID,"width",relX(40,elementsSID)-1)
6826 addElementToScreen(elementsSDDMenu2ID,elementsSID,relX(10,elementsSID),relY(50,elementsSID))
6827
6828 addDropDownMenu(elementsSDDMenu1ID,array,1)
6829 changeProperty(elementsSDDMenu1ID,"borderThickness",1)
6830 changeProperty(elementsSDDMenu1ID,"borderColor",colorPalette[3])
6831 changeProperty(elementsSDDMenu1ID,"highlightTextColor",colorPalette[2])
6832 changeProperty(elementsSDDMenu1ID,"highlightBGColor",colorPalette[1])
6833 changeProperty(elementsSDDMenu1ID,"width",relX(40,elementsSID)-1)
6834 addElementToScreen(elementsSDDMenu1ID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6835
6836 run(nil)
6837else
6838 writeToLog("Loaded as API.",2)
6839 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6840 loadMonitors()
6841 else
6842 print("EasyGUI was loaded as API, but there is no monitor file present. Starting monitor initialization sequence.")
6843 sleep(5)
6844 setupStuff()
6845 findMonitors()
6846 saveMonitors()
6847 end
6848end
6849
6850--END OF EASYGUI API
6851-----------------------------