Update of /cvsroot/agd/client
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27183
Modified Files:
gui.c main.c net.c
Log Message:
Backspace; scrolling
Index: net.c
===================================================================
RCS file: /cvsroot/agd/client/net.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- net.c 5 Aug 2004 13:25:28 -0000 1.2
+++ net.c 5 Aug 2004 13:44:13 -0000 1.3
@@ -4,8 +4,7 @@
#include "net.h"
#include "gui.h"
-extern int cursor_y;
-extern gui_font_t *fonts;
+extern int cursor_x, text_begin_x;
int fd;
fd_set readfd;
@@ -86,6 +85,7 @@
/* p = buf;
while(strlen(p)) {*/
gui_printf(screen, buf);
+ text_begin_x = cursor_x;
/* gui_label(screen, 0, buf, 0, cursor_y, SCREEN_W, SCREEN_H);
cursor_y += fonts[0].b->h;*/
break;
Index: main.c
===================================================================
RCS file: /cvsroot/agd/client/main.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- main.c 5 Aug 2004 13:25:06 -0000 1.3
+++ main.c 5 Aug 2004 13:44:13 -0000 1.4
@@ -85,17 +85,25 @@
net_events();
while(keypressed()) {
int c = readkey() & 0xff;
- if(c == '\r') {
- gui_putchar(screen, 0, '\n');
- net_send(kb_buf, kb_buf_siz);
- memset(kb_buf, 0, kb_buf_siz);
- } else {
- if(strlen(kb_buf)+1 >= kb_buf_siz) {
- kb_buf_siz += (kb_buf_siz / 2);
- kb_buf = xrealloc(kb_buf, kb_buf_siz);
- }
- sprintf(kb_buf, "%s%c", kb_buf, c);
- gui_putchar(screen, 0, c);
+ switch(c) {
+ case '\r':
+ gui_putchar(screen, 0, '\n');
+ net_send(kb_buf, kb_buf_siz);
+ memset(kb_buf, 0, kb_buf_siz);
+ break;
+ case '\b':
+ gui_putchar(screen, 0, '\b');
+ if(strlen(kb_buf))
+ kb_buf[strlen(kb_buf) - 1] = '\0';
+ break;
+ default:
+ if(strlen(kb_buf)+1 >= kb_buf_siz) {
+ kb_buf_siz += (kb_buf_siz / 2);
+ kb_buf = xrealloc(kb_buf, kb_buf_siz);
+ }
+ sprintf(kb_buf, "%s%c", kb_buf, c);
+ gui_putchar(screen, 0, c);
+ break;
}
}
/* blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);*/
Index: gui.c
===================================================================
RCS file: /cvsroot/agd/client/gui.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- gui.c 5 Aug 2004 13:24:43 -0000 1.3
+++ gui.c 5 Aug 2004 13:44:13 -0000 1.4
@@ -7,6 +7,8 @@
static int numfonts, fontsalloced;
static gui_font_t *fonts;
int cursor_x, cursor_y;
+int text_begin_x;
+
extern BITMAP *buffer;
void gui_init(void)
@@ -219,19 +221,40 @@
cursor_y = y;
}
-void gui_newline(int font)
+void gui_newline(BITMAP *bmp, int font)
{
cursor_y += fonts[font].b->h + 2;
cursor_x = 0;
+ if(cursor_y + fonts[font].b->h >= SCREEN_H) {
+ BITMAP *tmp;
+ tmp = create_bitmap(SCREEN_W, SCREEN_H);
+ blit(bmp, tmp, 0, 0, 0, -fonts[font].b->h-2, SCREEN_W, SCREEN_H);
+ clear_to_color(bmp, /*AGI_BLACK*/0);
+ blit(tmp, bmp, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
+ cursor_y -= fonts[font].b->h + 2;
+/* void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);*/
+ }
}
void gui_putchar(BITMAP *bmp, int font, char c)
{
+ if(c == '\b') {
+ if(cursor_x >= text_begin_x + fonts[font].char_w) {
+ cursor_x -= fonts[font].char_w;
+ rectfill(bmp, cursor_x, cursor_y, cursor_x+fonts[font].char_w, cursor_y+fonts[font].b->h, 0);
+ if(cursor_x <= 0 && cursor_y >= (fonts[font].b->h + 2)) {
+ cursor_y -= fonts[font].b->h + 2;
+ cursor_x = SCREEN_W - fonts[font].b->w;
+ }
+ }
+ return;
+ }
+
if(cursor_x + fonts[font].char_w >= SCREEN_W)
- gui_newline(font);
+ gui_newline(bmp, font);
if(c == '\n') {
- gui_newline(font);
+ gui_newline(bmp, font);
return;
}
@@ -285,7 +308,7 @@
int tmp;
tmp = gui_text(bmp, 0, ex->str[i], 0);
if(i+1 < ex->num)
- gui_newline(0);
+ gui_newline(bmp, 0);
if(!tmp)
break;
ex->str[i] += tmp;
|