2023-08-03 10:19:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include <luna/Result.h>
|
|
|
|
#include <luna/Types.h>
|
|
|
|
#include <ui/Color.h>
|
|
|
|
#include <ui/Point.h>
|
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
|
|
|
namespace ui
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @brief A drawable surface.
|
|
|
|
*/
|
|
|
|
struct Canvas
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int stride;
|
|
|
|
u8* ptr;
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Create a new Canvas object.
|
|
|
|
*
|
|
|
|
* @param ptr The memory to use for the canvas. It must be of at least width * height * 4 bytes of length.
|
|
|
|
* @param width The width of the canvas.
|
|
|
|
* @param height The height of the canvas.
|
|
|
|
* @return Canvas The new Canvas object.
|
|
|
|
*/
|
2023-08-03 10:19:45 +00:00
|
|
|
static Canvas create(u8* ptr, int width, int height);
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Return a new Canvas that represents a subsection of the current one.
|
|
|
|
*
|
|
|
|
* @param rect The dimensions of the new canvas. If these exceed the bounds of the current canvas, they will be
|
|
|
|
* clamped.
|
|
|
|
* @return Canvas The new Canvas object.
|
|
|
|
*/
|
|
|
|
Canvas subcanvas(Rect rect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return the dimensions of the current canvas.
|
|
|
|
*
|
|
|
|
* @return Rect This canvas's dimensions, as a Rect object.
|
|
|
|
*/
|
2023-08-03 10:19:45 +00:00
|
|
|
Rect rect()
|
|
|
|
{
|
2023-08-03 15:38:49 +00:00
|
|
|
return Rect { .pos = { 0, 0 }, .width = width, .height = height };
|
2023-08-03 10:19:45 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 15:38:49 +00:00
|
|
|
/**
|
|
|
|
* @brief Fill the entire canvas with one color.
|
|
|
|
*
|
|
|
|
* @param color The color to use.
|
|
|
|
*/
|
2023-08-03 10:19:45 +00:00
|
|
|
void fill(Color color);
|
2023-08-04 19:14:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Fill the canvas with pixels.
|
|
|
|
*
|
|
|
|
* @param pixels The array of pixels (must be at least width*height).
|
|
|
|
* @param stride The number of pixels to skip to go to the next line.
|
|
|
|
*/
|
|
|
|
void fill(u32* pixels, int stride);
|
2023-08-03 10:19:45 +00:00
|
|
|
};
|
|
|
|
};
|