BOOL WINAPI Ellipse(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect) { HWND hwnd; int rx, ry; RECT rc; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect); if(MwIsClientDC(hdc)) MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); rx = (rc.right - rc.left)/2 - 1; ry = (rc.bottom - rc.top)/2 - 1; rc.left += rx; rc.top += ry; /* fill ellipse in current brush color*/ if(hdc->brush->style != BS_NULL) { InflateRect(&rc, -1, -1); GdSetForeground(GdFindColor(hdc->brush->color)); GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, TRUE); } /* draw ellipse outline in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForeground(GdFindColor(hdc->pen->color)); GdEllipse(hdc->psd, rc.left, rc.top, rx, ry, FALSE); } return TRUE; }
BOOL WINAPI Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom) { HWND hwnd; RECT rc; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; SetRect(&rc, nLeft, nTop, nRight, nBottom); if(MwIsClientDC(hdc)) MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); /* draw rectangle in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForeground(GdFindColor(hdc->pen->color)); GdRect(hdc->psd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); } /* fill rectangle in current brush color*/ if(hdc->brush->style != BS_NULL) { InflateRect(&rc, -1, -1); GdSetForeground(GdFindColor(hdc->brush->color)); GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); } return TRUE; }
/* * Draw the border of a window if there is one. * Note: To allow the border to be drawn with the correct clipping, * we temporarily grow the size of the window to include the border. */ void GsDrawBorder(GR_WINDOW *wp) { GR_COORD lminx; /* left edge minimum x */ GR_COORD rminx; /* right edge minimum x */ GR_COORD tminy; /* top edge minimum y */ GR_COORD bminy; /* bottom edge minimum y */ GR_COORD topy; /* top y value of window */ GR_COORD boty; /* bottom y value of window */ GR_SIZE width; /* original width of window */ GR_SIZE height; /* original height of window */ GR_SIZE bs; /* border size */ bs = wp->bordersize; if (bs <= 0) return; width = wp->width; height = wp->height; lminx = wp->x - bs; rminx = wp->x + width; tminy = wp->y - bs; bminy = wp->y + height; topy = wp->y; boty = bminy - 1; wp->x -= bs; wp->y -= bs; wp->width += (bs * 2); wp->height += (bs * 2); wp->bordersize = 0; clipwp = NULL; GsSetClipWindow(wp, NULL, 0); curgcp = NULL; GdSetMode(GR_MODE_COPY); GdSetForeground(GdFindColor(wp->bordercolor)); if (bs == 1) { GdLine(wp->psd, lminx, tminy, rminx, tminy, TRUE); GdLine(wp->psd, lminx, bminy, rminx, bminy, TRUE); GdLine(wp->psd, lminx, topy, lminx, boty, TRUE); GdLine(wp->psd, rminx, topy, rminx, boty, TRUE); } else { GdFillRect(wp->psd, lminx, tminy, width + bs * 2, bs); GdFillRect(wp->psd, lminx, bminy, width + bs * 2, bs); GdFillRect(wp->psd, lminx, topy, bs, height); GdFillRect(wp->psd, rminx, topy, bs, height); } /* * Restore the true window size. * Forget the currently clipped window since we messed it up. */ wp->x += bs; wp->y += bs; wp->width -= (bs * 2); wp->height -= (bs * 2); wp->bordersize = bs; clipwp = NULL; }
/* draw line segments by connecting passed points*/ BOOL WINAPI Polyline(HDC hdc, CONST POINT *lppt, int cPoints) { HWND hwnd; POINT beg, end; if(cPoints <= 1) return FALSE; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; if(hdc->pen->style == PS_NULL) return TRUE; /* draw line in current pen color*/ GdSetForeground(GdFindColor(hdc->pen->color)); beg = *lppt++; if(MwIsClientDC(hdc)) ClientToScreen(hwnd, &beg); while(--cPoints > 0) { end = *lppt++; if(MwIsClientDC(hdc)) ClientToScreen(hwnd, &end); /* don't draw last point*/ GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE); beg = end; } return TRUE; }
BOOL WINAPI LineTo(HDC hdc, int x, int y) { HWND hwnd; POINT beg, end; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; beg.x = hdc->pt.x; beg.y = hdc->pt.y; end.x = x; end.y = y; if(MwIsClientDC(hdc)) { ClientToScreen(hwnd, &beg); ClientToScreen(hwnd, &end); } /* draw line in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForeground(GdFindColor(hdc->pen->color)); /* don't draw last point*/ GdLine(hdc->psd, beg.x, beg.y, end.x, end.y, FALSE); } hdc->pt.x = x; hdc->pt.y = y; return TRUE; }
/* * Set the cursor size and bitmaps. */ void GdSetCursor(PMWCURSOR pcursor) { int bytes; GdHideCursor(&scrdev); curmaxx = curminx + pcursor->width - 1; curmaxy = curminy + pcursor->height - 1; curfg = GdFindColor(pcursor->fgcolor); curbg = GdFindColor(pcursor->bgcolor); bytes = MWIMAGE_WORDS(pcursor->width) * pcursor->height * sizeof(MWIMAGEBITS); memcpy(cursorcolor, pcursor->image, bytes); memcpy(cursormask, pcursor->mask, bytes); GdShowCursor(&scrdev); }
/* * Clear the specified area of a window and possibly make an exposure event. * This sets the area window to its background color or pixmap. If the * exposeflag is nonzero, then this also creates an exposure event for the * window. */ void GsWpClearWindow(GR_WINDOW *wp, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height, GR_BOOL exposeflag) { if (wp->unmapcount || !wp->output) return; /* * Reduce the arguments so that they actually lie within the window. */ if (x < 0) { width += x; x = 0; } if (y < 0) { height += y; y = 0; } if (x + width > wp->width) width = wp->width - x; if (y + height > wp->height) height = wp->height - y; /* * Now see if the region is really in the window. If not, then * do nothing. */ if ((x >= wp->width) || (y >= wp->height) || (width <= 0) || (height <= 0)) return; /* * Draw the background of the window. * Invalidate the current graphics context since * we are changing the foreground color and mode. */ GsSetClipWindow(wp, NULL, 0); curgcp = NULL; if (!(wp->props & GR_WM_PROPS_NOBACKGROUND)) { GdSetMode(GR_MODE_COPY); GdSetForeground(GdFindColor(wp->background)); if (wp->bgpixmap) { GsWpDrawBackgroundPixmap(wp, wp->bgpixmap, x, y, width, height); } else { GdFillRect(wp->psd, wp->x + x, wp->y + y, width,height); } } /* * Now do the exposure if required. */ if (exposeflag) GsDeliverExposureEvent(wp, x, y, width, height); }
static void dopiearc(HDC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int ax, int ay, int bx, int by, int type) { HWND hwnd; int rx, ry; RECT rc, rc2; hwnd = MwPrepareDC(hdc); if(!hwnd) return; SetRect(&rc, nLeftRect, nTopRect, nRightRect, nBottomRect); SetRect(&rc2, ax, ay, bx, by); if(MwIsClientDC(hdc)) { MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); MapWindowPoints(hwnd, NULL, (LPPOINT)&rc2, 2); } rx = (rc.right - rc.left)/2 - 1; ry = (rc.bottom - rc.top)/2 - 1; rc.left += rx; rc.top += ry; /* fill ellipse in current brush color*/ if(hdc->brush->style != BS_NULL && type == MWPIE) { GdSetForeground(GdFindColor(hdc->brush->color)); GdArc(hdc->psd, rc.left, rc.top, rx, ry, rc2.left, rc2.top, rc2.right, rc2.bottom, MWPIE); } /* draw ellipse outline in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForeground(GdFindColor(hdc->pen->color)); if(type == MWPIE) type = MWARC; /* MWARCOUTLINE?*/ GdArc(hdc->psd, rc.left, rc.top, rx, ry, rc2.left, rc2.top, rc2.right, rc2.bottom, type); } }
BOOL WINAPI Polygon(HDC hdc, CONST POINT *lpPoints, int nCount) { HWND hwnd; int i; LPPOINT pp, ppAlloc = NULL; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; if(MwIsClientDC(hdc)) { /* convert points to client coords*/ ppAlloc = (LPPOINT)malloc(nCount * sizeof(POINT)); if(!ppAlloc) return FALSE; memcpy(ppAlloc, lpPoints, nCount*sizeof(POINT)); pp = ppAlloc; for(i=0; i<nCount; ++i) ClientToScreen(hwnd, pp++); pp = ppAlloc; } else pp = (LPPOINT)lpPoints; /* fill polygon in current brush color*/ if(hdc->brush->style != BS_NULL) { GdSetForeground(GdFindColor(hdc->brush->color)); GdFillPoly(hdc->psd, nCount, pp); } /* draw polygon outline in current pen color*/ if(hdc->pen->style != PS_NULL) { GdSetForeground(GdFindColor(hdc->pen->color)); GdPoly(hdc->psd, nCount, pp); } if(ppAlloc) free(ppAlloc); return TRUE; }
COLORREF WINAPI SetPixel(HDC hdc, int x, int y, COLORREF crColor) { HWND hwnd; POINT pt; hwnd = MwPrepareDC(hdc); if(!hwnd) return 0; /* doesn't return previous color*/ pt.x = x; pt.y = y; if(MwIsClientDC(hdc)) ClientToScreen(hwnd, &pt); /* draw point in passed color*/ GdSetForeground(GdFindColor(crColor)); GdPoint(hdc->psd, pt.x, pt.y); return 0; /* doesn't return previous color*/ }
int WINAPI FillRect(HDC hdc, CONST RECT *lprc, HBRUSH hbr) { HWND hwnd; RECT rc; MWBRUSHOBJ * obr = (MWBRUSHOBJ *)hbr; COLORREF crFill; hwnd = MwPrepareDC(hdc); if(!hwnd || !obr) return FALSE; if(!lprc) { if(MwIsClientDC(hdc)) GetClientRect(hwnd, &rc); else GetWindowRect(hwnd, &rc); lprc = &rc; } else rc = *lprc; if(MwIsClientDC(hdc)) MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); /* handle COLOR_xxx + 1 passed as HBRUSH*/ if((PTRTOINT)obr <= MAXSYSCOLORS) crFill = GetSysColor((int)obr-1); else { /* get color from passed HBRUSH*/ if(obr->style == BS_NULL) return TRUE; crFill = obr->color; } /* fill rectangle in passed brush color*/ GdSetForeground(GdFindColor(crFill)); GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); return TRUE; }
/* * Initialize the graphics and mouse devices at startup. * Returns nonzero with a message printed if the initialization failed. */ int GsInitialize(void) { GR_WINDOW *wp; /* root window */ static IMAGEBITS cursorbits[16] = { 0xe000, 0x9800, 0x8600, 0x4180, 0x4060, 0x2018, 0x2004, 0x107c, 0x1020, 0x0910, 0x0988, 0x0544, 0x0522, 0x0211, 0x000a, 0x0004 }; static IMAGEBITS cursormask[16] = { 0xe000, 0xf800, 0xfe00, 0x7f80, 0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc, 0x1fe0, 0x0ff0, 0x0ff8, 0x077c, 0x073e, 0x021f, 0x000e, 0x0004 }; wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW)); if (wp == NULL) { fprintf(stderr, "Cannot allocate root window\n"); return -1; } #if !NONETWORK if (GsOpenSocket() < 0) { perror("Cannot bind to named socket"); free(wp); return -1; } #endif if ((keyb_fd = GdOpenKeyboard()) < 0) { perror("Cannot initialise keyboard"); /*GsCloseSocket();*/ free(wp); return -1; } if (GdOpenScreen() < 0) { perror("Cannot initialise screen"); /*GsCloseSocket();*/ GdCloseKeyboard(); free(wp); return -1; } if ((mouse_fd = GdOpenMouse()) == -1) { /* -2 == mou_nul.c */ perror("Cannot initialise mouse"); /*GsCloseSocket();*/ GdCloseScreen(); GdCloseKeyboard(); free(wp); return -1; } /* * Get screen dimensions for our own and the client's use, * and the information about the default font. */ GdGetScreenInfo(&scrdev, &sinfo); GdGetFontInfo(&scrdev, FONT_OEM_FIXED, &curfont); GdGetModifierInfo(&sinfo.modifiers); GdGetButtonInfo(&sinfo.buttons); /* * Initialize the root window. */ wp->id = GR_ROOT_WINDOW_ID; wp->parent = wp; wp->children = NULL; wp->siblings = NULL; wp->next = NULL; wp->x = 0; wp->y = 0; wp->width = sinfo.cols; wp->height = sinfo.rows; wp->bordersize = 0; wp->background = BLACK; wp->bordercolor = BLACK; wp->nopropmask = 0; wp->eventclients = NULL; wp->cursor = NULL; wp->mapped = GR_TRUE; wp->unmapcount = 0; wp->output = GR_TRUE; listwp = wp; rootwp = wp; focuswp = wp; mousewp = wp; focusfixed = GR_FALSE; /* * Initialize and position the default cursor. */ curcursor = NULL; cursorx = -1; cursory = -1; GsMoveCursor(sinfo.cols / 2, sinfo.rows / 2); GsSetCursor(GR_ROOT_WINDOW_ID, 16, 16, 0, 0, WHITE, BLACK, cursorbits, cursormask); #if FRAMEBUFFER | BOGL fb_InitVt(); #endif scrdev.FillRect(&scrdev, 0, 0, sinfo.cols-1, sinfo.rows-1, GdFindColor(BLACK)); /* * Finally tell the mouse driver some things. */ curbuttons = 0; /*GdSetAccelMouse(5, 3);*/ GdRestrictMouse(0, 0, sinfo.cols - 1, sinfo.rows - 1); GdMoveMouse(sinfo.cols / 2, sinfo.rows / 2); GsFlush(); /* * All done. */ connectcount = 0; return 0; }
/* * Prepare to do drawing in a window or pixmap using the specified * graphics context. Returns the drawable pointer if successful, * and the type of drawing id that was supplied. Returns the special value * GR_DRAW_TYPE_NONE if an error is generated, or if drawing is useless. */ GR_DRAW_TYPE GsPrepareDrawing(GR_DRAW_ID id, GR_GC_ID gcid, GR_DRAWABLE **retdp) { GR_WINDOW *wp; /* found window */ GR_PIXMAP *pp; /* found pixmap */ GR_GC *gcp; /* found graphics context */ GR_FONT *fontp; GR_REGION *regionp; /* user clipping region */ MWCLIPREGION *reg; PMWFONT pf; *retdp = NULL; gcp = GsFindGC(gcid); if (gcp == NULL) return GR_DRAW_TYPE_NONE; /* * If the graphics context is not the current one, then * make it the current one and remember to update it. */ if (gcp != curgcp) { curgcp = gcp; gcp->changed = GR_TRUE; } /* * Look for window or pixmap id */ pp = NULL; wp = GsFindWindow(id); if (wp == NULL) { pp = GsFindPixmap(id); if (pp == NULL) return GR_DRAW_TYPE_NONE; #if DYNAMICREGIONS reg = GdAllocRectRegion(0, 0, pp->psd->xvirtres, pp->psd->yvirtres); /* intersect with user region if any*/ if (gcp->regionid) { regionp = GsFindRegion(gcp->regionid); if (regionp) GdIntersectRegion(reg, reg, regionp->rgn); } GdSetClipRegion(pp->psd, reg); #else { MWCLIPRECT cliprect; /* FIXME: setup pixmap clipping, different from windows*/ cliprect.x = 0; cliprect.y = 0; cliprect.width = pp->psd->xvirtres; cliprect.height = pp->psd->yvirtres; GdSetClipRects(pp->psd, 1, &cliprect); } #endif /* reset clip cache for next window draw*/ clipwp = NULL; } else { if (!wp->output) { GsError(GR_ERROR_INPUT_ONLY_WINDOW, id); return GR_DRAW_TYPE_NONE; } if (wp->unmapcount) return GR_DRAW_TYPE_NONE; /* * If the window is not the currently clipped one, * then make it the current one and define its clip rectangles. */ if (wp != clipwp || gcp->changed) { /* find user region for intersect*/ if (gcp->regionid) regionp = GsFindRegion(gcp->regionid); else regionp = NULL; /* * Special handling if user region is not at offset 0,0 */ if (regionp && (gcp->xoff || gcp->yoff)) { MWCLIPREGION *local = GdAllocRegion(); GdCopyRegion(local, regionp->rgn); GdOffsetRegion(local, gcp->xoff, gcp->yoff); GsSetClipWindow(wp, local, gcp->mode & ~GR_MODE_DRAWMASK); GdDestroyRegion(local); } else { GsSetClipWindow(wp, regionp? regionp->rgn: NULL, gcp->mode & ~GR_MODE_DRAWMASK); } } } /* * If the graphics context has been changed, then tell the * device driver about it. */ if (gcp->changed) { GdSetForeground(GdFindColor(gcp->foreground)); GdSetBackground(GdFindColor(gcp->background)); GdSetMode(gcp->mode & GR_MODE_DRAWMASK); GdSetUseBackground(gcp->usebackground); fontp = GsFindFont(gcp->fontid); pf = fontp? fontp->pfont: stdfont; GdSetFont(pf); gcp->changed = GR_FALSE; } *retdp = wp? (GR_DRAWABLE *)wp: (GR_DRAWABLE *)pp; return wp? GR_DRAW_TYPE_WINDOW: GR_DRAW_TYPE_PIXMAP; }
/* internal version of ExtTextOut, passed flags for text data type*/ static BOOL MwExtTextOut(HDC hdc, int x, int y, UINT fuOptions, CONST RECT *lprc, LPCVOID lpszString, UINT cbCount, CONST INT *lpDx, int flags) { HWND hwnd; POINT pt; RECT rc; hwnd = MwPrepareDC(hdc); if(!hwnd) return FALSE; pt.x = x; pt.y = y; if(MwIsClientDC(hdc)) ClientToScreen(hwnd, &pt); /* optionally fill passed rectangle*/ if(lprc && (fuOptions&ETO_OPAQUE)) { rc = *lprc; if(MwIsClientDC(hdc)) MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2); /* fill rectangle with current background color*/ GdSetForeground(GdFindColor(hdc->bkcolor)); GdFillRect(hdc->psd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); GdSetUseBackground(FALSE); } else { /* use current background mode for text background draw*/ GdSetUseBackground(hdc->bkmode == OPAQUE? TRUE: FALSE); /* always set background color in case GdArea is * used to draw, which compares gr_foreground != gr_background * if gr_usebg is false... */ /*if(hdc->bkmode == OPAQUE)*/ GdSetBackground(GdFindColor(hdc->bkcolor)); } /* nyi: lpDx*/ /* draw text in current text foreground and background color*/ GdSetForeground(GdFindColor(hdc->textcolor)); GdSetFont(hdc->font->pfont); /* this whole text alignment thing needs rewriting*/ if((hdc->textalign & TA_BASELINE) == TA_BASELINE) { /* this is not right... changed for kaffe port flags |= MWTF_TOP; */ flags |= MWTF_BASELINE; } else if(hdc->textalign & TA_BOTTOM) { MWCOORD ph, pw, pb; if(lprc) pt.y += lprc->bottom - lprc->top; else { GdGetTextSize(hdc->font->pfont, lpszString, cbCount, &pw, &ph, &pb, flags); pt.y += ph; } flags |= MWTF_BOTTOM; } else flags |= MWTF_TOP; GdText(hdc->psd, pt.x, pt.y, lpszString, cbCount, flags); return TRUE; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { PAINTSTRUCT ps; HDC hdc; #if CLIENT3D | IMAGE | GRAPH3D RECT rc; #endif #if GRAPH3D static int countup = 1; int id; static vec1 gx, gy; #endif #if TIMERDEMO static POINT mousept; #endif #if ARCDEMO static int startdegrees = 0; static int enddegrees = 30; #endif switch( msg) { #if TIMERDEMO case WM_CREATE: SetTimer(hwnd, 1, 100, NULL); mousept.x = 60; mousept.y = 20; break; case WM_TIMER: #if GRAPH3D GetClientRect(hwnd, &rc); if(countup) { mousept.y += 20; if(mousept.y >= rc.bottom) { mousept.y -= 20; countup = 0; } } else { mousept.y -= 20; if(mousept.y < 20) { mousept.y += 20; countup = 1; } } SendMessage(hwnd, WM_MOUSEMOVE, 0, MAKELONG(mousept.x, mousept.y)); #endif #if ARCDEMO startdegrees += 10; if(startdegrees >= 360) startdegrees = 0; enddegrees += 15; if(enddegrees >= 360) enddegrees = 0; InvalidateRect(hwnd, NULL, TRUE); #endif break; case WM_DESTROY: KillTimer(hwnd, 1); break; #endif /* TIMERDEMO*/ case WM_SIZE: break; case WM_MOVE: break; #if CLIENT3D case WM_SETFOCUS: PostMessage((HWND)wp, WM_PAINT, 0, 0L); break; case WM_KILLFOCUS: PostMessage((HWND)wp, WM_PAINT, 0, 0L); break; case WM_ERASEBKGND: if(GetFocus() != hwnd) return DefWindowProc(hwnd, msg, wp, lp); return 1; #endif #if GRAPH3D case WM_ERASEBKGND: if((GetWindowLong(hwnd, GWL_ID) & 03) == 1) return 1; return DefWindowProc(hwnd, msg, wp, lp); #endif case WM_PAINT: hdc = BeginPaint(hwnd, &ps); #if CLIENT3D if(GetFocus() == hwnd) { GetClientRect(hwnd, &rc); Draw3dShadow(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, GetSysColor(COLOR_3DDKSHADOW), GetSysColor(COLOR_3DLIGHT)); InflateRect(&rc, -1, -1); FillRect(hdc, &rc, GetStockObject(GRAY_BRUSH)); } #endif #if IMAGE GetClientRect(hwnd, &rc); DrawDIB(hdc, rc.left+2, rc.top+2, image2); #endif #if ARCDEMO { int x, y, w, h; RECT rc; if(hdc != NULL) { GetWindowRect(hwnd, &rc); rc.top += 13; InflateRect(&rc, -3, -3); /*Ellipse(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top);*/ /*Arc(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top, 0,0, 0,0);*/ /*Pie(hdc, 0, 0, rc.right-rc.left, rc.bottom-rc.top, 0,0, 0,0);*/ x = rc.left; y = rc.top; w = rc.right - rc.left; h = rc.bottom - rc.top; w += 10; GdSetForeground(GdFindColor(RGB(0,255,0))); GdArcAngle(hdc->psd, x+w/2, y+h/2, w/2, h/2, startdegrees*64, enddegrees*64, MWPIE); GdSetForeground(GdFindColor(RGB(0,0,0))); GdArcAngle(hdc->psd, x+w/2, y+h/2, w/2, h/2, startdegrees*64, enddegrees*64, MWARCOUTLINE); /*GdSetForeground(GdFindColor(RGB(255,255,255)));*/ /*GdPoint(hdc->psd, x+w/2, y+h/2);*/ } EndPaint(hwnd, &ps); break; } #endif /* ARCDEMO*/ #if GRAPH3D id = (int)GetWindowLong(hwnd, GWL_ID) & 03; init3(hdc, id == 1? hwnd: NULL); switch(id) { case 0: rose(1.0, 7, 13); break; case 1: /*look3(0.5, 0.7, 1.5);*/ /*look3(0.2, -2 * gy, 1.0+gx);*/ look3(-2 * gx, -2 * gy, 1.2); drawgrid(-8.0, 8.0, 10, -8.0, 8.0, 10); break; case 2: setcolor3(BLACK); circle3(1.0); break; case 3: setcolor3(BLUE); daisy(1.0, 20); break; } #if CLIPDEMO if(id == 1) { HRGN hrgn, hrgn2; /* create circular clip region for effect*/ GetClientRect(hwnd, &rc); InflateRect(&rc, -80, -80); switch((int)GetWindowLong(hwnd, GWL_ID)) { default: hrgn = CreateEllipticRgnIndirect(&rc); break; case 5: hrgn = CreateRoundRectRgn(rc.left, rc.top, rc.right, rc.bottom, 100, 100); break; case 1: hrgn = CreateRectRgnIndirect(&rc); break; } /* erase background, clip out blit area*/ GetClientRect(hwnd, &rc); hrgn2 = CreateRectRgnIndirect(&rc); SelectClipRgn(hdc, hrgn2); ExtSelectClipRgn(hdc, hrgn, RGN_XOR); DeleteObject(hrgn2); GetClientRect(hwnd, &rc); FillRect(hdc, &rc, GetStockObject(BLACK_BRUSH)); /* clip in only blit area*/ SelectClipRgn(hdc, hrgn); DeleteObject(hrgn); } #endif /* CLIPDEMO*/ paint3(hdc); #endif /* GRAPH3D*/ EndPaint(hwnd, &ps); break; case WM_LBUTTONDOWN: break; case WM_MOUSEMOVE: #if GRAPH3D if((GetWindowLong(hwnd, GWL_ID) & 03) == 1) { POINT pt; POINTSTOPOINT(pt, lp); GetClientRect(hwnd, &rc); gx = (vec1)pt.x / rc.right; gy = (vec1)pt.y / rc.bottom; InvalidateRect(hwnd, NULL, FALSE); mousept.x = pt.x; mousept.y = pt.y; } #endif break; case WM_LBUTTONUP: break; case WM_RBUTTONDOWN: break; default: return DefWindowProc( hwnd, msg, wp, lp); } return( 0); }
/* * Open low level graphics driver */ PSD GdOpenScreen(void) { PSD psd; MWPALENTRY * stdpal; MWSCREENINFO sinfo; psd = scrdev.Open(&scrdev); if (!psd) return NULL; GdGetScreenInfo(psd, &sinfo); gr_pixtype = sinfo.pixtype; gr_ncolors = sinfo.ncolors; /* assume no user changable palette entries*/ gr_firstuserpalentry = (int)psd->ncolors; /* set palette according to system colors and devpalX.c*/ switch((int)psd->ncolors) { #if !defined(NOSTDPAL1) /* don't require stdpal1 if not needed */ case 2: /* 1bpp*/ { extern MWPALENTRY mwstdpal1[2]; stdpal = mwstdpal1; } break; #endif #if !defined(NOSTDPAL2) /* don't require stdpal2 if not needed */ case 4: /* 2bpp*/ { extern MWPALENTRY mwstdpal2[4]; stdpal = mwstdpal2; } break; #endif #if !defined(NOSTDPAL4) /* don't require stdpal4 if not needed */ case 8: /* 3bpp - not fully supported*/ case 16: /* 4bpp*/ { extern MWPALENTRY mwstdpal4[16]; stdpal = mwstdpal4; } break; #endif #if !defined(NOSTDPAL8) /* don't require large stdpal8 if not needed */ case 256: /* 8bpp*/ { extern MWPALENTRY mwstdpal8[256]; #if xxxALPHABLEND /* don't change uniform palette if alpha blending*/ gr_firstuserpalentry = 256; #else /* start after last system-reserved color*/ gr_firstuserpalentry = FIRSTUSERPALENTRY; #endif stdpal = mwstdpal8; } break; #endif /* !defined(NOSTDPAL8)*/ default: /* truecolor*/ /* no palette*/ gr_firstuserpalentry = 0; stdpal = NULL; } /* reset next user palette entry, write hardware palette*/ GdResetPalette(); GdSetPalette(psd, 0, (int)psd->ncolors, stdpal); #if xxxALPHABLEND /* one-time create alpha lookup table for 8bpp systems (takes ~1 sec)*/ if(psd->ncolors == 256) init_alpha_lookup(); #endif #if !NOFONTSORCLIPPING /* init local vars*/ GdSetMode(MWMODE_COPY); GdSetForeground(GdFindColor(MWRGB(255, 255, 255))); /* WHITE*/ GdSetBackground(GdFindColor(MWRGB(0, 0, 0))); /* BLACK*/ GdSetUseBackground(TRUE); GdSetFont(GdCreateFont(psd, MWFONT_SYSTEM_VAR, 0, NULL)); #if DYNAMICREGIONS GdSetClipRegion(psd, GdAllocRectRegion(0, 0, psd->xvirtres, psd->yvirtres)); #else GdSetClipRects(psd, 0, NULL); #endif /* DYNAMICREGIONS*/ #endif /* NOFONTSORCLIPPING*/ /* fill black (actually fill to first palette entry or truecolor 0*/ psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1, 0); return psd; }
/* * Initialize the graphics and mouse devices at startup. * Returns nonzero with a message printed if the initialization failed. */ int GsInitialize(void) { GR_WINDOW *wp; /* root window */ PSD psd; GR_CURSOR_ID cid; static MWIMAGEBITS cursorbits[16] = { 0xe000, 0x9800, 0x8600, 0x4180, 0x4060, 0x2018, 0x2004, 0x107c, 0x1020, 0x0910, 0x0988, 0x0544, 0x0522, 0x0211, 0x000a, 0x0004 }; static MWIMAGEBITS cursormask[16] = { 0xe000, 0xf800, 0xfe00, 0x7f80, 0x7fe0, 0x3ff8, 0x3ffc, 0x1ffc, 0x1fe0, 0x0ff0, 0x0ff8, 0x077c, 0x073e, 0x021f, 0x000e, 0x0004 }; /* If needed, initialize the server mutex. */ SERVER_LOCK_INIT(); setbuf(stdout, NULL); setbuf(stderr, NULL); wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW)); if (wp == NULL) { EPRINTF("Cannot allocate root window\n"); return -1; } startTicks = GsGetTickCount(); #ifndef MW_NOSIGNALS /* catch terminate signal to restore tty state*/ signal(SIGTERM, (void *)GsTerminate); #endif #if MW_FEATURE_TIMERS screensaver_delay = 0; #endif screensaver_active = GR_FALSE; selection_owner.wid = 0; selection_owner.typelist = NULL; #if !NONETWORK #ifndef MW_NOSIGNALS /* ignore pipe signal, sent when clients exit*/ signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); #endif if (GsOpenSocket() < 0) { EPRINTF("Cannot bind to named socket\n"); free(wp); return -1; } #endif if ((keyb_fd = GdOpenKeyboard()) == -1) { EPRINTF("Cannot initialise keyboard\n"); /*GsCloseSocket();*/ free(wp); return -1; } #ifdef MW_FEATURE_TWO_KEYBOARDS if ((keyb2_fd = GdOpenKeyboard2()) == -1) { EPRINTF("Cannot initialise second keyboard\n"); /*GsCloseSocket();*/ free(wp); return -1; } #endif if ((psd = GdOpenScreen()) == NULL) { EPRINTF("Cannot initialise screen\n"); /*GsCloseSocket();*/ GdCloseKeyboard(); free(wp); return -1; } GdSetPortraitMode(psd, portraitmode); if ((mouse_fd = GdOpenMouse()) == -1) { EPRINTF("Cannot initialise mouse\n"); /*GsCloseSocket();*/ GdCloseScreen(psd); GdCloseKeyboard(); free(wp); return -1; } /* * Create std font. */ #if (HAVE_BIG5_SUPPORT | HAVE_GB2312_SUPPORT | HAVE_JISX0213_SUPPORT | HAVE_KSC5601_SUPPORT) /* system fixed font looks better when mixed with builtin fixed fonts*/ stdfont = GdCreateFont(psd, MWFONT_SYSTEM_FIXED, 0, NULL); #else stdfont = GdCreateFont(psd, MWFONT_SYSTEM_VAR, 0, NULL); #endif /* * Initialize the root window. */ wp->psd = psd; wp->id = GR_ROOT_WINDOW_ID; wp->parent = NULL; /* changed: was = NULL*/ wp->owner = NULL; wp->children = NULL; wp->siblings = NULL; wp->next = NULL; wp->x = 0; wp->y = 0; wp->width = psd->xvirtres; wp->height = psd->yvirtres; wp->bordersize = 0; wp->background = BLACK; wp->bordercolor = wp->background; wp->nopropmask = 0; wp->bgpixmap = NULL; wp->bgpixmapflags = GR_BACKGROUND_TILE; wp->eventclients = NULL; wp->cursorid = 0; wp->mapped = GR_TRUE; wp->realized = GR_TRUE; wp->output = GR_TRUE; wp->props = 0; wp->title = NULL; wp->clipregion = NULL; listpp = NULL; listwp = wp; rootwp = wp; focuswp = wp; mousewp = wp; focusfixed = GR_FALSE; /* * Initialize and position the default cursor. */ curcursor = NULL; cursorx = -1; cursory = -1; GdShowCursor(psd); GsMoveCursor(psd->xvirtres / 2, psd->yvirtres / 2); SERVER_UNLOCK(); cid = GrNewCursor(16, 16, 0, 0, WHITE, BLACK, cursorbits, cursormask); GrSetWindowCursor(GR_ROOT_WINDOW_ID, cid); SERVER_LOCK(); stdcursor = GsFindCursor(cid); #if VTSWITCH MwInitVt(); /* Check for VT change every 50 ms: */ GdAddTimer(50, CheckVtChange, NULL); #endif psd->FillRect(psd, 0, 0, psd->xvirtres-1, psd->yvirtres-1, GdFindColor(psd, wp->background)); /* * Tell the mouse driver some things. */ curbuttons = 0; GdRestrictMouse(0, 0, psd->xvirtres - 1, psd->yvirtres - 1); GdMoveMouse(psd->xvirtres / 2, psd->yvirtres / 2); /* Force root window screen paint*/ GsRedrawScreen(); /* * Force the cursor to appear on the screen at startup. * (not required with above GsRedrawScreen) GdHideCursor(psd); GdShowCursor(psd); */ /* * All done. */ connectcount = 0; return 0; }