structure AppWith = struct open AppType 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 , modalNum } = app val squares = Vector.mapi (fn (idx, el) => if idx = newX then Vector.mapi (fn (iidx, iel) => if iidx = newY then 1 else iel) el else el) squares 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , 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 , modalNum = newNum } end fun modalNumToFloat num = Real32.fromInt num / 255.0 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 , modalNum } = app val r = modalNumToFloat 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 , modalNum = modalNum } 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 , modalNum } = app val g = modalNumToFloat 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 , modalNum = modalNum } 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 = _ , modalNum } = app val b = modalNumToFloat 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 , modalNum = modalNum } end (* todo: fun useSquaresAndSetNormalMode (app: app_type, squares, canvasWidth, canvasHeight) = *) end