cleanups (coding style...)

ugfx_release_2.6
Tectu 2012-06-13 21:48:29 +02:00
parent 6599378981
commit 4d4acdd9d1
2 changed files with 45 additions and 49 deletions

92
glcd.c
View File

@ -4,13 +4,10 @@
#include <math.h> #include <math.h>
uint16_t lcd_width, lcd_height; uint16_t lcd_width, lcd_height;
uint16_t bgcolor=White, fgcolor=Black; uint16_t bgcolor=White, fgcolor=Black;
uint16_t cx, cy; uint16_t cx, cy;
static uint8_t tpText=0; static uint8_t tpText=0;
uint8_t* font;
const uint8_t* font;
void lcdInit(void) { void lcdInit(void) {
lld_lcdInit(); lld_lcdInit();
@ -128,47 +125,45 @@ void lcdEnableTransparentText(uint8_t en) {
void lcdDrawChar(char c) { void lcdDrawChar(char c) {
const uint8_t* ptr; const uint8_t* ptr;
uint8_t fontHeight = lcdGetCurFontHeight();
uint8_t fontHeight=lcdGetCurFontHeight(); uint8_t sps = font[FONT_TABLE_PAD_AFTER_CHAR_IDX];
uint8_t sps=font[FONT_TABLE_PAD_AFTER_CHAR_IDX];
uint16_t chi; uint16_t chi;
uint16_t x,y; uint16_t x,y;
// No support for nongraphic characters, so just ignore them // No support for nongraphic characters, so just ignore them
if (c<0x20||c>0x7F) { if(c < 0x20 || c > 0x7F) {
if (c=='\n') lcdLineBreak(); if(c=='\n')
lcdLineBreak();
return; return;
} }
chi=*(uint16_t*)(&font[FONT_TABLE_CHAR_LOOKUP_IDX+ (c-0x20)*2]); chi = *(uint16_t*)(&font[FONT_TABLE_CHAR_LOOKUP_IDX + (c-0x20)*2]);
ptr=font+chi; ptr = font + chi;
uint8_t fontWidth=*(ptr++); uint8_t fontWidth = *(ptr++);
if (cx+fontWidth>lcdGetWidth()) lcdLineBreak(); if(cx + fontWidth > lcdGetWidth())
lcdLineBreak();
for (x=0;x<fontWidth;x++) { for(x = 0; x < fontWidth; x++) {
chi=*(uint16_t*)ptr; chi = *(uint16_t*)ptr;
for(y = 0; y < fontHeight; y++) {
for (y=0;y<fontHeight;y++) { if(chi & 0x01)
if (chi&0x01)
lcdDrawPixel(cx+x, cy+y, fgcolor); lcdDrawPixel(cx+x, cy+y, fgcolor);
else if (!tpText) else if(!tpText)
lcdDrawPixel(cx+x, cy+y, bgcolor); lcdDrawPixel(cx+x, cy+y, bgcolor);
chi>>=1; chi >>= 1;
} }
ptr+=2; ptr += 2;
} }
cx+=fontWidth; cx += fontWidth;
if (sps!=0) { if(sps != 0) {
if (!tpText) lcdFillArea(cx,cy,sps,fontHeight,fgcolor); if(!tpText)
cx+=sps; lcdFillArea(cx, cy, sps, fontHeight, fgcolor);
cx += sps;
} }
} }
@ -177,47 +172,48 @@ void lcdPutString(const char *str) {
} }
void lcdDrawString(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bkcolor) { void lcdDrawString(uint16_t x, uint16_t y, const char *str, uint16_t color, uint16_t bkcolor) {
uint16_t _bg=bgcolor, _fg=fgcolor; uint16_t _bg = bgcolor, _fg = fgcolor;
cx=x; cx = x;
cy=y; cy = y;
bgcolor=bkcolor; bgcolor = bkcolor;
fgcolor=color; fgcolor = color;
lcdPutString(str); lcdPutString(str);
bgcolor=_bg; bgcolor = _bg;
fgcolor=_fg; fgcolor = _fg;
} }
uint16_t lcdMeasureChar(char c) { uint16_t lcdMeasureChar(char c) {
const uint8_t* ptr; const uint8_t *ptr;
// First get spaces after each character, usually 0 but can change // First get spaces after each character, usually 0 but can change
uint8_t sps=font[FONT_TABLE_PAD_AFTER_CHAR_IDX]; uint8_t sps = font[FONT_TABLE_PAD_AFTER_CHAR_IDX];
uint16_t chi; uint16_t chi;
if (c<0x20||c>0x7F) { if(c < 0x20 || c > 0x7F)
return 0; return 0;
}
chi=*(uint16_t*)(&font[FONT_TABLE_CHAR_LOOKUP_IDX+ (c-0x20)*2]); chi = *(uint16_t*)(&font[FONT_TABLE_CHAR_LOOKUP_IDX + (c-0x20)*2]);
ptr=font+chi; ptr = font + chi;
uint8_t fontWidth=*(ptr++); uint8_t fontWidth = *(ptr++);
return fontWidth+sps; return fontWidth + sps;
} }
uint16_t lcdMeasureString(const char* str) { uint16_t lcdMeasureString(const char *str) {
uint16_t result=0; uint16_t result = 0;
while (*str) result+=lcdMeasureChar(*str++);
while (*str)result += lcdMeasureChar(*str++);
return result; return result;
} }
void lcdLineBreak() { void lcdLineBreak() {
// x=0 seems too much on the edge. So I keep it at 3 // x=0 seems too much on the edge. So I keep it at 3
cx=3; cx = 3;
cy+=lcdGetCurFontHeight(); cy += lcdGetCurFontHeight();
} }
uint16_t lcdBGR2RGB(uint16_t color) { uint16_t lcdBGR2RGB(uint16_t color) {

2
glcd.h
View File

@ -34,7 +34,7 @@ enum filled {frame, filled};
// For text rendering only // For text rendering only
extern uint16_t bgcolor, fgcolor; extern uint16_t bgcolor, fgcolor;
extern uint16_t cx, cy; extern uint16_t cx, cy;
extern const uint8_t* font; extern uint8_t* font;
// A few macros // A few macros
#define lcdGotoXY(x,y) { cx=x; cy=y; } #define lcdGotoXY(x,y) { cx=x; cy=y; }