structure AppWith = struct open AppType fun updateSquares (squares, newX, newY, item) = Vector.mapi (fn (idx, el) => if idx = newX then Vector.mapi (fn (iidx, iel) => if iidx = newY then item else iel) el else el) squares 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 addSquare (app, newX, newY, arrowX, arrowY) : app_type = let val { mode , squares , arrowX = _ , arrowY = _ , canvasWidth , canvasHeight , windowWidth , windowHeight , xClickPoints , yClickPoints , showGraph , mouseX , mouseY , openFilePath , fileBrowser , fileBrowserIdx , r , g , b , a , modalNum , undo , redo } = app val yAxis = Vector.sub (squares, newX) val undoData = Vector.sub (yAxis, newY) val undo = undoData :: undo val redo = [] val item = {r = r, g = g, b = b, a = a} val squares = updateSquares (squares, newX, newY, item) 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = modalNum , undo = undo , redo = redo } 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 , modalNum = prevNum , undo , redo } = 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 , modalNum = newNum , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } 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 = _ , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } 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 , modalNum , undo , redo } = 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 , modalNum = 0 , undo = undo , redo = redo } end (* todo: fun useSquaresAndSetNormalMode (app: app_type, squares, canvasWidth, canvasHeight) = *) end