add ability to move from normal mode to move mode, and from move mode back to normal mode
This commit is contained in:
@@ -7,9 +7,6 @@ struct
|
|||||||
|
|
||||||
(* todo: resize message, escape button to go back to normal mode *)
|
(* todo: resize message, escape button to go back to normal mode *)
|
||||||
|
|
||||||
fun makeBlankYAxis length =
|
|
||||||
Vector.tabulate (length, fn _ => {r = 0, g = 0, b = 0, a = 0})
|
|
||||||
|
|
||||||
fun getDrawMsg (model: app_type) =
|
fun getDrawMsg (model: app_type) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
@@ -40,6 +37,9 @@ struct
|
|||||||
(model, [DRAW drawMsg])
|
(model, [DRAW drawMsg])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun makeBlankYAxis length =
|
||||||
|
Vector.tabulate (length, fn _ => {r = 0, g = 0, b = 0, a = 0})
|
||||||
|
|
||||||
fun moveImageUp (model: app_type) =
|
fun moveImageUp (model: app_type) =
|
||||||
let
|
let
|
||||||
val {squares, ...} = model
|
val {squares, ...} = model
|
||||||
@@ -79,8 +79,10 @@ struct
|
|||||||
val squares =
|
val squares =
|
||||||
Vector.mapi
|
Vector.mapi
|
||||||
(fn (idx, yAxis) =>
|
(fn (idx, yAxis) =>
|
||||||
if idx = 0 then makeBlankYAxis (Vector.length squares)
|
if idx + 1 = Vector.length squares then
|
||||||
else Vector.sub (squares, idx - 1)) squares
|
makeBlankYAxis (Vector.length squares)
|
||||||
|
else
|
||||||
|
Vector.sub (squares, idx + 1)) squares
|
||||||
|
|
||||||
val model = AppWith.squares (model, squares)
|
val model = AppWith.squares (model, squares)
|
||||||
in
|
in
|
||||||
@@ -94,21 +96,25 @@ struct
|
|||||||
val squares =
|
val squares =
|
||||||
Vector.mapi
|
Vector.mapi
|
||||||
(fn (idx, yAxis) =>
|
(fn (idx, yAxis) =>
|
||||||
if idx + 1 = Vector.length squares then
|
if idx = 0 then makeBlankYAxis (Vector.length squares)
|
||||||
makeBlankYAxis (Vector.length squares)
|
else Vector.sub (squares, idx - 1)) squares
|
||||||
else
|
|
||||||
Vector.sub (squares, idx + 1)) squares
|
|
||||||
|
|
||||||
val model = AppWith.squares (model, squares)
|
val model = AppWith.squares (model, squares)
|
||||||
in
|
in
|
||||||
getDrawMsg model
|
getDrawMsg model
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun enterNormalMode model =
|
||||||
|
let val model = AppWith.mode (model, AppType.NORMAL_MODE)
|
||||||
|
in (model, [])
|
||||||
|
end
|
||||||
|
|
||||||
fun update (model, inputMsg) =
|
fun update (model, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
ARROW_UP => moveImageUp model
|
ARROW_UP => moveImageUp model
|
||||||
| ARROW_DOWN => moveImageDown model
|
| ARROW_DOWN => moveImageDown model
|
||||||
| ARROW_LEFT => moveImageLeft model
|
| ARROW_LEFT => moveImageLeft model
|
||||||
| ARROW_RIGHT => moveImageRight model
|
| ARROW_RIGHT => moveImageRight model
|
||||||
|
| KEY_ESC => enterNormalMode model
|
||||||
| _ => (model, [])
|
| _ => (model, [])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -336,6 +336,11 @@ struct
|
|||||||
(model, fileMsg)
|
(model, fileMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun enterMoveMode model =
|
||||||
|
let val model = AppWith.mode (model, AppType.MOVE_MODE)
|
||||||
|
in (model, [])
|
||||||
|
end
|
||||||
|
|
||||||
fun handleFileBrowserAndPathInNormalMode (model, fileBrowser, path) =
|
fun handleFileBrowserAndPathInNormalMode (model, fileBrowser, path) =
|
||||||
let val model = AppWith.fileBrowserAndPath (model, fileBrowser, path)
|
let val model = AppWith.fileBrowserAndPath (model, fileBrowser, path)
|
||||||
in (model, [])
|
in (model, [])
|
||||||
@@ -356,6 +361,7 @@ struct
|
|||||||
| KEY_A => updateAlpha model
|
| KEY_A => updateAlpha model
|
||||||
| KEY_W => updateCanvasWidth model
|
| KEY_W => updateCanvasWidth model
|
||||||
| KEY_H => updateCanvasHeight model
|
| KEY_H => updateCanvasHeight model
|
||||||
|
| KEY_M => enterMoveMode model
|
||||||
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
|
| RESIZE_WINDOW {width, height} => resizeWindow (model, width, height)
|
||||||
| UNDO_ACTION => undoAction model
|
| UNDO_ACTION => undoAction model
|
||||||
| REDO_ACTION => redoAction model
|
| REDO_ACTION => redoAction model
|
||||||
@@ -377,4 +383,5 @@ struct
|
|||||||
| KEY_SPACE => enterOrSpaceCoordinates model
|
| KEY_SPACE => enterOrSpaceCoordinates model
|
||||||
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
| FILE_BROWSER_AND_PATH {fileBrowser, path} =>
|
||||||
handleFileBrowserAndPathInNormalMode (model, fileBrowser, path)
|
handleFileBrowserAndPathInNormalMode (model, fileBrowser, path)
|
||||||
|
| KEY_ESC => (model, [])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ int KEY_A = GLFW_KEY_A;
|
|||||||
int KEY_W = GLFW_KEY_W;
|
int KEY_W = GLFW_KEY_W;
|
||||||
int KEY_H = GLFW_KEY_H;
|
int KEY_H = GLFW_KEY_H;
|
||||||
int KEY_C = GLFW_KEY_C;
|
int KEY_C = GLFW_KEY_C;
|
||||||
|
int KEY_M = GLFW_KEY_M;
|
||||||
|
|
||||||
int KEY_ENTER = GLFW_KEY_ENTER;
|
int KEY_ENTER = GLFW_KEY_ENTER;
|
||||||
int KEY_SPACE = GLFW_KEY_SPACE;
|
int KEY_SPACE = GLFW_KEY_SPACE;
|
||||||
@@ -31,6 +32,7 @@ int KEY_LEFT = GLFW_KEY_LEFT;
|
|||||||
int KEY_RIGHT = GLFW_KEY_RIGHT;
|
int KEY_RIGHT = GLFW_KEY_RIGHT;
|
||||||
int KEY_DOWN = GLFW_KEY_DOWN;
|
int KEY_DOWN = GLFW_KEY_DOWN;
|
||||||
int KEY_BACKSPACE = GLFW_KEY_BACKSPACE;
|
int KEY_BACKSPACE = GLFW_KEY_BACKSPACE;
|
||||||
|
int KEY_ESC = GLFW_KEY_ESCAPE;
|
||||||
|
|
||||||
int KEY_0 = GLFW_KEY_0;
|
int KEY_0 = GLFW_KEY_0;
|
||||||
int KEY_1 = GLFW_KEY_1;
|
int KEY_1 = GLFW_KEY_1;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ struct
|
|||||||
_symbol "KEY_B" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_B" public : ( unit -> int ) * ( int -> unit );
|
||||||
val (KEY_C, _) =
|
val (KEY_C, _) =
|
||||||
_symbol "KEY_C" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_C" public : ( unit -> int ) * ( int -> unit );
|
||||||
|
val (KEY_M, _) =
|
||||||
|
_symbol "KEY_M" public : ( unit -> int ) * ( int -> unit );
|
||||||
|
|
||||||
val (KEY_T, _) =
|
val (KEY_T, _) =
|
||||||
_symbol "KEY_T" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_T" public : ( unit -> int ) * ( int -> unit );
|
||||||
@@ -78,6 +80,8 @@ struct
|
|||||||
_symbol "KEY_DOWN" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_DOWN" public : ( unit -> int ) * ( int -> unit );
|
||||||
val (KEY_BACKSPACE, _) =
|
val (KEY_BACKSPACE, _) =
|
||||||
_symbol "KEY_BACKSPACE" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_BACKSPACE" public : ( unit -> int ) * ( int -> unit );
|
||||||
|
val (KEY_ESC, _) =
|
||||||
|
_symbol "KEY_ESC" public : ( unit -> int ) * ( int -> unit );
|
||||||
|
|
||||||
val (KEY_0, _) =
|
val (KEY_0, _) =
|
||||||
_symbol "KEY_0" public : ( unit -> int ) * ( int -> unit );
|
_symbol "KEY_0" public : ( unit -> int ) * ( int -> unit );
|
||||||
|
|||||||
@@ -164,6 +164,14 @@ struct
|
|||||||
key = Input.KEY_9 () andalso action = Input.PRESS () andalso mods = 0
|
key = Input.KEY_9 () andalso action = Input.PRESS () andalso mods = 0
|
||||||
then
|
then
|
||||||
Mailbox.send (mailbox, NUM 9)
|
Mailbox.send (mailbox, NUM 9)
|
||||||
|
else if
|
||||||
|
key = Input.KEY_ESC () andalso action = Input.PRESS () andalso mods = 0
|
||||||
|
then
|
||||||
|
Mailbox.send (mailbox, KEY_ESC)
|
||||||
|
else if
|
||||||
|
key = Input.KEY_M () andalso action = Input.PRESS () andalso mods = 0
|
||||||
|
then
|
||||||
|
Mailbox.send (mailbox, KEY_M)
|
||||||
else
|
else
|
||||||
()
|
()
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ struct
|
|||||||
| KEY_A
|
| KEY_A
|
||||||
| KEY_W
|
| KEY_W
|
||||||
| KEY_H
|
| KEY_H
|
||||||
|
| KEY_M
|
||||||
| KEY_BACKSPACE
|
| KEY_BACKSPACE
|
||||||
| KEY_CTRL_S
|
| KEY_CTRL_S
|
||||||
| KEY_CTRL_L
|
| KEY_CTRL_L
|
||||||
| KEY_CTRL_E
|
| KEY_CTRL_E
|
||||||
| KEY_CTRL_O
|
| KEY_CTRL_O
|
||||||
| KEY_CTRL_C
|
| KEY_CTRL_C
|
||||||
|
| KEY_ESC
|
||||||
| NUM of int
|
| NUM of int
|
||||||
| ARROW_UP
|
| ARROW_UP
|
||||||
| ARROW_LEFT
|
| ARROW_LEFT
|
||||||
|
|||||||
Reference in New Issue
Block a user