- 學號:R11922101
- 系級:資工碩一
- 姓名:黃嘉宏
- My code for HW2 is put under the subfolder
create_your_own
, and is linked from theCREATE YOUR OWN
link on the website from HW1. - My code works no matter how many
div
s there are.
- mouse-click on a
div
- mouse-click on workarea, not on any objects
- mouse down on a
div
and move (dragging mode)-
div
start moving, following the mouse, until mouse-up. - This way of moving should not change the selected
div
.
-
- mouse double-click (following mode)
- Starts a mode in which this
div
follows the mouse. - The
div
should stop following the mouse on the next mouse up event. - While in this mode, all other mouse behaviors on the
div
s should be suspended.
- Starts a mode in which this
-
ESC
keydown- The moving or growing should be aborted.
- The
div
should go back to the way it was before the operation starts.
- one-finger tap and double-tap
- Do the same thing as mouse-click, dragging and mouse-double-click.
- Double tap (following-the-finger mode): When you do touchstart, the
div
follows the finger even if the touch is not on the object, until touchend. - Touchend does not stop the mode, so the next touchstart continues to move the same
div
. This mode only ends with a click action. - If the user puts down another finger in the following-the-finger mode, then this should be aborted (same as
ESC
keydown).
- two-finger touch
- Resizing in horizontal direction.
- If one finger is released but the other stays on the screen, this should stop the size change as it last was (just stop growing but not abort).
- If the finger goes back into contact before the other finger lets up, the div can go back to changing size.
- If a third finger is put down on the surface, this should abort the change size and go back to the original size before the change size started.
- Minimum width and height for the
div
(20pt
fo each).
- Resizing in either horizontal or vertical directions.
- Depending on the orientation of the fingers when they both touch the surface.
Three global variables is used to switch between states:
isDown
- Controls the move and reset operations in dragging mode and following mode.
- Set to
false
by default. - Set to
true
on mousedown. - Set to
false
on mouseup.
isClicked
- Controls whether all selected
div
s should be cleared. - Set to
false
by default. - Set to
true
on click event of adiv
. - Set to
false
on click event of the workspace.
- Controls whether all selected
clickWorks
- Controls whether to change selected
div
when anotherdiv
is clicked. - Set to
true
by default. - Set to
false
when in dragging mode and following mode. - Set to
true
after adiv
or the workspace is clicked.
- Controls whether to change selected
The variable touchState
is used to store the current state of the process. There are eight states:
pending
- Default mode.
- On touchmove event of a
div
, change todraggingTarget
state. - On touchend event of one-finger tap on a
div
, change totouchingTarget
state. - On touchend event of double-tap on a
div
, change todoubleTouchingTarget
state.
focused
- A
div
is selected and can be further operated. - On touchstart of the workspace, if a two-finger touch is detected, change to
resizing
state. - On touchend event of one-finger tap on a
div
, change totouchingTarget
state. - On touchend event of double-tap on a
div
, change todoubleTouchingTarget
state. - On touchend event of the workspace, change to
pending
state.
- A
touchingTarget
- Touched but no further changes.
- On touchend event of the workspace, change to
focused
state.
doubleTouchingTarget
- A
div
is double touched but not yet start moving. - On touchend event of the workspace, change to
movingTarget
state.
- A
movingTarget
- A
div
is double-tapped and in the following-the-finger mode. - On touchend event of the workspace:
- If another finger is put down (Aborted), change to
focused
state. - If a click action (touchstart and touchend quickly in the same place) is detected, change to
pending
state.
- If another finger is put down (Aborted), change to
- A
draggingTarget
- If a
div
is moved and not inabortDragging
state, the state will change todraggingTarget
state. In this state, thediv
is in dragging mode and can be dragged. - On touchend event of the workspace:
- If another finger is put down (Aborted), change to
abortDragging
state. - Else if there is a selected
div
, change tofocused
state. - Else, change to
pending
state.
- If another finger is put down (Aborted), change to
- If a
abortDragging
- The dragging mode is aborted, and further moving is disabled.
- On touchend event of a
div
:- If there is a selected
div
, change tofocused
state. - Else, change to
pending
state.
- If there is a selected
resizing
- The selected
div
is in resizing mode and can be resized in either horizontal and vertical directions. - On touchstart event of a
div
, if a third-finger touch is detected, change tofocused
state. - On touchend event of the workspace, if all fingers have left the screen (
e.touches.length == 0
), change tofocused
state.
- The selected
- Resizing on boundary: Any resizing attempts to make the
div
out of the boundary of the screen will just be ignored, but the resizing mode continues, in case the user moves their fingers further apart again.