📄 grphics.cpp
字号:
newop->header.fd = fd; /*send the fd */ newop->type = DRAW2D; /*send the operator */ newop->param.p[0].f = x; /*set parameters */ newop->param.p[1].f = y; }}/********************************************************************** * rectangle * * Draw a rectangle using current perimeter/interior controls. **********************************************************************/void WINFD::Rectangle( /*draw a rectangle */ float x1, /*coords to draw to */ float y1, /*coords to draw to */ float x2, /*coords to draw to */ float y2 /*coords to draw to */ ) { FOUROP *newop; /*message structure */ /*get some space */ newop = (FOUROP *) getshm (sizeof (FOUROP)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = RECTANGLE; /*send the operator */ newop->param.p[0].f = x1; /*set parameters */ newop->param.p[1].f = y1; newop->param.p[2].f = x2; newop->param.p[3].f = y2; }}/********************************************************************** * text_alignment * * Control text position. **********************************************************************/void WINFD::Text_alignment( /*draw a rectangle */ INT32 h_select, //horizontal INT32 v_select, //vertical float horiz, /*coords to draw to */ float vert /*coords to draw to */ ) { FOUROP *newop; /*message structure */ /*get some space */ newop = (FOUROP *) getshm (sizeof (FOUROP)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = TEXT_ALIGNMENT;/*send the operator */ newop->param.p[0].i = h_select; newop->param.p[1].i = v_select; newop->param.p[2].f = horiz; newop->param.p[3].f = vert; }}/********************************************************************** * polyline2d * * Draw a polyline using current line colour/type. **********************************************************************/voidWINFD::Polyline2d ( /*draw a polyline */float clist[], /*coordinate list */INT16 numpts, /*number of coords */INT16 flags /*does it have move/draws */) { POLYOP *newop; /*message structure */ INT32 floatcount; /*no of floats */ floatcount = flags ? numpts * 3/*move/draw flags in */ : numpts * 2; /*no move/draw flags */ /*get some space */ newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = POLYLINE2D; /*send the operator */ /*pointer to array */ newop->param.clist = newop->clist; newop->param.numpts = numpts;/*other params */ newop->param.flags = flags; memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float)); }}/********************************************************************** * polygon2d * * Draw a polygon using current line colour/type. **********************************************************************/voidWINFD::Polygon2d ( /*draw a polygon */float clist[], /*coordinate list */INT16 numpts, /*number of coords */INT16 flags /*does it have move/draws */) { POLYOP *newop; /*message structure */ INT32 floatcount; /*no of floats */ floatcount = flags ? numpts * 3/*move/draw flags in */ : numpts * 2; /*no move/draw flags */ /*get some space */ newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = POLYGON2D; /*send the operator */ /*pointer to array */ newop->param.clist = newop->clist; newop->param.numpts = numpts;/*other params */ newop->param.flags = flags; memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float)); }}/********************************************************************** * polymarker2d * * Draw a polymarker using current marker colour/type. **********************************************************************/voidWINFD::Polymarker2d ( /*draw a polymarker */float clist[], /*coordinate list */INT16 numpts, /*number of coords */INT16 flags /*does it have move/draws */) { POLYOP *newop; /*message structure */ INT32 floatcount; /*no of floats */ floatcount = flags ? numpts * 3/*move/draw flags in */ : numpts * 2; /*no move/draw flags */ /*get some space */ newop = (POLYOP *) getshm (sizeof (POLYOP) + sizeof (float) * (floatcount - 1)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = POLYMARKER2D; /*send the operator */ /*pointer to array */ newop->param.clist = newop->clist; newop->param.numpts = numpts;/*other params */ newop->param.flags = flags; memcpy (newop->clist, clist, (UINT32) floatcount * sizeof (float)); }}/********************************************************************** * text2d * * Draw a text string using current font, colour, height. **********************************************************************/void WINFD::Text2d( /*draw a text */ float x, /*coords of text */ float y, const char *string, /*text to draw */ INT16 xform, /*transform */ INT16 more /*more text? */ ) { TEXTOP *newop; /*message structure */ INT16 length; /*length of string */ length = strlen (string) + 1; /*include null */ length += 3; length &= ~3; /*round up to words */ /*get some space */ newop = (TEXTOP *) getshm (sizeof (TEXTOP) + length - 4); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = TEXT2D; /*send the operator */ newop->param.x = x; /*copy parameters */ newop->param.y = y; newop->param.string = newop->chars; newop->param.xform = xform; newop->param.more = more; /*copy the string */ strcpy (newop->chars, string); }}/********************************************************************** * append_text * * Draw a text string using current font, colour, height. **********************************************************************/void WINFD::Append_text( /*draw a text */ const char *string, /*text to draw */ INT16 xform, /*transform */ INT16 more /*more text? */ ) { APPENDOP *newop; /*message structure */ INT16 length; /*length of string */ length = strlen (string) + 1; /*include null */ length += 3; length &= ~3; /*round up to words */ /*get some space */ newop = (APPENDOP *) getshm (sizeof (APPENDOP) + length - 4); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = APPENDTEXT; /*send the operator */ newop->param.string = newop->chars; newop->param.xform = xform; newop->param.more = more; /*copy the string */ strcpy (newop->chars, string); }}/********************************************************************** * ellipse * * Draw an ellipse using current perimeter/interior controls. **********************************************************************/void WINFD::Ellipse( /*draw a ellipse */ float x_radius, /*radii of ellipse */ float y_radius, /*radii of ellipse */ float x_center, /*centre of ellipse */ float y_center, /*centre of ellipse */ float rotation /*rotation of ellipse */ ) { EIGHTOP *newop; /*message structure */ /*get some space */ newop = (EIGHTOP *) getshm (sizeof (EIGHTOP)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = ELLIPSE; /*send the operator */ /*set parameters */ newop->param.p[0].f = x_radius; newop->param.p[1].f = y_radius; newop->param.p[2].f = x_center; newop->param.p[3].f = y_center; newop->param.p[4].f = rotation; }}/********************************************************************** * arc * * Draw an arc using current perimeter/interior controls. **********************************************************************/void WINFD::Arc( /*draw a arc */ float x_radius, /*radii of arc */ float y_radius, /*radii of arc */ float x_center, /*centre of arc */ float y_center, /*centre of arc */ float start, /*ends of arc */ float stop, /*ends of arc */ float rotation, /*rotation of arc */ INT16 close_type /*type of closure */ ) { EIGHTOP *newop; /*message structure */ /*get some space */ newop = (EIGHTOP *) getshm (sizeof (EIGHTOP)); if (newop != NULL) { newop->header.fd = fd; /*send the fd */ newop->type = ARC; /*send the operator */ /*set parameters */ newop->param.p[0].f = x_radius; newop->param.p[1].f = y_radius; newop->param.p[2].f = x_center; newop->param.p[3].f = y_center; newop->param.p[4].f = start; newop->param.p[5].f = stop; newop->param.p[6].f = rotation; newop->param.p[7].i = close_type; }}/********************************************************************** * create_window * * Create a window and register event handlers on the window. * The return "file descriptor" is used in subsequent starbase * primitives to refer to this window. **********************************************************************/WINDOW WINFD::create( /*create a window */ const char *name, /*name/title of window */ INT8 window_type, /*type of window */ INT16 xpos, /*coords of window */ INT16 ypos, /*coords of window */ INT16 xsize, /*size of window */ INT16 ysize, /*size of window */ float xmin, /*scrolling limits */ float xmax, /*to stop users */ float ymin, /*getting lost in */ float ymax, /*empty space */ BOOL8 downon, /*Events wanted */ BOOL8 moveon, BOOL8 upon, BOOL8 keyon) { INT16 fd; //integer index CREATEOP *newop; /*create structure */ WINDOW win; //output if (xmin == xmax || ymin == ymax) return NO_WINDOW; if (maxsbfd == 0) { maxsbfd = 1; /*don't use 0 */ start_sbdaemon(); /*startup daemon */ } /*find a free one */ for (fd = 1; fd < maxsbfd && sbfds[fd].used; fd++); if (fd == maxsbfd) { /*need a new one */ if (maxsbfd == MAXWINDOWS) return NO_WINDOW; maxsbfd++; } win = &sbfds[fd]; //this win->fd = fd; win->used = TRUE; /*it is in use */ win->downevent = downon; win->moveevent = moveon; win->upevent = upon; win->keyevent = keyon; win->click_handler = NULL; win->selection_handler = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -