Permalink
Browse files

finally removed model.pos

  • Loading branch information...
1 parent ab70171 commit 8685498f7448a55ac7f2f68e3d066fc593f62f8b @torii-y torii-y committed Nov 17, 2016
View
@@ -25,7 +25,7 @@ cache =
defaultUserState : Language -> UserState
defaultUserState lang =
{ scale = Scale.default
- , offset = (35, 35)
+ , offset = { x = 35, y = 35 }
, lang = lang
}
@@ -57,19 +57,25 @@ clear cache =
Cache.clear cache
+type alias Position =
+ { x : Int
+ , y : Int
+ }
+
+
type alias UserState =
{ scale : Scale
- , offset : (Int, Int)
+ , offset : Position
, lang : Language
}
decode : Decoder UserState
decode =
D.object3
- (\scale offset lang ->
+ (\scale (x, y) lang ->
{ scale = Scale.init scale
- , offset = offset
+ , offset = { x = x, y = y }
, lang = if lang == "JA" then I18n.JA else I18n.EN
}
)
@@ -83,7 +89,7 @@ encode : UserState -> Value
encode state =
E.object
[ ("scale", E.int state.scale.scaleDown)
- , ("offset", E.list [ E.int (fst state.offset), E.int (snd state.offset) ] )
+ , ("offset", E.list [ E.int state.offset.x, E.int state.offset.y ] )
, ("lang", E.string <| case state.lang of
JA -> "JA"
EN -> "EN"
@@ -177,10 +177,14 @@ moveObjects gridSize (dx, dy) object =
(x, y, _, _) =
Object.rect object
- (newX, newY) =
- ObjectsOperation.fitPositionToGrid gridSize (x + dx, y + dy)
+ new =
+ ObjectsOperation.fitPositionToGrid
+ gridSize
+ { x = x + dx
+ , y = y + dy
+ }
in
- Object.move (newX, newY) object
+ Object.move (new.x, new.y) object
paste : List (Object, ObjectId) -> (Int, Int) -> Floor -> Floor
@@ -7,6 +7,10 @@ import Model.Object as Object exposing (Object)
type alias FloorId = String
type alias ObjectId = String
+type alias Position =
+ { x : Int
+ , y : Int
+ }
rectFloat : Object -> (Float, Float, Float, Float)
@@ -313,14 +317,18 @@ minBoundsOf positions =
) (99999, 99999) positions
-fitPositionToGrid : Int -> (Int, Int) -> (Int, Int)
-fitPositionToGrid gridSize (x, y) =
- (x // gridSize * gridSize, y // gridSize * gridSize)
+fitPositionToGrid : Int -> Position -> Position
+fitPositionToGrid gridSize { x, y } =
+ { x = x // gridSize * gridSize
+ , y = y // gridSize * gridSize
+ }
fitSizeToGrid : Int -> (Int, Int) -> (Int, Int)
fitSizeToGrid gridSize (x, y) =
- (x // gridSize * gridSize, y // gridSize * gridSize)
+ ( x // gridSize * gridSize
+ , y // gridSize * gridSize
+ )
backgroundColorProperty : List Object -> Maybe String
@@ -1,25 +1,35 @@
module Model.ProfilePopupLogic exposing (..)
import Model.Scale as Scale exposing (Scale)
-import Model.Object as Object exposing (..)
+import Model.Object as Object exposing (Object)
-centerTopScreenXYOfObject : Scale -> (Int, Int) -> Object -> (Int, Int)
-centerTopScreenXYOfObject scale (offsetX, offsetY) object =
+type alias Position =
+ { x : Int
+ , y : Int
+ }
+
+
+centerTopScreenXYOfObject : Scale -> Position -> Object -> Position
+centerTopScreenXYOfObject scale offset object =
let
(x, y, w, h) =
- rect object
+ Object.rect object
in
- Scale.imageToScreenForPosition scale (offsetX + x + w//2, offsetY + y)
+ Scale.imageToScreenForPosition
+ scale
+ { x = offset.x + x + w//2
+ , y = offset.y + y
+ }
-bottomScreenYOfObject : Scale -> (Int, Int) -> Object -> Int
-bottomScreenYOfObject scale (offsetX, offsetY) object =
+bottomScreenYOfObject : Scale -> Position -> Object -> Int
+bottomScreenYOfObject scale offset object =
let
(x, y, w, h) =
- rect object
+ Object.rect object
in
- Scale.imageToScreen scale (offsetY + y + h)
+ Scale.imageToScreen scale (offset.y + y + h)
calcPopupLeftFromObjectCenter : Int -> Int -> Int
@@ -37,31 +47,33 @@ calcPopupTopFromObjectTop popupHeight objTop =
objTop - (popupHeight + 10)
-adjustOffset : (Int, Int) -> (Int, Int) -> Scale -> (Int, Int) -> Object -> (Int, Int)
-adjustOffset (containerWidth, containerHeight) (popupWidth, popupHeight) scale (offsetX, offsetY) object =
+adjustOffset : (Int, Int) -> (Int, Int) -> Scale -> Position -> Object -> Position
+adjustOffset (containerWidth, containerHeight) (popupWidth, popupHeight) scale offset object =
let
- (objCenter, objTop) =
- centerTopScreenXYOfObject scale (offsetX, offsetY) object
+ objCenterTop =
+ centerTopScreenXYOfObject scale offset object
left =
- calcPopupLeftFromObjectCenter popupWidth objCenter
+ calcPopupLeftFromObjectCenter popupWidth objCenterTop.x
top =
- calcPopupTopFromObjectTop popupHeight objTop
+ calcPopupTopFromObjectTop popupHeight objCenterTop.y
right =
- calcPopupRightFromObjectCenter popupWidth objCenter
+ calcPopupRightFromObjectCenter popupWidth objCenterTop.x
bottom =
- bottomScreenYOfObject scale (offsetX, offsetY) object
+ bottomScreenYOfObject scale offset object
- offsetX' =
- adjust scale containerWidth left right offsetX
+ offsetX_ =
+ adjust scale containerWidth left right offset.x
- offsetY' =
- adjust scale containerHeight top bottom offsetY
+ offsetY_ =
+ adjust scale containerHeight top bottom offset.y
in
- (offsetX', offsetY')
+ { x = offsetX_
+ , y = offsetY_
+ }
adjust : Scale -> Int -> Int -> Int -> Int -> Int
@@ -16,6 +16,12 @@ type alias Prototypes =
}
+type alias Position =
+ { x : Int
+ , y : Int
+ }
+
+
gridSize : Int
gridSize = 8 --TODO
@@ -125,9 +131,14 @@ generateAllCandidatePosition (deskWidth, deskHeight) (centerLeft, centerTop) (in
List.concatMap (\left -> List.map (\top -> (left, top)) tops) lefts
-positionedPrototypesOnDragging : Int -> Prototype -> (Int, Int) -> (Int, Int) -> List PositionedPrototype
-positionedPrototypesOnDragging gridSize prototype (x1, y1) (x2, y2) = -- imagePos
+positionedPrototypesOnDragging : Int -> Prototype -> Position -> Position -> List PositionedPrototype
+positionedPrototypesOnDragging gridSize prototype xy1 xy2 = -- imagePos
let
+ x1 = xy1.x
+ y1 = xy1.y
+ x2 = xy2.x
+ y2 = xy2.y
+
deskSize = (prototype.width, prototype.height)
flip (w, h) = (h, w)
@@ -141,13 +152,17 @@ positionedPrototypesOnDragging gridSize prototype (x1, y1) (x2, y2) = -- imagePo
(indicesX, indicesY) =
stampIndices horizontal (deskWidth, deskHeight) (x1, y1) (x2, y2)
- (centerLeft, centerTop) =
- ObjectsOperation.fitPositionToGrid gridSize (x1 - fst deskSize // 2, y1 - snd deskSize // 2)
+ center =
+ ObjectsOperation.fitPositionToGrid
+ gridSize
+ { x = x1 - fst deskSize // 2
+ , y = y1 - snd deskSize // 2
+ }
all =
generateAllCandidatePosition
(deskWidth, deskHeight)
- (centerLeft, centerTop)
+ (center.x, center.y)
(indicesX, indicesY)
prototype' =
@@ -9,6 +9,12 @@ type alias Scale =
}
+type alias Position =
+ { x : Int
+ , y : Int
+ }
+
+
default : Scale
default = init 0
@@ -29,16 +35,18 @@ update msg scale =
{ scale | scaleDown = min 4 (scale.scaleDown + 1) }
-screenToImageForPosition : Scale -> (Int, Int) -> (Int, Int)
-screenToImageForPosition scale (screenX, screenY) =
- ( screenToImage scale screenX
- , screenToImage scale screenY)
+screenToImageForPosition : Scale -> Position -> Position
+screenToImageForPosition scale screenPosition =
+ { x = screenToImage scale screenPosition.x
+ , y = screenToImage scale screenPosition.y
+ }
-imageToScreenForPosition : Scale -> (Int, Int) -> (Int, Int)
-imageToScreenForPosition scale (imageX, imageY) =
- ( imageToScreen scale imageX
- , imageToScreen scale imageY)
+imageToScreenForPosition : Scale -> Position -> Position
+imageToScreenForPosition scale imagePosition =
+ { x = imageToScreen scale imagePosition.x
+ , y = imageToScreen scale imagePosition.y
+ }
imageToScreenForRect : Scale -> (Int, Int, Int, Int) -> (Int, Int, Int, Int)
@@ -39,15 +39,18 @@ type alias Position =
adjustImagePositionOfMovingObject : Int -> Scale -> Position -> Position -> Position -> Position
adjustImagePositionOfMovingObject gridSize scale start end from =
let
- (dx, dy) =
- Scale.screenToImageForPosition scale ((end.x - start.x), (end.y - start.y))
-
- (toX, toY) =
- ObjectsOperation.fitPositionToGrid gridSize (from.x + dx, from.y + dy)
+ shift =
+ Scale.screenToImageForPosition
+ scale
+ { x = end.x - start.x
+ , y = end.y - start.y
+ }
in
- { x = toX
- , y = toY
- }
+ ObjectsOperation.fitPositionToGrid
+ gridSize
+ { x = from.x + shift.x
+ , y = from.y + shift.y
+ }
type alias ObjectViewOption =
@@ -214,12 +217,10 @@ canvasView model floor =
canvasViewStyles : Model -> Floor -> List (String, String)
canvasViewStyles model floor =
let
- (offsetX, offsetY) = model.offset
-
rect =
Scale.imageToScreenForRect
model.scale
- (offsetX, offsetY, Floor.width floor, Floor.height floor)
+ (model.offset.x, model.offset.y, Floor.width floor, Floor.height floor)
in
if (Mode.isPrintMode model.mode) then
S.canvasViewForPrint (model.windowSize.width, model.windowSize.height) rect
@@ -405,8 +406,8 @@ temporaryStampView scale selected (prototype, (left, top)) =
temporaryPenView : Model -> Html msg
temporaryPenView model =
case model.draggingContext of
- PenFromScreenPos (x, y) ->
- case Model.temporaryPen model (x, y) of
+ PenFromScreenPos start ->
+ case Model.temporaryPen model start of
Just (color, name, (left, top, width, height)) ->
ObjectView.viewDesk
ObjectView.noEvents
Oops, something went wrong.

0 comments on commit 8685498

Please sign in to comment.