00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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;
00082 }
00083
00084 if (artRect->Bottom + localY - shiftY > bounds.Bottom)
00085 {
00086 artRect->Bottom -= (artRect->Bottom + localY - shiftY) - bounds.Bottom;
00087 }
00088
00089 if (artRect->Left + localX - shiftX < bounds.Left)
00090 {
00091 localX += bounds.Left - (artRect->Left + localX - shiftX);
00092 artRect->Left += localX - x;
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
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