⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editpal.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 5 页
字号:
      PalTable__HlPal(this, this->curr[0], -1);
      PalTable__HlPal(this, this->curr[1], fg_color);
      }

   PalTable__DrawStatus(this, FALSE);

   Cursor_Show();
   }



static BOOLEAN PalTable__SetCurr(PalTable *this, int which, int curr)
   {
   BOOLEAN redraw = (which < 0) ? TRUE : FALSE;

   if ( redraw )
      {
      which = this->active;
      curr = this->curr[which];
      }
   else
      if ( curr == this->curr[which] || curr < 0 )
	 return (FALSE);

   Cursor_Hide();

   PalTable__HlPal(this, this->curr[0], bg_color);
   PalTable__HlPal(this, this->curr[1], bg_color);
   PalTable__HlPal(this, this->top,     bg_color);
   PalTable__HlPal(this, this->bottom,  bg_color);

   if ( this->freestyle )
      {
      this->curr[which] = curr;

      PalTable__CalcTopBottom(this);

      PalTable__HlPal(this, this->top,    -1);
      PalTable__HlPal(this, this->bottom, -1);
      PalTable__HlPal(this, this->curr[this->active], fg_color);

      RGBEditor_SetRGB(this->rgb[which], this->curr[which], &this->fs_color);
      RGBEditor_Update(this->rgb[which]);

      PalTable__UpdateDAC(this);

      Cursor_Show();

      return (TRUE);
      }

   this->curr[which] = curr;

   if (this->curr[0] != this->curr[1])
      PalTable__HlPal(this, this->curr[this->active==0?1:0], -1);
   PalTable__HlPal(this, this->curr[this->active], fg_color);

   RGBEditor_SetRGB(this->rgb[which], this->curr[which], &(this->pal[this->curr[which]]));

   if (redraw)
      {
      int other = (which==0) ? 1 : 0;
      RGBEditor_SetRGB(this->rgb[other], this->curr[other], &(this->pal[this->curr[other]]));
      RGBEditor_Update(this->rgb[0]);
      RGBEditor_Update(this->rgb[1]);
      }
   else
      RGBEditor_Update(this->rgb[which]);

   if (this->exclude)
      PalTable__UpdateDAC(this);

   Cursor_Show();

   this->curr_changed = FALSE;

   return(TRUE);
   }


static BOOLEAN PalTable__MemoryAlloc(PalTable *this, long size)
   {
   char far *temp;

   if (debugflag = 420)
      {
      this->stored_at = NOWHERE;
      return (FALSE);   /* can't do it */
      }
   temp = farmemalloc(FAR_RESERVE);   /* minimum free space */

   if (temp == NULL)
      {
      this->stored_at = NOWHERE;
      return (FALSE);   /* can't do it */
      }

   this->memory = farmemalloc( size );

   farmemfree(temp);

   if ( this->memory == NULL )
      {
      this->stored_at = NOWHERE;
      return (FALSE);
      }
   else
      {
      this->stored_at = MEMORY;
      return (TRUE);
      }
   }


static void PalTable__SaveRect(PalTable *this)
   {
   char buff[MAX_WIDTH];
   int  width = PalTable_PALX + this->csize*16 + 1 + 1,
        depth = PalTable_PALY + this->csize*16 + 1 + 1;
   int  yoff;


   /* first, do any de-allocationg */

   switch( this->stored_at )
      {
      case NOWHERE:
	 break;

      case DISK:
	 break;

      case MEMORY:
	 if (this->memory != NULL)
	    farmemfree(this->memory);
	 this->memory = NULL;
	 break;
      } ;

   /* allocate space and store the rect */

   if ( PalTable__MemoryAlloc(this, (long)width*depth) )
      {
      char far  *ptr = this->memory;
      char far  *bufptr = buff; /* MSC needs this indirection to get it right */

      Cursor_Hide();
      for (yoff=0; yoff<depth; yoff++)
	 {
	 getrow(this->x, this->y+yoff, width, buff);
	 hline (this->x, this->y+yoff, width, bg_color);
	 movedata(FP_SEG(bufptr), FP_OFF(bufptr), FP_SEG(ptr), FP_OFF(ptr), width);
	 ptr = (char far *)normalize(ptr+width);
	 }
      Cursor_Show();
      }

   else /* to disk */
      {
      this->stored_at = DISK;

      if ( this->file == NULL )
	 {
	 this->file = fopen(scrnfile, "w+b");
	 if (this->file == NULL)
	    {
	    this->stored_at = NOWHERE;
	    buzzer(3);
	    return ;
	    }
	 }

      rewind(this->file);
      Cursor_Hide();
      for (yoff=0; yoff<depth; yoff++)
	 {
	 getrow(this->x, this->y+yoff, width, buff);
	 hline (this->x, this->y+yoff, width, bg_color);
	 if ( fwrite(buff, width, 1, this->file) != 1 )
	    {
	    buzzer(3);
	    break;
	    }
	 }
      Cursor_Show();
      }

   }


static void PalTable__RestoreRect(PalTable *this)
   {
   char buff[MAX_WIDTH];
   int  width = PalTable_PALX + this->csize*16 + 1 + 1,
        depth = PalTable_PALY + this->csize*16 + 1 + 1;
   int  yoff;

   if (this->hidden)
      return;

   switch ( this->stored_at )
      {
      case DISK:
	 rewind(this->file);
	 Cursor_Hide();
	 for (yoff=0; yoff<depth; yoff++)
	    {
	    if ( fread(buff, width, 1, this->file) != 1 )
	       {
	       buzzer(3);
	       break;
	       }
	    putrow(this->x, this->y+yoff, width, buff);
	    }
	 Cursor_Show();
	 break;

      case MEMORY:
	 {
	 char far  *ptr = this->memory;
	 char far  *bufptr = buff; /* MSC needs this indirection to get it right */

	 Cursor_Hide();
	 for (yoff=0; yoff<depth; yoff++)
	    {
	    movedata(FP_SEG(ptr), FP_OFF(ptr), FP_SEG(bufptr), FP_OFF(bufptr), width);
	    putrow(this->x, this->y+yoff, width, buff);
	    ptr = (char far *)normalize(ptr+width);
	    }
	 Cursor_Show();
	 break;
	 }

      case NOWHERE:
	 break;
      } /* switch */
   }


static void PalTable__SetPos(PalTable *this, int x, int y)
   {
   int width = PalTable_PALX + this->csize*16 + 1 + 1;

   this->x = x;
   this->y = y;

   RGBEditor_SetPos(this->rgb[0], x+2, y+2);
   RGBEditor_SetPos(this->rgb[1], x+width-2-RGBEditor_WIDTH, y+2);
   }


static void PalTable__SetCSize(PalTable *this, int csize)
   {
   this->csize = csize;
   PalTable__SetPos(this, this->x, this->y);
   }


static int PalTable__GetCursorColor(PalTable *this)
   {
   int x     = Cursor_GetX(),
       y     = Cursor_GetY(),
       size;
   int color = getcolor(x, y);

   if ( is_reserved(color) )
      {
      if ( is_in_box(x, y, this->x, this->y, 1+(this->csize*16)+1+1, 2+RGBEditor_DEPTH+2+(this->csize*16)+1+1) )
	 {  /* is the cursor over the editor? */
	 x -= this->x + PalTable_PALX;
	 y -= this->y + PalTable_PALY;
	 size = this->csize;

	 if (x < 0 || y < 0 || x > size*16 || y > size*16)
	    return (-1);

	 if ( x == size*16 )
	    --x;
	 if ( y == size*16 )
	    --y;

	 return ( (y/size)*16 + x/size );
	 }
      else
	 return (color);
      }

   return (color);
   }



#define CURS_INC 1

static void PalTable__DoCurs(PalTable *this, int key)
   {
   BOOLEAN done  = FALSE;
   BOOLEAN first = TRUE;
   int	   xoff  = 0,
	   yoff  = 0;

   while ( !done )
      {
      switch(key)
	 {
	 case RIGHT_ARROW_2:	 xoff += CURS_INC*4;   break;
	 case RIGHT_ARROW:	 xoff += CURS_INC;     break;
	 case LEFT_ARROW_2:	 xoff -= CURS_INC*4;   break;
	 case LEFT_ARROW:	 xoff -= CURS_INC;     break;
	 case DOWN_ARROW_2:	 yoff += CURS_INC*4;   break;
	 case DOWN_ARROW:	 yoff += CURS_INC;     break;
	 case UP_ARROW_2:	 yoff -= CURS_INC*4;   break;
	 case UP_ARROW: 	 yoff -= CURS_INC;     break;

	 default:
	    done = TRUE;
	 }

      if (!done)
	 {
	 if (!first)
	    getakey();	     /* delete key from buffer */
	 else
	    first = FALSE;
	 key = keypressed();   /* peek at the next one... */
	 }
      }

   Cursor_Move(xoff, yoff);

   if (this->auto_select)
      PalTable__SetCurr(this, this->active, PalTable__GetCursorColor(this));
   }


#ifdef __TURBOC__
#   pragma argsused
#endif

static void PalTable__change(RGBEditor *rgb, VOIDPTR info)
   {
   PalTable *this = (PalTable *)info;
   int       pnum = this->curr[this->active];

   if ( this->freestyle )
      {
      this->fs_color = RGBEditor_GetRGB(rgb);
      PalTable__UpdateDAC(this);
      return ;
      }

   if ( !this->curr_changed )
      {
      PalTable__SaveUndoData(this, pnum, pnum);
      this->curr_changed = TRUE;
      }

   this->pal[pnum] = RGBEditor_GetRGB(rgb);

   if (this->curr[0] == this->curr[1])
      {
      int      other = this->active==0 ? 1 : 0;
      PALENTRY color;

      color = RGBEditor_GetRGB(this->rgb[this->active]);
      RGBEditor_SetRGB(this->rgb[other], this->curr[other], &color);

      Cursor_Hide();
      RGBEditor_Update(this->rgb[other]);
      Cursor_Show();
      }

   }


static void PalTable__UpdateDAC(PalTable *this)
   {
   if ( this->exclude )
      {
      memset(dacbox, 0, 256*3);
      if (this->exclude == 1)
	 {
	 int a = this->curr[this->active];
	 memmove(dacbox[a], &this->pal[a], 3);
	 }
      else
	 {
	 int a = this->curr[0],
	     b = this->curr[1];

	 if (a>b)
	    {
	    int t=a;
	    a=b;
	    b=t;
	    }

	 memmove(dacbox[a], &this->pal[a], 3*(1+(b-a)));
	 }
      }
   else
      {
      memmove(dacbox[0], this->pal, 3*colors);

      if ( this->freestyle )
         PalTable__PutBand(this, (PALENTRY *)dacbox);   /* apply band to dacbox */
      }

   if ( !this->hidden )
      {
      if (inverse)
	 {
	 memset(dacbox[fg_color], 0, 3);	 /* dacbox[fg] = (0,0,0) */
	 memset(dacbox[bg_color], 48, 3);	 /* dacbox[bg] = (48,48,48) */
	 }
      else
	 {
	 memset(dacbox[bg_color], 0, 3);	 /* dacbox[bg] = (0,0,0) */
	 memset(dacbox[fg_color], 48, 3);	 /* dacbox[fg] = (48,48,48) */
	 }
      }

   spindac(0,1);
   }


static void PalTable__Rotate(PalTable *this, int dir, int lo, int hi)
   {

   rotatepal(this->pal, dir, lo, hi);

   Cursor_Hide();

   /* update the DAC.  */

   PalTable__UpdateDAC(this);

   /* update the editors. */

   RGBEditor_SetRGB(this->rgb[0], this->curr[0], &(this->pal[this->curr[0]]));
   RGBEditor_SetRGB(this->rgb[1], this->curr[1], &(this->pal[this->curr[1]]));
   RGBEditor_Update(this->rgb[0]);
   RGBEditor_Update(this->rgb[1]);

   Cursor_Show();
   }


static void PalTable__other_key(int key, RGBEditor *rgb, VOIDPTR info)
   {
   PalTable *this = (PalTable *)info;

   switch(key)
      {
      case '\\':    /* move/resize */
	 {
	 if (this->hidden)
	    break;	     /* cannot move a hidden pal */
	 Cursor_Hide();
	 PalTable__RestoreRect(this);
	 MoveBox_SetPos(this->movebox, this->x, this->y);
	 MoveBox_SetCSize(this->movebox, this->csize);
	 if ( MoveBox_Process(this->movebox) )
	    {
	    if ( MoveBox_ShouldHide(this->movebox) )
	       PalTable_SetHidden(this, TRUE);
	    else if ( MoveBox_Moved(this->movebox) )
	       {
	       PalTable__SetPos(this, MoveBox_X(this->movebox), MoveBox_Y(this->movebox));
	       PalTable__SetCSize(this, MoveBox_CSize(this->movebox));
	       PalTable__SaveRect(this);
	       }
	    }
	 PalTable__Draw(this);
	 Cursor_Show();

	 RGBEditor_SetDone(this->rgb[this->active], TRUE);

	 if (this->auto_select)
	    PalTable__SetCurr(this, this->active, PalTable__GetCursorColor(this));
	 break;
	 }

      case 'Y':    /* exclude range */
      case 'y':
	 if ( this->exclude==2 )
	    this->exclude = 0;
	 else
	    this->exclude = 2;
	 PalTable__UpdateDAC(this);
         PalTable__DrawStatus(this, FALSE);
	 break;

      case 'X':
      case 'x':     /* exclude current entry */
	 if ( this->exclude==1 )
	    this->exclude = 0;
	 else
	    this->exclude = 1;
	 PalTable__UpdateDAC(this);
         PalTable__DrawStatus(this, FALSE);
	 break;

      case RIGHT_ARROW:
      case LEFT_ARROW:
      case UP_ARROW:
      case DOWN_ARROW:
      case RIGHT_ARROW_2:
      case LEFT_ARROW_2:
      case UP_ARROW_2:
      case DOWN_ARROW_2:
	 PalTable__DoCurs(this, key);
	 break;

      case ESC:
	 this->done = TRUE;
	 RGBEditor_SetDone(rgb, TRUE);
	 break;

      case ' ':     /* select the other palette register */
	 this->active = (this->active==0) ? 1 : 0;
	 if (this->auto_select)
	    PalTable__SetCurr(this, this->active, PalTable__GetCursorColor(this));
	  else
	    PalTable__SetCurr(this, -1, 0);

	 if (this->exclude || this->freestyle)
	    PalTable__UpdateDAC(this);

	 RGBEditor_SetDone(rgb, TRUE);
	 break;

      case ENTER:    /* set register to color under cursor.  useful when not */
      case ENTER_2:  /* in auto_select mode */

         if ( this->freestyle )
            {
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -