1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-18 13:55:12 +03:00

3djc/taranis draw number review (#4157)

* Move to Horus style implementation

* TINSIZE handling

* Fix timers

* Add the option to align left on first digit (ie '-' if left of alignment point)

* Compile fix

* Reduce DBL font dot size

* Get ready for PR

* Remove unused function

* Remove leftover declaration

* Performance

* Cosmetics
This commit is contained in:
3djc 2016-12-23 23:57:32 +01:00 committed by Bertrand Songis
parent b0de35f57d
commit d1ef22ee47
5 changed files with 41 additions and 131 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before After
Before After

View file

@ -284,8 +284,21 @@ void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlag
break; break;
} }
else if (c >= 0x20) { else if (c >= 0x20) {
lcdDrawChar(x, y, c, flags); if ( ( c == 46) && ((FONTSIZE(flags) == TINSIZE) || (FONTSIZE(flags) == SMLSIZE))) { // '.' handling
x = lcdNextPos; uint8_t c_height = (FONTSIZE(flags) == TINSIZE ? 5 : 6);
if (flags & INVERS) {
lcdDrawSolidVerticalLine(x, y-1, c_height);
lcdDrawPoint(x, y + c_height);
}
else {
lcdDrawPoint(x, y + c_height -1 , flags);
}
x+=2;
}
else {
lcdDrawChar(x, y, c, flags);
x = lcdNextPos;
}
} }
else if (c == 0x1F) { //X-coord prefix else if (c == 0x1F) { //X-coord prefix
setx = true; setx = true;
@ -368,135 +381,33 @@ void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags)
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len) void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len)
{ {
uint8_t fw = FWNUM; char str[16+1];
int8_t mode = MODE(flags); char *s = str+16;
flags &= ~LEADING0; *s = '\0';
uint32_t fontsize = FONTSIZE(flags); int idx = 0;
bool dblsize = (fontsize == DBLSIZE); int mode = MODE(flags);
bool xxlsize = (fontsize == XXLSIZE);
bool midsize = (fontsize == MIDSIZE);
bool smlsize = (fontsize == SMLSIZE);
bool tinsize = (fontsize == TINSIZE);
bool neg = false; bool neg = false;
if (val < 0) { if (val < 0) {
neg = true;
val = -val; val = -val;
neg = true;
} }
do {
coord_t xn = 0; *--s = '0' + (val % 10);
uint8_t ln = 2; ++idx;
val /= 10;
if (mode != MODE(LEADING0)) { if (mode!=0 && idx==mode) {
len = 1; mode = 0;
int32_t tmp = val / 10; *--s = '.';
while (tmp) { if (val==0) {
len++; *--s = '0';
tmp /= 10;
}
if (len <= mode) {
len = mode + 1;
}
}
if (dblsize) {
fw += FWNUM;
}
else if (xxlsize) {
fw += 4*FWNUM-1;
}
else if (midsize) {
fw += FWNUM-3;
}
else if (tinsize) {
fw -= 1;
}
else {
if (!(flags & RIGHT)) {
if (mode > 0)
x += 2;
}
if (flags & BOLD) fw += 1;
}
if (!(flags & RIGHT)) {
x += len * fw;
if (neg) {
x += ((xxlsize|dblsize|midsize) ? 7 : FWNUM);
}
}
lcdLastPos = x;
x -= fw;
if (dblsize) x++;
for (uint8_t i=1; i<=len; i++) {
div_t qr = div(val, 10);
char c = qr.rem + '0';
LcdFlags f = flags;
lcdDrawChar(x, y, c, f);
if (mode == i) {
if (dblsize) {
xn = x - 2;
if (c>='2' && c<='3') ln++;
uint8_t tn = (qr.quot % 10);
if (tn==2 || tn==4) {
if (c=='4') {
xn++;
}
else {
xn--;
ln++;
}
}
}
else if (xxlsize) {
x -= 17;
lcdDrawChar(x+2, y, '.', f);
}
else if (midsize) {
x -= 3;
xn = x;
}
else if (smlsize) {
x -= 2;
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) {
lcdDrawSolidVerticalLine(x, y-1, 8, INVERS);
}
lcdDrawPoint(x, y+5);
}
else if (tinsize) {
x -= 2;
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) {
lcdDrawSolidVerticalLine(x, y-1, 7, INVERS);
}
lcdDrawPoint(x, y+4);
}
else {
x -= (flags & BOLD) ? 3 : 2;
lcdDrawChar(x, y, '.', f);
} }
} }
val = qr.quot; } while (val!=0 || mode>0 || (mode==MODE(LEADING0) && idx<len));
x -= fw; if (neg) {
if (i==len && (flags & BOLD)) x += 1; *--s = '-';
} }
flags &= ~LEADING0;
if (xn) { lcdDrawText(x, y, s, flags);
if (midsize) {
if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) {
lcdDrawSolidVerticalLine(xn, y, 12);
lcdDrawSolidVerticalLine(xn+1, y, 12);
}
lcdDrawSolidHorizontalLine(xn, y+9, 2);
lcdDrawSolidHorizontalLine(xn, y+10, 2);
}
else {
// TODO needed on CPUAVR? y &= ~0x07;
lcdDrawFilledRect(xn, y+2*FH-3, ln, 2);
}
}
if (neg) lcdDrawChar(x, y, '-', flags);
} }
#endif #endif
@ -551,12 +462,12 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
} }
} }
} }
#endif
void lcdDrawSolidVerticalLine(coord_t x, scoord_t y, scoord_t h, LcdFlags att) void lcdDrawSolidVerticalLine(coord_t x, scoord_t y, scoord_t h, LcdFlags att)
{ {
lcdDrawVerticalLine(x, y, h, SOLID, att); lcdDrawVerticalLine(x, y, h, SOLID, att);
} }
#endif
void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att) void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att)
{ {
@ -627,7 +538,7 @@ void drawTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att, LcdFlags att2
if (att & TIMEHOUR) { if (att & TIMEHOUR) {
div_t qr2 = div(qr.quot, 60); div_t qr2 = div(qr.quot, 60);
lcdDrawNumber(x, y, qr2.quot, att|LEADING0|LEFT, 2); lcdDrawNumber(x, y, qr2.quot, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdLastPos, y, separator, att); lcdDrawChar(lcdNextPos, y, separator, att);
qr.quot = qr2.rem; qr.quot = qr2.rem;
if (att & MIDSIZE) if (att & MIDSIZE)
x += 17; x += 17;
@ -639,9 +550,9 @@ void drawTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att, LcdFlags att2
lcdDrawNumber(x, y, qr.quot, att|LEADING0|LEFT, 2); lcdDrawNumber(x, y, qr.quot, att|LEADING0|LEFT, 2);
if (att & TIMEBLINK) if (att & TIMEBLINK)
lcdDrawChar(lcdLastPos, y, separator, BLINK); lcdDrawChar(lcdNextPos, y, separator, BLINK);
else else
lcdDrawChar(lcdLastPos, y, separator, att&att2); lcdDrawChar(lcdNextPos, y, separator, att&att2);
lcdDrawNumber(lcdNextPos, y, qr.rem, (att2|LEADING0) & (~RIGHT), 2); lcdDrawNumber(lcdNextPos, y, qr.rem, (att2|LEADING0) & (~RIGHT), 2);
} }

View file

@ -2,7 +2,7 @@
* Copyright (C) OpenTX * Copyright (C) OpenTX
* *
* Based on code named * Based on code named
* th9x - http://code.google.com/p/th9x * th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x * er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x * gruvin9x - http://code.google.com/p/gruvin9x
* *
@ -118,7 +118,6 @@ void lcdDrawTextAlignedLeft(coord_t y, const pm_char * s);
#define lcdDrawTextAlignedCenter(y, s) lcdDrawText((LCD_W-sizeof(TR_##s)*FW+FW+1)/2, y, STR_##s) #define lcdDrawTextAlignedCenter(y, s) lcdDrawText((LCD_W-sizeof(TR_##s)*FW+FW+1)/2, y, STR_##s)
void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags mode=0); void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags mode=0);
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode, uint8_t len); void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode, uint8_t len);
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode=0); void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags mode=0);

View file

@ -214,7 +214,7 @@ Display a number at (x,y)
@param value (number) value to display @param value (number) value to display
@param flags (unsigned number) drawing flags: @param flags (unsigned number) drawing flags:
* `0 or not specified` normal representation * `0 or not specified` display with no decimal (like abs())
* `PREC1` display with one decimal place (number 386 is displayed as 38.6) * `PREC1` display with one decimal place (number 386 is displayed as 38.6)
* `PREC2` display with tow decimal places (number 386 is displayed as 3.86) * `PREC2` display with tow decimal places (number 386 is displayed as 3.86)
* other general LCD flag also apply * other general LCD flag also apply

Binary file not shown.

Before

Width:  |  Height:  |  Size: 389 B

After

Width:  |  Height:  |  Size: 373 B

Before After
Before After