/alliance-5.0/xvpn/src/XMX_cursor.c

https://github.com/clothbot/Alliance-VLSI-CAD-System · C · 514 lines · 300 code · 102 blank · 112 comment · 45 complexity · 8eb2fd501735495d2be1a3267830e5db MD5 · raw file

  1. /*------------------------------------------------------------\
  2. | |
  3. | This file is part of the Alliance CAD System Copyright |
  4. | (C) Laboratoire LIP6 - Département ASIM Universite P&M Curie|
  5. | |
  6. | Home page : http://www-asim.lip6.fr/alliance/ |
  7. | E-mail : mailto:alliance-users@asim.lip6.fr |
  8. | |
  9. | This progam is free software; you can redistribute it |
  10. | and/or modify it under the terms of the GNU General Public |
  11. | License as published by the Free Software Foundation; |
  12. | either version 2 of the License, or (at your option) any |
  13. | later version. |
  14. | |
  15. | Alliance VLSI CAD System is distributed in the hope that |
  16. | it will be useful, but WITHOUT ANY WARRANTY; |
  17. | without even the implied warranty of MERCHANTABILITY or |
  18. | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
  19. | Public License for more details. |
  20. | |
  21. | You should have received a copy of the GNU General Public |
  22. | License along with the GNU C Library; see the file COPYING. |
  23. | If not, write to the Free Software Foundation, Inc., |
  24. | 675 Mass Ave, Cambridge, MA 02139, USA. |
  25. | |
  26. \------------------------------------------------------------*/
  27. /*------------------------------------------------------------\
  28. | |
  29. | Tool : XVPN |
  30. | |
  31. | File : Cursor.c |
  32. | |
  33. | Authors : Jacomme Ludovic |
  34. | |
  35. | Date : 04.12.96 |
  36. | |
  37. \------------------------------------------------------------*/
  38. /*------------------------------------------------------------\
  39. | |
  40. | Include Files |
  41. | |
  42. \------------------------------------------------------------*/
  43. # include <stdio.h>
  44. # include <X11/Intrinsic.h>
  45. # include <X11/StringDefs.h>
  46. # include <Xm/Xm.h>
  47. # include "mut.h"
  48. # include "aut.h"
  49. # include "XSB.h"
  50. # include "XMX.h"
  51. # include "XMX_grid.h"
  52. # include "XMX_cursor.h"
  53. /*------------------------------------------------------------\
  54. | |
  55. | Constants |
  56. | |
  57. \------------------------------------------------------------*/
  58. /*------------------------------------------------------------\
  59. | |
  60. | Types |
  61. | |
  62. \------------------------------------------------------------*/
  63. /*------------------------------------------------------------\
  64. | |
  65. | Variables |
  66. | |
  67. \------------------------------------------------------------*/
  68. /*------------------------------------------------------------\
  69. | |
  70. | Buffer |
  71. | |
  72. \------------------------------------------------------------*/
  73. static char XvpnCursorBuffer[ XVPN_MAX_CURSOR_BUFFER ];
  74. /*------------------------------------------------------------\
  75. | |
  76. | Coordinates |
  77. | |
  78. \------------------------------------------------------------*/
  79. Position XvpnCursorX = 0;
  80. Position XvpnCursorY = 0;
  81. Position XvpnCursorSaveX = 0;
  82. Position XvpnCursorSaveY = 0;
  83. short XvpnCursorSaved = XVPN_FALSE;
  84. short XvpnCursorInside = XVPN_FALSE;
  85. short XvpnCursorType = XVPN_INPUT_HALF_BOX;
  86. long XvpnUnitCursorX = 0;
  87. long XvpnUnitCursorY = 0;
  88. long XvpnPixelCursorX = 0;
  89. long XvpnPixelCursorY = 0;
  90. long XvpnUnitCursorSaveX[ 2 ] = { 0, 0 };
  91. long XvpnUnitCursorSaveY[ 2 ] = { 0, 0 };
  92. short XvpnCursorIndex = 0;
  93. /*------------------------------------------------------------\
  94. | |
  95. | Functions |
  96. | |
  97. \------------------------------------------------------------*/
  98. /*------------------------------------------------------------\
  99. | |
  100. | XvpnComputeCursor |
  101. | |
  102. \------------------------------------------------------------*/
  103. void XvpnComputeCursor( X, Y )
  104. Position X;
  105. Position Y;
  106. {
  107. autbegin();
  108. Y = XvpnGraphicDy - Y;
  109. XvpnUnitCursorX = X + XvpnPixelGridX;
  110. XvpnUnitCursorY = Y + XvpnPixelGridY;
  111. if ( XvpnUnitCursorX < 0 )
  112. {
  113. XvpnUnitCursorX = ((float)(XvpnUnitCursorX) / XvpnUnitGridStep) - 0.5 ;
  114. }
  115. else
  116. {
  117. XvpnUnitCursorX = ((float)(XvpnUnitCursorX) / XvpnUnitGridStep) + 0.5 ;
  118. }
  119. if ( XvpnUnitCursorY < 0 )
  120. {
  121. XvpnUnitCursorY = ((float)(XvpnUnitCursorY) / XvpnUnitGridStep) - 0.5 ;
  122. }
  123. else
  124. {
  125. XvpnUnitCursorY = ((float)(XvpnUnitCursorY) / XvpnUnitGridStep) + 0.5 ;
  126. }
  127. XvpnPixelCursorX = ((float)(XvpnUnitCursorX) * XvpnUnitGridStep);
  128. XvpnPixelCursorY = ((float)(XvpnUnitCursorY) * XvpnUnitGridStep);
  129. XvpnCursorX = XvpnPixelCursorX - XvpnPixelGridX;
  130. XvpnCursorY = XvpnPixelCursorY - XvpnPixelGridY;
  131. XvpnCursorY = XvpnGraphicDy - XvpnCursorY;
  132. autend();
  133. }
  134. /*------------------------------------------------------------\
  135. | |
  136. | XvpnDisplayCoordinates |
  137. | |
  138. \------------------------------------------------------------*/
  139. void XvpnDisplayCoordinates()
  140. {
  141. autbegin();
  142. sprintf( XvpnCursorBuffer, "%ld", XvpnUnitCursorX );
  143. XvpnDisplayMessage( XVPN_MESSAGE_X, XvpnCursorBuffer );
  144. sprintf( XvpnCursorBuffer, "%ld", XvpnUnitCursorY );
  145. XvpnDisplayMessage( XVPN_MESSAGE_Y, XvpnCursorBuffer );
  146. sprintf( XvpnCursorBuffer, "%ld", XvpnUnitCursorX - XvpnUnitCursorSaveX[0] );
  147. XvpnDisplayMessage( XVPN_MESSAGE_DX, XvpnCursorBuffer );
  148. sprintf( XvpnCursorBuffer, "%ld", XvpnUnitCursorY - XvpnUnitCursorSaveY[0] );
  149. XvpnDisplayMessage( XVPN_MESSAGE_DY, XvpnCursorBuffer );
  150. autend();
  151. }
  152. /*------------------------------------------------------------\
  153. | |
  154. | XvpnPointCursor |
  155. | |
  156. \------------------------------------------------------------*/
  157. void XvpnPointCursor()
  158. {
  159. autbegin();
  160. XvpnUndisplayCursor();
  161. XvpnUnitCursorSaveX[ XvpnCursorIndex ] = XvpnUnitCursorX;
  162. XvpnUnitCursorSaveY[ XvpnCursorIndex ] = XvpnUnitCursorY;
  163. XvpnCursorIndex = XvpnCursorIndex + 1;
  164. XvpnDisplayCursor();
  165. autend();
  166. }
  167. /*------------------------------------------------------------\
  168. | |
  169. | XvpnResetCursor |
  170. | |
  171. \------------------------------------------------------------*/
  172. void XvpnResetCursor()
  173. {
  174. autbegin();
  175. XvpnUndisplayCursor();
  176. XvpnCursorIndex = XvpnCursorIndex - 1;
  177. XvpnDisplayCursor();
  178. autend();
  179. }
  180. /*------------------------------------------------------------\
  181. | |
  182. | XvpnChangeCursor |
  183. | |
  184. \------------------------------------------------------------*/
  185. void XvpnChangeCursorType( ArrayX, ArrayY, Index, Type )
  186. long *ArrayX;
  187. long *ArrayY;
  188. short Index;
  189. short Type;
  190. {
  191. autbegin();
  192. XvpnUndisplayCursor();
  193. XvpnCursorType = Type;
  194. XvpnCursorIndex = Index;
  195. if ( Index != 0 )
  196. {
  197. XvpnUnitCursorSaveX[ 0 ] = ArrayX[0];
  198. XvpnUnitCursorSaveY[ 0 ] = ArrayY[0];
  199. XvpnUnitCursorSaveX[ 1 ] = ArrayX[1];
  200. XvpnUnitCursorSaveY[ 1 ] = ArrayY[1];
  201. }
  202. XvpnDisplayCursor();
  203. autend();
  204. }
  205. /*------------------------------------------------------------\
  206. | |
  207. | XvpnDrawCursor |
  208. | |
  209. \------------------------------------------------------------*/
  210. void XvpnDrawCursor()
  211. {
  212. long X1;
  213. long Y1;
  214. long X2;
  215. long Y2;
  216. long DeltaX;
  217. long DeltaY;
  218. long Swap;
  219. short DrawLine;
  220. autbegin();
  221. XDrawLine( XvpnGraphicDisplay,
  222. XtWindow( XvpnGraphicWindow ),
  223. XvpnXorGC,
  224. XvpnCursorSaveX - XVPN_CURSOR_SIZE,
  225. XvpnCursorSaveY - XVPN_CURSOR_SIZE,
  226. XvpnCursorSaveX + XVPN_CURSOR_SIZE,
  227. XvpnCursorSaveY + XVPN_CURSOR_SIZE );
  228. XDrawLine( XvpnGraphicDisplay,
  229. XtWindow( XvpnGraphicWindow ),
  230. XvpnXorGC,
  231. XvpnCursorSaveX - XVPN_CURSOR_SIZE,
  232. XvpnCursorSaveY + XVPN_CURSOR_SIZE,
  233. XvpnCursorSaveX + XVPN_CURSOR_SIZE,
  234. XvpnCursorSaveY - XVPN_CURSOR_SIZE );
  235. if ( XvpnCursorIndex > 0 )
  236. {
  237. X1 = (float)(XvpnUnitCursorSaveX[0]) * XvpnUnitGridStep;
  238. Y1 = (float)(XvpnUnitCursorSaveY[0]) * XvpnUnitGridStep;
  239. X1 = X1 - XvpnPixelGridX;
  240. Y1 = Y1 - XvpnPixelGridY;
  241. Y1 = XvpnGraphicDy - Y1;
  242. if ( XvpnCursorIndex == 1 )
  243. {
  244. X2 = XvpnCursorSaveX;
  245. Y2 = XvpnCursorSaveY;
  246. }
  247. else
  248. {
  249. X2 = (float)(XvpnUnitCursorSaveX[1]) * XvpnUnitGridStep;
  250. Y2 = (float)(XvpnUnitCursorSaveY[1]) * XvpnUnitGridStep;
  251. X2 = X2 - XvpnPixelGridX;
  252. Y2 = Y2 - XvpnPixelGridY;
  253. Y2 = XvpnGraphicDy - Y2;
  254. }
  255. switch( XvpnCursorType )
  256. {
  257. case XVPN_INPUT_POINT :
  258. break;
  259. case XVPN_INPUT_LINE :
  260. XDrawLine( XvpnGraphicDisplay,
  261. XtWindow( XvpnGraphicWindow ),
  262. XvpnXorGC,
  263. X1, Y1, X2, Y2 );
  264. break;
  265. case XVPN_INPUT_HALF_BOX :
  266. XDrawLine( XvpnGraphicDisplay,
  267. XtWindow( XvpnGraphicWindow ),
  268. XvpnXorGC,
  269. X1, Y1, X2, Y1 );
  270. XDrawLine( XvpnGraphicDisplay,
  271. XtWindow( XvpnGraphicWindow ),
  272. XvpnXorGC,
  273. X2, Y1, X2, Y2 );
  274. break;
  275. case XVPN_INPUT_ORTHO :
  276. case XVPN_INPUT_SORTHO :
  277. case XVPN_INPUT_LSTRING :
  278. DeltaX = X2 - X1; if ( DeltaX < 0 ) DeltaX = - DeltaX;
  279. DeltaY = Y2 - Y1; if ( DeltaY < 0 ) DeltaY = - DeltaY;
  280. if ( DeltaX > DeltaY )
  281. {
  282. Y2 = Y1;
  283. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  284. if ( X1 < 0 ) X1 = 0;
  285. if ( X2 > XvpnGraphicDx ) X2 = XvpnGraphicDx;
  286. if ( ( X1 < X2 ) &&
  287. ( Y1 >= 0 ) &&
  288. ( Y1 <= XvpnGraphicDy ) )
  289. {
  290. XDrawLine( XvpnGraphicDisplay,
  291. XtWindow( XvpnGraphicWindow ),
  292. XvpnXorGC,
  293. X1, Y1, X2, Y2 );
  294. }
  295. }
  296. else
  297. {
  298. X2 = X1;
  299. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  300. if ( Y1 < 0 ) Y1 = 0;
  301. if ( Y2 > XvpnGraphicDy ) Y2 = XvpnGraphicDy;
  302. if ( ( Y1 < Y2 ) &&
  303. ( X1 >= 0 ) &&
  304. ( X1 <= XvpnGraphicDx ) )
  305. {
  306. XDrawLine( XvpnGraphicDisplay,
  307. XtWindow( XvpnGraphicWindow ),
  308. XvpnXorGC,
  309. X1, Y1, X2, Y2 );
  310. }
  311. }
  312. break;
  313. case XVPN_INPUT_BOX :
  314. if ( X1 > X2 ) { Swap = X1; X1 = X2; X2 = Swap; }
  315. if ( Y1 > Y2 ) { Swap = Y1; Y1 = Y2; Y2 = Swap; }
  316. DrawLine = 0;
  317. if ( X1 < 0 ) { X1 = 0; DrawLine |= XVPN_WEST; }
  318. if ( X2 > XvpnGraphicDx ) { X2 = XvpnGraphicDx; DrawLine |= XVPN_EAST; }
  319. if ( Y1 < 0 ) { Y1 = 0; DrawLine |= XVPN_SOUTH; }
  320. if ( Y2 > XvpnGraphicDy ) { Y2 = XvpnGraphicDy; DrawLine |= XVPN_NORTH; }
  321. if ( DrawLine == 0 )
  322. {
  323. XDrawRectangle( XvpnGraphicDisplay,
  324. XtWindow( XvpnGraphicWindow ),
  325. XvpnXorGC,
  326. X1, Y1,
  327. X2 - X1, Y2 - Y1 );
  328. }
  329. else
  330. {
  331. if ( ( DrawLine & XVPN_WEST ) == 0 )
  332. {
  333. XDrawLine( XvpnGraphicDisplay,
  334. XtWindow( XvpnGraphicWindow ),
  335. XvpnXorGC,
  336. X1, Y2,
  337. X1, Y1 );
  338. }
  339. if ( ( DrawLine & XVPN_EAST ) == 0 )
  340. {
  341. XDrawLine( XvpnGraphicDisplay,
  342. XtWindow( XvpnGraphicWindow ),
  343. XvpnXorGC,
  344. X2, Y2,
  345. X2, Y1 );
  346. }
  347. if ( ( DrawLine & XVPN_SOUTH ) == 0 )
  348. {
  349. XDrawLine( XvpnGraphicDisplay,
  350. XtWindow( XvpnGraphicWindow ),
  351. XvpnXorGC,
  352. X1, Y1,
  353. X2, Y1 );
  354. }
  355. if ( ( DrawLine & XVPN_NORTH ) == 0 )
  356. {
  357. XDrawLine( XvpnGraphicDisplay,
  358. XtWindow( XvpnGraphicWindow ),
  359. XvpnXorGC,
  360. X1, Y2,
  361. X2, Y2 );
  362. }
  363. }
  364. break;
  365. }
  366. }
  367. autend();
  368. }
  369. /*------------------------------------------------------------\
  370. | |
  371. | XvpnUndisplayCursor |
  372. | |
  373. \------------------------------------------------------------*/
  374. void XvpnUndisplayCursor()
  375. {
  376. autbegin();
  377. if ( XvpnCursorInside == XVPN_TRUE )
  378. {
  379. if ( XvpnCursorSaved == XVPN_TRUE )
  380. {
  381. XvpnDrawCursor();
  382. }
  383. XvpnCursorSaved = XVPN_FALSE;
  384. }
  385. autend();
  386. }
  387. /*------------------------------------------------------------\
  388. | |
  389. | XvpnDisplayCursor |
  390. | |
  391. \------------------------------------------------------------*/
  392. void XvpnDisplayCursor()
  393. {
  394. autbegin();
  395. if ( XvpnCursorInside == XVPN_TRUE )
  396. {
  397. if ( XvpnCursorSaved == XVPN_TRUE )
  398. {
  399. XvpnDrawCursor();
  400. XvpnCursorSaved = XVPN_FALSE;
  401. }
  402. if ( ( XvpnCursorY >= 0 ) &&
  403. ( XvpnCursorX <= (Position)XvpnGraphicDx ) )
  404. {
  405. XvpnCursorSaveX = XvpnCursorX;
  406. XvpnCursorSaveY = XvpnCursorY;
  407. XvpnDrawCursor();
  408. XvpnCursorSaved = XVPN_TRUE;
  409. }
  410. }
  411. autend();
  412. }