From: bernie Date: Thu, 27 Apr 2006 05:39:24 +0000 (+0000) Subject: Enhance text rendering to arbitrary x,y coords. X-Git-Tag: 1.0.0~645 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=81ba34ccf5b8be398101bbcf54d5e6cc9d2eda05;p=bertos.git Enhance text rendering to arbitrary x,y coords. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@596 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/gfx/gfx.h b/gfx/gfx.h index 2cfe5b5f..a165fd7e 100755 --- a/gfx/gfx.h +++ b/gfx/gfx.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.14 2006/04/27 05:39:24 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* *#* Revision 1.13 2006/04/11 00:08:24 bernie *#* text_offset(): New function, but I'm not quite confident with the design. *#* @@ -141,6 +144,8 @@ typedef struct Bitmap * The text rendering routine can apply a few simple transformations * to the current font in order to generate common styles such as * bold, italic and underline from plain glyphs. + * + * \see text_style() */ uint8_t styles; #endif diff --git a/gfx/text.c b/gfx/text.c index a9f653c4..28dbd8e3 100755 --- a/gfx/text.c +++ b/gfx/text.c @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.10 2006/04/27 05:39:23 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* *#* Revision 1.9 2006/04/11 00:08:24 bernie *#* text_offset(): New function, but I'm not quite confident with the design. *#* @@ -107,41 +110,35 @@ #include -/*! ANSI escape sequences flag: true for ESC state on */ +/** + * ANSI escape sequences flag: true for ESC state on. + * + * \fixme Move to Bitmap.flags. + */ static bool ansi_mode = false; -// FIXME: move in bitmap? -static coord_t text_xoff, text_yoff; - -void text_offset(Bitmap *bm, coord_t x, coord_t y) +/*! + * Move (imaginary) cursor to coordinates specified. + */ +void text_setCoord(struct Bitmap *bm, int x, int y) { - text_xoff = x; - text_yoff = y; + bm->penX = x; + bm->penY = y; } + /*! * Move (imaginary) cursor to column and row specified. * Next text write will start a that row and col. */ -void text_moveto(struct Bitmap *bm, int row, int col) +void text_moveTo(struct Bitmap *bm, int row, int col) { ASSERT(col >= 0); ASSERT(col < bm->width / bm->font->width); ASSERT(row >= 0); ASSERT(row < bm->height / bm->font->height); - bm->penX = col * bm->font->width + text_xoff; - bm->penY = row * bm->font->height + text_yoff; -} - - -/*! - * Move (imaginary) cursor to coordinates specified. - */ -void text_setcoord(struct Bitmap *bm, int x, int y) -{ - bm->penX = x; - bm->penY = y; + text_setCoord(bm, col * bm->font->width, row * bm->font->height); } diff --git a/gfx/text.h b/gfx/text.h index 76ffa55d..4f603061 100755 --- a/gfx/text.h +++ b/gfx/text.h @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.6 2006/04/27 05:39:24 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* *#* Revision 1.5 2006/04/11 00:08:24 bernie *#* text_offset(): New function, but I'm not quite confident with the design. *#* @@ -68,6 +71,7 @@ #include #include /* BV() */ #include /* CPU_HARVARD */ +#include /* coord_t */ #include @@ -110,9 +114,8 @@ struct Bitmap; /* Low-level text functions (mware/text.c) */ -void text_offset(struct Bitmap *bm, coord_t x, coord_t y); -void text_moveto(struct Bitmap *bm, int row, int col); -void text_setcoord(struct Bitmap *bm, int x, int y); +void text_moveTo(struct Bitmap *bm, int col, int row); +void text_setCoord(struct Bitmap *bm, int x, int y); int text_putchar(char c, struct Bitmap *bm); uint8_t text_style(struct Bitmap *bm, uint8_t flags, uint8_t mask); void text_clear(struct Bitmap *bm); @@ -122,6 +125,8 @@ void text_clearLine(struct Bitmap *bm, int line); int text_puts(const char *str, struct Bitmap *bm); int text_vprintf(struct Bitmap *bm, const char *fmt, va_list ap); int text_printf(struct Bitmap *bm, const char *fmt, ...) FORMAT(__printf__, 2, 3); +int text_xyvprintf(struct Bitmap *bm, coord_t x, coord_t y, uint16_t mode, const char *fmt, va_list ap); +int text_xyprintf(struct Bitmap *bm, coord_t x, coord_t col, uint16_t mode, const char *fmt, ...) FORMAT(__printf__, 5, 6); int text_xprintf(struct Bitmap *bm, uint8_t row, uint8_t col, uint16_t mode, const char *fmt, ...) FORMAT(__printf__, 5, 6); int text_vwidthf(struct Bitmap *bm, const char * fmt, va_list ap); int text_widthf(struct Bitmap *bm, const char * fmt, ...) FORMAT(__printf__, 2, 3); diff --git a/gfx/text_format.c b/gfx/text_format.c index 54dab7c8..433794ad 100755 --- a/gfx/text_format.c +++ b/gfx/text_format.c @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.9 2006/04/27 05:39:24 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* *#* Revision 1.8 2006/03/22 09:50:11 bernie *#* Don't use C99 stuff. *#* @@ -144,32 +147,18 @@ int PGM_FUNC(text_printf)(struct Bitmap *bm, const char * PGM_ATTR fmt, ...) return len; } - -/*! - * Render the result of printf()-like formatting in a specified position - * of a Bitmap. - * - * \param bm Bitmap where to render the text - * \param row Starting row in character units (zero based) - * \param col Starting column in character units (zero based) - * \param style Formatting style to use. In addition to any STYLEF_ - * flag, it can be TEXT_NORMAL, TEXT_FILL, TEXT_INVERT or - * TEXT_RIGHT, or a combination of these flags ORed together. - * \param fmt String possibly containing printf() formatting commands. +/** + * Render text with vprintf()-like formatting at a specified pixel position. * - * \see text_puts() text_putchar() text_printf() text_vprintf() - * \see text_moveto() text_style() + * \see text_xyprintf() */ -int PGM_FUNC(text_xprintf)(struct Bitmap *bm, - uint8_t row, uint8_t col, uint16_t style, const char * PGM_ATTR fmt, ...) +int PGM_FUNC(text_xyvprintf)(struct Bitmap *bm, + coord_t x, coord_t y, uint16_t style, const char * PGM_ATTR fmt, va_list ap) { int len; uint8_t oldstyle = 0; - va_list ap; - va_start(ap, fmt); - - text_moveto(bm, row, col); + text_setCoord(bm, x, y); if (style & STYLEF_MASK) oldstyle = text_style(bm, style, STYLEF_MASK); @@ -182,17 +171,16 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm, pad /= 2; if (style & TEXT_FILL) - gfx_rectFillC(bm, 0, row * bm->font->height, pad, (row + 1) * bm->font->height, + gfx_rectFillC(bm, 0, y, pad, y + bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); - text_setcoord(bm, pad, row * bm->font->height); + text_setCoord(bm, pad, y); } len = PGM_FUNC(text_vprintf)(bm, fmt, ap); - va_end(ap); if (style & TEXT_FILL) - gfx_rectFillC(bm, bm->penX, row * bm->font->height, bm->width, (row + 1) * bm->font->height, + gfx_rectFillC(bm, bm->penX, y, bm->width, y + bm->font->height, (style & STYLEF_INVERT) ? 0xFF : 0x00); /* Restore old style */ @@ -203,6 +191,55 @@ int PGM_FUNC(text_xprintf)(struct Bitmap *bm, } +/** + * Render text with printf()-like formatting at a specified pixel position. + * + * \param bm Bitmap where to render the text + * \param x [pixels] Initial X coordinate of text. + * \param y [pixels] Coordinate of top border of text. + * \param style Formatting style to use. In addition to any STYLEF_ + * flag, it can be TEXT_NORMAL, TEXT_FILL, TEXT_INVERT or + * TEXT_RIGHT, or a combination of these flags ORed together. + * \param fmt String possibly containing printf() formatting commands. + * + * \see text_puts() text_putchar() text_printf() text_vprintf() + * \see text_moveTo() text_style() + */ +int PGM_FUNC(text_xyprintf)(struct Bitmap *bm, + coord_t x, coord_t y, uint16_t style, const char * PGM_ATTR fmt, ...) +{ + int len; + va_list ap; + + va_start(ap, fmt); + len = PGM_FUNC(text_xyvprintf)(bm, x, y, style, fmt, ap); + va_end(ap); + + return len; +} + + +/** + * Render text with printf()-like formatting at a specified row/column position. + * + * \see text_xyprintf() + */ +int PGM_FUNC(text_xprintf)(struct Bitmap *bm, + uint8_t row, uint8_t col, uint16_t style, const char * PGM_ATTR fmt, ...) +{ + int len; + va_list ap; + + va_start(ap, fmt); + len = PGM_FUNC(text_xyvprintf)( + bm, col * bm->font->width, row * bm->font->height, + style, fmt, ap); + va_end(ap); + + return len; +} + + struct TextWidthData { Bitmap *bitmap; diff --git a/mware/menu.c b/mware/menu.c index be52b5ff..9c1149db 100755 --- a/mware/menu.c +++ b/mware/menu.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.7 2006/04/27 05:39:24 bernie + *#* Enhance text rendering to arbitrary x,y coords. + *#* *#* Revision 1.6 2006/04/11 00:07:32 bernie *#* Implemenent MF_SAVESEL flag. *#* @@ -91,6 +94,10 @@ #include /* strncpy_P() */ #endif +#if CONFIG_MENU_SMOOTH +#include +#endif + #if CONFIG_MENU_MENUBAR #include "menubar.h" #endif @@ -101,7 +108,6 @@ #define PTRMSG(x) ((const char *)x) #endif - /* Temporary fake defines for ABORT stuff... */ #define abort_top 0 #define PUSH_ABORT false @@ -134,26 +140,6 @@ static int menu_count(const struct Menu *menu) return cnt; } -#if 0 /* UNUSED */ -/** - * Compute total number of visible entries, which excludes items - * without a label. - */ -static int menu_count_visible(const struct Menu *menu) -{ - struct MenuItem *item; - int visible_entries = 0; - - for (item = menu->items; (item->label || item->hook); ++item) - { - if (!(item->flags & MIF_HIDDEN)) - ++visible_entries; - } - - return visible_entries; -} -#endif - #if CONFIG_MENU_MENUBAR /*! @@ -205,20 +191,35 @@ static void menu_layout( { int ypos, cnt; const char * PROGMEM title = PTRMSG(menu->title); + Bitmap *bm = menu->bitmap; - ypos = 0; + ypos = bm->cr.ymin; if (title) - text_xprintf(menu->bitmap, ypos++, 0, STYLEF_UNDERLINE | STYLEF_BOLD | TEXT_CENTER | TEXT_FILL, title); + { + text_xyprintf(bm, 0, ypos, STYLEF_UNDERLINE | STYLEF_BOLD | TEXT_CENTER | TEXT_FILL, title); + ypos += bm->font->height; + } #if CONFIG_MENU_SMOOTH static coord_t yoffset = 0; static int old_first_item = 0; + static mtime_t old_time = 0; //UNUSED + static int speed; + coord_t old_ymin = bm->cr.ymin; + + gfx_setClipRect(bm, + bm->cr.xmin, bm->cr.ymin + ypos, + bm->cr.xmax, bm->cr.ymax); + if (old_first_item != first_item) { + speed = ABS(old_first_item - first_item) * 3; + if (old_first_item > first_item) { - if (++yoffset > menu->bitmap->font->height) + yoffset += speed; + if (yoffset > bm->font->height) { yoffset = 0; --old_first_item; @@ -226,7 +227,8 @@ static void menu_layout( } else { - if (--yoffset < -menu->bitmap->font->height) + yoffset -= speed; + if (yoffset < -bm->font->height) { yoffset = 0; ++old_first_item; @@ -234,7 +236,7 @@ static void menu_layout( } first_item = old_first_item; } - text_offset(menu->bitmap, 0, yoffset); + ypos += yoffset; #endif for (cnt = 0; cnt < items_per_page; ++cnt) @@ -257,12 +259,12 @@ static void menu_layout( if (!(item->flags & MIF_HIDDEN)) { #if CPU_HARVARD - text_xprintf_P + text_xyprintf_P #else - text_xprintf + text_xyprintf #endif ( - menu->bitmap, ypos++, 0, + bm, 0, ypos, (first_item + cnt == selected) ? (STYLEF_INVERT | TEXT_FILL) : TEXT_FILL, (item->flags & MIF_RAMLABEL) ? PSTR("%s%S") : PSTR("%S%S"), PTRMSG(item->label), @@ -270,8 +272,18 @@ static void menu_layout( ( (item->flags & MIF_CHECKED) ? PSTR(":ON") : PSTR(":OFF") ) : ( (item->flags & MIF_CHECKED) ? PSTR("\04") : PSTR("") ) ); + ypos += bm->font->height; } } + +#if CONFIG_MENU_SMOOTH + /* Restore old cliprect */ + gfx_setClipRect(bm, + bm->cr.xmin, old_ymin, + bm->cr.xmax, bm->cr.ymax); + + lcd_blitBitmap(&lcd_bitmap); +#endif } @@ -406,6 +418,9 @@ iptr_t menu_handle(const struct Menu *menu) /* Selected item should be a visible entry */ first_item = selected = menu_next_visible_item(menu, menu->selected - 1); + /* Clear screen */ + text_clear(menu->bitmap); + for(;;) { keymask_t key; @@ -418,8 +433,6 @@ iptr_t menu_handle(const struct Menu *menu) while (selected >= first_item + items_per_page) first_item = menu_next_visible_item(menu, first_item); - /* Clear screen */ - text_clear(menu->bitmap); menu_layout(menu, first_item, items_per_page, selected); #if CONFIG_MENU_MENUBAR @@ -453,6 +466,9 @@ iptr_t menu_handle(const struct Menu *menu) CONST_CAST(struct Menu *, menu)->selected = selected; return item->userdata; } + + /* Clear screen */ + text_clear(menu->bitmap); } else if (key & K_UP) {