donjames
Topic Author
Posts: 25
Joined: 27 May 2013, 16:35

Re: Rendering curves

14 Feb 2014, 16:11

Having said that, and sorry for posting several times, I am thinking that probably you could extend noesisGUI creating a new class that derives from UIElement and implement the OnRender method.
void OnRender(DrawingContext* context);
DrawingContext offers a lot more flexibility for drawing:
class DrawingContext
{
    /// Draws an ellipse
    void DrawEllipse(Brush* brush, Pen* pen, const Drawing::Point& center, NsFloat32 radiusX,
        NsFloat32 radiusY);

    /// Draws the specified Geometry using the specified Brush and Pen
    void DrawGeometry(Brush* brush, Pen* pen, Geometry* geometry);

    /// Draws an image into the region defined by the specified Rect
    void DrawImage(ImageSource* imageSource, const Drawing::Rect& rect);

    /// Draws a line with the specified Pen
    void DrawLine(Pen* pen, const Drawing::Point& p0, const Drawing::Point& p1);

    /// Draws a rectangle
    void DrawRectangle(Brush* brush, Pen* pen, const Drawing::Rect& rect);

    /// Draws a rounded rectangle
    void DrawRoundedRectangle(Brush* brush, Pen* pen, const Drawing::Rect& rect, NsFloat32 radiusX,
        NsFloat32 radiusY);

    /// Draws formatted text at the specified location
    void DrawText(FormattedText* formattedText, const Drawing::Rect& bounds);

    /// Pops the last opacity mask, opacity, clip, effect, or transform operation that was pushed
    /// onto the drawing context
    void Pop();

    /// Pushes the specified clip region onto the drawing context
    void PushClip(Geometry* clipGeometry);

    /// Pushes the specified opacity setting onto the drawing context
    void PushOpacity(NsFloat32 opacity);

    /// Pushes the specified opacity mask onto the drawing context
    void PushOpacityMask(Brush* opacityMask);

    /// Pushes the specified Transform onto the drawing context
    void PushTransform(Transform* transform);
};
Is there a sample/C++ example that derives and uses this approach?
 
User avatar
jsantos
Site Admin
Posts: 2909
Joined: 20 Jan 2012, 17:18
Contact:

Re: Rendering curves

17 Feb 2014, 10:43

I assume then that means that you should not add the same instance of a path twice to the canvas children.
UIElements, and path derives from that base class, can only have a parent. That implies that they cannot be added twice to the tree. But you could have two paths sharing the same geometry.
If so then I should create two identical paths and set them independently with brushes for fill/stroke.

And does this do a (deep) copy of the path?

m_pPathCopy = *new Gui::Path();
Geometry *pGeom = m_pPath->GetData();
Geometry *pGeomCopy = (Geometry *) pGeom->Clone().GetPtr();
m_pPathCopy->SetData(pGeomCopy);

And does this do a deep copy of a brush:
m_pBrushCopy = *(Brush*) m_pBrush->Clone().GetPtr();
The correct way to clone is as follows:
Ptr<Brush> clonedBrush = NsStaticCast< Ptr<Brush> >(brush->Clone());
Note that because a new resource is created the returned object must be stored in a Ptr to retain ownership. As soon as you set that brush to an element in the tree you can release that reference.
 
User avatar
jsantos
Site Admin
Posts: 2909
Joined: 20 Jan 2012, 17:18
Contact:

Re: Rendering curves

17 Feb 2014, 10:44

Is there a sample/C++ example that derives and uses this approach?
As soon as we release v1.1.5 (today?) I will find time to create a sample for you.

Thanks.
 
donjames
Topic Author
Posts: 25
Joined: 27 May 2013, 16:35

Re: Rendering curves

18 Feb 2014, 15:43

Thanks but don't bother with the sample. I have been able to implement it will the current canvas approach and it works well.
Thanks
Don

Who is online

Users browsing this forum: No registered users and 1 guest