/hpc_kernel_samples/sparse_linear_algebra/casestudies/pagerank-petsc/petsc-2.3.2-p10/src/sys/draw/impls/x/frame.c

https://gitlab.com/pheinzlr/CodeVault · C · 118 lines · 90 code · 10 blank · 18 comment · 11 complexity · ec13fa3394436dcb7c563eea12ed766f MD5 · raw file

  1. #define PETSC_DLL
  2. /*
  3. This file contains routines to draw a 3-d like frame about a given
  4. box with a given width. Note that we might like to use a high/low
  5. color for highlights.
  6. The region has 6 parameters. These are the dimensions of the actual frame.
  7. */
  8. #include "src/sys/draw/impls/x/ximpl.h"
  9. EXTERN PixVal XiGetColor(PetscDraw_X *,char *,int);
  10. /* 50% grey stipple pattern */
  11. static Pixmap grey50 = (Pixmap)0;
  12. #define cboard50_width 8
  13. #define cboard50_height 8
  14. static unsigned char cboard50_bits[] = {
  15. 0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa};
  16. static PixVal HiPix=0,LoPix=0;
  17. /*
  18. Set the colors for the highlights by name
  19. */
  20. #undef __FUNCT__
  21. #define __FUNCT__ "XiFrameColors"
  22. PetscErrorCode XiFrameColors(PetscDraw_X* XiWin,XiDecoration *Rgn,char *Hi,char *Lo)
  23. {
  24. PetscFunctionBegin;
  25. Rgn->Hi = XiGetColor(XiWin,Hi,1);
  26. Rgn->Lo = XiGetColor(XiWin,Lo,1);
  27. Rgn->HasColor = Rgn->Hi != Rgn->Lo;
  28. PetscFunctionReturn(0);
  29. }
  30. #undef __FUNCT__
  31. #define __FUNCT__ "XiDrawFrame"
  32. PetscErrorCode XiDrawFrame(PetscDraw_X *XiWin,XiDecoration *Rgn)
  33. {
  34. int xl = Rgn->Box.x,yl = Rgn->Box.y,xh = Rgn->Box.xh,yh = Rgn->Box.yh,
  35. o = Rgn->width;
  36. XPoint high[7],low[7];
  37. PixVal Hi,Lo;
  38. PetscFunctionBegin;
  39. /* High polygon */
  40. high[0].x = xl; high[0].y = yh;
  41. high[1].x = xl + o; high[1].y = yh - o;
  42. high[2].x = xh - o; high[2].y = yh - o;
  43. high[3].x = xh - o; high[3].y = yl + o;
  44. high[4].x = xh; high[4].y = yl;
  45. high[5].x = xh; high[5].y = yh;
  46. high[6].x = xl; high[6].y = yh; /* close path */
  47. low[0].x = xl; low[0].y = yh;
  48. low[1].x = xl; low[1].y = yl;
  49. low[2].x = xh; low[2].y = yl;
  50. low[3].x = xh - o; low[3].y = yl + o;
  51. low[4].x = xl + o; low[4].y = yl + o;
  52. low[5].x = xl + o; low[5].y = yh - o;
  53. low[6].x = xl; low[6].y = yh; /* close path */
  54. if (Rgn->HasColor) {
  55. if (Rgn->Hi) Hi = Rgn->Hi;
  56. else Hi = HiPix;
  57. if (Rgn->Lo) Lo = Rgn->Lo;
  58. else Lo = LoPix;
  59. XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Hi : Lo);
  60. if (o <= 1)
  61. XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  62. high,7,CoordModeOrigin);
  63. else
  64. XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  65. high,7,Nonconvex,CoordModeOrigin);
  66. XiSetPixVal(XiWin,(Rgn->is_in !=0) ? Lo : Hi);
  67. if (o <= 1)
  68. XDrawLines(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  69. low,7,CoordModeOrigin);
  70. else
  71. XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  72. low,7,Nonconvex,CoordModeOrigin);
  73. /* We could use additional highlights here,such as lines drawn
  74. connecting the mitred edges. */
  75. }
  76. else {
  77. if (!grey50)
  78. grey50 = XCreatePixmapFromBitmapData(XiWin->disp,XiWin->win,
  79. (char *)cboard50_bits,
  80. cboard50_width,
  81. cboard50_height,1,0,1);
  82. XiSetPixVal(XiWin,Rgn->Hi);
  83. XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  84. high,7,Nonconvex,CoordModeOrigin);
  85. /* This can actually be done by using a stipple effect */
  86. XSetFillStyle(XiWin->disp,XiWin->gc.set,FillStippled);
  87. XSetStipple(XiWin->disp,XiWin->gc.set,grey50);
  88. XFillPolygon(XiWin->disp,XiDrawable(XiWin),XiWin->gc.set,
  89. low,7,Nonconvex,CoordModeOrigin);
  90. XSetFillStyle(XiWin->disp,XiWin->gc.set,FillSolid);
  91. }
  92. PetscFunctionReturn(0);
  93. }
  94. /*
  95. Set the colors for the highlights by name
  96. */
  97. #undef __FUNCT__
  98. #define __FUNCT__ "XiFrameColorsByName"
  99. PetscErrorCode XiFrameColorsByName(PetscDraw_X* XiWin,char *Hi,char *Lo)
  100. {
  101. PetscFunctionBegin;
  102. if (XiWin->numcolors > 2) {
  103. HiPix = XiGetColor(XiWin,Hi,1);
  104. LoPix = XiGetColor(XiWin,Lo,1);
  105. }
  106. PetscFunctionReturn(0);
  107. }