From: Peep P. <so...@us...> - 2004-08-05 13:24:52
|
Update of /cvsroot/agd/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24539 Modified Files: gui.c gui.h Log Message: gui_putchar, gui_printf, lots of cleanups Index: gui.c =================================================================== RCS file: /cvsroot/agd/client/gui.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- gui.c 3 Aug 2004 14:48:46 -0000 1.2 +++ gui.c 5 Aug 2004 13:24:43 -0000 1.3 @@ -5,8 +5,9 @@ #include "sys.h" static int numfonts, fontsalloced; -/*static*/ gui_font_t *fonts; -int cursor_y; +static gui_font_t *fonts; +int cursor_x, cursor_y; +extern BITMAP *buffer; void gui_init(void) { @@ -21,10 +22,15 @@ fonts = xrealloc(fonts, sizeof(BITMAP*) * (fontsalloced *= 2)); } fonts[numfonts].b = load_bitmap(filename, NULL); + if(!fonts[numfonts].b) { + printf("Can't load font %s\n", filename); + exit(1); + } fonts[numfonts].char_w = fonts[numfonts].b->w / 94; numfonts++; } +#if 0 gui_window_t *gui_new_window(int w, int h, int x, int y, int properties) { gui_window_t *win = xmalloc(sizeof(gui_window_t)); @@ -205,11 +211,48 @@ rectfill(bmp, x+1, y+1, x+w-1, y+h-1, col_face); gui_text(bmp, font, caption, x+(w/2-text_w/2)+1+pressed, y+(h/2-text_h/2)+1+pressed, w); } +#endif -/* returns 1 if wrapped */ -int gui_text(BITMAP *bmp, int font, char *text, int x, int y, int maxwidth) +void gui_goto(int x, int y) { - int scrx, i; + cursor_x = x; + cursor_y = y; +} + +void gui_newline(int font) +{ + cursor_y += fonts[font].b->h + 2; + cursor_x = 0; +} + +void gui_putchar(BITMAP *bmp, int font, char c) +{ + if(cursor_x + fonts[font].char_w >= SCREEN_W) + gui_newline(font); + + if(c == '\n') { + gui_newline(font); + return; + } + + masked_blit(fonts[font].b, bmp, fonts[font].char_w * (c - '!'), 0, + cursor_x, cursor_y, fonts[font].char_w, fonts[font].b->h); + cursor_x += fonts[font].char_w; +} + +/* returns length of written text if wrapped */ +int gui_text(BITMAP *bmp, int font, char *text, int maxwidth) +{ + char *p; + int begin_x; + + begin_x = cursor_x; + for(p=text;*p;p++) { + if(maxwidth && cursor_x - begin_x >= maxwidth) + return p-text; + gui_putchar(bmp, font, *p); + } +/* int scrx, i; for(scrx = x, i = 0; text[i]; scrx += fonts[font].char_w, i++) { if(scrx-x >= maxwidth) return 1; @@ -217,27 +260,52 @@ fonts[font].char_w * (text[i] - '!'), 0, scrx, y, fonts[font].char_w, fonts[font].b->h); - } + }*/ return 0; } -void gui_label(BITMAP *bmp, int font, char *text, int x, int y, int w, int h) +void gui_printf(BITMAP *bmp, char *fmt, ...) { + va_list va; + char buf[1024]; + exploded_t *ex; int i, yy; - ex = explode(text, "\n"); + va_start(va, fmt); + vsprintf(buf, fmt, va); + va_end(va); + + ex = explode(buf, "\n"); - yy = y; - for(i=0;i<ex->num;i++,yy+=fonts[font].b->h) { - if(ex->str[i]) - while(gui_text(bmp, font, ex->str[i], x, yy, w)) { +/* yy = y;*/ + for(i=0;i<ex->num;i++/*,yy+=fonts[0].b->h*/) { + if(ex->str[i] && strlen(ex->str[i])) { + while(1) { + int tmp; + tmp = gui_text(bmp, 0, ex->str[i], 0); + if(i+1 < ex->num) + gui_newline(0); + if(!tmp) + break; + ex->str[i] += tmp; + } + } else { + gui_putchar(bmp, 0, '\n'); + } +/* while(gui_text(bmp, 0, ex->str[i], x, yy, w)) { ex->str[i] += w / fonts[font].char_w; yy += fonts[font].b->h; - } + }*/ } } + +#if 0 +void gui_label(BITMAP *bmp, int font, char *text, int x, int y, int w, int h) +{ +} + void gui_textbox(BITMAP *bmp, int font, char *value, int x, int y, int w, int h) { int text_w, text_h; @@ -260,6 +328,7 @@ /* gui_text(bmp, font, value, x+(w/2-text_w/2)+1+pressed, y+(h/2-text_h/2)+1+pressed, w);*/ gui_text(bmp, font, value, x + 1, y + ((h - text_h)/ 2) + 1, w); } +#endif #if 0 int gui_menu(BITMAP *bmp, int gui_active_menu) Index: gui.h =================================================================== RCS file: /cvsroot/agd/client/gui.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- gui.h 3 Aug 2004 14:50:03 -0000 1.2 +++ gui.h 5 Aug 2004 13:24:43 -0000 1.3 @@ -66,7 +66,7 @@ void gui_add_widget(gui_window_t *win, void *widg, int type, int x, int y); void gui_draw_window(BITMAP *bmp, gui_window_t *win); -int gui_text(BITMAP *bmp, int font, char *text, int x, int y, int maxwidth); +int gui_text(BITMAP *bmp, int font, char *text, int maxwidth); void gui_button(BITMAP *bmp, int font, char *caption, int x, int y, int w, int h, int pressed); void gui_label(BITMAP *bmp, int font, char *text, int x, int y, int w, int h); void gui_textbox(BITMAP *bmp, int font, char *value, int x, int y, int w, int h); |