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

📄 overlap.c

📁 dos 1.0 其中包含quick basic源代码、内存管理himem emm386 发展历史
💻 C
📖 第 1 页 / 共 2 页
字号:
		 *  2 - Top right corner	*  3 - Left side
		 *  4 - middle of window	*  5 - Right side
		 *  6 - Bottom left corner	*  7 - Bottom side
		 *  8 - Bottom right corner
		 */

		iZoneY = (ay == pwnd->arcWindow.ayTop) ? 0 :
			 ((ay == pwnd->arcWindow.ayBottom-1) ? 2 : 1);
		iZoneX = (ax == pwnd->arcWindow.axLeft) ? 0 :
			 ((ax == pwnd->arcWindow.axRight-1) ? 2 : 1);

		if (iZoneY * 3 + iZoneX == 4)  /* not on the border */
			return(FALSE);

		owds.owdf = rgowdf[iZoneY * 3 + iZoneX];

		owds.pwndMoving = pwnd;
		owds.pwndBackground = pwnd->pwndParent;

		if (!FAllocDragSave()) return(FALSE);

		SetCapture (pwnd);  /* we want the mouse captured */
		owds.ax = ax;
		owds.ay = ay;
		fDragging = TRUE;	/* we are dragging -> owds is valid */
		InitDragRrc(pwnd);
		SaveDragRrc();
		DisplayDrag();
		return(TRUE);


	case WM_MOUSEMOVE:
		/* if we're not dragging or not dragging due to mouse */
		if ((!fDragging)||(!owds.owdf.fMouse))
			return (FALSE);

		{
		int	dax, day;
		PWND	pwndParent = pwnd->pwndParent;

		ax = (AX) max((int)ax, (int)pwndParent->arcClipping.axLeft);
		ay = (AY) max((int)ay, (int)pwndParent->arcClipping.ayTop);
		ax = (AX) min((int)ax, (int)pwndParent->arcClipping.axRight -1);
		ay = (AY) min((int)ay, (int)pwndParent->arcClipping.ayBottom-1);
		dax = ax - owds.ax;
		day = ay - owds.ay;

		if (FAdjustDragRrc(&dax, &day))
			{
			if (owds.owdf.fOutline)
				{
				owds.ax = (AX) ((int) owds.ax + dax);
				owds.ay = (AY) ((int) owds.ay + day);
				}
			SaveDragRrc();
			DisplayDrag();
			}
		}
		return (TRUE);


	case WM_LBUTTONUP:
		if ((!fDragging) || (!owds.owdf.fMouse))
			return (FALSE);
		ReleaseCapture ();
		EndDrag();
		return (TRUE);


	case WM_CHAR:
		if (HIWORD(pmsg->lParam) & KK_MENU)
			return(FALSE);
		if ((fDragging) && (!owds.owdf.fMouse))
			{
			int	dax = 0, day = 0;

			switch(LOBYTE(pmsg->wParam))
				{
			default:
				return(FALSE);

			case LOBYTE(VK_LEFT):
				dax = -1;
				break;
			case LOBYTE(VK_RIGHT):
				dax = 1;
				break;
			case LOBYTE(VK_DOWN):
				day = 1;
				break;
			case LOBYTE(VK_UP):
				day = -1;
				break;
			case LOBYTE(VK_ESCAPE):
				owds.owdf.fEscapeMove = 1;
			case LOBYTE(VK_RETURN):
				fDragging = FALSE;
				return (TRUE);
				}

			if (HIWORD(pmsg->lParam) & KK_CONTROL)
				{
				dax *= 8;
				day *= 4;
				}
			if (owds.owdf.message == WM_MOVE)
				{
				/* make sure that we don't move off
				 * the right side or bottom
				*/
				dax = min( dax,
				 (int) owds.pwndBackground->arcClipping.axRight
				  - 1 - (int) AxOfRx(owds.pwndBackground,
					 owds.rrc.rxLeft));
				day = min( day,
				 (int) owds.pwndBackground->arcClipping.ayBottom
				  - 1 - (int) AyOfRy(owds.pwndBackground,
					owds.rrc.ryTop));
				}
			else
				{
				/* stop window from extending beyond
				 * right or bottom
				*/
				Assert(owds.owdf.message == WM_SIZE);
				dax = min( dax,
				 (int) owds.pwndBackground->arcClipping.axRight
				  - (int) AxOfRx(owds.pwndBackground,
					 owds.rrc.rxRight));
				day = min( day,
				 (int) owds.pwndBackground->arcClipping.ayBottom
				  - (int) AyOfRy(owds.pwndBackground,
					owds.rrc.ryBottom));
				}
			if (FAdjustDragRrc(&dax, &day))
				{
				SaveDragRrc();
				DisplayDrag();
				}
			return(TRUE);
			}
		}

	return(FALSE);
	}




