· 4 years ago · Jan 16, 2021, 01:42 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--16/01/2020: Release 1.0 pastebin:
49--fixed #1,#2 and #3
50--cleaned up adding a new screen while running designer on monitor
51--everything else appears very stable up to this point
52
53--25/12/2020: Release Beta v.0.1 pastebin: LGVzZLwK
54-- All features that were planned at this point have now been implemented.
55-- It took roughly half a year. An intensive testing phase is about to begin.
56-------
57
58-- Bugs
59--#1 designer not usable on turtle and pocket screen / fixed 16/01/2021
60--#2 wireless modems throw errors during monitor initialization sequence / fixed 16/01/2021
61--#3 when using only terminal and no monitors, will always try to find new monitors / fixed 16/01/2021
62--#4 all functions are globally accessible 16/01/2021 unfixable
63
64----------------------------------
65--Technical stuff starting. Enjoy.
66refreshTimerID = nil
67refreshRate = nil
68
69IDlist = {}
70startTime = os.clock()
71logFile = nil
72lastLogString = nil
73
74refreshFunction = nil
75processClickEventFunc = nil
76processEventFunc = nil
77
78args = {...}
79
80--color arrays
81colorsArrayStrToNum = {}
82colorsArrayStrToNum["0"] = colors.white
83colorsArrayStrToNum["1"] = colors.orange
84colorsArrayStrToNum["2"] = colors.magenta
85colorsArrayStrToNum["3"] = colors.lightBlue
86colorsArrayStrToNum["4"] = colors.yellow
87colorsArrayStrToNum["5"] = colors.lime
88colorsArrayStrToNum["6"] = colors.pink
89colorsArrayStrToNum["7"] = colors.gray
90colorsArrayStrToNum["8"] = colors.lightGray
91colorsArrayStrToNum["9"] = colors.cyan
92colorsArrayStrToNum["a"] = colors.purple
93colorsArrayStrToNum["b"] = colors.blue
94colorsArrayStrToNum["c"] = colors.brown
95colorsArrayStrToNum["d"] = colors.green
96colorsArrayStrToNum["e"] = colors.red
97colorsArrayStrToNum["f"] = colors.black
98
99colorsArrayNumToNum = {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}
100
101colorsArrayNumToString = {}
102colorsArrayNumToString[colors.white] = "0"
103colorsArrayNumToString[colors.orange] = "1"
104colorsArrayNumToString[colors.magenta] = "2"
105colorsArrayNumToString[colors.lightBlue] = "3"
106colorsArrayNumToString[colors.yellow] = "4"
107colorsArrayNumToString[colors.lime] = "5"
108colorsArrayNumToString[colors.pink] = "6"
109colorsArrayNumToString[colors.gray] = "7"
110colorsArrayNumToString[colors.lightGray] = "8"
111colorsArrayNumToString[colors.cyan] = "9"
112colorsArrayNumToString[colors.purple] = "a"
113colorsArrayNumToString[colors.blue] = "b"
114colorsArrayNumToString[colors.brown] = "c"
115colorsArrayNumToString[colors.green] = "d"
116colorsArrayNumToString[colors.red] = "e"
117colorsArrayNumToString[colors.black] = "f"
118
119--designer stuff
120designerMonitor = nil
121designerScreen = nil
122designerX = nil
123designerY = nil
124lastSave = nil
125saveTimerID = nil
126selectedPart = ""
127
128--hashes (md5)
129terminalID = "a8bcae0d70fdbf14c572156f8e31000a"
130
131initMonsSID = "cdac1a98818689af48db3b552851fc6f"
132initMonsSHeadingID = "890f2028b00a4579df6b48ad34d8a269"
133initMonsSLeftRectID = "ea24a45da7a8fbef8b236748907aa7fb"
134initMonsSTextID = "4900d0b145e8533b398b5e12dd7525e5"
135initMonsSPictureID = "694b8cec4ab3a26d01c68005ec8aa56c"
136initMonsSErrorID = "fb95b84d5b14a09ab93511fc6fb575f4"
137
138changeMonSID = "c737dc7d97748d8b40963a95a0dc7861"
139changeMonSDDMenuID = "d73a60583fc13ea25db201571bca7301"
140changeMonSApplyID = "c1eac4028ea88abba1e9fa2b5894a5ac"
141changeMonSScaleDDID = "0f76acbc91744387905e22aa7420e892"
142
143mainSID = "174e80d8ed22ac2287bf056b4e7c2c0a"
144mainSBorderID = "42adbd6df1cf676ed2cbf9040ff73d69"
145mainSButton1ID = "9d8692e9a7d29f1cea8ff0728b27ec15"
146mainSButton2ID = "9ce00dc655e34d3e4ade16daa7267a12"
147mainSButton3ID = "a79fa19cb268b702bcbcaccbbb7ce8d3"
148mainSHeadingID = "0ede5fa492669473d6f765e957967296"
149
150screensSID = "c00d2f1c0bc784e4d9bd67f800a0e702"
151screensSHeadingID = "04f609cb0bf336e33b5ac887858f8a81"
152screensSButton1ID = "aaa4cb31682f6968660ef882899b16b2"
153screensSButton2ID = "b10a959313edf31aa004faffcf905256"
154screensSButton3ID = "f2ca3bcbb6f6febcb3d73236ff285fb5"
155screensSDDMenuID = "a2f436771da5644c27a39d73b57fd29c"
156screensSMsgID = "b823cc4d92c1748967586c2878967248"
157
158elementsSID = "0ce4a8f25a81d19b9abf7cfcbd450a4d"
159elementsSHeadingID = "f34a17e23d41cffa1b9fbd6a33cd4f71"
160elementsSButton1ID = "c8a2c4a1a569bc97d659707bc42539fe"
161elementsSButton2ID = "650a9aef06bb8e99389773a9fd6ec2cd"
162elementsSDDMenu1ID = "bc9fc4bada884c28114d4bfb1783b8c7"
163elementsSDDMenu2ID = "030bbbca3d6cf0847f87feda6bf6a783"
164
165editorSID = "ba0832bc2dcb0adcf14b490ac6be2065"
166editorSElementID = nil
167editorSElementType = nil
168editorSElementX = nil
169editorSElementY = nil
170editorSRelocateButtonID = "ca5d5014d000faa233f4c58909e9ea21"
171editorSLastSaveID = "70461177a186553350dbb333d5b2cde2"
172editorSExitID = "99f1eb11c00f5c188844a7311c879bac"
173editorSUndoID = "0f7132a19e8760f425c2eef5b386cc61"
174editorSRedoID = "fe21a08c7dffa4717d24593f7fcd0a0e"
175editorSPropsID = "e46d61c144903147e4cb5f136a0fecb8"
176editorSPropsMenuID = "cbf856355edab7b830d36dec09857e0d"
177editorSDescID = "06431f84d6b74e6796e52341a882e9a5"
178editorSHideUIID = "ad4e5a2c6c8b4995893cec8cd4e2f219"
179editorSPropColorPickID = "25c276460958a39672b08d75baf86b4d"
180editorSPropResetButtonID = "6c04474a36beb72d7659bb0be1a07753"
181editorSPropDDMenuID = "0603d9ac23d75d560d24cf76b2321882"
182editorSPropDisplayID = "43c8ab35bc70361a89080b0e6c8d0dcc"
183editorSPropConsoleInputButtonID = "48066d14f326e44bc285eacea5953c53"
184editorSPropConsoleMsgID = "253177a56e1e679a671650ff660ac628"
185editorSPropColorsArrayDDID = "f786c674209bc58c63be21a9973a36a7"
186editorSPropStringArrayDDID = "873ab20d4a621beb75c4a288aafc4d9b"
187editorSPropNavMenuID = "1a8bf4cb11854ddc7070fa988b6bd061"
188editorSPropNavMenuHintID = "5e192f2543b2955606ea876e5a0f5061"
189editorSPropCSTableIndexDDID = "c0db47af6a31df0c8b5d6d93528e8789"
190editorSPropCSTableDDID = "285065eb94ad1d28cc4256b2ba90313e"
191editorSPropCSChangeID = "69280395cc41074df3a851bd35dae7eb"
192editorSPropCSRemoveID = "947a332a5fd6e2f12cdee783584d7b2f"
193editorSPropCSDesignsIndexDDID = "6cc418ef452522709716091a3fee13b4"
194editorSPropCSDesignsDDID = "dcf4b18661fa3189e028cc5b9e3bb091"
195editorSPropCSDesignsDisplayID = "a911bd54fc2a722273349b86b7ba7e5b"
196editorSPropPicEditButtonID = "d4baa6b9a4165cd060adf01ac06413c1"
197
198pictureESID = "8c62478c73d841127d5cfee2ca0057f5"
199pictureESCurrentX = 1
200pictureESCurrentY = 1
201pictureESButtonBackID = "2b0706da3b5d426fa94dc2f8296b3163"
202pictureESCoordsDisplayID = "badf495b60b2dfbf16a6505fc5a6abea"
203pictureESControlPicID = "8e30ae73df15a61c5031fbb303d0aacb"
204pictureESIndicatorID = "eedc3c41696a69f23da0afaa26966886"
205pictureESChangeID = "6fa7bc313ff09ed5ffe3a03eabd9f023"
206pictureESColorPick1ID = "b35a1604be58560bed010a10814b9e96"
207pictureESColorPick2ID = "f21f6272bc5b1fde77e1fae2b81a8cd2"
208pictureESUseDefault1ID = "544eede5770aab86e04abe55a69df30e"
209pictureESUseDefault2ID = "6ecb339249a0d6fc15345a3a9678d801"
210pictureESTransparentID = "2273d20c36018b7d17dc3c2986581939"
211
212newScreenSID = "4c87e69acef20548469e1739e668a0b2"
213newScreenSHeadingID = "d3b18e12b96639b9185abb60ba990ddb"
214newScreenSTextID = "8413e43f729eccce6ae5ec696b90dbda"
215newScreenSDDM1ID = "5febc01add087220c728a65579e148f3"
216newScreenSDDM2ID = "e5cc2beacfc426487c711c85deb2015d"
217newScreenSDDM3ID = "1f2fae049f3e7a22afd512769a7b171d"
218newScreenSResultID = "bbdc5855b127608208219ecc1a275978"
219newScreenSColor1ID = "d43e48d259cd4baa3c209f590f912cbf"
220newScreenSColor2ID = "0acbe4f69fa595fd123d03ad834cc50d"
221
222designerSID = nil
223designerSExitButtonID = "1d3b801e5d4f2c7226492cf2a66f9ebd"
224designerSHideUIID = "9818d56316ad57a0567c4076c26ae597"
225designerSControlPicID = "71e90f74303d96e10277d15591add23e"
226designerSSelectionID = "31cf20d5dd112d373b987ca97d7bec60"
227designerSAddID = "ebd3455e1d4cb26e3880b7ef5963ef55"
228designerSRemoveID = "2a2abf50f7ca26032ee56471ead9ed46"
229designerSIndicatorID = "61a218bc9eadf687b5218d580c99d1c7"
230designerSLastSaveID = "5d7d14cce74cf0f0506a47557b2c49b7"
231designerSSelection = ""
232designerSmaxX = nil
233designerSmaxY = nil
234designerSBox1ID = "d0dca4a2df75fbc538d26bf55f838068"
235designerSBox2ID = "dd5bd01b51b9dae60c4908954a25da05"
236designerSUndoID = "b690378913463294bc11c499bf032798"
237designerSRedoID = "25d97fd89146fa2a0378577fea852434"
238designerRefresh = false
239designerSButtonHeld = false
240
241undoRedoTable = {}
242undoRedoIndex = 0
243
244--property tables
245--width, height, content, variables, textColor, textAlignmentHorizontal, textAlignmentVertical, BGColor, borderColor, onActiveFunction, onInactiveFunction, onClickMode, activeDuration, activeContent, activeTextColor, activeBGColor, activeBorderColor, borderThickness, active, timerID, visible, enabled
246dynamicTextBoxProperties = {}
247dynamicTextBoxProperties["content"] = {}
248dynamicTextBoxProperties["content"]["input"] = "string"
249dynamicTextBoxProperties["content"]["essential"] = true
250dynamicTextBoxProperties["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."
251dynamicTextBoxProperties["content"]["default"] = "Your Text"
252
253dynamicTextBoxProperties["width"] = {}
254dynamicTextBoxProperties["width"]["input"] = "number"
255dynamicTextBoxProperties["width"]["essential"] = false
256dynamicTextBoxProperties["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."
257
258dynamicTextBoxProperties["height"] = {}
259dynamicTextBoxProperties["height"]["input"] = "number"
260dynamicTextBoxProperties["height"]["essential"] = false
261dynamicTextBoxProperties["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."
262
263dynamicTextBoxProperties["variables"] = {}
264dynamicTextBoxProperties["variables"]["input"] = "manual"
265dynamicTextBoxProperties["variables"]["essential"] = false
266dynamicTextBoxProperties["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))"
267
268dynamicTextBoxProperties["textColor"] = {}
269dynamicTextBoxProperties["textColor"]["input"] = "color"
270dynamicTextBoxProperties["textColor"]["essential"] = false
271dynamicTextBoxProperties["textColor"]["desc"] = "textColor (color): color of the text inside the dynamicTextBox. If unused (nil) defaultTextColor of the screen will be used."
272
273dynamicTextBoxProperties["BGColor"] = {}
274dynamicTextBoxProperties["BGColor"]["input"] = "color"
275dynamicTextBoxProperties["BGColor"]["essential"] = false
276dynamicTextBoxProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dynamicTextBox. If unused (nil) defaultBGColor of the screen will be used."
277
278dynamicTextBoxProperties["borderColor"] = {}
279dynamicTextBoxProperties["borderColor"]["input"] = "color"
280dynamicTextBoxProperties["borderColor"]["essential"] = false
281dynamicTextBoxProperties["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."
282
283dynamicTextBoxProperties["activeContent"] = {}
284dynamicTextBoxProperties["activeContent"]["input"] = "string"
285dynamicTextBoxProperties["activeContent"]["essential"] = false
286dynamicTextBoxProperties["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."
287
288dynamicTextBoxProperties["activeTextColor"] = {}
289dynamicTextBoxProperties["activeTextColor"]["input"] = "color"
290dynamicTextBoxProperties["activeTextColor"]["essential"] = false
291dynamicTextBoxProperties["activeTextColor"]["desc"] = "activeTextColor (color): color of the text inside the dynamicTextBox if it's active. If unused (nil) textColor will be used."
292
293dynamicTextBoxProperties["activeBGColor"] = {}
294dynamicTextBoxProperties["activeBGColor"]["input"] = "color"
295dynamicTextBoxProperties["activeBGColor"]["essential"] = false
296dynamicTextBoxProperties["activeBGColor"]["desc"] = "activeBGColor (color): color of background of the dynamicTextBox if it's active. If unused (nil) BGColor will be used."
297
298dynamicTextBoxProperties["activeBorderColor"] = {}
299dynamicTextBoxProperties["activeBorderColor"]["input"] = "color"
300dynamicTextBoxProperties["activeBorderColor"]["essential"] = false
301dynamicTextBoxProperties["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."
302
303dynamicTextBoxProperties["textAlignmentHorizontal"] = {}
304dynamicTextBoxProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
305dynamicTextBoxProperties["textAlignmentHorizontal"]["essential"] = false
306dynamicTextBoxProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside the dynamicTextBox shall be placed horizontally. If unused (nil) defaults to center."
307
308dynamicTextBoxProperties["textAlignmentVertical"] = {}
309dynamicTextBoxProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
310dynamicTextBoxProperties["textAlignmentVertical"]["essential"] = false
311dynamicTextBoxProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside the dynamicTextBox shall be placed vertically. If unused (nil) defaults to center."
312
313dynamicTextBoxProperties["borderThickness"] = {}
314dynamicTextBoxProperties["borderThickness"]["input"] = "number"
315dynamicTextBoxProperties["borderThickness"]["essential"] = false
316dynamicTextBoxProperties["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)"
317
318dynamicTextBoxProperties["onClickMode"] = {}
319dynamicTextBoxProperties["onClickMode"]["input"] = "DDM:flash:toggle"
320dynamicTextBoxProperties["onClickMode"]["essential"] = false
321dynamicTextBoxProperties["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."
322
323dynamicTextBoxProperties["activeDuration"] = {}
324dynamicTextBoxProperties["activeDuration"]["input"] = "decimal"
325dynamicTextBoxProperties["activeDuration"]["essential"] = false
326dynamicTextBoxProperties["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."
327
328dynamicTextBoxProperties["onActiveFunction"] = {}
329dynamicTextBoxProperties["onActiveFunction"]["input"] = "manual"
330dynamicTextBoxProperties["onActiveFunction"]["essential"] = false
331dynamicTextBoxProperties["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)"
332
333dynamicTextBoxProperties["onInactiveFunction"] = {}
334dynamicTextBoxProperties["onInactiveFunction"]["input"] = "manual"
335dynamicTextBoxProperties["onInactiveFunction"]["essential"] = false
336dynamicTextBoxProperties["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)"
337
338--length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
339sliderProperties = {}
340sliderProperties["length"] = {}
341sliderProperties["length"]["input"] = "number"
342sliderProperties["length"]["essential"] = true
343sliderProperties["length"]["desc"] = "length (number): the maximum value the slider shall take on. Not necessarily the length in pixels, for more info see pixelsPerUnit."
344sliderProperties["length"]["default"] = 5
345
346sliderProperties["value"] = {}
347sliderProperties["value"]["input"] = "number"
348sliderProperties["value"]["essential"] = true
349sliderProperties["value"]["desc"] = "value (number): the default value the slider shall take on."
350sliderProperties["value"]["default"] = 1
351
352sliderProperties["broadness"] = {}
353sliderProperties["broadness"]["input"] = "number"
354sliderProperties["broadness"]["essential"] = false
355sliderProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the slider shall be. Perpendicular to slider orientation. If unused (nil) will be 1."
356
357sliderProperties["pixelsPerUnit"] = {}
358sliderProperties["pixelsPerUnit"]["input"] = "number"
359sliderProperties["pixelsPerUnit"]["essential"] = false
360sliderProperties["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."
361
362sliderProperties["orientation"] = {}
363sliderProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
364sliderProperties["orientation"]["essential"] = false
365sliderProperties["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."
366
367sliderProperties["color"] = {}
368sliderProperties["color"]["input"] = "color"
369sliderProperties["color"]["essential"] = false
370sliderProperties["color"]["desc"] = "color (color): the color the bar of the slider shall take on. If unused (nil) will be the defaultTextColor of the screen."
371
372sliderProperties["BGColor"] = {}
373sliderProperties["BGColor"]["input"] = "color"
374sliderProperties["BGColor"]["essential"] = false
375sliderProperties["BGColor"]["desc"] = "BGColor (color): the background of the slider. If unused (nil) will be the defaultBGColor of the screen."
376
377sliderProperties["borderColor"] = {}
378sliderProperties["borderColor"]["input"] = "color"
379sliderProperties["borderColor"]["essential"] = false
380sliderProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the slider. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
381
382sliderProperties["borderThickness"] = {}
383sliderProperties["borderThickness"]["input"] = "number"
384sliderProperties["borderThickness"]["essential"] = false
385sliderProperties["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)"
386
387sliderProperties["colorsArray"] = {}
388sliderProperties["colorsArray"]["input"] = "colorsArray"
389sliderProperties["colorsArray"]["essential"] = false
390sliderProperties["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."
391
392sliderProperties["mode"] = {}
393sliderProperties["mode"]["input"] = "DDM:fill:value"
394sliderProperties["mode"]["essential"] = false
395sliderProperties["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."
396
397sliderProperties["textPosition"] = {}
398sliderProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
399sliderProperties["textPosition"]["essential"] = false
400sliderProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
401
402sliderProperties["textMargin"] = {}
403sliderProperties["textMargin"]["input"] = "number"
404sliderProperties["textMargin"]["essential"] = false
405sliderProperties["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."
406
407sliderProperties["changeButtons"] = {}
408sliderProperties["changeButtons"]["input"] = "string"
409sliderProperties["changeButtons"]["essential"] = false
410sliderProperties["changeButtons"]["desc"] = "changeButtons (2 characters): if set draws an increment button with the first character and a decrement button with the second character. Example: '+-'"
411
412sliderProperties["onChangeFunction"] = {}
413sliderProperties["onChangeFunction"]["input"] = "manual"
414sliderProperties["onChangeFunction"]["essential"] = false
415sliderProperties["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)"
416
417--entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
418dropDownMenuProperties = {}
419dropDownMenuProperties["entries"] = {}
420dropDownMenuProperties["entries"]["input"] = "stringArray"
421dropDownMenuProperties["entries"]["essential"] = true
422dropDownMenuProperties["entries"]["desc"] = "entries (numerically indexed table): all entries of the dropDownMenu."
423dropDownMenuProperties["entries"]["default"] = {"Entry 1","Entry 2","Entry 3"}
424
425dropDownMenuProperties["selectionID"] = {}
426dropDownMenuProperties["selectionID"]["input"] = "number"
427dropDownMenuProperties["selectionID"]["essential"] = true
428dropDownMenuProperties["selectionID"]["desc"] = "selectionID (non-decimal number): by default selected entry of dropDownMenu."
429dropDownMenuProperties["selectionID"]["default"] = 1
430
431dropDownMenuProperties["width"] = {}
432dropDownMenuProperties["width"]["input"] = "number"
433dropDownMenuProperties["width"]["essential"] = false
434dropDownMenuProperties["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."
435
436dropDownMenuProperties["expandedMaxHeight"] = {}
437dropDownMenuProperties["expandedMaxHeight"]["input"] = "number"
438dropDownMenuProperties["expandedMaxHeight"]["essential"] = false
439dropDownMenuProperties["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."
440
441dropDownMenuProperties["textColor"] = {}
442dropDownMenuProperties["textColor"]["input"] = "color"
443dropDownMenuProperties["textColor"]["essential"] = false
444dropDownMenuProperties["textColor"]["desc"] = "textColor (color): color of the text of the entries. If unused (nil) defaultTextColor of the screen will be used."
445
446dropDownMenuProperties["BGColor"] = {}
447dropDownMenuProperties["BGColor"]["input"] = "color"
448dropDownMenuProperties["BGColor"]["essential"] = false
449dropDownMenuProperties["BGColor"]["desc"] = "BGColor (color): color of background of the dropDownMenu. If unused (nil) defaultBGColor of the screen will be used."
450
451dropDownMenuProperties["borderColor"] = {}
452dropDownMenuProperties["borderColor"]["input"] = "color"
453dropDownMenuProperties["borderColor"]["essential"] = false
454dropDownMenuProperties["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."
455
456dropDownMenuProperties["highlightTextColor"] = {}
457dropDownMenuProperties["highlightTextColor"]["input"] = "color"
458dropDownMenuProperties["highlightTextColor"]["essential"] = false
459dropDownMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of the highlighted entry. If unused (nil) textColor will be used."
460
461dropDownMenuProperties["highlightBGColor"] = {}
462dropDownMenuProperties["highlightBGColor"]["input"] = "color"
463dropDownMenuProperties["highlightBGColor"]["essential"] = false
464dropDownMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of background of the highlighted entry. If unused (nil) BGColor will be used."
465
466dropDownMenuProperties["buttonsColor"] = {}
467dropDownMenuProperties["buttonsColor"]["input"] = "color"
468dropDownMenuProperties["buttonsColor"]["essential"] = false
469dropDownMenuProperties["buttonsColor"]["desc"] = "buttonsColor (color): textColor of expand/collapse/scroll buttons. If unused (nil) textColor will be used."
470
471dropDownMenuProperties["buttonsBGColor"] = {}
472dropDownMenuProperties["buttonsBGColor"]["input"] = "color"
473dropDownMenuProperties["buttonsBGColor"]["essential"] = false
474dropDownMenuProperties["buttonsBGColor"]["desc"] = "buttonsBGColor (color): BGColor of expand/collapse/scroll buttons. If unused (nil) BGColor will be used."
475
476dropDownMenuProperties["borderThickness"] = {}
477dropDownMenuProperties["borderThickness"]["input"] = "number"
478dropDownMenuProperties["borderThickness"]["essential"] = false
479dropDownMenuProperties["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)"
480
481dropDownMenuProperties["onChangeFunction"] = {}
482dropDownMenuProperties["onChangeFunction"]["input"] = "manual"
483dropDownMenuProperties["onChangeFunction"]["essential"] = false
484dropDownMenuProperties["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)"
485
486dropDownMenuProperties["onExpandFunction"] = {}
487dropDownMenuProperties["onExpandFunction"]["input"] = "manual"
488dropDownMenuProperties["onExpandFunction"]["essential"] = false
489dropDownMenuProperties["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)"
490
491dropDownMenuProperties["onCollapseFunction"] = {}
492dropDownMenuProperties["onCollapseFunction"]["input"] = "manual"
493dropDownMenuProperties["onCollapseFunction"]["essential"] = false
494dropDownMenuProperties["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)"
495
496--title,menuArray (text, submenu),titleTextColor,titleBGColor,titleTextColorExpanded,titleBGColorExpanded,textAlignmentHorizontal,textAlignmentVertical,entryWidth,entryHeight,entryTextColor,entryBGColor,borderColor,spaceBetweenEntries,borderThickness,highlightTextColor,highlightBGColor,expanded,highlightIDs,onChangeFunction,enabled,visible
497navigationMenuProperties = {}
498navigationMenuProperties["title"] = {}
499navigationMenuProperties["title"]["input"] = "string"
500navigationMenuProperties["title"]["essential"] = true
501navigationMenuProperties["title"]["desc"] = "title (string): the text of the title of the navigationMenu. Also displayed when the menu is collapsed."
502navigationMenuProperties["title"]["default"] = "Menu"
503
504navigationMenuProperties["menuArray"] = {}
505navigationMenuProperties["menuArray"]["input"] = "navMenuArray"
506navigationMenuProperties["menuArray"]["essential"] = true
507navigationMenuProperties["menuArray"]["desc"] = "menuArray (numerically indexed nested table): all entries of the navigationMenu with submenus if necessary. Structure: array[index]={[\"text\"]=\"text\",[\"submenu\"]=anotherMenuArray}"
508navigationMenuProperties["menuArray"]["default"] = {{["text"]="Entry 1"},{["text"]="Entry 2"},{["text"]="Entry 3"}}
509
510navigationMenuProperties["titleTextColor"] = {}
511navigationMenuProperties["titleTextColor"]["input"] = "color"
512navigationMenuProperties["titleTextColor"]["essential"] = false
513navigationMenuProperties["titleTextColor"]["desc"] = "titleTextColor (color): color of the text of title. If unused (nil) defaultTextColor of the screen will be used."
514
515navigationMenuProperties["titleBGColor"] = {}
516navigationMenuProperties["titleBGColor"]["input"] = "color"
517navigationMenuProperties["titleBGColor"]["essential"] = false
518navigationMenuProperties["titleBGColor"]["desc"] = "titleBGColor (color): color of the background of title. If unused (nil) defaultBGColor of the screen will be used."
519
520navigationMenuProperties["titleTextColorExpanded"] = {}
521navigationMenuProperties["titleTextColorExpanded"]["input"] = "color"
522navigationMenuProperties["titleTextColorExpanded"]["essential"] = false
523navigationMenuProperties["titleTextColorExpanded"]["desc"] = "titleTextColor (color): color of the text of title when menu is expanded. If unused (nil) titleTextColor will be used."
524
525navigationMenuProperties["titleBGColorExpanded"] = {}
526navigationMenuProperties["titleBGColorExpanded"]["input"] = "color"
527navigationMenuProperties["titleBGColorExpanded"]["essential"] = false
528navigationMenuProperties["titleBGColorExpanded"]["desc"] = "titleBGColor (color): color of the background of title when menu is expanded. If unused (nil) titleBGColor will be used."
529
530navigationMenuProperties["borderColor"] = {}
531navigationMenuProperties["borderColor"]["input"] = "color"
532navigationMenuProperties["borderColor"]["essential"] = false
533navigationMenuProperties["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."
534
535navigationMenuProperties["entryTextColor"] = {}
536navigationMenuProperties["entryTextColor"]["input"] = "color"
537navigationMenuProperties["entryTextColor"]["essential"] = false
538navigationMenuProperties["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."
539
540navigationMenuProperties["entryBGColor"] = {}
541navigationMenuProperties["entryBGColor"]["input"] = "color"
542navigationMenuProperties["entryBGColor"]["essential"] = false
543navigationMenuProperties["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."
544
545navigationMenuProperties["highlightTextColor"] = {}
546navigationMenuProperties["highlightTextColor"]["input"] = "color"
547navigationMenuProperties["highlightTextColor"]["essential"] = false
548navigationMenuProperties["highlightTextColor"]["desc"] = "highlightTextColor (color): color of the text of a highlighted entry of the expanded menu. If unused (nil) entryTextColor will be used."
549
550navigationMenuProperties["highlightBGColor"] = {}
551navigationMenuProperties["highlightBGColor"]["input"] = "color"
552navigationMenuProperties["highlightBGColor"]["essential"] = false
553navigationMenuProperties["highlightBGColor"]["desc"] = "highlightBGColor (color): color of the background of a highlighted entry of the expanded menu. If unused (nil) entryBGColor will be used."
554
555navigationMenuProperties["entryWidth"] = {}
556navigationMenuProperties["entryWidth"]["input"] = "number"
557navigationMenuProperties["entryWidth"]["essential"] = false
558navigationMenuProperties["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."
559
560navigationMenuProperties["entryHeight"] = {}
561navigationMenuProperties["entryHeight"]["input"] = "number"
562navigationMenuProperties["entryHeight"]["essential"] = false
563navigationMenuProperties["entryHeight"]["desc"] = "entryHeight (non-decimal number in pixels): how broad (y) every entry shall be including submenus. If unused (nil) will be 1."
564
565navigationMenuProperties["textAlignmentHorizontal"] = {}
566navigationMenuProperties["textAlignmentHorizontal"]["input"] = "DDM:left:center:right"
567navigationMenuProperties["textAlignmentHorizontal"]["essential"] = false
568navigationMenuProperties["textAlignmentHorizontal"]["desc"] = "textAlignmentHorizontal (left,center,right): where the text inside every entry including submenus shall be placed horizontally. If unused (nil) defaults to center."
569
570navigationMenuProperties["textAlignmentVertical"] = {}
571navigationMenuProperties["textAlignmentVertical"]["input"] = "DDM:top:center:bottom"
572navigationMenuProperties["textAlignmentVertical"]["essential"] = false
573navigationMenuProperties["textAlignmentVertical"]["desc"] = "textAlignmentVertical (top,center,bottom): where the text inside every entry including submenus shall be placed vertically. If unused (nil) defaults to center."
574
575navigationMenuProperties["borderThickness"] = {}
576navigationMenuProperties["borderThickness"]["input"] = "number"
577navigationMenuProperties["borderThickness"]["essential"] = false
578navigationMenuProperties["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)"
579
580navigationMenuProperties["spaceBetweenEntries"] = {}
581navigationMenuProperties["spaceBetweenEntries"]["input"] = "number"
582navigationMenuProperties["spaceBetweenEntries"]["essential"] = false
583navigationMenuProperties["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)"
584
585navigationMenuProperties["onChangeFunction"] = {}
586navigationMenuProperties["onChangeFunction"]["input"] = "manual"
587navigationMenuProperties["onChangeFunction"]["essential"] = false
588navigationMenuProperties["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)"
589
590--selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
591colorPickerProperties = {}
592colorPickerProperties["selection"] = {}
593colorPickerProperties["selection"]["input"] = "color"
594colorPickerProperties["selection"]["essential"] = false
595colorPickerProperties["selection"]["desc"] = "selection (color): by default selected color."
596
597colorPickerProperties["borderColor"] = {}
598colorPickerProperties["borderColor"]["input"] = "color"
599colorPickerProperties["borderColor"]["essential"] = false
600colorPickerProperties["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."
601
602colorPickerProperties["borderThickness"] = {}
603colorPickerProperties["borderThickness"]["input"] = "number"
604colorPickerProperties["borderThickness"]["essential"] = false
605colorPickerProperties["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)"
606
607colorPickerProperties["colorWidth"] = {}
608colorPickerProperties["colorWidth"]["input"] = "number"
609colorPickerProperties["colorWidth"]["essential"] = false
610colorPickerProperties["colorWidth"]["desc"] = "colorWidth (non-decimal number in pixels): how wide (x) every color shall be. If unused (nil) will be 1."
611
612colorPickerProperties["colorHeight"] = {}
613colorPickerProperties["colorHeight"]["input"] = "number"
614colorPickerProperties["colorHeight"]["essential"] = false
615colorPickerProperties["colorHeight"]["desc"] = "colorHeight (non-decimal number in pixels): how broad (y) every color shall be. If unused (nil) will be 1."
616
617colorPickerProperties["selectionCharacter"] = {}
618colorPickerProperties["selectionCharacter"]["input"] = "string"
619colorPickerProperties["selectionCharacter"]["essential"] = false
620colorPickerProperties["selectionCharacter"]["desc"] = "selectionCharacter (1 character): the character which shall indicate the currently selected color. If unused will be X."
621
622colorPickerProperties["onChangeFunction"] = {}
623colorPickerProperties["onChangeFunction"]["input"] = "manual"
624colorPickerProperties["onChangeFunction"]["essential"] = false
625colorPickerProperties["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)"
626
627--length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
628progressBarProperties = {}
629progressBarProperties["length"] = {}
630progressBarProperties["length"]["input"] = "number"
631progressBarProperties["length"]["essential"] = true
632progressBarProperties["length"]["desc"] = "length (non-decimal number in pixels): the length of the progressBar."
633progressBarProperties["length"]["default"] = 5
634
635progressBarProperties["value"] = {}
636progressBarProperties["value"]["input"] = "number"
637progressBarProperties["value"]["essential"] = false
638progressBarProperties["value"]["desc"] = "value (non-decimal number): the default value the progressBar shall take on, either in percent or absolute, see valueType. Defaults to 0."
639
640progressBarProperties["valueType"] = {}
641progressBarProperties["valueType"]["input"] = "DDM:relative:absolute"
642progressBarProperties["valueType"]["essential"] = false
643progressBarProperties["valueType"]["desc"] = "valueType (relative,absolute): whether value shall be an absolute value or a percentage. Defaults to absolute."
644
645progressBarProperties["color"] = {}
646progressBarProperties["color"]["input"] = "color"
647progressBarProperties["color"]["essential"] = false
648progressBarProperties["color"]["desc"] = "color (color): the color the bar of the progressBar shall take on. If unused (nil) will be the defaultTextColor of the screen."
649
650progressBarProperties["BGColor"] = {}
651progressBarProperties["BGColor"]["input"] = "color"
652progressBarProperties["BGColor"]["essential"] = false
653progressBarProperties["BGColor"]["desc"] = "BGColor (color): the background of the progressBar. If unused (nil) will be the defaultBGColor of the screen."
654
655progressBarProperties["borderColor"] = {}
656progressBarProperties["borderColor"]["input"] = "color"
657progressBarProperties["borderColor"]["essential"] = false
658progressBarProperties["borderColor"]["desc"] = "borderColor (color): color of the border of the progressBar. borderThickness needs to be greater than 0. If unused (nil) will be BGColor."
659
660progressBarProperties["borderThickness"] = {}
661progressBarProperties["borderThickness"]["input"] = "number"
662progressBarProperties["borderThickness"]["essential"] = false
663progressBarProperties["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)"
664
665progressBarProperties["colorsArray"] = {}
666progressBarProperties["colorsArray"]["input"] = "colorsArray"
667progressBarProperties["colorsArray"]["essential"] = false
668progressBarProperties["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."
669
670progressBarProperties["broadness"] = {}
671progressBarProperties["broadness"]["input"] = "number"
672progressBarProperties["broadness"]["essential"] = false
673progressBarProperties["broadness"]["desc"] = "broadness (non-decimal number in pixels): how broad the progressBar shall be. Perpendicular to progressBar orientation. If unused (nil) will be 1."
674
675progressBarProperties["orientation"] = {}
676progressBarProperties["orientation"]["input"] = "DDM:top-bottom:bottom-top:left-right:right-left"
677progressBarProperties["orientation"]["essential"] = false
678progressBarProperties["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."
679
680progressBarProperties["textPosition"] = {}
681progressBarProperties["textPosition"]["input"] = "DDM:top:bottom:left:right"
682progressBarProperties["textPosition"]["essential"] = false
683progressBarProperties["textPosition"]["desc"] = "textPosition (top,bottom,left,right): if this value is set will display the current value at the chosen position."
684
685progressBarProperties["textMargin"] = {}
686progressBarProperties["textMargin"]["input"] = "number"
687progressBarProperties["textMargin"]["essential"] = false
688progressBarProperties["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."
689
690--width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepX,stepY
691coordinateSystemProperties = {}
692coordinateSystemProperties["width"] = {}
693coordinateSystemProperties["width"]["input"] = "number"
694coordinateSystemProperties["width"]["essential"] = true
695coordinateSystemProperties["width"]["desc"] = "width (non-decimal number in pixels): how long the x axis shall be."
696coordinateSystemProperties["width"]["default"] = 10
697
698coordinateSystemProperties["height"] = {}
699coordinateSystemProperties["height"]["input"] = "number"
700coordinateSystemProperties["height"]["essential"] = true
701coordinateSystemProperties["height"]["desc"] = "height (non-decimal number in pixels): how long the y axis shall be."
702coordinateSystemProperties["height"]["default"] = 10
703
704coordinateSystemProperties["graphTables"] = {}
705coordinateSystemProperties["graphTables"]["input"] = "CSTable"
706coordinateSystemProperties["graphTables"]["essential"] = false
707coordinateSystemProperties["graphTables"]["desc"] = "graphTables (numerically-indexed nested table) all graphs to be displayed. Structure: array[index]={[x]=y}"
708
709coordinateSystemProperties["graphDesigns"] = {}
710coordinateSystemProperties["graphDesigns"]["input"] = "CSDesignsTable"
711coordinateSystemProperties["graphDesigns"]["essential"] = false
712coordinateSystemProperties["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}"
713
714coordinateSystemProperties["numbersColor"] = {}
715coordinateSystemProperties["numbersColor"]["input"] = "color"
716coordinateSystemProperties["numbersColor"]["essential"] = false
717coordinateSystemProperties["numbersColor"]["desc"] = "numbersColor (color): color of the numbers next to the axes. If unused (nil) will be defaultTextColor of the screen."
718
719coordinateSystemProperties["axesColor"] = {}
720coordinateSystemProperties["axesColor"]["input"] = "color"
721coordinateSystemProperties["axesColor"]["essential"] = false
722coordinateSystemProperties["axesColor"]["desc"] = "axesColor (color): color of the axes. If unused (nil) will be defaultTextColor of the screen."
723
724coordinateSystemProperties["unitsPerPixelX"] = {}
725coordinateSystemProperties["unitsPerPixelX"]["input"] = "decimal"
726coordinateSystemProperties["unitsPerPixelX"]["essential"] = false
727coordinateSystemProperties["unitsPerPixelX"]["desc"] = "unitsPerPixelX (decimal number): how many units one pixel equals on the x axis. If unused (nil) will be 1."
728
729coordinateSystemProperties["unitsPerPixelY"] = {}
730coordinateSystemProperties["unitsPerPixelY"]["input"] = "decimal"
731coordinateSystemProperties["unitsPerPixelY"]["essential"] = false
732coordinateSystemProperties["unitsPerPixelY"]["desc"] = "unitsPerPixelY (decimal number): how many units one pixel equals on the y axis. If unused (nil) will be 1."
733
734coordinateSystemProperties["labelX"] = {}
735coordinateSystemProperties["labelX"]["input"] = "string"
736coordinateSystemProperties["labelX"]["essential"] = false
737coordinateSystemProperties["labelX"]["desc"] = "labelX (string): label of the x axis to be placed next to it. If unused (nil) will be X."
738
739coordinateSystemProperties["labelY"] = {}
740coordinateSystemProperties["labelY"]["input"] = "string"
741coordinateSystemProperties["labelY"]["essential"] = false
742coordinateSystemProperties["labelY"]["desc"] = "labelY (string): label of the y axis to be placed next to it. If unused (nil) will be Y."
743
744coordinateSystemProperties["startX"] = {}
745coordinateSystemProperties["startX"]["input"] = "decimal"
746coordinateSystemProperties["startX"]["essential"] = false
747coordinateSystemProperties["startX"]["desc"] = "startX (decimal number): what x coordinate shall be at the origin of the system. If unused (nil) will be 0."
748
749coordinateSystemProperties["startY"] = {}
750coordinateSystemProperties["startY"]["input"] = "decimal"
751coordinateSystemProperties["startY"]["essential"] = false
752coordinateSystemProperties["startY"]["desc"] = "startY (decimal number): what y coordinate shall be at the origin of the system. If unused (nil) will be 0."
753
754coordinateSystemProperties["stepX"] = {}
755coordinateSystemProperties["stepX"]["input"] = "number"
756coordinateSystemProperties["stepX"]["essential"] = false
757coordinateSystemProperties["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."
758
759coordinateSystemProperties["stepY"] = {}
760coordinateSystemProperties["stepY"]["input"] = "number"
761coordinateSystemProperties["stepY"]["essential"] = false
762coordinateSystemProperties["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."
763
764--linesArray
765pictureProperties = {}
766pictureProperties["linesArray"] = {}
767pictureProperties["linesArray"]["input"] = "picArray"
768pictureProperties["linesArray"]["essential"] = true
769pictureProperties["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."
770pictureProperties["linesArray"]["default"] = {"#;#;#;#;#;#;#;#;#;#;","#;*:#:Y;*:#:o;*:#:u;*:#:r;#;*:#:P;*:#:i;*:#:c;#;","#;#;#;#;#;#;#;#;#;#;"}
771
772pictureProperties["width"] = {}
773pictureProperties["width"]["input"] = "number"
774pictureProperties["width"]["essential"] = true
775pictureProperties["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."
776pictureProperties["width"]["default"] = 10
777
778pictureProperties["height"] = {}
779pictureProperties["height"]["input"] = "number"
780pictureProperties["height"]["essential"] = true
781pictureProperties["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."
782pictureProperties["height"]["default"] = 3
783
784--elementProperties
785elementProperties = {}
786elementProperties["dynTextBox"] = dynamicTextBoxProperties
787elementProperties["slider"] = sliderProperties
788elementProperties["dropDownMenu"] = dropDownMenuProperties
789elementProperties["navMenu"] = navigationMenuProperties
790elementProperties["colorPicker"] = colorPickerProperties
791elementProperties["progressBar"] = progressBarProperties
792elementProperties["coordsSystem"] = coordinateSystemProperties
793elementProperties["picture"] = pictureProperties
794
795elements = {}
796elements["dynTextBox"] = dynamicTextBoxes
797elements["slider"] = sliders
798elements["dropDownMenu"] = dropDownMenus
799elements["navMenu"] = navigationMenus
800elements["colorPicker"] = colorPickers
801elements["progressBar"] = progressBars
802elements["coordsSystem"] = coordinateSystems
803elements["picture"] = pictures
804
805--string to boolean
806function toBool(var)
807 if type(var)=="string" then
808 if var=="true" then
809 return true
810 else
811 return false
812 end
813 end
814end
815
816--this is used to avoid ID conflicts
817function trackID(ID)
818 ID = string.lower(ID)
819 local found = false
820 for i,current in ipairs(IDlist) do
821 if current==ID then
822 found = true
823 break
824 end
825 end
826 if found then
827 writeToLog("Potential ID conflict: "..ID..". Ignore if designer.",3)
828 else
829 if ID~=nil then
830 table.insert(IDlist,ID)
831 writeToLog("ID "..ID.." added to list.",1)
832 else
833 writeToLog("ID can't be nil!",4)
834 return false
835 end
836 end
837 return not found
838end
839
840function IDExists(ID)
841 ID = string.lower(ID)
842 for i,current in ipairs(IDlist) do
843 if ID==current then
844 return true
845 end
846 end
847 return false
848end
849
850--function to turn a percentage into an absolute coordinate
851function relX(perc,screenID)
852 if math.floor(((screens[screenID]["sizeX"])/100)*perc)>0 then
853 return math.floor(((screens[screenID]["sizeX"])/100)*perc+0.5)
854 else
855 return 1
856 end
857end
858
859function relY(perc,screenID)
860 if math.floor(((screens[screenID]["sizeY"])/100)*perc)>0 then
861 return math.floor(((screens[screenID]["sizeY"])/100)*perc+0.5)
862 else
863 return 1
864 end
865end
866
867--writeToLog function with 5 different levels and time since program start
868function writeToLog(text,level)
869 local levels = {"DEBUG","INFO","WARNING","ERROR","FATAL"}
870 if level == nil then
871 level = 2
872 end
873 if level>=writingLogLevel then
874 if fs.getFreeSpace(fs.combine(root,"EasyGUI/"))>1000 then
875 local timeNumber = os.clock() - startTime
876 local hours = 0
877 local minutes = 0
878 local seconds = 0
879 local milliseconds = 0
880 while timeNumber>=3600 do
881 hours = hours + 1
882 timeNumber = timeNumber - 3600
883 end
884 while timeNumber>=60 do
885 minutes = minutes + 1
886 timeNumber = timeNumber - 60
887 end
888 seconds = timeNumber
889
890 local hours = tostring(hours)
891 local minutes = tostring(minutes)
892 local seconds = tostring(seconds)
893 if string.len(hours)==1 then
894 hours = "0"..hours
895 end
896 if string.len(minutes)==1 then
897 minutes = "0"..minutes
898 end
899 if lastLogString~="[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text then
900 logFile.writeLine("[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text)
901 logFile.flush()
902 lastLogString = "[EasyGUI]["..hours..":"..minutes..":"..seconds.."] "..levels[level]..": "..text
903 end
904 end
905 end
906end
907
908--save and load functions from here:
909--monitors,screens,dynamicTextBoxes,sliders,dropDownMenus,navigationMenus,colorPickers,progressBars,coordinateSystem,picture
910
911function saveMonitors()
912 writeToLog("Saving monitors to monitors.xml...",2)
913 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
914 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
915 end
916 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"a")
917 stream.writeLine("<monitors>")
918
919 for sMonitor,data in pairs(monitors) do
920 writeToLog("Saving monitor "..sMonitor.." to monitors.xml...",1)
921 stream.writeLine("\t<monitor>")
922 stream.writeLine("\t\t<name>"..sMonitor.."</name>")
923 writeToLog("Saving side "..data["side"]..".",1)
924 stream.writeLine("\t\t<side>"..data["side"].."</side>")
925 writeToLog("Saving networkID "..data["networkID"]..".",1)
926 stream.writeLine("\t\t<networkID>"..data["networkID"].."</networkID>")
927 stream.writeLine("\t</monitor>")
928 writeToLog("Done saving monitor "..sMonitor.." to monitors.xml.",1)
929 end
930
931 stream.writeLine("</monitors>")
932 stream.close()
933 writeToLog("Done saving monitors to monitors.xml.",2)
934end
935
936function loadMonitors()
937 writeToLog("Loading monitors from monitors.xml...",2)
938 local stream = fs.open(fs.combine(root,"EasyGUI/monitors.xml"),"r")
939
940 local line = stream.readLine()
941 local mon = nil
942 while line~=nil do
943 if string.match(line,"<monitor>") then
944 if mon==nil then
945 mon = {}
946 writeToLog("Reading new monitor tag...",1)
947 else
948 writeToLog("Found monitor tag even though previous monitor tag was not closed. Did someone mess around with the xml?",4)
949 mon = {}
950 end
951 end
952 if string.match(line,"<name>") and string.match(line,"</name>") then
953 a,start = string.find(line,"<name>")
954 sEnd,b = string.find(line,"</name>")
955 name = string.sub(line,start+1,sEnd-1)
956 if mon~=nil then
957 writeToLog("Reading monitor name: "..name,1)
958 mon["name"] = name
959 else
960 writeToLog("Found name tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
961 end
962 end
963 if string.match(line,"<side>") and string.match(line,"</side>") then
964 a,start = string.find(line,"<side>")
965 sEnd,b = string.find(line,"</side>")
966 side = string.sub(line,start+1,sEnd-1)
967 if mon~=nil then
968 writeToLog("Reading monitor side: "..side,1)
969 mon["side"] = side
970 else
971 writeToLog("Found side tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
972 end
973 end
974 if string.match(line,"<networkID>") and string.match(line,"</networkID>") then
975 a,start = string.find(line,"<networkID>")
976 sEnd,b = string.find(line,"</networkID>")
977 networkID = string.sub(line,start+1,sEnd-1)
978 if mon~=nil then
979 writeToLog("Reading monitor networkID: "..networkID,1)
980 mon["networkID"] = networkID
981 else
982 writeToLog("Found networkID tag even though no monitor tag is opened. Did someone mess around with the xml?",4)
983 end
984 end
985 if string.match(line,"</monitor>") then
986 if mon~=nil then
987 name = mon["name"]
988 mon["name"] = nil
989 if mon["side"]~=nil and mon["networkID"]~=nil then
990 monitors[name] = mon
991 trackID(name)
992 if mon["networkID"]=="NONE" then
993 monitors[name]["peripheral"] = peripheral.wrap(mon["side"])
994 if monitors[name]["peripheral"]==nil then
995 monitors[name]=nil
996 writeToLog("A saved monitor is missing. Reinitializing search.",4)
997 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
998 findMonitors()
999 saveMonitors()
1000 break
1001 else
1002 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
1003 end
1004 else
1005 monitors[name]["peripheral"] = peripheral.wrap(mon["networkID"])
1006 if monitors[name]["peripheral"]==nil then
1007 monitors[name]=nil
1008 writeToLog("A saved monitor is missing. Reinitializing search.",4)
1009 fs.delete(fs.combine(root,"EasyGUI/monitors.xml"))
1010 findMonitors()
1011 saveMonitors()
1012 break
1013 else
1014 writeToLog("Successfully read information for monitor "..name.." and added to the system.",1)
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 writeToLog("Done loading monitors from monitors.xml.",2)
1030 stream.close()
1031end
1032
1033function saveScreen(ID)
1034 if screens[ID]~=nil then
1035 writeToLog("Saving screen "..ID.."...",2)
1036 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1037 fs.delete(fs.combine(root,"EasyGUI/screens/"..ID..".xml"))
1038 end
1039
1040 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"a")
1041
1042 local data = screens[ID]
1043
1044 handle.writeLine("<screen>")
1045 saveProp(handle,"sizeX",data)
1046 saveProp(handle,"sizeY",data)
1047 saveProp(handle,"defaultTextColor",data)
1048 saveProp(handle,"defaultBGColor",data)
1049
1050 handle.writeLine("\t<elements>")
1051 for i,element in ipairs(data["elements"]) do
1052 if string.len(element["ID"])<32 then
1053 handle.writeLine("\t\t<element>")
1054 handle.writeLine("\t\t\t<type>"..element["type"].."</type>")
1055 handle.writeLine("\t\t\t<ID>"..element["ID"].."</ID>")
1056 handle.writeLine("\t\t\t<x>"..element["x"].."</x>")
1057 handle.writeLine("\t\t\t<y>"..element["y"].."</y>")
1058 saveElement(element["ID"],element["type"])
1059 handle.writeLine("\t\t</element>")
1060 end
1061 end
1062 handle.writeLine("\t</elements>")
1063
1064 handle.writeLine("</screen>")
1065 handle.close()
1066 writeToLog("Done saving screen "..ID..".",2)
1067 else
1068 writeToLog("Could not save screen "..ID.." because it was not found.",3)
1069 end
1070end
1071
1072function loadScreen(ID)
1073 if fs.exists(fs.combine(root,"EasyGUI/screens/"..ID..".xml")) then
1074 local handle = fs.open(fs.combine(root,"EasyGUI/screens/"..ID..".xml"),"r")
1075 local temp = {}
1076 local line = handle.readLine()
1077 while line~=nil do
1078 readPropNumber(line,"sizeX",temp)
1079 readPropNumber(line,"sizeY",temp)
1080 readPropNumber(line,"defaultTextColor",temp)
1081 readPropNumber(line,"defaultBGColor",temp)
1082 if string.match(line,"<elements>") then
1083 local temp2 = {}
1084 line = handle.readLine()
1085 while not string.match(line,"</elements>") do
1086 if string.match(line,"<element>") then
1087 local temp3 = {}
1088 line = handle.readLine()
1089 while not string.match(line,"</element>") do
1090 if string.match(line,"<type>") and string.match(line,"</type>") then
1091 a,start = string.find(line,"<type>")
1092 sEnd,b = string.find(line,"</type>")
1093 type_ = string.sub(line,start+1,sEnd-1)
1094 temp3["type"] = type_
1095 end
1096 if string.match(line,"<ID>") and string.match(line,"</ID>") then
1097 a,start = string.find(line,"<ID>")
1098 sEnd,b = string.find(line,"</ID>")
1099 ID_ = string.sub(line,start+1,sEnd-1)
1100 temp3["ID"] = ID_
1101 end
1102 if string.match(line,"<x>") and string.match(line,"</x>") then
1103 a,start = string.find(line,"<x>")
1104 sEnd,b = string.find(line,"</x>")
1105 x_ = string.sub(line,start+1,sEnd-1)
1106 temp3["x"] = tonumber(x_)
1107 end
1108 if string.match(line,"<y>") and string.match(line,"</y>") then
1109 a,start = string.find(line,"<y>")
1110 sEnd,b = string.find(line,"</y>")
1111 y_ = string.sub(line,start+1,sEnd-1)
1112 temp3["y"] = tonumber(y_)
1113 end
1114
1115 line = handle.readLine()
1116 end
1117 loadElement(temp3["ID"],temp3["type"])
1118 table.insert(temp2,temp3)
1119 end
1120 line = handle.readLine()
1121 end
1122 temp["elements"] = temp2
1123 end
1124 line = handle.readLine()
1125 end
1126 if temp["sizeX"]~=nil and temp["sizeY"]~=nil and temp["defaultTextColor"]~=nil and temp["defaultBGColor"]~=nil and temp["elements"]~=nil then
1127 temp["pixelMatrix"] = {}
1128 screens[ID] = temp
1129 trackID(ID)
1130 writeToLog("Succesfully loaded screen "..ID..".",2)
1131 else
1132 writeToLog("Information for screen "..ID.." is faulty. Did someone mess around with the xml?",4)
1133 end
1134 handle.close()
1135 else
1136 writeToLog("Could not load screen "..ID.." because the file was not found.",3)
1137 end
1138end
1139
1140function tryLoadAllScreens()
1141 if fs.exists(fs.combine(root,"/EasyGUI/screens/")) then
1142 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/screens/"))) do
1143 if string.sub(name,-4)==".xml" then
1144 if screens[string.sub(name,1,-5)]==nil then
1145 loadScreen(string.sub(name,1,-5))
1146 end
1147 end
1148 end
1149 end
1150end
1151
1152function tryLoadAllElements()
1153 for type_,data in pairs(elements) do
1154 if fs.exists(fs.combine(root,"/EasyGUI/"..type_.."/")) then
1155 for i,name in ipairs(fs.list(fs.combine(root,"/EasyGUI/"..type_.."/"))) do
1156 if string.sub(name,-4)==".xml" then
1157 if elements[type_][string.sub(name,1,-5)]==nil then
1158 loadElement(string.sub(name,1,-5),type_)
1159 end
1160 end
1161 end
1162 end
1163 end
1164end
1165
1166function saveProp(handle,prop,data)
1167 if data[prop]~=nil then
1168 handle.writeLine("\t<"..prop..">"..data[prop].."</"..prop..">")
1169 writeToLog("Saving "..prop.." "..data[prop]..".",1)
1170 end
1171end
1172
1173function readPropString(line,prop,temp)
1174 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1175 local a,start = string.find(line,"<"..prop..">")
1176 local sEnd,b = string.find(line,"</"..prop..">")
1177 local value = string.sub(line,start+1,sEnd-1)
1178 temp[prop] = value
1179 writeToLog("Reading "..prop..": "..value,1)
1180 end
1181end
1182
1183function readPropNumber(line,prop,temp)
1184 if string.match(line,"<"..prop..">") and string.match(line,"</"..prop..">") then
1185 local a,start = string.find(line,"<"..prop..">")
1186 local sEnd,b = string.find(line,"</"..prop..">")
1187 local value = string.sub(line,start+1,sEnd-1)
1188 temp[prop] = tonumber(value)
1189 writeToLog("Reading "..prop..": "..value,1)
1190 end
1191end
1192
1193function saveArray(handle,prop,data)
1194 if data[prop]~=nil then
1195 handle.writeLine("\t<"..prop..">")
1196 writeToLog("Saving "..prop..".",1)
1197 for i,entry in ipairs(data[prop]) do
1198 handle.writeLine("\t\t<"..i..">"..entry.."</"..i..">")
1199 end
1200 handle.writeLine("\t</"..prop..">")
1201 end
1202end
1203
1204function readNumberArray(line,prop,temp,handle)
1205 if string.match(line,"<"..prop..">") then
1206 line = handle.readLine()
1207 local temp2 = {}
1208 while not (string.match(line,"</"..prop..">")) do
1209 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1210 local a,start = string.find(line,"<%d+>")
1211 local sEnd,b = string.find(line,"</%d+>")
1212 local currentValue = tonumber(string.sub(line,start+1,sEnd-1))
1213 local index = tonumber(string.sub(line,a+1,start-1))
1214 temp2[index] = currentValue
1215 end
1216
1217 line = handle.readLine()
1218 end
1219 temp[prop] = temp2
1220 writeToLog("Reading "..prop..".",1)
1221 end
1222end
1223
1224function readStringArray(line,prop,temp,handle)
1225 if string.match(line,"<"..prop..">") then
1226 line = handle.readLine()
1227 local temp2 = {}
1228 while not (string.match(line,"</"..prop..">")) do
1229 if string.match(line,"<%d+>") and string.match(line,"</%d+>") then
1230 local a,start = string.find(line,"<%d+>")
1231 local sEnd,b = string.find(line,"</%d+>")
1232 local currentValue = (string.sub(line,start+1,sEnd-1))
1233 local index = tonumber(string.sub(line,a+1,start-1))
1234 temp2[index] = currentValue
1235 end
1236
1237 line = handle.readLine()
1238 end
1239 temp[prop] = temp2
1240 writeToLog("Reading "..prop..".",1)
1241 end
1242end
1243
1244--helper function for writing navMenu arrays (recursive)
1245function writeSubmenu(handle,array,level)
1246 local tabs = "\t\t"
1247 for i=1,level-1 do
1248 tabs = tabs.."\t\t"
1249 end
1250 for i,entry in ipairs(array) do
1251 handle.writeLine(tabs.."<"..i..">")
1252 handle.writeLine(tabs.."\t<text>"..entry["text"].."</text>")
1253 if entry["submenu"]~=nil then
1254 handle.writeLine(tabs.."\t<submenu>")
1255 writeSubmenu(handle,entry["submenu"],level+1)
1256 handle.writeLine(tabs.."\t</submenu>")
1257 end
1258 handle.writeLine(tabs.."</"..i..">")
1259 end
1260end
1261
1262function saveNavMenu(handle,prop,data)
1263 handle.writeLine("\t<"..prop..">")
1264 writeSubmenu(handle,data[prop],1)
1265 handle.writeLine("\t</"..prop..">")
1266end
1267
1268function readNavMenu(line,prop,temp,handle)
1269 if string.match(line,"<"..prop..">") then
1270 line = handle.readLine()
1271 local temp2 = {}
1272 local currentPos = {}
1273 local indexTagOpen = 0
1274 local submenuTagOpen = 0
1275 local currentIndex = nil
1276 while not string.match(line,"</"..prop..">") do
1277 if string.match(line,"<%d+>") then
1278 a,start = string.find(line,"<%d+>")
1279 sEnd,b = string.find(line,"</%d+>")
1280 index = tonumber(string.sub(line,a+1,start-1))
1281
1282 local currentArray = temp2
1283 for i=1,table.getn(currentPos) do
1284 currentArray = currentArray[currentPos[i]]
1285 end
1286
1287 currentIndex = index
1288 currentArray[currentIndex] = {}
1289 indexTagOpen = indexTagOpen + 1
1290 end
1291 if string.match(line,"</%d+>") then
1292 if indexTagOpen==0 then
1293 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1294 end
1295 currentIndex = nil
1296 indexTagOpen = indexTagOpen - 1
1297 end
1298 if string.match(line,"<text>") and string.match(line,"</text>") then
1299 a,start = string.find(line,"<text>")
1300 sEnd,b = string.find(line,"</text>")
1301 text = string.sub(line,start+1,sEnd-1)
1302 writeToLog("Reading text: "..text,1)
1303 if indexTagOpen==0 or currentIndex==nil then
1304 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1305 else
1306 local currentArray = temp2
1307 for i=1,table.getn(currentPos) do
1308 currentArray = currentArray[currentPos[i]]["submenu"]
1309 end
1310 currentArray[currentIndex] = {}
1311 currentArray[currentIndex]["text"] = text
1312 end
1313 end
1314 if string.match(line,"<submenu>") then
1315 if indexTagOpen==0 or currentIndex==nil then
1316 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1317 else
1318 local currentArray = temp2
1319 for i=1,table.getn(currentPos) do
1320 currentArray = currentArray[currentPos[i]]["submenu"]
1321 end
1322 table.insert(currentPos,currentIndex)
1323 currentArray[currentIndex]["submenu"] = {}
1324 end
1325 submenuTagOpen = submenuTagOpen + 1
1326 end
1327 if string.match(line,"</submenu>") then
1328 if submenuTagOpen == 0 then
1329 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1330 else
1331 currentPos[table.getn(currentPos)] = nil
1332 end
1333
1334 submenuTagOpen = submenuTagOpen - 1
1335 end
1336 line = handle.readLine()
1337 end
1338 if submenuTagOpen~=0 or indexTagOpen~=0 then
1339 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1340 else
1341 temp["menuArray"] = temp2
1342 end
1343 end
1344end
1345
1346function saveCSTable(handle,prop,data)
1347 if data[prop]~=nil then
1348 handle.writeLine("\t<"..prop..">")
1349 for i,currentTable in ipairs(data[prop]) do
1350 handle.writeLine("\t\t<"..i..">")
1351 for name,currentNumber in pairs(currentTable) do
1352 handle.writeLine("\t\t\t<"..name..">"..currentNumber.."</"..name..">")
1353 end
1354 handle.writeLine("\t\t</"..i..">")
1355 end
1356 handle.writeLine("\t</"..prop..">")
1357 end
1358end
1359
1360function saveCSDesignsTable(handle,prop,data)
1361 if data[prop]~=nil then
1362 handle.writeLine("\t<"..prop..">")
1363 for i,design in ipairs(data[prop]) do
1364 handle.writeLine("\t\t<"..i..">")
1365 if design["color"]~=nil then
1366 handle.writeLine("\t\t\t<color>"..design["color"].."</color>")
1367 end
1368 if design["BGColor"]~=nil then
1369 handle.writeLine("\t\t\t<BGColor>"..design["BGColor"].."</BGColor>")
1370 end
1371 if design["character"]~=nil then
1372 handle.writeLine("\t\t\t<character>"..design["character"].."</character>")
1373 end
1374 handle.writeLine("\t\t</"..i..">")
1375 end
1376 handle.writeLine("\t</"..prop..">")
1377 end
1378end
1379
1380function readCSTable(line,prop,temp,handle)
1381 if string.match(line,"<"..prop..">") then
1382 line = handle.readLine()
1383 local temp2 = {}
1384 local tableOpen = nil
1385 while not string.match(line,"</"..prop..">") do
1386 if string.match(line,"<[%d.-]+>") then
1387 a,start = string.find(line,"<[%d.-]+>")
1388 index = tonumber(string.sub(line,a+1,start-1))
1389 if tableOpen==nil then
1390 tableOpen = index
1391 temp2[tableOpen] = {}
1392 else
1393 if string.match(line,"</[%d.-]+>") then
1394 sEnd,b = string.find(line,"</[%d.-]+>")
1395 currentNumber = tonumber(string.sub(line,start+1,sEnd-1))
1396 temp2[tableOpen][index] = currentNumber
1397 end
1398 end
1399 else if string.match(line,"</[%d.-]+>") then
1400 tableOpen = nil
1401 end
1402 end
1403 line = handle.readLine()
1404 end
1405 temp[prop] = temp2
1406 end
1407end
1408
1409function readCSDesignsTable(line,prop,temp,handle)
1410 if string.match(line,"<"..prop..">") then
1411 line = handle.readLine()
1412 local temp2 = {}
1413 local tableOpen = nil
1414 while not string.match(line,"</"..prop..">") do
1415 if string.match(line,"<%d+>") then
1416 a,start = string.find(line,"<%d+>")
1417 index = tonumber(string.sub(line,a+1,start-1))
1418 if tableOpen==nil then
1419 tableOpen = index
1420 temp2[tableOpen] = {}
1421 else
1422 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1423 end
1424 end
1425 if string.match(line,"</%d+>") then
1426 tableOpen = nil
1427 end
1428 if string.match(line,"<color>") and string.match(line,"</color>") then
1429 a,start = string.find(line,"<color>")
1430 sEnd,b = string.find(line,"</color>")
1431 color = string.sub(line,start+1,sEnd-1)
1432 if tableOpen==nil then
1433 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1434 else
1435 temp2[tableOpen]["color"] = tonumber(color)
1436 end
1437 end
1438 if string.match(line,"<BGColor>") and string.match(line,"</BGColor>") then
1439 a,start = string.find(line,"<BGColor>")
1440 sEnd,b = string.find(line,"</BGColor>")
1441 BGColor = string.sub(line,start+1,sEnd-1)
1442 if tableOpen==nil then
1443 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1444 else
1445 temp2[tableOpen]["BGColor"] = tonumber(BGColor)
1446 end
1447 end
1448 if string.match(line,"<character>") and string.match(line,"</character>") then
1449 a,start = string.find(line,"<character>")
1450 sEnd,b = string.find(line,"</character>")
1451 character = string.sub(line,start+1,sEnd-1)
1452 if tableOpen==nil then
1453 writeToLog("Invalid "..prop.." structure. Did someone mess around with the xml?",4)
1454 else
1455 temp2[tableOpen]["character"] = character
1456 end
1457 end
1458 line = handle.readLine()
1459 end
1460 temp[prop] = temp2
1461 end
1462end
1463
1464function saveElement(ID,type_)
1465 if elements[type_][ID]~=nil then
1466 writeToLog("Saving "..type_.." "..ID.."...",2)
1467 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1468 fs.delete(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"))
1469 end
1470
1471 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"a")
1472
1473 local data = elements[type_][ID]
1474
1475 handle.writeLine("<"..type_..">")
1476
1477 for name,data2 in pairs(elementProperties[type_]) do
1478 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
1479 saveProp(handle,name,data)
1480 end
1481 if data2["input"]=="colorsArray" or data2["input"]=="stringArray" or data2["input"]=="picArray" then
1482 saveArray(handle,name,data)
1483 end
1484 if data2["input"]=="navMenuArray" then
1485 saveNavMenu(handle,name,data)
1486 end
1487 if data2["input"]=="CSTable" then
1488 saveCSTable(handle,name,data)
1489 end
1490 if data2["input"]=="CSDesignsTable" then
1491 saveCSDesignsTable(handle,name,data)
1492 end
1493 end
1494
1495 handle.writeLine("</"..type_..">")
1496 handle.close()
1497 writeToLog("Done saving "..type_.." "..ID..".",2)
1498 else
1499 writeToLog("Could not save "..type_.." "..ID.." because it was not found.",3)
1500 end
1501end
1502
1503function loadElement(ID,type_)
1504 if fs.exists(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml")) then
1505 local handle = fs.open(fs.combine(root,"EasyGUI/"..type_.."/"..ID..".xml"),"r")
1506 local temp = {}
1507 local line = handle.readLine()
1508 while line~=nil do
1509 for name,data2 in pairs(elementProperties[type_]) do
1510 if data2["input"]=="number" or data2["input"]=="decimal" or data2["input"]=="color" then
1511 readPropNumber(line,name,temp)
1512 end
1513 if data2["input"]=="string" or string.sub(data2["input"],1,3)=="DDM" then
1514 readPropString(line,name,temp)
1515 end
1516 if data2["input"]=="stringArray" or data2["input"]=="picArray" then
1517 readStringArray(line,name,temp,handle)
1518 end
1519 if data2["input"]=="colorsArray" then
1520 readNumberArray(line,name,temp,handle)
1521 end
1522 if data2["input"]=="navMenuArray" then
1523 readNavMenu(line,name,temp,handle)
1524 end
1525 if data2["input"]=="CSTable" then
1526 readCSTable(line,name,temp,handle)
1527 end
1528 if data2["input"]=="CSDesignsTable" then
1529 readCSDesignsTable(line,name,temp,handle)
1530 end
1531 end
1532
1533 line = handle.readLine()
1534 end
1535 local valid = true
1536 for name,data2 in pairs(elementProperties[type_]) do
1537 if data2["essential"] then
1538 if temp[name]==nil then
1539 valid = false
1540 break
1541 end
1542 end
1543 end
1544 if valid then
1545 temp["visible"] = true
1546 temp["enabled"] = true
1547 temp["expanded"] = false
1548 elements[type_][ID] = temp
1549 trackID(ID)
1550 writeToLog("Succesfully loaded "..type_.." "..ID..".",2)
1551 else
1552 writeToLog("Information for "..type_.." "..ID.." is faulty. Did someone mess around with the xml?",4)
1553 end
1554 handle.close()
1555 else
1556 writeToLog("Could not load "..type_.." "..ID.." because the file was not found.",3)
1557 end
1558end
1559
1560--screens and pixel matrices from here
1561--this functions adds a screen
1562function addScreen(id,sizeX,sizeY,defaultTextColor,defaultBGColor)
1563 if trackID(id) then
1564 screens[id] = {}
1565 screens[id]["sizeX"] = sizeX
1566 screens[id]["sizeY"] = sizeY
1567 screens[id]["defaultTextColor"] = defaultTextColor
1568 screens[id]["defaultBGColor"] = defaultBGColor
1569 screens[id]["elements"] = {}
1570 screens[id]["pixelMatrix"] = {}
1571 writeToLog("Added screen "..id..".",2)
1572 else
1573 writeToLog("Did not add screen because of ID conflict.",3)
1574 end
1575end
1576
1577--this is an essential function which adds pixels to screen matrices accordingly
1578function writeToPixelMatrix(screenID,s,x,y,textColor,BGColor,elementID,elementType,sPart)
1579 if string.len(s)==1 then
1580 if x<=screens[screenID]["sizeX"] and y<=screens[screenID]["sizeY"] and x>=1 and y>=1 then
1581 writeToLog("Drawing "..sPart.." of "..elementType.." "..elementID..".",1)
1582 screens[screenID]["pixelMatrix"][x..":"..y] = {}
1583 screens[screenID]["pixelMatrix"][x..":"..y]["character"] = s
1584 screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] = textColor
1585 screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] = BGColor
1586 screens[screenID]["pixelMatrix"][x..":"..y]["elementID"] = elementID
1587 screens[screenID]["pixelMatrix"][x..":"..y]["elementType"] = elementType
1588 screens[screenID]["pixelMatrix"][x..":"..y]["part"] = sPart
1589 else
1590 writeToLog("Part "..sPart.." of "..elementType.." "..elementID.." tried to draw outside of screen "..screenID..".",3)
1591 end
1592 else
1593 for i=1,string.len(s) do
1594 writeToPixelMatrix(screenID,string.sub(s,i,i),x+i-1,y,textColor,BGColor,elementID,elementType,sPart)
1595 end
1596 end
1597end
1598
1599function fullRefresh()
1600 clearTerminal()
1601 clearMonitors()
1602 for name,data in pairs(screens) do
1603 screens[name]["pixelMatrix"] = {}
1604 end
1605 refresh()
1606end
1607
1608function restartTimer(nRefreshRate)
1609 if nRefreshRate~=nil then
1610 refreshRate = nRefreshRate
1611 refreshTimerID = os.startTimer(refreshRate)
1612 writeToLog("Restarting refresh timer with refreshRate "..refreshRate.." seconds.",1)
1613 end
1614end
1615
1616--this function adds an element to the screen
1617function addElementToScreen(elementID, screenID, x,y)
1618 if x==nil then
1619 x = 1
1620 end
1621 if y==nil then
1622 y = 1
1623 end
1624 if screens[screenID]~=nil then
1625 local elements = screens[screenID]["elements"]
1626 local element = {}
1627 local exists = false
1628
1629 for i,current in ipairs(elements) do
1630 if current["ID"]==elementID then
1631 exists = true
1632 end
1633 end
1634
1635 if not exists then
1636 if getType(elementID)~=nil then
1637 element["type"] = getType(elementID)
1638 element["ID"] = elementID
1639 element["x"] = x
1640 element["y"] = y
1641
1642 table.insert(elements, element)
1643 screens[screenID]["elements"] = elements
1644 writeToLog("Successfully added element "..elementID.." to screen "..screenID..".",2)
1645 else
1646 writeToLog("Could not add element to the screen. Element was not found or nil.",3)
1647 end
1648 else
1649 writeToLog("Did not add element to the screen because the element is already on that screen.",2)
1650 end
1651 else
1652 writeToLog("Could not add the element to the screen. Screen was not found or nil.",3)
1653 end
1654end
1655
1656function removeElementFromScreen(elementID,screenID)
1657 if screens[screenID]~=nil then
1658 for i,data in ipairs(screens[screenID]["elements"]) do
1659 if data["ID"]==elementID then
1660 table.remove(screens[screenID]["elements"],i)
1661 break
1662 end
1663 end
1664 else
1665 writeToLog("Could not remove the element from the screen. Screen was not found or nil.",3)
1666 end
1667end
1668
1669function changePos(elementID,screenID,x,y)
1670 if x==nil then
1671 x = 1
1672 end
1673 if y==nil then
1674 y = 1
1675 end
1676 if screens[screenID]~=nil then
1677 local elements = screens[screenID]["elements"]
1678 local found = false
1679
1680 for name,data in pairs(screens[screenID]["elements"]) do
1681 if data["ID"]==elementID then
1682 found = true
1683 data["x"] = x
1684 data["y"] = y
1685 break
1686 end
1687 end
1688
1689 if found then
1690 writeToLog("Successfully changed pos of element "..elementID.." on screen "..screenID..".",2)
1691 else
1692 writeToLog("Could not change pos of element. Element was not found or nil.",3)
1693 end
1694 else
1695 writeToLog("Could not change pos of element. Screen was not found or nil.",3)
1696 end
1697end
1698
1699function getPos(elementID,screenID)
1700 if screens[screenID]~=nil then
1701 local elements = screens[screenID]["elements"]
1702
1703 for name,data in pairs(screens[screenID]["elements"]) do
1704 if data["ID"]==elementID then
1705 return data["x"],data["y"]
1706 end
1707 end
1708 end
1709end
1710
1711--this function updates the pixel matrix of a certain screen
1712function updatePixelMatrix(screenID,str)
1713 writeToLog("Updating pixel matrix of screen "..screenID..".",2)
1714 --write elements to pixel matrix
1715 for i,element in ipairs(screens[screenID]["elements"]) do
1716 if str==nil or (string.len(element["ID"])>31 and str=="ONLYHASH") or (string.len(element["ID"])<32 and str=="ONLYNONHASH") then
1717 if elements[element["type"]][element["ID"]]["visible"] then
1718 writeToLog("Writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1719 success,msg = pcall(writeElementToPixelMatrix,screenID,element["ID"],element["x"],element["y"],element["type"])
1720 if success then
1721 writeToLog("Done writing "..element["type"].." "..element["ID"].." to pixel matrix.",1)
1722 else
1723 writeToLog("There was an error writing "..element["type"].." "..element["ID"].." to pixel matrix. Error message: "..msg,4)
1724 end
1725 end
1726 end
1727 end
1728 writeToLog("Done updating pixel matrix.",2)
1729end
1730
1731function writeElementToPixelMatrix(screenID,ID,x,y,type_)
1732 if type_=="dynTextBox" then
1733 writeDynamicTextBoxToPixelMatrix(screenID,ID,x,y)
1734 end
1735 if type_=="slider" then
1736 writeSliderToPixelMatrix(screenID,ID,x,y)
1737 end
1738 if type_=="dropDownMenu" then
1739 writeDropDownMenuToPixelMatrix(screenID,ID,x,y)
1740 end
1741 if type_=="navMenu" then
1742 writeNavigationMenuToPixelMatrix(screenID,ID,x,y)
1743 end
1744 if type_=="colorPicker" then
1745 writeColorPickerToPixelMatrix(screenID,ID,x,y)
1746 end
1747 if type_=="progressBar" then
1748 writeProgressBarToPixelMatrix(screenID,ID,x,y)
1749 end
1750 if type_=="coordsSystem" then
1751 writeCoordinateSystemToPixelMatrix(screenID,ID,x,y)
1752 end
1753 if type_=="picture" then
1754 writePictureToPixelMatrix(screenID,ID,x,y)
1755 end
1756end
1757
1758function setScreenToRenderOnMon(screenID,monID,textScale,offsetX,offsetY)
1759 if offsetX ==nil then
1760 offsetX = 0
1761 end
1762 if offsetY ==nil then
1763 offsetY = 0
1764 end
1765 if monitors[monID]~=nil then
1766 if screens[screenID]~=nil then
1767 clearMonitor(monID)
1768 screens[screenID]["pixelMatrix"] = {}
1769 monitors[monID]["screen"] = screenID
1770 monitors[monID]["offsetX"] = offsetX
1771 monitors[monID]["offsetY"] = offsetY
1772 monitors[monID]["textScale"] = textScale
1773 writeToLog("Set screen "..screenID.." to be rendered on monitor "..monID..".",2)
1774 else
1775 writeToLog("Could not set screen to be rendered on monitor. Screen was not found or nil.",3)
1776 end
1777 else
1778 writeToLog("Could not set the screen to be rendered on monitor. Monitor was not found or nil.",3)
1779 end
1780end
1781
1782function setScreenToRenderOnTerminal(screenID)
1783 if screens[screenID]~=nil then
1784 clearTerminal()
1785 screens[screenID]["pixelMatrix"] = {}
1786 terminalScreen = screenID
1787 writeToLog("Set screen "..screenID.." to be rendered on terminal.")
1788 else
1789 terminalScreen = nil
1790 writeToLog("Could not set screen to be rendered on terminal. Screen was not found or nil.")
1791 end
1792end
1793
1794function setRefreshFunction(func)
1795 refreshFunction = func
1796 writeToLog("Changed refresh function.",2)
1797end
1798
1799function setProcessClickEventFunction(func)
1800 processClickEventFunc = func
1801 writeToLog("Changed processClickEvent function.",2)
1802end
1803
1804function setProcessEventFunction(func)
1805 processEventFunc = func
1806 writeToLog("Changed processEvent function.",2)
1807end
1808
1809function drawPixels(x,y,textColor,BGColor,str,monID)
1810 if monID~=nil then
1811 monitors[monID]["peripheral"].setBackgroundColor(BGColor)
1812 monitors[monID]["peripheral"].setTextColor(textColor)
1813 monitors[monID]["peripheral"].setCursorPos(x+monitors[monID]["offsetX"],y+monitors[monID]["offsetY"])
1814 monitors[monID]["peripheral"].write(str)
1815 else
1816 term.setBackgroundColor(BGColor)
1817 term.setTextColor(textColor)
1818 term.setCursorPos(x,y)
1819 term.write(str)
1820 end
1821end
1822
1823function drawOnMonitors(x,y,textColor,BGColor,str,monitorList)
1824 for i,monID in ipairs(monitorList) do
1825 if monID==terminalID then
1826 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str)
1827 else
1828 success,msg = pcall(drawPixels,x,y,textColor,BGColor,str,monID)
1829 end
1830 if success then
1831 writeToLog("Drew "..str.." at "..x..":"..y..".",1)
1832 else
1833 writeToLog("There was an error drawing "..str.." at "..x..":"..y..". Error message: "..msg,4)
1834 end
1835 end
1836end
1837
1838function refresh()
1839 writeToLog("Refreshing all monitors...",2)
1840 local startTime = os.clock()
1841 for screenID,screenData in pairs(screens) do
1842 monitorList = {}
1843 for monID,data in pairs(monitors) do
1844 if screenID==data["screen"] then
1845 table.insert(monitorList,monID)
1846 end
1847 end
1848 if screenID==terminalScreen then
1849 table.insert(monitorList,terminalID)
1850 end
1851 if table.getn(monitorList)~=0 then
1852 --store previous pixels in this array
1853 local previousMatrix = {}
1854 for name,data in pairs(screens[screenID]["pixelMatrix"]) do
1855 previousMatrix[name] = data
1856 end
1857 screens[screenID]["pixelMatrix"] = {}
1858
1859 if designerRefresh then
1860 updatePixelMatrix(screenID,"ONLYNONHASH")
1861 screens[screenID]["sizeX"] = designerX
1862 screens[screenID]["sizeY"] = designerY
1863 updatePixelMatrix(screenID,"ONLYHASH")
1864 else
1865 updatePixelMatrix(screenID)
1866 end
1867
1868 writeToLog("Drawing pixels of screen "..screenID.." on monitors.",2)
1869 --render pixel matrix
1870 for y=1,screens[screenID]["sizeY"] do
1871 --this is a system which is performance optimized
1872 --instead of drawing each pixel separately, it collects all the pixels which use the same colors and writes it as a whole string
1873 local currStr = ""
1874 local currTextColor = nil
1875 local currBGColor = nil
1876 local currX = nil
1877 for x=1,screens[screenID]["sizeX"] do
1878 if screens[screenID]["pixelMatrix"][x..":"..y]~=nil then
1879 --only draw it if something changed about the pixel
1880 --performance
1881 local draw = true
1882 if previousMatrix[x..":"..y]~=nil then
1883 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
1884 draw = false
1885 end
1886 else
1887 if screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]==screens[screenID]["defaultBGColor"] and screens[screenID]["pixelMatrix"][x..":"..y]["character"]==" " then
1888 draw = false
1889 end
1890 end
1891 if draw then
1892 if currTextColor==screens[screenID]["pixelMatrix"][x..":"..y]["textColor"] and currBGColor==screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"] then
1893 currStr = currStr ..screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1894 else
1895 if currStr~="" and currStr~=nil then
1896 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1897 end
1898 currStr = screens[screenID]["pixelMatrix"][x..":"..y]["character"]
1899 currTextColor = screens[screenID]["pixelMatrix"][x..":"..y]["textColor"]
1900 currBGColor = screens[screenID]["pixelMatrix"][x..":"..y]["BGColor"]
1901 currX = x
1902 end
1903 else
1904 if currStr~="" and currStr~=nil then
1905 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1906 end
1907 currStr = ""
1908 currTextColor = nil
1909 currBGColor = nil
1910 currX = nil
1911 end
1912 previousMatrix[x..":"..y] = nil
1913 else
1914 if currStr~="" and currStr~=nil then
1915 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1916 end
1917 currStr = ""
1918 currTextColor = nil
1919 currBGColor = nil
1920 currX = nil
1921 end
1922 end
1923 if currStr~="" and currStr~=nil then
1924 drawOnMonitors(currX,y,currTextColor,currBGColor,currStr,monitorList)
1925 end
1926 end
1927 writeToLog("Done drawing pixels of screen "..screenID.. " on monitors.",2)
1928
1929 --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
1930 --this is a clever way to increase performance
1931 writeToLog("Cleaning up monitors. (screen "..screenID..")",2)
1932 for y=1,screens[screenID]["sizeY"] do
1933 local str = ""
1934 local currX = nil
1935 for x=1,screens[screenID]["sizeX"] do
1936 if previousMatrix[x..":"..y]~=nil then
1937 if currX==nil then
1938 currX = x
1939 end
1940 str = str .." "
1941 else
1942 if str~="" then
1943 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
1944 end
1945 str = ""
1946 currX = nil
1947 end
1948 end
1949 if str~="" then
1950 drawOnMonitors(currX,y,screens[screenID]["defaultTextColor"],screens[screenID]["defaultBGColor"],str,monitorList)
1951 end
1952 end
1953 writeToLog("Done cleaning up monitors. (screen "..screenID..")",2)
1954
1955 if designerRefresh then
1956 screens[screenID]["sizeX"] = designerSmaxX
1957 screens[screenID]["sizeY"] = designerSmaxY
1958 end
1959 end
1960 end
1961 writeToLog("Done refreshing all monitors. Took "..(os.clock()-startTime).."seconds.",2)
1962end
1963
1964function clearMonitor(monID)
1965 local data = monitors[monID]
1966 if data["screen"]~=nil then
1967 local screenID = data["screen"]
1968 local offsetX = data["offsetX"]
1969 local offsetY = data["offsetY"]
1970 local textScale = data["textScale"]
1971 screens[screenID]["pixelMatrix"] = {}
1972 --check sizes
1973 monitors[monID]["peripheral"].setBackgroundColor(colors.black)
1974 monitors[monID]["peripheral"].clear()
1975 monX,monY = monitors[monID]["peripheral"].getSize()
1976 monitors[monID]["peripheral"].setTextScale(textScale)
1977 if (screens[screenID]["sizeX"] + offsetX)>monX or (screens[screenID]["sizeY"] + offsetY)>monY then
1978 writeToLog("Screen "..screenID.." cannot be displayed completely with given offset and textScale.",3)
1979 end
1980 monitors[monID]["peripheral"].setBackgroundColor(screens[screenID]["defaultBGColor"])
1981 --custom clear
1982 writeToLog("Clearing monitor "..monID.."...",1)
1983 local s = ""
1984 for i=1,screens[screenID]["sizeX"] do
1985 s = s.." "
1986 end
1987 for i=1,screens[screenID]["sizeY"] do
1988 monitors[monID]["peripheral"].setCursorPos(offsetX+1,offsetY+i)
1989 monitors[monID]["peripheral"].write(s)
1990 end
1991 writeToLog("Done clearing monitor "..monID..".",2)
1992 end
1993end
1994
1995function clearMonitors()
1996 for monID,data in pairs(monitors) do
1997 clearMonitor(monID)
1998 end
1999end
2000
2001function clearTerminal()
2002 if terminalScreen~=nil then
2003 local screenID = terminalScreen
2004 screens[screenID]["pixelMatrix"] = {}
2005 --check sizes
2006 sizeX,sizeY = term.getSize()
2007 if (screens[screenID]["sizeX"])>sizeX or (screens[screenID]["sizeY"])>sizeY then
2008 writeToLog("Screen "..screenID.." cannot be displayed completely on terminal.",3)
2009 end
2010 term.setBackgroundColor(colors.black)
2011 term.clear()
2012 term.setBackgroundColor(screens[screenID]["defaultBGColor"])
2013 --custom clear
2014 writeToLog("Clearing terminal.",1)
2015 local s = ""
2016 for i=1,screens[screenID]["sizeX"] do
2017 s = s.." "
2018 end
2019 for i=1,screens[screenID]["sizeY"] do
2020 term.setCursorPos(1,i)
2021 term.write(s)
2022 end
2023 writeToLog("Done clearing terminal.",2)
2024 end
2025end
2026
2027function run(nRefreshRate)
2028 writeToLog("Starting program, clearing all monitors...")
2029 clearMonitors()
2030 clearTerminal()
2031 writeToLog("Done clearing all monitors.")
2032
2033 refresh()
2034 if nRefreshRate~=nil then
2035 refreshRate = nRefreshRate
2036 refreshTimerID = os.startTimer(refreshRate)
2037 writeToLog("Starting refresh timer with refreshRate "..refreshRate.." seconds.",1)
2038 end
2039 local running = true
2040 while running do
2041 event,var1,var2,var3,var4,var5 = os.pullEventRaw()
2042 writeToLog("Caught "..event.." event.",2)
2043 if event=="monitor_touch" then
2044 processClickEvent(var1,var2,var3)
2045 end
2046 if event=="timer" then
2047 processTimerEvent(var1)
2048 end
2049 if event=="monitor_resize" then
2050 fullRefresh()
2051 end
2052 if event=="mouse_click" then
2053 if var1==1 then
2054 processClickEvent(terminalID,var2,var3)
2055 end
2056 end
2057 if event=="mouse_drag" then
2058 processDragEvent(var2,var3)
2059 end
2060 if event=="mouse_scroll" then
2061 processScrollEvent(var1,var2,var3)
2062 end
2063 if event=="terminate" then
2064 writeToLog("User terminated. Exiting.",2)
2065 logFile.writeLine("")
2066 logFile.flush()
2067 for sMonitor,data in pairs(monitors) do
2068 data["peripheral"].setBackgroundColor(colors.black)
2069 data["peripheral"].clear()
2070 end
2071 term.setBackgroundColor(colors.black)
2072 term.setTextColor(colors.white)
2073 term.clear()
2074 term.setCursorPos(1,1)
2075 running = false
2076 end
2077 if event=="easygui_interrupt" then
2078 running = false
2079 end
2080 if processEventFunc~=nil then
2081 success,msg = pcall(processEventFunc,event,var1,var2,var3,var4,var5)
2082 if success then
2083 writeToLog("Successfully called processEventFunc.",2)
2084 else
2085 writeToLog("There was an error calling processEventFunc. Msg: "..msg)
2086 end
2087 end
2088 end
2089end
2090
2091function processScrollEvent(direction,x,y)
2092 if terminalScreen~=nil then
2093 local s = x..":"..y
2094 local screenID = terminalScreen
2095
2096 local data = screens[screenID]["pixelMatrix"][s]
2097 if data~=nil then
2098 local elementType = data["elementType"]
2099 local ID = data["elementID"]
2100 local part = data["part"]
2101
2102 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2103 if direction==-1 then
2104 if dropDownMenus[ID]["selectionID"]~=1 then
2105 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2106 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]-1
2107 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2108 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2109 if success then
2110 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2111 else
2112 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2113 end
2114 end
2115 refresh()
2116 end
2117 else
2118 if dropDownMenus[ID]["selectionID"]~=table.getn(dropDownMenus[ID]["entries"]) then
2119 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of scroll event.",2)
2120 dropDownMenus[ID]["selectionID"] = dropDownMenus[ID]["selectionID"]+1
2121 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2122 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2123 if success then
2124 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2125 else
2126 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2127 end
2128 end
2129 refresh()
2130 end
2131 end
2132 end
2133
2134 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] and dropDownMenus[ID]["expanded"] and (string.match(part,"entry") or string.match(part,"scroll")) then
2135 if dropDownMenus[ID]["scrollPositionIndex"]~=nil then
2136 if direction==-1 then
2137 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2138 writeToLog("Scrolled up dropDownMenu "..ID.." because of scroll event.",2)
2139 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2140 refresh()
2141 end
2142 else
2143 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2144 writeToLog("Scrolled down dropDownMenu "..ID.." because of scroll event.",2)
2145 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2146 refresh()
2147 end
2148 end
2149 end
2150 end
2151
2152 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2153 if direction==1 then
2154 if sliders[ID]["value"]~=sliders[ID]["length"] then
2155 sliders[ID]["value"] = sliders[ID]["value"] + 1
2156 writeToLog("Incremented value of slider "..ID.." because of scroll event.",2)
2157 if sliders[ID]["onChangeFunction"]~=nil then
2158 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2159 if success then
2160 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2161 else
2162 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2163 end
2164 end
2165 refresh()
2166 end
2167 else
2168 if sliders[ID]["value"]~=1 then
2169 sliders[ID]["value"] = sliders[ID]["value"] - 1
2170 writeToLog("Decremented value of slider "..ID.." because of scroll event.",2)
2171 if sliders[ID]["onChangeFunction"]~=nil then
2172 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2173 if success then
2174 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2175 else
2176 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2177 end
2178 end
2179 refresh()
2180 end
2181 end
2182 end
2183 end
2184 end
2185end
2186
2187function processDragEvent(x,y)
2188 if terminalScreen~=nil then
2189 local s = x..":"..y
2190 local screenID = terminalScreen
2191
2192 local data = screens[screenID]["pixelMatrix"][s]
2193 if data~=nil then
2194 local elementType = data["elementType"]
2195 local ID = data["elementID"]
2196 local part = data["part"]
2197
2198 if elementType=="slider" and sliders[ID]["enabled"] and string.match(part,"bar") then
2199 processClickEvent(terminalID,x,y)
2200 end
2201 end
2202 end
2203end
2204
2205function processTimerEvent(timerID)
2206 writeToLog("Processing timerEvent with ID "..timerID.."...",2)
2207 if timerID==refreshTimerID then
2208 if refreshFunction~=nil then
2209 success,msg = pcall(refreshFunction)
2210 if success then
2211 writeToLog("Successfully called refresh function.",1)
2212 else
2213 writeToLog("There was an error calling the refresh function. Error message: "..msg,4)
2214 end
2215 end
2216 refresh()
2217 writeToLog("Restarting refresh timer.",2)
2218 refreshTimerID = os.startTimer(refreshRate)
2219 end
2220
2221 for name,data in pairs(dynamicTextBoxes) do
2222 if data["timerID"]==timerID then
2223 writeToLog("Processing timer of dynamicTextBox "..name..".",1)
2224 dynamicTextBoxes[name]["active"] = false
2225 dynamicTextBoxes[name]["timerID"] = nil
2226 if dynamicTextBoxes[name]["onInactiveFunction"]~=nil then
2227 success,msg = pcall(dynamicTextBoxes[name]["onInactiveFunction"],name,dynamicTextBoxes[name]["active"])
2228 if success then
2229 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..name..".",1)
2230 else
2231 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..name..". Error message: "..msg,4)
2232 end
2233 end
2234 refresh()
2235 end
2236 end
2237
2238 writeToLog("Done processing timerEvent with ID "..timerID..".",2)
2239end
2240
2241function processClickEvent(monitorName,x,y)
2242 writeToLog("Processing click event.",2)
2243 local monID
2244 for name,data in pairs(monitors) do
2245 if monitorName==data["networkID"] then
2246 monID = name
2247 break
2248 end
2249 if monitorName==data["side"] and data["networkID"]=="NONE" then
2250 monID = name
2251 break
2252 end
2253 end
2254 if (monitorName==terminalID and terminalScreen~=nil) or (monitors[monID]~=nil and monitors[monID]["screen"]~=nil) then
2255 local s = nil
2256 local screenID = nil
2257 if monitorName==terminalID then
2258 s = x..":"..y
2259 screenID = terminalScreen
2260 else
2261 s = x-monitors[monID]["offsetX"]..":"..y-monitors[monID]["offsetY"]
2262 screenID = monitors[monID]["screen"]
2263 end
2264
2265 local data = screens[screenID]["pixelMatrix"][s]
2266 if data~=nil then
2267 local elementType = data["elementType"]
2268 local ID = data["elementID"]
2269 local part = data["part"]
2270
2271 --button
2272 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="toggle" then
2273 dynamicTextBoxes[ID]["active"] = not dynamicTextBoxes[ID]["active"]
2274 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2275 if dynamicTextBoxes[ID]["active"] then
2276 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2277 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2278 if success then
2279 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2280 else
2281 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2282 end
2283 end
2284 end
2285 if not dynamicTextBoxes[ID]["active"] then
2286 if dynamicTextBoxes[ID]["onInactiveFunction"]~=nil then
2287 success,msg = pcall(dynamicTextBoxes[ID]["onInactiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2288 if success then
2289 writeToLog("Successfully called onInactiveFunction of dynamicTextBox "..ID..".",1)
2290 else
2291 writeToLog("There was an error calling the onInactiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2292 end
2293 end
2294 end
2295 refresh()
2296 end
2297 if elementType=="dynamicTextBox" and dynamicTextBoxes[ID]["enabled"] and dynamicTextBoxes[ID]["onClickMode"]=="flash" and not dynamicTextBoxes[ID]["active"] then
2298 dynamicTextBoxes[ID]["active"] = true
2299 writeToLog("Changed status of dynamicTextBox "..ID.."because of click event.",2)
2300 if dynamicTextBoxes[ID]["onActiveFunction"]~=nil then
2301 success,msg = pcall(dynamicTextBoxes[ID]["onActiveFunction"],ID,dynamicTextBoxes[ID]["active"])
2302 if success then
2303 writeToLog("Successfully called onActiveFunction of dynamicTextBox "..ID..".",1)
2304 else
2305 writeToLog("There was an error calling the onActiveFunction of dynamicTextBox "..ID..". Error message: "..msg,4)
2306 end
2307 end
2308 refresh()
2309 if dynamicTextBoxes[ID]["activeDuration"]~=nil then
2310 writeToLog("Starting timer of dynamicTextBox "..ID..".",1)
2311 dynamicTextBoxes[ID]["timerID"] = os.startTimer(dynamicTextBoxes[ID]["activeDuration"])
2312 else
2313 writeToLog("Even though mode of dynamicTextBox "..ID.." is 'flash', activeDuration is not defined!",2)
2314 dynamicTextBoxes[ID]["timerID"] = os.startTimer(0)
2315 end
2316 end
2317
2318 --slider
2319 if elementType=="slider" and sliders[ID]["enabled"] then
2320 if part=="incrementButton" then
2321 if sliders[ID]["value"]~=sliders[ID]["length"] then
2322 sliders[ID]["value"] = sliders[ID]["value"] + 1
2323 writeToLog("Incremented value of slider "..ID.." because of click event.",2)
2324 if sliders[ID]["onChangeFunction"]~=nil then
2325 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2326 if success then
2327 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2328 else
2329 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2330 end
2331 end
2332 refresh()
2333 end
2334 end
2335 if part=="decrementButton" then
2336 if sliders[ID]["value"]~=1 then
2337 sliders[ID]["value"] = sliders[ID]["value"] - 1
2338 writeToLog("Decremented value of slider "..ID.." because of click event.",2)
2339 if sliders[ID]["onChangeFunction"]~=nil then
2340 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2341 if success then
2342 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2343 else
2344 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2345 end
2346 end
2347 refresh()
2348 end
2349 end
2350 if string.match(part,"bar") then
2351 local index = tonumber(string.sub(part,5))
2352 if index~=sliders[ID]["value"] then
2353 sliders[ID]["value"] = index
2354 writeToLog("Changed value of slider "..ID.." because of click event.",2)
2355 if sliders[ID]["onChangeFunction"]~=nil then
2356 success,msg = pcall(sliders[ID]["onChangeFunction"],ID,sliders[ID]["value"])
2357 if success then
2358 writeToLog("Succesfully called onChangeFunction of slider "..ID..".",1)
2359 else
2360 writeToLog("There was an error calling the onChangeFunction of slider "..ID..". Error message: "..msg,4)
2361 end
2362 end
2363 refresh()
2364 end
2365 end
2366 end
2367
2368 --dropdownmenus
2369 if elementType=="dropDownMenu" and dropDownMenus[ID]["enabled"] then
2370 if part=="collapseButton" then
2371 dropDownMenus[ID]["expanded"] = false
2372 dropDownMenus[ID]["scrollPositionIndex"] = nil
2373 dropDownMenus[ID]["highlightID"] = nil
2374 writeToLog("Collapsed dropDownMenu "..ID.." because of click event.",2)
2375 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2376 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2377 if success then
2378 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2379 else
2380 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2381 end
2382 end
2383 refresh()
2384 end
2385 if (part=="expandButton" or part=="BG" or part=="text") and not dropDownMenus[ID]["expanded"] then
2386 dropDownMenus[ID]["expanded"] = true
2387 writeToLog("Expanded dropDownMenu "..ID.." because of click event.",2)
2388 if dropDownMenus[ID]["onExpandFunction"]~=nil then
2389 success,msg = pcall(dropDownMenus[ID]["onExpandFunction"],ID,dropDownMenus[ID]["expanded"])
2390 if success then
2391 writeToLog("Successfully called onExpandFunction of dropDownMenu "..ID..".",1)
2392 else
2393 writeToLog("There was an error calling the onExpandFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2394 end
2395 end
2396 refresh()
2397 end
2398 if part=="scrollUpButton" then
2399 if dropDownMenus[ID]["scrollPositionIndex"]~=1 then
2400 writeToLog("Scrolled up dropDownMenu "..ID.." because of click event.",2)
2401 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]-1
2402 refresh()
2403 end
2404 end
2405 if part=="scrollDownButton" then
2406 if dropDownMenus[ID]["scrollPositionIndex"]~=table.getn(dropDownMenus[ID]["entries"])-dropDownMenus[ID]["spaceY"]+1 then
2407 writeToLog("Scrolled down dropDownMenu "..ID.." because of click event.",2)
2408 dropDownMenus[ID]["scrollPositionIndex"] = dropDownMenus[ID]["scrollPositionIndex"]+1
2409 refresh()
2410 end
2411 end
2412 if string.match(part,"entry") then
2413 local index = tonumber(string.sub(part,7))
2414 if index==dropDownMenus[ID]["highlightID"] then
2415 dropDownMenus[ID]["selectionID"] = index
2416 dropDownMenus[ID]["highlightID"] = nil
2417 dropDownMenus[ID]["scrollPositionIndex"] = nil
2418 writeToLog("Changed selectionID of dropDownMenu "..ID.." because of click event.",2)
2419 dropDownMenus[ID]["expanded"] = false
2420 writeToLog("Collapsed dropDownMenu "..ID.." because of selection.",2)
2421 if dropDownMenus[ID]["onChangeFunction"]~=nil then
2422 success,msg = pcall(dropDownMenus[ID]["onChangeFunction"],ID,dropDownMenus[ID]["selectionID"])
2423 if success then
2424 writeToLog("Successfully called onChangeFunction of dropDownMenu "..ID..".",1)
2425 else
2426 writeToLog("There was an error calling onChangeFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2427 end
2428 end
2429
2430 if dropDownMenus[ID]["onCollapseFunction"]~=nil then
2431 success,msg = pcall(dropDownMenus[ID]["onCollapseFunction"],ID,dropDownMenus[ID]["expanded"])
2432 if success then
2433 writeToLog("Successfully called onCollapseFunction of dropDownMenu "..ID..".",1)
2434 else
2435 writeToLog("There was an error calling the onCollapseFunction of dropDownMenu "..ID..". Error message: "..msg,4)
2436 end
2437 end
2438 refresh()
2439 else
2440 if dropDownMenus[ID]["highlightID"]~=index then
2441 dropDownMenus[ID]["highlightID"] = index
2442 writeToLog("Changed highlightID of dropDownMenu "..ID.." because of click event.",2)
2443 refresh()
2444 end
2445 end
2446 end
2447 end
2448
2449 --navMenus
2450 if elementType=="navigationMenu" and navigationMenus[ID]["enabled"] then
2451 if string.match(part,"title") then
2452 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2453 navigationMenus[ID]["highlightIDs"] = nil
2454 writeToLog("Expanded navMenu "..ID.." because of click event.",2)
2455 refresh()
2456 end
2457 if string.match(part,"entry") then
2458 local s = string.sub(part,7)
2459 local level = string.sub(s,1,string.find(s,":")-1)
2460 local entry = string.sub(s,string.find(s,":")+1)
2461 if tonumber(level)==1 then
2462 if navigationMenus[ID]["menuArray"][tonumber(entry)]["submenu"]~=nil then
2463 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2464 local i = 1
2465 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2466 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2467 i = i + 1
2468 end
2469 writeToLog("Opened submenu on level 2 for navMenu "..ID..".",2)
2470 else
2471 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2472 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2473 navigationMenus[ID]["highlightIDs"] = {tonumber(entry)}
2474 if navigationMenus[ID]["onChangeFunction"]~=nil then
2475 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2476 if success then
2477 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2478 else
2479 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2480 end
2481 end
2482 navigationMenus[ID]["highlightIDs"] = nil
2483 end
2484 else
2485 array = navigationMenus[ID]["menuArray"]
2486
2487 for i=1,tonumber(level)-1 do
2488 array = array[navigationMenus[ID]["highlightIDs"][i]]["submenu"]
2489 end
2490
2491 if array[tonumber(entry)]["submenu"]~=nil then
2492 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2493 local i = 1
2494 while navigationMenus[ID]["highlightIDs"][tonumber(level)+i]~=nil do
2495 navigationMenus[ID]["highlightIDs"][tonumber(level)+i] = nil
2496 i = i + 1
2497 end
2498 writeToLog("Opened submenu on level "..(tonumber(level)+1).." for navMenu "..ID..".",2)
2499 else
2500 navigationMenus[ID]["expanded"] = not navigationMenus[ID]["expanded"]
2501 writeToLog("Collapsed navMenu "..ID.." because of click event.",2)
2502 navigationMenus[ID]["highlightIDs"][tonumber(level)] = tonumber(entry)
2503 if navigationMenus[ID]["onChangeFunction"]~=nil then
2504 success,msg = pcall(navigationMenus[ID]["onChangeFunction"],ID,navigationMenus[ID]["highlightIDs"])
2505 if success then
2506 writeToLog("Successfully called onChangeFunction of navMenu "..ID..".",1)
2507 else
2508 writeToLog("There was an error calling onChangeFunction of navMenu "..ID..". Error message: "..msg,4)
2509 end
2510 end
2511 navigationMenus[ID]["highlightIDs"] = nil
2512 end
2513 end
2514 refresh()
2515 end
2516 end
2517
2518 --colorpicker
2519 if elementType=="colorPicker" and colorPickers[ID]["enabled"] then
2520 if part~="border" then
2521 if colorPickers[ID]["selection"]~=part then
2522 colorPickers[ID]["selection"] = part
2523 writeToLog("Changed selection of colorPicker "..ID.." because of clickEvent.",2)
2524 refresh()
2525 if colorPickers[ID]["onChangeFunction"]~=nil then
2526 success,msg = pcall(colorPickers[ID]["onChangeFunction"],ID,colorPickers[ID]["selection"])
2527 if success then
2528 writeToLog("Successfully called onChangeFunction of colorPicker "..ID..".",1)
2529 else
2530 writeToLog("There was an error calling onChangeFunction of colorPicker "..ID..". Error message: "..msg,4)
2531 end
2532 end
2533 end
2534 end
2535 end
2536
2537 if processClickEventFunc~=nil then
2538 success,msg = pcall(processClickEventFunc,elementType,ID,part)
2539 if success then
2540 writeToLog("Successfully called processClickEventFunction.",1)
2541 else
2542 writeToLog("There was an error calling the processClickEventFunction. Error message: "..msg,4)
2543 end
2544 end
2545 end
2546 end
2547 writeToLog("Done processing click event.",2)
2548end
2549
2550--function to change any property from any element
2551function changeProperty(ID, propName, propValue)
2552 if elements[getType(ID)]~=nil then
2553 if elements[getType(ID)][ID]~=nil then
2554 elements[getType(ID)][ID][propName] = propValue
2555 writeToLog("Changed property of element "..ID..".",2)
2556 else
2557 writeToLog("Could not change property of element "..ID..". Element was not found. ",3)
2558 end
2559 end
2560end
2561
2562--function to get any property from any element
2563function getProperty(ID, propName)
2564 if elements[getType(ID)]~=nil then
2565 if elements[getType(ID)][ID]~=nil then
2566 return elements[getType(ID)][ID][propName]
2567 end
2568 end
2569end
2570
2571function getType(elementID)
2572 for name,data in pairs(dynamicTextBoxes) do
2573 if elementID==name then
2574 return "dynTextBox"
2575 end
2576 end
2577
2578 for name,data in pairs(sliders) do
2579 if elementID==name then
2580 return "slider"
2581 end
2582 end
2583
2584 for name,data in pairs(dropDownMenus) do
2585 if elementID==name then
2586 return "dropDownMenu"
2587 end
2588 end
2589
2590 for name,data in pairs(navigationMenus) do
2591 if elementID==name then
2592 return "navMenu"
2593 end
2594 end
2595
2596 for name,data in pairs(colorPickers) do
2597 if elementID==name then
2598 return "colorPicker"
2599 end
2600 end
2601
2602 for name,data in pairs(progressBars) do
2603 if elementID==name then
2604 return "progressBar"
2605 end
2606 end
2607
2608 for name,data in pairs(coordinateSystems) do
2609 if elementID==name then
2610 return "coordsSystem"
2611 end
2612 end
2613
2614 for name,data in pairs(pictures) do
2615 if elementID==name then
2616 return "picture"
2617 end
2618 end
2619
2620 return ""
2621end
2622
2623--DynamicTextBoxes from here
2624--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
2625function addDynamicTextBox(id, content)
2626 if trackID(id) then
2627 dynamicTextBoxes[id] = {}
2628 dynamicTextBoxes[id]["content"] = content
2629 dynamicTextBoxes[id]["visible"] = true
2630 dynamicTextBoxes[id]["enabled"] = true
2631 writeToLog("Added dynamicTextBox "..id..".",2)
2632 else
2633 writeToLog("Did not add dynamicTextBox because of ID conflict.",3)
2634 end
2635end
2636
2637--internal function used to draw a dynamic text box on a monitor
2638function writeDynamicTextBoxToPixelMatrix(screenID,dynamicTextBoxID,x,y)
2639 local data = dynamicTextBoxes[dynamicTextBoxID]
2640
2641 local content
2642 local textLines = {}
2643 local nTextLines
2644 local textColor
2645 local BGColor
2646 local borderColor
2647 local borderThickness
2648 local textAlignmentHorizontal
2649 local textAlignmentVertical
2650
2651 --standard value for horizontal alignment is center
2652 if data["textAlignmentHorizontal"]~=nil then
2653 textAlignmentHorizontal = data["textAlignmentHorizontal"]
2654 else
2655 textAlignmentHorizontal = "center"
2656 end
2657
2658 --standard value for vertical alignment is center
2659 if data["textAlignmentVertical"]~=nil then
2660 textAlignmentVertical = data["textAlignmentVertical"]
2661 else
2662 textAlignmentVertical = "center"
2663 end
2664
2665 --if no borderThickness is specified, assign the variable a zero value
2666 if data["borderThickness"]~=nil then
2667 borderThickness = data["borderThickness"]
2668 else
2669 borderThickness = 0
2670 end
2671
2672 --take care of all of the colors
2673 --if the button is active, colors might be different
2674 if data["active"] then
2675 if data["activeContent"]~=nil then
2676 content = data["activeContent"]
2677 else
2678 content = data["content"]
2679 end
2680 if data["activeTextColor"]~=nil then
2681 textColor = data["activeTextColor"]
2682 else
2683 textColor = data["textColor"]
2684 end
2685 if data["activeBGColor"]~=nil then
2686 BGColor = data["activeBGColor"]
2687 else
2688 BGColor = data["BGColor"]
2689 end
2690 if data["activeBorderColor"]~=nil then
2691 borderColor = data["activeBorderColor"]
2692 else
2693 borderColor = data["borderColor"]
2694 end
2695 else
2696 content = data["content"]
2697 textColor = data["textColor"]
2698 BGColor = data["BGColor"]
2699 borderColor = data["borderColor"]
2700 end
2701
2702 --if no colors are specified, use default colors of the corresponding screen
2703 if BGColor==nil then
2704 BGColor = screens[screenID]["defaultBGColor"]
2705 end
2706 if textColor==nil then
2707 textColor = screens[screenID]["defaultTextColor"]
2708 end
2709
2710 --if no bordercolor is specified, use the background color
2711 if borderColor==nil then
2712 borderColor = BGColor
2713 end
2714
2715 --replace variable placeholder with values
2716 if data["variables"]~=nil then
2717 for name, variableData in pairs(data["variables"]) do
2718 if data["variables"][name]~=nil then
2719 if type(data["variables"][name])=="function" then
2720 success,text = pcall(data["variables"][name],dynamicTextBoxID,name)
2721 if success then
2722 content = string.gsub(content,"$"..name,text)
2723 else
2724 writeToLog("There was an error retrieving variable "..name.." for dynamicTextBox "..dynamicTextBoxID..". Error message: "..text,4)
2725 end
2726 else if type(data["variables"][name])=="string" or type(data["variables"][name])=="number" then
2727 content = string.gsub(content,"$"..name,data["variables"][name])
2728 end end
2729 end
2730 end
2731 end
2732
2733 local maxX
2734 local maxY
2735
2736 if data["width"]~=nil then
2737 --if a width is specified the following variable is the maxX value
2738 maxX = x + data["width"] - 1
2739 --check if the content fits in one line with the specified width
2740 if string.len(content)<=(data["width"] - borderThickness*2) then
2741 textLines[1] = content
2742 nTextLines = 1
2743 end
2744 --if it does not fit, text will be split down below
2745 else
2746 --check if it fits in one line, assuming maxX is the monitors sizeX
2747 if string.len(content)<=(screens[screenID]["sizeX"]-x+1-(borderThickness*2)) then
2748 textLines[1] = content
2749 nTextLines = 1
2750 maxX = x + string.len(content) + borderThickness*2 - 1
2751 else
2752 --if it does not fit, text will be split down below
2753 maxX = screens[screenID]["sizeX"]
2754 end
2755 end
2756
2757 --variable used to determine the space for text on the dynamicTextBox
2758 local spaceX = maxX - x + 1 - borderThickness*2
2759
2760 --split text into lines
2761 if nTextLines~=1 then
2762 local words = {}
2763 --find spaces in the content string and use string.sub accordingly to create a list of words only
2764 local index = string.find(content," ")
2765 if index~=nil then
2766 repeat
2767 --insert the word into the table
2768 table.insert(words,string.sub(content,1,index-1))
2769 --remove the content that is already dealt with
2770 content = string.sub(content,index+1)
2771 index = string.find(content," ")
2772 until index==nil
2773 table.insert(words,content)
2774 else
2775 --in this case the content is one word alone
2776 table.insert(words,content)
2777 end
2778
2779 --create lines out of the words
2780 local sBuffer = ""
2781 for i,word in ipairs(words) do
2782 --the line is complete under three conditions: buffer not empty, current word added would be too long, current word is not longer than spaceX
2783 --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
2784 --if the current word is longer than spaceX anyway, it can start in the current line and break subsequently
2785 if sBuffer~="" and ((string.len(sBuffer.." "..word)>spaceX and string.len(word)<=spaceX) or string.len(sBuffer)>=spaceX-1) then
2786 table.insert(textLines,sBuffer)
2787 sBuffer = ""
2788 end
2789
2790 --split down too long words
2791 while string.len(word)>spaceX do
2792 if sBuffer == "" then
2793 --if the buffer is empty, simply insert the first 'spaceX' letters of the word
2794 table.insert(textLines,string.sub(word,1,spaceX))
2795 word = string.sub(word,spaceX+1)
2796 sBuffer = ""
2797 else
2798 --otherwise, add as many letters as still fit in the line (spaceX-lengthOfBuffer-space)
2799 table.insert(textLines,sBuffer.." "..string.sub(word,1,spaceX-string.len(sBuffer)-1))
2800 word = string.sub(word,spaceX-string.len(sBuffer)-1+1)
2801 sBuffer = ""
2802 end
2803 end
2804
2805 --add the word to the buffer accordingly
2806 if sBuffer=="" then
2807 sBuffer = word
2808 else
2809 sBuffer = sBuffer.." "..word
2810 end
2811 end
2812
2813 --there can be one bit left at the end if it was a too long word
2814 if sBuffer~="" then
2815 table.insert(textLines,sBuffer)
2816 end
2817
2818 nTextLines = table.getn(textLines)
2819 end
2820
2821 if data["height"]~=nil then
2822 --if a height is specified, calculate maxY in the following variable
2823 maxY = y + data["height"] - 1
2824 --check if the lines fit with the given height
2825 if nTextLines>(data["height"] - borderThickness*2) then
2826 --in this case they don't, therefore use as many lines as there is space
2827 nTextLines = data["height"] - borderThickness*2
2828 end
2829 else
2830 --no height is specified therefore calculate maxY with as many lines as needed
2831 maxY = y + nTextLines + borderThickness*2 - 1
2832 --check if maxY is now bigger than the actual monitor's maxY
2833 if maxY>screens[screenID]["sizeY"] then
2834 --in this case it is bigger therefore maxY needs to be adjusted as well as the number of textLines
2835 maxY = screens[screenID]["sizeY"]
2836 nTextLines = maxY - y + 1 - borderThickness*2
2837 end
2838 end
2839
2840 --calculate the space for the text in y direction to be used later on
2841 local spaceY = maxY - y + 1 - borderThickness*2
2842
2843 --start drawing
2844 --border
2845 for currentOffset=0,borderThickness-1 do
2846 --this draws two horizontal lines
2847 for currentX=(x+currentOffset),(maxX-currentOffset) do
2848 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2849 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2850 end
2851
2852 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
2853 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
2854 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2855 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dynamicTextBoxID,"dynamicTextBox","border")
2856 end
2857 end
2858
2859 --draw the BGColor, offset by the borderThickness
2860 for currentX=(x+borderThickness),(maxX-borderThickness) do
2861 for currentY=(y+borderThickness),(maxY-borderThickness) do
2862 writeToPixelMatrix(screenID," ",currentX,currentY,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","BG")
2863 end
2864 end
2865
2866 --draw the text
2867 --calculate vertical offset
2868 local startOffsetY
2869 if textAlignmentVertical=="center" then
2870 --if vertical alignment is center, calculate the corresponding offset
2871 startOffsetY = math.floor((spaceY-nTextLines)/2)
2872 else
2873 if textAlignmentVertical=="top" then
2874 --no offset for top alignment
2875 startOffsetY = 0
2876 else
2877 if textAlignmentVertical=="bottom" then
2878 --calculate offsetY if alignment is bottom
2879 startOffsetY = spaceY - nTextLines
2880 end
2881 end
2882 end
2883
2884 local startOffsetX = {}
2885 --deal with horizontal alignment, calculate an offset for each line
2886 if textAlignmentHorizontal=="right" then
2887 for i,line in ipairs(textLines) do
2888 --calculate number for right alignment
2889 startOffsetX[i] = spaceX-string.len(line)
2890 end
2891 else
2892 if textAlignmentHorizontal=="center" then
2893 for i,line in ipairs(textLines) do
2894 --calculate number for center horizontal alignment
2895 startOffsetX[i] = math.floor((spaceX-string.len(line))/2)
2896 end
2897 else
2898 for i,line in ipairs(textLines) do
2899 --no offset needed for left alignment
2900 startOffsetX[i] = 0
2901 end
2902 end
2903 end
2904
2905 --write text, offset by borderThickness
2906 for i=1,nTextLines do
2907 writeToPixelMatrix(screenID,textLines[i],x+borderThickness+startOffsetX[i],y+borderThickness+startOffsetY+i-1,textColor,BGColor,dynamicTextBoxID,"dynamicTextBox","text")
2908 end
2909end
2910
2911--Sliders from here
2912--Sliders all properties: length, value, broadness, orientation, pixelsPerUnit, color, colorsArray, textPosition, textMargin, BGColor, borderColor, onChangeFunction, borderThickness, visible, enabled, mode, changeButtons
2913function addSlider(id,length, value)
2914 if trackID(id) then
2915 sliders[id] = {}
2916 sliders[id]["length"] = length
2917 sliders[id]["value"] = value
2918 sliders[id]["visible"] = true
2919 sliders[id]["enabled"] = true
2920 writeToLog("Added slider "..id..".",2)
2921 else
2922 writeToLog("Did not add slider because of ID conflict.",3)
2923 end
2924end
2925
2926--function which draws a slider in the pixel matrix
2927function writeSliderToPixelMatrix(screenID,sliderID,x,y)
2928 local data = sliders[sliderID]
2929
2930 local length = data["length"]
2931 local value = math.floor(tonumber(data["value"]))
2932 local broadness
2933 local orientation
2934 local pixelsPerUnit
2935 local color
2936 local colorsArray
2937 local textPosition = data["textPosition"]
2938 local textMargin
2939 local BGColor
2940 local borderColor
2941 local borderThickness
2942 local mode
2943 local changeButtons
2944
2945 --take care of all variable defaults
2946 if data["broadness"]~=nil then
2947 broadness = data["broadness"]
2948 else
2949 broadness = 1
2950 end
2951
2952 if data["orientation"]~=nil then
2953 orientation = data["orientation"]
2954 else
2955 orientation = "left-right"
2956 end
2957
2958 if data["pixelsPerUnit"]~=nil then
2959 pixelsPerUnit = data["pixelsPerUnit"]
2960 else
2961 pixelsPerUnit = 1
2962 end
2963
2964 if data["color"]~=nil then
2965 color = data["color"]
2966 else
2967 color = screens[screenID]["defaultTextColor"]
2968 end
2969
2970 if data["colorsArray"]~=nil then
2971 if data["colorsArray"][value]~=nil then
2972 color = data["colorsArray"][value]
2973 end
2974 end
2975
2976 if data["textMargin"]~=nil then
2977 textMargin = data["textMargin"]
2978 else
2979 textMargin = 0
2980 end
2981
2982 if data["BGColor"]~=nil then
2983 BGColor = data["BGColor"]
2984 else
2985 BGColor = screens[screenID]["defaultBGColor"]
2986 end
2987
2988 if data["borderColor"]~=nil then
2989 borderColor = data["borderColor"]
2990 else
2991 borderColor = BGColor
2992 end
2993
2994 if data["borderThickness"]~=nil then
2995 borderThickness = data["borderThickness"]
2996 else
2997 borderThickness = 0
2998 end
2999
3000 if data["mode"]~=nil then
3001 mode = data["mode"]
3002 else
3003 mode = "fill"
3004 end
3005
3006 changeButtons = data["changeButtons"]
3007
3008 local maxX
3009 local maxY
3010
3011 --calculate maxX and maxY based on the orientation of slider
3012 if orientation=="left-right" or orientation=="right-left" then
3013 maxX = x + borderThickness*2 + length*pixelsPerUnit - 1
3014 maxY = y + borderThickness*2 + broadness - 1
3015 else
3016 maxX = x + borderThickness*2 + broadness - 1
3017 maxY = y + borderThickness*2 + length*pixelsPerUnit - 1
3018 end
3019
3020 --start drawing
3021 --border
3022 for currentOffset=0,borderThickness-1 do
3023 --this draws two horizontal lines
3024 for currentX=(x+currentOffset),(maxX-currentOffset) do
3025 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,sliderID,"slider","border")
3026 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,sliderID,"slider","border")
3027 end
3028
3029 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3030 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3031 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3032 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,sliderID,"slider","border")
3033 end
3034 end
3035
3036 --draw bar case horizontal
3037 if orientation=="left-right" or orientation=="right-left" then
3038 --this makes things easier
3039 local s = ""
3040 for i=1,pixelsPerUnit do
3041 s = s.." "
3042 end
3043 --loop for x coordinate (length)
3044 for i=1,length do
3045 --change color according to slider value
3046 --check mode
3047 local currentColor
3048 if mode=="fill" then
3049 if i<=value then
3050 currentColor = color
3051 else
3052 currentColor = BGColor
3053 end
3054 end
3055 if mode=="value" then
3056 if i==value then
3057 currentColor = color
3058 else
3059 currentColor = BGColor
3060 end
3061 end
3062 --loop for y coordinate (broadness)
3063 for currentY=y+borderThickness,maxY-borderThickness do
3064 --take pixelsPerUnit into account for calculations
3065 if orientation=="left-right" then
3066 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3067 end
3068 if orientation=="right-left" then
3069 writeToPixelMatrix(screenID,s,maxX-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit,currentY,currentColor,currentColor,sliderID,"slider","bar:"..i)
3070 end
3071 end
3072 end
3073 else
3074 --this makes things easier
3075 local s = ""
3076 for i=1,broadness do
3077 s = s.." "
3078 end
3079 --draw bar case vertical
3080 --loop for y coordinate (length)
3081 for i=1,length do
3082 local currentColor
3083 if mode=="fill" then
3084 if i<=value then
3085 currentColor = color
3086 else
3087 currentColor = BGColor
3088 end
3089 end
3090 if mode=="value" then
3091 if i==value then
3092 currentColor = color
3093 else
3094 currentColor = BGColor
3095 end
3096 end
3097 --loop for x coordinate (broadness)
3098 for j=1,pixelsPerUnit do
3099 if orientation=="top-bottom" then
3100 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3101 end
3102 if orientation=="bottom-top" then
3103 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-pixelsPerUnit+1-(i-1)*pixelsPerUnit+j-1,currentColor,currentColor,sliderID,"slider","bar:"..i)
3104 end
3105 end
3106 end
3107 end
3108
3109 --this fixes rounding issue
3110 value = tostring(value)
3111 --draw text
3112 if textPosition~=nil then
3113 --calculations to center the text
3114 if textPosition=="right" then
3115 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3116 end
3117 if textPosition=="left" then
3118 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3119 end
3120 if textPosition=="top" then
3121 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3122 end
3123 if textPosition=="bottom" then
3124 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],sliderID,"slider","value")
3125 end
3126 end
3127
3128 --if defined, draws an increment and decrement button according to slider orientation
3129 if changeButtons~=nil then
3130 if orientation=="left-right" then
3131 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3132 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3133 end
3134 if orientation=="right-left" then
3135 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),maxX+1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3136 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x-1,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3137 end
3138 if orientation=="bottom-top" then
3139 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3140 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3141 end
3142 if orientation=="top-bottom" then
3143 writeToPixelMatrix(screenID,string.sub(changeButtons,2,2),x+math.floor((maxX-x+1-1)/2),y-1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","decrementButton")
3144 writeToPixelMatrix(screenID,string.sub(changeButtons,1,1),x+math.floor((maxX-x+1-1)/2),maxY+1,color,screens[screenID]["defaultBGColor"],sliderID,"slider","incrementButton")
3145 end
3146 end
3147end
3148
3149--Dropdownmenus from here
3150--All properties: entries,width,expandedMaxHeight, textColor, BGColor, borderColor, onChangeFunction, onExpandFunction, onCollapseFunction, highlightTextColor, highlightBGColor, borderThickness, expanded, visible, enabled,selectionID,scrollPositionIndex,highlightID,buttonsColor,buttonsBGColor
3151function addDropDownMenu(id,entries,selectionID)
3152 if trackID(id) then
3153 dropDownMenus[id] = {}
3154 dropDownMenus[id]["entries"] = entries
3155 dropDownMenus[id]["selectionID"] = selectionID
3156 dropDownMenus[id]["visible"] = true
3157 dropDownMenus[id]["enabled"] = true
3158 dropDownMenus[id]["expanded"] = false
3159 writeToLog("Added dropDownMenu "..id..".",2)
3160 else
3161 writeToLog("Did not add dropDownMenu because of ID conflict.",3)
3162 end
3163end
3164
3165function writeDropDownMenuToPixelMatrix(screenID,dropDownMenuID,x,y)
3166 local data = dropDownMenus[dropDownMenuID]
3167
3168 local entries = data["entries"]
3169 local selectionID = data["selectionID"]
3170 local expanded = data["expanded"]
3171 local width
3172 local textColor
3173 local BGColor
3174 local borderColor
3175 local borderThickness
3176 local highlightTextColor
3177 local highlightBGColor
3178 local highlightID = data["highlightID"]
3179 local scrollPositionIndex = data["scrollPositionIndex"]
3180 local buttonsColor
3181 local buttonsBGColor
3182
3183 --take care of the colors and set other default values
3184 if data["textColor"]~=nil then
3185 textColor = data["textColor"]
3186 else
3187 textColor = screens[screenID]["defaultTextColor"]
3188 end
3189
3190 if data["BGColor"]~=nil then
3191 BGColor = data["BGColor"]
3192 else
3193 BGColor = screens[screenID]["defaultBGColor"]
3194 end
3195
3196 if data["borderColor"]~=nil then
3197 borderColor = data["borderColor"]
3198 else
3199 borderColor = BGColor
3200 end
3201
3202 if data["borderThickness"]~=nil then
3203 borderThickness = data["borderThickness"]
3204 else
3205 borderThickness = 0
3206 end
3207
3208 if data["highlightTextColor"]~=nil then
3209 highlightTextColor = data["highlightTextColor"]
3210 else
3211 highlightTextColor = textColor
3212 end
3213
3214 if data["highlightBGColor"]~=nil then
3215 highlightBGColor = data["highlightBGColor"]
3216 else
3217 highlightBGColor = BGColor
3218 end
3219
3220 if data["buttonsColor"]~=nil then
3221 buttonsColor = data["buttonsColor"]
3222 else
3223 buttonsColor = textColor
3224 end
3225
3226 if data["buttonsBGColor"]~=nil then
3227 buttonsBGColor = data["buttonsBGColor"]
3228 else
3229 buttonsBGColor = BGColor
3230 end
3231
3232 --calculate greatestTextLength to later define a width if its not specified
3233 local greatestTextLength = 0
3234 for name,entry in pairs(entries) do
3235 if string.len(entry)>greatestTextLength then
3236 greatestTextLength = string.len(entry)
3237 end
3238 end
3239
3240 --fill this array with entries and manipulate later
3241 local shortenedEntries = {}
3242 for i,entry in ipairs(entries) do
3243 shortenedEntries[i] = entry
3244 end
3245 local nEntries = table.getn(entries)
3246 if data["width"]~=nil then
3247 width = data["width"]
3248 --two pixel space: one for v and one for a space (or space + scrollbar)
3249 if greatestTextLength>width-borderThickness*2-2 then
3250 --shorten entries if necessary
3251 for i,entry in ipairs(entries) do
3252 shortenedEntries[i] = string.sub(entry,1,width-borderThickness*2-2)
3253 end
3254 end
3255 else
3256 if greatestTextLength>screens[screenID]["sizeX"]-x-borderThickness*2+1-2 then
3257 --shorten entries if necessary
3258 for i,entry in ipairs(entries) do
3259 shortenedEntries[i] = string.sub(entry,1,screens[screenID]["sizeX"]-x-borderThickness*2+1-2)
3260 end
3261 width = screens[screenID]["sizeX"]-x+1
3262 else
3263 --as wide as it needs
3264 width = borderThickness*2+greatestTextLength + 2
3265 end
3266 end
3267
3268 local maxX = x + width - 1
3269
3270 --draw collapsed menu
3271 if not expanded then
3272 local maxY = y + borderThickness*2
3273 --start drawing
3274 --border
3275 for currentOffset=0,borderThickness-1 do
3276 --this draws two horizontal lines
3277 for currentX=(x+currentOffset),(maxX-currentOffset) do
3278 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3279 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3280 end
3281
3282 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3283 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3284 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3285 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3286 end
3287 end
3288
3289 --draw the BGColor, offset by the borderThickness
3290 for currentX=(x+borderThickness),(maxX-borderThickness) do
3291 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3292 end
3293
3294 --draw text
3295 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3296
3297 --draw v (expandbutton)
3298 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","expandButton")
3299 else
3300 --determine if a scrollbar is necessary
3301 local scrollBar
3302 local maxY
3303 if highlightID ==nil then
3304 highlightID = selectionID
3305 end
3306 dropDownMenus[dropDownMenuID]["highlightID"] = highlightID
3307 if data["expandedMaxHeight"]~=nil then
3308 local expandedMaxHeight = data["expandedMaxHeight"]
3309 --check if all entries fit with the given height
3310 if borderThickness*2 + 1 + nEntries > expandedMaxHeight then
3311 maxY = y+expandedMaxHeight-1
3312 scrollBar = true
3313 else
3314 --as wide as it needs
3315 maxY = y + borderThickness*2 + 1 + nEntries -1
3316 scrollBar = false
3317 end
3318 else
3319 --with no specified height, check if the full list would be greater than screen size
3320 if y + borderThickness*2 +1 + nEntries - 1>screens[screenID]["sizeY"] then
3321 maxY = screens[screenID]["sizeY"]
3322 scrollBar = true
3323 else
3324 maxY = y + borderThickness*2 + 1 + nEntries - 1
3325 scrollBar = false
3326 end
3327 end
3328
3329 --draw the BGColor, offset by the borderThickness
3330 for currentX=(x+borderThickness),(maxX-borderThickness) do
3331 writeToPixelMatrix(screenID," ",currentX,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","BG")
3332 end
3333
3334 --draw text
3335 writeToPixelMatrix(screenID,shortenedEntries[selectionID],x+borderThickness,y+borderThickness,textColor,BGColor,dropDownMenuID,"dropDownMenu","text")
3336
3337 --draw v
3338 writeToPixelMatrix(screenID,"v",maxX-borderThickness,y+borderThickness,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","collapseButton")
3339
3340 --draw list without scrollbar
3341 if not scrollBar then
3342 --entries need to be spaced in order to fill the whole line
3343 local spacedEntries = {}
3344 for i,entry in ipairs(shortenedEntries) do
3345 local s = ""
3346 for j=1,width-borderThickness*2-string.len(entry) do
3347 s = s.." "
3348 end
3349 spacedEntries[i] = entry..s
3350 end
3351 for i,entry in ipairs(spacedEntries) do
3352 --change color accordingly
3353 local currentTextColor
3354 local currentBGColor
3355 if i==highlightID then
3356 currentTextColor = highlightTextColor
3357 currentBGColor = highlightBGColor
3358 else
3359 currentTextColor = textColor
3360 currentBGColor = BGColor
3361 end
3362 writeToPixelMatrix(screenID,entry,x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i)
3363 end
3364 else
3365 local spacedEntries = {}
3366 for i,entry in ipairs(shortenedEntries) do
3367 local s = ""
3368 --this time -1 because of scrollbar
3369 for j=1,width-borderThickness*2-string.len(entry)-1 do
3370 s = s.." "
3371 end
3372 spacedEntries[i] = entry..s
3373 end
3374 local spaceY = maxY-y+1-borderThickness*2-1
3375 dropDownMenus[dropDownMenuID]["spaceY"] = spaceY
3376 --set scrollposition if menu was just opened
3377 if scrollPositionIndex==nil then
3378 --make sure not to overrun
3379 if selectionID>nEntries-spaceY then
3380 scrollPositionIndex = nEntries-spaceY+1
3381 else
3382 scrollPositionIndex = selectionID
3383 end
3384
3385 --set for next time
3386 dropDownMenus[dropDownMenuID]["scrollPositionIndex"] = scrollPositionIndex
3387 end
3388
3389 for i=1,spaceY do
3390 local currentTextColor
3391 local currentBGColor
3392 if i+scrollPositionIndex-1==highlightID then
3393 currentTextColor = highlightTextColor
3394 currentBGColor = highlightBGColor
3395 else
3396 currentTextColor = textColor
3397 currentBGColor = BGColor
3398 end
3399
3400 --this is a workaround for a very special case where one dropDownMenu is displayed on different screens with different space
3401 if spacedEntries[i+scrollPositionIndex-1]==nil then
3402 maxY = y+borderThickness+i
3403 break
3404 else
3405 writeToPixelMatrix(screenID,spacedEntries[i+scrollPositionIndex-1],x+borderThickness,y+borderThickness+i,currentTextColor,currentBGColor,dropDownMenuID,"dropDownMenu","entry:"..i+scrollPositionIndex-1)
3406 end
3407 end
3408
3409 --draw scrollbar buttons and bg
3410 local scrollBarX = maxX-1
3411 for currentY=y+borderThickness+1,maxY-1 do
3412 if currentY==y+borderThickness+1 then
3413 writeToPixelMatrix(screenID,"^",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollUpButton")
3414 else if currentY==maxY-1 then
3415 writeToPixelMatrix(screenID,"v",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollDownButton")
3416 else
3417 writeToPixelMatrix(screenID," ",scrollBarX,currentY,buttonsColor,buttonsBGColor,dropDownMenuID,"dropDownMenu","scrollBarBG")
3418 end
3419 end
3420 end
3421 end
3422
3423 --draw border
3424 for currentOffset=0,borderThickness-1 do
3425 --this draws two horizontal lines
3426 for currentX=(x+currentOffset),(maxX-currentOffset) do
3427 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3428 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3429 end
3430
3431 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3432 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3433 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3434 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,textColor,borderColor,dropDownMenuID,"dropDownMenu","border")
3435 end
3436 end
3437 end
3438end
3439
3440--navMenus from here
3441-- 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
3442function addNavigationMenu(id,title,menuArray)
3443 if trackID(id) then
3444 navigationMenus[id] = {}
3445 navigationMenus[id]["title"] = title
3446 navigationMenus[id]["menuArray"] = menuArray
3447 navigationMenus[id]["visible"] = true
3448 navigationMenus[id]["enabled"] = true
3449 navigationMenus[id]["expanded"] = false
3450 navigationMenus[id]["highlightIDs"] = nil
3451 writeToLog("Added navMenu "..id..".",2)
3452 else
3453 writeToLog("Did not add navMenu because of ID conflict.",3)
3454 end
3455end
3456
3457function writeNavigationMenuToPixelMatrix(screenID,navigationMenuID,x,y)
3458 local data = navigationMenus[navigationMenuID]
3459
3460 local title = data["title"]
3461 local menuArray = data["menuArray"]
3462 local expanded = data["expanded"]
3463 local entryWidth = data["entryWidth"]
3464 local entryHeight
3465 local titleTextColor
3466 local titleBGColor
3467 local titleTextColorExpanded
3468 local titleBGColorExpanded
3469 local entryTextColor
3470 local entryBGColor
3471 local borderColor
3472 local borderThickness
3473 local spaceBetweenEntries
3474 local highlightIDs = data["highlightIDs"]
3475 local highlightTextColor
3476 local highlightBGColor
3477 local expanded = data["expanded"]
3478 local textAlignmentHorizontal
3479 local textAlignmentVertical
3480
3481 --take care of the colors and set other default values
3482 if data["entryTextColor"]~=nil then
3483 entryTextColor = data["entryTextColor"]
3484 else
3485 entryTextColor = screens[screenID]["defaultTextColor"]
3486 end
3487
3488 if data["entryBGColor"]~=nil then
3489 entryBGColor = data["entryBGColor"]
3490 else
3491 entryBGColor = screens[screenID]["defaultBGColor"]
3492 end
3493
3494 if data["titleTextColor"]~=nil then
3495 titleTextColor = data["titleTextColor"]
3496 else
3497 titleTextColor = screens[screenID]["defaultTextColor"]
3498 end
3499
3500 if data["titleBGColor"]~=nil then
3501 titleBGColor = data["titleBGColor"]
3502 else
3503 titleBGColor = screens[screenID]["defaultBGColor"]
3504 end
3505
3506 if data["titleTextColorExpanded"]~=nil then
3507 titleTextColorExpanded = data["titleTextColorExpanded"]
3508 else
3509 titleTextColorExpanded = titleTextColor
3510 end
3511
3512 if data["titleBGColorExpanded"]~=nil then
3513 titleBGColorExpanded = data["titleBGColorExpanded"]
3514 else
3515 titleBGColorExpanded = titleBGColor
3516 end
3517
3518 if data["borderColor"]~=nil then
3519 borderColor = data["borderColor"]
3520 else
3521 borderColor = screens[screenID]["defaultBGColor"]
3522 end
3523
3524 if data["borderThickness"]~=nil then
3525 borderThickness = data["borderThickness"]
3526 else
3527 borderThickness = 0
3528 end
3529
3530 if data["spaceBetweenEntries"]~=nil then
3531 spaceBetweenEntries = data["spaceBetweenEntries"]
3532 else
3533 spaceBetweenEntries = 0
3534 end
3535
3536 if data["highlightTextColor"]~=nil then
3537 highlightTextColor = data["highlightTextColor"]
3538 else
3539 highlightTextColor = entryTextColor
3540 end
3541
3542 if data["highlightBGColor"]~=nil then
3543 highlightBGColor = data["highlightBGColor"]
3544 else
3545 highlightBGColor = entryBGColor
3546 end
3547
3548 if data["entryHeight"]~=nil then
3549 entryHeight = data["entryHeight"]
3550 else
3551 entryHeight = 1
3552 end
3553
3554 --standard value for horizontal alignment is center
3555 if data["textAlignmentHorizontal"]~=nil then
3556 textAlignmentHorizontal = data["textAlignmentHorizontal"]
3557 else
3558 textAlignmentHorizontal = "center"
3559 end
3560
3561 --standard value for vertical alignment is center
3562 if data["textAlignmentVertical"]~=nil then
3563 textAlignmentVertical = data["textAlignmentVertical"]
3564 else
3565 textAlignmentVertical = "center"
3566 end
3567
3568 local greatestRootTextLength = string.len(title)
3569 local rootEntryCount = 0
3570 for name,entry in pairs(menuArray) do
3571 rootEntryCount = rootEntryCount + 1
3572 if string.len(entry["text"])>greatestRootTextLength then
3573 greatestRootTextLength = string.len(entry["text"])
3574 end
3575 end
3576
3577 --fill this array with entries and manipulate later
3578 local nRootEntries = 0
3579 local shortenedEntries = {}
3580 for i,entry in ipairs(menuArray) do
3581 nRootEntries = nRootEntries + 1
3582 shortenedEntries[i] = entry
3583 end
3584
3585 local rootMaxX
3586 if entryWidth~=nil then
3587 rootMaxX = x+borderThickness*2+entryWidth-1
3588 --shorten text
3589 if greatestRootTextLength>entryWidth then
3590 title = string.sub(title,1,entryWidth)
3591 for i,entry in ipairs(shortenedEntries) do
3592 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3593 end
3594 end
3595 else
3596 rootMaxX = x+borderThickness*2+greatestRootTextLength-1
3597 entryWidth = greatestRootTextLength
3598 end
3599
3600 local currentTextColor
3601 local currentBGColor
3602
3603 if expanded then
3604 currentTextColor = titleTextColorExpanded
3605 currentBGColor = titleBGColorExpanded
3606 else
3607 currentTextColor = titleTextColor
3608 currentBGColor = titleBGColor
3609 end
3610
3611 --titleBG
3612 for currentX=(x+borderThickness),(rootMaxX-borderThickness) do
3613 for currentY=(y+borderThickness),(y+borderThickness+entryHeight-1) do
3614 writeToPixelMatrix(screenID," ",currentX,currentY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","titleBG")
3615 end
3616 end
3617
3618 local rootMaxY
3619 if not expanded then
3620 rootMaxY = y+borderThickness*2+entryHeight-1
3621 else
3622 rootMaxY = y+borderThickness*2+entryHeight+((entryHeight+spaceBetweenEntries)*rootEntryCount)-1
3623 end
3624
3625 --draw border
3626 for currentOffset=0,borderThickness-1 do
3627 --this draws two horizontal lines
3628 for currentX=(x+currentOffset),(rootMaxX-currentOffset) do
3629 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3630 writeToPixelMatrix(screenID," ",currentX,rootMaxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3631 end
3632
3633 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3634 for currentY=(y+currentOffset+1),(rootMaxY-currentOffset-1) do
3635 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3636 writeToPixelMatrix(screenID," ",rootMaxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3637 end
3638 end
3639
3640 --calculate vertical offset
3641 local startOffsetY
3642 if textAlignmentVertical=="center" then
3643 --if vertical alignment is center, calculate the corresponding offset
3644 startOffsetY = math.floor((entryHeight-1)/2)
3645 else
3646 if textAlignmentVertical=="top" then
3647 --no offset for top alignment
3648 startOffsetY = 0
3649 else
3650 if textAlignmentVertical=="bottom" then
3651 --calculate offsetY if alignment is bottom
3652 startOffsetY = entryHeight - 1
3653 end
3654 end
3655 end
3656
3657 local startOffsetX = 0
3658 --deal with horizontal alignment, calculate an offset
3659 if textAlignmentHorizontal=="right" then
3660 startOffsetX = entryWidth-string.len(title)
3661 else
3662 if textAlignmentHorizontal=="center" then
3663 --calculate number for center horizontal alignment
3664 startOffsetX = math.floor((entryWidth-string.len(title))/2)
3665 end
3666 end
3667
3668 --write title text
3669 writeToPixelMatrix(screenID,title,x+borderThickness+startOffsetX,y+borderThickness+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","title")
3670
3671 local nextY
3672 if expanded then
3673 -- this makes things easier
3674 local s = ""
3675 for i=1,entryWidth do
3676 s = s.." "
3677 end
3678 --draw entries
3679 for i=1,nRootEntries do
3680 for j=0,spaceBetweenEntries-1 do
3681 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3682 end
3683 local currentTextColor = entryTextColor
3684 local currentBGColor = entryBGColor
3685 if highlightIDs~=nil then
3686 if highlightIDs[1]==i then
3687 currentTextColor = highlightTextColor
3688 currentBGColor = highlightBGColor
3689 --for next submenu
3690 nextY = y+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))
3691 end
3692 end
3693 for j=0,entryHeight-1 do
3694 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3695 end
3696 --calculate vertical offset
3697 local startOffsetY
3698 if textAlignmentVertical=="center" then
3699 --if vertical alignment is center, calculate the corresponding offset
3700 startOffsetY = math.floor((entryHeight-1)/2)
3701 else
3702 if textAlignmentVertical=="top" then
3703 --no offset for top alignment
3704 startOffsetY = 0
3705 else
3706 if textAlignmentVertical=="bottom" then
3707 --calculate offsetY if alignment is bottom
3708 startOffsetY = entryHeight - 1
3709 end
3710 end
3711 end
3712
3713 local startOffsetX = 0
3714 --deal with horizontal alignment, calculate an offset
3715 if textAlignmentHorizontal=="right" then
3716 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3717 else
3718 if textAlignmentHorizontal=="center" then
3719 --calculate number for center horizontal alignment
3720 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3721 end
3722 end
3723
3724 --write title text
3725 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+entryHeight+spaceBetweenEntries+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:1:"..i)
3726 end
3727
3728 --draw submenus
3729 if highlightIDs~=nil then
3730 --like this a lot of code is reused
3731 x = x + borderThickness + entryWidth
3732 y = nextY
3733 local subTable = menuArray[highlightIDs[1]]["submenu"]
3734 for k=1,table.getn(highlightIDs) do
3735 local greatestTextLength = 0
3736 local nEntries = 0
3737 for name,entry in pairs(subTable) do
3738 nEntries = nEntries + 1
3739 if string.len(entry["text"])>greatestTextLength then
3740 greatestTextLength = string.len(entry["text"])
3741 end
3742 end
3743
3744 --fill this array with entries and manipulate later
3745 local shortenedEntries = {}
3746 for i,entry in ipairs(subTable) do
3747 shortenedEntries[i] = entry
3748 end
3749
3750 entryWidth = data["entryWidth"]
3751 local maxX
3752 if entryWidth~=nil then
3753 maxX = x+borderThickness*2+entryWidth-1
3754 --shorten text
3755 if greatestTextLength>entryWidth then
3756 for i,entry in ipairs(shortenedEntries) do
3757 shortenedEntries[i]["text"] = string.sub(entry["text"],1,entryWidth)
3758 end
3759 end
3760 else
3761 maxX = x+borderThickness*2+greatestTextLength-1
3762 entryWidth = greatestTextLength
3763 end
3764
3765 -- this makes things easier
3766 local s = ""
3767 for i=1,entryWidth do
3768 s = s.." "
3769 end
3770
3771 local maxY = y + borderThickness*2 + (nEntries)*entryHeight + (nEntries-1)*spaceBetweenEntries - 1
3772
3773 --border
3774 for currentOffset=0,borderThickness-1 do
3775 --this draws two horizontal lines
3776 for currentX=(x+currentOffset),(maxX-currentOffset) do
3777 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3778 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3779 end
3780
3781 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3782 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3783 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3784 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,titleTextColor,borderColor,navigationMenuID,"navigationMenu","border")
3785 end
3786 end
3787
3788 for i=1,nEntries do
3789 if i~=nEntries then
3790 for j=0,spaceBetweenEntries-1 do
3791 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+entryHeight+((i-1)*(spaceBetweenEntries+entryHeight)),titleTextColor,borderColor,navigationMenuID,"navigationMenu","spaceBorder")
3792 end
3793 end
3794
3795 local currentTextColor = entryTextColor
3796 local currentBGColor = entryBGColor
3797 if highlightIDs[k+1]==i then
3798 currentTextColor = highlightTextColor
3799 currentBGColor = highlightBGColor
3800 nextY = y+((i-1)*(spaceBetweenEntries+entryHeight))
3801 end
3802 for j=0,entryHeight-1 do
3803 writeToPixelMatrix(screenID,s,x+borderThickness,j+y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight)),currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3804 end
3805 --calculate vertical offset
3806 local startOffsetY
3807 if textAlignmentVertical=="center" then
3808 --if vertical alignment is center, calculate the corresponding offset
3809 startOffsetY = math.floor((entryHeight-1)/2)
3810 else
3811 if textAlignmentVertical=="top" then
3812 --no offset for top alignment
3813 startOffsetY = 0
3814 else
3815 if textAlignmentVertical=="bottom" then
3816 --calculate offsetY if alignment is bottom
3817 startOffsetY = entryHeight - 1
3818 end
3819 end
3820 end
3821
3822 local startOffsetX = 0
3823 --deal with horizontal alignment, calculate an offset
3824 if textAlignmentHorizontal=="right" then
3825 startOffsetX = entryWidth-string.len(shortenedEntries[i]["text"])
3826 else
3827 if textAlignmentHorizontal=="center" then
3828 --calculate number for center horizontal alignment
3829 startOffsetX = math.floor((entryWidth-string.len(shortenedEntries[i]["text"]))/2)
3830 end
3831 end
3832
3833 --write title text
3834 writeToPixelMatrix(screenID,shortenedEntries[i]["text"],x+borderThickness+startOffsetX,y+borderThickness+((i-1)*(spaceBetweenEntries+entryHeight))+startOffsetY,currentTextColor,currentBGColor,navigationMenuID,"navigationMenu","entry:"..(k+1)..":"..i)
3835 end
3836
3837 if highlightIDs[k+1]~=nil then
3838 x = x + borderThickness + entryWidth
3839 y = nextY
3840 subTable = subTable[highlightIDs[k+1]]["submenu"]
3841 end
3842 end
3843 end
3844 end
3845end
3846
3847--colorPickers from here
3848--all props: selection,borderColor,borderThickness,colorWidth,colorHeight,selectionCharacter,onChangeFunction,visible,enabled
3849function addColorPicker(id,default)
3850 if trackID(id) then
3851 colorPickers[id] = {}
3852 colorPickers[id]["selection"] = default
3853 colorPickers[id]["visible"] = true
3854 colorPickers[id]["enabled"] = true
3855 writeToLog("Added colorPicker "..id..".",2)
3856 else
3857 writeToLog("Did not add colorPicker because of ID conflict.",3)
3858 end
3859end
3860
3861function writeColorPickerToPixelMatrix(screenID,colorPickerID,x,y)
3862 data = colorPickers[colorPickerID]
3863
3864 local selection = data["selection"]
3865 local colorWidth
3866 local colorHeight
3867 local borderColor
3868 local borderThickness
3869 local selectionCharacter
3870
3871 if data["colorWidth"]~=nil then
3872 colorWidth = data["colorWidth"]
3873 else
3874 colorWidth = 1
3875 end
3876
3877 if data["colorHeight"]~=nil then
3878 colorHeight = data["colorHeight"]
3879 else
3880 colorHeight = 1
3881 end
3882
3883 if data["borderColor"]~=nil then
3884 borderColor = data["borderColor"]
3885 else
3886 borderColor = screens[screenID]["defaultBGColor"]
3887 end
3888
3889 if data["borderThickness"]~=nil then
3890 borderThickness = data["borderThickness"]
3891 else
3892 borderThickness = 0
3893 end
3894
3895 if data["selectionCharacter"]~=nil then
3896 selectionCharacter = string.sub(data["selectionCharacter"],1,1)
3897 else
3898 selectionCharacter = "X"
3899 end
3900
3901 local maxX = x + borderThickness*2 + 4*colorWidth -1
3902 local maxY = y + borderThickness*2 + 4*colorHeight -1
3903
3904 --border
3905 for currentOffset=0,borderThickness-1 do
3906 --this draws two horizontal lines
3907 for currentX=(x+currentOffset),(maxX-currentOffset) do
3908 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
3909 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,borderColor,borderColor,colorPickerID,"colorPicker","border")
3910 end
3911
3912 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
3913 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
3914 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
3915 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,borderColor,borderColor,colorPickerID,"colorPicker","border")
3916 end
3917 end
3918
3919 for i=0,3 do
3920 for j=1,4 do
3921 local text = " "
3922 if selection==colorsArrayNumToNum[i*4+j] then
3923 text = selectionCharacter
3924 end
3925 local s = ""
3926 for h=1,colorWidth do
3927 s = s.. text
3928 end
3929
3930 for k=1,colorHeight do
3931 if selection==colors.black then
3932 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])
3933 else
3934 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])
3935 end
3936 end
3937 end
3938 end
3939end
3940
3941--Progressbars from here
3942-- all properties: length, value, valueType, broadness, orientation, textPosition, textMargin, color, colorsArray, BGColor, borderColor, borderThickness, visible
3943function addProgressBar(id,length)
3944 if trackID(id) then
3945 progressBars[id] = {}
3946 progressBars[id]["length"] = length
3947 progressBars[id]["visible"] = true
3948 writeToLog("Added progressBar "..id..".",2)
3949 else
3950 writeToLog("Did not add progressBar because of ID conflict.",3)
3951 end
3952end
3953
3954function writeProgressBarToPixelMatrix(screenID,progressBarID,x,y)
3955 data = progressBars[progressBarID]
3956
3957 local length = data["length"]
3958 local value = data["value"]
3959 local valueType
3960 local broadness
3961 local orientation
3962 local color
3963 local colorsArray
3964 local textPosition = data["textPosition"]
3965 local textMargin
3966 local BGColor
3967 local borderColor
3968 local borderThickness
3969
3970 --take care of all variable defaults
3971 if value==nil then
3972 value = 0
3973 end
3974
3975 if data["valueType"]~=nil then
3976 valueType = data["valueType"]
3977 else
3978 valueType = "absolute"
3979 end
3980
3981 local originalValue = value
3982 if valueType == "relative" then
3983 value = math.floor((length/100)*value)
3984 end
3985
3986 if data["broadness"]~=nil then
3987 broadness = data["broadness"]
3988 else
3989 broadness = 1
3990 end
3991
3992 if data["orientation"]~=nil then
3993 orientation = data["orientation"]
3994 else
3995 orientation = "left-right"
3996 end
3997
3998 if data["color"]~=nil then
3999 color = data["color"]
4000 else
4001 color = screens[screenID]["defaultTextColor"]
4002 end
4003
4004 if data["colorsArray"]~=nil then
4005 color = data["colorsArray"][value]
4006 end
4007
4008 if data["textMargin"]~=nil then
4009 textMargin = data["textMargin"]
4010 else
4011 textMargin = 0
4012 end
4013
4014 if data["BGColor"]~=nil then
4015 BGColor = data["BGColor"]
4016 else
4017 BGColor = screens[screenID]["defaultBGColor"]
4018 end
4019
4020 if data["borderColor"]~=nil then
4021 borderColor = data["borderColor"]
4022 else
4023 borderColor = color
4024 end
4025
4026 if data["borderThickness"]~=nil then
4027 borderThickness = data["borderThickness"]
4028 else
4029 borderThickness = 1
4030 end
4031
4032 local maxX
4033 local maxY
4034
4035 --calculate maxX and maxY based on the orientation of progressBar
4036 if orientation=="left-right" or orientation=="right-left" then
4037 maxX = x + borderThickness*2 + length - 1
4038 maxY = y + borderThickness*2 + broadness - 1
4039 else
4040 maxX = x + borderThickness*2 + broadness - 1
4041 maxY = y + borderThickness*2 + length - 1
4042 end
4043
4044 --start drawing
4045 --border
4046 for currentOffset=0,borderThickness-1 do
4047 --this draws two horizontal lines
4048 for currentX=(x+currentOffset),(maxX-currentOffset) do
4049 writeToPixelMatrix(screenID," ",currentX,y+currentOffset,color,borderColor,progressBarID,"progressBar","border")
4050 writeToPixelMatrix(screenID," ",currentX,maxY-currentOffset,color,borderColor,progressBarID,"progressBar","border")
4051 end
4052
4053 --this draws two vertical lines to finish the border,offset by one because those spaces are already drawn
4054 for currentY=(y+currentOffset+1),(maxY-currentOffset-1) do
4055 writeToPixelMatrix(screenID," ",x+currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4056 writeToPixelMatrix(screenID," ",maxX-currentOffset,currentY,color,borderColor,progressBarID,"progressBar","border")
4057 end
4058 end
4059
4060 --draw bar case horizontal
4061 if orientation=="left-right" or orientation=="right-left" then
4062 --this makes things easier
4063 local s = " "
4064
4065 --loop for x coordinate (length)
4066 for i=1,length do
4067 --change color according to slider value
4068 --check mode
4069 local currentColor
4070 if i<=value then
4071 currentColor = color
4072 else
4073 currentColor = BGColor
4074 end
4075 --loop for y coordinate (broadness)
4076 for currentY=y+borderThickness,maxY-borderThickness do
4077 --take pixelsPerUnit into account for calculations
4078 if orientation=="left-right" then
4079 writeToPixelMatrix(screenID,s,x+borderThickness+(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4080 end
4081 if orientation=="right-left" then
4082 writeToPixelMatrix(screenID,s,maxX-borderThickness-(i-1),currentY,currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4083 end
4084 end
4085 end
4086 else
4087 --this makes things easier
4088 local s = ""
4089 for i=1,broadness do
4090 s = s.." "
4091 end
4092 --draw bar case vertical
4093 --loop for y coordinate (length)
4094 for i=1,length do
4095 local currentColor
4096 if i<=value then
4097 currentColor = color
4098 else
4099 currentColor = BGColor
4100 end
4101 if orientation=="top-bottom" then
4102 writeToPixelMatrix(screenID,s,x+borderThickness,y+borderThickness+(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4103 end
4104 if orientation=="bottom-top" then
4105 writeToPixelMatrix(screenID,s,x+borderThickness,maxY-borderThickness-(i-1),currentColor,currentColor,progressBarID,"progressBar","bar:"..i)
4106 end
4107 end
4108 end
4109
4110 value = originalValue
4111 if valueType == "relative" then
4112 value = value .."%"
4113 end
4114 --draw text
4115 if textPosition~=nil then
4116 --calculations to center the text
4117 if textPosition=="right" then
4118 writeToPixelMatrix(screenID,value,maxX+1+textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4119 end
4120 if textPosition=="left" then
4121 writeToPixelMatrix(screenID,value,x-string.len(value)-textMargin,y+math.floor((maxY-y+1-1)/2),color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4122 end
4123 if textPosition=="top" then
4124 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),y-1-textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4125 end
4126 if textPosition=="bottom" then
4127 writeToPixelMatrix(screenID,value,x+math.floor((maxX-x+1-string.len(value))/2),maxY+1+textMargin,color,screens[screenID]["defaultBGColor"],progressBarID,"progressBar","value")
4128 end
4129 end
4130end
4131
4132--coordinateSystems from here
4133-- all props: width,height,graphTables,graphDesigns(color,BGColor,character),unitsPerPixelX,unitsPerPixelY,axesColor,numbersColor,labelX,labelY,startX,startY,stepsX,stepsY
4134function addCoordinateSystem(id,width,height)
4135 if trackID(id) then
4136 coordinateSystems[id] = {}
4137 coordinateSystems[id]["width"] = width
4138 coordinateSystems[id]["height"] = height
4139 coordinateSystems[id]["visible"] = true
4140 writeToLog("Added coordinateSystem "..id..".",2)
4141 else
4142 writeToLog("Did not add coordinateSystem because of ID conflict.",3)
4143 end
4144end
4145
4146function writeCoordinateSystemToPixelMatrix(screenID,coordinateSystemID,x,y)
4147 data = coordinateSystems[coordinateSystemID]
4148
4149 local width = data["width"]
4150 local height = data["height"]
4151 local graphTables = data["graphTables"]
4152 local graphDesigns = data["graphDesigns"]
4153 local unitsPerPixelX
4154 local unitsPerPixelY
4155 local axesColor
4156 local numbersColor
4157 local labelX
4158 local labelY
4159 local startX
4160 local startY
4161 local numbersOffset
4162 local stepX = data["stepX"]
4163 local stepY
4164
4165 if data["stepY"]~=nil then
4166 stepY = data["stepY"]
4167 else
4168 stepY = 2
4169 end
4170
4171 if data["unitsPerPixelX"]~=nil then
4172 unitsPerPixelX = data["unitsPerPixelX"]
4173 else
4174 unitsPerPixelX = 1
4175 end
4176
4177 if data["unitsPerPixelY"]~=nil then
4178 unitsPerPixelY = data["unitsPerPixelY"]
4179 else
4180 unitsPerPixelY = 1
4181 end
4182
4183 if data["axesColor"]~=nil then
4184 axesColor = data["axesColor"]
4185 else
4186 axesColor = screens[screenID]["defaultTextColor"]
4187 end
4188
4189 if data["numbersColor"]~=nil then
4190 numbersColor = data["numbersColor"]
4191 else
4192 numbersColor = screens[screenID]["defaultTextColor"]
4193 end
4194
4195 if data["labelX"]~=nil then
4196 labelX = data["labelX"]
4197 else
4198 labelX = "X"
4199 end
4200
4201 if data["labelY"]~=nil then
4202 labelY = data["labelY"]
4203 else
4204 labelY = "Y"
4205 end
4206
4207 if data["startX"]~=nil then
4208 startX = data["startX"]
4209 else
4210 startX = 0
4211 end
4212
4213 if data["startY"]~=nil then
4214 startY = data["startY"]
4215 else
4216 startY = 0
4217 end
4218
4219 if data["numbersOffset"]~=nil then
4220 numbersOffset = data["numbersOffset"]
4221 else
4222 numbersOffset = 0
4223 end
4224
4225 --draw coordinateSystem
4226 --draw origin
4227 writeToPixelMatrix(screenID,"+",x,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisOrigin")
4228
4229 --draw start numbers around origin
4230 if startX == startY then
4231 writeToPixelMatrix(screenID,tostring(startX),x-string.len(startX)-numbersOffset,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginXY")
4232 else
4233 writeToPixelMatrix(screenID,tostring(startX),x-math.floor(string.len(startX)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginX")
4234 writeToPixelMatrix(screenID,tostring(startY),x-string.len(startY)-numbersOffset,y,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numberOriginY")
4235 end
4236
4237 --draw axes
4238 for i=1,width-2 do
4239 writeToPixelMatrix(screenID,"-",x+i,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4240 end
4241 writeToPixelMatrix(screenID,">",x+width-1,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisXEnd")
4242
4243 for i=1,height-2 do
4244 writeToPixelMatrix(screenID,"|",x,y-i,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4245 end
4246 writeToPixelMatrix(screenID,"^",x,y-height+1,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4247
4248 --draw numbers
4249 if stepX==nil then
4250 local greatestTextLength = string.len(startX)
4251 if string.len(startX + (width-1)*unitsPerPixelX)>greatestTextLength then
4252 greatestTextLength = string.len(startX + (width-1)*unitsPerPixelX)
4253 end
4254 stepX = greatestTextLength + 1
4255 end
4256
4257 local currentX = x+stepX
4258 local currentValue = startX+(stepX*unitsPerPixelX)
4259 local maxX = x + width-1
4260 while currentX<maxX do
4261 writeToPixelMatrix(screenID,"+",currentX,y,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisX")
4262
4263 writeToPixelMatrix(screenID,tostring(currentValue),currentX-math.floor(string.len(currentValue)/2),y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersX")
4264
4265 currentX = currentX + stepX
4266 currentValue = currentValue + (stepX*unitsPerPixelX)
4267 end
4268
4269 local currentY = y-stepY
4270 local currentValue = startY+(stepY*unitsPerPixelY)
4271 local maxY = y - height+1
4272 while currentY>maxY do
4273 writeToPixelMatrix(screenID,"+",x,currentY,axesColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","axisY")
4274
4275 writeToPixelMatrix(screenID,tostring(currentValue),x-numbersOffset-string.len(currentValue),currentY,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","numbersY")
4276
4277 currentY = currentY - stepY
4278 currentValue = currentValue + (stepY*unitsPerPixelY)
4279 end
4280
4281 --draw labels
4282 writeToPixelMatrix(screenID,labelX,x+width-math.floor(string.len(labelX)/2)-1,y+1+numbersOffset,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelX")
4283 writeToPixelMatrix(screenID,labelY,x-string.len(labelY)-numbersOffset,y-height+1,numbersColor,screens[screenID]["defaultBGColor"],coordinateSystemID,"coordinateSystem","labelY")
4284
4285 --draw graphs
4286 if graphTables~=nil then
4287 for i,graph in ipairs(graphTables) do
4288 local color = numbersColor
4289 local BGColor = screens[screenID]["defaultBGColor"]
4290 local character = "X"
4291 if graphDesigns~=nil then
4292 if graphDesigns[i]~=nil then
4293 if graphDesigns[i]["color"]~=nil then
4294 color = graphDesigns[i]["color"]
4295 end
4296 if graphDesigns[i]["BGColor"]~=nil then
4297 BGColor = graphDesigns[i]["BGColor"]
4298 end
4299 if graphDesigns[i]["character"]~=nil then
4300 character = graphDesigns[i]["character"]
4301 end
4302 end
4303 end
4304
4305 for currentX=x,maxX do
4306 if graph[((currentX-x)*unitsPerPixelX)+startX]~=nil then
4307 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
4308 writeToPixelMatrix(screenID,character,currentX,y-math.floor((graph[((currentX-x)*unitsPerPixelX)+startX]-startY)/unitsPerPixelY+0.5),color,BGColor,coordinateSystemID,"coordinateSystem","graph:"..i)
4309 end
4310 end
4311 end
4312 end
4313 end
4314end
4315
4316--pictures from here
4317-- all props: linesArray
4318function addPicture(id,width,height,linesArray)
4319 if trackID(id) then
4320 pictures[id] = {}
4321 pictures[id]["width"] = width
4322 pictures[id]["height"] = height
4323 pictures[id]["linesArray"] = linesArray
4324 pictures[id]["visible"] = true
4325 writeToLog("Added picture "..id..".",2)
4326 else
4327 writeToLog("Did not add picture because of ID conflict.",3)
4328 end
4329end
4330
4331function writePictureToPixelMatrix(screenID,pictureID,x,y)
4332 data = pictures[pictureID]
4333 colorsArrayStrToNum["*"]=screens[screenID]["defaultTextColor"]
4334 colorsArrayStrToNum["#"]=screens[screenID]["defaultBGColor"]
4335
4336 local linesArray = data["linesArray"]
4337 local width = data["width"]
4338 local height = data["height"]
4339
4340 for i=1,height do
4341 local j = 1
4342 local line = linesArray[i]
4343 local correct = true
4344 if line~=nil then
4345 while string.find(line,";")~=nil do
4346 local currentLetter = string.sub(line,1,string.find(line,";")-1)
4347 line = string.sub(line,string.find(line,";")+1)
4348
4349 if string.len(currentLetter)==5 and string.sub(currentLetter,2,2)==":" and string.sub(currentLetter,4,4)==":" then
4350 local textColor = string.sub(currentLetter,1,1)
4351 local BGColor = string.sub(currentLetter,3,3)
4352 local character = string.sub(currentLetter,5,5)
4353
4354 writeToPixelMatrix(screenID,character,x+j-1,y+i-1,colorsArrayStrToNum[textColor],colorsArrayStrToNum[BGColor],pictureID,"picture",j..":"..i)
4355 end
4356
4357 if string.len(currentLetter)==1 then
4358 writeToPixelMatrix(screenID," ",x+j-1,y+i-1,colorsArrayStrToNum[currentLetter],colorsArrayStrToNum[currentLetter],pictureID,"picture",j..":"..i)
4359 end
4360
4361 if j == width then correct = false break end
4362 j = j + 1
4363 end
4364 else
4365 linesArray[i] = ""
4366 end
4367 --correct mistakes
4368 if correct then
4369 for k=1,width-j+1 do
4370 linesArray[i] = linesArray[i].."#;"
4371 end
4372 end
4373 end
4374end
4375
4376--initalizing function searching for all monitors and adding them
4377function findMonitors()
4378 local nMonitorCount = 0
4379 monitors = {}
4380 writeToLog("Searching for monitors...",2)
4381
4382 setScreenToRenderOnTerminal(initMonsSID)
4383 refresh()
4384 local sides = {"front","back","left","right","top","bottom"}
4385 --search for monitors and modems
4386 for i,side in ipairs(sides) do
4387 --check if there is a monitor
4388 if peripheral.isPresent(side) then
4389 if peripheral.getType(side)=="monitor" then
4390 --check if monitor is advanced
4391 if peripheral.call(side,"isColor") then
4392 -- initialize monitor
4393 monitor = peripheral.wrap(side)
4394 monitor.setBackgroundColor(colors.red)
4395 monitor.clear()
4396 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!")
4397
4398 writeToLog("Found monitor on side "..side..".",2)
4399 local sID
4400 local success = false
4401 repeat
4402 refresh()
4403 local x,y = term.getSize()
4404 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4405 term.setTextColor(colorPalette[1])
4406 term.write(">")
4407 sID = read()
4408 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4409 for i=1,string.len(sID) do
4410 term.write(" ")
4411 end
4412 if sID=="" then
4413 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4414 refresh()
4415 else
4416 if trackID(sID) then
4417 success = true
4418 else
4419 changeProperty(initMonsSErrorID,"content","ID already taken!")
4420 refresh()
4421 end
4422 end
4423 until success==true
4424 monitors[sID] = {}
4425 monitors[sID]["peripheral"] = monitor
4426 monitors[sID]["side"] = side
4427 monitors[sID]["networkID"] = "NONE"
4428 monitor.setBackgroundColor(colors.black)
4429 monitor.clear()
4430 nMonitorCount = nMonitorCount + 1
4431 writeToLog("Added monitor "..sID.." to the system.",2)
4432 changeProperty(initMonsSErrorID,"content","")
4433 end
4434 else
4435 --check monitors connected via modems
4436 if peripheral.getType(side)=="modem" then
4437 local modem = peripheral.wrap(side)
4438 if not modem.isWireless() then
4439 for i,sPeripheral in ipairs(modem.getNamesRemote()) do
4440 if string.match(sPeripheral,"monitor") then
4441 if modem.callRemote(sPeripheral,"isColor") then
4442 -- initialize monitor
4443 monitor = peripheral.wrap(sPeripheral)
4444 monitor.setBackgroundColor(colors.red)
4445 monitor.clear()
4446 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!")
4447
4448 writeToLog("Found monitor on side "..side.." through modem.",2)
4449 local sID
4450 local success = false
4451 repeat
4452 refresh()
4453 local x,y = term.getSize()
4454 term.setCursorPos(relX(20,initMonsSID)+2,y-1)
4455 term.setTextColor(colorPalette[1])
4456 term.write(">")
4457 sID = read()
4458 term.setCursorPos(relX(20,initMonsSID)+3,y-1)
4459 for i=1,string.len(sID) do
4460 term.write(" ")
4461 end
4462 if sID=="" then
4463 changeProperty(initMonsSErrorID,"content","Cannot be empty!")
4464 refresh()
4465 else
4466 if trackID(sID) then
4467 success = true
4468 else
4469 changeProperty(initMonsSErrorID,"content","ID already taken!")
4470 refresh()
4471 end
4472 end
4473 until success==true
4474 monitors[sID] = {}
4475 monitors[sID]["peripheral"] = monitor
4476 monitors[sID]["side"] = side
4477 monitors[sID]["networkID"] = sPeripheral
4478 monitor.setBackgroundColor(colors.black)
4479 monitor.clear()
4480 nMonitorCount = nMonitorCount + 1
4481 writeToLog("Added monitor "..sID.." to the system.",2)
4482 changeProperty(initMonsSErrorID,"content","")
4483 end
4484 end
4485 end
4486 end
4487 end
4488 end
4489 end
4490 end
4491
4492 if nMonitorCount == 0 then
4493 writeToLog("Did not find any advanced monitors.",2)
4494 else
4495 writeToLog("Found "..nMonitorCount.." monitors.",2)
4496 end
4497end
4498
4499function setupStuff()
4500 local x,y = term.getSize()
4501 addScreen(initMonsSID,x,y,colorPalette[1],colorPalette[2])
4502 addDynamicTextBox(initMonsSLeftRectID,"")
4503 changeProperty(initMonsSLeftRectID,"width",relX(20,initMonsSID))
4504 changeProperty(initMonsSLeftRectID,"height",relY(100,initMonsSID))
4505 changeProperty(initMonsSLeftRectID,"BGColor",colorPalette[3])
4506 addElementToScreen(initMonsSLeftRectID,initMonsSID,1,1)
4507
4508 addDynamicTextBox(initMonsSHeadingID,"EasyGUI Monitor Initialization")
4509 changeProperty(initMonsSHeadingID,"width",relX(80,initMonsSID))
4510 changeProperty(initMonsSHeadingID,"borderThickness",1)
4511 addElementToScreen(initMonsSHeadingID,initMonsSID,relX(20,initMonsSID)+1,1)
4512
4513 addDynamicTextBox(initMonsSTextID,"Searching for monitors...")
4514 changeProperty(initMonsSTextID,"width",relX(80,initMonsSID))
4515 changeProperty(initMonsSTextID,"borderThickness",1)
4516 addElementToScreen(initMonsSTextID,initMonsSID,relX(20,initMonsSID)+1,relY(30,initMonsSID))
4517
4518 local picArray = {}
4519 for i=1,y do
4520 if (i%3)==1 then
4521 table.insert(picArray,"*;;;")
4522 end
4523 if (i%3)==2 then
4524 table.insert(picArray,";*;;")
4525 end
4526 if (i%3)==0 then
4527 table.insert(picArray,";;*;")
4528 end
4529 end
4530 addPicture(initMonsSPictureID,3,y,picArray)
4531 addElementToScreen(initMonsSPictureID,initMonsSID,relX(10,initMonsSID)-1,1)
4532
4533 addDynamicTextBox(initMonsSErrorID,"")
4534 changeProperty(initMonsSErrorID,"width",relX(80,initMonsSID))
4535 changeProperty(initMonsSErrorID,"textColor",colors.red)
4536 addElementToScreen(initMonsSErrorID,initMonsSID,relX(20,initMonsSID)+1,y)
4537end
4538
4539function setDesignerScreen(ID)
4540 if designerMonitor==terminalID then
4541 setScreenToRenderOnTerminal(ID)
4542 else
4543 setScreenToRenderOnMon(ID,designerMonitor,tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]),0,0)
4544 end
4545end
4546
4547function transferDesigner()
4548 local array = {"term"}
4549 for name,data in pairs(monitors) do
4550 table.insert(array,name)
4551 end
4552 if table.getn(array)~=1 then
4553 local x,y = term.getSize()
4554 addScreen(changeMonSID,x,y,colorPalette[1],colorPalette[2])
4555 setScreenToRenderOnTerminal(changeMonSID)
4556 addElementToScreen(initMonsSLeftRectID,changeMonSID,1,1)
4557 addElementToScreen(initMonsSPictureID,changeMonSID,relX(10,changeMonSID)-1,1)
4558 changeProperty(initMonsSHeadingID,"content","EasyGUI Designer transfer")
4559 addElementToScreen(initMonsSHeadingID,changeMonSID,relX(20,changeMonSID)+1,1)
4560 changeProperty(initMonsSTextID,"content","Would you like to transfer the designer on a monitor?")
4561 addElementToScreen(initMonsSTextID,changeMonSID,relX(20,changeMonSID)+1,relY(30,changeMonSID))
4562
4563 addDropDownMenu(changeMonSScaleDDID,{"0.5","1","1.5","2"},1)
4564 changeProperty(changeMonSScaleDDID,"borderThickness",1)
4565 changeProperty(changeMonSScaleDDID,"borderColor",colorPalette[3])
4566 changeProperty(changeMonSScaleDDID,"highlightTextColor",colorPalette[2])
4567 changeProperty(changeMonSScaleDDID,"highlightBGColor",colorPalette[1])
4568 changeProperty(changeMonSScaleDDID,"width",relX(40,changeMonSID)-2)
4569 addElementToScreen(changeMonSScaleDDID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)+2)
4570
4571 addDropDownMenu(changeMonSDDMenuID,array,1)
4572 changeProperty(changeMonSDDMenuID,"borderThickness",1)
4573 changeProperty(changeMonSDDMenuID,"borderColor",colorPalette[3])
4574 changeProperty(changeMonSDDMenuID,"highlightTextColor",colorPalette[2])
4575 changeProperty(changeMonSDDMenuID,"highlightBGColor",colorPalette[1])
4576 changeProperty(changeMonSDDMenuID,"width",relX(40,changeMonSID)-2)
4577 addElementToScreen(changeMonSDDMenuID,changeMonSID,relX(20,changeMonSID)+2,relY(70,changeMonSID)-2)
4578
4579 addDynamicTextBox(changeMonSApplyID,"Apply")
4580 changeProperty(changeMonSApplyID,"width",relX(40,changeMonSID)-2)
4581 changeProperty(changeMonSApplyID,"textColor",colorPalette[3])
4582 changeProperty(changeMonSApplyID,"BGColor",colorPalette[1])
4583 changeProperty(changeMonSApplyID,"borderThickness",1)
4584 changeProperty(changeMonSApplyID,"onClickMode","flash")
4585 changeProperty(changeMonSApplyID,"onActiveFunction",function()
4586 os.queueEvent("easygui_interrupt") end)
4587 addElementToScreen(changeMonSApplyID,changeMonSID,relX(60,changeMonSID)+2,relY(70,changeMonSID))
4588
4589 run()
4590
4591 if getProperty(changeMonSDDMenuID,"selectionID")==1 then
4592 designerMonitor = terminalID
4593 else
4594 designerMonitor = array[getProperty(changeMonSDDMenuID,"selectionID")]
4595 end
4596 else
4597 designerMonitor = terminalID
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 term.clear()
6524 setupStuff()
6525 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6526 loadMonitors()
6527 else
6528 findMonitors()
6529 saveMonitors()
6530 end
6531 transferDesigner()
6532 if designerMonitor==terminalID then
6533 designerX,designerY = term.getSize()
6534 if designerX<51 then
6535 term.clear()
6536 term.setCursorPos(1,1)
6537 term.setBackgroundColor(colors.black)
6538 error("Turtle and pocket screens are to small to run EasyGUI designer. You can either switch to a computer or run the designer on an attached monitor.")
6539 end
6540 else
6541 monitors[designerMonitor]["peripheral"].setTextScale(tonumber(getProperty(changeMonSScaleDDID,"entries")[getProperty(changeMonSScaleDDID,"selectionID")]))
6542 designerX,designerY = monitors[designerMonitor]["peripheral"].getSize()
6543 end
6544 --main program start
6545 addScreen(mainSID,designerX,designerY,colorPalette[1],colorPalette[2])
6546 setScreenToRenderOnTerminal(nil)
6547 term.setTextColor(colorPalette[1])
6548 term.setBackgroundColor(colorPalette[2])
6549 term.clear()
6550 term.setCursorPos(1,1)
6551 term.write("EasyGUI Designer running on monitor.")
6552 setDesignerScreen(mainSID)
6553 addDynamicTextBox(mainSBorderID,"")
6554 changeProperty(mainSBorderID,"borderThickness",1)
6555 changeProperty(mainSBorderID,"borderColor",colorPalette[3])
6556 changeProperty(mainSBorderID,"width",designerX)
6557 changeProperty(mainSBorderID,"height",designerY)
6558 addElementToScreen(mainSBorderID,mainSID,1,1)
6559
6560 addDynamicTextBox(mainSHeadingID,"EasyGUI Designer Main Menu")
6561 changeProperty(mainSHeadingID,"width",designerX-2)
6562 addElementToScreen(mainSHeadingID,mainSID,2,3)
6563
6564 addDynamicTextBox(mainSButton1ID,"Screens")
6565 changeProperty(mainSButton1ID,"BGColor",colorPalette[3])
6566 changeProperty(mainSButton1ID,"textColor",colorPalette[2])
6567 changeProperty(mainSButton1ID,"borderColor",colorPalette[1])
6568 changeProperty(mainSButton1ID,"width",relX(80,mainSID))
6569 changeProperty(mainSButton1ID,"height",relY(15,mainSID))
6570 changeProperty(mainSButton1ID,"borderThickness",1)
6571 changeProperty(mainSButton1ID,"onClickMode","flash")
6572 changeProperty(mainSButton1ID,"onActiveFunction",function() setDesignerScreen(screensSID)
6573 onLoadScreensS() end)
6574 addElementToScreen(mainSButton1ID,mainSID,relX(10,mainSID),relY(25,mainSID))
6575
6576 addDynamicTextBox(mainSButton2ID,"Elements")
6577 changeProperty(mainSButton2ID,"BGColor",colorPalette[3])
6578 changeProperty(mainSButton2ID,"textColor",colorPalette[2])
6579 changeProperty(mainSButton2ID,"borderColor",colorPalette[1])
6580 changeProperty(mainSButton2ID,"width",relX(80,mainSID))
6581 changeProperty(mainSButton2ID,"height",relY(15,mainSID))
6582 changeProperty(mainSButton2ID,"borderThickness",1)
6583 changeProperty(mainSButton2ID,"onClickMode","flash")
6584 changeProperty(mainSButton2ID,"onActiveFunction",function() setDesignerScreen(elementsSID)
6585 onLoadElementsS() end)
6586 addElementToScreen(mainSButton2ID,mainSID,relX(10,mainSID),relY(50,mainSID))
6587
6588 addDynamicTextBox(mainSButton3ID,"Exit")
6589 changeProperty(mainSButton3ID,"BGColor",colorPalette[3])
6590 changeProperty(mainSButton3ID,"textColor",colorPalette[2])
6591 changeProperty(mainSButton3ID,"borderColor",colorPalette[1])
6592 changeProperty(mainSButton3ID,"width",relX(80,mainSID))
6593 changeProperty(mainSButton3ID,"height",relY(15,mainSID))
6594 changeProperty(mainSButton3ID,"borderThickness",1)
6595 changeProperty(mainSButton3ID,"onClickMode","flash")
6596 changeProperty(mainSButton3ID,"onActiveFunction",function()
6597 os.queueEvent("terminate") end)
6598 addElementToScreen(mainSButton3ID,mainSID,relX(10,mainSID),relY(75,mainSID))
6599
6600 addScreen(screensSID,designerX,designerY,colorPalette[1],colorPalette[2])
6601 addDynamicTextBox(screensSHeadingID,"EasyGUI Designer Screens Menu")
6602 changeProperty(screensSHeadingID,"width",designerX-2)
6603 addElementToScreen(mainSBorderID,screensSID,1,1)
6604 addElementToScreen(screensSHeadingID,screensSID,2,3)
6605
6606 addScreen(newScreenSID,designerX,designerY,colorPalette[1],colorPalette[2])
6607 addElementToScreen(mainSBorderID,newScreenSID,1,1)
6608 addDynamicTextBox(newScreenSHeadingID,"EasyGUI Create new screen")
6609 changeProperty(newScreenSHeadingID,"width",designerX-2)
6610 addElementToScreen(newScreenSHeadingID,newScreenSID,2,3)
6611
6612 addDynamicTextBox(newScreenSTextID,"Please choose the size of the new screen.")
6613 changeProperty(newScreenSTextID,"width",designerX-2)
6614 addElementToScreen(newScreenSTextID,newScreenSID,2,5)
6615
6616 addColorPicker(newScreenSColor1ID,nil)
6617 addColorPicker(newScreenSColor2ID,nil)
6618 changeProperty(newScreenSColor1ID,"visible",false)
6619 changeProperty(newScreenSColor2ID,"visible",false)
6620 addElementToScreen(newScreenSColor1ID,newScreenSID,3,relY(40,newScreenSID))
6621 addElementToScreen(newScreenSColor2ID,newScreenSID,designerX-5,relY(40,newScreenSID))
6622
6623 addDynamicTextBox(newScreenSResultID,"Resulting size: $size <Continue>")
6624 changeProperty(newScreenSResultID,"width",designerX-2)
6625 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end})
6626 changeProperty(newScreenSResultID,"onClickMode","flash")
6627 changeProperty(newScreenSResultID,"onActiveFunction",function()
6628 if getProperty(newScreenSColor1ID,"visible") then
6629 if getProperty(newScreenSColor1ID,"selection")~=nil and getProperty(newScreenSColor2ID,"selection")~=nil then
6630 term.setTextColor(colorPalette[1])
6631 term.setBackgroundColor(colorPalette[2])
6632 term.clear()
6633 term.setCursorPos(1,1)
6634 print("Please enter an unique ID for the new screen:")
6635 repeat
6636 local input = read()
6637 if input~="" and input~=nil then
6638 if string.len(input)<32 then
6639 if not IDExists(input) then
6640 ID = input
6641 else
6642 print("ID already taken!")
6643 end
6644 else
6645 print("Must be less than 32 characters!")
6646 end
6647 else
6648 print("Cannot be an empty string.")
6649 end
6650 until ID~=nil
6651
6652 local bool,s = pcall(getProperty(newScreenSResultID,"variables")["size"])
6653 local x = tonumber(string.sub(s,1,string.find(s,":")-1))
6654 local y = tonumber(string.sub(s,string.find(s,":")+1))
6655 addScreen(ID,x,y,getProperty(newScreenSColor1ID,"selection"),getProperty(newScreenSColor2ID,"selection"))
6656 saveScreen(ID)
6657 changeProperty(newScreenSDDM1ID,"visible",true)
6658 changeProperty(newScreenSColor1ID,"visible",false)
6659 changeProperty(newScreenSColor2ID,"visible",false)
6660 changeProperty(newScreenSTextID,"content","Please choose the size of the new screen.")
6661 changeProperty(newScreenSResultID,"content","Resulting size: $size <Continue>")
6662 startDesigner(ID)
6663 end
6664 else
6665 changeProperty(newScreenSDDM1ID,"visible",false)
6666 changeProperty(newScreenSDDM2ID,"visible",false)
6667 changeProperty(newScreenSDDM3ID,"visible",false)
6668 changeProperty(newScreenSTextID,"content","[text] choose default colors [background]")
6669 changeProperty(newScreenSResultID,"content","<Continue>")
6670 changeProperty(newScreenSColor1ID,"visible",true)
6671 changeProperty(newScreenSColor2ID,"visible",true)
6672 refresh()
6673 end
6674 end)
6675 addElementToScreen(newScreenSResultID,newScreenSID,2,designerY-2)
6676
6677 local array = {}
6678 for name,data in pairs(monitors) do
6679 table.insert(array,name)
6680 end
6681 addDropDownMenu(newScreenSDDM2ID,array,1)
6682 changeProperty(newScreenSDDM2ID,"borderThickness",1)
6683 changeProperty(newScreenSDDM2ID,"borderColor",colorPalette[3])
6684 changeProperty(newScreenSDDM2ID,"highlightTextColor",colorPalette[2])
6685 changeProperty(newScreenSDDM2ID,"highlightBGColor",colorPalette[1])
6686 changeProperty(newScreenSDDM2ID,"visible",false)
6687 addElementToScreen(newScreenSDDM2ID,newScreenSID,relX(15,newScreenSID),relY(65,newScreenSID))
6688
6689 addDropDownMenu(newScreenSDDM3ID,{"0.5","1","1.5","2"},1)
6690 changeProperty(newScreenSDDM3ID,"borderThickness",1)
6691 changeProperty(newScreenSDDM3ID,"borderColor",colorPalette[3])
6692 changeProperty(newScreenSDDM3ID,"highlightTextColor",colorPalette[2])
6693 changeProperty(newScreenSDDM3ID,"highlightBGColor",colorPalette[1])
6694 changeProperty(newScreenSDDM3ID,"visible",false)
6695 addElementToScreen(newScreenSDDM3ID,newScreenSID,relX(60,newScreenSID),relY(65,newScreenSID))
6696
6697 addDropDownMenu(newScreenSDDM1ID,{"computer (51:19)","turtle (39:13)","pocket com (26:20)","monitor (variable)","custom"},1)
6698 changeProperty(newScreenSDDM1ID,"borderThickness",1)
6699 changeProperty(newScreenSDDM1ID,"borderColor",colorPalette[3])
6700 changeProperty(newScreenSDDM1ID,"highlightTextColor",colorPalette[2])
6701 changeProperty(newScreenSDDM1ID,"highlightBGColor",colorPalette[1])
6702 changeProperty(newScreenSDDM1ID,"onChangeFunction",function(ID,selec)
6703 if selec==4 then
6704 changeProperty(newScreenSDDM2ID,"visible",true)
6705 changeProperty(newScreenSDDM3ID,"visible",true)
6706 changeProperty(newScreenSResultID,"variables",{["size"]=function() monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].setTextScale(tonumber(getProperty(newScreenSDDM3ID,"entries")[getProperty(newScreenSDDM3ID,"selectionID")]))
6707 local a,b = monitors[getProperty(newScreenSDDM2ID,"entries")[getProperty(newScreenSDDM2ID,"selectionID")]]["peripheral"].getSize()
6708 return a..":"..b end})
6709 refresh()
6710 else
6711 if selec==1 then
6712 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "51:19" end })
6713 end
6714 if selec==2 then
6715 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "39:13" end })
6716 end
6717 if selec==3 then
6718 changeProperty(newScreenSResultID,"variables",{["size"]=function() return "26:20" end })
6719 end
6720 if selec==5 then
6721 term.setBackgroundColor(colorPalette[2])
6722 term.setTextColor(colorPalette[1])
6723 term.clear()
6724 term.setCursorPos(1,1)
6725 print("Enter size X for new screen:")
6726 local a = read()
6727 print("Enter size Y for new screen:")
6728 local b = read()
6729 changeProperty(newScreenSResultID,"variables",{["size"]=function() return a..":"..b end })
6730 fullRefresh()
6731 end
6732 changeProperty(newScreenSDDM2ID,"visible",false)
6733 changeProperty(newScreenSDDM3ID,"visible",false)
6734 end
6735 end)
6736 addElementToScreen(newScreenSDDM1ID,newScreenSID,relX(15,newScreenSID),relY(35,newScreenSID))
6737
6738 addDynamicTextBox(screensSMsgID,"Please check term!")
6739 changeProperty(screensSMsgID,"width",relX(80,screensSID))
6740 changeProperty(screensSMsgID,"height",relY(15,screensSID))
6741 changeProperty(screensSMsgID,"borderThickness",1)
6742 changeProperty(screensSMsgID,"visible",false)
6743 addElementToScreen(screensSMsgID,screensSID,relX(10,screensSID),relY(25,screensSID))
6744
6745 addDynamicTextBox(screensSButton1ID,"New Screen")
6746 changeProperty(screensSButton1ID,"BGColor",colorPalette[3])
6747 changeProperty(screensSButton1ID,"textColor",colorPalette[2])
6748 changeProperty(screensSButton1ID,"borderColor",colorPalette[1])
6749 changeProperty(screensSButton1ID,"width",relX(80,screensSID))
6750 changeProperty(screensSButton1ID,"height",relY(15,screensSID))
6751 changeProperty(screensSButton1ID,"borderThickness",1)
6752 changeProperty(screensSButton1ID,"onClickMode","flash")
6753 changeProperty(screensSButton1ID,"onActiveFunction",function()
6754 setDesignerScreen(newScreenSID)
6755 fullRefresh()
6756 end)
6757 addElementToScreen(screensSButton1ID,screensSID,relX(10,screensSID),relY(25,screensSID))
6758
6759 addDynamicTextBox(screensSButton2ID,"Edit")
6760 changeProperty(screensSButton2ID,"BGColor",colorPalette[3])
6761 changeProperty(screensSButton2ID,"textColor",colorPalette[2])
6762 changeProperty(screensSButton2ID,"borderColor",colorPalette[1])
6763 changeProperty(screensSButton2ID,"width",relX(40,screensSID)-1)
6764 changeProperty(screensSButton2ID,"height",relY(15,screensSID))
6765 changeProperty(screensSButton2ID,"borderThickness",1)
6766 changeProperty(screensSButton2ID,"onClickMode","flash")
6767 changeProperty(screensSButton2ID,"onActiveFunction",function() startDesigner(getProperty(screensSDDMenuID,"entries")[getProperty(screensSDDMenuID,"selectionID")]) end)
6768 addElementToScreen(screensSButton2ID,screensSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,screensSID))
6769
6770 addDynamicTextBox(screensSButton3ID,"Back")
6771 changeProperty(screensSButton3ID,"BGColor",colorPalette[3])
6772 changeProperty(screensSButton3ID,"textColor",colorPalette[2])
6773 changeProperty(screensSButton3ID,"borderColor",colorPalette[1])
6774 changeProperty(screensSButton3ID,"width",relX(80,screensSID))
6775 changeProperty(screensSButton3ID,"height",relY(15,screensSID))
6776 changeProperty(screensSButton3ID,"borderThickness",1)
6777 changeProperty(screensSButton3ID,"onClickMode","flash")
6778 changeProperty(screensSButton3ID,"onActiveFunction",function() setDesignerScreen(mainSID) end)
6779 addElementToScreen(screensSButton3ID,screensSID,relX(10,screensSID),relY(75,screensSID))
6780
6781 addDropDownMenu(screensSDDMenuID,nil,1)
6782 changeProperty(screensSDDMenuID,"borderThickness",1)
6783 changeProperty(screensSDDMenuID,"borderColor",colorPalette[3])
6784 changeProperty(screensSDDMenuID,"highlightTextColor",colorPalette[2])
6785 changeProperty(screensSDDMenuID,"highlightBGColor",colorPalette[1])
6786 changeProperty(screensSDDMenuID,"width",relX(40,screensSID)-1)
6787 addElementToScreen(screensSDDMenuID,screensSID,relX(10,screensSID),relY(50,screensSID))
6788
6789 addScreen(elementsSID,designerX,designerY,colorPalette[1],colorPalette[2])
6790 addDynamicTextBox(elementsSHeadingID,"EasyGUI Designer Elements Menu")
6791 changeProperty(elementsSHeadingID,"width",designerX-2)
6792 addElementToScreen(mainSBorderID,elementsSID,1,1)
6793 addElementToScreen(elementsSHeadingID,elementsSID,2,3)
6794 addElementToScreen(screensSButton3ID,elementsSID,relX(10,screensSID),relY(75,screensSID))
6795
6796 addElementToScreen(screensSMsgID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6797
6798 local array = {"dynTextBox","slider","dropDownMenu","navMenu","colorPicker","progressBar","coordsSystem","picture"}
6799
6800 addDynamicTextBox(elementsSButton1ID,"Add")
6801 changeProperty(elementsSButton1ID,"BGColor",colorPalette[3])
6802 changeProperty(elementsSButton1ID,"textColor",colorPalette[2])
6803 changeProperty(elementsSButton1ID,"borderColor",colorPalette[1])
6804 changeProperty(elementsSButton1ID,"width",relX(40,elementsSID)-1)
6805 changeProperty(elementsSButton1ID,"height",relY(15,elementsSID))
6806 changeProperty(elementsSButton1ID,"borderThickness",1)
6807 changeProperty(elementsSButton1ID,"onClickMode","flash")
6808 changeProperty(elementsSButton1ID,"onActiveFunction",function() startEditor(newElement(array[getProperty(elementsSDDMenu1ID,"selectionID")])) end)
6809 addElementToScreen(elementsSButton1ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(25,elementsSID))
6810
6811 addDynamicTextBox(elementsSButton2ID,"Edit")
6812 changeProperty(elementsSButton2ID,"BGColor",colorPalette[3])
6813 changeProperty(elementsSButton2ID,"textColor",colorPalette[2])
6814 changeProperty(elementsSButton2ID,"borderColor",colorPalette[1])
6815 changeProperty(elementsSButton2ID,"width",relX(40,elementsSID)-1)
6816 changeProperty(elementsSButton2ID,"height",relY(15,elementsSID))
6817 changeProperty(elementsSButton2ID,"borderThickness",1)
6818 changeProperty(elementsSButton2ID,"onClickMode","flash")
6819 changeProperty(elementsSButton2ID,"onActiveFunction",function() startEditor(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")],getType(getProperty(elementsSDDMenu2ID,"entries")[getProperty(elementsSDDMenu2ID,"selectionID")])) end)
6820 addElementToScreen(elementsSButton2ID,elementsSID,relX(10,screensSID)+relX(80,screensSID)-relX(40,screensSID)+1,relY(50,elementsSID))
6821
6822 addDropDownMenu(elementsSDDMenu2ID,nil,1)
6823 changeProperty(elementsSDDMenu2ID,"borderThickness",1)
6824 changeProperty(elementsSDDMenu2ID,"borderColor",colorPalette[3])
6825 changeProperty(elementsSDDMenu2ID,"highlightTextColor",colorPalette[2])
6826 changeProperty(elementsSDDMenu2ID,"highlightBGColor",colorPalette[1])
6827 changeProperty(elementsSDDMenu2ID,"width",relX(40,elementsSID)-1)
6828 addElementToScreen(elementsSDDMenu2ID,elementsSID,relX(10,elementsSID),relY(50,elementsSID))
6829
6830 addDropDownMenu(elementsSDDMenu1ID,array,1)
6831 changeProperty(elementsSDDMenu1ID,"borderThickness",1)
6832 changeProperty(elementsSDDMenu1ID,"borderColor",colorPalette[3])
6833 changeProperty(elementsSDDMenu1ID,"highlightTextColor",colorPalette[2])
6834 changeProperty(elementsSDDMenu1ID,"highlightBGColor",colorPalette[1])
6835 changeProperty(elementsSDDMenu1ID,"width",relX(40,elementsSID)-1)
6836 addElementToScreen(elementsSDDMenu1ID,elementsSID,relX(10,elementsSID),relY(25,elementsSID))
6837
6838 run(nil)
6839else
6840 writeToLog("Loaded as API.",2)
6841 if fs.exists(fs.combine(root,"EasyGUI/monitors.xml")) then
6842 loadMonitors()
6843 else
6844 print("EasyGUI was loaded as API, but there is no monitor file present. Starting monitor initialization sequence.")
6845 sleep(5)
6846 term.clear()
6847 setupStuff()
6848 findMonitors()
6849 saveMonitors()
6850 end
6851end
6852
6853--END OF EASYGUI API
6854-----------------------------