reduce number of type conversoins required for mouse move callback (and fix the other code which uses it too)

This commit is contained in:
2024-08-01 21:17:39 +01:00
parent 39b8b45b45
commit 0fc6201231
7 changed files with 7 additions and 7 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -157,7 +157,7 @@ typedef Pointer Objptr;
extern "C" { extern "C" {
#endif #endif
MLLIB_PUBLIC(void mltonMouseMoveCallback (Int32 x0, Int32 x1);) MLLIB_PUBLIC(void mltonMouseMoveCallback (Real32 x0, Real32 x1);)
MLLIB_PUBLIC(void mltonMouseClickCallback (Int32 x0, Int32 x1);) MLLIB_PUBLIC(void mltonMouseClickCallback (Int32 x0, Int32 x1);)
#undef MLLIB_PRIVATE #undef MLLIB_PRIVATE

View File

@@ -7,7 +7,7 @@ int LEFT_MOUSE_BUTTON = GLFW_MOUSE_BUTTON_1;
// Calls function exported from SML // Calls function exported from SML
void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) { void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) {
mltonMouseMoveCallback((int)xpos, (int)ypos); mltonMouseMoveCallback((float)xpos, (float)ypos);
} }
void mouseClickCallback(GLFWwindow *window, int button, int action, int mods) { void mouseClickCallback(GLFWwindow *window, int button, int action, int mods) {

View File

@@ -4,7 +4,7 @@ struct
(* Export function to C. *) (* Export function to C. *)
val exportMouseMoveCallback = val exportMouseMoveCallback =
_export "mltonMouseMoveCallback" public : (int * int -> unit) -> unit; _export "mltonMouseMoveCallback" public : (Real32.real * Real32.real -> unit) -> unit;
(* Import function to set callback for GLFW. *) (* Import function to set callback for GLFW. *)
val setMouseMoveCallback = _import "setMouseMoveCallback" public reentrant : window -> unit; val setMouseMoveCallback = _import "setMouseMoveCallback" public reentrant : window -> unit;

View File

@@ -90,7 +90,7 @@ struct
*) *)
fun getClickPos (mouseX, mouseY, r, g, b) = fun getClickPos (mouseX, mouseY, r, g, b) =
getHorizontalClickPos getHorizontalClickPos
(0, Real32.fromInt mouseX, Real32.fromInt mouseY, r, g, b) (0, mouseX, mouseY, r, g, b)
end end
fun getFirstTriangleStageVector (x1, y1, drawVec) = fun getFirstTriangleStageVector (x1, y1, drawVec) =

View File

@@ -15,7 +15,7 @@ struct
end end
in in
fun update (inputMailbox, drawMailbox) = fun update (inputMailbox, drawMailbox) =
loop (inputMailbox, drawMailbox, 0, 0, AppType.initial) loop (inputMailbox, drawMailbox, 0.0, 0.0, AppType.initial)
end end
fun draw fun draw

View File

@@ -1,7 +1,7 @@
signature INPUT_MESSAGE = signature INPUT_MESSAGE =
sig sig
datatype t = datatype t =
MOUSE_MOVE of {x: int, y: int} MOUSE_MOVE of {x: Real32.real, y: Real32.real}
| MOUSE_LEFT_CLICK | MOUSE_LEFT_CLICK
| MOUSE_LEFT_RELEASE | MOUSE_LEFT_RELEASE
end end
@@ -9,7 +9,7 @@ end
structure InputMessage :> INPUT_MESSAGE = structure InputMessage :> INPUT_MESSAGE =
struct struct
datatype t = datatype t =
MOUSE_MOVE of {x: int, y: int} MOUSE_MOVE of {x: Real32.real, y: Real32.real}
| MOUSE_LEFT_CLICK | MOUSE_LEFT_CLICK
| MOUSE_LEFT_RELEASE | MOUSE_LEFT_RELEASE
end end