add font centering, minor fixes
This commit is contained in:
+25
-3
@@ -231,17 +231,39 @@ static const int char_heights[] = {
|
|||||||
// library. AND HEAVILY MODIFIED
|
// library. AND HEAVILY MODIFIED
|
||||||
void LCD_setStrEx(const char *dString, int x, int y, enum Color color, struct TextStyle style)
|
void LCD_setStrEx(const char *dString, int x, int y, enum Color color, struct TextStyle style)
|
||||||
{
|
{
|
||||||
const int x0 = x;
|
struct Utf8Char uchar;
|
||||||
struct Utf8Iterator iter;
|
struct Utf8Iterator iter;
|
||||||
Utf8Iterator_Init(&iter, dString);
|
Utf8Iterator_Init(&iter, dString);
|
||||||
|
|
||||||
int charw = char_widths[style.size];
|
int charw = char_widths[style.size];
|
||||||
int charh = char_heights[style.size];
|
int charh = char_heights[style.size];
|
||||||
|
|
||||||
int spacingx = char_spacings[style.size] + style.spacing_x;
|
int spacingx = char_spacings[style.size] + style.spacing_x;
|
||||||
int spacingy = style.spacing_y;
|
int spacingy = style.spacing_y;
|
||||||
|
|
||||||
struct Utf8Char uchar;
|
if (style.align != ALIGN_LEFT) {
|
||||||
|
int line_len = 0;
|
||||||
|
int skip = style.skip;
|
||||||
|
while ((uchar = Utf8Iterator_Next(&iter)).uint) {
|
||||||
|
if (skip > 0) {
|
||||||
|
skip -= 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (uchar.bytes[0] == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
line_len++;
|
||||||
|
}
|
||||||
|
if (style.align == ALIGN_CENTER) {
|
||||||
|
x -= ((charw + spacingx) * line_len) / 2 - spacingx/2;
|
||||||
|
} else {
|
||||||
|
// right
|
||||||
|
x -= ((charw + spacingx) * line_len) - spacingx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const int x0 = x;
|
||||||
|
Utf8Iterator_Init(&iter, dString);
|
||||||
|
|
||||||
int limit = style.limit;
|
int limit = style.limit;
|
||||||
int skip = style.skip;
|
int skip = style.skip;
|
||||||
bool wrap;
|
bool wrap;
|
||||||
|
|||||||
+15
-8
@@ -50,15 +50,22 @@ enum TextSize {
|
|||||||
FONT_BOLD = 2,
|
FONT_BOLD = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TextAlign {
|
||||||
|
ALIGN_LEFT = 0,
|
||||||
|
ALIGN_CENTER = 1,
|
||||||
|
ALIGN_RIGHT = 2,
|
||||||
|
};
|
||||||
|
|
||||||
struct TextStyle {
|
struct TextStyle {
|
||||||
bool bg; //!< Fill the characters background with the opposite color
|
bool bg; //!< Fill the characters background with the opposite color
|
||||||
enum TextSize size; //!< Character size
|
enum TextSize size; //!< Character size
|
||||||
int limit; //!< Number of characters to print from the string, if > 0
|
enum TextAlign align; //!< Alignment (works only for single line)
|
||||||
int skip; //!< Characters to skip before printing
|
int limit; //!< Number of characters to print from the string, if > 0
|
||||||
int spacing_x; //!< Additional X spacing
|
int skip; //!< Characters to skip before printing
|
||||||
int spacing_y; //!< Additional Y spacing
|
int spacing_x; //!< Additional X spacing
|
||||||
bool nowrap; //!< Stop painting when the right edge of the screen is reached
|
int spacing_y; //!< Additional Y spacing
|
||||||
bool wrap_to_0; //!< wrap to 0 instead of the initial X coordinate
|
bool nowrap; //!< Stop painting when the right edge of the screen is reached
|
||||||
|
bool wrap_to_0; //!< wrap to 0 instead of the initial X coordinate
|
||||||
};
|
};
|
||||||
|
|
||||||
// setStr draws a string of characters, calling setChar with
|
// setStr draws a string of characters, calling setChar with
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <freertos/timers.h>
|
|
||||||
|
|
||||||
#include "gui.h"
|
|
||||||
#include "nokia.h"
|
#include "nokia.h"
|
||||||
#include "liquid.h"
|
#include "liquid.h"
|
||||||
#include "drawing.h"
|
#include "drawing.h"
|
||||||
@@ -27,7 +25,6 @@ void gui_init() {
|
|||||||
* 0b10 - knowb CCW
|
* 0b10 - knowb CCW
|
||||||
* 0b100 - button released
|
* 0b100 - button released
|
||||||
* 0b1000 - button pressed
|
* 0b1000 - button pressed
|
||||||
* 0b10000 - ticker event
|
|
||||||
*
|
*
|
||||||
* @param arg
|
* @param arg
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <analog.h>
|
|
||||||
#include <firehazard.h>
|
|
||||||
|
|
||||||
|
#include "analog.h"
|
||||||
|
#include "firehazard.h"
|
||||||
|
#include "graphics/bitmaps.h"
|
||||||
#include "liquid.h"
|
#include "liquid.h"
|
||||||
#include "graphics/drawing.h"
|
#include "graphics/drawing.h"
|
||||||
#include "graphics/display_spec.h"
|
#include "graphics/display_spec.h"
|
||||||
@@ -74,8 +75,8 @@ static void paint(struct MenuScene *self)
|
|||||||
char buf[10];
|
char buf[10];
|
||||||
sprintf(buf, "%.0f", analog_read());
|
sprintf(buf, "%.0f", analog_read());
|
||||||
// TODO centering
|
// TODO centering
|
||||||
LCD_setStrEx(buf, 0, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE});
|
LCD_setStrEx(buf, XLINE/2, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE, .align = ALIGN_CENTER});
|
||||||
LCD_setStrEx("°C", 0, 17, BLACK, (struct TextStyle) {.size = FONT_BOLD});
|
LCD_setStrEx("°C", XLINE/2, 17, BLACK, (struct TextStyle) {.align = ALIGN_CENTER}); //.size = FONT_BOLD,
|
||||||
|
|
||||||
if (fire_enabled()) {
|
if (fire_enabled()) {
|
||||||
strcpy(buf, "RUN");
|
strcpy(buf, "RUN");
|
||||||
|
|||||||
Reference in New Issue
Block a user