STATIC BOOL
FAllocDragSave()
/*
  -- Allocate the save buffers, return FALSE if not possible
*/
	{
	RRC	rrc;

	if (owds.owdf.fOutline)
		{
		RX	rxSave;

		GetClientRrc(owds.pwndBackground, &rrc);

		/*
		 * We allocate enough space to save the top side
		 * right, left and bottom sides of the moveable outline.
		*/
		rxSave		= rrc.rxRight;
		rrc.rxRight	= 1;
		owds.cbSaveSide	= CbSizeRrc(&rrc);
		rrc.rxRight	= rxSave;
		rrc.ryBottom	= 1;
		owds.cbSaveTop	= CbSizeRrc(&rrc);

		owds.lpbSave	= LpbAllocWorkFar(owds.cbSaveTop * 2
						 + owds.cbSaveSide * 2);

		if (owds.lpbSave == NULL)
			return(FALSE);
		}
	else
		{
		/* we just need enough space to save the
		 * corner button
		*/
		rrc.rxLeft = rrc.ryTop = 0;
		rrc.ryBottom = 1;
		rrc.rxRight = 3;

		owds.cbSaveTop = CbSizeRrc(&rrc);

		owds.lpbSave = LpbAllocWorkFar(owds.cbSaveTop);

		if (owds.lpbSave == NULL)
			return(FALSE);
		}

	return(TRUE);
	}




STATIC VOID
InitDragRrc(pwnd)
PWND	pwnd;
/*
  -- initialize the rrcDrag
*/
	{
	if (owds.owdf.fOutline)
		{
		/* moveable outline is initialized to be the border of
		 * the window being moved
		*/
		owds.rrc.rxLeft
			 = RxOfAx(owds.pwndBackground,pwnd->arcWindow.axLeft);
		owds.rrc.rxRight
			 = RxOfAx(owds.pwndBackground,pwnd->arcWindow.axRight);
		owds.rrc.ryTop
			 = RyOfAy(owds.pwndBackground,pwnd->arcWindow.ayTop);
		owds.rrc.ryBottom
			 = RyOfAy(owds.pwndBackground,pwnd->arcWindow.ayBottom);
		}
	else
		{
		/* for a corner button, we save the corner and a space
		 * to the left and right
		*/
		owds.rrc.rxLeft = RxOfAx(owds.pwndBackground,owds.ax);
		owds.rrc.ryTop = RyOfAy(owds.pwndBackground,owds.ay);
		owds.rrc.rxRight = owds.rrc.rxLeft + 2;
		owds.rrc.ryBottom = owds.rrc.ryTop + 1;
		if (owds.rrc.rxLeft > 0) owds.rrc.rxLeft--;
		}
	}



STATIC VOID
DisplayDrag()
/*
  -- display the border or button
*/
	{
	DrawThisWnd(NULL);
	if (owds.owdf.fOutline)
		{
		ARC	arc;

		arc.axLeft	= AxOfRx(owds.pwndBackground,owds.rrc.rxLeft);
		arc.ayTop	= AyOfRy(owds.pwndBackground,owds.rrc.ryTop);
		arc.axRight	= AxOfRx(owds.pwndBackground,owds.rrc.rxRight);
		arc.ayBottom	= AyOfRy(owds.pwndBackground,owds.rrc.ryBottom);

		pwndClip = owds.pwndBackground;
		DrawBoxArc(&boxActiveWindowOut, &arc, isaButtonDown,
				 TRUE, TRUE, NULL);
		pwndClip = NULL;
		}
	else
		{
		if (owds.owdf.fButton)
			{
			CharOutAbs(owds.ax,owds.ay,chBullet, isaButtonDown);
			if (owds.ax > owds.pwndBackground->arcClipping.axLeft)
				CharOutAbs(owds.ax-1,owds.ay,'<',isaButtonDown);
			if (owds.ax <owds.pwndBackground->arcClipping.axRight-1)
				CharOutAbs(owds.ax+1,owds.ay,'>',isaButtonDown);
			}
		}
	}


STATIC VOID
SaveDragRrc()
/*
  -- save the  rrcDrag
*/
	{
	if (owds.owdf.fOutline)
		{
		/* just save the outline around the rrcDrag */
		RRC	rrc;

		rrc = owds.rrc;
		rrc.ryBottom = rrc.ryTop + 1;	/* save the top side */
		SaveRrc(owds.pwndBackground, &rrc, owds.lpbSave);
		rrc.ryBottom = owds.rrc.ryBottom;

		rrc.rxRight = rrc.rxLeft + 1;	/* save the left side */
		SaveRrc(owds.pwndBackground, &rrc, owds.lpbSave
						 + owds.cbSaveTop);
		rrc.rxRight = owds.rrc.rxRight;

		rrc.ryTop = rrc.ryBottom - 1;	/* save the bottom side */
		SaveRrc(owds.pwndBackground, &rrc, owds.lpbSave
				 + owds.cbSaveTop + owds.cbSaveSide);
		rrc.ryTop = owds.rrc.ryTop;

		rrc.rxLeft = rrc.rxRight - 1;	/* save the right side */
		SaveRrc(owds.pwndBackground, &rrc, owds.lpbSave
				 + 2*owds.cbSaveTop + owds.cbSaveSide);
		rrc.rxLeft = owds.rrc.rxLeft;
		}
	else
		{
		/* for a corner button */
		SaveRrc(owds.pwndBackground, &owds.rrc, owds.lpbSave);
		}
	}



