PageRenderTime 28ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/SN-NG4/tix/unix/tixUnixDraw.c

https://gitlab.com/OpenSourceMirror/sourcenav
C | 307 lines | 196 code | 18 blank | 93 comment | 16 complexity | e20b74f0b898c0677361fc723d2be07a MD5 | raw file
  1. /*
  2. * tixUnixDraw.c --
  3. *
  4. * Implement the Unix specific function calls for drawing.
  5. *
  6. * Copyright (c) 1996, Expert Interface Technologies
  7. *
  8. * See the file "license.terms" for information on usage and redistribution
  9. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10. *
  11. */
  12. #include <tixPort.h>
  13. #include <tixUnixInt.h>
  14. /*
  15. *----------------------------------------------------------------------
  16. * TixpDrawTmpLine --
  17. *
  18. * Draws a "temporary" line between the two points. The line can be
  19. * removed by calling the function again with the same parameters.
  20. *
  21. * Results:
  22. * Standard Tcl result.
  23. *
  24. * Side effects:
  25. * A line is XOR'ed onto the screen.
  26. *----------------------------------------------------------------------
  27. */
  28. void
  29. TixpDrawTmpLine(x1, y1, x2, y2, tkwin)
  30. int x1;
  31. int y1;
  32. int x2;
  33. int y2;
  34. Tk_Window tkwin;
  35. {
  36. GC gc;
  37. XGCValues values;
  38. unsigned long valuemask = GCForeground | GCSubwindowMode | GCFunction;
  39. Window winId; /* The Window to draw into. */
  40. Tk_Window toplevel; /* Toplevel containing the tkwin. */
  41. int rootx1, rooty1; /* Root x and y of the toplevel window. */
  42. int rootx2, rooty2;
  43. for (toplevel=tkwin; !Tk_IsTopLevel(toplevel);
  44. toplevel=Tk_Parent(toplevel)) {
  45. ;
  46. }
  47. Tk_GetRootCoords(toplevel, &rootx1, &rooty1);
  48. rootx2 = rootx1 + Tk_Width(toplevel) - 1;
  49. rooty2 = rooty1 + Tk_Height(toplevel) - 1;
  50. if (x1 >= rootx1 && x2 <= rootx2 && y1 >= rooty1 && y2 <= rooty2) {
  51. /*
  52. * The line is completely inside the toplevel containing
  53. * tkwin. It's better to draw into this window because on some
  54. * X servers, especially PC X Servers running on Windows,
  55. * drawing into the root window shows no effect.
  56. */
  57. winId = Tk_WindowId(toplevel);
  58. x1 -= rootx1;
  59. y1 -= rooty1;
  60. x2 -= rootx1;
  61. y2 -= rooty1;
  62. } else {
  63. winId = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
  64. }
  65. values.foreground = 0xff;
  66. values.subwindow_mode = IncludeInferiors;
  67. values.function = GXxor;
  68. gc = XCreateGC(Tk_Display(tkwin), winId, valuemask, &values);
  69. XDrawLine(Tk_Display(tkwin), winId, gc, x1, y1, x2, y2);
  70. XFreeGC(Tk_Display(tkwin), gc);
  71. }
  72. /*----------------------------------------------------------------------
  73. * TixpDrawAnchorLines --
  74. *
  75. * See comments near Tix_DrawAnchorLines.
  76. *----------------------------------------------------------------------
  77. */
  78. void TixpDrawAnchorLines(display, drawable, gc, x, y, w, h)
  79. Display *display;
  80. Drawable drawable;
  81. GC gc;
  82. int x;
  83. int y;
  84. int w;
  85. int h;
  86. {
  87. XPoint points[4];
  88. if (w < 1) {
  89. w = 1;
  90. }
  91. if (h < 1) {
  92. h = 1;
  93. }
  94. XDrawRectangle(display, drawable, gc, x, y, w-1, h-1);
  95. /*
  96. * Draw these points so that the corners will not be rounded
  97. */
  98. points[0].x = x;
  99. points[0].y = y;
  100. points[1].x = x + w - 1;
  101. points[1].y = y;
  102. points[2].x = x;
  103. points[2].y = y + h - 1;
  104. points[3].x = x + w - 1;
  105. points[3].y = y + h - 1;
  106. XDrawPoints(display, drawable, gc, points, 4, CoordModeOrigin);
  107. }
  108. /*----------------------------------------------------------------------
  109. * TixpStartSubRegionDraw --
  110. *
  111. * Limits the subsequent drawing operations into the prescribed
  112. * rectangle region. This takes effect up to a matching
  113. * TixEndSubRegionDraw() call.
  114. *
  115. * Return value:
  116. * none.
  117. *----------------------------------------------------------------------
  118. */
  119. void
  120. TixpStartSubRegionDraw(display, drawable, gc, subRegPtr, origX, origY,
  121. x, y, width, height, needWidth, needHeight)
  122. Display *display;
  123. Drawable drawable;
  124. GC gc;
  125. TixpSubRegion * subRegPtr;
  126. int origX;
  127. int origY;
  128. int x;
  129. int y;
  130. int width;
  131. int height;
  132. int needWidth;
  133. int needHeight;
  134. {
  135. if ((width < needWidth) || (height < needHeight)) {
  136. subRegPtr->rectUsed = 1;
  137. subRegPtr->rect.x = (short)x;
  138. subRegPtr->rect.y = (short)y;
  139. subRegPtr->rect.width = (short)width;
  140. subRegPtr->rect.height = (short)height;
  141. XSetClipRectangles(display, gc, origX, origY, &subRegPtr->rect,
  142. 1, Unsorted);
  143. } else {
  144. subRegPtr->rectUsed = 0;
  145. }
  146. }
  147. /*----------------------------------------------------------------------
  148. * TixpEndSubRegionDraw --
  149. *
  150. *
  151. *----------------------------------------------------------------------
  152. */
  153. void
  154. TixpEndSubRegionDraw(display, drawable, gc, subRegPtr)
  155. Display *display;
  156. Drawable drawable;
  157. GC gc;
  158. TixpSubRegion * subRegPtr;
  159. {
  160. if (subRegPtr->rectUsed) {
  161. subRegPtr->rect.x = (short)0;
  162. subRegPtr->rect.y = (short)0;
  163. subRegPtr->rect.width = (short)20000;
  164. subRegPtr->rect.height = (short)20000;
  165. XSetClipRectangles(display, gc, 0, 0, &subRegPtr->rect, 1, Unsorted);
  166. }
  167. }
  168. /*
  169. *----------------------------------------------------------------------
  170. *
  171. * TixpSubRegDisplayText --
  172. *
  173. * Display a text string on one or more lines in a sub region.
  174. *
  175. * Results:
  176. * See TkDisplayText
  177. *
  178. * Side effects:
  179. * See TkDisplayText
  180. *
  181. *----------------------------------------------------------------------
  182. */
  183. void
  184. TixpSubRegDisplayText(display, drawable, gc, subRegPtr, font, string,
  185. numChars, x, y, length, justify, underline)
  186. Display *display; /* X display to use for drawing text. */
  187. Drawable drawable; /* Window or pixmap in which to draw the
  188. * text. */
  189. GC gc; /* Graphics context to use for drawing text. */
  190. TixpSubRegion * subRegPtr; /* Information about the subregion */
  191. TixFont font; /* Font that determines geometry of text
  192. * (should be same as font in gc). */
  193. char *string; /* String to display; may contain embedded
  194. * newlines. */
  195. int numChars; /* Number of characters to use from string. */
  196. int x, y; /* Pixel coordinates within drawable of
  197. * upper left corner of display area. */
  198. int length; /* Line length in pixels; used to compute
  199. * word wrap points and also for
  200. * justification. Must be > 0. */
  201. Tk_Justify justify; /* How to justify lines. */
  202. int underline; /* Index of character to underline, or < 0
  203. * for no underlining. */
  204. {
  205. TixDisplayText(display, drawable, font, string,
  206. numChars, x, y, length, justify, underline, gc);
  207. }
  208. /*----------------------------------------------------------------------
  209. * TixpSubRegFillRectangle --
  210. *
  211. *
  212. *----------------------------------------------------------------------
  213. */
  214. void
  215. TixpSubRegFillRectangle(display, drawable, gc, subRegPtr, x, y, width, height)
  216. Display *display; /* X display to use for drawing rectangle. */
  217. Drawable drawable; /* Window or pixmap in which to draw the
  218. * rectangle. */
  219. GC gc; /* Graphics context to use for drawing. */
  220. TixpSubRegion * subRegPtr; /* Information about the subregion */
  221. int x, y; /* Pixel coordinates within drawable of
  222. * upper left corner of display area. */
  223. int width, height; /* Size of the rectangle. */
  224. {
  225. XFillRectangle(display, drawable, gc, x, y, width, height);
  226. }
  227. /*----------------------------------------------------------------------
  228. * TixpSubRegDrawImage --
  229. *
  230. * Draws a Tk image in a subregion.
  231. *----------------------------------------------------------------------
  232. */
  233. void
  234. TixpSubRegDrawImage(subRegPtr, image, imageX, imageY, width, height,
  235. drawable, drawableX, drawableY)
  236. TixpSubRegion * subRegPtr;
  237. Tk_Image image;
  238. int imageX;
  239. int imageY;
  240. int width;
  241. int height;
  242. Drawable drawable;
  243. int drawableX;
  244. int drawableY;
  245. {
  246. if (subRegPtr->rectUsed) {
  247. if (drawableX < subRegPtr->rect.x) {
  248. width -= subRegPtr->rect.x - drawableX;
  249. imageX += subRegPtr->rect.x - drawableX;
  250. drawableX = subRegPtr->rect.x;
  251. }
  252. if (drawableX + width > subRegPtr->rect.x + subRegPtr->rect.width) {
  253. width = subRegPtr->rect.x - drawableX + subRegPtr->rect.width;
  254. }
  255. if (drawableY < subRegPtr->rect.y) {
  256. height -= subRegPtr->rect.y - drawableY;
  257. imageY += subRegPtr->rect.y - drawableY;
  258. drawableY = subRegPtr->rect.y;
  259. }
  260. if (drawableY + height > subRegPtr->rect.y + subRegPtr->rect.height) {
  261. height = subRegPtr->rect.y - drawableY + subRegPtr->rect.height;
  262. }
  263. }
  264. Tk_RedrawImage(image, imageX, imageY, width, height, drawable,
  265. drawableX, drawableY);
  266. }
  267. void
  268. TixpSubRegDrawBitmap(display, drawable, gc, subRegPtr, bitmap, src_x, src_y,
  269. width, height, dest_x, dest_y, plane)
  270. Display *display;
  271. Drawable drawable;
  272. GC gc;
  273. TixpSubRegion * subRegPtr;
  274. Pixmap bitmap;
  275. int src_x, src_y;
  276. int width, height;
  277. int dest_x, dest_y;
  278. unsigned long plane;
  279. {
  280. XCopyPlane(display, bitmap, drawable, gc, src_x, src_y, width, height,
  281. dest_x, dest_y, plane);
  282. }