00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "CATLayer.h"
00015 #include "CATApp.h"
00016 #include "CATFileSystem.h"
00017 #include "CATStream.h"
00018 #include "CATEvent.h"
00019 #include "CATWindow.h"
00020 #include "CATEventDefs.h"
00021
00022
00023
00024
00025
00026
00027
00028 CATLayer::CATLayer( const CATString& element,
00029 const CATString& rootDir)
00030 : CATWidget(element, rootDir)
00031 {
00032 }
00033
00034
00035
00036
00037 CATLayer::~CATLayer()
00038 {
00039 }
00040
00041
00042 CATResult CATLayer::ParseAttributes()
00043 {
00044 return CATWidget::ParseAttributes();
00045 }
00046
00047
00048
00049
00050 CATControl* CATLayer::HitTest(const CATPOINT& point)
00051 {
00052 if (!fRect.InRect(point))
00053 {
00054 return 0;
00055 }
00056
00057 CATPOINT layerPt = point;
00058 layerPt.x -= fRect.left;
00059 layerPt.y -= fRect.top;
00060 CATControl* finalHit = 0;
00061
00062 CATUInt32 numControls = this->GetNumChildren();
00063 for (CATUInt32 i = 0; i < numControls; i++)
00064 {
00065 CATXMLObject* curChild = 0;
00066 if (0 != (curChild = GetChild(i)))
00067 {
00068 CATWidget* curControl = (CATWidget*)curChild;
00069 if (curControl->IsEnabled())
00070 {
00071
00072 CATControl* hitControl = curControl->HitTest(layerPt);
00073 if (hitControl)
00074 {
00075 finalHit = hitControl;
00076 }
00077 }
00078 }
00079 }
00080
00081 return finalHit;
00082 }
00083
00084
00085 void CATLayer::Draw(CATImage* image, const CATRect& dirtyRect)
00086 {
00087 if (this->IsVisible() == false)
00088 {
00089 return;
00090 }
00091
00092 CATRect layerRect;
00093 if (!fRect.Intersect( dirtyRect, &layerRect))
00094 return;
00095
00096 layerRect.Offset( -fRect.left, -fRect.top);
00097
00098 CATImage* subImage = 0;
00099
00100 if (CATSUCCEEDED(CATImage::CreateSub( image,
00101 subImage,
00102 fRect.left,
00103 fRect.top,
00104 CATMin(image->Width() - fRect.left, fRect.Width()),
00105 CATMin(image->Height() - fRect.top, fRect.Height()) )))
00106 {
00107
00108 CATXMLObject* curChild = 0;
00109 CATUInt32 index;
00110 CATUInt32 numChildren = this->GetNumChildren();
00111 for (index = 0; index < numChildren; index++)
00112 {
00113 if (0 != (curChild = GetChild(index)))
00114 {
00115 CATWidget* curControl = (CATWidget*)curChild;
00116 curControl->Draw(subImage,layerRect);
00117 }
00118 }
00119
00120 CATImage::ReleaseImage(subImage);
00121 }
00122 }
00123
00124 void CATLayer::PostDraw(CATDRAWCONTEXT context, const CATRect& dirtyRect)
00125 {
00126 if (this->IsVisible() == false)
00127 {
00128 return;
00129 }
00130
00131 CATRect layerRect;
00132 if (!fRect.Intersect( dirtyRect, &layerRect))
00133 return;
00134 layerRect.Offset( -fRect.left, -fRect.top);
00135
00136
00137 CATXMLObject* curChild = 0;
00138 CATUInt32 numChildren = this->GetNumChildren();
00139
00140 for (CATUInt32 i = 0; i < numChildren; i++)
00141 {
00142 if (0 != (curChild = GetChild(i)))
00143 {
00144 CATWidget* curControl = (CATWidget*)curChild;
00145 curControl->PostDraw(context,layerRect);
00146 }
00147 }
00148 }
00149
00150
00151
00152
00153
00154 void CATLayer::OnParentCreate()
00155 {
00156 CATXMLObject* curChild = 0;
00157 CATUInt32 numChildren = this->GetNumChildren();
00158
00159 for (CATUInt32 i = 0; i < numChildren; i++)
00160 {
00161 if (0 != (curChild = GetChild(i)))
00162 {
00163 CATWidget* curControl = (CATWidget*)curChild;
00164 curControl->OnParentCreate();
00165 }
00166 }
00167 }
00168
00169
00170
00171
00172
00173 void CATLayer::OnParentDestroy()
00174 {
00175 CATXMLObject* curChild = 0;
00176 CATUInt32 numChildren = this->GetNumChildren();
00177
00178 for (CATUInt32 i = 0; i < numChildren; i++)
00179 {
00180 if (0 != (curChild = GetChild(i)))
00181 {
00182 CATWidget* curControl = (CATWidget*)curChild;
00183 curControl->OnParentDestroy();
00184 }
00185 }
00186 }
00187
00188 void CATLayer::SetEnabled(bool enabled)
00189 {
00190 CATWidget::SetEnabled(enabled);
00191
00192 CATXMLObject* curChild = 0;
00193 CATUInt32 numChildren = this->GetNumChildren();
00194
00195 for (CATUInt32 i = 0; i < numChildren; i++)
00196 {
00197 if (0 != (curChild = GetChild(i)))
00198 {
00199 CATWidget* curControl = (CATWidget*)curChild;
00200 CATInt32 evRes = 0;
00201 (void)curControl->OnEvent(CATEvent(CATEVENT_ENABLE_CHANGE),evRes);
00202 }
00203 }
00204 }