Advertisement
bobmarley12345

shitcum

Nov 13th, 2023 (edited)
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.33 KB | None | 0 0
  1. -- used to dump incoming events to the screen
  2. IS_DEBUG_MODE = false
  3.  
  4. -- Animation timer data
  5. AnimTimerId = 0
  6. AppLastTickTime = 0
  7.  
  8. -- The application animation timer tick rate
  9. AnimTimerTickRate = 10
  10.  
  11. -- The interval of an application tick, in seconds
  12. AnimIntervalSecs = 1 / AnimTimerTickRate
  13.  
  14. -- True or false if the current event is a timer/render tick
  15. IsAnimationTick = false
  16.  
  17. -- A helper to print a debug message to the screen
  18. LastDebugMessage = "Debug Message Here"
  19.  
  20. BLANK_EVENT = { type = nil, p1 = nil, p2 = nil, p3 = nil, p4 = nil, }
  21. COMPONENT_MOUSE_CAPTURE = nil
  22.  
  23. APP_ROOT_OBJECTS = {}
  24.  
  25. -- A base table template for a drawable component object
  26. DRAWABLE_TEMPLATE = {
  27.     -- x,y are the x and y coords, relative to the parent
  28.     -- w,h are the width and height of the object
  29.     x = 0, y = 0, w = 0, h = 0,
  30.     IsUpdating = false,
  31.     OnAnimTick = function(this, time, delta)
  32.         -- update object here. e contains the last event data,
  33.         -- which may be the timer event
  34.     end,
  35.     RenderFunc = function(this, x, y)
  36.         -- draw here. X and Y are absolute coordinates, accumulated
  37.         -- during the recursive render process
  38.     end,
  39.     -- returns the handled state. True = don't go further
  40.     -- These are the function definitions though, however, the handlers are stored in tables,
  41.     -- OnPreviewMouseDown =   function(this, time, delta, btn, x, y) return false end,
  42.     -- OnMouseDown =          function(this, time, delta, hit, btn, x, y) return false end,
  43.     -- OnPreviewMouseDrag =   function(this, time, delta, btn, x, y) return false end,
  44.     -- OnMouseDrag =          function(this, time, delta, btn, x, y) return false end,
  45.     -- OnPreviewKeyPressed =  function(this, time, delta, keyCode) return false end,
  46.     -- OnKeyPressed =         function(this, time, delta, keyCode) return false end,
  47.     -- OnPreviewCharPressed = function(this, time, delta, ch) return false end,
  48.     -- OnCharPressed =        function(this, time, delta, ch) return false end,
  49.     OnPreviewMouseDown = {},
  50.     OnMouseDown = {},
  51.     OnPreviewMouseDrag = {},
  52.     OnMouseDrag = {},
  53.     OnPreviewKeyPressed = {},
  54.     OnKeyPressed = {},
  55.     OnPreviewCharPressed = {},
  56.     OnCharPressed = {},
  57.     -- our parent object
  58.     parent = nil,
  59.     indexInParent = -1,
  60.     IsInVisualTree = false,
  61.     children = {}, -- a table of child drawable objects
  62.     childrenToRemove = {}
  63. }
  64.  
  65. --region Helper String Functions
  66.  
  67. function string.jsub(str, startIndex, endIndex)
  68.     if (endIndex == nil) then
  69.         return string.sub(str, startIndex)
  70.     end
  71.     return string.sub(str, startIndex, endIndex - 1)
  72. end
  73.  
  74. -- Checks if the given `str` starts with the given `value` (optionally start searching with the given start offset index. 1 by default). `string.startsWith("hello", "he", 1)` == `true`
  75. function string.startsWith(str, value, startIndex)
  76.     if (startIndex == nil) then
  77.         startIndex = 1
  78.     end
  79.     return string.jsub(str, startIndex, string.len(value) + startIndex) == value
  80. end
  81.  
  82. -- Checks if the given `str` ends with the given value. string.endsWith("hello", "lo") == true
  83. function string.endsWith(str, value)
  84.     local strLen = string.len(str)
  85.     local valLen = string.len(value)
  86.     return string.sub(str, strLen - valLen + 1, strLen) == value
  87. end
  88.  
  89. function string.contains(str, value, startIndex)
  90.     if (startIndex == nil) then
  91.         startIndex = 1
  92.     end
  93.  
  94.     return string.find(str, value) ~= nil
  95. end
  96.  
  97. function string.indexOf(str, value, startIndex)
  98.     if (startIndex == nil) then
  99.         startIndex = 1
  100.     end
  101.  
  102.     local s, e, c = string.find(str, value)
  103.     if (s == nil) then
  104.         return -1
  105.     end
  106.  
  107.     return s
  108. end
  109.  
  110. -- Clamps the given string to the given length. `string.len(str)` is smaller than or equal to `maxLen` then `str` is returned. Otherwise, a substring of `maxLen - 3` of characters + `"..."` is returned
  111. function string.clamp(str, maxLen)
  112.     if (#str <= maxLen) then
  113.         return str
  114.     end
  115.  
  116.     return (string.sub(str, 1, maxLen - 3) .. "...")
  117. end
  118.  
  119. --endregion
  120.  
  121. utils = {
  122.     centerOf = function(start, ending)
  123.         if (start == ending) then
  124.             return start
  125.         elseif (start < ending) then
  126.             return math.floor((ending - start) / 2)
  127.         else
  128.             return math.floor((start - ending) / 2)
  129.         end
  130.     end,
  131.     centerForText = function(size, text)
  132.         local strLen = #text
  133.         if (strLen < 1) then
  134.             return math.floor(size / 2)
  135.         else
  136.             return math.floor((size / 2) - (strLen / 2))
  137.         end
  138.     end,
  139.     thatOrNull = function(nullable, nonNull)
  140.         if (nullable == nil) then return nonNull else return nullable end
  141.     end,
  142.     byteToMegaByte = function(bytes) return bytes / 1048576 end,
  143.     byteToKiloByte = function(bytes) return bytes / 1024 end,
  144.     byteToGigaByte = function(bytes) return bytes / 1073741824 end
  145. }
  146.  
  147. --region GUI Functions
  148.  
  149. GDI = {
  150.     Handle = term,
  151.     -- returns a non null text colour
  152.     nonNullTextColour = function(text_colour)
  153.         if (text_colour == nil) then
  154.             return colours.white
  155.         end
  156.  
  157.         return text_colour
  158.     end,
  159.     -- returns a non null background colour
  160.     nonNullBackgroundColour = function(background_colour)
  161.         if (background_colour == nil) then
  162.             return colours.black
  163.         end
  164.  
  165.         return background_colour
  166.     end,
  167.     -- sets the monitor cursor pos
  168.     cpos = function(x, y)
  169.         GDI.Handle.setCursorPos(x, y)
  170.     end,
  171.     -- sets the monitor text colour
  172.     textColour = function(colour)
  173.         GDI.Handle.setTextColor(colour)
  174.     end,
  175.     -- sets the monitor background colour
  176.     backgroundColour = function(colour)
  177.         GDI.Handle.setBackgroundColor(colour)
  178.     end,
  179.     clearBackground = function(foreground, background)
  180.         GDI.textColour(GDI.nonNullTextColour(foreground))
  181.         GDI.backgroundColour(GDI.nonNullBackgroundColour(background))
  182.         GDI.Handle.clear()
  183.     end,
  184.     clearMonitor = function()
  185.         GDI.clearBackground(colours.white, colours.black)
  186.     end,
  187.     -- draws text on the monitor
  188.     drawText = function(x, y, text, foreground, background)
  189.         GDI.textColour(GDI.nonNullTextColour(foreground))
  190.         GDI.backgroundColour(GDI.nonNullBackgroundColour(background))
  191.         GDI.cpos(x, y)
  192.         GDI.Handle.write(text)
  193.     end,
  194.     drawTextClamped = function(x, y, maxLength, text, foreground, background)
  195.         GDI.drawText(x, y, string.clamp(text, maxLength), foreground, background)
  196.     end,
  197.     drawTextCenteredClamped = function(x, y, w, h, text, foreground, background)
  198.         local theText = string.clamp(text, w)
  199.         local finalX = x + math.floor((w / 2) - (#text / 2))
  200.         local finalY = y + math.floor(h / 2)
  201.         GDI.drawText(finalX, finalY, theText, foreground, background)
  202.     end,
  203.     drawLineH = function(x, y, w, background)
  204.         GDI.drawText(x, y, string.rep(" ", w), background, background)
  205.     end,
  206.     drawLineV = function(x, y, h, background)
  207.         GDI.textColour(GDI.nonNullTextColour(background))
  208.         GDI.backgroundColour(GDI.nonNullBackgroundColour(background))
  209.         for i = y, h do
  210.             GDI.Handle.write(" ")
  211.             GDI.cpos(x, i)
  212.         end
  213.     end,
  214.     drawSquare = function(x, y, w, h, background)
  215.         local line = y
  216.         local endLine = y + h
  217.         while (true) do
  218.             GDI.drawLineH(x, line, w, background)
  219.             line = line + 1
  220.             if (line >= endLine) then
  221.                 return
  222.             end
  223.         end
  224.     end,
  225.     drawProgressBar = function(x, y, w, h, min, max, val, foreground, background)
  226.         GDI.drawSquare(x, y, w, h, background)
  227.         GDI.drawSquare(x, y, math.floor((val / (max - min)) * w), h, foreground)
  228.     end,
  229.     drawGroupBoxHeader = function(x, y, w, text, foreground, background)
  230.         local strLen = string.len(text)
  231.         if (strLen >= w) then
  232.             GDI.drawText(x, y, string.sub(text, 1, w), foreground, background)
  233.         elseif (strLen == (w - 1)) then
  234.             GDI.drawText(x, y, text .. "-", foreground, background)
  235.         elseif (strLen == (w - 2)) then
  236.             GDI.drawText(x, y, "-" .. text .. "-", foreground, background)
  237.         elseif (strLen == (w - 3)) then
  238.             GDI.drawText(x, y, "-" .. text .. " -", foreground, background)
  239.         else
  240.             local leftOverSpace = strLen - w
  241.             local halfLeftOver = leftOverSpace / 2
  242.             if (leftOverSpace % 2 == 0) then
  243.                 -- even
  244.                 local glyphText = string.rep("-", halfLeftOver - 1)
  245.                 GDI.drawText(x, y, glyphText .. " " .. text .. " " .. glyphText)
  246.             else
  247.                 -- odd
  248.                 local glyphTextA = string.rep("-", math.floor(halfLeftOver - 1))
  249.                 local glyphTextB = string.rep("-", math.ceil(halfLeftOver - 1))
  250.                 GDI.drawText(x, y, glyphTextA .. " " .. text .. " " .. glyphTextB)
  251.             end
  252.         end
  253.     end,
  254.     drawGroupBoxWall = function(x, y, h, foreground, background)
  255.         GDI.textColour(GDI.nonNullTextColour(foreground))
  256.         GDI.backgroundColour(GDI.nonNullBackgroundColour(background))
  257.         for i = y, h do
  258.             GDI.Handle.write("-")
  259.             GDI.cpos(x, i)
  260.         end
  261.     end,
  262.     drawGroupBoxFooter = function(x, y, w, foreground, background)
  263.         GDI.drawText(x, y, string.rep("-", w), foreground, background)
  264.     end,
  265.     drawGroupBox = function(x, y, w, h, header, border_foreground, border_background, background)
  266.         GDI.drawSquare(x, y, w, h, background)
  267.         GDI.drawGroupBoxHeader(x, y, w, header, border_foreground, border_background)
  268.         GDI.drawGroupBoxWall(x, y, h, border_foreground, border_background)
  269.         GDI.drawGroupBoxWall(x + w, y, h, border_foreground, border_background)
  270.         GDI.drawGroupBoxFooter(x, y + h, w, border_foreground, border_background)
  271.     end,
  272.     drawWindowTitle = function(x, y, w, title, foreground, background)
  273.         if (background == nil) then
  274.             background = colours.grey
  275.         end
  276.         local text = string.clamp(title, w - 5)
  277.         GDI.drawText(x, y, text, foreground, background)
  278.         local len = #text
  279.         local endX = x + w
  280.         GDI.drawLineH(x + len, y, w - len - 4, background)
  281.         GDI.drawText(endX - 4, y, "-", colours.foreground, colours.lightGrey)
  282.         GDI.drawText(endX - 3, y, "[]", colours.foreground, colours.lightGrey)
  283.         GDI.drawText(endX - 1, y, "x", colours.foreground, colours.red)
  284.     end,
  285.     drawWindow = function(x, y, w, h, title, titleForeground, titleBackground, background)
  286.         GDI.drawSquare(x, y, w, h, utils.thatOrNull(background, colours.white))
  287.         GDI.drawWindowTitle(x, y, w, title, utils.thatOrNull(titleForeground, colours.lightGrey), utils.thatOrNull(titleBackground, colours.grey))
  288.     end
  289. }
  290.  
  291. --endregion
  292.  
  293. app = {}
  294.  
  295. function app.IsPointInArea(absX, absY, minX, minY, width, height)
  296.     return absX >= minX and absX < (minX + width) and absY >= minY and absY < (minY + height)
  297. end
  298.  
  299. function app.GetAbsolutePosition(theComponent)
  300.     local x = theComponent.x
  301.     local y = theComponent.y
  302.     local parent = theComponent.parent
  303.     while (parent ~= nil) do
  304.         x = x + parent.x
  305.         y = y + parent.y
  306.         parent = parent.parent
  307.     end
  308.     return x, y
  309. end
  310.  
  311. function app.IsMouseOverComponent(theComponent, absX, absY)
  312.     local cX, cY = app.GetAbsolutePosition(theComponent)
  313.     return absX >= cX and absX < (cX + theComponent.w) and absY >= cY and absY < (cY + theComponent.h)
  314. end
  315.  
  316. function app.GetRelativeMousePos(component, mPosX, mPosY)
  317.     local absX, absY = app.GetAbsolutePosition(component)
  318.     return (mPosX - absX), (mPosY - absY)
  319. end
  320.  
  321. function app.SetupTimer(nTime)
  322.     AnimTimerId = os.startTimer(nTime)
  323. end
  324.  
  325. function app.UpdateCachedIndices(children)
  326.     for k, obj in pairs(children) do
  327.         obj.indexInParent = k
  328.     end
  329. end
  330.  
  331. function app.InsertComponent(parent, child)
  332.     if (child.IsInVisualTree == true) then
  333.         error("Child already added to visual tree. It must be removed first")
  334.         return
  335.     end
  336.  
  337.     local targetTable
  338.     if (parent == nil) then
  339.         targetTable = APP_ROOT_OBJECTS
  340.         child.parent = nil
  341.     else
  342.         if (parent.children == nil) then
  343.             parent.children = {}
  344.         end
  345.         targetTable = parent.children
  346.         child.parent = parent
  347.     end
  348.  
  349.     child.indexInParent = #table
  350.     table.insert(targetTable, child)
  351.     child.IsInVisualTree = true
  352.     app.UpdateCachedIndices(targetTable)
  353.     return child
  354. end
  355.  
  356. function app.RemoveFromParent(child)
  357.     if (child.IsInVisualTree ~= true or child.indexInParent == -1) then
  358.         return
  359.     end
  360.  
  361.     local children
  362.     if (child.parent == nil) then
  363.         children = APP_ROOT_OBJECTS
  364.     else
  365.         children = child.parent.children
  366.         if (children == nil) then
  367.             return
  368.         end
  369.     end
  370.  
  371.     table.remove(children, child.indexInParent)
  372.     app.UpdateCachedIndices(children)
  373. end
  374.  
  375. function app.RenderComponent(component, x, y)
  376.     if (component.RenderFunc ~= nil) then
  377.         component.RenderFunc(component, x, y)
  378.     end
  379.  
  380.     if (component.children ~= nil) then
  381.         for k, v in pairs(component.children) do
  382.             app.RenderComponent(v, x + v.x, y + v.y)
  383.         end
  384.     end
  385. end
  386.  
  387. -- function app.CleanChildrenTableForScheduledRemoval(theTable)
  388. --     for i = #theTable, 1, -1 do
  389. --         if (theTable[i].isScheduledForRemoval) then
  390. --             table.remove(theTable, i)
  391. --         end
  392. --     end
  393. -- end
  394.  
  395. function app.DoAnimationTick(component, time, delta)
  396.     component.IsUpdating = true
  397.     if (component.OnAnimTick ~= nil) then
  398.         component.OnAnimTick(component, time, delta)
  399.     end
  400.  
  401.     local children = component.children
  402.     if (children ~= nil) then
  403.         for k, comp in pairs(children) do
  404.             if (comp.IsInVisualTree == true) then
  405.                 app.DoAnimationTick(comp, time, delta)
  406.             end
  407.         end
  408.     end
  409.     component.IsUpdating = false
  410. end
  411.  
  412. core_component_button = {}
  413.  
  414. --#region Button Component
  415.  
  416. function core_component_button.DoAnimTick(this, time, delta)
  417.     if (this.IsButtonPressed and this.IsToggleButton == false) then
  418.         if (this.TimeToClearButtonPress ~= nil and time > this.TimeToClearButtonPress) then
  419.             this.IsButtonPressed = false
  420.         end
  421.     end
  422. end
  423.  
  424. function core_component_button.CoreOnMouseDown(this, time, delta, hit, btn, x, y)
  425.     if (this.IsToggleButton) then
  426.         if (this.IsButtonPressed) then
  427.             this.IsButtonPressed = false
  428.         else
  429.             this.IsButtonPressed = true
  430.         end
  431.     else
  432.         this.TimeToClearButtonPress = time + 0.6
  433.         this.IsButtonPressed = true
  434.     end
  435.  
  436.     LastDebugMessage = "Hit at: " .. x .. "," .. y
  437. end
  438.  
  439. function core_component_button.OnDrawButton(this, x, y)
  440.     local tColour
  441.     if (this.IsButtonPressed == true) then
  442.         tColour = this.PressedColour
  443.     else
  444.         tColour = this.BackgroundColour
  445.     end
  446.     GDI.drawSquare(x, y, this.w, this.h, tColour)
  447.     GDI.drawTextCenteredClamped(x, y, this.w, this.h, this.ButtonText, this.ForegroundColour, tColour)
  448. end
  449.  
  450. --#endregion
  451.  
  452. function app.Component_CreateCore(x, y, w, h)
  453.     local obj = {}
  454.     obj.x = x
  455.     obj.y = y
  456.     obj.w = w
  457.     obj.h = h
  458.     obj.OnPreviewMouseDown = {}
  459.     obj.OnMouseDown = {}
  460.     obj.OnPreviewMouseDrag = {}
  461.     obj.OnMouseDrag = {}
  462.     obj.OnPreviewKeyPressed = {}
  463.     obj.OnKeyPressed = {}
  464.     obj.OnPreviewCharPressed = {}
  465.     obj.OnCharPressed = {}
  466.     return obj
  467. end
  468.  
  469. function app.CreateButton(x, y, w, h, text, isToggleButton, onClicked)
  470.     local btn = app.Component_CreateCore(x, y, w, h)
  471.     btn.ButtonText = text
  472.     btn.OnAnimTick = core_component_button.DoAnimTick
  473.     btn.RenderFunc = core_component_button.OnDrawButton
  474.     table.insert(btn.OnMouseDown, core_component_button.CoreOnMouseDown)
  475.     if onClicked ~= nil then
  476.         table.insert(btn.OnMouseDown, onClicked)
  477.     end
  478.  
  479.     btn.IsButtonPressed = false
  480.     if (isToggleButton == nil) then
  481.         isToggleButton = false
  482.     end
  483.     btn.IsToggleButton = isToggleButton
  484.     btn.ForegroundColour = colours.white
  485.     btn.BackgroundColour = colours.lightGrey
  486.     btn.PressedColour = colours.green
  487.     return btn
  488. end
  489.  
  490. --region Application Entry Point and message handling
  491.  
  492. function app.DoTunnelMouseClick(component, time, delta, btn, absX, absY)
  493.     if (app.IsMouseOverComponent(component, absX, absY) ~= true) then
  494.         return nil
  495.     end
  496.  
  497.     if (component.OnPreviewMouseDown ~= nil) then
  498.         local relX, relY = app.GetRelativeMousePos(component, absX, absY)
  499.         for i, handler in pairs(component.OnPreviewMouseDown) do
  500.             if (handler(component, time, delta, btn, relX, relY)) then
  501.                 return component
  502.             end
  503.         end
  504.     end
  505.  
  506.     local items = component.children
  507.     if (items == nil) then
  508.         return component
  509.     end
  510.  
  511.     for i = #items, 1, -1  do
  512.         local hitObj = app.DoTunnelMouseClick(items[i], time, delta, btn, absX, absY)
  513.         if (hitObj ~= nil) then
  514.             return hitObj
  515.         end
  516.     end
  517.  
  518.     return component
  519. end
  520.  
  521. function app.DoBubbleMouseClick(component, originalComponent, time, delta, btn, absX, absY)
  522.     if (component.OnMouseDown ~= nil) then
  523.         local relX, relY = app.GetRelativeMousePos(component, absX, absY)
  524.         for i, handler in pairs(component.OnMouseDown) do
  525.             if (handler(component, time, delta, originalComponent, btn, relX, relY)) then
  526.                 return true
  527.             end
  528.         end
  529.     end
  530.  
  531.     if (component.parent == nil) then
  532.         return false
  533.     end
  534.  
  535.     return app.DoBubbleMouseClick(component.parent, originalComponent, time, delta, btn, absX, absY)
  536. end
  537.  
  538. function app.OnMouseClick(time, delta, btn, absX, absY)
  539.     local hitComponent = nil
  540.     for i = #APP_ROOT_OBJECTS, 1, -1 do
  541.         hitComponent = app.DoTunnelMouseClick(APP_ROOT_OBJECTS[i], time, delta, btn, absX, absY)
  542.         if (hitComponent ~= nil) then
  543.             break
  544.         end
  545.     end
  546.  
  547.     if (hitComponent ~= nil) then
  548.         app.DoBubbleMouseClick(hitComponent, hitComponent, time, delta, btn, absX, absY)
  549.     end
  550. end
  551.  
  552. -- TODO: implement these
  553.  
  554. function app.OnMouseDrag(time, delta, btn, absX, absY)
  555.  
  556. end
  557.  
  558. function app.OnKeyPress(time, delta, keyCode)
  559.  
  560. end
  561.  
  562. function app.OnCharPress(time, delta, ch)
  563.  
  564. end
  565.  
  566. -- Application Tick. This may be called extremely frequently during events
  567. -- such as mouse dragging, key events, etc. But this is also called during the
  568. -- application timer event, which is classed as a render tick
  569. --
  570. -- The time parameter is the os time (seconds since the computer started)
  571. --
  572. -- The delta parameter is the time since the last tick. Usually this is the
  573. -- tick rate interval, but it may be exactly 1 server tick if something like
  574. -- a mouse drag event came in
  575. function OnApplicationMessage(time, delta, eventType, p1, p2, p3, p4, p5)
  576.     if (IS_DEBUG_MODE == true) then
  577.         term.clear()
  578.         term.setCursorPos(1, 1)
  579.         term.write("System Timer: " .. time)
  580.         term.setCursorPos(1, 2)
  581.         term.write(tostring(eventType))
  582.         term.setCursorPos(1, 3)
  583.         term.write(tostring(p1))
  584.         term.setCursorPos(1, 4)
  585.         term.write(tostring(p2))
  586.         term.setCursorPos(1, 5)
  587.         term.write(tostring(p3))
  588.         term.setCursorPos(1, 6)
  589.         term.write(tostring(p4))
  590.         term.setCursorPos(1, 7)
  591.         term.write(tostring(p5))
  592.         return
  593.     end
  594.  
  595.     if (IsAnimationTick) then
  596.         -- tick animations
  597.         for k, obj in pairs(APP_ROOT_OBJECTS) do
  598.             app.DoAnimationTick(obj, time, delta)
  599.         end
  600.  
  601.         -- render application
  602.         GDI.clearMonitor()
  603.         for k, obj in pairs(APP_ROOT_OBJECTS) do
  604.             app.RenderComponent(obj, obj.x, obj.y)
  605.         end
  606.  
  607.         GDI.drawText(1, 19, LastDebugMessage)
  608.     else
  609.         if (eventType == "mouse_click") then
  610.             app.OnMouseClick(time, delta, p1, p2, p3)
  611.         elseif (eventType == "mouse_drag") then
  612.             app.OnMouseDrag(time, delta, p1, p2, p3)
  613.         elseif (eventType == "key") then
  614.             app.OnKeyPress(time, delta, p1)
  615.         elseif (eventType == "char") then
  616.             app.OnCharPress(time, delta, p1)
  617.         end
  618.     end
  619. end
  620.  
  621. function AppMain()
  622.     GDI.clearMonitor()
  623.     -- load GUI components onto screen
  624.     app.InsertComponent(nil, app.CreateButton(1, 1, 16, 3, "Copy Template", false))
  625.     app.InsertComponent(nil, app.CreateButton(18, 4, 16, 3, "Paste Template", false))
  626.  
  627.     -- Application event/message loop. no need to modify this!!!
  628.     app.SetupTimer(AnimIntervalSecs)
  629.     while true do
  630.         local eType, p1, p2, p3, p4, p5 = os.pullEventRaw()
  631.         local osTime = os.clock()
  632.         if (eType == "terminate") then
  633.             GDI.clearMonitor()
  634.             GDI.drawText(1, 1, "Application Terminated", colours.white, colours.red)
  635.             term.setCursorPos(1, 2)
  636.             break
  637.         end
  638.  
  639.         if (eType == "timer" and p1 == AnimTimerId) then
  640.             app.SetupTimer(AnimIntervalSecs)
  641.             IsAnimationTick = true
  642.         end
  643.  
  644.         OnApplicationMessage(osTime, osTime - AppLastTickTime, eType, p1, p2, p3, p4, p5)
  645.         AppLastTickTime = osTime
  646.         IsAnimationTick = false
  647.     end
  648. end
  649.  
  650. --endregion
  651.  
  652. AppMain()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement