home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / art2 / src.lzh / PEN.C < prev    next >
C/C++ Source or Header  |  1995-06-19  |  2KB  |  122 lines

  1. #define MODULE_PEN
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <winb.h>
  7. #include <te.h>
  8. #include <fntb.h>
  9. #include <gui.h>
  10. #include <egb.h>
  11. #include "art.h"
  12. #include "guisub.h"
  13. #include "wgbmac.h"
  14. #include "pen.h"
  15. #include "pensel.h"
  16. #include "desktop.h"
  17.  
  18. /*
  19. ペン(A段階)
  20.  
  21. テスト用
  22. */
  23.  
  24. Pen pen_new(int wid,int ht)
  25. {
  26.     Pen p;
  27.     p = TL_calloc(1,sizeof(PEN_DATA));
  28.     if (p == NULL)
  29.         return NULL;
  30.     p->buf = NULL;
  31.     p->wid = wid;
  32.     p->ht = ht;
  33.     p->ofsx = wid / 2;
  34.     p->ofsy = ht / 2;
  35.     if (wid * ht > 0)
  36.     {
  37.         if ((p->buf = TL_calloc(wid*ht,1)) == NULL)
  38.             { TL_free(p);  return NULL; }
  39.     }
  40.     else
  41.         p->buf = NULL;
  42.     return p;
  43. }
  44.  
  45. Pen pen_createCopy(Pen pen)
  46. {
  47.     Pen p;
  48.     p = TL_calloc(1,sizeof(PEN_DATA));
  49.     if (p == NULL)
  50.         return NULL;
  51.     p->wid = pen->wid;
  52.     p->ht = pen->ht;
  53.     p->ofsx = pen->ofsx;
  54.     p->ofsy = pen->ofsy;
  55.     if ((p->buf = TL_calloc(1,p->wid * p->ht)) == NULL)
  56.         { TL_free(p);  return NULL; }
  57.     memcpy(p->buf, pen->buf, p->wid * p->ht);
  58.     return p;
  59. }
  60.  
  61. void    pen_destroy(Pen pen)
  62. {
  63.     if (pen->buf != NULL)
  64.         TL_free(pen->buf);
  65.     TL_free(pen);
  66. }
  67.  
  68. void    pen_getPattern(Pen pen, char **buf, int *wid, int *ht)
  69. {
  70.     if (buf!=NULL)
  71.         *buf = pen->buf;
  72.     if (wid!=NULL)
  73.         *wid = pen->wid;
  74.     if (ht!=NULL)
  75.         *ht = pen->ht;
  76. }
  77.  
  78. int        pen_setPattern(Pen pen, char *buf, int wid, int ht)
  79. {
  80.     if (buf == pen->buf)
  81.         return 0;    /* この場合、サイズの変更はしないものとする */
  82.     if (wid != pen->wid || ht != pen->ht)
  83.     {
  84.         if (pen->buf!=NULL)
  85.             TL_free(pen->buf);
  86.         if ((pen->buf = TL_calloc(wid*ht, 1)) == NULL)
  87.             return -1;
  88.     }
  89.     memcpy(pen->buf, buf, wid*ht);
  90.     return 0;
  91. }
  92.  
  93. void    pen_setSampleData(Pen pen, int n)
  94. {
  95.     
  96.  
  97. }
  98.  
  99. void pen_setPixel(Pen pen,int x,int y,int gray)
  100. // gray:0..255
  101. {
  102.     *(pen->buf + pen->wid * y + x) = gray;
  103. }
  104.  
  105. int pen_getPixel(Pen pen,int x,int y)
  106. // ret:0..255
  107. {
  108.     return *(pen->buf + pen->wid * y + x);
  109. }
  110.  
  111. BOOL pen_IsNull(Pen pen)
  112. {
  113.     int i;
  114.     char *p = pen->buf;
  115.     for (i=pen->wid*pen->ht; i>0; i--,p++)
  116.     {
  117.         if (*p != 0)
  118.             return FALSE;
  119.     }
  120.     return TRUE;
  121. }
  122.