Date: Thu, 12 Jul 2012 22:50:38 GMT From: Brooks Davis <brooks@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 214310 for review Message-ID: <201207122250.q6CMoc5r063650@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@214310?ac=10 Change 214310 by brooks@brooks_ecr_current on 2012/07/12 22:50:17 Add the beginnings of a dialog box function. Currently only pinch to close is supported, but basic text rendering works. Also add a function to fill buffers with a given color. Affected files ... .. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libde4tc/de4tc.c#7 edit .. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libde4tc/de4tc.h#7 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libde4tc/de4tc.c#7 (text+ko) ==== @@ -267,6 +267,16 @@ void +fb_fill_buf(u_int32_t *buf, u_int32_t color, int width, int height) +{ + int i; + + for (i = 0; i < width * height; i++) + buf[i] = color; +} + + +void fb_post(u_int32_t *buf) { int addr; @@ -511,3 +521,126 @@ for(x=0; x<maxwidth; x++) imgbuf[x+y*maxwidth] = 0; } + +#define FBD_BORDER_LWIDTH 2 +#define FBD_BORDER_SPACE 3 +#define FBD_BORDER_WIDTH (FBD_BORDER_LWIDTH + FBD_BORDER_SPACE * 2) +fb_dialog_action +fb_dialog(fb_dialog_type type, u_int32_t bcolor, u_int32_t bgcolor, + u_int32_t tcolor, const char *title, const char *text) +{ + int dheight, dwidth, x0, y0, x, y; + int i, textlines, linewidth, maxwidth; + int textheight, textwidth, titleheight, titlewidth; + char **lines; + char *textdup; + u_int32_t *textbuf, *titlebuf; + struct tsstate *ts; + + titlewidth = strlen(title) * fb_get_font_width() * 2; + titleheight = fb_get_font_height() * 2; + + textlines = 0; + linewidth = 0; + textwidth = 0; + for (i = 0; text[i] != '\0'; i++) { + if (text[i] == '\n') { + textlines++; + textwidth = (linewidth > textwidth) ? linewidth : + textwidth; + linewidth = 0; + } else + linewidth++; + } + textlines++; + textwidth = (linewidth > textwidth) ? linewidth : textwidth; + textwidth *= fb_get_font_width() * 2; + textheight = fb_get_font_height() * 2; + + maxwidth = (textwidth > titlewidth) ? textwidth : titlewidth; + + dwidth = FBD_BORDER_WIDTH + maxwidth + FBD_BORDER_WIDTH; + if (dwidth > fb_width) + errx(1, "text too wide"); + + dheight = FBD_BORDER_WIDTH + titleheight + FBD_BORDER_WIDTH + + textheight * textlines + FBD_BORDER_WIDTH; + if (dheight > fb_height) + errx(1, "text too tall"); + + x0 = (fb_width - dwidth) / 2; + y0 = (fb_height - dheight) / 2; + + lines = malloc(textlines * sizeof(char *)); + if (lines == NULL) + err(1, "malloc"); + textdup = strdup(text); + if (textdup == NULL) + err(1, "strdup"); + textlines = 0; + lines[textlines] = textdup; + for (i = 0; textdup[i] != '\0'; i++) { + if (textdup[i] == '\n') { + textdup[i] = '\0'; + lines[++textlines] = &textdup[i+1]; + } + } + textlines++; + + fb_fill_region(bgcolor, x0, y0, dwidth, dheight); + for (x = x0 + FBD_BORDER_SPACE; x < x0 + dwidth - FBD_BORDER_SPACE; + x++) { + for (y = 0; y < FBD_BORDER_LWIDTH; y++) { + fb_putpixel(x, y0 + FBD_BORDER_SPACE + y, bcolor); + fb_putpixel(x, y0 + FBD_BORDER_SPACE + y + + FBD_BORDER_WIDTH + titleheight, bcolor); + fb_putpixel(x, y0 + FBD_BORDER_SPACE + y + dheight - + FBD_BORDER_WIDTH, bcolor); + } + } + for (y = y0 + FBD_BORDER_SPACE; y < y0 + dheight - FBD_BORDER_SPACE; + y++) { + for (x = 0; x < FBD_BORDER_LWIDTH; x++) { + fb_putpixel(x0 + FBD_BORDER_SPACE + x, y, bcolor); + fb_putpixel(x0 + dwidth + FBD_BORDER_SPACE + x - + FBD_BORDER_WIDTH, y, bcolor); + } + } + + titlebuf = malloc(sizeof(u_int32_t) * titlewidth * titleheight); + if (titlebuf == NULL) + err(1, "malloc"); + fb_render_text(title, 2, tcolor, bgcolor, titlebuf, + titlewidth, titleheight); + fb_post_region(titlebuf, + x0 + (dwidth - titlewidth) / 2, y0 + FBD_BORDER_WIDTH, + titlewidth, titleheight); + free(titlebuf); + + printf("text width %d height %d\n", textwidth, textheight); + textbuf = malloc(sizeof(u_int32_t) * textwidth * textheight); + if (textbuf == NULL) + err(1, "malloc"); + for(i = 0; i < textlines; i++) { + printf("writing text '%s'\n", lines[i]); + fb_fill_buf(textbuf, bgcolor, textwidth, textheight); + fb_render_text(lines[i], 2, tcolor, bgcolor, textbuf, + textwidth, textheight); + fb_post_region(textbuf, x0 + FBD_BORDER_WIDTH, + y0 + 2 * FBD_BORDER_WIDTH + titleheight + i * textheight, + textwidth, textheight); + } + free(textbuf); + free(lines); + + switch (type) { + case FBDT_PINCH2CLOSE: + for (;;) { + ts = ts_poll(); + if (ts->ts_gesture == TSG2_ZOOM_OUT) + return(FBDA_OK); + } + default: + err(1, "Unhandled dialog type"); + } +} ==== //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libde4tc/de4tc.h#7 (text+ko) ==== @@ -57,6 +57,22 @@ #define TSG2_ZOOM_IN 0x48 #define TSG2_ZOOM_OUT 0x49 +typedef enum { + FBDA_CANCEL, + FBDA_OK, + FBDA_YES, + FBDA_NO +} fb_dialog_action; + +typedef enum { + FBDT_PINCH2CLOSE, +#ifdef NOTYET + FBDT_OK, + FBDT_OKCANCEL, + FBDT_YESNO +#endif +} fb_dialog_type; + struct tsstate { int ts_x1; int ts_y1; @@ -89,6 +105,7 @@ void fb_putpixel(int px, int py, int colour); void fb_fill(int col); void fb_fill_region(u_int32_t colour, int x, int y, int w, int h); +void fb_fill_buf(u_int32_t *buf, u_int32_t color, int width, int height); void fb_post(u_int32_t *buf); void fb_post_region(u_int32_t *buf, int x, int y, int w, int h); void fb_blend(int blend_text_bg, int blend_text_fg, int blend_pixel, int wash); @@ -96,6 +113,7 @@ void fb_fade2off(void); void fb_fade2on(void); void fb_fade2text(int textbg_alpha); + void plot_line(int x1, int y1, int x2, int y2, unsigned int colour); void read_png_file(const char* file_name, u_int32_t* imgbuf, int maxwidth, int maxheight); @@ -104,5 +122,7 @@ int fb_get_font_width(void); void fb_render_text(const char *string, int expand, u_int32_t con, u_int32_t coff, u_int32_t *buffer, int w, int h); +fb_dialog_action fb_dialog(fb_dialog_type type, u_int32_t bcolor, + u_int32_t bgcolor, u_int32_t tcolor, const char *title, const char *text); #endif /* !_DE4TC_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207122250.q6CMoc5r063650>