11using namespace MaxOS::common;
98GraphicsContext::~GraphicsContext() =
default;
251 for(
uint32_t i = 0; i <= 255; ++i) {
254 ((
int) colour.
red - (
int) c->red) * ((
int) colour.
red - (
int) c->red)
255 + ((
int) colour.
green - (
int) c->green) * ((
int) colour.
green - (
int) c->green)
256 + ((
int) colour.
blue - (
int) c->blue) * ((
int) colour.
blue - (
int) c->blue);
308 result.red = (colour & 0xF800) >> 8;
309 result.green = (colour & 0x07E0) >> 3;
310 result.blue = (colour & 0x001F) << 3;
319 result.red = (colour & 0xFF0000) >> 16;
320 result.green = (colour & 0x00FF00) >> 8;
321 result.blue = (colour & 0x0000FF);
431 colour.
red = 255 - colour.
red;
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
uint8_t alpha
The amount of alpha 0-255 (0 is visible, 255 is invisible) todo: confirm.
uint8_t green
The amount of green 0-255.
uint8_t blue
The amount of blue 0-255.
uint8_t red
The amount of red 0-255.
void fill_circle(uint32_t x0, uint32_t y0, uint32_t radius, const Colour &colour)
Draws a circle on the screen, filled with a colour.
void put_pixel(uint32_t x, uint32_t y, const Colour &colour)
Renders a pixel to the screen (automatically converts the colour to an integer)
void draw_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour &colour)
Draws a rectangle on the screen.
virtual uint8_t get_rendered_pixel_8_bit(uint32_t x, uint32_t y)
Gets the colour of a pixel on the screen using the 8 bit color depth.
virtual void render_pixel_8_bit(uint32_t x, uint32_t y, uint8_t colour)
Renders a pixel to the screen using the 8 bit color depth.
uint32_t colour_to_int(const Colour &)
Converts a colour to an integer value based on the current color depth.
void invert_pixel(uint32_t x, uint32_t y)
Inverts a pixel.
uint64_t * framebuffer_address()
Gets the address of the context's framebuffer to draw on.
uint32_t m_color_depth
The color depth of the screen in bits per pixel.
Colour get_pixel(uint32_t x, uint32_t y)
Gets the colour of a pixel, or returns black if the pixel is outside the screen.
virtual void render_pixel_24_bit(uint32_t x, uint32_t y, uint32_t colour)
Renders a pixel to the screen using the 24 bit color depth.
Colour int_to_colour(uint32_t)
Converts an integer value to a colour based on the current color depth.
Colour m_colour_pallet[256]
The colour pallet for 8 bit color depth.
virtual uint32_t get_rendered_pixel_24_bit(uint32_t x, uint32_t y)
Gets the colour of a pixel on the screen using the 24 bit color depth.
virtual uint16_t get_rendered_pixel_16_bit(uint32_t x, uint32_t y)
Gets the colour of a pixel on the screen using the 16 bit color depth.
virtual uint32_t get_rendered_pixel(uint32_t x, uint32_t y)
Gets the colour of a pixel on the screen, automatically uses the correct color depth.
uint32_t width() const
Gets the width of the screen.
uint64_t * m_framebuffer_address
The address of the framebuffer.
virtual void render_pixel(uint32_t x, uint32_t y, uint32_t colour)
Renders a pixel to the screen based on the current color depth.
bool mirror_y_axis
Should the y axis be mirrored (0,0 is top left if false, bottom left if true)
uint32_t height() const
Gets the height of the screen.
uint32_t m_width
The width of the screen in pixels.
virtual void render_pixel_32_bit(uint32_t x, uint32_t y, uint32_t colour)
Renders a pixel to the screen using the 32 bit color depth.
GraphicsContext()
Constructs a GraphicsContext object and initializes the color palette.
void fill_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour &colour)
Draws a rectangle on the screen, filled with a colour.
void draw_line(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour &colour)
Draws a line on the screen.
virtual void render_pixel_16_bit(uint32_t x, uint32_t y, uint16_t colour)
Renders a pixel to the screen using the 16 bit color depth.
virtual uint32_t get_rendered_pixel_32_bit(uint32_t x, uint32_t y)
Gets the colour of a pixel on the screen using the 32 bit color depth.
uint32_t color_depth() const
Gets the current color depth (bits per pixel)
void draw_circle(uint32_t x0, uint32_t y0, uint32_t radius, const Colour &colour)
Draws a circle on the screen.
uint32_t m_height
The height of the screen in pixels.
Stores the left, top, width and height of a rectangle.
Defines a GraphicsContext class for drawing pixels, lines, rectangles and circles to the screen.