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

📄 zect9.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/*         Copyright (c) 1997 - 1999 Accelerated Technology, Inc.        */
/*                                                                       */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the      */
/* subject matter of this material.  All manufacturing, reproduction,    */
/* use, and sales rights pertaining to this subject matter are governed  */
/* by the license agreement.  The recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      ZECT9.c                                          1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the ShiftRect function.                       */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Giac Dinh, Accelerated Technology, Inc.                          */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*                                                                       */
/*************************************************************************/

#include "meta_wnd.h"
#include "metconst.h"    /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h"    /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"
 

/* Function ShiftRect moves the specified rectangle by adding the delta-X (DX) 
   value to the rectangle 'R' X coordinates, and delta-Y (DY) values to the 
   rectangle 'R' Y coordinates.  The rectangle retains its shade and size, it is 
   simply offsetto a different position on the coordinate plane.

   The area(s) voided by the rectangle move are RETURNed are RETURNed in 
   rectangles R1 and R2.  The function RETURN value, 0,1 or 2,  indicates if 
   no (DX=DY=0), one (R1) or two (R1 & R2) voided rectangles are RETURNed.

  Note: this functions assumes a proper rectangle where Xmin, Ymin are less
  than Xmax, Ymax, respectively.
				             	 _________________
					            |Dst              |
		...................  	|                 |
		:Src              : ==> |                 |
		:                 :     |                 |
		:       R1        :     |_________________|
		:                 :
		:.................:

      
       DX<0                      DX=0                       DX>0
 _________________         __________________         _________________
|Dst              |       |Dst               |       |Dst              |
|    ...          |.....  | . . . . . . . .  |  .....|          ...    |
|    :            | Src:  |                  |  :Src |            :    |  DY>0
|                 | R2 :  |                  |  : R2 |                 |
|_________________|....:  |__________________|  :....|_________________|
     :       R1        :  :        R1     Src:  :       R1        :
     :.................:  :..................:  :.................:

 _________________ .....   __________________   ..... _________________
|Dst .            | Src:  |Src/Dst           |  :Src |Dst         .    |
|    :            |    :  |                  |  :    |            :    |
|    :            | R1 :  |                  |  : R1 |            :    |  DY=0
|    :            |    :  |                  |  :    |            :    |
|_________________|....:  |__________________|  :....|_________________|

     ...................  ....................  ...................
     :Src     R1       :  :Src    R1         :  :Src     R1       :
 _________________ ....:  :__________________:  :.... _________________
|Dst              |    :  |Dst               |  :    |Dst              |  DY<0
|    .            | R2 :  |                  |  : R2 |            .    |
|    :..          |....:  |..................|  :....|          ..:    |
|                 |       |                  |       |                 |
|_________________|       |__________________|       |_________________|

*/


int ShiftRect ( rect *R , int dltX, int dltY, rect *R1, rect *R2)
{
	short width;
	short height;

/* Load passing parameters for calculation purpose  */
	
	*R1 = *R;
	width = R->Xmax - R->Xmin;
	height = R->Ymax - R->Ymin;
	R->Xmin = R->Xmin + dltX;	/* move the rectangle */
	R->Xmax = R->Xmax + dltX;
	R->Ymin = R->Ymin + dltY;
	R->Ymax = R->Ymax + dltY;

	if (dltX == 0)
	{	/* 0 or 1 rectangle returned; R1->X values = R->X values */
		if (dltY == 0) return(0);	/* nothing moved */

		if (dltY < 0)
		{	/* moving down */
			if (-dltY >= height) return(1);	/* moved out of source */
			R1->Ymin = R->Ymax;	/* adjust Ymin */
			return(1);
		}
		else
		{	/* moving up */
			if (dltY >= height) return(1);	/* moved out of source */
			R1->Ymax = R->Ymin;	/* adjust Ymax */
			return(1);
		}
	}

/* Case of negative delta X with all value of delta Y  */
	if ( dltX < 0 )                             
	{
		if(-dltX >= width) return(1);	/* moved out of source */

		R2->Xmax = R1->Xmax; 
		R2->Xmin = R->Xmax;
		if (dltY == 0)
		{	/* moved left */
			R1->Xmin = R2->Xmin;
			return(1);
		}

		if (dltY < 0)
		{	/* moving down */
			if (-dltY >= height) return(1);	/* moved out of source */
			R2->Ymin = R1->Ymin;
			R2->Ymax = R->Ymax; 
			R1->Ymin = R->Ymax;
			return(2);
		}
		else
		{	/* moving up */
			if (dltY >= height) return(1);	/* moved out of source */
			R2->Ymax = R1->Ymax; 
			R2->Ymin = R->Ymin;
			R1->Ymax = R->Ymin;
			return(2);
		}
	}

/* Case of positive delta X with all value of delta Y  */
	if(dltX >= width) return(1);	/* moved out of source */

	R2->Xmin = R1->Xmin; 
	R2->Xmax = R->Xmin;
	if (dltY == 0)
	{	/* moved right */
		R1->Xmax = R2->Xmax;
		return(1);
	}

	if (dltY < 0)
	{	/* moving down */
		if (-dltY >= height) return(1);	/* moved out of source */
		R2->Ymin = R1->Ymin;
		R2->Ymax = R->Ymax; 
		R1->Ymin = R->Ymax;
		return(2);
	}
	else
	{	/* moving up */
		if (dltY >= height) return(1);	/* moved out of source */
		R2->Ymax = R1->Ymax; 
		R2->Ymin = R->Ymin;
		R1->Ymax = R->Ymin;
		return(2);
	}
}

⌨️ 快捷键说明

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