static void window_redraw(Window *w, Graphics *g) { Rect r; Point p; int l, h; int length; char *buffer; assert(lines != NULL); /* Each wide char is encoded in at most 6 UTF8 characters. For the Base Plane, * 3 UTF8 characters per Unicode character is enough */ buffer = malloc((6 * NUM_COLUMNS + 1) * sizeof(char)); if (buffer != NULL) { r = get_window_area(w); set_rgb(g, rgb(240,240,240)); //??? attrib fill_rect(g, r); set_rgb(g, rgb(0,0,0)); //??? attrib set_font(g, font); set_text_direction(g, LR_TB); p = pt(0,0); h = font_height(font); for (l = 0; l < NUM_LINES; l++) { #if defined _UNICODE /* convert the line to UTF8 */ int c; char *ptr; for (c = 0, ptr = buffer; c < NUM_COLUMNS; c++) amx_UTF8Put(ptr, &ptr, 6, lines + l * NUM_COLUMNS + c); *ptr = '\0'; length = (int)(ptr - buffer); #else /* assume line is ASCII */ memcpy(buffer, lines + l * NUM_COLUMNS, NUM_COLUMNS); buffer[NUM_COLUMNS] = '\0'; length = NUM_COLUMNS; #endif /* draw the line */ draw_utf8(g, p, buffer, length); p.y += h; if (p.y > r.height) break; } /* if */ free(buffer); } /* if */ }
static void refresh_screen(int top, int bottom) { Rect r; int h; if (top != bottom) { assert(win != NULL); r = get_window_area(win); assert(font != NULL); h = font_height(font); redraw_rect(win, rect(0, top * h, r.width, (bottom - top) * h)); } /* if */ //??? set to draw a caret }
/* dx = in columns, dy = in lines */ void scroll_window(int dx, int dy) { Graphics *g; Rect r; Point p; /* a negative value scrolls up */ assert(lines != NULL); if (dy < 0) { assert(-dy < NUM_LINES); memmove(lines,lines-dy*NUM_COLUMNS,(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR)); memset(lines+(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR), __T(' '), -dy*NUM_COLUMNS); } else if (dy > 0) { assert(dy < NUM_LINES); memmove(lines+dy*NUM_COLUMNS,lines,(NUM_LINES-dy)*NUM_COLUMNS*sizeof(TCHAR)); memset(lines, __T(' '), dy*NUM_COLUMNS); } /* if */ csry += dy; if (csry < 0) csry = 0; if (csry >= NUM_LINES) csry=NUM_LINES - 1; assert(font != NULL); dx *= font_width(font, "x", 1); dy *= font_height(font); g = get_window_graphics(win); r = get_window_area(win); p = pt(r.x + dx, r.y + dy); copy_rect(g, p, g, r); if (dy > 0) { /* moving window contents downwards */ redraw_rect(win, rect(0,0,r.width,dy)); } else if (dy < 0) { /* moving window contents upwards */ redraw_rect(win, rect(0,r.height+dy,r.width,0-dy)); } /* if */ if (dx > 0) { /* moving window contents to the right */ redraw_rect(win, rect(0,0,dx,r.height)); } else if (dx < 0) { /* moving window contents to the left */ redraw_rect(win, rect(r.width+dx,0,0-dx,r.height)); } /* if */ del_graphics(g); }