API Review RT:17407 Canvas Node
Kevin Rushforth
kevin.rushforth at oracle.com
Fri Apr 20 05:35:04 PDT 2012
I'll take a stab at a couple of your questions.
> Another thing I'm not sure about is how I get informed e.g. that I
> should redraw. Do I have to react on Size-Changes, ... myself or would I
> get a callback, to do so?
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.
>> Canvas.getGC() only keeps one instance and keeps returning it - good/bad?
>>
>
> What happens if I fetch to 2 GCs - are both valid to draw in the canvas
> at the same time? If it returns a new one everytime createGC() is
> probably the right for it name.
>
Each call to getGC() returns exactly the same object. So you can't have
two GCs for the same canvas with the current API. If that were to change
(and so far there doesn't seem to be a compelling reason to do so), I
agree that createGC() would be a better name.
-- Kevin
Tom Schindl wrote:
> Hi Jim,
>
> Another thing I'm not sure about is how I get informed e.g. that I
> should redraw. Do I have to react on Size-Changes, ... myself or would I
> get a callback, to do so?
>
> This leads to the next question: Let's say I have a Canvas who has a
> size of 1000x1000 but only a rect of 0/0/100/100 is visible can I
> somehow find out this and only draw the content in this area and
> possible get a callback when the visible area changes?
>
> So an API like this would be a really cool thing to have:
>
> ---------8<---------
> Canvas#setPaintContextCallback(Callback<PaintContext> callback);
>
> PaintContext {
> private Rectangle bounds;
> private GraphicsContext context;
> }
> ---------8<---------
>
> Maybe such an API could be added later on?
>
> Should there be a short circuite method to clear the complete drawing if
> I get the API correct I currently have to call clearRect().
>
> Tom
>
> Am 20.04.12 02:09, schrieb Jim Graham:
>
>> Some targeted questions I'd like to see more reactions on (we made a
>> preliminary prototype based on the HTML5 flavors in most cases, but
>> we've done APIs that go either way in the past so we are flexible here):
>>
>> Canvas.getGC() only keeps one instance and keeps returning it - good/bad?
>>
>>
>
> What happens if I fetch to 2 GCs - are both valid to draw in the canvas
> at the same time? If it returns a new one everytime createGC() is
> probably the right for it name. I don't feel very strong about that.
>
>
>> Constructing a path in the GC vs. separate Path object?
>>
>>
>
> I would vote for GC.createPath() and move the Path API to it which would
> make the GC-API smaller and would align with the createImageData API.
>
> GC#createPath(): Path
>
> Path {
> arc(double centerX, double centerY, double radiusX, double radiusY,
> double startAngle, double length);
> arcTo(double x1, double y1, double x2, double y2, double radius);
> // ...
> }
>
>
>> drawFoo() vs. strokeFoo() for drawing the outline of something?
>>
>>
>
> I don't fully understand why there is strokeRect() what is it good for?
> You currently have:
> * drawRoundRect
> * strokeRect
>
> a) Shouldn't you use Rectangle?
> b) I would vote for drawRectangle which BTW is nothing more than
> calling drawRoundRectangle with 0 as the arcs right?
>
>
>
>
>> ...jim
>>
>> On 4/18/12 3:36 PM, joe andresen wrote:
>>
>>> Hello Everyone,
>>>
>>> We propose to add a Canvas node and GraphicsContext to a new
>>> javafx.scene.canvas package for JavaFX 2.2. The javafx.scene.canvas
>>> package provides a pair of classes for an immediate mode style API for
>>> rendering. Canvas Node works seemlessly with effects as well as
>>> Animation timers, and will be tightly bound to the new ImageOps API.
>>>
>>> This new API will allow HTML5 Canvas users to easily port their existing
>>> applications that make heavy use of the HTML5 canvas directly to JavaFX
>>> without the need to morph their application to fit the scenegraph model.
>>>
>>> You can Download and unzip the (preliminary) relevant docs here:
>>> JIRA: http://javafx-jira.kenai.com/browse/RT-17407
>>>
>>> Note that the docs are a work in progress but should be enough for API
>>> Review. (Also, Jira will be down Thursday 4/19 at 1400 PDT for a while).
>>>
>>> A list of the the methods for Canvas and GraphicsContext are listed
>>> below.
>>>
>>> Canvas:
>>>
>>> GraphicsContext getGraphicsContext2D()
>>> double getHeight()
>>> double getWidth()
>>> DoubleProperty heightProperty()
>>> void setHeight(double value)
>>> void setWidth(double value)
>>> DoubleProperty widthProperty()
>>>
>>> GraphicsContext:
>>> void appendSVGPath(java.lang.String svgpath)
>>> void applyEffect(Effect e)
>>> void arc(double centerX, double centerY, double radiusX, double radiusY,
>>> double startAngle, double length)
>>> void arcTo(double x1, double y1, double x2, double y2, double radius)
>>> void beginPath()
>>> void bezierCurveTo(double xc1, double yc1, double xc2, double yc2,
>>> double x1, double y1)
>>> void clearRect(double x, double y, double w, double h)
>>> void clip()
>>> void closePath()
>>> void drawArc(double x, double y, double w, double h, double startAngle,
>>> double arcExtent, ArcType closure)
>>> void drawImage(Image img, double x, double y)
>>> void drawImage(Image img, double x, double y, double w, double h)
>>> void drawImage(Image img, double sx, double sy, double sw, double sh,
>>> double dx, double dy, double dw, double dh)
>>> void drawLine(double x1, double y1, double x2, double y2)
>>> void drawOval(double x, double y, double w, double h)
>>> void drawPolygon(double[] xPoints, double[] yPoints, int nPoints)
>>> void drawPolyline(double[] xPoints, double[] yPoints, int nPoints)
>>> void drawRoundRect(double x, double y, double w, double h, double
>>> arcWidth, double arcHeight)
>>> void fill()
>>> void fillArc(double x, double y, double w, double h, double startAngle,
>>> double arcExtent, ArcType closure)
>>> void fillOval(double x, double y, double w, double h)
>>> void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
>>> void fillRect(double x, double y, double w, double h)
>>> void fillRoundRect(double x, double y, double w, double h, double
>>> arcWidth, double arcHeight)
>>> void fillText(java.lang.String text, double x, double y)
>>> void fillText(java.lang.String text, double x, double y, double maxWidth)
>>> Canvas getCanvas()
>>> boolean isPointInPath(double x, double y)
>>> void lineTo(double x1, double y1)
>>> double measureText(java.lang.String text)
>>> void moveTo(double x0, double y0)
>>> void putImageData(GraphicsContext.ImageData imagedata, double dx, double
>>> dy)
>>> void putImageData(GraphicsContext.ImageData imagedata, double dx, double
>>> dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight)
>>> void quadraticCurveTo(double xc, double yc, double x1, double y1)
>>> void rect(double x, double y, double w, double h)
>>> void restore()
>>> void rotate(double degrees)
>>> void save()
>>> void scale(double x, double y)
>>> void setEffect(Effect e)
>>> void setFill(Paint p)
>>> void setFont(Font f)
>>> void setGlobalAlpha(double alpha)
>>> void setGlobalCompositeOperation(GraphicsContext.CompositeOperation op)
>>> void setLineCap(StrokeLineCap cap)
>>> void setLineJoin(StrokeLineJoin join)
>>> void setLineWidth(double lw)
>>> void setMiterLimit(double ml)
>>> void setStroke(Paint p)
>>> void setTextAlign(TextAlignment align)
>>> void setTextBaseline(VPos baseline)
>>> void setTransform(double mxx, double myx, double mxy, double myy, double
>>> mxt, double myt)
>>> void stroke()
>>> void strokeRect(double x, double y, double w, double h)
>>> void strokeText(java.lang.String text, double x, double y)
>>> void strokeText(java.lang.String text, double x, double y, double
>>> maxWidth)
>>> void transform(double mxx, double myx, double mxy, double myy, double
>>> mxt, double myt)
>>> void translate(double x, double y)
>>>
>
>
>
More information about the openjfx-dev
mailing list