📄 srvfunc.c
字号:
SERVER_LOCK(); prgn1 = GsFindRegion(rgn1); prgn2 = GsFindRegion(rgn2); if (!prgn1 && !prgn2) { result = GR_TRUE; } else if (!prgn1 || !prgn2) { result = GR_FALSE; } else { result = GdEqualRegion(prgn1->rgn, prgn2->rgn); } SERVER_UNLOCK(); return result;}/* * Offset a region by dx, dy. */ voidGrOffsetRegion(GR_REGION_ID region, GR_SIZE dx, GR_SIZE dy){ GR_REGION *regionp; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp) GdOffsetRegion(regionp->rgn, dx, dy); SERVER_UNLOCK();}/* * Return the bounding box for the specified region. */intGrGetRegionBox(GR_REGION_ID region, GR_RECT *rect){ GR_REGION *regionp; MWRECT rc; int ret_val; SERVER_LOCK(); regionp = GsFindRegion(region); if (regionp == NULL) { memset(rect, 0, sizeof(GR_RECT)); SERVER_UNLOCK(); return MWREGION_ERROR; } ret_val = GdGetRegionBox(regionp->rgn, &rc); /* convert MW rect to Nano-X rect*/ rect->x = rc.left; rect->y = rc.top; rect->width = rc.right - rc.left; rect->height = rc.bottom - rc.top; SERVER_UNLOCK(); return ret_val;}static int nextfontid = 1000;/* * Allocate a new GC with default parameters. * The GC is owned by the current client. */GR_FONT_IDGrCreateFont(GR_CHAR *name, GR_COORD height, GR_LOGFONT *plogfont){ GR_FONT *fontp; SERVER_LOCK(); fontp = (GR_FONT *) malloc(sizeof(GR_FONT)); if (fontp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } if (plogfont) fontp->pfont = GdCreateFont(&scrdev, NULL, 0, plogfont); else fontp->pfont = GdCreateFont(&scrdev, (const char *)name, height, NULL); /* if no font created, deallocate and return ID 0*/ if (!fontp->pfont) { free(fontp); return 0; } fontp->id = nextfontid++; fontp->owner = curclient; fontp->next = listfontp; listfontp = fontp; SERVER_UNLOCK(); return fontp->id;}#if HAVE_FREETYPE_2_SUPPORT/* * Create a new font from memory. * The font is owned by the current client. */GR_FONT_IDGrCreateFontFromBuffer(const void *buffer, unsigned length, const char *format, GR_COORD height){ GR_FONT *fontp; SERVER_LOCK(); fontp = (GR_FONT *)malloc(sizeof(GR_FONT)); if (fontp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } /* DPRINTF("Font magic = '%c%c%c%c', len = %u @ GrCreateFontFromBuffer\n", * (char) buffer[0], (char) buffer[1], * (char) buffer[2], (char) buffer[3], length); */ fontp->pfont = GdCreateFontFromBuffer(&scrdev, buffer, length, format, height); if (fontp->pfont == NULL) { /* Error loading font, probably corrupt data or unsupported format. */ free(fontp); SERVER_UNLOCK(); return 0; } fontp->id = nextfontid++; fontp->owner = curclient; fontp->next = listfontp; listfontp = fontp; SERVER_UNLOCK(); return fontp->id;}/* * Create a new font from memory. * The font is owned by the current client. */GR_FONT_IDGrCopyFont(GR_FONT_ID fontid, GR_COORD height){ GR_FONT *srcfontp; GR_FONT *fontp; SERVER_LOCK(); fontp = (GR_FONT *)malloc(sizeof(GR_FONT)); if (fontp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } srcfontp = GsFindFont(fontid); if (srcfontp) fontp->pfont = GdDuplicateFont(&scrdev, srcfontp->pfont,height); else fontp->pfont = GdCreateFont(&scrdev, NULL, height, NULL); fontp->id = nextfontid++; fontp->owner = curclient; fontp->next = listfontp; listfontp = fontp; SERVER_UNLOCK(); return fontp->id;}#endif /*HAVE_FREETYPE_2_SUPPORT*//* Set the font size for the passed font*/voidGrSetFontSize(GR_FONT_ID fontid, GR_COORD size){ GR_FONT *fontp; SERVER_LOCK(); fontp = GsFindFont(fontid); if (fontp) GdSetFontSize(fontp->pfont, size); SERVER_UNLOCK();}/* Set the font rotation in tenths of degrees for the passed font*/voidGrSetFontRotation(GR_FONT_ID fontid, int tenthdegrees){ GR_FONT *fontp; SERVER_LOCK(); fontp = GsFindFont(fontid); if (fontp) GdSetFontRotation(fontp->pfont, tenthdegrees); SERVER_UNLOCK();}/* Set the font size for the passed font*/voidGrSetFontAttr(GR_FONT_ID fontid, int setflags, int clrflags){ GR_FONT *fontp; SERVER_LOCK(); fontp = GsFindFont(fontid); if (fontp) GdSetFontAttr(fontp->pfont, setflags, clrflags); SERVER_UNLOCK();}/* * Unload and deallocate an existing font. */voidGrDestroyFont(GR_FONT_ID fontid){ GR_FONT *fontp; GR_FONT *prevfontp; SERVER_LOCK(); fontp = GsFindFont(fontid); if (fontp == NULL) { SERVER_UNLOCK(); return; } if (listfontp == fontp) listfontp = fontp->next; else { prevfontp = listfontp; while (prevfontp->next != fontp) prevfontp = prevfontp->next; prevfontp->next = fontp->next; } GdDestroyFont(fontp->pfont); free(fontp); SERVER_UNLOCK();}/* * Return useful information about the specified font. * Font #0 returns info about the standard font. */voidGrGetFontInfo(GR_FONT_ID font, GR_FONT_INFO *fip){ GR_FONT *fontp; PMWFONT pf; SERVER_LOCK(); if (font == 0) pf = stdfont; else { fontp = GsFindFont(font); if (!fontp) { memset(fip, 0, sizeof(GR_FONT_INFO)); SERVER_UNLOCK(); return; } pf = fontp->pfont; } GdGetFontInfo(pf, fip); SERVER_UNLOCK();}/* * Select events for a window for this client. * The events are a bitmask for the events desired. */void GrSelectEvents(GR_WINDOW_ID wid, GR_EVENT_MASK eventmask){ GR_WINDOW *wp; /* window structure */ GR_EVENT_CLIENT *evp; /* event-client structure */ SERVER_LOCK(); wp = GsFindWindow(wid); if (wp == NULL) { SERVER_UNLOCK(); return; } /* * See if this client is already in the event client list. * If so, then just replace the events he is selecting for. */ for (evp = wp->eventclients; evp; evp = evp->next) { if (evp->client == curclient) { evp->eventmask = eventmask; SERVER_UNLOCK(); return; } } /* * A new client for this window, so allocate a new event client * structure and insert it into the front of the list in the window. */ evp = (GR_EVENT_CLIENT *) malloc(sizeof(GR_EVENT_CLIENT)); if (evp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, wid); SERVER_UNLOCK(); return; } evp->client = curclient; evp->eventmask = eventmask; evp->next = wp->eventclients; wp->eventclients = evp; /* * If it's a request for child updates to the root window, * then search entire list and send map events for * mapped windows now. This allows a window manager * to get the mapped window list without another API call. */ if (wid==GR_ROOT_WINDOW_ID && (eventmask & GR_EVENT_MASK_CHLD_UPDATE)) { for (wp = listwp; wp; wp = wp->next) { if (wp->realized) GsDeliverUpdateEvent(wp, GR_UPDATE_MAP, wp->x, wp->y, wp->width, wp->height); } } SERVER_UNLOCK();}static GR_WINDOW *NewWindow(GR_WINDOW *pwp, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height, GR_SIZE bordersize, GR_COLOR background, GR_COLOR bordercolor){ GR_WINDOW *wp; /* new window*/ if (width <= 0 || height <= 0 || bordersize < 0) { GsError(GR_ERROR_BAD_WINDOW_SIZE, 0); return NULL; } wp = (GR_WINDOW *) malloc(sizeof(GR_WINDOW)); if (wp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); return NULL; } wp->id = nextid++; wp->psd = rootwp->psd; wp->parent = pwp; wp->children = NULL; wp->siblings = pwp->children; wp->next = listwp; wp->x = pwp->x + x; wp->y = pwp->y + y; wp->width = width; wp->height = height; wp->bordersize = bordersize; wp->background = background; wp->bgpixmap = NULL; wp->bgpixmapflags = GR_BACKGROUND_TILE; wp->bordercolor = bordercolor; wp->nopropmask = 0; wp->eventclients = NULL; wp->owner = curclient; wp->cursorid = pwp->cursorid; wp->mapped = GR_FALSE; wp->realized = GR_FALSE; wp->output = GR_TRUE; wp->props = 0; wp->title = NULL; wp->clipregion = NULL; pwp->children = wp; listwp = wp; return wp;}/* * Allocate a new window which is a child of the specified window. * The window inherits the cursor of the parent window. * The window is owned by the current client. */GR_WINDOW_IDGrNewWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height, GR_SIZE bordersize, GR_COLOR background, GR_COLOR bordercolor){ GR_WINDOW *pwp; /* parent window */ GR_WINDOW *wp; /* new window */ GR_WINDOW_ID id; SERVER_LOCK(); pwp = GsFindWindow(parent); if (pwp == NULL) { SERVER_UNLOCK(); return 0; } if (!pwp->output) { GsError(GR_ERROR_INPUT_ONLY_WINDOW, pwp->id); SERVER_UNLOCK(); return 0; } wp = NewWindow(pwp, x, y, width, height, bordersize, background, bordercolor); id = wp? wp->id: 0; SERVER_UNLOCK(); return id;}/* * Allocate a new input-only window which is a child of the specified window. * Such a window is invisible, cannot be drawn into, and is only used to * return events. The window inherits the cursor of the parent window. * The window is owned by the current client. */GR_WINDOW_IDGrNewInputWindow(GR_WINDOW_ID parent, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height){ GR_WINDOW *pwp; /* parent window */ GR_WINDOW *wp; /* new window */ GR_WINDOW_ID id; SERVER_LOCK(); pwp = GsFindWindow(parent); if (pwp == NULL) { SERVER_UNLOCK(); return 0; } wp = NewWindow(pwp, x, y, width, height, 0, BLACK, BLACK); if (wp) { /* convert to input-only window*/ wp->output = GR_FALSE; id = wp->id; SERVER_UNLOCK(); return id; } SERVER_UNLOCK(); return 0;}/* * Allocate a pixmap, can be used with any drawing functions * for offscreen drawing */GR_WINDOW_IDGrNewPixmap(GR_SIZE width, GR_SIZE height, void * pixels){ GR_PIXMAP *pp; PSD psd; int size, linelen, bpp, planes; GR_WINDOW_ID id; if (width <= 0 || height <= 0) { /* no error for now, server will desynchronize w/app*/ /*GsError(GR_ERROR_BAD_WINDOW_SIZE, 0);*/ return 0; } SERVER_LOCK(); /* * allocate offscreen psd. If screen driver doesn't * support blitting, this will fail. Use root window screen * device for compatibility for now. */ planes = rootwp->psd->planes; bpp = rootwp->psd->bpp; psd = rootwp->psd->AllocateMemGC(rootwp->psd); if (!psd) { SERVER_UNLOCK(); return 0; } pp = (GR_PIXMAP *) malloc(sizeof(GR_PIXMAP)); if (pp == NULL) { GsError(GR_ERROR_MALLOC_FAILED, 0); psd->FreeMemGC(psd); SERVER_UNLOCK(); return 0; } GdCalcMemGCAlloc(psd, width, height, 0, 0, &size, &linelen); /* Allocate space for pixel values */ if (!pixels) { pixels = calloc(size, 1); psd->flags |= PSF_ADDRMALLOC; } if (!pixels) { free(pp); psd->FreeMemGC(psd); GsError(GR_ERROR_MALLOC_FAILED, 0); SERVER_UNLOCK(); return 0; } pp->id = nextid++; pp->next = listpp; pp->psd = psd; pp->x = 0; pp->y = 0; pp->width = width; pp->height = height; pp->owner = curclient; psd->MapMemGC(psd, width, height, planes, bpp, linelen, size, pixels); listpp = pp; id = pp->id; SERVER_UNLOCK(); return id;}/* * Map the window to make it (and possibly its children) visible on the screen. */voidGrMapWindow(GR_WINDOW_ID wid){ GR_WINDOW *wp; /* window structure */ SERVER_LOCK(); wp = GsFindWindow(wid); if (!wp || wp->mapped) { SERVER_UNLOCK(); return; } wp->mapped = GR_TRUE; GsWpRealizeWindow(wp, GR_FALSE); SERVER_UNLOCK();}/* * Unmap the window to make it and its children invisible on the screen. */voidGrUnmapWindow(GR_WINDOW_ID wid){ GR_WINDOW *wp; /* window structure */ SERVER_LOCK(); wp = GsFindWindow(wid); if (!wp || !wp->mapped) { SERVER_UNLOCK(); return; } GsWpUnrealizeWindow(wp, GR_FALSE); wp->mapped = GR_FALSE; SERVER_UNLOCK();}/* * Clear the associated area of a window to its background color * or pixmap. Generate expose event for window if exposeflag set. */voidGrClearArea(GR_WINDOW_ID wid, GR_COORD x, GR_COORD y, GR_SIZE width, GR_SIZE height, GR_BOOL exposeflag){ GR_WINDOW *wp; /* window structure */ SERVER_LOCK(); wp = GsPrepareWindow(wid); if (wp) { if (width == 0) width = wp->width; if (height == 0) height = wp->height; GsWpClearWindow(wp, x, y, width, height, exposeflag); } SERVER_UNLOCK();}/* Return window with keyboard focus.*/GR_WINDOW_IDGrGetFocus(void){ GR_WINDOW_ID id; SERVER_LOCK(); id = focuswp->id; SERVER_UNLOCK(); return id;}/* * Set the focus to a particular window. * This makes keyboard events only visible to that window or children of it, * depending on the pointer location. */voidGrSetFocus(GR_WINDOW_ID wid){ GR_WINDOW *wp; /* window structure */ SERVER_LOCK(); wp = GsFindWindow(wid); if (wp == NULL) { SERVER_UNLOCK(); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -