Skip to content
qPCR4vir edited this page Apr 5, 2019 · 20 revisions

πŸ“š.

The wrapper class drawing provides interfaces to draw graphics on the surface of a widget, having only a handle (nana::window) to it.
Once the wrapper is created you use the functions draw or draw_diehard to set the function you want to be used to draw on the surface of the widget. The difference between the two versions is that the drawing functions set with draw are all unset with clear(), while draw_diehard return a handle (of type diehard_t) which you need to pass to erase to unset the drawing function. The drawing function self is a callable object taking a reference to an graphics, object and returning void. Every time the widget redraws, this drawing method will be applied.

Example:

Draw a 50 X 50 red rectangle at point(5,5) of a form (and a line diagonal): :octocat:

#include <nana/gui/wvl.hpp>

int main()
{
    using namespace nana;

    form fm;
    drawing dw(fm);
    dw.draw([](paint::graphics& graph)
    {
        graph.rectangle(rectangle{5, 5, 50, 50}, true, colors::red );
        graph.line(point(5, 5), point(55, 55), colors::blue);
        graph.line_begin(200,100);
        graph.line_to(point(300,300));
        graph.line_to(point(100,200));
        graph.line_to(point(300,200));
        graph.line_to(point(100,300));
        graph.line_to(point(200,100));

    });

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

See also [Draw-through of Form:books:](Draw-through of Form) to draw graphics directly on the system native window. By using this feature, it is possible to render graphics with OpenGL and DX.

Clone this wiki locally