Add GDISP font routines. Fix demo bugs

Add GDISP font routines to Open and Close a font by name.
Allows wildcard searching for fonts.
Old global font variables are now only optionally included (soon to be
deprecated).
More demo fixing
This commit is contained in:
Andrew Hannam 2012-12-07 00:52:01 +10:00
parent ec89b8e82d
commit 5873d87ca2
17 changed files with 374 additions and 127 deletions

View File

@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 FALSE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -26,10 +26,18 @@
#define GDISP_NEED_SCROLL FALSE
#define GDISP_NEED_PIXELREAD FALSE
#define GDISP_NEED_CONTROL FALSE
#define GDISP_NEED_MULTITHREAD FALSE
#define GDISP_NEED_MULTITHREAD TRUE
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -26,8 +26,8 @@
#define PEN_SIZE 20
#define OFFSET 3
#define COLOR_BOX(a) (x >= a && x <= a + COLOR_SIZE)
#define PEN_BOX(a) (y >= a && y <= a + COLOR_SIZE)
#define COLOR_BOX(a) (ev.x >= a && ev.x <= a + COLOR_SIZE)
#define PEN_BOX(a) (ev.y >= a && ev.y <= a + COLOR_SIZE)
#define GET_COLOR(a) (COLOR_BOX(a * COLOR_SIZE + OFFSET))
#define GET_PEN(a) (PEN_BOX(a * 2 * PEN_SIZE + OFFSET))
#define DRAW_COLOR(a) (a * COLOR_SIZE + OFFSET)
@ -37,9 +37,13 @@
void drawScreen(void) {
char *msg = "ChibiOS/GFX";
font_t font1, font2;
font1 = gdispOpenFont("UI2 Double");
font2 = gdispOpenFont("LargeNumbers");
gdispClear(White);
gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, &fontUI2Double)-3, 3, msg, &fontUI2Double, Black);
gdispDrawString(gdispGetWidth()-gdispGetStringWidth(msg, font1)-3, 3, msg, font1, Black);
/* colors */
gdispFillArea(0 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* Black */
@ -50,11 +54,14 @@ void drawScreen(void) {
gdispDrawBox (5 * COLOR_SIZE + 3, 3, COLOR_SIZE, COLOR_SIZE, Black); /* White */
/* pens */
gdispDrawString(OFFSET * 2, DRAW_PEN(1), "1", &fontLargeNumbers, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(2), "2", &fontLargeNumbers, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(3), "3", &fontLargeNumbers, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(4), "4", &fontLargeNumbers, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(5), "5", &fontLargeNumbers, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(1), "1", font2, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(2), "2", font2, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(3), "3", font2, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(4), "4", font2, Black);
gdispDrawString(OFFSET * 2, DRAW_PEN(5), "5", font2, Black);
gdispCloseFont(font1);
gdispCloseFont(font2);
}
GEventMouse ev;
@ -73,11 +80,11 @@ int main(void) {
while (TRUE) {
ginputGetMouseStatus(0, &ev);
if (!(ev->current_buttons & GINPUT_MOUSE_BTN_LEFT))
if (!(ev.current_buttons & GINPUT_MOUSE_BTN_LEFT))
continue;
/* inside color box ? */
if(ev->y >= OFFSET && ev->y <= COLOR_SIZE) {
if(ev.y >= OFFSET && ev.y <= COLOR_SIZE) {
if(GET_COLOR(0)) color = Black;
else if(GET_COLOR(1)) color = Red;
else if(GET_COLOR(2)) color = Yellow;
@ -86,7 +93,7 @@ int main(void) {
else if(GET_COLOR(5)) color = White;
/* inside pen box ? */
} else if(ev->x >= OFFSET && ev->x <= PEN_SIZE) {
} else if(ev.x >= OFFSET && ev.x <= PEN_SIZE) {
if(GET_PEN(1)) pen = 0;
else if(GET_PEN(2)) pen = 1;
else if(GET_PEN(3)) pen = 2;
@ -94,11 +101,11 @@ int main(void) {
else if(GET_PEN(5)) pen = 4;
/* inside drawing area ? */
} else if(DRAW_AREA(ev->x, ev->y)) {
} else if(DRAW_AREA(ev.x, ev.y)) {
if(pen == 0)
gdispDrawPixel(ev->x, ev->y, color);
gdispDrawPixel(ev.x, ev.y, color);
else
gdispFillCircle(ev->x, ev->y, pen, color);
gdispFillCircle(ev.x, ev.y, pen, color);
}
}
}

View File

@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL TRUE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE TRUE

View File

@ -37,6 +37,7 @@ BaseSequentialStream *S1, *S2, *S3;
int main(void) {
uint8_t i;
font_t font1, font2;
halInit();
chSysInit();
@ -44,11 +45,13 @@ int main(void) {
/* initialize and clear the display */
gdispInit();
gdispClear(Black);
font1 = gdispOpenFont("UI2 Double");
font2 = gdispOpenFont("Small");
/* create the three console windows and set a font for each */
GW1 = gwinCreateConsole(NULL, 0, 0, gdispGetWidth(), gdispGetHeight()/2, &fontUI2Double);
GW2 = gwinCreateConsole(NULL, 0, gdispGetHeight()/2, gdispGetWidth()/2, gdispGetHeight(), &fontSmall);
GW3 = gwinCreateConsole(NULL, gdispGetWidth()/2, gdispGetHeight()/2, gdispGetWidth(), gdispGetHeight(), &fontSmall);
GW1 = gwinCreateConsole(NULL, 0, 0, gdispGetWidth(), gdispGetHeight()/2, font1);
GW2 = gwinCreateConsole(NULL, 0, gdispGetHeight()/2, gdispGetWidth()/2, gdispGetHeight(), font2);
GW3 = gwinCreateConsole(NULL, gdispGetWidth()/2, gdispGetHeight()/2, gdispGetWidth(), gdispGetHeight(), font2);
/* Set the fore- and background colors for each console */
gwinSetColor(GW1, Green);

View File

@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON TRUE
#define GWIN_NEED_CONSOLE TRUE

View File

@ -40,6 +40,7 @@ int main(void) {
GHandle ghc, ghNext, ghPrev;
BaseSequentialStream *gp;
GEventType deviceType;
font_t font;
halInit(); // Initialise the Hardware
chSysInit(); // Initialize the OS
@ -51,10 +52,11 @@ int main(void) {
ghNext = ghPrev = 0;
// Create our title
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", &fontUI2, Red, White, justifyLeft);
font = gdispOpenFont("UI2");
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Red, White, justifyLeft);
// Create our main display window
ghc = gwinCreateConsole(&gc, 0, 20, swidth, sheight-20, &fontUI2);
ghc = gwinCreateConsole(&gc, 0, 20, swidth, sheight-20, font);
gwinClear(ghc);
gp = gwinGetConsoleStream(ghc);
@ -195,13 +197,13 @@ StepCalibrate:
/* From now on we can use Next and Previous Buttons */
if (!ghNext) {
ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, &fontUI2, GBTN_NORMAL);
ghNext = gwinCreateButton(&gNext, swidth-50, 0, 50, 20, font, GBTN_NORMAL);
gwinSetButtonText(ghNext, "Next", FALSE);
gsNext = gwinGetButtonSource(ghNext);
geventAttachSource(&gl, gsNext, 0);
gwinAttachButtonMouseSource(ghNext, gs);
ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, &fontUI2, GBTN_NORMAL);
ghPrev = gwinCreateButton(&gPrev, swidth-100, 0, 50, 20, font, GBTN_NORMAL);
gwinSetButtonText(ghPrev, "Back", FALSE);
gsPrev = gwinGetButtonSource(ghPrev);
geventAttachSource(&gl, gsPrev, 0);
@ -226,7 +228,7 @@ StepCalibrate:
}
// Calibration used the whole screen - re-establish our title
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", &fontUI2, Green, White, justifyLeft);
gdispFillStringBox(0, 0, swidth, 20, "Touch Calibration", font, Green, White, justifyLeft);
gwinButtonDraw(ghNext);
gwinButtonDraw(ghPrev);

View File

@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 FALSE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 FALSE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -19,7 +19,7 @@
/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_TEXT TRUE
#define GDISP_NEED_TEXT FALSE
#define GDISP_NEED_CIRCLE TRUE
#define GDISP_NEED_ELLIPSE FALSE
#define GDISP_NEED_ARC FALSE
@ -30,6 +30,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL FALSE
#define GDISP_INCLUDE_FONT_LARGER FALSE
#define GDISP_INCLUDE_FONT_UI1 FALSE
#define GDISP_INCLUDE_FONT_UI2 FALSE
#define GDISP_INCLUDE_FONT_LARGENUMBERS FALSE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -30,7 +30,7 @@
// This driver supports being both a mouse or a touch device (we don't actually know which it really is)
// When operating in mouse mode a long left button click does not generate a context click.
// When operating in touch mode we allow sloppier clicks etc
#if GINPUT_NEED_MOUSE
#if 1
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_MOUSE
#define GINPUT_MOUSE_CLICK_TIME TIME_INFINITE // Long click != Context Click
#define GINPUT_MOUSE_NEED_CALIBRATION FALSE

View File

@ -35,6 +35,14 @@
#define GDISP_NEED_ASYNC FALSE
#define GDISP_NEED_MSGAPI FALSE
/* Builtin Fonts */
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#define GDISP_INCLUDE_FONT_SMALL TRUE
#define GDISP_INCLUDE_FONT_LARGER TRUE
#define GDISP_INCLUDE_FONT_UI1 TRUE
#define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE
/* Features for the GWIN sub-system. */
#define GWIN_NEED_BUTTON FALSE
#define GWIN_NEED_CONSOLE FALSE

View File

@ -33,16 +33,6 @@
/* Don't test against GFX_USE_GDISP as we may want to use this in other non-GDISP utilities. */
/**
* @brief The maximum height of a font.
* @details Either 16 or 32. Defaults to 16
* @note Setting this to 32 causes the font tables to take
* twice the internal program memory.
*/
#ifndef GDISP_MAX_FONT_HEIGHT
#define GDISP_MAX_FONT_HEIGHT 16
#endif
/**
* @brief The type of a font column.
* @note Set by defining @p GDISP_MAX_FNT_HEIGHT appropriately.
@ -65,6 +55,7 @@
* to allow the tables to work across many different compilers.
*/
struct font {
const char * name;
uint8_t height;
uint8_t charPadding;
uint8_t lineSpacing;

View File

@ -96,25 +96,35 @@ typedef enum fontmetric {fontHeight, fontDescendersHeight, fontLineSpacing, font
/* External declarations. */
/*===========================================================================*/
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Predefined fonts.
*/
extern const struct font fontSmall;
extern const struct font fontSmallDouble;
extern const struct font fontSmallNarrow;
extern const struct font fontLarger;
extern const struct font fontLargerDouble;
extern const struct font fontLargerNarrow;
extern const struct font fontUI1;
extern const struct font fontUI1Double;
extern const struct font fontUI1Narrow;
extern const struct font fontUI2;
extern const struct font fontUI2Double;
extern const struct font fontUI2Narrow;
extern const struct font fontLargeNumbers;
extern const struct font fontLargeNumbersDouble;
extern const struct font fontLargeNumbersNarrow;
#if (GDISP_NEED_TEXT && GDISP_OLD_FONT_DEFINITIONS) || defined(__DOXYGEN__)
/**
* @brief Predefined fonts.
*/
#if GDISP_INCLUDE_FONT_SMALL
extern const struct font fontSmall;
extern const struct font fontSmallDouble;
extern const struct font fontSmallNarrow;
#endif
#if GDISP_INCLUDE_FONT_LARGER
extern const struct font fontLarger;
extern const struct font fontLargerDouble;
extern const struct font fontLargerNarrow;
#endif
#if GDISP_INCLUDE_FONT_UI1
extern const struct font fontUI1;
extern const struct font fontUI1Double;
extern const struct font fontUI1Narrow;
#endif
#if GDISP_INCLUDE_FONT_UI2
extern const struct font fontUI2;
extern const struct font fontUI2Double;
extern const struct font fontUI2Narrow;
#endif
#if GDISP_INCLUDE_FONT_LARGENUMBERS
extern const struct font fontLargeNumbers;
extern const struct font fontLargeNumbersDouble;
extern const struct font fontLargeNumbersNarrow;
#endif
#endif
#ifdef __cplusplus
@ -226,6 +236,9 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color);
coord_t gdispGetFontMetric(font_t font, fontmetric_t metric);
coord_t gdispGetCharWidth(char c, font_t font);
coord_t gdispGetStringWidth(const char* str, font_t font);
font_t gdispOpenFont(const char *name);
void gdispCloseFont(font_t font);
const char *gdispGetFontName(font_t font);
#endif
/* Extra Arc Functions */

View File

@ -149,6 +149,39 @@
#ifndef GDISP_NEED_ASYNC
#define GDISP_NEED_ASYNC FALSE
#endif
/**
* @}
*
* @name GDISP Fonts
* @{
*/
/**
* @brief Include the old global font variable definitions
* @details Defaults to FALSE
*/
#ifndef GDISP_OLD_FONT_DEFINITIONS
#define GDISP_OLD_FONT_DEFINITIONS FALSE
#endif
/**
* @brief Predefined built in fonts.
* @note Turning off the ones you are not using can save program size.
*/
#ifndef GDISP_INCLUDE_FONT_SMALL
#define GDISP_INCLUDE_FONT_SMALL TRUE
#endif
#ifndef GDISP_INCLUDE_FONT_LARGER
#define GDISP_INCLUDE_FONT_LARGER TRUE
#endif
#ifndef GDISP_INCLUDE_FONT_UI1
#define GDISP_INCLUDE_FONT_UI1 TRUE
#endif
#ifndef GDISP_INCLUDE_FONT_UI2
#define GDISP_INCLUDE_FONT_UI2 TRUE
#endif
#ifndef GDISP_INCLUDE_FONT_LARGENUMBERS
#define GDISP_INCLUDE_FONT_LARGENUMBERS TRUE
#endif
/**
* @}
*

View File

@ -18,9 +18,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Font tables included into gdisp.c
*/
/**
* @file src/gdisp/fonts.c
* @brief GDISP Font Handling.
*
* @addtogroup GDISP
* @{
*/
#include "ch.h"
#include "hal.h"
#include "gfx.h"
@ -29,26 +34,37 @@
#include "gdisp/fonts.h"
#if GDISP_OLD_FONT_DEFINITIONS
#define FONT_DECL
#else
#define FONT_DECL static
#endif
/* fontSmall - for side buttons */
#if 1
#if GDISP_INCLUDE_FONT_SMALL
/* Forward Declarations of internal arrays */
static const uint8_t fontSmall_Widths[];
static const uint16_t fontSmall_Offsets[];
static const fontcolumn_t fontSmall_Data[];
const struct font fontSmall = { 11, 0, 14, 2, 2, 12, ' ', '~', 1, 1,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
const struct font fontSmallDouble = { 11, 0, 14, 2, 2, 12, ' ', '~', 2, 2,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
const struct font fontSmallNarrow = { 11, 0, 14, 2, 2, 12, ' ', '~', 1, 2,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
FONT_DECL const struct font fontSmall = {
"Small",
11, 0, 14, 2, 2, 12, ' ', '~', 1, 1,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
FONT_DECL const struct font fontSmallDouble = {
"Small Double",
11, 0, 14, 2, 2, 12, ' ', '~', 2, 2,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
FONT_DECL const struct font fontSmallNarrow = {
"Small Narrow",
11, 0, 14, 2, 2, 12, ' ', '~', 1, 2,
fontSmall_Widths,
fontSmall_Offsets,
fontSmall_Data};
static const uint8_t fontSmall_Widths[] = {
2, 3, 6, 8, 7, 9, 7, 3, 4, 4, 5, 7, 4, 4, 3, 6,
@ -172,24 +188,30 @@
#endif
/* fontLarger - Tahoma, 11, Bold */
#if 1
#if GDISP_INCLUDE_FONT_LARGER
/* Forward Declarations of internal arrays */
static const uint8_t fontLarger_Widths[];
static const uint16_t fontLarger_Offsets[];
static const fontcolumn_t fontLarger_Data[];
const struct font fontLarger = { 12, 1, 13, 2, 2, 13, ' ', '~', 1, 1,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
const struct font fontLargerDouble = { 12, 1, 13, 2, 2, 13, ' ', '~', 2, 2,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
const struct font fontLargerNarrow = { 12, 1, 13, 2, 2, 13, ' ', '~', 1, 2,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
FONT_DECL const struct font fontLarger = {
"Larger",
12, 1, 13, 2, 2, 13, ' ', '~', 1, 1,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
FONT_DECL const struct font fontLargerDouble = {
"Larger Double",
12, 1, 13, 2, 2, 13, ' ', '~', 2, 2,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
FONT_DECL const struct font fontLargerNarrow = {
"Larger Narrow",
12, 1, 13, 2, 2, 13, ' ', '~', 1, 2,
fontLarger_Widths,
fontLarger_Offsets,
fontLarger_Data};
static const uint8_t fontLarger_Widths[] = {
2, 3, 5, 8, 7, 13, 8, 2, 4, 4, 7, 8, 3, 4, 3, 5,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 3, 9, 8, 9, 6,
@ -313,24 +335,30 @@
#endif
/* fontUI1 - UI Font 1 Medium Bold */
#if 1
#if GDISP_INCLUDE_FONT_UI1
/* Forward Declarations of internal arrays */
static const uint8_t fontUI1_Widths[];
static const uint16_t fontUI1_Offsets[];
static const fontcolumn_t fontUI1_Data[];
const struct font fontUI1 = { 13, 0, 15, 2, 3, 13, ' ', '~', 1, 1,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
const struct font fontUI1Double = { 13, 0, 15, 2, 3, 13, ' ', '~', 2, 2,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
const struct font fontUI1Narrow = { 13, 0, 15, 2, 3, 13, ' ', '~', 1, 2,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
FONT_DECL const struct font fontUI1 = {
"UI1",
13, 0, 15, 2, 3, 13, ' ', '~', 1, 1,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
FONT_DECL const struct font fontUI1Double = {
"UI1 Double",
13, 0, 15, 2, 3, 13, ' ', '~', 2, 2,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
FONT_DECL const struct font fontUI1Narrow = {
"UI1 Narrow",
13, 0, 15, 2, 3, 13, ' ', '~', 1, 2,
fontUI1_Widths,
fontUI1_Offsets,
fontUI1_Data};
static const uint8_t fontUI1_Widths[] = {
3, 3, 6, 8, 7, 13, 9, 3, 5, 5, 6, 8, 3, 5, 3, 7,
@ -455,24 +483,30 @@
#endif
/* fontUI1 - UI Font 2 Medium Bold */
#if 1
#if GDISP_INCLUDE_FONT_UI2
/* Forward Declarations of internal arrays */
static const uint8_t fontUI2_Widths[];
static const uint16_t fontUI2_Offsets[];
static const fontcolumn_t fontUI2_Data[];
const struct font fontUI2 = { 11, 1, 13, 2, 2, 12, ' ', '~', 1, 1,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
const struct font fontUI2Double = { 11, 1, 13, 2, 2, 12, ' ', '~', 2, 2,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
const struct font fontUI2Narrow = { 11, 1, 13, 2, 2, 12, ' ', '~', 1, 2,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
FONT_DECL const struct font fontUI2 = {
"UI2",
11, 1, 13, 2, 2, 12, ' ', '~', 1, 1,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
FONT_DECL const struct font fontUI2Double = {
"UI2 Double",
11, 1, 13, 2, 2, 12, ' ', '~', 2, 2,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
FONT_DECL const struct font fontUI2Narrow = {
"UI2 Narrow",
11, 1, 13, 2, 2, 12, ' ', '~', 1, 2,
fontUI2_Widths,
fontUI2_Offsets,
fontUI2_Data};
static const uint8_t fontUI2_Widths[] = {
2, 2, 5, 8, 6, 12, 8, 2, 4, 4, 6, 8, 2, 4, 2, 5,
@ -600,24 +634,29 @@
Large numbers font, height = 16 (including the decenders)
Characters include: 0 - 9, -, +, ., %, :, Space, Comma
*/
#if 1
#if GDISP_INCLUDE_FONT_LARGENUMBERS
/* Forward Declarations of internal arrays */
static const uint8_t fontLargeNumbers_Widths[];
static const uint16_t fontLargeNumbers_Offsets[];
static const fontcolumn_t fontLargeNumbers_Data[];
const struct font fontLargeNumbers = { 16, 2, 21, 1, 3, 15, '%', ':', 1, 1,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
const struct font fontLargeNumbersDouble = { 16, 2, 21, 1, 3, 15, '%', ':', 2, 2,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
const struct font fontLargeNumbersNarrow = { 16, 2, 21, 1, 3, 15, '%', ':', 1, 2,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
FONT_DECL const struct font fontLargeNumbers = {
"LargeNumbers",
16, 2, 21, 1, 3, 15, '%', ':', 1, 1,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
FONT_DECL const struct font fontLargeNumbersDouble = {
"LargeNumbers Double",
16, 2, 21, 1, 3, 15, '%', ':', 2, 2,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
FONT_DECL const struct font fontLargeNumbersNarrow = {
"LargeNumbers Narrow", 16, 2, 21, 1, 3, 15, '%', ':', 1, 2,
fontLargeNumbers_Widths,
fontLargeNumbers_Offsets,
fontLargeNumbers_Data};
static const uint8_t fontLargeNumbers_Widths[] = {
15, 0, 0, 0, 0, 0, 11, 3, 6, 3, 0, 10, 10, 10, 10, 10,
@ -649,4 +688,93 @@
};
#endif
static const struct font *BuiltinFontTable[] = {
#if GDISP_INCLUDE_FONT_SMALL
&fontSmall, &fontSmallDouble, &fontSmallNarrow,
#endif
#if GDISP_INCLUDE_FONT_LARGER
&fontLarger, &fontLargerDouble, &fontLargerNarrow,
#endif
#if GDISP_INCLUDE_FONT_UI1
&fontUI1, &fontUI1Double, &fontUI1Narrow,
#endif
#if GDISP_INCLUDE_FONT_UI2
&fontUI2, &fontUI2Double, &fontUI2Narrow,
#endif
#if GDISP_INCLUDE_FONT_LARGENUMBERS
&fontLargeNumbers, &fontLargeNumbersDouble, &fontLargeNumbersNarrow,
#endif
};
/**
* Match a pattern against the font name.
*/
static bool_t matchfont(const char *pattern, const char *name) {
while(1) {
switch (pattern[0]) {
case '*':
if (name[0] == 0)
return pattern[1] == 0;
if (pattern[1] == name[0])
pattern++;
else
name++;
break;
case 0:
return name[0] == 0;
default:
if (name[0] != pattern[0])
return FALSE;
pattern++;
name++;
break;
}
}
}
/**
* @brief Find a font and return it.
* @details The supplied name is matched against the font name. A '*' will replace 0 or more characters.
* @return Returns a font or NULL if no matching font could be found.
*
* @params[in] name The font name to find.
*
* @note Wildcard matching will match the shortest possible match.
*
* @api
*/
font_t gdispOpenFont(const char *name) {
const struct font **p;
for(p = BuiltinFontTable; p < BuiltinFontTable+sizeof(BuiltinFontTable)/sizeof(BuiltinFontTable[0]); p++) {
if (matchfont(name, p[0]->name))
return p[0];
}
return 0;
}
/**
* @brief Release a font after use.
*
* @params[in] font The font to release.
*
* @api
*/
void gdispCloseFont(font_t font) {
(void) font;
}
/**
* @brief Get the name of the specified font.
* @returns The name of the font.
*
* @params[in] font The font to get the name for.
*
* @api
*/
const char *gdispGetFontName(font_t font) {
return font->name;
}
#endif /* GFX_USE_GDISP && GDISP_NEED_TEXT */
/** @} */

View File

@ -38,8 +38,8 @@
#error "GINPUT: GFX_USE_GDISP must be defined when mouse or touch calibration is required"
#endif
#define GINPUT_MOUSE_CALIBRATION_FONT &fontUI2Double
#define GINPUT_MOUSE_CALIBRATION_FONT2 &fontUI2Narrow
#define GINPUT_MOUSE_CALIBRATION_FONT "* Double"
#define GINPUT_MOUSE_CALIBRATION_FONT2 "* Narrow"
#define GINPUT_MOUSE_CALIBRATION_TEXT "Calibration"
#define GINPUT_MOUSE_CALIBRATION_ERROR_TEXT "Failed - Please try again!"
#define GINPUT_MOUSE_CALIBRATION_SAME_TEXT "Error: Same Reading - Check Driver!"
@ -422,6 +422,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
MousePoint *pt;
int32_t px, py;
unsigned i, j;
font_t font1, font2;
#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
unsigned err;
#endif
@ -429,6 +430,9 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
if (instance || (MouseConfig.flags & FLG_IN_CAL))
return FALSE;
font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT);
font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2);
MouseConfig.flags |= FLG_IN_CAL;
gtimerStop(&MouseTimer);
MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED);
@ -446,7 +450,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
#endif
gdispClear(Blue);
gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, GINPUT_MOUSE_CALIBRATION_FONT, White, Blue, justifyCenter);
gdispFillStringBox(0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1, White, Blue, justifyCenter);
for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) {
_tsDrawCross(pc);
@ -475,7 +479,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
_tsClearCross(pc);
if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) {
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, GINPUT_MOUSE_CALIBRATION_FONT2, Red, Yellow, justifyCenter);
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter);
chThdSleepMilliseconds(5000);
gdispFillArea(0, 35, width, 40, Blue);
}
@ -503,12 +507,14 @@ bool_t ginputCalibrateMouse(uint16_t instance) {
if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR)
break;
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, GINPUT_MOUSE_CALIBRATION_FONT2, Red, Yellow, justifyCenter);
gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter);
chThdSleepMilliseconds(5000);
}
#endif
// Restart everything
gdispCloseFont(font1);
gdispCloseFont(font2);
MouseConfig.flags |= FLG_CAL_OK;
MouseConfig.last_buttons = 0;
get_calibrated_reading(&MouseConfig.t);