HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
439 stars 77 forks source link

Adding some primitive to the Canvas #88

Closed mathk closed 9 years ago

mathk commented 10 years ago

Here are some primitive for drawing on a canvas.

HeinrichApfelmus commented 10 years ago

Looks good. However, note that the Canvas API has already seen some extension in the develop branch.

Sorry for not having merged these older changes into the master branch yet, I will have to do some branch maintenance on my local repo.

mathk commented 10 years ago

Ok.

It seems that it is all in the develop branch. I would like to had the State monad for avoiding passing Canvas all over the place. A also I would like to had an other monad to combine the different method for drawing line on canvas. Avoiding the need to manually call beginPath and stroke.

What do you think?

mathk commented 10 years ago

I have merge the develop work on canvas and added a couple of other function. You can fine a new design for drawing on a canvas.

I have add 2 new datatype Drawing and DrawingPath. Both can be combine to shape more complex drawing.

For example here is the intended way to draw on a canvas:

    testCanvas = do
        canvas <- UI.canvas #
                    set UI.height 150 # 
                    set UI.width 300 # 
                    set style [("border", "solid black 1px")] #
        UI.renderDrawing canvas 
            ((UI.openedPath red 4.0 
                (UI.line (10.0,10.0) (100.0,100.0) <>
                (UI.move (150.0,100.0)) <>
                (UI.bezierCurve [(180.0,30.0), (250.0,180.0), (300.0,100.0)]))) <>
            (UI.openedPath red 4.0 (UI.arc (125.0, 115.0) 30.0 0.0 360.0)))
            element canvas
              where red = UI.solidColor (UI.RGB 0xFF 0 0) 

For the time being there is more a work in progress than a final design. Let me know if all is ok.

mathk commented 10 years ago

I am reopening this pull request. Let me know if the code looks ok for you. Thanks

HeinrichApfelmus commented 10 years ago

I'll have a look, but I'm currently short on time, so this may take a while. Sorry about that.

HeinrichApfelmus commented 9 years ago

Sorry about the rather long delay, I finally managed to take a look at your code.

The DrawingPath and Drawing monoids are good ideas, they are the first steps towards a more declarative drawing API. However, for Threepenny-GUI, I do not wish to implement a more declarative API. That may sound surprising, but the reason is simple: the diagrams package already does a thorough job at this! I think that the way to go is to make a Canvas backend for the diagrams package.

(That said, for the moment (October 2014), I temporarily advise against trying to implement a Canvas backend for Diagrams. I first want to improve the JavaScript FFI used by Threepenny.)