00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "transparent.h"
00028 static TInt CallDoChangeTransparencyL(TAny *aPtr)
00029 {
00030 return (static_cast<CTransparentUtil *> (aPtr)->DoChangeTransparencyL());
00031 }
00032
00037 static TInt CallDoSetTransparentRegion(TAny *aPtr)
00038 {
00039 return (static_cast<CTransparentUtil *> (aPtr)->DoSetTransparentRegion());
00040 }
00041
00045 CTransparentUtil::CTransparentUtil()
00046 {
00047 }
00048
00053 CTransparentUtil* CTransparentUtil::NewL()
00054 {
00055 CTransparentUtil* self = new(ELeave) CTransparentUtil();
00056 CleanupStack::PushL(self);
00057 self->ConstructL();
00058 CleanupStack::Pop(self);
00059 return self;
00060 }
00061
00065 CTransparentUtil::~CTransparentUtil()
00066 {
00067 if(iPeriodicObject->IsActive())
00068 {
00069 iPeriodicObject->Cancel();
00070 }
00071 delete iPeriodicObject;
00072 delete iBitmapGc;
00073 delete iBitmapDevice;
00074 delete iEventHandler;
00075
00076 iForegndWindowTrans.Close();
00077 iFgndWinTransRegion.Close();
00078 iBackgndWindow.Close();
00079 iGroup.Close();
00080
00081 delete iGc;
00082 delete iScr;
00083 iWs.Close();
00084 }
00085
00093 void CTransparentUtil::ConstructL()
00094 {
00095
00096 User::LeaveIfError(iWs.Connect());
00097
00098
00099 iScr = new(ELeave) CWsScreenDevice(iWs);
00100 User::LeaveIfError(iScr->Construct(0));
00101
00102
00103 iGc = new(ELeave) CWindowGc(iScr);
00104
00105
00106 User::LeaveIfError(iGc->Construct());
00107
00108
00109 iGroup = RWindowGroup(iWs);
00110 User::LeaveIfError(iGroup.Construct((TUint)&iGroup, ETrue));
00111
00112
00113 iBackgndWindow = RWindow(iWs);
00114
00115
00116 iForegndWindowTrans = RWindow(iWs);
00117
00118
00119 iFgndWinTransRegion = RWindow(iWs);
00120
00121
00122 iPeriodicObject=CPeriodic::NewL(CActive::EPriorityUserInput);
00123
00124
00125 iEventHandler = CEventHandler::NewL(iWs);
00126
00127
00128 User::LeaveIfError(iBackgndWindow.Construct(iGroup, (TUint)&iBackgndWindow));
00129 User::LeaveIfError(iForegndWindowTrans.Construct(iGroup, (TUint)&iForegndWindowTrans));
00130 User::LeaveIfError(iFgndWinTransRegion.Construct(iGroup, (TUint)&iFgndWinTransRegion));
00131
00132 iForegndWindowTrans.SetRequiredDisplayMode(EColor16MA);
00133 iFgndWinTransRegion.SetRequiredDisplayMode(EColor16MA);
00134
00135
00136 TSize bgRectSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight);
00137 iBackgndWindow.SetExtent(TPoint(),bgRectSize);
00138 iBackgndWindow.Activate();
00139
00140
00141 TSize fgRectSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight/2);
00142 iForegndWindowTrans.SetExtent(TPoint(),fgRectSize);
00143
00144 User::LeaveIfError(iForegndWindowTrans.SetTransparencyAlphaChannel());
00145 iForegndWindowTrans.Activate();
00146
00147
00148 iFgndWinTransRegion.SetExtent(TPoint(0, iScr->SizeInPixels().iHeight/2),fgRectSize);
00149
00150
00151 User::LeaveIfError(iFgndWinTransRegion.SetTransparencyAlphaChannel());
00152 iFgndWinTransRegion.Activate();
00153
00154 TRect circleRect(TPoint(80,50), TSize(170, 170));
00155
00156
00157 _LIT(KBackGrndWindow, "Background window");
00158 DrawWindow(iBackgndWindow, TRgb(234,234,236), TRgb(0,255,0), circleRect , KBackGrndWindow);
00159
00160
00161 iEventHandler->IssueRequest();
00162 }
00163
00171 void CTransparentUtil::DrawWindow(RWindow& aWindow, TRgb aColor1, TRgb aColor2, TRect aRect, const TDesC& aText)
00172 {
00173 aWindow.Invalidate();
00174 aWindow.BeginRedraw();
00175 iGc->Activate(aWindow);
00176
00177 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
00178 iGc->SetPenStyle(CGraphicsContext::ENullPen);
00179 iGc->SetBrushColor(aColor1);
00180 iGc->Clear();
00181 iGc->SetBrushColor(aColor2);
00182 iGc->DrawEllipse(aRect);
00183 iGc->UseFont(iEikonEnv->NormalFont());
00184 iGc->DrawText(aText, TPoint(10, aWindow.Size().iHeight/2 + 5));
00185 iGc->Deactivate();
00186 aWindow.EndRedraw();
00187 iWs.Flush();
00188 }
00189
00197 void CTransparentUtil::TransparencyVarianceL()
00198 {
00199
00200 ClearWindow(iWs, iForegndWindowTrans, iGc, TRgb::Gray16(10));
00201
00202
00203 if((iPeriodicObject->IsActive()))
00204 {
00205 iPeriodicObject->Cancel();
00206 }
00207 iPeriodicObject->Start(0,KDelay,TCallBack(CallDoChangeTransparencyL,this));
00208 }
00209
00217 void CTransparentUtil::ClearWindow(RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc, TRgb aColor)
00218 {
00219 aWindow.Invalidate();
00220 aWindow.BeginRedraw();
00221 aGc->Activate(aWindow);
00222 aGc->SetBrushColor(aColor);
00223 aGc->Clear();
00224 aGc->Deactivate();
00225 aWindow.EndRedraw();
00226 aSession.Flush();
00227 }
00228
00234 TBool CTransparentUtil::DoChangeTransparencyL()
00235 {
00236
00237
00238 iForegndWindowTrans.SetBackgroundColor( TRgb(255,0, 0, iAlphaValue));
00239
00240 TRect drawEllipse(TPoint(170, 45), TSize(65, 45));
00241 _LIT(KForeGrndWindowforTrans, "Foreground window for Vary Tra...");
00242 DrawWindow(iForegndWindowTrans, TRgb(255,0,0,iAlphaValue), TRgb(100,100,100, iAlphaValue), drawEllipse, KForeGrndWindowforTrans);
00243
00244 iAlphaValue += 20;
00245 if (iAlphaValue < 255)
00246 {
00247 return ETrue;
00248 }
00249 else
00250 {
00251 iAlphaValue=0;
00252 iPeriodicObject->Cancel();
00253 return EFalse;
00254 }
00255 }
00256
00263 void CTransparentUtil::TransparentRegionL()
00264 {
00265
00266
00267 if(iBoolVisible)
00268 {
00269 iFgndWinTransRegion.SetVisible(EFalse);
00270 iBoolVisible = EFalse;
00271 iWs.Flush();
00272 }
00273 else
00274 {
00275 iFgndWinTransRegion.SetVisible(ETrue);
00276
00277
00278 iFgndWinTransRegion.SetBackgroundColor(TRgb(0, 0 , 255 , 50));
00279
00280
00281 TSize rectsize1(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight/4);
00282 TRect chopRect1(TPoint(0, iScr->SizeInPixels().iHeight/4), rectsize1);
00283
00284
00285 iRegion = TRegionFix<2>(chopRect1);
00286
00287 iFgndWinTransRegion.SetTransparentRegion(iRegion);
00288
00289
00290 TRect chopRect2(TPoint(0, 0), rectsize1);
00291
00292 TRect circleRect2(TPoint(60,20), TSize(40, 40));
00293 _LIT(KOpqRegion, "Opaque region of the transparent window");
00294 DrawWindowRegion(iFgndWinTransRegion, TRgb(255, 255, 0), TRgb(100, 100, 0), chopRect2, circleRect2, KOpqRegion, TPoint(10, 15));
00295
00296
00297 TRect circleRect3(TPoint(110,80), TSize(40, 40));
00298 _LIT(KTransRegion, "Transparent region of the transparent window");
00299 DrawWindowRegion(iFgndWinTransRegion, TRgb(0, 0 , 255 , 50), TRgb(255,0,0, 100), chopRect1, circleRect3, KTransRegion, TPoint(10, 75));
00300 iBoolVisible = ETrue;
00301 }
00302 }
00303
00314 void CTransparentUtil::DrawWindowRegion(RWindow& aWindow, TRgb aColor1, TRgb aColor2, TRect aChopRect, TRect aRect, const TDesC& aText, const TPoint& aPoint)
00315 {
00316 aWindow.Invalidate(aChopRect);
00317 aWindow.BeginRedraw(aChopRect);
00318 iGc->Activate(aWindow);
00319
00320 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
00321 iGc->SetPenStyle(CGraphicsContext::ENullPen);
00322
00323 iGc->SetBrushColor(aColor1);
00324 iGc->Clear();
00325
00326 iGc->SetBrushColor(aColor2);
00327 iGc->DrawEllipse(aRect);
00328 iGc->SetBrushColor(TRgb(0, 0, 0));
00329 iGc->UseFont(iEikonEnv->NormalFont());
00330 iGc->DrawText(aText, aPoint);
00331 iGc->Deactivate();
00332 aWindow.EndRedraw();
00333 iWs.Flush();
00334 }