/* Provides the calling sequences for all the basic PetscDraw routines. */ #include /*I "petscdraw.h" I*/ /*@C PetscDrawString - PetscDraws text onto a drawable. Not Collective Input Parameters: + draw - the drawing context . xl,yl - the coordinates of lower left corner of text . cl - the color of the text - text - the text to draw Level: beginner .seealso: `PetscDrawStringVertical()`, `PetscDrawStringCentered()`, `PetscDrawStringBoxed()`, `PetscDrawStringSetSize()`, `PetscDrawStringGetSize()`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`, `PetscDrawMarker()`, `PetscDrawPoint()` @*/ PetscErrorCode PetscDrawString(PetscDraw draw,PetscReal xl,PetscReal yl,int cl,const char text[]) { PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(text,5); PetscCheck(draw->ops->string,PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing strings",((PetscObject)draw)->type_name); PetscCall((*draw->ops->string)(draw,xl,yl,cl,text)); PetscFunctionReturn(0); } /*@C PetscDrawStringVertical - PetscDraws text onto a drawable. Not Collective Input Parameters: + draw - the drawing context . xl,yl - the coordinates of upper left corner of text . cl - the color of the text - text - the text to draw Level: beginner .seealso: `PetscDrawString()`, `PetscDrawStringCentered()`, `PetscDrawStringBoxed()`, `PetscDrawStringSetSize()`, `PetscDrawStringGetSize()` @*/ PetscErrorCode PetscDrawStringVertical(PetscDraw draw,PetscReal xl,PetscReal yl,int cl,const char text[]) { int i; char chr[2] = {0, 0}; PetscReal tw,th; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(text,5); if (draw->ops->stringvertical) { PetscCall((*draw->ops->stringvertical)(draw,xl,yl,cl,text)); PetscFunctionReturn(0); } PetscCall(PetscDrawStringGetSize(draw,&tw,&th)); for (i = 0; (chr[0] = text[i]); i++) { PetscCall(PetscDrawString(draw,xl,yl-th*(i+1),cl,chr)); } PetscFunctionReturn(0); } /*@C PetscDrawStringCentered - PetscDraws text onto a drawable centered at a point Not Collective Input Parameters: + draw - the drawing context . xc - the coordinates of right-left center of text . yl - the coordinates of lower edge of text . cl - the color of the text - text - the text to draw Level: beginner .seealso: `PetscDrawStringVertical()`, `PetscDrawString()`, `PetscDrawStringBoxed()`, `PetscDrawStringSetSize()`, `PetscDrawStringGetSize()` @*/ PetscErrorCode PetscDrawStringCentered(PetscDraw draw,PetscReal xc,PetscReal yl,int cl,const char text[]) { size_t len; PetscReal tw,th; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(text,5); PetscCall(PetscDrawStringGetSize(draw,&tw,&th)); PetscCall(PetscStrlen(text,&len)); xc = xc - len*tw/2; PetscCall(PetscDrawString(draw,xc,yl,cl,text)); PetscFunctionReturn(0); } /*@C PetscDrawStringBoxed - Draws a string with a box around it Not Collective Input Parameters: + draw - the drawing context . sxl - the coordinates of center of the box . syl - the coordinates of top line of box . sc - the color of the text . bc - the color of the bounding box - text - the text to draw Output Parameter: . w,h - width and height of resulting box (optional) Level: beginner .seealso: `PetscDrawStringVertical()`, `PetscDrawString()`, `PetscDrawStringCentered()`, `PetscDrawStringSetSize()`, `PetscDrawStringGetSize()` @*/ PetscErrorCode PetscDrawStringBoxed(PetscDraw draw,PetscReal sxl,PetscReal syl,int sc,int bc,const char text[],PetscReal *w,PetscReal *h) { PetscReal top,left,right,bottom,tw,th; size_t len,mlen = 0; char **array; int cnt,i; PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscValidCharPointer(text,6); if (draw->ops->boxedstring) { PetscCall((*draw->ops->boxedstring)(draw,sxl,syl,sc,bc,text,w,h)); PetscFunctionReturn(0); } PetscCall(PetscStrToArray(text,'\n',&cnt,&array)); for (i=0; iboundbox_xl = PetscMin(draw->boundbox_xl,left); draw->boundbox_xr = PetscMax(draw->boundbox_xr,right); draw->boundbox_yl = PetscMin(draw->boundbox_yl,bottom); draw->boundbox_yr = PetscMax(draw->boundbox_yr,top); /* top, left, bottom, right lines */ PetscCall(PetscDrawLine(draw,left,top,right,top,bc)); PetscCall(PetscDrawLine(draw,left,bottom,left,top,bc)); PetscCall(PetscDrawLine(draw,right,bottom,right,top,bc)); PetscCall(PetscDrawLine(draw,left,bottom,right,bottom,bc)); for (i=0; iops->stringsetsize) PetscCall((*draw->ops->stringsetsize)(draw,width,height)); PetscFunctionReturn(0); } /*@ PetscDrawStringGetSize - Gets the size for character text. The width is relative to the user coordinates of the window. Not Collective Input Parameters: + draw - the drawing context . width - the width in user coordinates - height - the character height Level: advanced .seealso: `PetscDrawStringVertical()`, `PetscDrawString()`, `PetscDrawStringCentered()`, `PetscDrawStringBoxed()`, `PetscDrawStringSetSize()` @*/ PetscErrorCode PetscDrawStringGetSize(PetscDraw draw,PetscReal *width,PetscReal *height) { PetscFunctionBegin; PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); PetscCheck(draw->ops->stringgetsize,PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support getting string size",((PetscObject)draw)->type_name); PetscCall((*draw->ops->stringgetsize)(draw,width,height)); PetscFunctionReturn(0); }