STATIC VOID
RestoreDragRrc()
/*
  -- save the rrcDrag
*/
	{
	if (owds.owdf.fOutline)
		{
		RRC	rrc;

		rrc = owds.rrc;
		rrc.ryBottom = rrc.ryTop + 1;	/* restore top side */
		RestoreRrc(owds.pwndBackground, &rrc, owds.lpbSave);
		rrc.ryBottom = owds.rrc.ryBottom;

		rrc.rxRight = rrc.rxLeft + 1;	/* restore left side */
		RestoreRrc(owds.pwndBackground, &rrc, owds.lpbSave
						 + owds.cbSaveTop);
		rrc.rxRight = owds.rrc.rxRight;

		rrc.ryTop = rrc.ryBottom - 1;   /* restore the bottom */
		RestoreRrc(owds.pwndBackground, &rrc, owds.lpbSave 
					+ owds.cbSaveTop + owds.cbSaveSide);
		rrc.ryTop = owds.rrc.ryTop;

		rrc.rxLeft = rrc.rxRight - 1;	/* restore the right side */
		RestoreRrc(owds.pwndBackground, &rrc, owds.lpbSave 
					+ 2*owds.cbSaveTop + owds.cbSaveSide);
		rrc.rxLeft = owds.rrc.rxLeft;
		}
	else
		{
		RestoreRrc(owds.pwndBackground, &owds.rrc, owds.lpbSave);
		}
	}



STATIC BOOL
FAdjustDragRrc(pdax, pday)
int	*pdax;
int	*pday;
/*
  -- adjust the dragged rectangle, restore the old one if necessary
  -- return true if adjustment was made
  -- dax and day must already be adjusted so that the window doesn't
     go off the right side or the bottom (since the cursor and keyboard
     cases are different)
*/
	{
	int	dax = *pdax;
	int	day = *pday;

	if (owds.owdf.fOutline)
		{
		if (owds.owdf.message == WM_MOVE)
			{
			/* don't go off the left or top */
			dax = max(dax, - (int) owds.rrc.rxLeft);
			day = max(day, - (int) owds.rrc.ryTop);
			}
		else
			{
			/* don't size too small */
			Assert(owds.owdf.message == WM_SIZE);
			if (owds.owdf.fXDrag)
				dax = max(dax, (int) axMinSize + (int)
					owds.rrc.rxLeft -(int)owds.rrc.rxRight);
			else
				dax = 0;
			if (owds.owdf.fYDrag)
				day = max(day, (int) ayMinSize + (int)
					owds.rrc.ryTop -(int)owds.rrc.ryBottom);
			else
				day = 0;
			}

		if ((dax == 0) && (day == 0))
			return(FALSE);

		RestoreDragRrc();

		owds.rrc.rxRight  = (RX) ((int) owds.rrc.rxRight + dax);
		owds.rrc.ryBottom = (RY) ((int) owds.rrc.ryBottom + day);
		if (owds.owdf.message == WM_MOVE)
			{
			owds.rrc.rxLeft = (RX) ((int) owds.rrc.rxLeft + dax);
			owds.rrc.ryTop  = (RY) ((int) owds.rrc.ryTop + day);
			}
		}
	else
		{ /* dealing with a corner button */
		if (((dax > -2) && (dax < 2)) && (day == 0))
			{
			if (owds.owdf.fButton)
				return(FALSE);
			else
				owds.owdf.fButton = 1;
			}
		else
			{
			if (!(owds.owdf.fButton))
				return(FALSE);
			else
				owds.owdf.fButton = 0;
			}

		RestoreDragRrc();
		}

	*pdax = dax;
	*pday = day;
	return(TRUE);
	}

VOID PRIVATE
EndDrag()
/*
  -- deallocate the buffers and send the message and restore the screen
*/
	{
	WORD	wParam = 0;
	DWORD	lParam = 0L;

	fDragging = FALSE;
	RestoreDragRrc();
	FreeWorkFar(owds.lpbSave);

	if ((!(owds.owdf.fOutline) && !(owds.owdf.fButton))
				   || owds.owdf.fEscapeMove)
		return;

	if (owds.owdf.fOutline)
		{
		/*
		 * include the location and size of the moved window
		 * ax,ay in the high word, dax,day in the low word
		*/
		lParam = MAKELONG(
			MAKEWORD((owds.rrc.ryBottom - owds.rrc.ryTop),
				 (owds.rrc.rxRight - owds.rrc.rxLeft)), 
			MAKEWORD(AyOfRy(owds.pwndBackground,owds.rrc.ryTop),
				 AxOfRx(owds.pwndBackground,owds.rrc.rxLeft))
				 );
		}

	SendMessage(owds.pwndMoving, owds.owdf.message, wParam, lParam);
	RedrawDamagedRegions();
	UpdateCursor();
	}

#endif /* WINDOW_OVERLAP, entire file */

⌨️ 快捷键说明

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