libg15render
screen.c File Reference
#include "libg15render.h"

Go to the source code of this file.

Functions

void g15r_clearScreen (g15canvas *canvas, int color)
 Fills the screen with pixels of color.
 
int g15r_getPixel (g15canvas *canvas, unsigned int x, unsigned int y)
 Gets the value of the pixel at (x, y)
 
void g15r_initCanvas (g15canvas *canvas)
 Clears the canvas and resets the mode switches.
 
void g15r_setPixel (g15canvas *canvas, unsigned int x, unsigned int y, int val)
 Sets the value of the pixel at (x, y)
 

Function Documentation

void g15r_clearScreen ( g15canvas canvas,
int  color 
)

Fills the screen with pixels of color.

Clears the screen and fills it with pixels of color

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
colorScreen will be filled with this color.

Definition at line 80 of file screen.c.

References g15canvas::buffer, and G15_BUFFER_LEN.

{
memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
}
int g15r_getPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y 
)

Gets the value of the pixel at (x, y)

Retrieves the value of the pixel at (x, y)

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xX offset for pixel to be retrieved.
yY offset for pixel to be retrieved.

Definition at line 29 of file screen.c.

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, and G15_LCD_WIDTH.

Referenced by g15r_pixelReverseFill(), and g15r_setPixel().

{
if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
return 0;
unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
unsigned int byte_offset = pixel_offset / BYTE_SIZE;
unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
return (canvas->buffer[byte_offset] & (1 << bit_offset)) >> bit_offset;
}
void g15r_initCanvas ( g15canvas canvas)

Clears the canvas and resets the mode switches.

Clears the screen and resets the mode values for a canvas

Parameters
canvasA pointer to a g15canvas struct

Definition at line 91 of file screen.c.

References g15canvas::buffer, g15canvas::ftLib, G15_BUFFER_LEN, g15canvas::mode_cache, g15canvas::mode_reverse, and g15canvas::mode_xor.

{
memset (canvas->buffer, 0, G15_BUFFER_LEN);
canvas->mode_cache = 0;
canvas->mode_reverse = 0;
canvas->mode_xor = 0;
#ifdef TTF_SUPPORT
if (FT_Init_FreeType (&canvas->ftLib))
printf ("Freetype couldnt initialise\n");
#endif
}
void g15r_setPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y,
int  val 
)

Sets the value of the pixel at (x, y)

Sets the value of the pixel at (x, y)

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xX offset for pixel to be set.
yY offset for pixel to be set.
valValue to which pixel should be set.

Definition at line 50 of file screen.c.

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, G15_LCD_WIDTH, g15r_getPixel(), g15canvas::mode_reverse, and g15canvas::mode_xor.

Referenced by draw_ttf_char(), g15r_drawCircle(), g15r_drawIcon(), g15r_drawLine(), g15r_drawRoundBox(), g15r_drawSprite(), g15r_pixelBox(), g15r_pixelOverlay(), g15r_pixelReverseFill(), g15r_renderCharacterLarge(), g15r_renderCharacterMedium(), and g15r_renderCharacterSmall().

{
if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
return;
unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
unsigned int byte_offset = pixel_offset / BYTE_SIZE;
unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
if (canvas->mode_xor)
val ^= g15r_getPixel (canvas, x, y);
if (canvas->mode_reverse)
val = !val;
if (val)
canvas->buffer[byte_offset] =
canvas->buffer[byte_offset] | 1 << bit_offset;
else
canvas->buffer[byte_offset] =
canvas->buffer[byte_offset] & ~(1 << bit_offset);
}