Remove screenWidth and screenHeight getters.

replace/f6b7a8b5cdddf9ff6382c5177e0b63e360c6bd7e
Federico Amedeo Izzo 2020-10-23 14:29:48 +02:00 zatwierdzone przez Niccolò Izzo
rodzic 75dd0d2fab
commit 6b0f0242d1
8 zmienionych plików z 32 dodań i 108 usunięć

Wyświetl plik

@ -74,18 +74,6 @@ void *display_getFrameBuffer();
*/
void display_terminate();
/**
* Get screen width in pixels.
* @return screen width, in pixels.
*/
uint16_t display_screenWidth();
/**
* Get screen height in pixels.
* @return screen height, in pixels.
*/
uint16_t display_screenHeight();
/**
* Copy a given section, between two given rows, of framebuffer content to the
* display.

Wyświetl plik

@ -98,20 +98,6 @@ void gfx_init();
*/
void gfx_terminate();
/**
* This function calls the correspondent method of the low level interface display.h
* Get screen width in pixels.
* @return screen width, in pixels.
*/
uint16_t gfx_screenWidth();
/**
* This function calls the correspondent method of the low level interface display.h
* Get screen height in pixels.
* @return screen height, in pixels.
*/
uint16_t gfx_screenHeight();
/**
* This function calls the correspondent method of the low level interface display.h
* Copy a given section, between two given rows, of framebuffer content to the

Wyświetl plik

@ -36,22 +36,17 @@ typedef enum
} bw_t;
bool initialized = 0;
uint16_t screen_width = 0;
uint16_t screen_height = 0;
uint8_t *buf;
uint16_t fbSize;
void gfx_init()
{
display_init();
// Set global variables and framebuffer pointer
screen_width = gfx_screenWidth();
screen_height = gfx_screenHeight();
buf = (uint8_t *)(display_getFrameBuffer());
// Calculate framebuffer size
fbSize = (screen_height * screen_width) / 8;
fbSize = (SCREEN_HEIGHT * SCREEN_WIDTH) / 8;
/* Compensate for eventual truncation error in division */
if((fbSize * 8) < (screen_height * screen_width)) fbSize += 1;
if((fbSize * 8) < (SCREEN_HEIGHT * SCREEN_WIDTH)) fbSize += 1;
fbSize *= sizeof(uint8_t);
initialized = 1;
}
@ -62,16 +57,6 @@ void gfx_terminate()
initialized = 0;
}
uint16_t gfx_screenWidth()
{
return display_screenWidth();
}
uint16_t gfx_screenHeight()
{
return display_screenHeight();
}
void gfx_renderRows(uint8_t startRow, uint8_t endRow)
{
display_renderRows(startRow, endRow);
@ -120,15 +105,15 @@ void _bw_setPixel(point_t pos, bw_t bw)
* Black and white 1bpp format: framebuffer is an array of uint8_t, where
* each cell contains the values of eight pixels, one per bit.
*/
uint16_t cell = (pos.x + pos.y*screen_width) / 8;
uint16_t elem = (pos.x + pos.y*screen_width) % 8;
uint16_t cell = (pos.x + pos.y*SCREEN_WIDTH) / 8;
uint16_t elem = (pos.x + pos.y*SCREEN_WIDTH) % 8;
buf[cell] &= ~(1 << elem);
buf[cell] |= (bw << elem);
}
void gfx_setPixel(point_t pos, color_t color)
{
if (pos.x >= screen_width || pos.y >= screen_height)
if (pos.x >= SCREEN_WIDTH || pos.y >= SCREEN_HEIGHT)
return; // off the screen
bw_t bw = _color2bw(color);
_bw_setPixel(pos, bw);
@ -155,8 +140,8 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
uint16_t x_max = start.x + width;
uint16_t y_max = start.y + height;
bool perimeter = 0;
if(x_max > (screen_width - 1)) x_max = screen_width - 1;
if(y_max > (screen_height - 1)) y_max = screen_height - 1;
if(x_max > (SCREEN_WIDTH - 1)) x_max = SCREEN_WIDTH - 1;
if(y_max > (SCREEN_HEIGHT - 1)) y_max = SCREEN_HEIGHT - 1;
for(int y = start.y; y < y_max; y++)
{
for(int x = start.x; x < x_max; x++)
@ -212,9 +197,9 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
int16_t sLen = strlen(text);
// Compute amount of letters that fit till the end of the screen
if ((charWidthPixels*sLen) + start.x > screen_width)
if ((charWidthPixels*sLen) + start.x > SCREEN_WIDTH)
{
sLen = (screen_width-start.x)/charWidthPixels;
sLen = (SCREEN_WIDTH-start.x)/charWidthPixels;
}
if (sLen < 0) return;
@ -225,10 +210,10 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
// left aligned, do nothing.
break;
case TEXT_ALIGN_CENTER:
start.x = (screen_width - (charWidthPixels * sLen))/2;
start.x = (SCREEN_WIDTH - (charWidthPixels * sLen))/2;
break;
case TEXT_ALIGN_RIGHT:
start.x = screen_width - (charWidthPixels * sLen);
start.x = SCREEN_WIDTH - (charWidthPixels * sLen);
break;
}

Wyświetl plik

@ -44,16 +44,11 @@ typedef struct
} rgb565_t;
bool initialized = 0;
uint16_t screen_width = 0;
uint16_t screen_height = 0;
rgb565_t *buf;
void gfx_init()
{
display_init();
// Set global variables and framebuffer pointer
screen_width = gfx_screenWidth();
screen_height = gfx_screenHeight();
buf = (rgb565_t *)(display_getFrameBuffer());
initialized = 1;
}
@ -64,16 +59,6 @@ void gfx_terminate()
initialized = 0;
}
uint16_t gfx_screenWidth()
{
return display_screenWidth();
}
uint16_t gfx_screenHeight()
{
return display_screenHeight();
}
void gfx_renderRows(uint8_t startRow, uint8_t endRow)
{
display_renderRows(startRow, endRow);
@ -103,28 +88,28 @@ void gfx_clearScreen()
{
if(!initialized) return;
// Set the whole framebuffer to 0x00 = make the screen black
memset(buf, 0x00, sizeof(rgb565_t) * screen_width * screen_height);
memset(buf, 0x00, sizeof(rgb565_t) * SCREEN_WIDTH * SCREEN_HEIGHT);
}
void gfx_fillScreen(color_t color)
{
if(!initialized) return;
rgb565_t color_565 = _true2highColor(color);
for(int y = 0; y < screen_height; y++)
for(int y = 0; y < SCREEN_HEIGHT; y++)
{
for(int x = 0; x < screen_width; x++)
for(int x = 0; x < SCREEN_WIDTH; x++)
{
buf[x + y*screen_width] = color_565;
buf[x + y*SCREEN_WIDTH] = color_565;
}
}
}
void gfx_setPixel(point_t pos, color_t color)
{
if (pos.x >= screen_width || pos.y >= screen_height)
if (pos.x >= SCREEN_WIDTH || pos.y >= SCREEN_HEIGHT)
return; // off the screen
buf[pos.x + pos.y*screen_width] = _true2highColor(color);
buf[pos.x + pos.y*SCREEN_WIDTH] = _true2highColor(color);
}
void gfx_drawLine(point_t start, point_t end, color_t color)
@ -135,7 +120,7 @@ void gfx_drawLine(point_t start, point_t end, color_t color)
{
for(int x = start.x; x < end.x; x++)
{
buf[x + y*screen_width] = color_565;
buf[x + y*SCREEN_WIDTH] = color_565;
}
}
}
@ -147,8 +132,8 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
uint16_t x_max = start.x + width;
uint16_t y_max = start.y + height;
bool perimeter = 0;
if(x_max > (screen_width - 1)) x_max = screen_width - 1;
if(y_max > (screen_height - 1)) y_max = screen_height - 1;
if(x_max > (SCREEN_WIDTH - 1)) x_max = SCREEN_WIDTH - 1;
if(y_max > (SCREEN_HEIGHT - 1)) y_max = SCREEN_HEIGHT - 1;
for(int y = start.y; y < y_max; y++)
{
for(int x = start.x; x < x_max; x++)
@ -156,7 +141,7 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
if(y == start.y || y == y_max-1 || x == start.x || x == x_max-1) perimeter = 1;
else perimeter = 0;
// If fill is false, draw only rectangle perimeter
if(fill || perimeter) buf[x + y*screen_width] = color_565;
if(fill || perimeter) buf[x + y*SCREEN_WIDTH] = color_565;
}
}
}
@ -200,9 +185,9 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
int16_t sLen = strlen(text);
// Compute amount of letters that fit till the end of the screen
if ((charWidthPixels*sLen) + start.x > screen_width)
if ((charWidthPixels*sLen) + start.x > SCREEN_WIDTH)
{
sLen = (screen_width-start.x)/charWidthPixels;
sLen = (SCREEN_WIDTH-start.x)/charWidthPixels;
}
if (sLen < 0) return;
@ -213,10 +198,10 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
// left aligned, do nothing.
break;
case TEXT_ALIGN_CENTER:
start.x = (screen_width - (charWidthPixels * sLen))/2;
start.x = (SCREEN_WIDTH - (charWidthPixels * sLen))/2;
break;
case TEXT_ALIGN_RIGHT:
start.x = screen_width - (charWidthPixels * sLen);
start.x = SCREEN_WIDTH - (charWidthPixels * sLen);
break;
}
@ -241,7 +226,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
int16_t byte = bitIndex >> 3;
int16_t bitMask = 1 << (bitIndex & 7);
if (currentCharData[byte] & bitMask)
buf[(start.y + vscan) * screen_width +
buf[(start.y + vscan) * SCREEN_WIDTH +
start.x + hscan + i * charWidthPixels] = color_565;
}
}

Wyświetl plik

@ -333,16 +333,6 @@ void display_terminate()
}
}
uint16_t display_screenWidth()
{
return SCREEN_WIDTH;
}
uint16_t display_screenHeight()
{
return SCREEN_HEIGHT;
}
void display_renderRows(uint8_t startRow, uint8_t endRow)
{
/*

Wyświetl plik

@ -175,16 +175,6 @@ void display_terminate()
SDL_Quit();
}
uint16_t display_screenWidth()
{
return SCREEN_WIDTH;
}
uint16_t display_screenHeight()
{
return SCREEN_HEIGHT;
}
void display_renderRows(uint8_t startRow, uint8_t endRow)
{
Uint32 *pixels = (Uint32*)renderSurface->pixels;

Wyświetl plik

@ -43,7 +43,7 @@ void drawRect(int x, int y, int width, int height, uint16_t color)
{
for(int j=x; j < x_max; j++)
{
buf[j + i*display_screenWidth()] = color;
buf[j + i * SCREEN_WIDTH] = color;
}
}
}
@ -54,13 +54,13 @@ int main()
display_setBacklightLevel(254);
/* Horizontal red line */
drawRect(0, 10, display_screenWidth(), 20, 0xF800);
drawRect(0, 10, SCREEN_WIDTH, 20, 0xF800);
/* Vertical blue line */
drawRect(10, 0, 20, display_screenHeight(), 0x001F);
drawRect(10, 0, 20, SCREEN_HEIGHT, 0x001F);
/* Vertical green line */
drawRect(80, 0, 20, display_screenHeight(), 0x07e0);
drawRect(80, 0, 20, SCREEN_HEIGHT, 0x07e0);
/*
* Use SDL event listener to check if window close button has been pressed,

Wyświetl plik

@ -97,13 +97,13 @@ static void gfxThread(void *arg)
point_t origin = {0, pos};
color_t color_red = {255, 0, 0};
color_t color_white = {255, 255, 255};
gfx_drawRect(origin, display_screenWidth(), 20, color_red, 1);
gfx_drawRect(origin, SCREEN_WIDTH, 20, color_red, 1);
char *buffer = "KEK";
gfx_print(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_LEFT,color_white);
gfx_render();
while(gfx_renderingInProgress()) ;
pos += 20;
if(pos > gfx_screenHeight() - 20) pos = 0;
if(pos > SCREEN_HEIGHT - 20) pos = 0;
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
}