StuBS
|
Driver managing the video mode and synchronizing its buffer with the graphics printer. More...
#include <graphics.h>
Public Member Functions | |
Graphics (unsigned size, void *frontbuffer, void *backbuffer) | |
Constructor. More... | |
bool | init (bool force=false) |
Initialize GraphicsPrinter according to the current video mode. More... | |
bool | switchBuffers () |
Switch front and back buffer (only if front buffer was already copied to video memory) More... | |
void | scanoutFrontbuffer () |
Copy current front buffer to the video memory. | |
void | clear () |
Clear all pixel of the current back buffer (set full screen to black) | |
bool | valid (const Point &p) |
Check if a Point can be displayed at the current resolution. More... | |
unsigned | height () |
Number of vertical pixels in current resolution. More... | |
unsigned | width () |
Number of horizontal pixels in current resolution. More... | |
void | pixel (const Point &p, const Color &color) |
Draw a pixel on the current back buffer. More... | |
void | pixel (const Point &p, const ColorAlpha &color) |
Draw a pixel on the current back buffer. More... | |
void | line (const Point &start, const Point &end, const Color &color) |
Draw a line on the current back buffer. More... | |
void | line (const Point &start, const Point &end, const ColorAlpha &color) |
Draw a line on the current back buffer. More... | |
void | rectangle (const Point &start, const Point &end, const Color &color, bool filled=true) |
Draw a rectangle on the current back buffer. More... | |
void | rectangle (const Point &start, const Point &end, const ColorAlpha &color, bool filled=true) |
Draw a rectangle on the current back buffer. More... | |
void | font (const Font &new_font) |
Change the current font for text output in video mode. More... | |
void | text (const Point &p, const char *string, unsigned len, const Color &color, const Font *font=nullptr) |
Print text (without automatic word wrap) on the current back buffer. More... | |
void | text (const Point &p, const char *string, unsigned len, const ColorAlpha &color, const Font *font=nullptr) |
Print text (without automatic word wrap) on the current back buffer. More... | |
void | image (const Point &p, PNG &image, unsigned width=0, unsigned height=0, unsigned offset_x=0, unsigned offset_y=0) |
Draw a PNG image [detail] on the current back buffer. More... | |
void | image (const Point &p, const GIMP &image, unsigned width=0, unsigned height=0, unsigned offset_x=0, unsigned offset_y=0) |
Draw a GIMP image [detail] on the current back buffer. More... | |
void | image (const Point &p, const Color *image, unsigned width, unsigned height, unsigned offset_x=0, unsigned offset_y=0) |
Draw a sprite on the current back buffer. More... | |
void | image (const Point &p, const ColorAlpha *image, unsigned width, unsigned height, unsigned offset_x=0, unsigned offset_y=0) |
Draw a sprite with alpha blending (transparency) on the current back buffer. More... | |
Private Attributes | |
AbstractGraphicsPrinter * | printer |
Pointer to a GraphicsPrinter supporting the current video mode. | |
void * | address |
Pointer to the physical address of the video memory (linear frame buffer) | |
unsigned | size |
Video memory size required for a full screen picture. | |
unsigned | buffer_size |
Size of the front (or back) buffer (which has to be at least size) | |
void *const | buffer [2] |
Pointer to the two buffers (used alternately as front and back buffers) | |
int | scanout_buffer |
Index of the current front buffer. | |
bool | refresh |
Has the current front buffer already been drawn? | |
Driver managing the video mode and synchronizing its buffer with the graphics printer.
This device detects the current video mode set by the Multiboot compliant boot loader and initializes a suitable GraphicsPrinter.
With the methods Graphics::switchBuffers() (to exchange front- and backbuffer) and Graphics::scanoutFrontbuffer() (copying the contents of the frontbuffer into the video memory) it provides some kind of manually triple buffering.
A typical usage is to fully prepare the back buffer before switching it with the front buffer
The method Graphics::scanoutFrontbuffer() has to be executed either inside the loop (right after Graphics::switchBuffers() in the example above) or at a predefined interval by employing the Watch.
boot/multiboot/config.inc
. Graphics::Graphics | ( | unsigned | size, |
void * | frontbuffer, | ||
void * | backbuffer | ||
) |
Constructor.
size | Size of each buffer |
frontbuffer | Pointer to a reserved memory area with a sufficient size to transmit a full screen picture to the video memory at the current video mode / resolution. |
backbuffer | Pointer to a reserved memory area with the same size as the front buffer to prepare the picture. |
|
inline |
|
inline |
Number of vertical pixels in current resolution.
|
inline |
Draw a sprite on the current back buffer.
Each element in the source array will be displayed as a single pixel.
p | Coordinate of the sprites upper left corner |
image | Source sprite to display |
width | Width of the sprite detail |
height | Height of the sprite detail |
offset_x | Right offset of the source sprite |
offset_y | Top offset of the source sprite |
|
inline |
Draw a sprite with alpha blending (transparency) on the current back buffer.
Each element in the source array will be displayed as a single pixel.
p | Coordinate of the sprites upper left corner |
image | Source sprite to display |
width | Width of the sprite detail |
height | Height of the sprite detail |
offset_x | Right offset of the source sprite |
offset_y | Top offset of the source sprite |
|
inline |
Draw a GIMP image [detail] on the current back buffer.
The image has to be exported as C-source (without Glib
types!) in GIMP, alpha blending (transparency) is supported.
p | Coordinate of the images upper left corner |
image | Source image to display |
width | Width of the image detail (full image width of the source image if zero/default value) |
height | Height of the image detail (full image height of the source if zero/default value) |
offset_x | Right offset of the source image |
offset_y | Top offset of the source image |
|
inline |
Draw a PNG image [detail] on the current back buffer.
The image can has to be in a supported PNG format. Alpha blending (transparency) is supported.
p | Coordinate of the images upper left corner |
image | Source image to display |
width | Width of the image detail (full image width of the source image if zero/default value) |
height | Height of the image detail (full image height of the source if zero/default value) |
offset_x | Right offset of the source image |
offset_y | Top offset of the source image |
bool Graphics::init | ( | bool | force = false | ) |
Initialize GraphicsPrinter according to the current video mode.
force | Do not check video attributes for the linear frame buffer (required on our test systems due to some strange VBE behaviour) |
Draw a line on the current back buffer.
start | Coordinates of the begin of the line |
end | Coordinates of the end of the line |
color | Color of the line |
Draw a line on the current back buffer.
start | Coordinates of the begin of the line |
end | Coordinates of the end of the line |
color | Color of the line |
|
inline |
Draw a pixel on the current back buffer.
p | Coordinates of the pixel |
color | Color of the pixel |
|
inline |
Draw a pixel on the current back buffer.
p | Coordinates of the pixel |
color | Color of the pixel |
|
inline |
Draw a rectangle on the current back buffer.
start | Coordinate of the rectangles upper left corner |
end | Coordinate of the rectangles lower right corner |
color | Color of the rectangle |
filled | If set, the rectangle will be filled with the same color. (otherwise only borders will be drawn) |
|
inline |
Draw a rectangle on the current back buffer.
start | Coordinate of the rectangles upper left corner |
end | Coordinate of the rectangles lower right corner |
color | Color of the rectangle |
filled | If set, the rectangle will be filled with the same color. (otherwise only borders will be drawn) |
bool Graphics::switchBuffers | ( | ) |
Switch front and back buffer (only if front buffer was already copied to video memory)
true
if buffers have been switched, false
if previous front buffer wasn't yet fully copied to video memory.
|
inline |
Print text (without automatic word wrap) on the current back buffer.
p | Upper left start position of the text |
string | Pointer to char array containing the text to be displayed |
len | Number of characters to be displayed |
color | Color for the text characters |
font | Explicit font – or nullptr to use default font (set by font method) |
|
inline |
Print text (without automatic word wrap) on the current back buffer.
p | Upper left start position of the text |
string | Pointer to char array containing the text to be displayed |
len | Number of characters to be displayed |
color | Color for the text characters |
font | Explicit font – or nullptr to use default font (set by font method) |
|
inline |
Check if a Point can be displayed at the current resolution.
p | Coordinates to check |
|
inline |
Number of horizontal pixels in current resolution.