📄 graphics.cpp
字号:
iSize = aSize;
User::LeaveIfError(iWindow.SetSizeErr(aSize));
}
void COplWindow::ClearWindow()
{
SetGcMode(EModeReplace); // does not affect current draw and text modes
iDrawableGc->Clear(TRect(KScreenOrigin,Size()));
}
void COplWindow::SetWinPosition(const TPoint& aPoint)
{
iWindow.SetPosition(aPoint);
}
void COplWindow::ActivateGc()
{
((CWindowGc*)iDrawableGc)->Activate(iWindow);
}
void COplWindow::DeactivateGc()
{
((CWindowGc*)iDrawableGc)->Deactivate();
}
void COplWindow::BackupBmpHandleL(CFbsBitmap& aBitmap)
{
User::LeaveIfError(aBitmap.Duplicate(BitmapHandle()));
}
TInt COplWindow::BitmapHandle()
{
iWindow.UpdateBackupBitmap();
return iWindow.BitmapHandle();
}
void COplWindow::SetCursorPosition(const TPoint& aPosition)
{
iCursorPosition = aPosition;
DrawCursorIfOn(iCursor);
}
void COplWindow::SetCursorEnabled(TBool aEnabled)
{
iCursorEnabled = aEnabled;
}
void COplWindow::DrawCursorIfOn(TTextCursor aCursor)
{
if (iCursorEnabled)
{
iCursor = aCursor;
((CEikonEnv*)(TheRuntime()->ConEnv()))->RootWin().SetTextCursor(iWindow,iCursorPosition,aCursor);
}
}
void COplWindow::Scroll(const TPoint& aOffset,const TRect& aArea)
{
iWindow.Scroll(aOffset,aArea);
DoScrollClear(aOffset,aArea);
}
void COplWindow::UseNewWindow(RBackedUpWindow& aNewWindow,TDisplayMode aDisplayMode)
{
DeleteClock();
DeactivateGc();
iWindow=aNewWindow;
iDisplayMode=aDisplayMode;
ActivateGc();
iDrawableGc->UseFont(iFont);
// iIsFontToBeReleased is already set because the font is aleady set...
SetCursorPosition(TPoint(0,0));
SetGcModeInvalid(); // ensure gc set correctly before it is used
}
TBool COplWindow::ClockIsVisible(const CEikLocaleConformantClock& /*aClock*/) const
{
return ETrue; // what if window is not visible??????
}
void COplWindow::GetClockPositionAndSize(TPoint& aPosition, TSize& aSize, const CEikLocaleConformantClock& /*aClock*/, const TSize& aMinimumSize)
{
aPosition=iClockPosition;
if (aSize.iWidth==0)
aSize=aMinimumSize;
}
#if !defined(__SERIES60__)
void COplWindow::CreateClockL(CEikonEnv& aEikonEnv,TInt aType,TInt aOffset)
{
TInt type=EEikLocaleConformantClockTypeAnalog;
TInt analogClock=R_EIK_ANALOG_CLOCK;
iFormatMatchesLocale=EFalse;
TLocale locale;
switch (aType)
{
case 6:
if (locale.ClockFormat()!=EClockAnalog)
type=EEikLocaleConformantClockTypeDigital;
iFormatMatchesLocale=ETrue;
break;
case 7:
break;
case 8:
type=EEikLocaleConformantClockTypeDigital;
break;
case 9:
analogClock=R_EIK_BIG_ANALOG_CLOCK;
type=EEikLocaleConformantClockTypeAnalog;
break;
default:
User::Leave(KErrArgument);
}
iClockPosition=iCursorPosition;
CEikLocaleConformantClock* clock=new(ELeave)CEikResourceConstructedClock(*this,aEikonEnv.ClockDllL(),iWindow,
type,EFalse,aEikonEnv,R_EIK_DIGITAL_CLOCK,analogClock);
CleanupStack::PushL(clock);
iTimeOffsetInSeconds=aOffset;
clock->ConstructL(iTimeOffsetInSeconds+locale.UniversalTimeOffset().Int(),EDstHome);
iClock=clock;
iClock->SetVisible(ETrue);
//iClock->Draw(*(CWindowGc*)iDrawableGc);
CleanupStack::Pop();
}
#else
void COplWindow::CreateClockL(CEikonEnv&,TInt,TInt)
{
}
#endif
void COplWindow::DrawClock()
{
#if !defined(__SERIES60__)
if (iFormattedClock)
iFormattedClock->Draw();
if (iClock)
iClock->RedrawAll(*(CWindowGc*)iDrawableGc);
#endif
}
#if !defined(__SERIES60__)
void COplWindow::UpdateClock(const TLocale& aLocale)
{
TInt universalOffset=aLocale.UniversalTimeOffset().Int();
if (iClock)
{
if (iFormatMatchesLocale) // only iClock can change format
{
TRAPD(ignore, iClock->ChangeFormatL(aLocale.ClockFormat()));
}
//#ifdef BADCLOCK
iClock->ChangeUniversalTimeOffsetAndDaylightSavingZone(iTimeOffsetInSeconds+universalOffset,EDstHome);
//#endif
iClock->Draw(*(CWindowGc*)iDrawableGc);
}
if (iFormattedClock)
{
iFormattedClock->SetUniversalTimeOffset(iTimeOffsetInSeconds+universalOffset+((aLocale.QueryHomeHasDaylightSavingOn())?3600:0));
iFormattedClock->Draw();
}
}
#else
void COplWindow::UpdateClock(const TLocale&)
{
}
#endif
#if !defined(__SERIES60__)
LOCAL_C void ClockDestroy(TAny* aClock)
{
((RClock*)aClock)->Destroy();
}
#endif
#if !defined(__SERIES60__)
void COplWindow::CreateFormattedClockL(RAnimDll& aClockDll,TInt aOffset,TInt aFontId,TInt aStyle,const TDesC& aFormat)
{
iFormatMatchesLocale=EFalse;
TLocale locale;
RDigitalClock* clock=new(ELeave) RDigitalClock(aClockDll,iWindow);
STimeDeviceShadow shadow;
shadow.iIsOn=EFalse;
TRgb foregroundColor=(aStyle&0x04)?iBackgroundColor:iForegroundColor;
TRgb backgroundColor=(aStyle&0x04)?iForegroundColor:iBackgroundColor;
TMargins margins;
margins.iLeft=0;
margins.iRight=0;
margins.iTop=0;
margins.iBottom=0;
CleanupStack::PushL(TCleanupItem(ClockDestroy,clock));
iTimeOffsetInSeconds=aOffset;
clock->ConstructL(iTimeOffsetInSeconds+locale.UniversalTimeOffset().Int()+((locale.DaylightSaving()&EDstHome)?3600:0),iCursorPosition,TSize(),margins,shadow,backgroundColor,1);
CFont* font=NULL;
TAlgStyle style;
style.SetHeightFactor(1);
style.SetWidthFactor(1);
if (aStyle&0x01)
style.SetIsBold(ETrue);
if (aStyle&0x08)
style.SetHeightFactor(2);
if (aStyle&0x10)
style.SetIsMono(ETrue);
if (aStyle&0x20)
style.SetIsItalic(ETrue);
TUid fontUid=OplUtil::MapFontId(aFontId,style);
User::LeaveIfError(iScreenDevice->GetFontById(font,fontUid,style));
SEikLocaleAndFontData localeAndFontData;
localeAndFontData.iLocale=&locale;
localeAndFontData.iFont=font;
_LIT(KSpace," ");
localeAndFontData.iWidthOfSpace=font->TextWidthInPixels(KSpace);
localeAndFontData.iWidthOfWidestCharacter=font->MaxNormalCharWidthInPixels();
localeAndFontData.iWidthOfWidestDigit=TFindWidthOfWidestDigit().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestAmPmName=TFindWidthOfWidestAmPmName().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestAbbreviatedDayName=TFindWidthOfWidestAbbreviatedDayName().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestDayName=TFindWidthOfWidestDayName().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestAbbreviatedMonthName=TFindWidthOfWidestAbbreviatedMonthName().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestMonthName=TFindWidthOfWidestMonthName().MaximumWidthInPixels(*font);
localeAndFontData.iWidthOfWidestDateSuffix=TFindWidthOfWidestDateSuffix().MaximumWidthInPixels(*font);
TInt width=CEikLocaleConformantClock::PotentialWidthOfTextBlock(aFormat,localeAndFontData);
TInt fontHandle=STATIC_CAST(CFbsFont*,font)->Handle();
TDigitalDisplayTextSection textSection(fontHandle,foregroundColor,EDigitalDisplayHorizontalTextAlignmentLeft,
EDigitalDisplayVerticalTextAlignmentTop,0,0,aFormat);
TRAPD(err,clock->AddTextSectionL(textSection));
if (!err)
clock->SetSize(TSize(width,font->HeightInPixels()));
iScreenDevice->ReleaseFont(font);
User::LeaveIfError(err);
iFormattedClock=clock;
CleanupStack::Pop(); // clock
iFormattedClock->SetVisible(ETrue);
// iFormattedClock->Draw();
}
#else
void COplWindow::CreateFormattedClockL(RAnimDll&,TInt,TInt,TInt,const TDesC&)
{
}
#endif
void COplWindow::DeleteClock()
{
#if !defined(__SERIES60__)
if (iFormattedClock)
{
iFormattedClock->Destroy();
iFormattedClock=NULL;
}
delete iClock;
iClock=NULL;
#endif
}
///////////////////////////
//// protected functions ////
///////////////////////////
CBitmapContext* COplWindow::CreateWindowGcL()
{
CWindowGc* gc;
User::LeaveIfError(iScreenDevice->CreateContext((CGraphicsContext*&)gc));
return gc;
}
void COplWindow::SetAttributesL(CCoeEnv& aConEnv)
{
TRgb color=TRgb::Gray16(0);
SetForegroundColor(color);
iScreenDevice=aConEnv.ScreenDevice();
iDrawableGc = CreateWindowGcL();
ActivateGc();
SetDrawMode(EModeSet);
SetTextMode(EModeSet);
iFont = GetDefaultFontL(*iScreenDevice); //This sets iIsFontToBeReleased flag if necessary.
iDrawableGc->UseFont(iFont);
iWindow.SetOrdinalPosition(0,-1); // just less than default
}
/*******************************
class COplBitmap
*******************************/
COplBitmap::COplBitmap()
{
}
void COplBitmap::ConstructL(TSize& aSize,TDisplayMode aMode)
{
iBitmap = new(ELeave) CFbsBitmap();
iDisplayMode=aMode;
User::LeaveIfError(iBitmap->Create(aSize,iDisplayMode));
SetSizeL(aSize);
SetAttributesL(iBitmap);
}
void COplBitmap::ConstructL(const TDesC* aFileName, TInt aWrite, TInt aNum)
// overloaded constructor used by gLoadBit
{
iBitmap = new(ELeave) CFbsBitmap();
if (aFileName)
RestoreBitmapL(aFileName,aWrite,aNum);
iSize=iBitmap->SizeInPixels();
iDisplayMode=iBitmap->DisplayMode();
if (aWrite==0)
{
iNullBitmap=new(ELeave) CFbsBitmap;
User::LeaveIfError(iNullBitmap->Create(TSize(0,0),DisplayMode(0)));
SetAttributesL(iNullBitmap);
}
else
SetAttributesL(iBitmap);
}
void COplBitmap::StoreBitmapL(COplRuntime& aRuntime, const TDesC& aFileName, TSize& aSize)
{
DoStoreBitmapL(aRuntime,aFileName,aSize,*iBitmap);
}
COplBitmap::~COplBitmap()
{
ReleaseFont();
delete iBitmapDevice;
delete iBitmap;
delete iNullBitmap;
}
#if defined(__SERIES60__)
void COplBitmap::ReleaseFont()
{
if (iBitmapDevice&&iFont)
if (iIsFontToBeReleased!=EFalse)
iBitmapDevice->ReleaseFont(iFont);
}
#else
void COplBitmap::ReleaseFont()
{
if (iBitmapDevice&&iFont)
iBitmapDevice->ReleaseFont(iFont);
}
#endif
void COplBitmap::SetSizeL(const TSize& aSize)
{
if (aSize != iBitmap->SizeInPixels())
User::LeaveIfError(iBitmap->Resize(aSize));
iSize = aSize;
}
void COplBitmap::ClearBitmap()
{
SetGcMode(EModeReplace); // does not affect current draw and text modes
iDrawableGc->Clear(TRect(KScreenOrigin,Size()));
((CFbsBitGc*)iDrawableGc)->SetShadowMode(EFalse); // disable shadow
}
void COplBitmap::Scroll(const TPoint& aOffset,const TRect& aArea)
{
TPoint point=aArea.iTl+aOffset;
iDrawableGc->BitBlt(point,iBitmap,aArea);
DoScrollClear(aOffset,aArea);
}
TInt COplBitmap::BitmapHandle()
{
return iBitmap->Handle();
}
///////////////////////////
//// protected functions ////
///////////////////////////
CBitmapContext* COplBitmap::CreateBitmapGcL(CFbsBitmap* aBitmap)
{
iBitmapDevice=CFbsBitmapDevice::NewL(aBitmap);
CFbsBitGc* gc;
User::LeaveIfError(iBitmapDevice->CreateContext((CGraphicsContext*&)gc));
// this also activates the gc
return gc;
}
void COplBitmap::RestoreBitmapL(const TDesC* aFileName, TInt aWrite, TInt aNum)
{
iBitmapFilename = *aFileName;
User::LeaveIfError(iBitmap->Load(iBitmapFilename,aNum,(aWrite==0)));
}
void COplBitmap::SetAttributesL(CFbsBitmap* aBitmap)
{
SetDrawableFlag(EIsOplBitmap);
TRgb color=TRgb::Gray16(0);
SetForegroundColor(color); // black
color=TRgb::Gray16(15);
SetBackgroundColor(color); // white
SetCursorPosition(KScreenOrigin);
iDrawableGc = CreateBitmapGcL(aBitmap);
SetDrawMode(EModeSet);
SetTextMode(EModeSet);
iFont = GetDefaultFontL(*iBitmapDevice); // This sets iIsFontToBeReleased if necessary.
iDrawableGc->UseFont(iFont);
}
//
// class COplClockUpdater
//
#if defined(_DEBUG)
_LIT(KClockUpdater, "ClockUpdater");
#endif
COplClockUpdater::COplClockUpdater(CDrawablesCollection& aDrawablesCollection)
: CActive(EPriorityStandard),
iDrawablesCollection(aDrawablesCollection)
{
}
COplClockUpdater::~COplClockUpdater()
{
Cancel();
iChangeNotifier.Close();
}
void COplClockUpdater::ConstructL()
{
User::LeaveIfError(iChangeNotifier.Create());
#if defined(_DEBUG)
const TInt error=
#endif
iChangeNotifier.Logon(iStatus);
__ASSERT_DEBUG(error==KErrNone, User::Panic(KClockUpdater, 1));
CActiveScheduler::Add(this);
SetActive();
}
void COplClockUpdater::RunL()
{
if (iStatus.Int()&EChangesLocale)
iDrawablesCollection.UpdateAllClocks();
#if defined(_DEBUG)
const TInt error=
#endif
iChangeNotifier.Logon(iStatus);
__ASSERT_DEBUG(error==KErrNone, User::Panic(KClockUpdater, 2));
if (!IsActive()) // COplClockUpdater::RunL may be called from the sequencer which will not set the CActive::iActive field to EFalse
SetActive();
}
void COplClockUpdater::DoCancel()
{
#if defined(_DEBUG)
const TInt error=
#endif
iChangeNotifier.LogonCancel();
__ASSERT_DEBUG((error==KErrNone) || (error==KErrGeneral), User::Panic(KClockUpdater, 3)); // RChangeNotifier::LogonCancel returns KErrGeneral if the preceding RChangeNotifier::Logon call completed straightaway
}
/* End of $Workfile GRAPHICS.CPP$ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -