diff --git a/dotscape b/dotscape index a1a8b1f..95450d8 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-init.sml b/fcore/app-init.sml index 056a7b2..97488e5 100644 --- a/fcore/app-init.sml +++ b/fcore/app-init.sml @@ -18,8 +18,9 @@ struct , canvasHeight ) : app_type = let - val xClickPoints = ClickPoints.generate (wStart, wFinish, canvasWidth) - val yClickPoints = ClickPoints.generate (hStart, hFinish, canvasHeight) + val (xClickPoints, yClickPoints) = + ClickPoints.generate + (windowWidth, windowHeight, canvasWidth, canvasHeight) val maxPoints = Int.max (canvasWidth, canvasHeight) val squares = Vector.tabulate (maxPoints, fn _ => diff --git a/fcore/app-with.sml b/fcore/app-with.sml index 505e211..dd849fc 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -160,9 +160,7 @@ struct } end - fun helpWindowResize - (app: app_type, windowWidth, windowHeight, wStart, wFinish, hStart, hFinish) : - app_type = + fun windowResize (app: app_type, windowWidth, windowHeight) : app_type = let val { mode @@ -188,9 +186,9 @@ struct , modalNum } = app - val maxPoints = Int.max (canvasWidth, canvasHeight) - val xClickPoints = ClickPoints.generate (wStart, wFinish, maxPoints) - val yClickPoints = ClickPoints.generate (hStart, hFinish, maxPoints) + val (xClickPoints, yClickPoints) = + ClickPoints.generate + (windowWidth, windowHeight, canvasWidth, canvasHeight) in { mode = mode , squares = squares @@ -216,29 +214,6 @@ struct } end - fun windowResize (app: app_type, windowWidth, windowHeight) = - if windowWidth = windowHeight then - helpWindowResize - (app, windowWidth, windowHeight, 0, windowWidth, 0, windowHeight) - else if windowWidth > windowHeight then - let - val difference = windowWidth - windowHeight - val wStart = difference div 2 - val wFinish = wStart + windowHeight - in - helpWindowResize - (app, windowWidth, windowHeight, wStart, wFinish, 0, windowHeight) - end - else - let - val difference = windowHeight - windowWidth - val hStart = difference div 2 - val hFinish = hStart + windowWidth - in - helpWindowResize - (app, windowWidth, windowHeight, 0, windowWidth, hStart, hFinish) - end - fun mousePosition (app: app_type, mouseX, mouseY) = let val diff --git a/fcore/click-points.sml b/fcore/click-points.sml index ed711c7..20a645f 100644 --- a/fcore/click-points.sml +++ b/fcore/click-points.sml @@ -1,12 +1,23 @@ structure ClickPoints = struct - fun generate (start, finish, numPoints) = + fun generate (windowWidth, windowHeight, canvasWidth, canvasHeight) = let - val difference = finish - start - val increment = Real32.fromInt difference / Real32.fromInt numPoints + val realWindowWidth = Real32.fromInt windowWidth + val realCanvasWidth = Real32.fromInt canvasWidth + val realWindowHeight = Real32.fromInt windowHeight + val realCanvasHeight = Real32.fromInt canvasHeight + + val xPixelSize = realWindowWidth / realCanvasWidth + val yPixelSize = realWindowHeight / realCanvasHeight + + val pixelSize = Real32.min (xPixelSize, yPixelSize) + + val xClickPoints = Vector.tabulate (canvasWidth + 1, fn i => + Real32.fromInt i * pixelSize) + val yClickPoints = Vector.tabulate (canvasHeight + 1, fn i => + Real32.fromInt i * pixelSize) in - Vector.tabulate (numPoints + 1, fn idx => - (Real32.fromInt idx * increment)) + (xClickPoints, yClickPoints) end fun getClickPos (clickPoints, mousePos, idx) =