![]() |
Max OS 0.3
|
Draws pixels to the screen, and handles drawing lines, rectangles and circles. More...
#include <graphicsContext.h>
Public Member Functions | |
| GraphicsContext () | |
| Constructs a GraphicsContext object and initializes the color palette. | |
| uint32_t | colour_to_int (const Colour &) |
| Converts a colour to an integer value based on the current color depth. | |
| Colour | int_to_colour (uint32_t) |
| Converts an integer value to a colour based on the current color depth. | |
| uint32_t | width () const |
| Gets the width of the screen. | |
| uint32_t | height () const |
| Gets the height of the screen. | |
| uint32_t | color_depth () const |
| Gets the current color depth (bits per pixel) | |
| uint64_t * | framebuffer_address () |
| Gets the address of the context's framebuffer to draw on. | |
| 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 | put_pixel (uint32_t x, uint32_t y, uint32_t colour) |
| Renders a pixel to the screen (automatically converts the colour to an integer), will not render the pixel if it is outside the screen. | |
| 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. | |
| void | invert_pixel (uint32_t x, uint32_t y) |
| Inverts a pixel. | |
| void | draw_line (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour &colour) |
| Draws a line on the screen. | |
| void | draw_line (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour) |
| Draws a line on the screen. | |
| void | draw_rectangle (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, const Colour &colour) |
| Draws a rectangle on the screen. | |
| void | draw_rectangle (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour) |
| Draws a rectangle on the screen. | |
| 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 | fill_rectangle (uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t colour) |
| Draws a rectangle on the screen, filled with a colour. | |
| void | draw_circle (uint32_t x0, uint32_t y0, uint32_t radius, const Colour &colour) |
| Draws a circle on the screen. | |
| void | draw_circle (uint32_t x0, uint32_t y0, uint32_t radius, uint32_t colour) |
| Draws a circle on the screen. | |
| 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 | fill_circle (uint32_t x0, uint32_t y0, uint32_t radius, uint32_t colour) |
| Draws a circle on the screen, filled with a colour. | |
Protected Member Functions | |
| 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. | |
| 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. | |
| 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 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. | |
| 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. | |
| 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. | |
| 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 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_24_bit (uint32_t x, uint32_t y) |
| Gets the colour of a pixel on the screen using the 24 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. | |
Protected Attributes | |
| bool | mirror_y_axis |
| Should the y axis be mirrored (0,0 is top left if false, bottom left if true) | |
| uint32_t | m_width { 0 } |
| The width of the screen in pixels. | |
| uint32_t | m_height { 0 } |
| The height of the screen in pixels. | |
| uint32_t | m_color_depth { 0 } |
| The color depth of the screen in bits per pixel. | |
| Colour | m_colour_pallet [256] |
| The colour pallet for 8 bit color depth. | |
| uint64_t * | m_framebuffer_address { nullptr } |
| The address of the framebuffer. | |
Draws pixels to the screen, and handles drawing lines, rectangles and circles.
Definition at line 22 of file graphicsContext.h.
| GraphicsContext::GraphicsContext | ( | ) |
Constructs a GraphicsContext object and initializes the color palette.
Definition at line 17 of file graphicsContext.cpp.
References m_colour_pallet.
| uint32_t GraphicsContext::color_depth | ( | ) | const |
Gets the current color depth (bits per pixel)
Definition at line 364 of file graphicsContext.cpp.
References m_color_depth.
Referenced by MaxOS::drivers::video::VideoDriver::set_mode(), and MaxOS::drivers::video::VideoElectronicsStandardsAssociation::supports_mode().
Converts a colour to an integer value based on the current color depth.
| colour | The colour class to convert |
Definition at line 245 of file graphicsContext.cpp.
References MaxOS::common::Colour::alpha, MaxOS::common::Colour::blue, MaxOS::common::Colour::green, m_color_depth, m_colour_pallet, and MaxOS::common::Colour::red.
Referenced by draw_circle(), draw_line(), draw_rectangle(), fill_circle(), fill_rectangle(), get_rendered_pixel(), and put_pixel().
| void GraphicsContext::draw_circle | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | radius, | ||
| const Colour & | colour | ||
| ) |
Draws a circle on the screen.
| x0 | The x coordinate of the centre of the circle |
| y0 | The y coordinate of the centre of the circle |
| radius | The radius of the circle |
| colour | The colour of the circle |
Definition at line 647 of file graphicsContext.cpp.
References colour_to_int(), and draw_circle().
Referenced by draw_circle().
Draws a circle on the screen.
| x0 | The x coordinate of the centre of the circle |
| y0 | The y coordinate of the centre of the circle |
| radius | The radius of the circle |
| colour | The colour of the circle |
Definition at line 659 of file graphicsContext.cpp.
References m_height, m_width, mirror_y_axis, and put_pixel().
| void GraphicsContext::draw_line | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | x1, | ||
| uint32_t | y1, | ||
| const Colour & | colour | ||
| ) |
Draws a line on the screen.
| x0 | The x coordinate of the m_first_memory_chunk point |
| y0 | The y coordinate of the m_first_memory_chunk point |
| x1 | The x coordinate of the final point |
| y1 | The y coordinate of the final point |
| colour | The colour of the line |
Definition at line 449 of file graphicsContext.cpp.
References colour_to_int(), and draw_line().
Referenced by draw_line(), draw_line(), and draw_rectangle().
| void GraphicsContext::draw_line | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | x1, | ||
| uint32_t | y1, | ||
| uint32_t | colour | ||
| ) |
Draws a line on the screen.
| x0 | The x coordinate of the m_first_memory_chunk point |
| y0 | The y coordinate of the m_first_memory_chunk point |
| x1 | The x coordinate of the final point |
| y1 | The y coordinate of the final point |
| colour | The colour of the line |
Definition at line 462 of file graphicsContext.cpp.
References draw_line(), m_height, m_width, mirror_y_axis, and put_pixel().
| void GraphicsContext::draw_rectangle | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | x1, | ||
| uint32_t | y1, | ||
| const Colour & | colour | ||
| ) |
Draws a rectangle on the screen.
| x0 | The x coordinate of the top left corner |
| y0 | The y coordinate of the top left corner |
| x1 | The x coordinate of the bottom right corner |
| y1 | The y coordinate of the bottom right corner |
| colour | The colour of the rectangle |
Definition at line 552 of file graphicsContext.cpp.
References colour_to_int(), and draw_rectangle().
Referenced by draw_rectangle().
| void GraphicsContext::draw_rectangle | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | x1, | ||
| uint32_t | y1, | ||
| uint32_t | colour | ||
| ) |
Draws a rectangle on the screen.
| x0 | The x coordinate of the top left corner |
| y0 | The y coordinate of the top left corner |
| x1 | The x coordinate of the bottom right corner |
| y1 | The y coordinate of the bottom right corner |
| colour | The colour of the rectangle |
Definition at line 566 of file graphicsContext.cpp.
References draw_line().
| void GraphicsContext::fill_circle | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | radius, | ||
| const Colour & | colour | ||
| ) |
Draws a circle on the screen, filled with a colour.
| x0 | The x coordinate of the centre of the circle |
| y0 | The y coordinate of the centre of the circle |
| radius | The radius of the circle |
| colour | The colour of the circle |
Definition at line 695 of file graphicsContext.cpp.
References colour_to_int(), and fill_circle().
Referenced by fill_circle().
Draws a circle on the screen, filled with a colour.
| x0 | The x coordinate of the centre of the circle |
| y0 | The y coordinate of the centre of the circle |
| radius | The radius of the circle |
| colour | The colour of the circle |
Definition at line 708 of file graphicsContext.cpp.
References m_height, m_width, mirror_y_axis, and put_pixel().
| void GraphicsContext::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.
| x0 | The x coordinate of the top left corner |
| y0 | The y coordinate of the top left corner |
| x1 | The x coordinate of the bottom right corner |
| y1 | The y coordinate of the bottom right corner |
| colour | The colour of the rectangle |
Definition at line 589 of file graphicsContext.cpp.
References colour_to_int(), and fill_rectangle().
Referenced by fill_rectangle(), and fill_rectangle().
| void GraphicsContext::fill_rectangle | ( | uint32_t | x0, |
| uint32_t | y0, | ||
| uint32_t | x1, | ||
| uint32_t | y1, | ||
| uint32_t | colour | ||
| ) |
Draws a rectangle on the screen, filled with a colour.
| x0 | The x coordinate of the top left corner |
| y0 | The y coordinate of the top left corner |
| x1 | The x coordinate of the bottom right corner |
| y1 | The y coordinate of the bottom right corner |
| colour | The colour of the rectangle |
Definition at line 602 of file graphicsContext.cpp.
References fill_rectangle(), m_height, m_width, mirror_y_axis, and put_pixel().
| uint64_t * GraphicsContext::framebuffer_address | ( | ) |
Gets the address of the context's framebuffer to draw on.
Definition at line 740 of file graphicsContext.cpp.
References m_framebuffer_address.
Gets the colour of a pixel, or returns black if the pixel is outside the screen.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 408 of file graphicsContext.cpp.
References get_rendered_pixel(), int_to_colour(), m_height, m_width, and mirror_y_axis.
Referenced by invert_pixel().
Gets the colour of a pixel on the screen, automatically uses the correct color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 179 of file graphicsContext.cpp.
References colour_to_int(), get_rendered_pixel_16_bit(), get_rendered_pixel_24_bit(), get_rendered_pixel_32_bit(), get_rendered_pixel_8_bit(), and m_color_depth.
Referenced by get_pixel().
Gets the colour of a pixel on the screen using the 16 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 213 of file graphicsContext.cpp.
Referenced by get_rendered_pixel().
Gets the colour of a pixel on the screen using the 24 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 224 of file graphicsContext.cpp.
Referenced by get_rendered_pixel().
Gets the colour of a pixel on the screen using the 32 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 235 of file graphicsContext.cpp.
Referenced by get_rendered_pixel().
Gets the colour of a pixel on the screen using the 8 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 202 of file graphicsContext.cpp.
Referenced by get_rendered_pixel().
| uint32_t GraphicsContext::height | ( | ) | const |
Gets the height of the screen.
Definition at line 356 of file graphicsContext.cpp.
References m_height.
Referenced by MaxOS::drivers::video::VideoDriver::set_mode(), MaxOS::drivers::video::VideoGraphicsArray::supports_mode(), and MaxOS::drivers::video::VideoElectronicsStandardsAssociation::supports_mode().
Converts an integer value to a colour based on the current color depth.
| colour | The integer value to convert |
Definition at line 296 of file graphicsContext.cpp.
References m_color_depth, and m_colour_pallet.
Referenced by get_pixel().
Inverts a pixel.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
Definition at line 425 of file graphicsContext.cpp.
References MaxOS::common::Colour::blue, get_pixel(), MaxOS::common::Colour::green, put_pixel(), and MaxOS::common::Colour::red.
Referenced by MaxOS::gui::Desktop::invert_mouse_cursor().
Renders a pixel to the screen (automatically converts the colour to an integer)
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The colour of the pixel |
Definition at line 375 of file graphicsContext.cpp.
References colour_to_int(), and put_pixel().
Referenced by draw_circle(), draw_line(), fill_circle(), fill_rectangle(), invert_pixel(), and put_pixel().
Renders a pixel to the screen (automatically converts the colour to an integer), will not render the pixel if it is outside the screen.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The colour of the pixel |
Definition at line 390 of file graphicsContext.cpp.
References m_height, m_width, mirror_y_axis, and render_pixel().
Renders a pixel to the screen based on the current color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The colour of the pixel |
Definition at line 107 of file graphicsContext.cpp.
References m_color_depth, render_pixel_16_bit(), render_pixel_24_bit(), render_pixel_32_bit(), and render_pixel_8_bit().
Referenced by put_pixel().
|
protectedvirtual |
Renders a pixel to the screen using the 16 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The 16Bit colour of the pixel |
Definition at line 146 of file graphicsContext.cpp.
Referenced by render_pixel().
|
protectedvirtual |
Renders a pixel to the screen using the 24 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The 24Bit colour of the pixel |
Definition at line 157 of file graphicsContext.cpp.
Referenced by render_pixel().
|
protectedvirtual |
Renders a pixel to the screen using the 32 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The 32Bit colour of the pixel |
Definition at line 168 of file graphicsContext.cpp.
Referenced by render_pixel().
|
protectedvirtual |
Renders a pixel to the screen using the 8 bit color depth.
| x | The x coordinate of the pixel |
| y | The y coordinate of the pixel |
| colour | The 8Bit colour of the pixel |
Definition at line 135 of file graphicsContext.cpp.
Referenced by render_pixel().
| uint32_t GraphicsContext::width | ( | ) | const |
Gets the width of the screen.
Definition at line 347 of file graphicsContext.cpp.
References m_width.
Referenced by MaxOS::drivers::video::VideoDriver::set_mode(), MaxOS::drivers::video::VideoGraphicsArray::supports_mode(), and MaxOS::drivers::video::VideoElectronicsStandardsAssociation::supports_mode().
|
protected |
The color depth of the screen in bits per pixel.
Definition at line 30 of file graphicsContext.h.
Referenced by color_depth(), colour_to_int(), get_rendered_pixel(), int_to_colour(), render_pixel(), and MaxOS::drivers::video::VideoDriver::set_mode().
|
protected |
The colour pallet for 8 bit color depth.
Definition at line 32 of file graphicsContext.h.
Referenced by colour_to_int(), GraphicsContext(), and int_to_colour().
The address of the framebuffer.
Definition at line 34 of file graphicsContext.h.
Referenced by framebuffer_address(), and MaxOS::drivers::video::VideoElectronicsStandardsAssociation::VideoElectronicsStandardsAssociation().
|
protected |
The height of the screen in pixels.
Definition at line 29 of file graphicsContext.h.
Referenced by draw_circle(), draw_line(), fill_circle(), fill_rectangle(), get_pixel(), height(), put_pixel(), and MaxOS::drivers::video::VideoDriver::set_mode().
|
protected |
The width of the screen in pixels.
Definition at line 28 of file graphicsContext.h.
Referenced by draw_circle(), draw_line(), fill_circle(), fill_rectangle(), get_pixel(), put_pixel(), MaxOS::drivers::video::VideoDriver::set_mode(), and width().
|
protected |
Should the y axis be mirrored (0,0 is top left if false, bottom left if true)
Definition at line 25 of file graphicsContext.h.
Referenced by draw_circle(), draw_line(), fill_circle(), fill_rectangle(), get_pixel(), and put_pixel().