Skip to content

bindings/cpp/gui.hpp

C++98 API source. Preserve the bindings/cpp/ layout when downloading multiple files.

Source files · Download gui.hpp

#ifndef GASPARDOS_GUI_HPP
#define GASPARDOS_GUI_HPP
#include "gaspardos.hpp"
#include "widgets.hpp"

namespace gaspardos
{
    namespace gui
    {
        class NativePainter : public Painter
        {
            Window& window_;

        public:
            explicit NativePainter(Window& window) : window_(window)
            {
            }

            int64_t fill(int x, int y, int w, int h, uint32_t color)
            {
                GO64_Drawing d;
                std::memset(&d, 0, sizeof(d));
                d.x      = x;
                d.y      = y;
                d.width  = w;
                d.height = h;
                d.color  = color;
                return window_.fill(d);
            }

            int64_t text(int x, int y, uint32_t color, const char* value)
            {
                GO64_Drawing d;
                std::memset(&d, 0, sizeof(d));
                d.x     = x;
                d.y     = y;
                d.color = color;
                std::strncpy(d.text, value, sizeof(d.text) - 1);
                return window_.text(d);
            }
        };

        inline int dispatch(Widgets& widgets, const GO64_Event& e)
        {
            Event event = { e.type, e.x, e.y, e.buttons, e.key };
            return widgets.event(event);
        }
    }  // namespace gui
}  // namespace gaspardos
#endif