API Review RT:17407 Canvas Node

Jeff McDonald deep.blue.6802 at gmail.com
Tue Apr 24 02:47:34 PDT 2012


Creating different GraphicsContext classes for handling different rendering
needs sounds ideal. Apple provides such abilities in their Quartz2D. The
simple idea is that a canvas is a bitmap surface to draw on. The
GraphicsContext (GC) is a base class which provides rudimentary support for
 higher level drawing classes such as HTML Canvas GC, SVG GC, or PostScript
GC. The JavaFX GC defined ealier in this thread could be the default
implementation. A GraphicsContext would more than likely be an abstract
class than an interface, just use whatever's best.

The way to avoid instance of tests is to use generics in the Canvas class:

public class Canvas<T extends GraphicsContext>
{
    ...
    public T  getGraphicsContext2D() ;
    ...
}

On the resizing issue, it seems more sensible to leave resizing behavior up
to the developer. Simply, does a resize infer scaling the canvas or
clipping it or expanding it with white space? Those are all design choices
best left up to the developer.

Regardless of how the implementation discussion ends up, the driving
question should be what do developers expect a 2D Canvas to do? I think of
things like photoshop, Illustrator, 8 bit arcade games, animations, 2D CAD
apps, Flow chart designers and the like.

When I Google to see what people have done with the Canvas node I'm not
overly impressed, but perhaps that's because of the early nature of the
HTML canvas element.

Cheers,
Jeff

On Mon, Apr 23, 2012 at 4:27 PM, Daniel Zwolenski <zonski at googlemail.com>wrote:

> Sorry, I'm not following the problem.
>
> Wouldn't the height and width properties provide the callback to say 'I
> have been resized'? This would include the amount resized-by so the
> developer could just render the new area if they want (or redraw the whole
> scene, etc). If the developer chooses not to patch/repaint then that's
> their choice.
>
> HTML has never had good layout manager concepts so for me it is not the
> best benchmark in this topic.
>
> What's the requirement to repaint on every frame? I don't follow that.
>
>
> On 24/04/2012, at 6:11 AM, Kevin Rushforth <kevin.rushforth at oracle.com>
> wrote:
>
> > I wrote:
> >> I can't think of any reason it should not be resizable.
> >
> > Good think I'm not the only one thinking about it, then. :)
> >
> > Yes, this would be an issue. So unless/until we are ready to deal with
> this, my earlier suggestion of binding to the width/height property, and
> adding your own listeners is probably the way to go.
> >
> > -- Kevin
> >
> >
> > Jim Graham wrote:
> >> We would have to deal with damage repair.  Right now it is a persistent
> rendering, not an area to be "repainted" on every frame.
> >>
> >> If we wanted it to be dynamically and asynchronously resizable we would
> have to switch to (or provide?) a call-back model of rendering and you
> would have to keep enough state to be able to render it again on every
> frame.  HTML5 Canvas demos are not rendered that way, though they can be at
> their own will - they simply clear the entire canvas and re-render on every
> pulse.  Or, they just render the new stuff.  Their call.  If they change
> size, like you can with Canvas, then they are responsible for changing the
> size and rendering the new stuff - just like if you manually modify the
> size of our Canvas.
> >>
> >>            ...jim
> >>
> >> On 4/23/12 5:36 AM, Kevin Rushforth wrote:
> >>> If Canvas were a "Resizable" node then yes, it could do that. Off-hand,
> >>> I can't think of any reason it should not be resizable.
> >>>
> >>> -- Kevin
> >>>
> >>>
> >>> Daniel Zwolenski wrote:
> >>>>> A Canvas node is a fixed size, so it only resizes when you tell it
> >>>>> to. If you want it to track the size of the Scene (or similar), you
> >>>>> could bind its width and height properties and react to change
> >>>>> notifications.
> >>>>
> >>>> Any reason why Canvas wouldn't just adhere to the Layout algorithm of
> >>>> the Container it is in? Eg if in a BorderPane center then fill, if in
> >>>> a GridPane take up that cell, etc. If we want to fix size then we
> >>>> would use min/max constraints.
> >>>> That would seem the most sensible and useful thing to me.
>


More information about the openjfx-dev mailing list