📄 xlib.c
字号:
SelectObject(hDC, oldObj); drawableRelDC(w,hDC); } /*free(ntps);*/ return 0;}/*****************************************************************\ Function: XDrawLine Inputs: display, window, geometry. Comments: Seems to work ok.\*****************************************************************/intXDrawLine(display,w,gc,x1,y1,x2,y2)Display *display;Drawable w;GC gc;int x1,y1,x2,y2;{ HDC hDC; HPEN hpen; RECT da; HANDLE oldObj; xtrace("XDrawLine\n"); if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); hpen = NT_get_GC_pen(hDC,gc); oldObj = SelectObject(hDC,hpen); MoveToEx(hDC,x1,y1,NULL); LineTo(hDC,x2,y2); SelectObject(hDC, oldObj); drawableRelDC(w,hDC); } return 0;}/*****************************************************************\ Function: XDrawLines Inputs: display, window, gc, points list, number of points, mode. Comments: Untested.\*****************************************************************/intXDrawLines(display,w,gc,points,nps,mode)Display *display;Drawable w;GC gc;XPoint *points;int nps,mode;{ HPEN hpen; int n; POINT pts[1000]; HDC hDC; HANDLE oldObj; xtrace("XDrawLines\n"); pts->x=(LONG)points->x; pts->y=(LONG)points->y; for(n=1;n<nps;++n) if (mode==CoordModeOrigin) { (pts+n)->x=(LONG)(points+n)->x; (pts+n)->y=(LONG)(points+n)->y; } else { (pts+n)->x=(LONG)(points+n)->x+(pts+n-1)->x; (pts+n)->y=(LONG)(points+n)->y+(pts+n-1)->y; } if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); hpen = NT_get_GC_pen(hDC,gc); oldObj = SelectObject(hDC,hpen); Polyline(hDC,pts,nps); SelectObject(hDC, oldObj); drawableRelDC(w,hDC); } return 0;}/*****************************************************************\ Function: XDrawPoints Inputs: display, window, gc, points list, number of points, mode. Comments: Untested.\*****************************************************************/intXDrawPoints(display,w,gc,points,nps,mode)Display *display;Drawable w;GC gc;XPoint *points;int nps,mode;{ HDC hDC; int n; xtrace("XDrawPoints\n"); if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); SetPixelV(hDC,points->x,points->y,CNUMTORGB(gc->values.foreground)); for (n=1;n<nps;++n) { if (mode==CoordModeOrigin) SetPixelV(hDC,(points+n)->x,(points+n)->y, CNUMTORGB(gc->values.foreground)); else SetPixelV(hDC,(points+n-1)->x+(points+n)->x, (points+n-1)->y+(points+n)->y, CNUMTORGB(gc->values.foreground)); } drawableRelDC(w,hDC); } return 0;}intXDrawPoint(display,w,gc,x,y)Display *display;Drawable w;GC gc;int x,y;{ HDC hDC; xtrace("XDrawPoint\n"); if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); SetPixelV(hDC,x,y,CNUMTORGB(gc->values.foreground)); drawableRelDC(w,hDC); } return 0;}/*****************************************************************\ Function: XDrawRectangle Inputs: display, window, gc, geometry Comments: Seems to work.\*****************************************************************/intXDrawRectangle(display,w,gc,x,y,width,height)Display *display;Drawable w;GC gc;int x,y;unsigned int width,height;{ HDC hDC; RECT rect; HBRUSH hbrush; HPEN hpen; HANDLE oldbrush, oldpen; xtrace("XDrawRectangle\n"); if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); hbrush = NT_get_GC_brush(hDC,gc); rect.left=(LONG)x; rect.right=(LONG)(x+width); rect.top=(LONG)y; rect.bottom=(LONG)(y+height); oldbrush = SelectObject(hDC,GetStockObject(NULL_BRUSH)); hpen = NT_get_GC_pen(hDC,gc); oldpen = SelectObject(hDC,hpen); Rectangle(hDC,(int)rect.left,(int)rect.top,(int)rect.right,(int)rect.bottom); /* FrameRect(hDC,&rect,hbrush); */ SelectObject(hDC, oldbrush); SelectObject(hDC, oldpen); drawableRelDC(w,hDC); } return 0;}/*****************************************************************\ Function: XDrawSegments Inputs: display, window, gc, segment list, number of segments. Comments: Untested.\*****************************************************************/intXDrawSegments(display,w,gc,segs,nsegs)Display *display;Drawable w;GC gc;XSegment *segs;int nsegs;{ HDC hDC; HPEN hpen; int n; HANDLE oldObj; xtrace("XDrawSegments\n"); if (VALID_WINDOW(w)) { hDC = drawableGetDC(w); hpen = NT_get_GC_pen(hDC,gc); oldObj = SelectObject(hDC,hpen); SetBkMode(hDC,TRANSPARENT); for (n=0;n<nsegs;n++) { MoveToEx(hDC,(segs+n)->x1,(segs+n)->y1,NULL); LineTo(hDC,(segs+n)->x2,(segs+n)->y2); } SelectObject(hDC, oldObj); drawableRelDC(w,hDC); } return 0;}PixmapXCreatePixmap(display,drawable,width,height,depth)Display *display;Drawable drawable;unsigned int width, height;unsigned int depth;{ RECT rct; NT_window *w = (NT_window *)NT_new_window(); HDC parenthDC = drawableGetDC(drawable); w->hDC = CreateCompatibleDC(parenthDC); w->hBitmap = CreateCompatibleBitmap(parenthDC,width,height); SelectObject(w->hDC, w->hBitmap); rct.left=(LONG) 0; rct.right=(LONG) width; rct.top=(LONG) 0; rct.bottom=(LONG) height; FillRect(w->hDC, &rct, GetStockObject(WHITE_BRUSH)); drawableRelDC(drawable,parenthDC); w->w = NONMAPPED_HANDLE; w->x=0; w->y=0; w->wdth = width; w->hght = height; w->min = depth; return (Pixmap)w;}const char revBytes[]={ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff};PixmapXCreateBitmapFromData(Display *display, Drawable drawable, const char *data, unsigned int width, unsigned int height){ NT_window *w = (NT_window *)NT_new_window(); HDC parenthDC = drawableGetDC(drawable); w->hDC = CreateCompatibleDC(parenthDC); { int i,j; char *newdata; int bytes = (width+7)>>3; int newbytes = (bytes&1)?bytes+1:bytes; newdata = allocateMemory(newbytes*height); for (i=0;i<height;i++) { for (j=0;j<bytes;j++) { newdata[(i*newbytes)+j]=revBytes[(unsigned char)data[(i*bytes)+j]]; } } w->hBitmap = CreateBitmap(width,height,1,1,newdata); freeMemory(newdata); } SelectObject(w->hDC, w->hBitmap); drawableRelDC(drawable,parenthDC); w->x=0; w->y=0; w->wdth = width; w->hght = height; w->min = 1; return (Pixmap)w;}intXFreePixmap(display, pixmap) Display *display; Pixmap pixmap;{ NT_window *w = (NT_window *)pixmap; NT_delete_window(w); return 0;}intXCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y)Display *display;Drawable src, dest;GC gc;int src_x, src_y;unsigned int width, height;int dest_x, dest_y;{ HDC hsrc, hdst; hsrc = drawableGetDC(src); if (VALID_WINDOW(dest)) { hdst = drawableGetDC(dest); (void)BitBlt(hdst,dest_x,dest_y,width,height,hsrc,src_x,src_y,SRCCOPY); drawableRelDC(src,hsrc); } drawableRelDC(dest,hdst); return 0;}XImage *NT_XCreateImage(){ return NULL;}int NT_XDestroyImage(ximage)XImage *ximage;{ /* freeMemory(ximage->data); */ freeMemory(ximage); return 1;}unsigned longNT_XGetPixel(ximage,x,y)XImage *ximage;int x,y;{ return 0;}intNT_XPutPixel(ximage,x,y,pixel)XImage *ximage;int x,y;unsigned long pixel;{ return 0;}XImage *NT_XSubImage(ximage,x,y,w,h)XImage *ximage;int x,y;unsigned int w,h;{ return NULL;}intNT_XAddPixel(ximage,value)XImage *ximage;unsigned long value;{ return 0;}XImage *XGetImage(display,drawable,x,y,width,height,plane_mask,format)Display *display;Drawable drawable;int x,y;unsigned int width, height;unsigned long plane_mask;int format;{ return NULL;}XImage *XCreateImage(display,visual,depth,format,offset,data,width,height, bitmap_pad, bytes_per_line)Display *display;Visual *visual;unsigned int depth;int format;int offset;char *data;unsigned int width, height;int bitmap_pad, bytes_per_line;{ XImage *img = (XImage *) allocateMemory(sizeof(XImage)); if (img) { img->depth = 24; /* depth; */ img->format = format; img->xoffset = offset; img->data = data; img->width = width; img->height = height; img->bitmap_pad = 32; img->bytes_per_line=width*((24)>>3); img->bits_per_pixel = 24; /* depth; */ img->bitmap_bit_order = LSBFirst; img->byte_order = MSBFirst; img->blue_mask = 0x0ff00000; img->green_mask=0x00ff0000; img->red_mask= 0x0000ff00; img->f.create_image = NT_XCreateImage; img->f.destroy_image = NT_XDestroyImage; img->f.get_pixel = NT_XGetPixel; img->f.put_pixel = NT_XPutPixel; img->f.sub_image = NT_XSubImage; img->f.add_pixel = NT_XAddPixel; } return img;}voidDrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart){ BITMAP bm; HDC hdcMem; DWORD dwSize; POINT ptSize, ptOrg; hdcMem = CreateCompatibleDC(hdc); SelectObject(hdcMem, hBitmap); SetMapMode(hdcMem,GetMapMode(hdc)); GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdc, &ptSize,1); ptOrg.x=0; ptOrg.y=0; DPtoLP(hdcMem,&ptOrg,1); BitBlt(hdc,xStart,yStart,ptSize.x,ptSize.y,hdcMem,ptOrg.x,ptOrg.y,SRCCOPY); DeleteDC(hdcMem);}/*static unsigned char wBrickBits[]={ 0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0, 0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0, 0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0, 0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0};*/intXPutImage(display,w,gc,image,sx,sy,dx,dy,width,height)Display *display;Drawable w;XImage *image;GC gc;int sx,sy,dx,dy;unsigned int width,height;{ BITMAPINFO bmInfo; NT_window *pix = (NT_window *)w; int res; if (VALID_WINDOW(w)) { HDC hDC = drawableGetDC(w); bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmInfo.bmiHeader.biWidth = width; bmInfo.bmiHeader.biHeight = height; bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 24; /*image->depth; */ bmInfo.bmiHeader.biCompression = BI_RGB; bmInfo.bmiHeader.biSizeImage = 0; bmInfo.bmiHeader.biXPelsPerMeter = 3600; bmInfo.bmiHeader.biYPelsPerMeter = 3600; bmInfo.bmiHeader.biClrUsed = 0; bmInfo.bmiHeader.biClrImportant = 0; res = SetDIBitsToDevice(hDC,0,0,width,height,0,0,0,height,image->data,&bmInfo,DIB_RGB_COLORS); /* BitBlt(CreateDC("DISPLAY",NULL,NULL,NULL),10,0,width,height,hDC,0,0,SRCCOPY); */ if (res==0) printf("SetDIBitsfailed %d\n",res,GetLastError()); drawableRelDC(w,hDC); } return 0;}intXSetWindowBackground(display, w, bg) Display *display; Window w; unsigned long bg;{ NT_window *window = (NT_window *)w; xtrace("XSetWindowBackground\n"); DeleteObject(window->bg); window->bg=CreateSolidBrush(CNUMTORGB(bg)); return 0;}intXSetWindowBackgroundPixmap(display, w, background_tile)Display *display;Window w;Pixmap background_tile;{ NT_window *window = (NT_window *)w; NT_window *wpix = (NT_window *)background_tile; BITMAPINFO *bmInfo; BITMAP bm; int res; xtrace("XSetWindowBackgroundPixmap\n"); if (background_tile==ParentRelative) { if (!window->parentRelative) { HBITMAP hb = NT_getWallpaper(); if (hb!=NULL) { DeleteObject(window->bg); window->bg = CreatePatternBrush(hb); window->parentRelative=1; NT_configureNotify(window,window->x,window->y); } } } else { GetObject(wpix->hBitmap, sizeof(BITMAP), &bm); bmInfo = allocateMemory(sizeof(BITMAPINFO) + ( (bm.bmBitsPixel>>3)* bm.bmWidth*bm.bmHeight)); bmInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmInfo->bmiHeader.biWidth = bm.bmWidth; bmInfo->bmiHeader.biHeight = bm.bmHeight; bmInfo->bmiHeader.biPlanes = 1; bmInfo->bmiHeader.biBitCount = bm.bmBitsPixel; bmInfo->bmiHeader.biCompression = BI_RGB; bmInfo->bmiHeader.biSizeImage = 0; bmInfo->bmiHeader.biClrImportant = 0; bmInfo->bmiHeader.biClrUsed = 0; res =GetDIBits(wpix->hDC,wpix->hBitmap,0,bm.bmHeight,bmInfo->bmiColors,bmInfo,DIB_RGB_COLORS); if (res==0) printf("getDIBits failed %d\n",res,GetLastError()); DeleteObject(window->bg); window->bg = CreateDIBPatternBrushPt(bmInfo, DIB_RGB_COLORS); freeMemory(bmInfo); }}/*****************************************************************\ Function: XSetFillStyle Inputs: display, gc, fill style. Comments: ZZzzz...\*****************************************************************/intXSetFillStyle(display,gc,fs)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -