PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/xorg-x11-apps-7.6/x11perf-1.5.3/do_arcs.c

#
C | 497 lines | 392 code | 71 blank | 34 comment | 53 complexity | 2e206ff2a316341aaaa7d5a7038ea4b0 MD5 | raw file
Possible License(s): MIT
  1. /*****************************************************************************
  2. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  3. All Rights Reserved
  4. Permission to use, copy, modify, and distribute this software and its
  5. documentation for any purpose and without fee is hereby granted,
  6. provided that the above copyright notice appear in all copies and that
  7. both that copyright notice and this permission notice appear in
  8. supporting documentation, and that the name of Digital not be
  9. used in advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.
  11. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  12. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  13. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  14. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  15. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  16. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  17. SOFTWARE.
  18. ******************************************************************************/
  19. #include "x11perf.h"
  20. static XArc *arcs;
  21. static GC pgc;
  22. #define DegreesToX(degrees) (degrees * 64)
  23. static void
  24. GenerateCircles(XParms xp, Parms p, Bool partialArcs, Bool ddashed)
  25. {
  26. int i;
  27. int rows; /* Number of rows filled in current column */
  28. int x, y; /* base of square to draw the circle in */
  29. int xorg, yorg; /* Used to get from column to column or row to row */
  30. int size;
  31. int half;
  32. int startAngle, arcAngle;
  33. if(ddashed)
  34. pgc = xp->ddfggc;
  35. else
  36. pgc = xp->fggc;
  37. size = p->special;
  38. half = (size + 19) / 20;
  39. arcs = (XArc *)malloc((p->objects) * sizeof(XArc));
  40. x = xorg = half; y = yorg = half;
  41. rows = 0;
  42. startAngle = DegreesToX(0);
  43. arcAngle = DegreesToX(360);
  44. for (i = 0; i != p->objects; i++) {
  45. arcs[i].x = x;
  46. arcs[i].y = y;
  47. arcs[i].width = size;
  48. arcs[i].height = size;
  49. arcs[i].angle1 = startAngle;
  50. arcs[i].angle2 = arcAngle;
  51. if (partialArcs) {
  52. startAngle += DegreesToX(30);
  53. if (startAngle >= DegreesToX(360)) startAngle -= DegreesToX(360);
  54. arcAngle -= DegreesToX(20);
  55. if (arcAngle <= DegreesToX(0)) arcAngle += DegreesToX(360);
  56. }
  57. y += size + 1;
  58. rows++;
  59. if (y >= HEIGHT - size - half || rows == MAXROWS) {
  60. /* Go to next column */
  61. rows = 0;
  62. x += size + 1;
  63. if (x >= WIDTH - size) {
  64. yorg++;
  65. if (yorg >= size + half || yorg >= HEIGHT - size - half) {
  66. yorg = half;
  67. xorg++;
  68. if (xorg >= size + half || xorg >= WIDTH - size - half) {
  69. xorg = half;
  70. }
  71. }
  72. x = xorg;
  73. }
  74. y = yorg;
  75. }
  76. }
  77. }
  78. int
  79. InitCircles(XParms xp, Parms p, int reps)
  80. {
  81. GenerateCircles(xp, p, False, False);
  82. return reps;
  83. }
  84. int
  85. InitPartCircles(XParms xp, Parms p, int reps)
  86. {
  87. GenerateCircles(xp, p, True, False);
  88. return reps;
  89. }
  90. int
  91. InitChordPartCircles(XParms xp, Parms p, int reps)
  92. {
  93. GenerateCircles(xp, p, True, False);
  94. XSetArcMode(xp->d, xp->bggc, ArcChord);
  95. XSetArcMode(xp->d, xp->fggc, ArcChord);
  96. return reps;
  97. }
  98. int
  99. InitSlicePartCircles(XParms xp, Parms p, int reps)
  100. {
  101. GenerateCircles(xp, p, True, False);
  102. XSetArcMode(xp->d, xp->bggc, ArcPieSlice);
  103. XSetArcMode(xp->d, xp->fggc, ArcPieSlice);
  104. return reps;
  105. }
  106. static void
  107. GenerateWideCircles(XParms xp, Parms p, Bool partialArcs, Bool ddashed)
  108. {
  109. int size;
  110. GenerateCircles(xp, p, partialArcs, ddashed);
  111. size = p->special;
  112. if(ddashed) {
  113. XSetLineAttributes(xp->d, xp->ddbggc, (int) ((size + 9) / 10),
  114. LineSolid, CapRound, JoinRound);
  115. XSetLineAttributes(xp->d, xp->ddfggc, (int) ((size + 9) / 10),
  116. LineSolid, CapRound, JoinRound);
  117. }
  118. else {
  119. XSetLineAttributes(xp->d, xp->bggc, (int) ((size + 9) / 10),
  120. LineSolid, CapRound, JoinRound);
  121. XSetLineAttributes(xp->d, xp->fggc, (int) ((size + 9) / 10),
  122. LineSolid, CapRound, JoinRound);
  123. }
  124. }
  125. int
  126. InitWideCircles(XParms xp, Parms p, int reps)
  127. {
  128. GenerateWideCircles (xp, p, False, False);
  129. return reps;
  130. }
  131. int
  132. InitPartWideCircles(XParms xp, Parms p, int reps)
  133. {
  134. GenerateWideCircles (xp, p, True, False);
  135. return reps;
  136. }
  137. int
  138. InitDashedCircles(XParms xp, Parms p, int reps)
  139. {
  140. char dashes[2];
  141. GenerateCircles(xp, p, False, False);
  142. /* Modify GCs to draw dashed */
  143. XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  144. XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  145. dashes[0] = 3; dashes[1] = 2;
  146. XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  147. XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  148. return reps;
  149. }
  150. int
  151. InitWideDashedCircles(XParms xp, Parms p, int reps)
  152. {
  153. int size;
  154. XGCValues gcv;
  155. char dashes[2];
  156. GenerateWideCircles(xp, p, False, False);
  157. size = p->special;
  158. size = (size + 9) / 10;
  159. /* Modify GCs to draw dashed */
  160. dashes[0] = 2*size; dashes[1] = 2*size;
  161. gcv.line_style = LineOnOffDash;
  162. XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  163. XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  164. XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  165. XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  166. return reps;
  167. }
  168. int
  169. InitDoubleDashedCircles(XParms xp, Parms p, int reps)
  170. {
  171. char dashes[2];
  172. GenerateCircles(xp, p, False, True);
  173. /* Modify GCs to draw dashed */
  174. XSetLineAttributes(xp->d, xp->ddbggc, 0, LineDoubleDash, CapButt, JoinMiter);
  175. XSetLineAttributes(xp->d, xp->ddfggc, 0, LineDoubleDash, CapButt, JoinMiter);
  176. dashes[0] = 3; dashes[1] = 2;
  177. XSetDashes(xp->d, xp->ddfggc, 0, dashes, 2);
  178. XSetDashes(xp->d, xp->ddbggc, 0, dashes, 2);
  179. return reps;
  180. }
  181. int
  182. InitWideDoubleDashedCircles(XParms xp, Parms p, int reps)
  183. {
  184. int size;
  185. XGCValues gcv;
  186. char dashes[2];
  187. GenerateWideCircles(xp, p, False, True);
  188. size = p->special;
  189. size = (size + 9) / 10;
  190. /* Modify GCs to draw dashed */
  191. dashes[0] = 2*size; dashes[1] = 2*size;
  192. gcv.line_style = LineDoubleDash;
  193. XChangeGC(xp->d, xp->ddfggc, GCLineStyle, &gcv);
  194. XChangeGC(xp->d, xp->ddbggc, GCLineStyle, &gcv);
  195. XSetDashes(xp->d, xp->ddfggc, 0, dashes, 2);
  196. XSetDashes(xp->d, xp->ddbggc, 0, dashes, 2);
  197. return reps;
  198. }
  199. static void
  200. GenerateEllipses(XParms xp, Parms p, int partialArcs, Bool ddashed)
  201. {
  202. int size;
  203. int half;
  204. int rows; /* Number of rows filled in current column */
  205. int i;
  206. int x, y; /* base of square to draw ellipse in */
  207. int vsize, vsizeinc;
  208. int dir;
  209. int startAngle, arcAngle;
  210. if(ddashed)
  211. pgc = xp->ddfggc;
  212. else
  213. pgc = xp->fggc;
  214. size = p->special;
  215. half = (size + 19) / 20;
  216. arcs = (XArc *)malloc((p->objects) * sizeof(XArc));
  217. vsize = 1;
  218. vsizeinc = (size - 1) / (p->objects - 1);
  219. if (vsizeinc == 0) vsizeinc = 1;
  220. x = half; y = half;
  221. dir = 0;
  222. rows = 0;
  223. startAngle = DegreesToX(0);
  224. arcAngle = DegreesToX(360);
  225. for (i = 0; i != p->objects; i++) {
  226. arcs[i].x = x;
  227. arcs[i].y = y;
  228. if ((i & 1) ^ dir) {
  229. /* Make vertical axis longer */
  230. arcs[i].width = vsize;
  231. arcs[i].height = size;
  232. } else {
  233. /* Make horizontal axis longer */
  234. arcs[i].width = size;
  235. arcs[i].height = vsize;
  236. }
  237. arcs[i].angle1 = startAngle;
  238. arcs[i].angle2 = arcAngle;
  239. if (partialArcs) {
  240. startAngle += DegreesToX(30);
  241. if (startAngle >= DegreesToX(360)) startAngle -= DegreesToX(360);
  242. arcAngle -= DegreesToX(20);
  243. if (arcAngle <= DegreesToX(0)) arcAngle += DegreesToX(360);
  244. }
  245. y += size + 1;
  246. rows++;
  247. if (y >= HEIGHT - size - half || rows == MAXROWS) {
  248. /* Go to next column */
  249. rows = 0;
  250. y = half;
  251. x += size + 1;
  252. if (x >= WIDTH - size - half) {
  253. x = half;
  254. }
  255. }
  256. vsize += vsizeinc;
  257. if (vsize > size) {
  258. vsize -= size;
  259. dir = 1 - dir;
  260. }
  261. }
  262. }
  263. int
  264. InitEllipses(XParms xp, Parms p, int reps)
  265. {
  266. GenerateEllipses(xp, p, False, False);
  267. return reps;
  268. }
  269. int
  270. InitPartEllipses(XParms xp, Parms p, int reps)
  271. {
  272. GenerateEllipses(xp, p, True, False);
  273. return reps;
  274. }
  275. int
  276. InitChordPartEllipses(XParms xp, Parms p, int reps)
  277. {
  278. GenerateEllipses(xp, p, True, False);
  279. XSetArcMode(xp->d, xp->bggc, ArcChord);
  280. XSetArcMode(xp->d, xp->fggc, ArcChord);
  281. return reps;
  282. }
  283. int
  284. InitSlicePartEllipses(XParms xp, Parms p, int reps)
  285. {
  286. GenerateEllipses(xp, p, True, False);
  287. XSetArcMode(xp->d, xp->bggc, ArcPieSlice);
  288. XSetArcMode(xp->d, xp->fggc, ArcPieSlice);
  289. return reps;
  290. }
  291. static void
  292. GenerateWideEllipses(XParms xp, Parms p, Bool partialArcs, Bool ddashed)
  293. {
  294. int size;
  295. GenerateEllipses (xp, p, partialArcs, ddashed);
  296. size = p->special;
  297. if(ddashed) {
  298. XSetLineAttributes(xp->d, xp->ddbggc, (int) ((size + 9) / 10),
  299. LineSolid, CapRound, JoinRound);
  300. XSetLineAttributes(xp->d, xp->ddfggc, (int) ((size + 9) / 10),
  301. LineSolid, CapRound, JoinRound);
  302. }
  303. else {
  304. XSetLineAttributes(xp->d, xp->bggc, (int) ((size + 9) / 10),
  305. LineSolid, CapRound, JoinRound);
  306. XSetLineAttributes(xp->d, xp->fggc, (int) ((size + 9) / 10),
  307. LineSolid, CapRound, JoinRound);
  308. }
  309. }
  310. int
  311. InitWideEllipses(XParms xp, Parms p, int reps)
  312. {
  313. GenerateWideEllipses(xp, p, False, False);
  314. return reps;
  315. }
  316. int
  317. InitPartWideEllipses(XParms xp, Parms p, int reps)
  318. {
  319. GenerateWideEllipses(xp, p, True, False);
  320. return reps;
  321. }
  322. int
  323. InitDashedEllipses(XParms xp, Parms p, int reps)
  324. {
  325. char dashes[2];
  326. GenerateEllipses(xp, p, False, False);
  327. /* Modify GCs to draw dashed */
  328. XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  329. XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  330. dashes[0] = 3; dashes[1] = 2;
  331. XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  332. XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  333. return reps;
  334. }
  335. int
  336. InitWideDashedEllipses(XParms xp, Parms p, int reps)
  337. {
  338. int size;
  339. XGCValues gcv;
  340. char dashes[2];
  341. GenerateWideEllipses(xp, p, False, False);
  342. size = p->special;
  343. size = (size + 9) / 10;
  344. /* Modify GCs to draw dashed */
  345. dashes[0] = 2*size; dashes[1] = 2*size;
  346. gcv.line_style = LineOnOffDash;
  347. XChangeGC(xp->d, xp->fggc, GCLineStyle, &gcv);
  348. XChangeGC(xp->d, xp->bggc, GCLineStyle, &gcv);
  349. XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  350. XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  351. return reps;
  352. }
  353. int
  354. InitDoubleDashedEllipses(XParms xp, Parms p, int reps)
  355. {
  356. char dashes[2];
  357. GenerateEllipses(xp, p, False, True);
  358. /* Modify GCs to draw dashed */
  359. XSetLineAttributes(xp->d, xp->ddbggc, 0, LineDoubleDash, CapButt, JoinMiter);
  360. XSetLineAttributes(xp->d, xp->ddfggc, 0, LineDoubleDash, CapButt, JoinMiter);
  361. dashes[0] = 3; dashes[1] = 2;
  362. XSetDashes(xp->d, xp->ddfggc, 0, dashes, 2);
  363. XSetDashes(xp->d, xp->ddbggc, 0, dashes, 2);
  364. return reps;
  365. }
  366. int
  367. InitWideDoubleDashedEllipses(XParms xp, Parms p, int reps)
  368. {
  369. int size;
  370. XGCValues gcv;
  371. char dashes[2];
  372. GenerateWideEllipses(xp, p, False, True);
  373. size = p->special;
  374. size = (size + 9) / 10;
  375. /* Modify GCs to draw dashed */
  376. dashes[0] = 2*size; dashes[1] = 2*size;
  377. gcv.line_style = LineDoubleDash;
  378. XChangeGC(xp->d, xp->ddfggc, GCLineStyle, &gcv);
  379. XChangeGC(xp->d, xp->ddbggc, GCLineStyle, &gcv);
  380. XSetDashes(xp->d, xp->ddfggc, 0, dashes, 2);
  381. XSetDashes(xp->d, xp->ddbggc, 0, dashes, 2);
  382. return reps;
  383. }
  384. void
  385. DoArcs(XParms xp, Parms p, int reps)
  386. {
  387. int i;
  388. for (i = 0; i != reps; i++) {
  389. XDrawArcs(xp->d, xp->w, pgc, arcs, p->objects);
  390. if (pgc == xp->ddbggc)
  391. pgc = xp->ddfggc;
  392. else if(pgc == xp->ddfggc)
  393. pgc = xp->ddbggc;
  394. else if (pgc == xp->bggc)
  395. pgc = xp->fggc;
  396. else
  397. pgc = xp->bggc;
  398. CheckAbort ();
  399. }
  400. }
  401. void
  402. DoFilledArcs(XParms xp, Parms p, int reps)
  403. {
  404. int i;
  405. for (i = 0; i != reps; i++) {
  406. XFillArcs(xp->d, xp->w, pgc, arcs, p->objects);
  407. if (pgc == xp->ddbggc)
  408. pgc = xp->ddfggc;
  409. else if(pgc == xp->ddfggc)
  410. pgc = xp->ddbggc;
  411. else if (pgc == xp->bggc)
  412. pgc = xp->fggc;
  413. else
  414. pgc = xp->bggc;
  415. CheckAbort ();
  416. }
  417. }
  418. void
  419. EndArcs(XParms xp, Parms p)
  420. {
  421. free(arcs);
  422. }