module Graphics.Blank.Types.Cursor where
import Data.Monoid
import Data.String (IsString(..))
import qualified Data.Text as TS (Text)
import Data.Text (pack)
import Graphics.Blank.JavaScript
import Graphics.Blank.Parser (stringCI, unlift)
import Prelude.Compat
import Text.ParserCombinators.ReadP (ReadP, (<++), between, char,
choice, munch, skipSpaces)
import Text.ParserCombinators.ReadPrec (lift)
import Text.Read (Read(..), readListPrecDefault)
import TextShow
class CanvasCursor a where
jsCanvasCursor :: a -> Builder
instance CanvasCursor TS.Text where
jsCanvasCursor = jsText
instance CanvasCursor Cursor where
jsCanvasCursor = jsCursor
data Cursor = Auto
| Default
| None
| ContextMenu
| Help
| Pointer
| Progress
| Wait
| Cell
| Crosshair
| Text
| VerticalText
| Alias
| Copy
| Move
| NoDrop
| NotAllowed
| AllScroll
| ColResize
| RowResize
| NResize
| EResize
| SResize
| WResize
| NEResize
| NWResize
| SEResize
| SWResize
| EWResize
| NSResize
| NESWResize
| NWSEResize
| ZoomIn
| ZoomOut
| Grab
| Grabbing
| URL TS.Text Cursor
deriving (Eq, Ord)
instance IsString Cursor where
fromString = read
instance JSArg Cursor where
showbJS = jsCursor
jsCursor :: Cursor -> Builder
jsCursor = jsLiteralBuilder . showb
instance Read Cursor where
readPrec = lift $ do
skipSpaces
choice
[ Auto <$ stringCI "auto"
, Default <$ stringCI "default"
, None <$ stringCI "none"
, ContextMenu <$ stringCI "context-menu"
, Help <$ stringCI "help"
, Pointer <$ stringCI "pointer"
, Progress <$ stringCI "progress"
, Wait <$ stringCI "wait"
, Cell <$ stringCI "cell"
, Crosshair <$ stringCI "crosshair"
, Text <$ stringCI "text"
, VerticalText <$ stringCI "vertical-text"
, Alias <$ stringCI "alias"
, Copy <$ stringCI "copy"
, Move <$ stringCI "move"
, NoDrop <$ stringCI "no-drop"
, NotAllowed <$ stringCI "not-allowed"
, AllScroll <$ stringCI "all-scroll"
, ColResize <$ stringCI "col-resize"
, RowResize <$ stringCI "row-resize"
, NResize <$ stringCI "n-resize"
, EResize <$ stringCI "e-resize"
, SResize <$ stringCI "s-resize"
, WResize <$ stringCI "w-resize"
, NEResize <$ stringCI "ne-resize"
, NWResize <$ stringCI "nw-resize"
, SEResize <$ stringCI "se-resize"
, SWResize <$ stringCI "sw-resize"
, EWResize <$ stringCI "ew-resize"
, NSResize <$ stringCI "ns-resize"
, NESWResize <$ stringCI "nesw-resize"
, NWSEResize <$ stringCI "nwse-resize"
, ZoomIn <$ stringCI "zoom-in"
, ZoomOut <$ stringCI "zoom-out"
, Grab <$ stringCI "grab"
, Grabbing <$ stringCI "grabbing"
, do _ <- stringCI "url("
let quoted quote = between (char quote) (char quote)
url' <- quoted '"' (readURL $ Just '"')
<++ quoted '\'' (readURL $ Just '\'')
<++ readURL Nothing
_ <- char ')'
skipSpaces
_ <- char ','
URL url' <$> unlift readPrec
]
readListPrec = readListPrecDefault
readURL :: Maybe Char -> ReadP TS.Text
readURL mQuote = do
url' <- case mQuote of
Just quote -> munch (/= quote)
Nothing -> munch (/= ')')
return $ pack url'
instance Show Cursor where
showsPrec p = showsPrec p . FromTextShow
instance TextShow Cursor where
showb Auto = "auto"
showb Default = "default"
showb None = "none"
showb ContextMenu = "context-menu"
showb Help = "help"
showb Pointer = "pointer"
showb Progress = "progress"
showb Wait = "wait"
showb Cell = "cell"
showb Crosshair = "crosshair"
showb Text = "text"
showb VerticalText = "vertical-text"
showb Alias = "alias"
showb Copy = "copy"
showb Move = "move"
showb NoDrop = "no-drop"
showb NotAllowed = "not-allowed"
showb AllScroll = "all-scroll"
showb ColResize = "col-resize"
showb RowResize = "row-resize"
showb NResize = "n-resize"
showb EResize = "e-resize"
showb SResize = "s-resize"
showb WResize = "w-resize"
showb NEResize = "ne-resize"
showb NWResize = "nw-resize"
showb SEResize = "se-resize"
showb SWResize = "sw-resize"
showb EWResize = "ew-resize"
showb NSResize = "ns-resize"
showb NESWResize = "nesw-resize"
showb NWSEResize = "nwse-resize"
showb ZoomIn = "zoom-in"
showb ZoomOut = "zoom-out"
showb Grab = "grab"
showb Grabbing = "grabbing"
showb (URL url' cur) =
"url(" <> jsLiteralBuilder (fromText url') <> "), " <> showb cur
auto :: Cursor
auto = Auto
default_ :: Cursor
default_ = Default
none :: Cursor
none = None
contextMenu :: Cursor
contextMenu = ContextMenu
help :: Cursor
help = Help
pointer :: Cursor
pointer = Pointer
progress :: Cursor
progress = Progress
wait :: Cursor
wait = Wait
cell :: Cursor
cell = Cell
crosshair :: Cursor
crosshair = Crosshair
text :: Cursor
text = Text
verticalText :: Cursor
verticalText = VerticalText
alias :: Cursor
alias = Alias
copy :: Cursor
copy = Copy
move :: Cursor
move = Move
noDrop :: Cursor
noDrop = NoDrop
notAllowed :: Cursor
notAllowed = NotAllowed
allScroll :: Cursor
allScroll = AllScroll
colResize :: Cursor
colResize = ColResize
rowResize :: Cursor
rowResize = RowResize
nResize :: Cursor
nResize = NResize
eResize :: Cursor
eResize = EResize
sResize :: Cursor
sResize = SResize
wResize :: Cursor
wResize = WResize
neResize :: Cursor
neResize = NEResize
nwResize :: Cursor
nwResize = NWResize
seResize :: Cursor
seResize = SEResize
swResize :: Cursor
swResize = SWResize
ewResize :: Cursor
ewResize = ewResize
nsResize :: Cursor
nsResize = NSResize
neswResize :: Cursor
neswResize = NESWResize
nwseResize :: Cursor
nwseResize = NWSEResize
zoomIn :: Cursor
zoomIn = ZoomIn
zoomOut :: Cursor
zoomOut = ZoomOut
grab :: Cursor
grab = Grab
grabbing :: Cursor
grabbing = Grabbing
url :: TS.Text -> Cursor -> Cursor
url = URL