progress towards resizing
This commit is contained in:
@@ -178,8 +178,8 @@ struct
|
||||
, yClickPoints = _
|
||||
, triangles
|
||||
, triangleStage
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, windowWidth = _
|
||||
, windowHeight = _
|
||||
} = app
|
||||
|
||||
val xClickPoints = genClickPoints (wStart, wFinish)
|
||||
|
||||
@@ -43,22 +43,76 @@ struct
|
||||
windowWidth, windowHeight)
|
||||
else
|
||||
let
|
||||
(* calculate normalised device coordinates *)
|
||||
val halfWidth = Real32.fromInt (windowWidth div 2)
|
||||
val halfHeight = Real32.fromInt (windowHeight div 2)
|
||||
val hpos = horizontalPos - halfWidth
|
||||
val vpos = ~(curVerticalPos - halfHeight)
|
||||
|
||||
(* coordinates to form small box around clicked area *)
|
||||
val left = (hpos - 5.0) / halfWidth
|
||||
val right = (hpos + 5.0) / halfWidth
|
||||
val bottom = (vpos - 5.0) / halfHeight
|
||||
val top = (vpos + 5.0) / halfHeight
|
||||
|
||||
(* normalised device coordinates of drawVec should be relative
|
||||
* to actual windowWidth and windowHeight,
|
||||
* even if not a square, to display cursor position... *)
|
||||
val drawVec = ltrbToVertex (left, top, right, bottom, r, g, b)
|
||||
|
||||
in
|
||||
(*
|
||||
* ...however, normalised device coordinate of hpos and vpos
|
||||
* should be relative to the vertical centre
|
||||
* (if height is greater than width)
|
||||
* or horizontal centre
|
||||
* (if width is greater than height).
|
||||
*
|
||||
* So, for example, a 900x1000 resolution
|
||||
* will have clickable points from 50...950,
|
||||
* in increments of 50.
|
||||
* Because we always want to show canvas as a square
|
||||
* with an aspect ratio of 1:1.
|
||||
* For displaying the click position on the screen, drawVec
|
||||
* which uses actual windowWidth and windowHeight, is fine.
|
||||
* However, we want to attach the meaning "start" to 50
|
||||
* and "end" to 950,
|
||||
* so the hpos and vpos stored in the app's triangle list
|
||||
* subtracts the offset 50 if needed,
|
||||
* allowing us to treat the coordinates as a 900x900 square.
|
||||
*
|
||||
* We may not actually want to render a square to the screen
|
||||
* if the screen's aspect ratio is not 1:1,
|
||||
* but it's the responsibility of the rendering code
|
||||
* which turns triangles into OpenGL vectors
|
||||
* to do that.
|
||||
* *)
|
||||
if windowWidth = windowHeight then
|
||||
let
|
||||
val hpos = hpos / halfWidth
|
||||
val vpos = vpos / halfHeight
|
||||
in
|
||||
(drawVec, hpos, vpos)
|
||||
end
|
||||
else if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
val offset = Real32.fromInt (difference div 2)
|
||||
val hpos = hpos / (halfWidth - offset)
|
||||
val vpos = vpos / halfHeight
|
||||
in
|
||||
(drawVec, hpos, vpos)
|
||||
end
|
||||
else
|
||||
(* windowHeight > windowWidth *)
|
||||
let
|
||||
val difference = windowHeight - windowWidth
|
||||
val offset = Real32.fromInt (difference div 2)
|
||||
val hpos = hpos / halfWidth
|
||||
val vpos = vpos / (halfHeight - offset)
|
||||
in
|
||||
(drawVec, hpos, vpos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fun getHorizontalClickPos (xClickPoints, yClickPoints, idx, mouseX, mouseY,
|
||||
|
||||
Reference in New Issue
Block a user