Max OS 0.3
Loading...
Searching...
No Matches
graphicsContext.h
Go to the documentation of this file.
1
11#ifndef MaxOS_COMMON_GRAPHICSCONTEX_H
12#define MaxOS_COMMON_GRAPHICSCONTEX_H
13
14#include <cstdint>
15#include <stdint.h>
16
17#include <libcommon/colour.h>
18
19namespace MaxOS::common {
20
26
27 protected:
29 false };
30
31 uint32_t m_width { 0 };
32 uint32_t m_height { 0 };
33 uint32_t m_color_depth { 0 };
34
35 Colour m_colour_pallet[256];
36
37 uint64_t* m_framebuffer_address { nullptr };
38
39 virtual void render_pixel(uint32_t x, uint32_t y, uint32_t colour);
40 virtual void render_pixel_8_bit(uint32_t x, uint32_t y, uint8_t colour);
41 virtual void render_pixel_16_bit(uint32_t x, uint32_t y, uint16_t colour);
42 virtual void render_pixel_24_bit(uint32_t x, uint32_t y, uint32_t colour);
43 virtual void render_pixel_32_bit(uint32_t x, uint32_t y, uint32_t colour);
44
45 virtual uint32_t get_rendered_pixel(uint32_t x, uint32_t y);
46 virtual uint8_t get_rendered_pixel_8_bit(uint32_t x, uint32_t y);
47 virtual uint16_t get_rendered_pixel_16_bit(uint32_t x, uint32_t y);
48 virtual uint32_t get_rendered_pixel_24_bit(uint32_t x, uint32_t y);
49 virtual uint32_t get_rendered_pixel_32_bit(uint32_t x, uint32_t y);
50
51 public:
54
55 static uint32_t colour_to_int(const Colour& colour, uint32_t color_depth);
56 uint32_t colour_to_int(const Colour&);
57 Colour int_to_colour(uint32_t);
58
59 // Convert uint32_t to uint64s?
60 [[nodiscard]] uint32_t width() const;
61 [[nodiscard]] uint32_t height() const;
62 [[nodiscard]] uint32_t color_depth() const;
63
64 uint64_t* framebuffer_address();
65
66 void put_pixel(uint32_t x, uint32_t y, const Colour& colour);
67 void put_pixel(uint32_t x, uint32_t y, uint32_t colour);
68 Colour get_pixel(uint32_t x, uint32_t y);
69 void invert_pixel(uint32_t x, uint32_t y);
70
71 void draw_line(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour& colour);
72 void draw_line(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour);
73
74 void draw_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour& colour);
75 void draw_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour);
76
77 void fill_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour& colour);
78 void fill_rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour);
79
80 void draw_circle(uint32_t x0, uint32_t y0, uint32_t radius, const Colour& colour);
81 void draw_circle(uint32_t x0, uint32_t y0, uint32_t radius, uint32_t colour);
82
83 void fill_circle(uint32_t x0, uint32_t y0, uint32_t radius, const Colour& colour);
84 void fill_circle(uint32_t x0, uint32_t y0, uint32_t radius, uint32_t colour);
85
86 };
87
88}
89
90
91#endif //MaxOS_COMMON_GRAPHICSCONTEX_H
Draws pixels to the screen, and handles drawing lines, rectangles and circles.
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.
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.
static uint32_t colour_to_int(const Colour &colour, uint32_t color_depth)
Converts a colour to an integer value based on the current color depth.
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.