nanoxwin.c
来自「远程桌面登陆软件 用rdesktop 但不基于Xwindows 可基于(nano」· C语言 代码 · 共 1,524 行 · 第 1/3 页
C
1,524 行
color = pen->colour; if (opcode == 5) /* GR_MODE_INVERT, not supported so convert it */ { /* i think x ^ -1 = ~x */ color = 0xffffffff; opcode = 6; /* GR_MODE_XOR */ } if (opcode == 12 || opcode == 6) /* nanox only supports these 2 opcode */ { op = g_ops[opcode]; GrSetGCMode(g_gc, op); if (g_server_bpp == 16 && g_bpp == 32) { color = COLOR16TO32(color); } GrSetGCForeground(g_gc, color); GrLine(g_wnd, g_gc, startx, starty, endx, endy); GrSetGCMode(g_gc, GR_MODE_COPY); } else { unimpl("opcode %d in ui_line\n", opcode); }}/*****************************************************************************/void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, void * src, int srcx, int srcy, BRUSH * brush, int bgcolor, int fgcolor){/* not used, turned off */}/*****************************************************************************/void ui_memblt(uint8 opcode, int x, int y, int cx, int cy, void * src, int srcx, int srcy){ uint8 * dest; uint8 * source; uint8 * final; GR_WINDOW_INFO wi; int i, j, s, d; GR_WINDOW_ID pixmap; if (opcode == 12) { GrCopyArea(g_wnd, g_gc, x, y, cx, cy, (GR_DRAW_ID)src, srcx, srcy, GR_MODE_COPY); } else /* do opcodes ourself */ { /* slow but its correct, ok to be slow here, these are rare */ GrGetWindowInfo((GR_DRAW_ID)src, &wi); dest = xmalloc(cx * cy * g_Bpp); source = xmalloc(wi.width * wi.height * g_Bpp); final = xmalloc(cx * cy * g_Bpp); memset(final, 0, cx * cy * g_Bpp); /* dest */ GrReadArea(g_wnd, x, y, cx, cy, (GR_PIXELVAL*)dest); /* source */ GrReadArea((GR_DRAW_ID)src, 0, 0, wi.width, wi.height, (GR_PIXELVAL*)source); for (i = 0; i < cy; i++) { for (j = 0; j < cx; j++) { s = get_pixel32(source, j + srcx, i + srcy, wi.width, wi.height); d = get_pixel32(dest, j, i, cx ,cy); set_pixel32(final, j, i, cx, cy, rop(opcode, s, d)); } } pixmap = GrNewPixmap(cx, cy, 0); GrArea(pixmap, g_gc_clean, 0, 0, cx, cy, final, MWPF_TRUECOLOR0888); GrCopyArea(g_wnd, g_gc, x, y, cx, cy, pixmap, 0, 0, GR_MODE_COPY); GrDestroyWindow(pixmap); xfree(dest); xfree(source); xfree(final); }}/*****************************************************************************/void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy){/* not used, turned off */}/*****************************************************************************/void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy){/* not used, turned off */}/*****************************************************************************/void ui_rect(int x, int y, int cx, int cy, int color){ if (g_server_bpp == 16 && g_bpp == 32) { color = COLOR16TO32(color); } GrSetGCForeground(g_gc, color); GrFillRect(g_wnd, g_gc, x, y, cx, cy);}/*****************************************************************************//* using warp_coords cause clip seems to affect source in GrCopyArea */void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy){ if (opcode == 12) { if (warp_coords(&x, &y, &cx, &cy, &srcx, &srcy)) { GrCopyArea(g_wnd, g_gc_clean, x, y, cx, cy, g_wnd, srcx, srcy, GR_MODE_COPY); } } else { unimpl("opcode %d in ui_screenblt\n", opcode); }}/******************************************************************************//* can't use stipple cause tsorigin don't work, GrPoint too slow, GrPoints too slow but better, using a copy from the screen, do the pattern and copy it back */void ui_patblt(uint8 opcode, int x, int y, int cx, int cy, BRUSH * brush, int bgcolor, int fgcolor){ uint8 ipattern[8], * dest, * final; uint32 op; int i, j, s, d; GR_WINDOW_ID pixmap; if (g_server_bpp == 16 && g_bpp == 32) { fgcolor = COLOR16TO32(fgcolor); bgcolor = COLOR16TO32(bgcolor); } switch (brush->style) { case 0: /* Solid */ if (opcode == 12 || opcode == 6) { op = g_ops[opcode]; GrSetGCMode(g_gc, op); GrSetGCForeground(g_gc, fgcolor); GrFillRect(g_wnd, g_gc, x, y, cx, cy); GrSetGCMode(g_gc, GR_MODE_COPY); } else { unimpl("opcode %d in ui_patblt solid brush\n", opcode); } break; case 3: /* Pattern - all opcodes ok */ for (i = 0; i != 8; i++) { ipattern[7 - i] = brush->pattern[i]; } dest = xmalloc(cx * cy * g_Bpp); final = xmalloc(cx * cy * g_Bpp); memset(final, 0, cx * cy * g_Bpp); /* dest */ if (opcode != 12) { GrReadArea(g_wnd, x, y, cx, cy, (GR_PIXELVAL*)dest); } for (i = 0; i < cy; i++) { for (j = 0; j < cx; j++) { if (is_pixel_on(ipattern, (x + j + brush->xorigin) % 8, (y + i + brush->yorigin) % 8, 8, 1)) { s = fgcolor; } else { s = bgcolor; } d = get_pixel32(dest, j, i, cx ,cy); set_pixel32(final, j, i, cx, cy, rop(opcode, s, d)); } } pixmap = GrNewPixmap(cx, cy, 0); GrArea(pixmap, g_gc_clean, 0, 0, cx, cy, final, MWPF_TRUECOLOR0888); GrCopyArea(g_wnd, g_gc, x, y, cx, cy, pixmap, 0, 0, GR_MODE_COPY); GrDestroyWindow(pixmap); xfree(dest); xfree(final); break; }}/*****************************************************************************/void ui_destblt(uint8 opcode, int x, int y, int cx, int cy){ uint32 op; if (opcode == 0) /* black */ { GrSetGCForeground(g_gc, 0); opcode = 12; } else if (opcode == 5) /* invert */ { GrSetGCForeground(g_gc, 0xffffffff); opcode = 6; } else if (opcode == 15) /* white */ { GrSetGCForeground(g_gc, 0xffffffff); opcode = 12; } if (opcode == 12 || opcode == 6) { op = g_ops[opcode]; GrSetGCMode(g_gc, op); GrFillRect(g_wnd, g_gc, x, y, cx, cy); GrSetGCMode(g_gc, GR_MODE_COPY); } else { unimpl("opcode %d in ui_destblt\n", opcode); }}/*****************************************************************************/void ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 * data){ void * b; b = ui_create_bitmap(width, height, data); ui_memblt(12, x, y, cx, cy, b, 0, 0); ui_destroy_bitmap(b);}/*****************************************************************************/void ui_move_pointer(int x, int y){ GrMoveCursor(x, y);}/*****************************************************************************/void ui_set_null_cursor(void){ GrSetWindowCursor(g_wnd, g_null_cursor);}/*****************************************************************************/void ui_set_cursor(void * cursor){ GrSetWindowCursor(g_wnd, (GR_CURSOR_ID)cursor);}//******************************************************************************static int is24on(uint8 * data, int x, int y){ uint8 r, g, b; int start; if (data == 0) { return 0; } start = y * 32 * 3 + x * 3; r = data[start]; g = data[start + 1]; b = data[start + 2]; return !((r == 0) && (g == 0) && (b == 0));}//******************************************************************************static int is1on(uint8 * data, int x, int y){ int start; int shift; if (data == 0) { return 0; } start = (y * 32) / 8 + x / 8; shift = x % 8; return (data[start] & (0x80 >> shift)) == 0;}//******************************************************************************static void set1(uint8 * data, int x, int y){ int start; int shift; if (data == 0) { return; } start = (y * 32) / 8 + x / 8; shift = x % 8; data[start] = data[start] | (0x80 >> shift);}//******************************************************************************static void flipover(uint8 * data){ uint8 adata[128]; int index; if (data == 0) { return; } memcpy(adata, data, 128); for (index = 0; index <= 31; index++) { data[127 - (index * 4 + 3)] = adata[index * 4]; data[127 - (index * 4 + 2)] = adata[index * 4 + 1]; data[127 - (index * 4 + 1)] = adata[index * 4 + 2]; data[127 - index * 4] = adata[index * 4 + 3]; }}/*****************************************************************************/void * ui_create_cursor(uint32 x, uint32 y, int width, int height, uint8 * andmask, uint8 * xormask){ uint8 adata[128]; uint8 amask[128]; GR_BITMAP * databitmap; GR_BITMAP * maskbitmap; GR_CURSOR_ID cursor; int i1, i2, bon, mon; if (width != 32 || height != 32) { return 0; } memset(adata, 0, 128); memset(amask, 0, 128); for (i1 = 0; i1 <= 31; i1++) { for (i2 = 0; i2 <= 31; i2++) { mon = is24on(xormask, i1, i2); bon = is1on(andmask, i1, i2); if (bon ^ mon) // xor { set1(adata, i1, i2); if (!mon) { set1(amask, i1, i2); } } if (mon) { set1(amask, i1, i2); } } } flipover(adata); flipover(amask); databitmap = ui_create_glyph(32, 32, adata); maskbitmap = ui_create_glyph(32, 32, amask); cursor = GrNewCursor(32, 32, x, y, 0xffffff, 0, databitmap, maskbitmap); ui_destroy_glyph(databitmap); ui_destroy_glyph(maskbitmap); return (void*)cursor;}/*****************************************************************************/void ui_destroy_cursor(void * cursor){ GrDestroyCursor((GR_CURSOR_ID)cursor);}/*****************************************************************************/uint16 ui_get_numlock_state(uint32 state){ return 0;}/*****************************************************************************/uint32 read_keyboard_state(void){ return 0;}/*****************************************************************************/void ui_resize_window(void){}/*****************************************************************************/void ui_begin_update(void){}/*****************************************************************************/void ui_end_update(void){}/*****************************************************************************/void ui_polygon(uint8 opcode, uint8 fillmode, POINT * point, int npoints, BRUSH * brush, int bgcolor, int fgcolor){/* not used, turned off */}/*****************************************************************************/void ui_polyline(uint8 opcode, POINT * points, int npoints, PEN * pen){ int i, x, y, dx, dy; if (npoints > 0) { x = points[0].x; y = points[0].y; for (i = 1; i < npoints; i++) { dx = points[i].x; dy = points[i].y; ui_line(opcode, x, y, x + dx, y + dy, pen); x = x + dx; y = y + dy; } }}/*****************************************************************************/void ui_ellipse(uint8 opcode, uint8 fillmode, int x, int y, int cx, int cy, BRUSH * brush, int bgcolor, int fgcolor){/* not used, turned off */}/*****************************************************************************/void generate_random(uint8 * random){ memcpy(random, "12345678901234567890123456789012", 32);}/*****************************************************************************/void save_licence(uint8 * data, int length){}/*****************************************************************************/int load_licence(uint8 ** data){ return 0;}/*****************************************************************************/void * xrealloc(void * in, int size){ if (size < 1) { size = 1; } return realloc(in, size);}/*****************************************************************************/void * xmalloc(int size){ return malloc(size);}/*****************************************************************************/void xfree(void * in){ if (in != 0) { free(in); }}/*****************************************************************************/void warning(char * format, ...){ va_list ap; fprintf(stderr, "WARNING: "); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);}/*****************************************************************************/void unimpl(char * format, ...){ va_list ap; fprintf(stderr, "NOT IMPLEMENTED: "); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);}/*****************************************************************************/void error(char * format, ...){ va_list ap;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?