Skip to content
Snippets Groups Projects
Commit 925ba2d6 authored by Abdulhasib's avatar Abdulhasib
Browse files

Ellipse ist zu shapes hinzugefügt.

Man kann Ellipse auch zeichnen / löschen.
parent cb350468
No related branches found
No related tags found
No related merge requests found
......@@ -62,21 +62,25 @@ updateInput inputType value modal modalType iShape ix iy mouse =
Empty -> modal -- ERROR
Circle _ b c -> modalInputConstruktor modalType (Circle value b c ) ix iy mouse
Rectangle _ b c d -> modalInputConstruktor modalType (Rectangle value b c d) ix iy mouse
Ellipse _ b c d -> modalInputConstruktor modalType (Ellipse value b c d) ix iy mouse
Polygon _ -> modalInputConstruktor modalType iShape value iy mouse
'2' -> case iShape of
Empty -> modal -- ERROR
Circle a _ c -> modalInputConstruktor modalType (Circle a value c ) ix iy mouse
Rectangle a _ c d -> modalInputConstruktor modalType (Rectangle a value c d) ix iy mouse
Ellipse a _ c d -> modalInputConstruktor modalType (Ellipse a value c d) ix iy mouse
Polygon _ -> modalInputConstruktor modalType iShape ix value mouse
'3' -> case iShape of
Empty -> modal -- ERROR
Circle a b _ -> modalInputConstruktor modalType (Circle a b value ) ix iy mouse
Rectangle a b _ d -> modalInputConstruktor modalType (Rectangle a b value d) ix iy mouse
Ellipse a b _ d -> modalInputConstruktor modalType (Ellipse a b value d) ix iy mouse
Polygon _ -> modal -- ERROR
'4' -> case iShape of
Empty -> modal -- ERROR
Circle _ _ _ -> modal -- ERROR
Rectangle a b c _ -> modalInputConstruktor modalType (Rectangle a b c value) ix iy mouse
Ellipse a b c _ -> modalInputConstruktor modalType (Ellipse a b c value) ix iy mouse
Polygon _ -> modal -- ERROR
_ -> modal -- ERROR
-- Modal Construktors
......
......@@ -78,6 +78,21 @@ updateModel msg model =
in { model | saved = (Rectangle coords.x coords.y coords.w coords.h)::model.saved
, state = Standby
}
Ellipse a b w h ->
if a==""
then { model | state = DrawShape
(Ellipse (String.fromInt mPos.x) (String.fromInt mPos.y) w h)
mPos
}
else let coords = manageRectCoords
{x= a
,y= b
,w= (abstand1D mPos.x (stringToInt a))
,h= (abstand1D mPos.y (stringToInt b))
}
in { model | saved = (Ellipse coords.x coords.y coords.w coords.h)::model.saved
, state = Standby
}
Polygon pList -> { model | state = DrawShape
(Polygon (( String.fromInt mPos.x
, String.fromInt mPos.y
......@@ -128,6 +143,7 @@ updateCmdMsg msg model =
"https://users.informatik.uni-halle.de/~hinnebur/fenster-liste.json"else
"https://users.informatik.uni-halle.de/~hinnebur/tueren-liste.json")
, expect = Http.expectJson ShapesLoaded rectListDecoder
--, expect = Http.expectJson ShapesLoaded ellipseListDecoder
}
else Cmd.none
Err e -> Cmd.none
......
......@@ -4,8 +4,8 @@ import Html exposing (Html, Attribute, div, text, node, button, a, h1
import Html.Attributes exposing (class, style, href, rel, id, title, value)
import Html.Events exposing (onClick, onInput)
-- Svg
import Svg exposing (Svg,svg, image,rect,circle,polygon,g)
import Svg.Attributes exposing (width,height, viewBox, version, xlinkHref, x, y, cx, cy, r)
import Svg exposing (Svg,svg, image,rect,ellipse,circle,polygon,g)
import Svg.Attributes exposing (width,height, viewBox, version, xlinkHref, x, y, cx, cy,rx,ry, r)
import Svg.Events
-- Own
import TypeHolder exposing (Model,Msg(..))
......@@ -102,6 +102,10 @@ viewHeader_Buttons state =
, onClick (OpenDrawShape (Rectangle "" "" "" ""))
, href ""
] [text "Rechteck"]
, a [class "dropdown-item"
, onClick (OpenDrawShape (Ellipse "" "" "" ""))
, href ""
] [text "Ellipse"]
, a [class "dropdown-item"
, onClick (OpenDrawShape (Polygon []))
, href ""
......@@ -130,6 +134,21 @@ viewImage model =
if x=="" then circle [cx (String.fromInt mPos.x)
, cy (String.fromInt mPos.y), r "5"] []
else circle [cx x, cy y, r (abstand x y mPos)] []
Ellipse a b w h ->
if a=="" then ellipse [ cx (String.fromInt mPos.x)
, cy (String.fromInt mPos.y)
, rx "10", ry "10"] []
else let coords = manageEllipseCoords
{x= a
,y= b
,w= (abstand1D mPos.x (stringToInt a))
,h= (abstand1D mPos.y (stringToInt b))
}
in ellipse [ cx coords.x
, cy coords.y
, rx coords.w
, ry coords.h
] []
Rectangle a b w h ->
if a=="" then rect [ x (String.fromInt mPos.x)
, y (String.fromInt mPos.y)
......@@ -195,6 +214,10 @@ viewNewShapeInputModal iShape ix iy =
, onClick (ManageModal (Check "Rectangle") "")
, href ""
] [text "Rechteck"]
, a [ class "dropdown-item"
, onClick (ManageModal (Check "Ellipse") "")
, href ""
] [text "Ellipse"]
, a [ class "dropdown-item"
, onClick (ManageModal (Check "Polygon" ) "")
, href ""
......@@ -235,6 +258,22 @@ viewNewShapeInputModal iShape ix iy =
, value d, onInput (ManageModal (Input '4' "")) ] [] ]
]
]
Ellipse a b c d ->
[ div []
[ label [class "label"] [text "X1-Position-"]
, label [] [ input [class "input", Html.Attributes.placeholder "X1-Position"
, value a, onInput (ManageModal (Input '1' "")) ] [] ]
, label [class "label"] [text "Y1-Position"]
, label [] [ input [class "input", Html.Attributes.placeholder "Y1-Position"
, value b, onInput (ManageModal (Input '2' "")) ] [] ]
, label [class "label"] [text "X2-Position"]
, label [] [ input [class "input", Html.Attributes.placeholder "X2-Position"
, value c, onInput (ManageModal (Input '3' "")) ] [] ]
, label [class "label"] [text "Y2-Position"]
, label [] [ input [class "input", Html.Attributes.placeholder "Y2-Position"
, value d, onInput (ManageModal (Input '4' "")) ] [] ]
]
]
Polygon _ ->
[ div []
[ label [class "label"] [text "X-Position"]
......@@ -322,6 +361,8 @@ viewSvgShapes shapes activeShape id =
++svgShapeStyle activeShape id) []
Rectangle a b c d -> rect ([Svg.Attributes.x a, y b, width c, height d ]
++svgShapeStyle activeShape id) []
Ellipse a b c d -> ellipse ([Svg.Attributes.cx a, cy b, rx c, ry d ]
++svgShapeStyle activeShape id) []
Polygon pointList -> polygon([Svg.Attributes.points (shapeCoordsToHtmlCoords x)]
++svgShapeStyle activeShape id) []
)::viewSvgShapes xs activeShape (id+1)
......
......@@ -6,6 +6,7 @@ type Shape
= Empty
| Circle String String String
| Rectangle String String String String
| Ellipse String String String String
| Polygon (List ( String, String ) )
type ShapesMsg
......@@ -26,6 +27,7 @@ shapeDefaultConstruktor shape =
case shape of
"Circle" -> Circle "" "" ""
"Rectangle"-> Rectangle "" "" "" ""
"Ellipse" -> Ellipse "" "" "" ""
"Polygon" -> Polygon []
_ -> Empty
shapesDecoder : String -> List Shape
......@@ -47,6 +49,13 @@ shapesDecoder s =
(shapesDecoderList "rectangle" "height" s)
]
else []
, if (String.contains "Ellipse" s)
then [ Ellipse (shapesDecoderList "Ellipse" "cx" s)
(shapesDecoderList "Ellipse" "cy" s)
(shapesDecoderList "Ellipse" "rx" s)
(shapesDecoderList "Ellipse" "ry" s)
]
else []
, if (String.contains "polygon" s)
then [ Polygon (List.map2 Tuple.pair
(shapesDecoderListPoly "x" s)
......@@ -64,6 +73,7 @@ deleteCoordsFromShape shape =
Empty -> Empty
Circle _ _ _ -> Circle "" "" ""
Rectangle _ _ _ _ -> Rectangle "" "" "" ""
Ellipse _ _ _ _ -> Ellipse "" "" "" ""
Polygon _ -> Polygon []
-- Get Methods : Parameter of Shapes
getPointListFromPolygon : Shape -> List (String,String)
......@@ -72,6 +82,7 @@ getPointListFromPolygon shape =
Empty -> []
Circle _ _ _ -> []
Rectangle _ _ _ _ -> []
Ellipse _ _ _ _ -> []
Polygon pointList -> pointList
-- Transform Shape to other Types
shapeNameToString : Shape -> String
......@@ -80,6 +91,7 @@ shapeNameToString shape =
Empty -> ""
Circle _ _ _ -> "Circle"
Rectangle _ _ _ _ -> "Rectangle"
Ellipse _ _ _ _ -> "Ellipse"
Polygon _ -> "Polygon"
shapeNameStringToGerman : String -> String
shapeNameStringToGerman shape =
......@@ -87,6 +99,7 @@ shapeNameStringToGerman shape =
"Circle" -> "Kreis"
"Rectangle"-> "Rechteck"
"Polygon" -> "Vieleck"
"Ellipse" -> "Ellipse"
_ -> ""
shapeCoordsToString : Shape -> String
shapeCoordsToString shape =
......@@ -94,6 +107,7 @@ shapeCoordsToString shape =
Empty -> ""
Circle x_center y_center radius -> x_center++","++y_center++","++radius
Rectangle x_left y_upper x_right y_lower -> x_left++","++y_upper++","++x_right++","++y_lower
Ellipse x_left y_upper x_right y_lower -> x_left++","++y_upper++","++x_right++","++y_lower
Polygon pointList ->
case pointList of
[] -> ""
......@@ -104,6 +118,7 @@ shapeCoordsToHtmlCoords shape =
Empty -> ""
Circle _ _ _ -> shapeCoordsToString shape
Rectangle _ _ _ _ -> shapeCoordsToString shape
Ellipse _ _ _ _ -> shapeCoordsToString shape
Polygon _ -> String.left ((String.length (shapeCoordsToHtmlCoordsHelper shape))-1)
(shapeCoordsToHtmlCoordsHelper shape)
shapeCoordsToHtmlCoordsHelper : Shape -> String
......@@ -112,6 +127,7 @@ shapeCoordsToHtmlCoordsHelper shape =
Empty -> ""
Circle _ _ _ -> shapeCoordsToString shape
Rectangle _ _ _ _ -> shapeCoordsToString shape
Ellipse _ _ _ _ -> shapeCoordsToString shape
Polygon pointList ->
case pointList of
[] -> ""
......@@ -126,6 +142,15 @@ rectListDecoder = JD.field "rectangle" (JD.list (JD.map4
(JD.field "height" JD.string)
)
)
ellipseListDecoder : JD.Decoder (List Shape)
ellipseListDecoder = JD.field "ellipse" (JD.list (JD.map4
Ellipse
(JD.field "cx" JD.string)
(JD.field "cy" JD.string)
(JD.field "rx" JD.string)
(JD.field "ry" JD.string)
)
)
shapesDecoderList : String -> String -> String -> String
shapesDecoderList shape var s =
let res = JD.decodeString
......
......@@ -46,6 +46,25 @@ manageRectCoords coords =
else if h>0
then {x=String.fromInt (x+w),y=String.fromInt y ,w=String.fromInt -w,h=String.fromInt h}
else {x=String.fromInt (x+w),y=String.fromInt (y+h),w=String.fromInt -w,h=String.fromInt -h}
type alias EllipseCoords =
{ x : String
, y : String
, w : String
, h : String
}
manageEllipseCoords : EllipseCoords -> EllipseCoords
manageEllipseCoords coords =
let x = stringToInt coords.x
y = stringToInt coords.y
w = stringToInt coords.w
h = stringToInt coords.h
in if w>0
then if h>0
then coords
else {x=String.fromInt x ,y=String.fromInt (y+h),w=String.fromInt w,h=String.fromInt -h}
else if h>0
then {x=String.fromInt (x+w),y=String.fromInt y ,w=String.fromInt -w,h=String.fromInt h}
else {x=String.fromInt (x+w),y=String.fromInt (y+h),w=String.fromInt -w,h=String.fromInt -h}
-- Transformation between elm-types
stringToInt : String -> Int
stringToInt a = Maybe.withDefault 0 (String.toInt a)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment