kopia lustrzana https://github.com/OpenRTX/OpenRTX
graphics.h renamed graphics_* to gfx_*
Removed unused print methodsreplace/befa3a27b948e5ef3fe9579bf7b9cc35aa34fecb
rodzic
019b43338f
commit
9a5e12d4f0
|
@ -77,7 +77,7 @@ typedef enum
|
|||
FONT_SIZE_2,
|
||||
FONT_SIZE_3,
|
||||
FONT_SIZE_4
|
||||
} font_t;
|
||||
} fontSize_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
@ -90,27 +90,27 @@ typedef enum
|
|||
* This function calls the correspondent method of the low level interface display.h
|
||||
* It initializes the display and sets the backlight to zero.
|
||||
*/
|
||||
void graphics_init();
|
||||
void gfx_init();
|
||||
|
||||
/**
|
||||
* This function calls the correspondent method of the low level interface display.h
|
||||
* It turns off backlight, shuts down backlight control and deallocates the framebuffer.
|
||||
*/
|
||||
void graphics_terminate();
|
||||
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 graphics_screenWidth();
|
||||
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 graphics_screenHeight();
|
||||
uint16_t gfx_screenHeight();
|
||||
|
||||
/**
|
||||
* This function calls the correspondent method of the low level interface display.h
|
||||
|
@ -118,7 +118,7 @@ uint16_t graphics_screenHeight();
|
|||
* @param level: backlight level, from 0 (backlight off) to 255 (backlight at
|
||||
* full brightness).
|
||||
*/
|
||||
void graphics_setBacklightLevel(uint8_t level);
|
||||
void gfx_setBacklightLevel(uint8_t level);
|
||||
|
||||
/**
|
||||
* This function calls the correspondent method of the low level interface display.h
|
||||
|
@ -127,14 +127,14 @@ void graphics_setBacklightLevel(uint8_t level);
|
|||
* @param startRow: first row of the framebuffer section to be copied
|
||||
* @param endRow: last row of the framebuffer section to be copied
|
||||
*/
|
||||
void graphics_renderRows(uint8_t startRow, uint8_t endRow);
|
||||
void gfx_renderRows(uint8_t startRow, uint8_t endRow);
|
||||
|
||||
/**
|
||||
* This function calls the correspondent method of the low level interface display.h
|
||||
* Copy framebuffer content to the display internal buffer. To be called
|
||||
* whenever there is need to update the display.
|
||||
*/
|
||||
void graphics_render();
|
||||
void gfx_render();
|
||||
|
||||
/**
|
||||
* This function calls the correspondent method of the low level interface display.h
|
||||
|
@ -142,25 +142,25 @@ void graphics_render();
|
|||
* can be modified without problems.
|
||||
* @return false if rendering is not in progress.
|
||||
*/
|
||||
bool graphics_renderingInProgress();
|
||||
bool gfx_renderingInProgress();
|
||||
|
||||
/**
|
||||
* Makes the screen black.
|
||||
*/
|
||||
void graphics_clearScreen();
|
||||
void gfx_clearScreen();
|
||||
|
||||
/**
|
||||
* Fills screen with the specified color.
|
||||
* @param color: border and fill color, in color_t format.
|
||||
*/
|
||||
void graphics_fillScreen(color_t color);
|
||||
void gfx_fillScreen(color_t color);
|
||||
|
||||
/**
|
||||
* Change the color of a single pixel.
|
||||
* @param pos: x,y coordinates of the pixel.
|
||||
* @param color: desired pixel color, in color_t format.
|
||||
*/
|
||||
void setPixel(point_t pos, color_t color);
|
||||
void gfx_setPixel(point_t pos, color_t color);
|
||||
|
||||
/**
|
||||
* Draw a line from start to end coordinates, ends included.
|
||||
|
@ -168,7 +168,7 @@ void setPixel(point_t pos, color_t color);
|
|||
* @param end: line end point, in pixel coordinates.
|
||||
* @param color: line color, in color_t format.
|
||||
*/
|
||||
void graphics_drawLine(point_t start, point_t end, color_t color);
|
||||
void gfx_drawLine(point_t start, point_t end, color_t color);
|
||||
|
||||
/**
|
||||
* Draw a rectangle of specified width, height and color.
|
||||
|
@ -177,12 +177,16 @@ void graphics_drawLine(point_t start, point_t end, color_t color);
|
|||
* @param color: border and fill color, in color_t format.
|
||||
* @param fill: if true the rectangle will be solid, otherwise it will be empty with a 1-pixel border
|
||||
*/
|
||||
void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill);
|
||||
void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill);
|
||||
|
||||
void printCentered(uint16_t y, const char *text, font_t fontSize, color_t color);
|
||||
|
||||
void printAt(point_t pos, const char *text, font_t fontSize, color_t color);
|
||||
|
||||
void printCore(point_t start, const char *szMsg, font_t fontSize, textAlign_t alignment, color_t color);
|
||||
/**
|
||||
* Prints text on the screen.
|
||||
* @param start: text line start point, in pixel coordinates.
|
||||
* @param text: text to print.
|
||||
* @param size: text font size, defined as enum.
|
||||
* @param alignment: text alignment type, defined as enum.
|
||||
* @param color: text color, in color_t format.
|
||||
*/
|
||||
void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t alignment, color_t color);
|
||||
|
||||
#endif /* GRAPHICS_H */
|
||||
|
|
|
@ -49,48 +49,48 @@ uint16_t screen_width = 0;
|
|||
uint16_t screen_height = 0;
|
||||
rgb565_t *buf;
|
||||
|
||||
void graphics_init()
|
||||
void gfx_init()
|
||||
{
|
||||
display_init();
|
||||
// Set global variables and framebuffer pointer
|
||||
screen_width = graphics_screenWidth();
|
||||
screen_height = graphics_screenHeight();
|
||||
screen_width = gfx_screenWidth();
|
||||
screen_height = gfx_screenHeight();
|
||||
buf = (rgb565_t *)(display_getFrameBuffer());
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
void graphics_terminate()
|
||||
void gfx_terminate()
|
||||
{
|
||||
display_terminate();
|
||||
initialized = 0;
|
||||
}
|
||||
|
||||
uint16_t graphics_screenWidth()
|
||||
uint16_t gfx_screenWidth()
|
||||
{
|
||||
return display_screenWidth();
|
||||
}
|
||||
|
||||
uint16_t graphics_screenHeight()
|
||||
uint16_t gfx_screenHeight()
|
||||
{
|
||||
return display_screenHeight();
|
||||
}
|
||||
|
||||
void graphics_setBacklightLevel(uint8_t level)
|
||||
void gfx_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
display_setBacklightLevel(level);
|
||||
}
|
||||
|
||||
void graphics_renderRows(uint8_t startRow, uint8_t endRow)
|
||||
void gfx_renderRows(uint8_t startRow, uint8_t endRow)
|
||||
{
|
||||
display_renderRows(startRow, endRow);
|
||||
}
|
||||
|
||||
void graphics_render()
|
||||
void gfx_render()
|
||||
{
|
||||
display_render();
|
||||
}
|
||||
|
||||
bool graphics_renderingInProgress()
|
||||
bool gfx_renderingInProgress()
|
||||
{
|
||||
return display_renderingInProgress();
|
||||
}
|
||||
|
@ -105,14 +105,14 @@ rgb565_t _true2highColor(color_t true_color)
|
|||
return high_color;
|
||||
}
|
||||
|
||||
void graphics_clearScreen()
|
||||
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);
|
||||
}
|
||||
|
||||
void graphics_fillScreen(color_t color)
|
||||
void gfx_fillScreen(color_t color)
|
||||
{
|
||||
if(!initialized) return;
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
|
@ -125,7 +125,7 @@ void graphics_fillScreen(color_t color)
|
|||
}
|
||||
}
|
||||
|
||||
void setPixel(point_t pos, color_t color)
|
||||
void gfx_setPixel(point_t pos, color_t color)
|
||||
{
|
||||
if (pos.x > screen_width || pos.y > screen_height)
|
||||
return; // off the screen
|
||||
|
@ -133,7 +133,7 @@ void setPixel(point_t pos, color_t color)
|
|||
buf[pos.x + pos.y*screen_width] = _true2highColor(color);
|
||||
}
|
||||
|
||||
void graphics_drawLine(point_t start, point_t end, color_t color)
|
||||
void gfx_drawLine(point_t start, point_t end, color_t color)
|
||||
{
|
||||
if(!initialized) return;
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
|
@ -146,7 +146,7 @@ void graphics_drawLine(point_t start, point_t end, color_t color)
|
|||
}
|
||||
}
|
||||
|
||||
void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill)
|
||||
void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill)
|
||||
{
|
||||
if(!initialized) return;
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
|
@ -167,18 +167,7 @@ void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t c
|
|||
}
|
||||
}
|
||||
|
||||
void printCentered(uint16_t y, const char *text, font_t fontSize, color_t color)
|
||||
{
|
||||
point_t origin = {0, y};
|
||||
printCore(origin, text, fontSize, TEXT_ALIGN_CENTER, color);
|
||||
}
|
||||
|
||||
void printAt(point_t pos, const char *text, font_t fontSize, color_t color)
|
||||
{
|
||||
printCore(pos, text, fontSize, TEXT_ALIGN_LEFT, color);
|
||||
}
|
||||
|
||||
void printCore(point_t start, const char *szMsg, font_t fontSize, textAlign_t alignment, color_t color)
|
||||
void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t alignment, color_t color)
|
||||
{
|
||||
uint8_t *currentCharData;
|
||||
uint8_t *currentFont;
|
||||
|
@ -187,7 +176,7 @@ void printCore(point_t start, const char *szMsg, font_t fontSize, textAlign_t al
|
|||
|
||||
rgb565_t color_565 = _true2highColor(color);
|
||||
|
||||
switch(fontSize)
|
||||
switch(size)
|
||||
{
|
||||
case FONT_SIZE_1:
|
||||
currentFont = (uint8_t *) font_6x8;
|
||||
|
@ -215,17 +204,14 @@ void printCore(point_t start, const char *szMsg, font_t fontSize, textAlign_t al
|
|||
int16_t charHeightPixels = currentFont[5]; // page count per char
|
||||
int16_t bytesPerChar = currentFont[7]; // bytes per char
|
||||
|
||||
int16_t sLen = strlen(szMsg);
|
||||
int16_t sLen = strlen(text);
|
||||
// Compute amount of letters that fit till the end of the screen
|
||||
if ((charWidthPixels*sLen) + start.x > screen_width)
|
||||
{
|
||||
sLen = (screen_width-start.x)/charWidthPixels;
|
||||
}
|
||||
|
||||
if (sLen < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (sLen < 0) return;
|
||||
|
||||
switch(alignment)
|
||||
{
|
||||
|
@ -242,7 +228,7 @@ void printCore(point_t start, const char *szMsg, font_t fontSize, textAlign_t al
|
|||
|
||||
for (int16_t i=0; i<sLen; i++)
|
||||
{
|
||||
uint32_t charOffset = (szMsg[i] - startCode);
|
||||
uint32_t charOffset = (text[i] - startCode);
|
||||
|
||||
// End boundary checking.
|
||||
if (charOffset > endCode)
|
||||
|
|
|
@ -86,29 +86,29 @@ static void gfxThread(void *arg)
|
|||
int pos = 0;
|
||||
SDL_Event eventListener;
|
||||
|
||||
graphics_init();
|
||||
gfx_init();
|
||||
|
||||
while(1)
|
||||
{
|
||||
SDL_PollEvent(&eventListener);
|
||||
if(eventListener.type == SDL_QUIT) break;
|
||||
|
||||
graphics_clearScreen();
|
||||
gfx_clearScreen();
|
||||
point_t origin = {0, pos};
|
||||
color_t color_red = {255, 0, 0};
|
||||
color_t color_white = {255, 255, 255};
|
||||
graphics_drawRect(origin, display_screenWidth(), 20, color_red, 1);
|
||||
gfx_drawRect(origin, display_screenWidth(), 20, color_red, 1);
|
||||
char *buffer = "KEK";
|
||||
printCore(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_LEFT,color_white);
|
||||
graphics_render();
|
||||
while(graphics_renderingInProgress()) ;
|
||||
gfx_print(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_LEFT,color_white);
|
||||
gfx_render();
|
||||
while(gfx_renderingInProgress()) ;
|
||||
pos += 20;
|
||||
if(pos > graphics_screenHeight() - 20) pos = 0;
|
||||
if(pos > gfx_screenHeight() - 20) pos = 0;
|
||||
|
||||
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
||||
}
|
||||
|
||||
running = 0;
|
||||
OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
||||
graphics_terminate();
|
||||
gfx_terminate();
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue