home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / ed / eestring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-20  |  8.3 KB  |  232 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. #include "EELayer.h"
  11. #include "Primary.h"
  12.  
  13. static void PutTextInfoNoCentering(int Orient, int PosX, int PosY, char *Str);
  14.  
  15. /*****************************************************************************
  16. * Put out a string, always centered to the given position, with given         *
  17. * orientation, taking into account current zoom factor.                 *
  18. *****************************************************************************/
  19. void PutTextInfo(int Orient, int PosX, int PosY, int Scale, char *Str)
  20. {
  21.     int Size = MAX(1, GRFontSize + (Scale - 1)) - DEFAULT_ZOOM_FACTOR;
  22.  
  23.     GRSetTextStyle(GRFontName, Orient, Size);
  24.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER);
  25.     GRText(PosX, PosY, Str);
  26.     GRSetTextStyle(GRFontName, GR_HORIZ_DIR, MAX(GRFontSize, 1) -
  27.                                    DEFAULT_ZOOM_FACTOR);
  28. }
  29.  
  30. /*****************************************************************************
  31. * Same as PutTextInfo but does no centering.                     *
  32. *****************************************************************************/
  33. void PutTextInfoNoCentering(int Orient, int PosX, int PosY, char *Str)
  34. {
  35.     int Size = MAX(1, GRFontSize) - DEFAULT_ZOOM_FACTOR;
  36.  
  37.     GRSetTextStyle(GRFontName, Orient, Size);
  38.     GRText(PosX, PosY, Str);
  39.     GRSetTextStyle(GRFontName, GR_HORIZ_DIR, MAX(GRFontSize, 1) -
  40.                                    DEFAULT_ZOOM_FACTOR);
  41. }
  42.  
  43. /*****************************************************************************
  44. * Put out pin number and pin text info, given the pin line coordinates.         *
  45. * The line must be vertical or horizontal.                     *
  46. * If PinNext == NULL nothing is printed. If PinNum = 0 no number is printed. *
  47. * Current Zoom factor is taken into account.                     *
  48. * If TextInside then the text is been put inside (moving from x1, y1 in      *
  49. * the opposite direction to x2,y2), otherwise all is drawn outside.         *
  50. *****************************************************************************/
  51. void PutLineTextInfo(int x1, int y1, int x2, int y2, char *PinText, int PinNum,
  52.                 BooleanType TextInside, BooleanType DrawNums,
  53.                 int Mode)
  54. {
  55. /* Mode 0=EE_ERASE_COLOR, Mode 1=Layer_Color */
  56.     int x, y;
  57.     BooleanType IsNot;
  58.     char SPinNum[MAX_PIN_INFO];
  59.  
  60.     /* Do we need to invert the string? Is this string has only "~"? */
  61.     if (PinText != NULL && (IsNot = PinText[0] == '~') != FALSE) {
  62.         PinText++;
  63.     if (PinText[0] == 0) PinText = NULL;
  64.     }
  65.  
  66.     if (TextInside) {  /* Draw the text inside, but the pin numbers outside. */
  67.     if (x1 != x2) {                  /* Its an horizontal line. */
  68.         if (PinText != NULL) {
  69.         if (x1 > x2) {
  70.             GRSetTextJustify(GR_TEXT_HJUSTIFY_LEFT,
  71.                              GR_TEXT_VJUSTIFY_CENTER);
  72.             x = x1 + TextInside;
  73.             if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  74.                 GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  75.             else
  76.             GRSetColor(EE_ERASE_COLOR);
  77.                 PutTextInfoNoCentering(GR_HORIZ_DIR, x, y1, PinText);
  78.                 if (GRDrawingText() && IsNot) {
  79.                 GRMoveTo(x, y1);
  80.                     GRSMoveRel(0, -GRGetTextHeight(PinText) / 2 - 1);
  81.                 GRSLineRel(GRGetTextWidth(PinText), 0);
  82.                 }
  83.             
  84.         }
  85.         else {
  86.             GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  87.                              GR_TEXT_VJUSTIFY_CENTER);
  88.             if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  89.                 GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  90.             else
  91.             GRSetColor(EE_ERASE_COLOR);
  92.                 x = x1 - TextInside;
  93.                 PutTextInfoNoCentering(GR_HORIZ_DIR, x, y1, PinText);
  94.                 if (GRDrawingText() && IsNot) {
  95.                 GRMoveTo(x, y1);
  96.                     GRSMoveRel(0, -GRGetTextHeight(PinText) / 2 - 1);
  97.                 GRSLineRel(-GRGetTextWidth(PinText), 0);
  98.                 }
  99.             
  100.         }
  101.         }
  102.         if (PinNum != 0 && DrawNums) {
  103.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  104.                          GR_TEXT_VJUSTIFY_BOTTOM);
  105.         if((ReturnLayerMode(LAYER_PINNUM)&0x03) & (Mode==1))
  106.             GRSetColor(ReturnLayerColor(LAYER_PINNUM));
  107.         else 
  108.             GRSetColor(EE_ERASE_COLOR);
  109.             sprintf(SPinNum, "%d", PinNum);
  110.             PutTextInfoNoCentering(GR_HORIZ_DIR, 
  111.                 (x1 + x2) / 2, y1 + 1, SPinNum);
  112.         
  113.         }
  114.     }
  115.     else {                         /* Its a vertical line. */
  116.         if (PinText != NULL) {
  117.         if (y1 > y2) {
  118.             GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  119.                                  GR_TEXT_VJUSTIFY_TOP);
  120.             if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  121.             GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  122.             else
  123.             GRSetColor(EE_ERASE_COLOR);
  124.                 y = y1 + TextInside;
  125.                 PutTextInfoNoCentering(GR_VERT_DIR, x1, y, PinText);
  126.                 if (GRDrawingText() && IsNot) {
  127.                 GRMoveTo(x1, y);
  128.                     GRSMoveRel(-GRGetTextHeight(PinText) / 2 - 1, 0);
  129.                 GRSLineRel(0, GRGetTextWidth(PinText));
  130.                 }
  131.             
  132.         }
  133.         else {
  134.             GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  135.                                     GR_TEXT_VJUSTIFY_BOTTOM);
  136.             if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  137.             GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  138.             else
  139.             GRSetColor(EE_ERASE_COLOR);
  140.                 y = y1 - TextInside;
  141.                 PutTextInfoNoCentering(GR_VERT_DIR, x1, y, PinText);
  142.                 if (GRDrawingText() && IsNot) {
  143.                 GRMoveTo(x1, y);
  144.                     GRSMoveRel(-GRGetTextHeight(PinText) / 2 - 1, 0);
  145.                 GRSLineRel(0, -GRGetTextWidth(PinText));
  146.                 }
  147.             
  148.         }
  149.         }
  150.         if (PinNum != 0 && DrawNums) {
  151.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  152.                          GR_TEXT_HJUSTIFY_CENTER);
  153.         if((ReturnLayerMode(LAYER_PINNUM)&0x03) & (Mode==1))
  154.             GRSetColor(ReturnLayerColor(LAYER_PINNUM));
  155.         else
  156.             GRSetColor(EE_ERASE_COLOR);
  157.             sprintf(SPinNum, "%d", PinNum);
  158.             PutTextInfoNoCentering(GR_VERT_DIR, x1 - 1,
  159.              (y1 + y2) / 2, SPinNum);
  160.         
  161.         }
  162.     }
  163.     }
  164.     else {                       /* Draw text outside as well. */
  165.     if (x1 != x2) {                  /* Its an horizontal line. */
  166.         if (PinText != NULL) {
  167.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  168.                          GR_TEXT_VJUSTIFY_BOTTOM);
  169.         if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  170.             GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  171.         else
  172.             GRSetColor(EE_ERASE_COLOR);
  173.             PutTextInfoNoCentering(GR_HORIZ_DIR, x = (x1 + x2) / 2,
  174.                     GRInvMapY(GRMapY(y1) - 1), PinText);
  175.             if (GRDrawingText() && IsNot) {
  176.                 GRMoveTo(x, y1);
  177.                 GRSMoveRel(-GRGetTextWidth(PinText) / 2,
  178.                        -GRGetTextHeight(PinText) - 2);
  179.                 GRSLineRel(GRGetTextWidth(PinText), 0);
  180.             }
  181.         
  182.         }
  183.         if (PinNum != 0 && DrawNums) {
  184.         GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  185.                          GR_TEXT_VJUSTIFY_TOP);
  186.         if((ReturnLayerMode(LAYER_PINNUM)&0x03) & (Mode==1))
  187.             GRSetColor(ReturnLayerColor(LAYER_PINNUM));
  188.         else
  189.             GRSetColor(EE_ERASE_COLOR);
  190.             sprintf(SPinNum, "%d", PinNum);
  191.             PutTextInfoNoCentering(GR_HORIZ_DIR, (x1 + x2) / 2,
  192.                       GRInvMapY(GRMapY(y1) + 2), SPinNum);
  193.         
  194.         }
  195.     }
  196.     else {                         /* Its a vertical line. */
  197.         if (PinText != NULL) {
  198.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  199.                          GR_TEXT_VJUSTIFY_CENTER);
  200.         if((ReturnLayerMode(LAYER_PINNAM)&0x03) & (Mode==1))
  201.             GRSetColor(ReturnLayerColor(LAYER_PINNAM));
  202.         else
  203.             GRSetColor(EE_ERASE_COLOR);
  204.             PutTextInfoNoCentering(GR_VERT_DIR,
  205.              GRInvMapX(GRMapX(x1) - 1),
  206.                  y = (y1 + y2) / 2, PinText);
  207.             if (GRDrawingText() && IsNot) {
  208.                 GRMoveTo(x1, y);
  209.                 GRSMoveRel(-GRGetTextHeight(PinText) - 2,
  210.                        -GRGetTextWidth(PinText) / 2);
  211.                 GRSLineRel(0, GRGetTextHeight(PinText));
  212.             }
  213.         
  214.         }
  215.         if (PinNum != 0 && DrawNums) {
  216.                 /* For some reason LEFT justification does not work!!! */
  217.         GRSetTextJustify(GR_TEXT_HJUSTIFY_RIGHT,
  218.                          GR_TEXT_VJUSTIFY_CENTER);
  219.         if((ReturnLayerMode(LAYER_PINNUM)&0x03) & (Mode==1))
  220.             GRSetColor(ReturnLayerColor(LAYER_PINNUM));
  221.         else
  222.             GRSetColor(EE_ERASE_COLOR);
  223.             sprintf(SPinNum, "%d", PinNum);
  224.             PutTextInfoNoCentering(GR_VERT_DIR,
  225.             GRInvMapX(GRMapX(x1) + 2 + GRGetTextHeight(PinText)),
  226.                               (y1 + y2) / 2, SPinNum);
  227.         
  228.         }
  229.     }
  230.     }
  231. }
  232.