Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

wgClip.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  WGCLIP.C                                                                            */
00003 /*                                                                                      */
00004 /*  Author: Thom Robertson                                                              */
00005 /*  Description: 2D rectangular clip testing support                                    */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*Genesis3D Version 1.1 released November 15, 1999                            */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #define WIN32_LEAN_AND_MEAN
00023 #pragma warning(disable : 4201 4214 4115)
00024 #include <windows.h>
00025 #include <windowsx.h>
00026 #pragma warning(default : 4201 4214 4115)
00027 
00028 #include <assert.h>
00029 #include <string.h>
00030 
00031 #include "genesis.h"
00032 #include "basetype.h"
00033 #include "extbox.h"
00034 
00035 #include "wgClip.h"
00036 
00037 #pragma warning (disable:4514)  // unreferenced inline function (caused by Windows)
00038 
00039 //***************************************************************
00040 // returns true if you need to draw at all.
00041 GENESISAPI geBoolean GENESISCC CalculateClipping(
00042                            GE_Rect *artRect, int32 *resultX, int32 *resultY, 
00043                            int32 x, int32 y,
00044                            const GE_Rect bounds, int32 type)
00045 {
00046 
00047         int32 localX, localY;
00048         int32 shiftX, shiftY;
00049         int32 baseX,  baseY;
00050 
00051    assert(artRect);
00052    assert(resultX);
00053    assert(resultY);
00054 
00055    baseX = artRect->Left;
00056    baseY = artRect->Top;
00057 
00058    // normalize the rect passed in.
00059    artRect->Left   = artRect->Left   - baseX;
00060    artRect->Right  = artRect->Right  - baseX;
00061    artRect->Top    = artRect->Top    - baseY;
00062    artRect->Bottom = artRect->Bottom - baseY;
00063 
00064 
00065         localX = x;
00066         localY = y;
00067 
00068         if (GE_CLIP_CENTER == type)
00069         {
00070                 shiftX = artRect->Right  / 2;
00071                 shiftY = artRect->Bottom / 2;
00072         }
00073         else
00074         {
00075                 shiftX = 0;                                                     
00076                 shiftY = 0;
00077         }
00078         
00079         if (artRect->Right + localX - shiftX > bounds.Right)
00080         {
00081                 artRect->Right  -= (artRect->Right + localX - shiftX) - bounds.Right;  // push Right edge Leftward
00082         }
00083 
00084         if (artRect->Bottom + localY - shiftY > bounds.Bottom)
00085         {
00086                 artRect->Bottom         -= (artRect->Bottom + localY - shiftY) - bounds.Bottom;  // push Bottom edge Leftward
00087         }
00088 
00089         if (artRect->Left + localX - shiftX < bounds.Left)
00090         {
00091                 localX                  += bounds.Left - (artRect->Left + localX - shiftX);
00092                 artRect->Left   += localX - x;  // push Left edge Rightward
00093         }
00094 
00095         if (artRect->Top + localY - shiftY < bounds.Top)
00096         {
00097                 localY                  += bounds.Top - (artRect->Top + localY - shiftY);
00098                 artRect->Top    += localY - y;
00099         }
00100 
00101    if (artRect->Left >= artRect->Right)
00102                 return GE_FALSE;
00103         if (artRect->Top >= artRect->Bottom)
00104                 return GE_FALSE;
00105 
00106         *resultX = localX - shiftX;
00107         *resultY = localY - shiftY;
00108 
00109    // un-normalize the rect passed in.
00110    artRect->Left   = artRect->Left   + baseX;
00111    artRect->Right  = artRect->Right  + baseX;
00112    artRect->Top    = artRect->Top    + baseY;
00113    artRect->Bottom = artRect->Bottom + baseY;
00114 
00115 
00116         return GE_TRUE;
00117 }
00118 

Generated on Tue Sep 30 12:36:39 2003 for GTestAndEngine by doxygen 1.3.2