home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ftes46b5.zip / ftes46b5 / src / g_draw.cpp < prev    next >
C/C++ Source or Header  |  1997-05-30  |  7KB  |  280 lines

  1. /*    g_draw.cpp
  2.  *
  3.  *    Copyright (c) 1994-1996, Marko Macek
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #include "console.h"
  11.  
  12. #ifdef  NT
  13. #   define  WIN32_LEAN_AND_MEAN 1
  14. #   include <windows.h>
  15. #endif
  16.  
  17. int CStrLen(char *p) {
  18.     int len = 0, was = 0;
  19.     while (*p) {
  20.         len++;
  21.         if (*p == '&' && !was) {
  22.             len--;
  23.             was = 1;
  24.         }
  25.         p++;
  26.         was = 0;
  27.     }
  28.     return len;
  29. }
  30.  
  31.  
  32. #ifndef NT
  33.  
  34. void MoveCh(PCell B, char CCh, TAttr Attr, int Count) {
  35.     unsigned char *p = (unsigned char *) B;
  36.     while (Count > 0) {
  37.         *p++ = (unsigned char) CCh;
  38.         *p++ = (unsigned char) Attr;
  39.         Count--;
  40.     }
  41. }
  42.  
  43. void MoveChar(PCell B, int Pos, int Width, char CCh, TAttr Attr, int Count) {
  44.     unsigned char *p = (unsigned char *) B;
  45.     if (Pos < 0) {
  46.         Count += Pos;
  47.         Pos = 0;
  48.     }
  49.     if (Pos >= Width) return;
  50.     if (Pos + Count > Width) Count = Width - Pos;
  51.     if (Count <= 0) return;
  52.     for (p += sizeof(TCell) * Pos; Count > 0; Count--) {
  53.         *p++ = (unsigned char) CCh;
  54.         *p++ = (unsigned char) Attr;
  55.     }
  56. }
  57.  
  58. void MoveMem(PCell B, int Pos, int Width, char* Ch, TAttr Attr, int Count) {
  59.     unsigned char *p = (unsigned char *) B;
  60.     
  61.     if (Pos < 0) {
  62.         Count += Pos;
  63.         Ch -= Pos;
  64.         Pos = 0;
  65.     }
  66.     if (Pos >= Width) return;
  67.     if (Pos + Count > Width) Count = Width - Pos;
  68.     if (Count <= 0) return;
  69.     for (p += sizeof(TCell) * Pos; Count > 0; Count--) {
  70.         *p++ = (unsigned char) (*Ch++);
  71.         *p++ = (unsigned char) Attr;
  72.     }
  73. }
  74.  
  75. void MoveStr(PCell B, int Pos, int Width, char* Ch, TAttr Attr, int MaxCount) {
  76.     unsigned char *p = (unsigned char *) B;
  77.     
  78.     if (Pos < 0) {
  79.         MaxCount += Pos;
  80.         Ch -= Pos;
  81.         Pos = 0;
  82.     }
  83.     if (Pos >= Width) return;
  84.     if (Pos + MaxCount > Width) MaxCount = Width - Pos;
  85.     if (MaxCount <= 0) return;
  86.     for (p += sizeof(TCell) * Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
  87.         *p++ = (unsigned char) (*Ch++);
  88.         *p++ = (unsigned char) Attr;
  89.     }
  90. }
  91.  
  92. void MoveCStr(PCell B, int Pos, int Width, char* Ch, TAttr A0, TAttr A1, int MaxCount) {
  93.     unsigned char *p = (unsigned char *) B;
  94.     
  95.     char was = 0;
  96.     if (Pos < 0) {
  97.         MaxCount += Pos;
  98.         Ch -= Pos;
  99.         Pos = 0;
  100.     }
  101.     if (Pos >= Width) return;
  102.     if (Pos + MaxCount > Width) MaxCount = Width - Pos;
  103.     if (MaxCount <= 0) return;
  104.     for (p += sizeof(TCell) * Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
  105.         if (*Ch == '&' && !was) {
  106.             Ch++;
  107.             MaxCount++;
  108.             was = 1;
  109.             continue;
  110.         } 
  111.         *p++ = (unsigned char) (*Ch++);
  112.         if (was) {
  113.             *p++ = (unsigned char) A1;
  114.             was = 0;
  115.         } else
  116.             *p++ = (unsigned char) A0;
  117.     }
  118. }
  119.  
  120. void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, int Count) {
  121.     unsigned char *p = (unsigned char *) B;
  122.     
  123.     if (Pos < 0) {
  124.         Count += Pos;
  125.         Pos = 0;
  126.     }
  127.     if (Pos >= Width) return;
  128.     if (Pos + Count > Width) Count = Width - Pos;
  129.     if (Count <= 0) return;
  130.     for (p += sizeof(TCell) * Pos; Count > 0; Count--) {
  131.         p++;
  132.         *p++ = (unsigned char) Attr;
  133.     }
  134. }
  135.  
  136. void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, int Count) {
  137.     char *p = (char *) B;
  138.     
  139.     if (Pos < 0) {
  140.         Count += Pos;
  141.         Pos = 0;
  142.     }
  143.     if (Pos >= Width) return;
  144.     if (Pos + Count > Width) Count = Width - Pos;
  145.     if (Count <= 0) return;
  146.     for (p += sizeof(TCell) * Pos; Count > 0; Count--) {
  147.         p++;
  148.         *p = ((unsigned char)(*p & 0x0F)) | ((unsigned char) Attr);
  149.         p++;
  150.     }
  151. }
  152.  
  153. #else
  154.  
  155. void MoveCh(PCell B, char Ch, TAttr Attr, int Count) {
  156.     PCHAR_INFO p = (PCHAR_INFO) B;
  157.     while (Count > 0) {
  158.         p->Char.AsciiChar = Ch;
  159.         p->Attributes = Attr;
  160.         p++;
  161.         Count--;
  162.     }
  163. }
  164.  
  165. void MoveChar(PCell B, int Pos, int Width, char Ch, TAttr Attr, int Count) {
  166.     PCHAR_INFO p = (PCHAR_INFO) B;
  167.     if (Pos < 0) {
  168.         Count += Pos;
  169.         Pos = 0;
  170.     }
  171.     if (Pos >= Width) return;
  172.     if (Pos + Count > Width) Count = Width - Pos;
  173.     if (Count <= 0) return;
  174.     for (p += Pos; Count > 0; Count--) {
  175.         p->Char.AsciiChar = Ch;
  176.         p->Attributes = Attr;
  177.         p++;
  178.     }
  179. }
  180.  
  181. void MoveMem(PCell B, int Pos, int Width, char* Ch, TAttr Attr, int Count) {
  182.     PCHAR_INFO p = (PCHAR_INFO) B;
  183.     
  184.     if (Pos < 0) {
  185.         Count += Pos;
  186.         Ch -= Pos;
  187.         Pos = 0;
  188.     }
  189.     if (Pos >= Width) return;
  190.     if (Pos + Count > Width) Count = Width - Pos;
  191.     if (Count <= 0) return;
  192.     for (p += Pos; Count > 0; Count--) {
  193.         p->Char.AsciiChar = *Ch++;
  194.         p->Attributes = Attr;
  195.         p++;
  196.     }
  197. }
  198.  
  199. void MoveStr(PCell B, int Pos, int Width, char* Ch, TAttr Attr, int MaxCount) {
  200.     PCHAR_INFO p = (PCHAR_INFO) B;
  201.     
  202.     if (Pos < 0) {
  203.         MaxCount += Pos;
  204.         Ch -= Pos;
  205.         Pos = 0;
  206.     }
  207.     if (Pos >= Width) return;
  208.     if (Pos + MaxCount > Width) MaxCount = Width - Pos;
  209.     if (MaxCount <= 0) return;
  210.     for (p += Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
  211.         p->Char.AsciiChar = *Ch++;
  212.         p->Attributes = Attr;
  213.         p++;
  214.     }
  215. }
  216.  
  217. void MoveCStr(PCell B, int Pos, int Width, char* Ch, TAttr A0, TAttr A1, int MaxCount) {
  218.     PCHAR_INFO p = (PCHAR_INFO) B;
  219.     char was;
  220.     TAttr A;
  221.     
  222.     if (Pos < 0) {
  223.         MaxCount += Pos;
  224.         Ch -= Pos;
  225.         Pos = 0;
  226.     }
  227.     if (Pos >= Width) return;
  228.     if (Pos + MaxCount > Width) MaxCount = Width - Pos;
  229.     if (MaxCount <= 0) return;
  230.     was = 0;
  231.     for (p += Pos; MaxCount > 0 && (*Ch != 0); MaxCount--) {
  232.         if (*Ch == '&' && !was) {
  233.             Ch++;
  234.             MaxCount++;
  235.             was = 1;
  236.             continue;
  237.         } 
  238.         p->Char.AsciiChar = (unsigned char) (*Ch++);
  239.         if (was) {
  240.             p->Attributes = A1;
  241.             was = 0;
  242.         } else
  243.             p->Attributes = A0;
  244.         p++;
  245.     }
  246. }
  247.  
  248. void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, int Count) {
  249.     PCHAR_INFO p = (PCHAR_INFO) B;
  250.     
  251.     if (Pos < 0) {
  252.         Count += Pos;
  253.         Pos = 0;
  254.     }
  255.     if (Pos >= Width) return;
  256.     if (Pos + Count > Width) Count = Width - Pos;
  257.     if (Count <= 0) return;
  258.     for (p += Pos; Count > 0; Count--, p++)
  259.         p->Attributes = Attr;
  260. }
  261.  
  262. void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, int Count) {
  263.     PCHAR_INFO p = (PCHAR_INFO) B;
  264.     
  265.     if (Pos < 0) {
  266.         Count += Pos;
  267.         Pos = 0;
  268.     }
  269.     if (Pos >= Width) return;
  270.     if (Pos + Count > Width) Count = Width - Pos;
  271.     if (Count <= 0) return;
  272.     for (p += Pos; Count > 0; Count--) {
  273.         p->Attributes =
  274.             ((unsigned char)(p->Attributes & 0xf)) |
  275.             ((unsigned char) Attr); +      p++;
  276.     }
  277. }
  278.  
  279. #endif
  280.