shine 0.2.0.3 → 0.2.0.4
raw patch · 6 files changed
+51/−105 lines, 6 filesdep −shinedep ~basedep ~ghcjs-domdep ~ghcjs-primPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: shine
Dependency ranges changed: base, ghcjs-dom, ghcjs-prim, mtl, time, transformers
API changes (from Hackage documentation)
- Graphics.Shine.Picture: Text :: Font -> TextAlignment -> (Maybe Double) -> String -> Picture
+ Graphics.Shine.Picture: Text :: Font -> TextAlignment -> Maybe Double -> String -> Picture
Files
- ChangeLog.md +13/−3
- LICENSE +1/−1
- README.md +30/−5
- shine.cabal +7/−19
- tests/everything.hs +0/−47
- tests/simpleInteraction.hs +0/−30
ChangeLog.md view
@@ -1,12 +1,22 @@ # Revision history for shine -## 0.1.0.0 -- 2016-04-20+## 0.2.0.4 -- 2020-01-04 -* First version.+* Docs updates, mainly about handling assets+* Moved the failing "tests" to the new shine-examples package +## 0.2.0.3 -- 2018-07-11++* Misc bugfixes+* Misc docs updates+ ## 0.2.0.0 -- 2017-06-23 -* Changed WIndow to Document in some places+* Changed Window to Document in some places * Use Double for everything * Use the new ghcjs-dom types++## 0.1.0.0 -- 2016-04-20++* First version.
LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2018 Francesco Gazzetta+Copyright (c) 2016-2019 Francesco Gazzetta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
README.md view
@@ -6,7 +6,7 @@ Heavily inspired by [gloss](http://gloss.ouroborus.net/). -**demo** (compiled tests) [here](http://fgaz.github.io/shine/tests)+**demo** (compiled shine-examples) [here](http://fgaz.github.io/shine/shine-examples) ## Compiling @@ -88,8 +88,8 @@ ```haskell main :: IO ()- {- get the context, see before -}- draw ctx concentricCircles+ {- omitted: get the context, see before -}+ render ctx concentricCircles ``` #### `animate`@@ -106,7 +106,7 @@ main :: IO () main = do- {- get the context, see before -}+ {- omitted: get the context, see before -} animate ctx 30 animation ``` @@ -121,7 +121,7 @@ -- left mouse button is pressed main :: IO () main = do- {- get the context and the document, see before -}+ {- omitted: get the context and the document, see before -} play ctx doc 30 initialState draw handleInput step where -- our state represents the state of the left mouse button@@ -134,4 +134,29 @@ handleInput _ = id -- catch-all for all other events step _ = id -- our state does not depend on time ```++### Examples++See the [`shine-examples`](./shine-examples) package+([Hackage](https://hackage.haskell.org/package/shine-examples)).++### Handling assets++Handling assets with ghcjs and the browser is somewhat tricky.++The usual way of doing it for normal haskell programs is to use+[`data-files`](https://www.haskell.org/cabal/users-guide/developing-packages.html#pkg-field-data-files).+Unfortunately, this work by either hardcoding an absolute path in the executable,+which will not work when the program is put on a server in a different path,+or with an environment variable override (`$pkgname_datadir`),+which will not work because+[environment variables do not exist in the browser](https://github.com/ghcjs/shims/blob/de9560ee1fb8d1ca58c12da20c71a778eb08f3db/src/environment.js#L155).++So, for now, the solution is to explicitly specify absolute or relative paths+in the source code, and then to manyully copy the assets to the appropriate+location after building/deploying the code.+This is what I did in the `animated-shapes` demo for the peppers image.++Relevant cabal ticket, discussing a possible new way of handling assets:+https://github.com/haskell/cabal/issues/6096#issuecomment-570784857
shine.cabal view
@@ -1,12 +1,12 @@ name: shine-version: 0.2.0.3+version: 0.2.0.4 cabal-version: >=1.8 build-type: Simple license: MIT license-file: LICENSE-copyright: (c) 2016-2018 Francesco Gazzetta+copyright: (c) 2016-2019 Francesco Gazzetta author: Francesco Gazzetta-maintainer: Francesco Gazzetta <francygazz@gmail.com>+maintainer: Francesco Gazzetta <fgaz@fgaz.me> stability: experimental homepage: https://github.com/fgaz/shine bug-reports: https://github.com/fgaz/shine/issues@@ -32,23 +32,11 @@ Graphics.Shine.Render build-depends: base >=4.11 && <4.13, ghcjs-dom >=0.9 && <0.10,- ghcjs-prim,+ ghcjs-prim >=0.1 && <0.2, keycode >=0.2 && <0.3,- time,- mtl,- transformers+ time >=1.8 && <1.10,+ mtl >=2.2 && <2.3,+ transformers >=0.5 && <0.6 hs-source-dirs: src ghc-options: -O2 -Wall - --TODO run this in an actual window-test-suite test-shine-animateeverything- type: exitcode-stdio-1.0- main-is: everything.hs- hs-source-dirs: tests- build-depends: base, ghcjs-dom, shine--test-suite test-shine-simpleinteraction- type: exitcode-stdio-1.0- main-is: simpleInteraction.hs- hs-source-dirs: tests- build-depends: base, ghcjs-dom, shine
− tests/everything.hs
@@ -1,47 +0,0 @@-{-# LANGUAGE CPP #-}--import Graphics.Shine-import Graphics.Shine.Image-import Graphics.Shine.Picture--import GHCJS.DOM (currentDocumentUnchecked)--#if defined(ghcjs_HOST_OS)-run :: a -> a-run = id-#elif defined(MIN_VERSION_jsaddle_wkwebview)-import Language.Javascript.JSaddle.WKWebView (run)-#else-import Language.Javascript.JSaddle.WebKitGTK (run)-#endif--animation :: ImageData -> Double -> Picture-animation img x =- Translate (75+x'/2) 15 (RectF (150+x') 30)- <> Colored (Color 255 0 0 1.0) (Translate 15 (75+x'/2) $ Rect 30 (150+x'))- <> Colored (Color 200 200 0 1.0) (Translate 660 30 $ RectF 120 60)- <> Colored (Color 100 100 (floor x') 1.0) (Translate 600 340 $ RectF 120 240)- <> Translate (150+x') 150 (circle 100)- <> Translate 140 120 (circle (80+x'))- <> Line 400 400 10 x'- <> Colored (Color 255 0 0 1.0) (Translate 800 500 $ CircleF (x'/10))- <> foldMap (Translate 300 300 . circle) [1,5..x']- <> Translate 350 350 (Rotate (x'/200) $ RectF 150 30)- <> Translate 100 500 (Image Original img)- <> Colored (Color 0 0 255 1) -- blue pentagon- (Translate 200 500- (Polygon [ (-110,-80)- , (50,-120)- , (140,20)- , (30,140)- , (-120,80)- ]))- <> Translate 600 500 (Text "20px Sans" CenterAlign (Just 300) "The quick brown fox jumps over the lazy dog")- where x' = sin (x*3) *100 +100--main :: IO ()-main = run $ do- doc <- currentDocumentUnchecked- ctx <- fixedSizeCanvas doc 800 600- img <- makeImage "httpS://placehold.it/200x70/afa"- animate ctx 30 $ animation img
− tests/simpleInteraction.hs
@@ -1,30 +0,0 @@-{-# LANGUAGE CPP #-}--import Graphics.Shine-import Graphics.Shine.Input-import Graphics.Shine.Picture--import GHCJS.DOM (currentDocumentUnchecked)--#if defined(ghcjs_HOST_OS)-run :: a -> a-run = id-#elif defined(MIN_VERSION_jsaddle_wkwebview)-import Language.Javascript.JSaddle.WKWebView (run)-#else-import Language.Javascript.JSaddle.WebKitGTK (run)-#endif--main :: IO ()-main = run $ do- doc <- currentDocumentUnchecked- ctx <- fixedSizeCanvas doc 800 600- play ctx doc 30 initialState draw handleInput step- where- initialState = False- draw False = Empty- draw True = RectF 300 300- handleInput (MouseBtn BtnLeft Down _) = const True- handleInput (MouseBtn BtnLeft Up _) = const False- handleInput _ = id- step _ = id