home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / EEDRW23S.ZIP / EEREDRAW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-12  |  9.6 KB  |  283 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams.                         *
  3. *                                         *
  4. * This module redraw/draw all structs.                         *
  5. *                                         *
  6. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Oct. 1989    *
  7. *****************************************************************************/
  8.  
  9. #include "Program.h"
  10. #include "EERedraw.h"
  11. #include "EEModify.h"
  12. #include "EEString.h"
  13.  
  14. static int CursorStartX, CursorStartY;
  15. static DrawGenericStruct *HighLightStruct = NULL;
  16. static DrawPolylineStruct *CrsrPolyline = NULL;
  17. static DrawConnectionStruct *CrsrConnection = NULL;
  18. static IntrCursorShapeStruct Cursor;
  19.  
  20. static void DrawPolylineCursor(int x, int y);
  21. static void DrawConnectionCursor(int x, int y);
  22.  
  23. /*****************************************************************************
  24. * Redraws only the active window which is assumed to be whole visible.         *
  25. *****************************************************************************/
  26. void SetHighLightStruct(DrawGenericStruct *HighLight)
  27. {
  28.     HighLightStruct = HighLight;
  29. }
  30.  
  31. /*****************************************************************************
  32. * Redraws only the active window which is assumed to be whole visible.         *
  33. *****************************************************************************/
  34. void RedrawActiveWindow(void)
  35. {
  36.     IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  37. }
  38.  
  39. /*****************************************************************************
  40. * Routine to redraw all windows defined.                     *
  41. *****************************************************************************/
  42. void RedrawAllWindows(void)
  43. {
  44.     IntrWndwRedrawAll();
  45. }
  46.  
  47. /*****************************************************************************
  48. * Routine to redraw list of structs.                         *
  49. * If the list is of DrawPickStruct types then the picked item are drawn.     *
  50. *****************************************************************************/
  51. void RedrawStructList(DrawGenericStruct *Structs, int DrawMode, int Color)
  52. {
  53.     while (Structs) {
  54.     if (Structs -> StructType == DRAW_PICK_ITEM_STRUCT_TYPE)
  55.         RedrawOneStruct(((DrawPickedStruct *) Structs) -> PickedStruct,
  56.                                   DrawMode, Color);
  57.     else
  58.         RedrawOneStruct(Structs, DrawMode, Color);
  59.  
  60.     Structs = Structs -> Pnext;
  61.     }
  62. }
  63.  
  64. /*****************************************************************************
  65. * Routine to redraw list of structs.                         *
  66. *****************************************************************************/
  67. void RedrawOneStruct(DrawGenericStruct *Struct, int DrawMode, int Color)
  68. {
  69.     if (HighLightStruct == Struct)
  70.     Color = EE_HIGHLIGHT_COLOR;
  71.  
  72.     switch (Struct -> StructType) {
  73.     case DRAW_POLYLINE_STRUCT_TYPE:
  74.         RedrawPolylineStruct((DrawPolylineStruct *) Struct, DrawMode,
  75.                                     Color);
  76.         break;
  77.     case DRAW_CONNECTION_STRUCT_TYPE:
  78.         RedrawConnectionStruct((DrawConnectionStruct *) Struct,
  79.                                   DrawMode, Color);
  80.         break;
  81.     case DRAW_TEXT_STRUCT_TYPE:
  82.         RedrawTextStruct((DrawTextStruct *) Struct, DrawMode, Color);
  83.         break;
  84.     case DRAW_LIB_ITEM_STRUCT_TYPE:
  85.         DrawLibPart((DrawLibItemStruct *) Struct, DrawMode, Color);
  86.         break;
  87.     }
  88. }
  89.  
  90. /*****************************************************************************
  91. * Routine to redraw polyline struct.                         *
  92. *****************************************************************************/
  93. void RedrawPolylineStruct(DrawPolylineStruct *Struct, int DrawMode, int Color)
  94. {
  95.     int i, CrntColor = GRGetColor();
  96.  
  97.     GRSetColor(Color);
  98.  
  99.     GRSetLineStyle(GR_SOLID_LINE, 0, Struct -> Width);
  100.  
  101.     GRSetWriteMode(DrawMode);
  102.  
  103.     GRMoveTo(Struct -> Points[0], Struct -> Points[1]);
  104.     for (i = 1; i < Struct -> NumOfPoints; i++)
  105.     GRLineTo(Struct -> Points[i * 2], Struct -> Points[i * 2 + 1]);
  106.  
  107.     GRSetColor(CrntColor);
  108. }
  109.  
  110. /*****************************************************************************
  111. * Routine to redraw connection struct.                         *
  112. *****************************************************************************/
  113. void RedrawConnectionStruct(DrawConnectionStruct *Struct, int DrawMode,
  114.                                 int Color)
  115. {
  116.     int CrntColor = GRGetColor(), Width = DEFAULT_SNAP_DISTANCE / 2;
  117.  
  118.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  119.  
  120.     GRSetWriteMode(DrawMode);
  121.     GRSetColor(Color);
  122.  
  123.     GRSetFillStyle(GR_SOLID_FILL, Color);
  124.  
  125.     GRBar(Struct -> PosX - Width, Struct -> PosY - Width,
  126.       Struct -> PosX + Width, Struct -> PosY + Width);
  127.  
  128.     GRSetColor(CrntColor);
  129. }
  130.  
  131. /*****************************************************************************
  132. * Routine to redraw text struct.                         *
  133. *****************************************************************************/
  134. void RedrawTextStruct(DrawTextStruct *Struct, int DrawMode, int Color)
  135. {
  136.     int CrntColor = GRGetColor();
  137.  
  138.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  139.  
  140.     GRSetWriteMode(DrawMode);
  141.     GRSetColor(Color);
  142.  
  143.     PutTextInfo(Struct -> Orient, Struct -> PosX, Struct -> PosY,
  144.                         Struct -> Scale, Struct -> Text);
  145.  
  146.     GRSetColor(CrntColor);
  147. }
  148.  
  149. /*****************************************************************************
  150. * Routine to place polyline struct. Return TRUE if not aborted.             *
  151. *****************************************************************************/
  152. BooleanType PlacePolylineStruct(DrawPolylineStruct *Struct)
  153. {
  154.     int i, Event, CursorEndX, CursorEndY, Dx, Dy, *Points;
  155.     DrawGenericStruct *Next;
  156.  
  157.     IntrPushCursorType();
  158.     Cursor.CursorType = INTR_CURSOR_CUSTOM;
  159.     Cursor.CursorRoutine = DrawPolylineCursor;
  160.     IntrSetCursorType(&Cursor);
  161.     IntrDrawMessage("Place polyline", EEPopUpForeColor, EEPopUpBackColor);
  162.  
  163.     CrsrPolyline = Struct;
  164.     CursorStartX = GRInvMapX(GRCurrentCursorX);
  165.     CursorStartY = GRInvMapY(GRCurrentCursorY);
  166.  
  167.     /*   Snap the CursorStartX/Y to the real polyline point. As we need to   */
  168.     /* snap to this structure only, make sure its next is NULL.             */
  169.     Next = Struct -> Pnext;
  170.     Struct -> Pnext = NULL;
  171.     SnapPoint2(&CursorStartX, &CursorStartY, FALSE,
  172.                     (DrawGenericStruct *) Struct, NULL);
  173.     Struct -> Pnext = Next;
  174.  
  175.     if ((Event = IntrGetEventWaitSA(&CursorEndX, &CursorEndY)) ==
  176.                             INTR_EVNT_SELECT) {
  177.     CursorEndX = GRInvMapX(CursorEndX);
  178.     CursorEndY = GRInvMapY(CursorEndY);
  179.     Points = Struct -> Points;
  180.     Dx = EE_SNAP(CursorEndX) - EE_SNAP(CursorStartX);
  181.     Dy = EE_SNAP(CursorEndY) - EE_SNAP(CursorStartY);
  182.     for (i = 0; i < Struct -> NumOfPoints; i++) {
  183.         Points[i * 2] += Dx;
  184.         Points[i * 2 + 1] += Dy;
  185.     }
  186.     }
  187.  
  188.     IntrEraseMessage();
  189.     IntrPopCursorType();
  190.  
  191.     return Event != INTR_EVNT_ABORT;
  192. }
  193.  
  194. /*****************************************************************************
  195. * Routine to place connection struct. Return TRUE if not aborted.         *
  196. *****************************************************************************/
  197. BooleanType PlaceConnectionStruct(DrawConnectionStruct *Struct)
  198. {
  199.     int Event, NewX = Struct -> PosX, NewY = Struct -> PosY;
  200.  
  201.     IntrPushCursorType();
  202.     Cursor.CursorType = INTR_CURSOR_CUSTOM;
  203.     Cursor.CursorRoutine = DrawConnectionCursor;
  204.     IntrSetCursorType(&Cursor);
  205.     IntrDrawMessage("Place connection", EEPopUpForeColor, EEPopUpBackColor);
  206.  
  207.     CrsrConnection = Struct;
  208.     if ((Event = IntrGetEventWaitSA(&NewX, &NewY)) == INTR_EVNT_SELECT) {
  209.     Struct -> PosX = EE_SNAP(GRInvMapX(NewX));
  210.     Struct -> PosY = EE_SNAP(GRInvMapY(NewY));
  211.     }
  212.  
  213.     IntrEraseMessage();
  214.     IntrPopCursorType();
  215.  
  216.     return Event != INTR_EVNT_ABORT;
  217. }
  218.  
  219. /*****************************************************************************
  220. * Routine to place text struct. Return TRUE if not aborted.             *
  221. *****************************************************************************/
  222. BooleanType PlaceTextStruct(DrawTextStruct *Struct)
  223. {
  224.     return PlaceString(Struct -> Text, &Struct -> Orient, Struct -> Scale,
  225.                &Struct -> PosX, &Struct -> PosY,
  226.                        INTR_WNDW_PLACE_CENTER);
  227. }
  228.  
  229. /*****************************************************************************
  230. * Routine called by the cursor routine to display current polyline.         *
  231. *****************************************************************************/
  232. static void DrawPolylineCursor(int x, int y)
  233. {
  234.     int i,
  235.         LastColor = GRGetColor();
  236.  
  237.     GRSetColor(EE_HIGHLIGHT_COLOR);
  238.  
  239.     GRSMoveTo(0, y);
  240.     GRSLineTo(GRScreenMaxX, y);
  241.  
  242.     GRSMoveTo(x, 0);
  243.     GRSLineTo(x, GRScreenMaxY);
  244.  
  245.     x = GRInvMapX(x) - CursorStartX;
  246.     y = GRInvMapY(y) - CursorStartY;
  247.  
  248.     GRMoveTo(CrsrPolyline -> Points[0] + x, CrsrPolyline -> Points[1] + y);
  249.     for (i = 1; i < CrsrPolyline -> NumOfPoints; i++)
  250.     GRLineTo(CrsrPolyline -> Points[i * 2] + x,
  251.          CrsrPolyline -> Points[i * 2 + 1] + y);
  252.  
  253.     GRSetColor(LastColor);
  254. }
  255.  
  256. /*****************************************************************************
  257. * Routine called by the cursor routine to display current connection.        *
  258. *****************************************************************************/
  259. static void DrawConnectionCursor(int x, int y)
  260. {
  261.     int Width = DEFAULT_SNAP_DISTANCE / 2,
  262.         LastColor = GRGetColor();
  263.  
  264.     GRSetColor(EE_HIGHLIGHT_COLOR);
  265.  
  266.     GRSMoveTo(0, y);
  267.     GRSLineTo(GRScreenMaxX, y);
  268.  
  269.     GRSMoveTo(x, 0);
  270.     GRSLineTo(x, GRScreenMaxY);
  271.  
  272.     x = GRInvMapX(x);
  273.     y = GRInvMapY(y);
  274.  
  275.     GRMoveTo(x - Width, y - Width);
  276.     GRLineTo(x + Width, y - Width);
  277.     GRLineTo(x + Width, y + Width);
  278.     GRLineTo(x - Width, y + Width);
  279.     GRLineTo(x - Width, y - Width);
  280.  
  281.     GRSetColor(LastColor);
  282. }
  283.