module TD.Data.MaskPosition
( MaskPosition(..)
, defaultMaskPosition
) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.MaskPoint as MaskPoint
data MaskPosition
= MaskPosition
{ MaskPosition -> Maybe MaskPoint
point :: Maybe MaskPoint.MaskPoint
, MaskPosition -> Maybe Double
x_shift :: Maybe Double
, MaskPosition -> Maybe Double
y_shift :: Maybe Double
, MaskPosition -> Maybe Double
scale :: Maybe Double
}
deriving (MaskPosition -> MaskPosition -> Bool
(MaskPosition -> MaskPosition -> Bool)
-> (MaskPosition -> MaskPosition -> Bool) -> Eq MaskPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MaskPosition -> MaskPosition -> Bool
== :: MaskPosition -> MaskPosition -> Bool
$c/= :: MaskPosition -> MaskPosition -> Bool
/= :: MaskPosition -> MaskPosition -> Bool
Eq, Int -> MaskPosition -> ShowS
[MaskPosition] -> ShowS
MaskPosition -> String
(Int -> MaskPosition -> ShowS)
-> (MaskPosition -> String)
-> ([MaskPosition] -> ShowS)
-> Show MaskPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MaskPosition -> ShowS
showsPrec :: Int -> MaskPosition -> ShowS
$cshow :: MaskPosition -> String
show :: MaskPosition -> String
$cshowList :: [MaskPosition] -> ShowS
showList :: [MaskPosition] -> ShowS
Show)
instance I.ShortShow MaskPosition where
shortShow :: MaskPosition -> String
shortShow MaskPosition
{ point :: MaskPosition -> Maybe MaskPoint
point = Maybe MaskPoint
point_
, x_shift :: MaskPosition -> Maybe Double
x_shift = Maybe Double
x_shift_
, y_shift :: MaskPosition -> Maybe Double
y_shift = Maybe Double
y_shift_
, scale :: MaskPosition -> Maybe Double
scale = Maybe Double
scale_
}
= String
"MaskPosition"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"point" String -> Maybe MaskPoint -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MaskPoint
point_
, String
"x_shift" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
x_shift_
, String
"y_shift" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
y_shift_
, String
"scale" String -> Maybe Double -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Double
scale_
]
instance AT.FromJSON MaskPosition where
parseJSON :: Value -> Parser MaskPosition
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"maskPosition" -> Value -> Parser MaskPosition
parseMaskPosition Value
v
String
_ -> Parser MaskPosition
forall a. Monoid a => a
mempty
where
parseMaskPosition :: A.Value -> AT.Parser MaskPosition
parseMaskPosition :: Value -> Parser MaskPosition
parseMaskPosition = String
-> (Object -> Parser MaskPosition) -> Value -> Parser MaskPosition
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"MaskPosition" ((Object -> Parser MaskPosition) -> Value -> Parser MaskPosition)
-> (Object -> Parser MaskPosition) -> Value -> Parser MaskPosition
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe MaskPoint
point_ <- Object
o Object -> Key -> Parser (Maybe MaskPoint)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"point"
Maybe Double
x_shift_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"x_shift"
Maybe Double
y_shift_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"y_shift"
Maybe Double
scale_ <- Object
o Object -> Key -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"scale"
MaskPosition -> Parser MaskPosition
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (MaskPosition -> Parser MaskPosition)
-> MaskPosition -> Parser MaskPosition
forall a b. (a -> b) -> a -> b
$ MaskPosition
{ point :: Maybe MaskPoint
point = Maybe MaskPoint
point_
, x_shift :: Maybe Double
x_shift = Maybe Double
x_shift_
, y_shift :: Maybe Double
y_shift = Maybe Double
y_shift_
, scale :: Maybe Double
scale = Maybe Double
scale_
}
parseJSON Value
_ = Parser MaskPosition
forall a. Monoid a => a
mempty
instance AT.ToJSON MaskPosition where
toJSON :: MaskPosition -> Value
toJSON MaskPosition
{ point :: MaskPosition -> Maybe MaskPoint
point = Maybe MaskPoint
point_
, x_shift :: MaskPosition -> Maybe Double
x_shift = Maybe Double
x_shift_
, y_shift :: MaskPosition -> Maybe Double
y_shift = Maybe Double
y_shift_
, scale :: MaskPosition -> Maybe Double
scale = Maybe Double
scale_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"maskPosition"
, Key
"point" Key -> Maybe MaskPoint -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe MaskPoint
point_
, Key
"x_shift" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
x_shift_
, Key
"y_shift" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
y_shift_
, Key
"scale" Key -> Maybe Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Double
scale_
]
defaultMaskPosition :: MaskPosition
defaultMaskPosition :: MaskPosition
defaultMaskPosition =
MaskPosition
{ point :: Maybe MaskPoint
point = Maybe MaskPoint
forall a. Maybe a
Nothing
, x_shift :: Maybe Double
x_shift = Maybe Double
forall a. Maybe a
Nothing
, y_shift :: Maybe Double
y_shift = Maybe Double
forall a. Maybe a
Nothing
, scale :: Maybe Double
scale = Maybe Double
forall a. Maybe a
Nothing
}