A little bit code cleaning...

This commit is contained in:
Bertrand Songis
2015-10-14 23:47:51 +02:00
parent 2902ae1887
commit c92909f7c5
15 changed files with 42 additions and 107 deletions
+18 -84
View File
@@ -116,80 +116,14 @@ void lcdDrawBitmapPattern(coord_t x, coord_t y, const uint8_t * img, LcdFlags fl
#define FONT_MAX_HEIGHT 42
void lcdPutFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags)
{
bool blink = false;
bool inv = false;
if (flags & BLINK) {
if (BLINK_ON_PHASE) {
if (flags & INVERS)
inv = true;
else {
blink = true;
}
}
}
else if (flags & INVERS) {
inv = true;
}
coord_t w = *((uint16_t *)font);
coord_t width = getFontPatternWidth(spec, index);
coord_t height = *(((uint16_t *)font)+1);
assert(height <= FONT_MAX_HEIGHT);
for (int i=0; i<width+2; i++) {
if (x < LCD_W) {
uint8_t b[FONT_MAX_HEIGHT] = { 0 };
if (i == 0) {
if (x==0 || !inv) {
lcdNextPos++;
continue;
}
else {
// we need to work on the previous x when INVERS
x--;
}
}
else if (i <= width) {
for (coord_t j=0; j<height; ++j) {
uint8_t p = *(font + 4 + j*w + spec[index] + i - 1);
b[j] = p;
}
}
for (int j=-1; j<=height; ++j) {
uint8_t plot;
if (j < 0 || j == height) {
plot = 0;
if (j<0 && !inv) continue;
if (y+j < 0) continue;
}
else {
plot = b[j];
}
if (inv) plot = !plot;
if (!blink) {
if (plot) {
lcdDrawTransparentPixel(x, y+j, plot, lcdColorTable[COLOR_IDX(flags)]);
}
// TODO needed?
// else if (flags & ERASEBG) {
// lcdDrawPoint(x, y+j, 0x0FFF0000);
// }
}
}
}
x++;
lcdNextPos++;
}
lcdNextPos--;
coord_t offset = spec[index];
coord_t width = spec[index+1] - offset;
lcdDrawBitmapPattern(x, y, font, flags, offset, width);
lcdNextPos = x + width;
}
void lcd_putcAtt(coord_t x, coord_t y, const unsigned char c, LcdFlags flags)
{
lcdNextPos = x-1;
int fontindex = FONTSIZE(flags) >> 8;
const pm_uchar * font = fontsTable[fontindex];
const uint16_t * fontspecs = fontspecsTable[fontindex];
@@ -216,9 +150,9 @@ int getFontHeight(LcdFlags flags)
return heightTable[FONTSIZE(flags) >> 8];
}
int getTextWidth(const pm_char *s, int len, LcdFlags flags)
int getTextWidth(const pm_char * s, int len, LcdFlags flags)
{
const uint16_t *specs = fontspecsTable[FONTSIZE(flags) >> 8];
const uint16_t * specs = fontspecsTable[FONTSIZE(flags) >> 8];
int result = 0;
for (int i=0; (len==0 || i<len) && (*s!='\0'); ++i) {
char c;
@@ -236,18 +170,18 @@ void lcd_putsnAtt(coord_t x, coord_t y, const pm_char * s, uint8_t len, LcdFlags
{
int width = getTextWidth(s, len, flags);
int height = getFontHeight(flags);
int fontindex = FONTSIZE(flags) >> 8;
const pm_uchar * font = fontsTable[fontindex];
const uint16_t * fontspecs = fontspecsTable[fontindex];
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) {
if ((COLOR_IDX(flags) == TEXT_COLOR_INDEX)) {
flags += TEXT_INVERTED_COLOR - TEXT_COLOR;
if (FONTSIZE(flags) == TINSIZE)
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN+2, y-INVERT_VERT_MARGIN+2, width+2*INVERT_HORZ_MARGIN-5, INVERT_LINE_HEIGHT-7, TEXT_INVERTED_BGCOLOR);
else if (FONTSIZE(flags) == SMLSIZE)
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN+1, y-INVERT_VERT_MARGIN, width+2*INVERT_HORZ_MARGIN-2, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
else
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN, y-INVERT_VERT_MARGIN, width+2*INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
}
flags &= ~(INVERS|BLINK);
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE) && (COLOR_IDX(flags) == TEXT_COLOR_INDEX)) {
flags += TEXT_INVERTED_COLOR - TEXT_COLOR;
if (FONTSIZE(flags) == TINSIZE)
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN+2, y-INVERT_VERT_MARGIN+2, width+2*INVERT_HORZ_MARGIN-5, INVERT_LINE_HEIGHT-7, TEXT_INVERTED_BGCOLOR);
else if (FONTSIZE(flags) == SMLSIZE)
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN+1, y-INVERT_VERT_MARGIN, width+2*INVERT_HORZ_MARGIN-2, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
else
lcdDrawFilledRect(x-INVERT_HORZ_MARGIN, y-INVERT_VERT_MARGIN, width+2*INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
}
char str[256];
@@ -272,7 +206,7 @@ void lcd_putsnAtt(coord_t x, coord_t y, const pm_char * s, uint8_t len, LcdFlags
break;
}
else if (c >= 0x20) {
lcd_putcAtt(x, y, c, flags);
lcdPutFontPattern(x, y, font, fontspecs, getMappedChar(c), flags);
x = lcdNextPos;
}
else if (c == 0x1F) { // X-coord prefix
+5 -6
View File
@@ -238,7 +238,7 @@ void lcd_line(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat=SOLID,
#if !defined(SIMU)
inline void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFlags att)
{
lcdFillRectangle(x, y, w, h, lcdColorTable[COLOR_IDX(att)]);
lcdDrawFilledRectDMA(x, y, w, h, lcdColorTable[COLOR_IDX(att)]);
}
#else
void lcdDrawFilledRect(coord_t x, scoord_t y, coord_t w, coord_t h, LcdFlags att);
@@ -266,9 +266,10 @@ void lcdDrawFilledRectWithAttributes(coord_t x, scoord_t y, coord_t w, coord_t h
void drawBlackOverlay();
void lcd_rect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat=SOLID, LcdFlags att=0);
inline void lcd_square(coord_t x, coord_t y, coord_t w, LcdFlags att=0) { lcd_rect(x, y, w, w, SOLID, att); }
void lcdDrawTelemetryTopBar();
inline void lcdDrawSquare(coord_t x, coord_t y, coord_t w, LcdFlags att=0)
{
lcdDrawRect(x, y, w, w, att);
}
#define V_BAR(xx, yy, ll) \
lcd_vline(xx-1,yy-ll,ll); \
@@ -283,10 +284,8 @@ void lcdDrawBitmapPattern(coord_t x, coord_t y, const uint8_t * img, LcdFlags fl
#define lcdSetRefVolt(...)
void lcdSetContrast();
void lcdInit();
#define lcdOff(...)
void lcdRefresh();
void lcdSendByte(uint8_t data);
void lcdSend(const uint8_t * data, uint32_t size);
void lcdSendString(const char * s);
+1 -1
View File
@@ -138,7 +138,7 @@ void displayTrims(uint8_t phase)
lcd_vline(xm, ym-1, 3);
}
}
lcd_square(xm-3, ym-3, 7, att);
lcdDrawSquare(xm-3, ym-3, 7, att);
}
}
+2 -2
View File
@@ -53,10 +53,10 @@ void drawStick(coord_t centrex, int16_t xval, int16_t yval)
#define BOX_CENTERY (170 - FH - BOX_WIDTH/2)
#define MARKER_WIDTH 5
lcd_square(centrex-BOX_WIDTH/2, BOX_CENTERY-BOX_WIDTH/2, BOX_WIDTH, TEXT_COLOR);
lcdDrawSquare(centrex-BOX_WIDTH/2, BOX_CENTERY-BOX_WIDTH/2, BOX_WIDTH, TEXT_COLOR);
lcd_vlineStip(centrex, BOX_CENTERY-1, 3, SOLID, TEXT_COLOR);
lcd_hlineStip(centrex-1, BOX_CENTERY, 3, SOLID, TEXT_COLOR);
lcd_square(centrex + (xval/((2*RESX)/(BOX_WIDTH-MARKER_WIDTH))) - MARKER_WIDTH/2, BOX_CENTERY - (yval/((2*RESX)/(BOX_WIDTH-MARKER_WIDTH))) - MARKER_WIDTH/2, MARKER_WIDTH, ROUND|TEXT_COLOR);
lcdDrawSquare(centrex + (xval/((2*RESX)/(BOX_WIDTH-MARKER_WIDTH))) - MARKER_WIDTH/2, BOX_CENTERY - (yval/((2*RESX)/(BOX_WIDTH-MARKER_WIDTH))) - MARKER_WIDTH/2, MARKER_WIDTH, ROUND|TEXT_COLOR);
#undef BOX_CENTERY
#undef MARKER_WIDTH