phoenix::Canvas
A widget for basic pixel-level drawing (icons, bitmaps, etc.)
Note that this is not a performance-based renderer. Use Viewport bound to a native rendering API like OpenGL or Direct3D for video or animation.
struct Canvas : Widget {
function<void ()> onMouseLeave();
function<void ()> onMouseMove(Position position);
function<void (Mouse::Button)> onMousePress(Mouse::Button button);
function<void (Mouse::Button)> onMouseRelease(Mouse::Button button);
uint32_t* data();
bool setImage(const image &image);
void setSize(const Size &size);
Size size();
void update();
};
function<void ()> Canvas::onMouseLeave;
Called when the mouse cursor leaves the control.
function<void (Position)> Canvas::onMouseMove;
Called when the mouse cursor moves within the control. First call after the last onMouseLeave() also indicates the mouse entering the control.
function<void (Mouse::Button)> Canvas::onMousePress;
Called when a mouse button is pressed down within the control.
function<void (Mouse::Button)> Canvas::onMouseRelease;
Called when a mouse button is released within the control.
Note that on some platforms, this message will be sent even if the mouse button is released outside of the control.
uint32_t Canvas::data();
Returns buffer to canvas pixel data. Format is ARGB8888, but note that the alpha channel is thus far unused.
bool Canvas::setImage(const image &image);
Copy image object into canvas data. Will set canvas size to image size.
void Canvas::setSize(const Size &size);
Resize the canvas buffer to requested size. Note that if the Canvas widget is smaller, the image will be cropped at the bottom right (that is, only the top left of the image will be displayed.) If the Canvas widget is larger, the excess area at the bottom right will be transparent (that is, the same color as the window itself.)
Size Canvas::size();
Returns the current Canvas size. This defaults to 256x256 if you do not specify your own size.
void Canvas::update();
Draws the contents of Canvas::data() to the screen. This function also caches the data internally, so that if the window is resized, the data that was present the last time update() was called will be used.