Nana does not provide an arc drawing primitive, so we have to use the windows API directly. Something like this:

#include <cmath>
#include <nana/gui.hpp>

#include <windows.h>

/** Draw Arc of circle
    @param[in] graph context
    @param[in] x for conter, pixels 0 at left of window
    @param[in] y for center, pixels 0 at top of window
    @param[in] r radius, pixels
    @param[in] sa start angle degrees anti-clockwise from 3 o'clock
    @param[in] se end angle degrees anti-clockwise from 3 o'clock
*/
void DrawArc(
    nana::paint::graphics& graph,
    int x, int y, double r,
    double sa, double ea,
    const nana::color& color )
{
    int xl =round( x-r );
    int yt =round( y-r );
    int xr =round( x+r );
    int yb =round( y+r );
    int xs =round( x + r * cos(sa * M_PI/180) );
    int ys =round( y + r * sin(sa * M_PI/180) );
    int xe =round( x + r * cos(ea * M_PI/180) );
    int ye =round( y + r * sin(ea * M_PI/180) );

    HDC hdc = reinterpret_cast<HDC>(const_cast<void*>(graph.context()));
    SelectObject(hdc, GetStockObject(DC_PEN));
    SetDCPenColor(hdc, RGB(color.r(),color.g(),color.b()));
    Arc(
        hdc,
        xl,yt,xr,yb,xs,ys,xe,ye );
}

int main()
{
    nana::form fm;
    fm.bgcolor( nana::colors::black );

    nana::drawing dw{fm};
    dw.draw([](nana::paint::graphics& graph)
    {

        DrawArc(
            graph,
            150, 150,
            100,
            315, 225,            // from 'ten past' to 'ten to'
            nana::colors::yellow
        );

    });

    fm.show();
    nana::exec();
}

which displays
5d54260006bce.png

A more complicated display, from my DXF file viewer ( https://github.com/JamesBremner/DXF_Viewer )

5d5426e537e96.png

Nana does not provide an arc drawing primitive, so we have to use the windows API directly. Something like this: ```` #include <cmath> #include <nana/gui.hpp> #include <windows.h> /** Draw Arc of circle @param[in] graph context @param[in] x for conter, pixels 0 at left of window @param[in] y for center, pixels 0 at top of window @param[in] r radius, pixels @param[in] sa start angle degrees anti-clockwise from 3 o'clock @param[in] se end angle degrees anti-clockwise from 3 o'clock */ void DrawArc( nana::paint::graphics& graph, int x, int y, double r, double sa, double ea, const nana::color& color ) { int xl =round( x-r ); int yt =round( y-r ); int xr =round( x+r ); int yb =round( y+r ); int xs =round( x + r * cos(sa * M_PI/180) ); int ys =round( y + r * sin(sa * M_PI/180) ); int xe =round( x + r * cos(ea * M_PI/180) ); int ye =round( y + r * sin(ea * M_PI/180) ); HDC hdc = reinterpret_cast<HDC>(const_cast<void*>(graph.context())); SelectObject(hdc, GetStockObject(DC_PEN)); SetDCPenColor(hdc, RGB(color.r(),color.g(),color.b())); Arc( hdc, xl,yt,xr,yb,xs,ys,xe,ye ); } int main() { nana::form fm; fm.bgcolor( nana::colors::black ); nana::drawing dw{fm}; dw.draw([](nana::paint::graphics& graph) { DrawArc( graph, 150, 150, 100, 315, 225, // from 'ten past' to 'ten to' nana::colors::yellow ); }); fm.show(); nana::exec(); } ```` which displays ![5d54260006bce.png](serve/attachment&path=5d54260006bce.png) A more complicated display, from my DXF file viewer ( https://github.com/JamesBremner/DXF_Viewer ) ![5d5426e537e96.png](serve/attachment&path=5d5426e537e96.png)

Nice, we can add a new method to draw arc for class graphics.

Nice, we can add a new method to draw arc for class graphics.

nana::shapes is a class for drawing shapes on a nana graph context

This class provides some primitive drawing shapes that are missing from nana::graph ( specifically circles and arcs ) and provides a consistent OOD wrapper for those that do

Implemented for Windows platform only.

This code:

#include <nana/gui.hpp>

#include "shapes.h"

int main()
{
    nana::form f;
    f.bgcolor( nana::colors::black );

    nana::drawing dw{f};
    dw.draw([](nana::paint::graphics& graph)
    {
        nana::shapes S( graph );
        S.color( nana::colors::yellow );

        int y = 10;
        S.line( 100, y, 200, y );

        y += 20;
        S.circle( 80, y+30, 15 );
        S.circle( 200, y+30, 15 );

        y += 50;
        S.arc(
            150, y+100,
            100,
            315, 225            // from 'ten past' to 'ten to'
        );

        S.color( nana::colors::white );
        S.rectangle( 5, 5, 280, 180 );

    });

    f.show();
    nana::exec();
}

outputs:

5d5c295ac51a2.png

The code is available at

https://github.com/JamesBremner/nana_draw_shapes

nana::shapes is a class for drawing shapes on a nana graph context This class provides some primitive drawing shapes that are missing from nana::graph ( specifically circles and arcs ) and provides a consistent OOD wrapper for those that do Implemented for Windows platform only. This code: ```` #include <nana/gui.hpp> #include "shapes.h" int main() { nana::form f; f.bgcolor( nana::colors::black ); nana::drawing dw{f}; dw.draw([](nana::paint::graphics& graph) { nana::shapes S( graph ); S.color( nana::colors::yellow ); int y = 10; S.line( 100, y, 200, y ); y += 20; S.circle( 80, y+30, 15 ); S.circle( 200, y+30, 15 ); y += 50; S.arc( 150, y+100, 100, 315, 225 // from 'ten past' to 'ten to' ); S.color( nana::colors::white ); S.rectangle( 5, 5, 280, 180 ); }); f.show(); nana::exec(); } ```` outputs: ![5d5c295ac51a2.png](serve/attachment&path=5d5c295ac51a2.png) The code is available at https://github.com/JamesBremner/nana_draw_shapes
26
views
2
replies
2
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft