📄 native.c
字号:
}static int copybox (GAL_GC gc, int x, int y, int w, int h, int nx, int ny){ if ((w <= 0) || (h <= 0)) return -1; //src clip to screen if ((x >= gc.psd->xres) || (x + w - 1 < 0)) return -1; if ((y >= gc.psd->yres) || (y + h - 1 < 0)) return -1; if (x < 0) { nx -= x; w += x; x = 0; } if (y < 0) { ny -= y; h += y; y = 0; } if (x + w - 1 >= gc.psd->xres) w = gc.psd->xres - x; if (y + h - 1 >= gc.psd->yres) h = gc.psd->yres - y; //dst do clip if (gc.psd->doclip) { if ((nx + w - 1 < gc.psd->clipminx) || (nx >= gc.psd->clipmaxx)) return -1; if ((ny + h - 1 < gc.psd->clipminy) || (ny >= gc.psd->clipmaxy)) return -1; if (nx < gc.psd->clipminx) { x += gc.psd->clipminx - nx; w -= gc.psd->clipminx - nx; nx = gc.psd->clipminx; } if (nx + w - 1 >= gc.psd->clipmaxx) { w = gc.psd->clipmaxx - nx; } if (ny < gc.psd->clipminy) { y += gc.psd->clipminy - ny; h -= gc.psd->clipminy - ny; ny = gc.psd->clipminy; } if (ny + h - 1 >= gc.psd->clipmaxy) { h = gc.psd->clipmaxy - ny; } } else { if ((nx + w - 1 < 0) || (nx >= gc.psd->xres)) return -1; if ((ny + h - 1 < 0) || (ny >= gc.psd->yres)) return -1; if (nx < 0) { x -= nx; w += nx; nx = 0; } if (nx + w - 1 >= gc.psd->xres) { w = gc.psd->xres- nx; } if (ny < 0) { y -= ny; h += ny; ny = 0; } if (ny + h - 1 >= gc.psd->yres) { h = gc.psd->yres- ny; } } if ((w <= 0) || (h <= 0)) return -1; if ((x < 0) || (x + w - 1 >= gc.psd->xres)) return -1; if ((y < 0) || (y + h - 1 >= gc.psd->yres)) return -1; if (gc.psd->doclip) { if ((nx < gc.psd->clipminx) || (nx + w - 1 >= gc.psd->clipmaxx)) return -1; if ((ny < gc.psd->clipminy) || (ny + h - 1 >= gc.psd->clipmaxy)) return -1; } else { if ((nx < 0) || (nx + w - 1 >= gc.psd->xres)) return -1; if ((ny < 0) || (ny + h - 1 >= gc.psd->yres)) return -1; } gc.psd->CopyBox(gc.psd,x,y,w,h,nx,ny); return 0;}/* * Must set destination graphics context */static int crossblit (GAL_GC src, int sx, int sy, int w, int h, GAL_GC dst, int dx, int dy){ if (src.psd == dst.psd) { return copybox(src,sx,sy,w,h,dx,dy); } // syslog(LOG_INFO,"native.c:crossblit1 :sx:%d,sy:%d,w:%d,h:%d,dx:%d,dy:%d",sx,sy,w,h,dx,dy);// syslog(LOG_INFO,"src:%d,%d,%d,%d,%d",src.psd->doclip,src.psd->clipminx,src.psd->clipminy, src.psd->clipmaxx,src.psd->clipmaxy);// syslog(LOG_INFO,"src:src.psd->size:%d",src.psd->size);// syslog(LOG_INFO,"dst:%d,%d,%d,%d,%d",dst.psd->doclip,dst.psd->clipminx,dst.psd->clipminy, dst.psd->clipmaxx,dst.psd->clipmaxy);// syslog(LOG_INFO,"dst:dst.psd->size:%d",dst.psd->size); if ((w <= 0) || (h <= 0)) return -1; //src clip to screen if ((sx >= src.psd->xres) || (sx + w - 1 < 0)) return -1; if ((sy >= src.psd->yres) || (sy + h - 1 < 0)) return -1; if (sx < 0) { dx -= sx; w += sx; sx = 0; } if (sy < 0) { dy -= sy; h += sy; sy = 0; } if (sx + w - 1 >= src.psd->xres) w = src.psd->xres - sx; if (sy + h - 1 >= src.psd->yres) h = src.psd->yres - sy; //dst do clip if (dst.psd->doclip) { if ((dx + w - 1 < dst.psd->clipminx) || (dx >= dst.psd->clipmaxx)) return -1; if ((dy + h - 1 < dst.psd->clipminy) || (dy >= dst.psd->clipmaxy)) return -1; if (dx < dst.psd->clipminx) { sx += dst.psd->clipminx - dx; w -= dst.psd->clipminx - dx; dx = dst.psd->clipminx; } if (dx + w - 1 >= dst.psd->clipmaxx) { w = dst.psd->clipmaxx - dx; } if (dy < dst.psd->clipminy) { sy += dst.psd->clipminy - dy; h -= dst.psd->clipminy - dy; dy = dst.psd->clipminy; } if (dy + h - 1 >= dst.psd->clipmaxy) { h = dst.psd->clipmaxy - dy; } } else { if ((dx + w - 1 < 0) || (dx >= dst.psd->xres)) return -1; if ((dy + h - 1 < 0) || (dy >= dst.psd->yres)) return -1; if (dx < 0) { sx -= dx; w += dx; dx = 0; } if (dx + w - 1 >= dst.psd->xres) { w = dst.psd->xres- dx; } if (dy < 0) { sy -= dy; h += dy; dy = 0; } if (dy + h - 1 >= dst.psd->yres) { h = dst.psd->yres- dy; } } if ((w <= 0) || (h <= 0)) return -1; if ((sx < 0) || (sx + w - 1 >= src.psd->xres)) return -1; if ((sy < 0) || (sy + h - 1 >= src.psd->yres)) return -1; if (dst.psd->doclip) { if ((dx < dst.psd->clipminx) || (dx + w - 1 >= dst.psd->clipmaxx)) return -1; if ((dy < dst.psd->clipminy) || (dy + h - 1 >= dst.psd->clipmaxy)) return -1; } else { if ((dx < 0) || (dx + w - 1 >= dst.psd->xres)) return -1; if ((dy < 0) || (dy + h - 1 >= dst.psd->yres)) return -1; }// syslog(LOG_INFO,"native.c:crossblit2 :sx:%d,sy:%d,w:%d,h:%d,dx:%d,dy:%d",sx,sy,w,h,dx,dy); src.psd->Blit(dst.psd,dx,dy,w,h,src.psd,sx,sy); return 0;}static int drawhline (GAL_GC gc, int x, int y, int w, gal_pixel pixel){ if (w <= 0 ) return -1; if ( native_gen_cliphline (gc.psd, &x, &y, &w) == CLIP_INVISIBLE ) return -1; // syslog(LOG_INFO,"x:%d,y:%d,w:%d",x,y,w); gc.psd->DrawHLine(gc.psd,x,y,w,pixel); return 0;}static int puthline (GAL_GC gc, int x, int y, int w, void* buf){ if (w <= 0 ) return -1; if (gc.psd->doclip) { if ((x + w - 1 < gc.psd->clipminx) || (x >= gc.psd->clipmaxx)) return -1; if ((y < gc.psd->clipminy) || (y >= gc.psd->clipmaxy)) return -1; } else { if ((x + w - 1 < 0) || (x >= gc.psd->xres)) return -1; if ((y < 0) || (y >= gc.psd->yres)); return -1; } gc.psd->PutHLine(gc.psd,x,y,w,buf); return 0;}static int gethline (GAL_GC gc, int x, int y, int w, void* buf){ if (w <= 0 ) return -1; if ((x + w - 1 < 0) || (x >= gc.psd->xres)) return -1; if ((y < 0) || (y >= gc.psd->yres)); return -1; gc.psd->GetHLine(gc.psd,x,y,w,buf); return 0;}static int drawvline (GAL_GC gc, int x, int y, int h, gal_pixel pixel){ if (h <= 0 ) return -1; // syslog(LOG_INFO,"native.c:drawvline:x:%d,y:%d,h:%d",x,y,h); if ( native_gen_clipvline (gc.psd, &x, &y, &h) == CLIP_INVISIBLE ) return -1; gc.psd->DrawVLine(gc.psd,x,y,h,pixel); return 0;}static int putvline (GAL_GC gc, int x, int y, int h, void* buf){ if (h <= 0 ) return -1; if (gc.psd->doclip) { if ((y + h - 1 < gc.psd->clipminy) || (y >= gc.psd->clipmaxy)) return -1; if ((x < gc.psd->clipminx) || (x >= gc.psd->clipmaxx)) return -1; } else { if ((y + h - 1 < 0) || (y >= gc.psd->yres)) return -1; if ((x < 0) || (x >= gc.psd->xres)); return -1; } gc.psd->PutVLine(gc.psd,x,y,h,buf); return 0;}static int getvline (GAL_GC gc, int x, int y, int h, void* buf){ if (h <= 0 ) return -1; if ((y + h - 1 < 0) || (y >= gc.psd->yres)) return -1; if ((x < 0) || (x >= gc.psd->xres)); return -1; gc.psd->GetVLine(gc.psd,x,y,h,buf); return 0;}/* * Pixel operations */static int drawpixel (GAL_GC gc, int x, int y, gal_pixel pixel){ if (native_gen_clippoint(gc.psd,x,y)) gc.psd->DrawPixel(gc.psd,x,y,pixel); return 0;}static int putpixel (GAL_GC gc, int x, int y, gal_pixel pixel){ if (native_gen_clippoint(gc.psd,x,y)) gc.psd->DrawPixel(gc.psd,x,y,pixel); return 0;}static int getpixel (GAL_GC gc, int x, int y, gal_pixel* pixel){ if ((x >= 0) && (x < gc.psd->xres) && (y >= 0) && (y < gc.psd->yres)) *pixel = gc.psd->ReadPixel(gc.psd,x,y); else return -1; return 0;}static int line (GAL_GC gc, int x1, int y1, int x2, int y2, gal_pixel pixel){ gal_pixel oldcolor; getfgcolor(gc,&oldcolor); setfgcolor(gc,pixel); native_gen_line (gc.psd, x1, y1, x2, y2, TRUE); setfgcolor(gc,oldcolor); return 0;}/* * NOTE: must be normalized rect. */static int rectangle (GAL_GC gc, int l, int t, int r, int b, gal_pixel pixel){ gal_pixel oldcolor; getfgcolor(gc,&oldcolor); setfgcolor(gc,pixel); native_gen_rect (gc.psd, l, t, r, b); setfgcolor(gc,oldcolor); return 0;}static int circle (GAL_GC gc, int x, int y, int r, gal_pixel pixel){ native_gen_circle (gc.psd, x, y, r, pixel); return 0;}static void panic (int exitcode){ fprintf (stderr, "MiniGUI Panic. Exit Code: %d.\n", exitcode); cur_gfx->phygc.psd->Close(cur_gfx->phygc.psd); kbddev.Close(); mousedev->Close();#ifndef __ECOS done_vtswitch(); #endif exit (exitcode);}/****************** Initialization and termination of SVGALib **************/BOOL InitNative (GFX* gfx){ PSD psd; int i; psd = scrdev.Open(&scrdev); if(!psd) return FALSE;#ifndef __ECOS init_vtswitch();#endif gfx->phygc.psd =psd; gfx->bytes_per_phypixel = (psd->bpp + 7 ) / 8; gfx->bits_per_phypixel = psd->bpp; gfx->width_phygc = psd->xres; gfx->height_phygc = psd->yres; gfx->colors_phygc = psd->ncolors; gfx->grayscale_screen = FALSE; gfx->bytesperpixel = bytesperpixel; gfx->bitsperpixel = bitsperpixel; gfx->width = width; gfx->height = height; gfx->colors = colors; //now functions gfx->allocategc = allocategc; gfx->freegc = freegc; gfx->enableclipping = enableclipping; gfx->disableclipping = disableclipping; gfx->setclipping = setclipping; gfx->getclipping = getclipping; gfx->getbgcolor = getbgcolor; gfx->setbgcolor = setbgcolor; gfx->getfgcolor = getfgcolor; gfx->setfgcolor = setfgcolor; gfx->mapcolor = mapcolor; gfx->unmappixel = unmappixel; gfx->packcolors = packcolors; gfx->unpackpixels = unpackpixels; gfx->getpalette = getpalette; gfx->setpalette = setpalette; gfx->setcolorfulpalette = setcolorfulpalette; gfx->boxsize = boxsize; gfx->fillbox = fillbox; gfx->putbox = putbox; gfx->putboxmask = putboxmask; gfx->getbox = getbox; gfx->scalebox = scalebox; gfx->copybox = copybox; gfx->crossblit = crossblit; gfx->drawhline = drawhline; gfx->puthline = puthline; gfx->gethline = gethline; gfx->drawvline = drawvline; gfx->putvline = putvline; gfx->getvline = getvline; gfx->drawpixel = drawpixel; gfx->putpixel = putpixel; gfx->getpixel = getpixel; gfx->line = line; gfx->rectangle = rectangle; gfx->panic = panic; gfx->circle = circle; gfx->setgc = NULL; gfx->putboxpart = NULL; gfx->putboxwithop = NULL; gfx->putchar = NULL; gfx->putstr = NULL; gfx->getcharsize = NULL; gfx->setputcharmode = NULL; gfx->setfontcolors = NULL; gfx->flush = NULL; gfx->flushregion = NULL; for (i=0; i<17; i++) SysPixelIndex [i] = mapcolor (gfx->phygc, (gal_color*)(SysPixelColor+i) ); setcolorfulpalette(gfx->phygc); setclipping (gfx->phygc, 0, 0, psd->xres, psd->yres);#if 0 syslog(LOG_INFO,"xres:%d,yres:%d",psd->xres,psd->yres); gfx->fillbox(gfx->phygc,10,0,100,10,SysPixelIndex[0]); gfx->fillbox(gfx->phygc,10,10,100,10,SysPixelIndex[1]); gfx->fillbox(gfx->phygc,10,20,100,10,SysPixelIndex[2]); gfx->fillbox(gfx->phygc,10,30,100,10,SysPixelIndex[3]); gfx->fillbox(gfx->phygc,10,40,100,10,SysPixelIndex[4]); gfx->fillbox(gfx->phygc,10,50,100,10,SysPixelIndex[5]); gfx->fillbox(gfx->phygc,10,60,100,10,SysPixelIndex[6]); gfx->fillbox(gfx->phygc,10,70,100,10,SysPixelIndex[7]); gfx->fillbox(gfx->phygc,10,80,100,10,SysPixelIndex[8]); gfx->fillbox(gfx->phygc,10,90,100,10,SysPixelIndex[9]); gfx->fillbox(gfx->phygc,10,100,100,10,SysPixelIndex[10]); gfx->fillbox(gfx->phygc,10,110,100,10,SysPixelIndex[11]); gfx->fillbox(gfx->phygc,10,120,100,10,SysPixelIndex[12]); gfx->fillbox(gfx->phygc,10,130,100,10,SysPixelIndex[13]); gfx->fillbox(gfx->phygc,10,140,100,10,SysPixelIndex[14]); gfx->fillbox(gfx->phygc,10,150,100,10,SysPixelIndex[15]); gfx->circle(gfx->phygc, 100, 100, 50,SysPixelIndex[2]); gfx->line(gfx->phygc,100,100,200,200,SysPixelIndex[3]); gfx->rectangle(gfx->phygc,10,10,50,50,SysPixelIndex[4]); while (1) {} { int c1,c2,i; gfx->fillbox(gfx->phygc,0,0,640,480,SysPixelIndex[16]); gfx->circle(gfx->phygc, 100, 100, 50,SysPixelIndex[2]); for(i=0;i<=16;i++){ c1 = SysPixelIndex[i]; c2 = 0; gfx->drawpixel(gfx->phygc,100+i,100,c1); gfx->getpixel(gfx->phygc,100+i,100,&c2); syslog(LOG_INFO,"init:c1:%d,c2:%d",c1,c2); } while (1) {} } #endif return TRUE;}void TermNative (GFX* gfx){ gfx->phygc.psd->Close(gfx->phygc.psd);#ifndef __ECOS done_vtswitch(); #endif }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -