/SRGP_DISTRIB/src/srgp/srgp_echo_X.c

https://gitlab.com/bratner/graphics · C · 339 lines · 209 code · 66 blank · 64 comment · 29 complexity · 884d00a0d63bf2e65659364d51150b3f MD5 · raw file

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3. /** INFORMATION ABOUT THE LOW-LEVEL ECHOING DRIVERS
  4. SRGP__initEchoModule ()
  5. Must be called once, during initialization.
  6. The echo-attribute globals must have already been given
  7. default initial values!
  8. SRGP__updateLocatorRubberAnchor ()
  9. Acesses current locator rubber anchor from globals.
  10. May be called whether rubber echo is active or not.
  11. SRGP__enableLocatorRubberEcho ()
  12. Accesses current locator measure info from global variables.
  13. May be called carelessly:
  14. 1) Will not re-enable if already enabled
  15. 2) Will refuse to enable echo for a device that is:
  16. A) not active currently, and
  17. B) not in a state for which echo is desired
  18. SRGP__updateLocatorRubberEcho ()
  19. Accesses current locator measure info from global variables.
  20. May be called carelessly:
  21. Will not update if device is currently disabled.
  22. SRGP__disableLocatorRubberEcho ()
  23. May be called carelessly:
  24. Will not re-disable if already disabled
  25. SRGP__updateLocatorCursorShape ()
  26. May be called whether or not the cursor echo is active.
  27. SRGP__enableLocatorCursorEcho ()
  28. SRGP__disableLocatorCursorEcho ()
  29. May be called carelessly.
  30. SRGP__updateRawCursorPosition ()
  31. Accesses cur_locator_measure from global variables.
  32. Informs the underlying graphics package of the desired "cursor warp".
  33. Automatically updates any type of locator echo: cursor or rubber.
  34. SRGP__updateKeyboardEchoAttributes ()
  35. May be called whether or not key echo is active.
  36. Obtains attributes from global variables.
  37. SRGP__enableKeyboardEcho ()
  38. SRGP__updateKeyboardEcho ()
  39. SRGP__disableKeyboardEcho ()
  40. Similar to above: may be called carelessly.
  41. **/
  42. /* FOR LOCATOR ECHO */
  43. static boolean locator_echo_is_active=FALSE;
  44. static GC echo__locator_gc;
  45. static Cursor echo__locator_cursor_shape;
  46. static point echo__locator_rubber_anchor, echo__locator_previous_position;
  47. /* IN X, not SRGP, COORDS */
  48. /* FOR KEYBOARD ECHO */
  49. static boolean keyboard_echo_is_active=FALSE;
  50. static GC echo__keyboard_gc;
  51. static XFontStruct *echo__keyboard_font;
  52. static int
  53. /* THE SCREEN LOCATION OF THE ECHO IN X's COORDINATE SYSTEM!
  54. */
  55. echo__keyboard_left, /* X */
  56. echo__keyboard_origin; /* Y */
  57. static XCharStruct echo__keyboard_overall;
  58. static int font_ascent, font_descent;
  59. void
  60. SRGP__initEchoModule ()
  61. {
  62. /* CREATE THE TWO GC's. */
  63. echo__keyboard_gc = XCreateGC (srgpx__display, srgpx__screenwin, 0L, NULL);
  64. echo__locator_gc = XCreateGC (srgpx__display, srgpx__screenwin, 0L, NULL);
  65. /* INITIALIZE KEYBOARD GC: font, color, origin */
  66. SRGP__updateKeyboardEchoAttributes ();
  67. /* DEFAULT LOCATOR-ECHO RUBBER ANCHOR (same as keyboard echo). */
  68. echo__locator_rubber_anchor =
  69. SRGP_defPoint(echo__keyboard_left, echo__keyboard_origin);
  70. /* INITIALIZE LOCATOR RUBBER-ECHO GC: write-mode XOR. */
  71. if (XWHITE == 0)
  72. XSetFunction (srgpx__display, echo__locator_gc, GXxor);
  73. else
  74. XSetFunction(srgpx__display, echo__locator_gc, GXequiv);
  75. XSetForeground (srgpx__display, echo__locator_gc, XBLACK);
  76. }
  77. static void
  78. ToggleRubberRect ()
  79. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  80. {
  81. int tlx, tly, width, height;
  82. if (echo__locator_rubber_anchor.x < echo__locator_previous_position.x) {
  83. tlx = echo__locator_rubber_anchor.x;
  84. width = echo__locator_previous_position.x - tlx + 1;
  85. }
  86. else {
  87. tlx = echo__locator_previous_position.x;
  88. width = echo__locator_rubber_anchor.x - tlx + 1;
  89. }
  90. if (echo__locator_rubber_anchor.y < echo__locator_previous_position.y) {
  91. tly = echo__locator_rubber_anchor.y;
  92. height = echo__locator_previous_position.y - tly + 1;
  93. }
  94. else {
  95. tly = echo__locator_previous_position.y;
  96. height = echo__locator_rubber_anchor.y - tly + 1;
  97. }
  98. XDrawRectangle (srgpx__display, srgpx__screenwin,
  99. echo__locator_gc,
  100. tlx,tly, width, height);
  101. }
  102. static void
  103. ToggleRubberLine()
  104. /* DRAWS BETWEEN rubber_anchor AND previous_position */
  105. {
  106. XDrawLine (srgpx__display, srgpx__screenwin,
  107. echo__locator_gc,
  108. ExplodePt(echo__locator_previous_position),
  109. ExplodePt(echo__locator_rubber_anchor));
  110. }
  111. static void
  112. ToggleRubberEcho()
  113. {
  114. if (srgp__cur_locator_echo_type == RUBBER_RECT)
  115. ToggleRubberRect();
  116. else
  117. ToggleRubberLine();
  118. }
  119. void
  120. SRGP__enableLocatorRubberEcho ()
  121. {
  122. if ( ! locator_echo_is_active)
  123. if (srgp__cur_mode[LOCATOR] != INACTIVE)
  124. if (srgp__cur_locator_echo_type > CURSOR) {
  125. echo__locator_previous_position =
  126. SRGP_defPoint
  127. (srgp__cur_locator_measure.position.x,
  128. SCREENFIXED(srgp__cur_locator_measure.position.y));
  129. echo__locator_rubber_anchor =
  130. SRGP_defPoint
  131. (srgp__cur_locator_echo_anchor.x,
  132. SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  133. locator_echo_is_active = TRUE;
  134. ToggleRubberEcho();
  135. }
  136. }
  137. void
  138. SRGP__disableLocatorRubberEcho()
  139. {
  140. if (locator_echo_is_active) {
  141. ToggleRubberEcho();
  142. locator_echo_is_active = FALSE;
  143. }
  144. }
  145. void
  146. SRGP__updateLocatorRubberEcho ()
  147. {
  148. if (locator_echo_is_active) {
  149. ToggleRubberEcho();
  150. echo__locator_previous_position =
  151. SRGP_defPoint (srgp__cur_Xcursor_x, srgp__cur_Xcursor_y);
  152. ToggleRubberEcho();
  153. }
  154. }
  155. void
  156. SRGP__updateLocatorRubberAnchor ()
  157. {
  158. if (locator_echo_is_active)
  159. ToggleRubberEcho();
  160. echo__locator_rubber_anchor =
  161. SRGP_defPoint
  162. (srgp__cur_locator_echo_anchor.x,
  163. SCREENFIXED(srgp__cur_locator_echo_anchor.y));
  164. if (locator_echo_is_active)
  165. ToggleRubberEcho();
  166. }
  167. void
  168. SRGP__enableLocatorCursorEcho ()
  169. {
  170. if (srgp__cur_mode[LOCATOR] != INACTIVE)
  171. if (srgp__cur_locator_echo_type == CURSOR) {
  172. XDefineCursor (srgpx__display, srgpx__screenwin,
  173. echo__locator_cursor_shape);
  174. }
  175. }
  176. void
  177. SRGP__disableLocatorCursorEcho ()
  178. {
  179. XUndefineCursor (srgpx__display, srgpx__screenwin);
  180. }
  181. void
  182. SRGP__updateLocatorCursorShape ()
  183. {
  184. echo__locator_cursor_shape = srgp__cursorTable[srgp__cur_cursor];
  185. SRGP__enableLocatorCursorEcho ();
  186. }
  187. /** KEYBOARD ECHO **/
  188. static void
  189. DrawText ()
  190. {
  191. int direction;
  192. XDrawImageString (srgpx__display, srgpx__screenwin, echo__keyboard_gc,
  193. echo__keyboard_left, echo__keyboard_origin,
  194. srgp__cur_keyboard_measure.buffer,
  195. srgp__cur_keyboard_measure_length);
  196. XTextExtents (echo__keyboard_font,
  197. srgp__cur_keyboard_measure.buffer,
  198. srgp__cur_keyboard_measure_length,
  199. &direction, &font_ascent, &font_descent,
  200. &echo__keyboard_overall);
  201. XFillRectangle (srgpx__display, srgpx__screenwin, echo__keyboard_gc,
  202. echo__keyboard_left + echo__keyboard_overall.width + 2,
  203. echo__keyboard_origin - font_ascent,
  204. 7, font_ascent + font_descent);
  205. }
  206. static void
  207. EraseText()
  208. {
  209. XClearArea (srgpx__display, srgpx__screenwin,
  210. echo__keyboard_left,
  211. echo__keyboard_origin - font_ascent,
  212. echo__keyboard_overall.width + 9,
  213. font_ascent + font_descent,
  214. FALSE);
  215. }
  216. void
  217. SRGP__enableKeyboardEcho ()
  218. {
  219. if ( ! keyboard_echo_is_active)
  220. if (srgp__cur_mode[KEYBOARD] != INACTIVE)
  221. if (srgp__cur_keyboard_processing_mode == EDIT) {
  222. keyboard_echo_is_active = TRUE;
  223. DrawText();
  224. }
  225. }
  226. void
  227. SRGP__disableKeyboardEcho ()
  228. {
  229. if (keyboard_echo_is_active) {
  230. EraseText();
  231. keyboard_echo_is_active = FALSE;
  232. }
  233. }
  234. void
  235. SRGP__updateKeyboardEcho ()
  236. {
  237. if (keyboard_echo_is_active) {
  238. EraseText();
  239. DrawText();
  240. }
  241. }
  242. void
  243. SRGP__updateKeyboardEchoAttributes ()
  244. {
  245. if (keyboard_echo_is_active) {
  246. EraseText();
  247. }
  248. echo__keyboard_left = srgp__cur_keyboard_echo_origin.x;
  249. echo__keyboard_origin = SCREENFIXED(srgp__cur_keyboard_echo_origin.y);
  250. XSetForeground (srgpx__display, echo__keyboard_gc,
  251. XCOLOR(COLORINDEX(srgp__cur_keyboard_echo_color)));
  252. XSetBackground (srgpx__display, echo__keyboard_gc,
  253. XCOLOR(COLORINDEX(SRGP_WHITE)));
  254. XSetFont (srgpx__display, echo__keyboard_gc,
  255. (echo__keyboard_font =
  256. srgp__fontTable[srgp__cur_keyboard_echo_font])->fid);
  257. if (keyboard_echo_is_active) {
  258. DrawText();
  259. }
  260. }