structure AppWith = struct open AppType fun changeSquaresSize (squares, newCanvasWidth, newCanvasHeight) = let val maxPoints = Int.max (newCanvasWidth, newCanvasHeight) in Vector.tabulate (maxPoints, fn i => if i < Vector.length squares then let val yAxis = Vector.sub (squares, i) in Vector.tabulate (maxPoints, fn ii => if ii < Vector.length yAxis then Vector.sub (yAxis, ii) else {r = 0, g = 0, b = 0, a = 0}) end else Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})) end fun squares (app, newSquares) = let val { mode , squares , arrowX , arrowY , canvasWidth , canvasHeight , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , squares = newSquares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , mouseX = mouseX , mouseY = mouseY , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun arrowX (app, arrowX) = let val { mode , squares , arrowX = _ , arrowY , canvasWidth , canvasHeight , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , mouseX = mouseX , mouseY = mouseY , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun arrowY (app, arrowY) = let val { mode , squares , arrowX , arrowY = _ , canvasWidth , canvasHeight , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , mouseX = mouseX , mouseY = mouseY , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun windowResize (app: app_type, windowWidth, windowHeight) : app_type = let val { mode , xClickPoints = _ , yClickPoints = _ , windowWidth = _ , windowHeight = _ , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app val (xClickPoints, yClickPoints) = ClickPoints.generate (windowWidth, windowHeight, canvasWidth, canvasHeight) in { mode = mode , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , mouseX = mouseX , mouseY = mouseY , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun mousePosition (app: app_type, mouseX, mouseY) = let val { mode , mouseX = _ , mouseY = _ , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun graphVisibility (app: app_type, shouldShowGraph) = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph = _ , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = shouldShowGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun mode (app: app_type, newMode) = let val { mode = _ , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = newMode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun fileBrowserAndPath (app: app_type, fileBrowser, path) = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath = _ , fileBrowser = _ , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = path , fileBrowser = fileBrowser , fileBrowserIdx = 0 , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun fileBrowserIdx (app: app_type, newFileBrowserIdx) = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx = _ , r , g , b , a , layer , layerTree , modalNum } = app in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = newFileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun modalNum (app: app_type, newNum) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum = prevNum } = app val newNum = (prevNum * 10) + newNum in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = newNum } end fun r (app: app_type) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r = _ , g , b , a , layer , layerTree , modalNum } = app val r = Int.min (modalNum, 255) in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun g (app: app_type) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g = _ , b , a , layer , layerTree , modalNum } = app val g = Int.min (modalNum, 255) in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun b (app: app_type) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b = _ , a , layer , layerTree , modalNum } = app val b = Int.min (modalNum, 255) in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun a (app: app_type) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a = _ , layer , layerTree , modalNum } = app val a = Int.min (modalNum, 255) in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun layer (app: app_type) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX , arrowY , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer = _ , layerTree , modalNum } = app val layer = modalNum in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun layerTree (app: app_type, layerTree, arrowX, arrowY) : app_type = let val { mode , mouseX , mouseY , xClickPoints , yClickPoints , windowWidth , windowHeight , squares , arrowX = _ , arrowY = _ , canvasWidth , canvasHeight , showGraph , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree = _ , modalNum } = app in { mode = mode , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowX = arrowX , arrowY = arrowY , canvasWidth = canvasWidth , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = modalNum } end fun canvasWidth (app: app_type, newCanvasWidth) = let val { mode , canvasWidth = _ , squares , arrowX , arrowY , canvasHeight , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app val squares = changeSquaresSize (squares, newCanvasWidth, canvasHeight) val arrowX = Int.min (arrowX, newCanvasWidth) val (xClickPoints, yClickPoints) = ClickPoints.generate (windowWidth, windowHeight, newCanvasWidth, canvasHeight) in { mode = mode , canvasWidth = newCanvasWidth , arrowX = arrowX , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowY = arrowY , canvasHeight = canvasHeight , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun canvasHeight (app: app_type, newCanvasHeight) = let val { mode , canvasHeight = _ , canvasWidth , squares , arrowX , arrowY , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app val squares = changeSquaresSize (squares, canvasWidth, newCanvasHeight) val arrowY = Int.min (arrowY, newCanvasHeight) val (xClickPoints, yClickPoints) = ClickPoints.generate (windowWidth, windowHeight, canvasWidth, newCanvasHeight) in { mode = mode , canvasHeight = newCanvasHeight , canvasWidth = canvasWidth , arrowX = arrowX , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowY = arrowY , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun useSquares (app: app_type, squares, canvasWidth, canvasHeight) = let val { mode , canvasHeight = _ , canvasWidth = _ , squares = _ , arrowX , arrowY , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , layer , layerTree , modalNum } = app val arrowX = Int.min (arrowX, canvasWidth) val arrowY = Int.min (arrowY, canvasHeight) val (xClickPoints, yClickPoints) = ClickPoints.generate (windowWidth, windowHeight, canvasWidth, canvasHeight) in { mode = mode , canvasHeight = canvasHeight , canvasWidth = canvasWidth , arrowX = arrowX , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowY = arrowY , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end fun cursorColour (app, r, g, b, a) = let val { mode , canvasHeight , canvasWidth , squares , arrowX , arrowY , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r = _ , g = _ , b = _ , a = _ , layer , layerTree , modalNum } = app in { mode = mode , canvasHeight = canvasHeight , canvasWidth = canvasWidth , arrowX = arrowX , mouseX = mouseX , mouseY = mouseY , squares = squares , arrowY = arrowY , windowWidth = windowWidth , windowHeight = windowHeight , xClickPoints = xClickPoints , yClickPoints = yClickPoints , showGraph = showGraph , openFilePath = openFilePath , fileBrowser = fileBrowser , fileBrowserIdx = fileBrowserIdx , r = r , g = g , b = b , a = a , layer = layer , layerTree = layerTree , modalNum = 0 } end end