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

  1. /*****************************************************************************
  2. *   Module to handle screen printing.                         *
  3. *                                         *
  4. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Dec. 1989    *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include "Program.h"
  9. #include "EEString.h"
  10.  
  11. static void PutTextInfoNoCentering(int Orient, int PosX, int PosY, char *Str);
  12.  
  13. /*****************************************************************************
  14. * Put out a string, always centered to the given position, with given         *
  15. * orientation, taking into account current zoom factor.                 *
  16. *****************************************************************************/
  17. void PutTextInfo(int Orient, int PosX, int PosY, int Scale, char *Str)
  18. {
  19.     int Size = MAX(1, GRFontSize + (Scale - 1)) - DEFAULT_ZOOM_FACTOR;
  20.  
  21.     GRSetTextStyle(GRFontName, Orient, Size);
  22.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER);
  23.     GRText(PosX, PosY, Str);
  24.     GRSetTextStyle(GRFontName, GR_HORIZ_DIR, MAX(GRFontSize, 1) -
  25.                                    DEFAULT_ZOOM_FACTOR);
  26. }
  27.  
  28. /*****************************************************************************
  29. * Same as PutTextInfo but does no centering.                     *
  30. *****************************************************************************/
  31. static void PutTextInfoNoCentering(int Orient, int PosX, int PosY, char *Str)
  32. {
  33.     int Size = MAX(1, GRFontSize) - DEFAULT_ZOOM_FACTOR;
  34.  
  35.     GRSetTextStyle(GRFontName, Orient, Size);
  36.     GRText(PosX, PosY, Str);
  37.     GRSetTextStyle(GRFontName, GR_HORIZ_DIR, MAX(GRFontSize, 1) -
  38.                                    DEFAULT_ZOOM_FACTOR);
  39. }
  40.  
  41. /*****************************************************************************
  42. * Put out pin number and pin text info, given the pin line coordinates.         *
  43. * The line must be vertical or horizontal.                     *
  44. * If PinNext == NULL nothing is printed. If PinNum = 0 no number is printed. *
  45. * Current Zoom factor is taken into account.                     *
  46. * If TextInside then the text is been put inside (moving from x1, y1 in      *
  47. * the opposite direction to x2,y2), otherwise all is drawn outside.         *
  48. *****************************************************************************/
  49. void PutLineTextInfo(int x1, int y1, int x2, int y2, char *PinText, int PinNum,
  50.                 BooleanType TextInside, BooleanType DrawNums)
  51. {
  52.     int x, y;
  53.     BooleanType IsNot;
  54.     char SPinNum[MAX_PIN_INFO];
  55.  
  56.     /* Do we need to invert the string? Is this string has only "~"? */
  57.     if (PinText != NULL && (IsNot = PinText[0] == '~') != FALSE) {
  58.         PinText++;
  59.     if (PinText[0] == 0) PinText = NULL;
  60.     }
  61.  
  62.     if (TextInside) {  /* Draw the text inside, but the pin numbers outside. */
  63.     if (x1 != x2) {                  /* Its an horizontal line. */
  64.         if (PinText != NULL) {
  65.         if (x1 > x2) {
  66.             GRSetTextJustify(GR_TEXT_HJUSTIFY_LEFT,
  67.                              GR_TEXT_VJUSTIFY_CENTER);
  68.             x = x1 + TextInside;
  69.             PutTextInfoNoCentering(GR_HORIZ_DIR, x, y1, PinText);
  70.             if (GRDrawingText() && IsNot) {
  71.             GRMoveTo(x, y1);
  72.                 GRSMoveRel(0, -GRGetTextHeight(PinText) / 2 - 1);
  73.             GRSLineRel(GRGetTextWidth(PinText), 0);
  74.             }
  75.         }
  76.         else {
  77.             GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  78.                              GR_TEXT_VJUSTIFY_CENTER);
  79.             x = x1 - TextInside;
  80.             PutTextInfoNoCentering(GR_HORIZ_DIR, x, y1, PinText);
  81.             if (GRDrawingText() && IsNot) {
  82.             GRMoveTo(x, y1);
  83.                 GRSMoveRel(0, -GRGetTextHeight(PinText) / 2 - 1);
  84.             GRSLineRel(-GRGetTextWidth(PinText), 0);
  85.             }
  86.         }
  87.         }
  88.         if (PinNum != 0 && DrawNums) {
  89.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  90.                          GR_TEXT_VJUSTIFY_BOTTOM);
  91.         sprintf(SPinNum, "%d", PinNum);
  92.         PutTextInfoNoCentering(GR_HORIZ_DIR, (x1 + x2) / 2, y1 + 1, SPinNum);
  93.         }
  94.     }
  95.     else {                         /* Its a vertical line. */
  96.         if (PinText != NULL) {
  97.         if (y1 > y2) {
  98.             GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  99.                                  GR_TEXT_VJUSTIFY_TOP);
  100.             y = y1 + TextInside;
  101.             PutTextInfoNoCentering(GR_VERT_DIR, x1, y, PinText);
  102.             if (GRDrawingText() && IsNot) {
  103.             GRMoveTo(x1, y);
  104.                 GRSMoveRel(-GRGetTextHeight(PinText) / 2 - 1, 0);
  105.             GRSLineRel(0, GRGetTextWidth(PinText));
  106.             }
  107.         }
  108.         else {
  109.             GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  110.                                     GR_TEXT_VJUSTIFY_BOTTOM);
  111.             y = y1 - TextInside;
  112.             PutTextInfoNoCentering(GR_VERT_DIR, x1, y, PinText);
  113.             if (GRDrawingText() && IsNot) {
  114.             GRMoveTo(x1, y);
  115.                 GRSMoveRel(-GRGetTextHeight(PinText) / 2 - 1, 0);
  116.             GRSLineRel(0, -GRGetTextWidth(PinText));
  117.             }
  118.         }
  119.         }
  120.         if (PinNum != 0 && DrawNums) {
  121.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  122.                          GR_TEXT_HJUSTIFY_CENTER);
  123.         sprintf(SPinNum, "%d", PinNum);
  124.         PutTextInfoNoCentering(GR_VERT_DIR, x1 - 1, (y1 + y2) / 2, SPinNum);
  125.         }
  126.     }
  127.     }
  128.     else {                       /* Draw text outside as well. */
  129.     if (x1 != x2) {                  /* Its an horizontal line. */
  130.         if (PinText != NULL) {
  131.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  132.                          GR_TEXT_VJUSTIFY_BOTTOM);
  133.         PutTextInfoNoCentering(GR_HORIZ_DIR, x = (x1 + x2) / 2,
  134.                     GRInvMapY(GRMapY(y1) - 1), PinText);
  135.         if (GRDrawingText() && IsNot) {
  136.             GRMoveTo(x, y1);
  137.             GRSMoveRel(-GRGetTextWidth(PinText) / 2,
  138.                    -GRGetTextHeight(PinText) - 2);
  139.             GRSLineRel(GRGetTextWidth(PinText), 0);
  140.         }
  141.         }
  142.         if (PinNum != 0 && DrawNums) {
  143.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  144.                          GR_TEXT_VJUSTIFY_TOP);
  145.         sprintf(SPinNum, "%d", PinNum);
  146.         PutTextInfoNoCentering(GR_HORIZ_DIR, (x1 + x2) / 2,
  147.                       GRInvMapY(GRMapY(y1) + 2), SPinNum);
  148.         }
  149.     }
  150.     else {                         /* Its a vertical line. */
  151.         if (PinText != NULL) {
  152.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  153.                          GR_TEXT_VJUSTIFY_CENTER);
  154.         PutTextInfoNoCentering(GR_VERT_DIR, GRInvMapX(GRMapX(x1) - 1),
  155.                                y = (y1 + y2) / 2, PinText);
  156.         if (GRDrawingText() && IsNot) {
  157.             GRMoveTo(x1, y);
  158.             GRSMoveRel(-GRGetTextHeight(PinText) - 2,
  159.                    -GRGetTextWidth(PinText) / 2);
  160.             GRSLineRel(0, GRGetTextHeight(PinText));
  161.         }
  162.         }
  163.         if (PinNum != 0 && DrawNums) {
  164.                 /* For some reason LEFT justification does not work!!! */
  165.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  166.                          GR_TEXT_VJUSTIFY_CENTER);
  167.         sprintf(SPinNum, "%d", PinNum);
  168.         PutTextInfoNoCentering(GR_VERT_DIR,
  169.             GRInvMapX(GRMapX(x1) + 2 + GRGetTextHeight(PinText)),
  170.                               (y1 + y2) / 2, SPinNum);
  171.         }
  172.     }
  173.     }
  174. }
  175.