From owner-p4-projects@FreeBSD.ORG Thu Jul 12 22:50:39 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5D0491065673; Thu, 12 Jul 2012 22:50:39 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F96B1065670 for ; Thu, 12 Jul 2012 22:50:39 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 07D7E8FC19 for ; Thu, 12 Jul 2012 22:50:39 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q6CMocq7063653 for ; Thu, 12 Jul 2012 22:50:38 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q6CMoc5r063650 for perforce@freebsd.org; Thu, 12 Jul 2012 22:50:38 GMT (envelope-from brooks@freebsd.org) Date: Thu, 12 Jul 2012 22:50:38 GMT Message-Id: <201207122250.q6CMoc5r063650@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 214310 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2012 22:50:39 -0000 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 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_ */