Drawing skins in container From Forum Nokia Wiki

本文介绍如何在S60平台中使用CCoeControl派生容器绘制皮肤。通过实例展示如何设置背景控制上下文,并调整容器大小来更新皮肤显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!-- /* Font Definitions */ @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:宋体; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@SimSun"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:SimSun;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:35.4pt; mso-footer-margin:35.4pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

 

Drawing skins in container From Forum Nokia Wiki


The CSkinnedContainer implementation illustrates how to draw skins in a CCoeControl derived container in the S60 platform.

The iBgContext is the CAknsBasicBackgroundControlContext which is used to draw the skin on the control's background. To draw on a different screen area you could change KAknsIIDQsnBgScreen identify to the background you would like to use with your container.

Note that for the skins to work properly you need to enable skins first. Usually this is done in Application user interface class' ConstructL() method by calling the ConstructL() method with CAknAppUi::EAknEnableSkin parameter.

Reviewer Approved   

Library required:

//CAknsBasicBackgroundControlContext , MAknsSkinInstance
LIBRARY   aknskins.lib aknskinsrv.lib aknswallpaperutils.lib

SkinnedContainer.cpp

CSkinnedContainer::~CSkinnedContainer()
{
            delete iBgContext;
            iBgContext = NULL;
}  
 
CSkinnedContainer* CSkinnedContainer::NewL(void)
{
    CSkinnedContainer* self = new(ELeave)CSkinnedContainer();
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop(self);
    return self;
}
 
void CSkinnedContainer::ConstructL(void)
   {
    CreateWindowL();
 
            // make first with no size at all
            iBgContext = CAknsBasicBackgroundControlContext::NewL(
                        KAknsIIDQsnBgScreen,TRect(0,0,1,1), ETrue);
            // Setting rect will cause SizeChanged to be called
            // and iBgContext size & position is updated accordingly.
            SetRect(CEikonEnv::Static()->EikAppUi()->ClientRect());
 
            ActivateL();
            DrawNow();
}
 
void CSkinnedContainer::SizeChanged()
{
            if ( iBgContext )
            {
                        iBgContext->SetRect(Rect());
 
                        if ( &Window() )
                        {
                                    iBgContext->SetParentPos( PositionRelativeToScreen() );
                        }
            }
}
 
 
void CSkinnedContainer::HandleResourceChange(TInt aType)
{
            TRect rect;
 
    if ( aType==KEikDynamicLayoutVariantSwitch )
    {   
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
    }
 
            CCoeControl::HandleResourceChange(aType);
}
 
 
TTypeUid::Ptr CSkinnedContainer::MopSupplyObject(TTypeUid aId)
{         
            if (iBgContext)
            {
                        return MAknsControlContext::SupplyMopObject(aId, iBgContext );
            }
 
            return CCoeControl::MopSupplyObject(aId);
}
 
 
void CSkinnedContainer::Draw(const TRect& aRect) const
{
            CWindowGc& gc = SystemGc();
 
            // draw background skin first.
            MAknsSkinInstance* skin = AknsUtils::SkinInstance();
            AknsDrawUtils::Background( skin, iBgContext, this, gc, aRect );
}

SkinnedContainer.h

#include <coecntrl.h>       // CCoeControl
#include <AknsBasicBackgroundControlContext.h>
#include <aknsdrawutils.h>
#include <aknscontrolcontext.h>
#include <AknsSkinInstance.h>
#include <aknsutils.h>
 
 
class CSkinnedContainer : public CCoeControl
    {
public:
            static CSkinnedContainer* NewL(void);
            ~CSkinnedContainer();
protected:
            TTypeUid::Ptr MopSupplyObject(TTypeUid aId); //
private:
            virtual void SizeChanged();
            virtual void HandleResourceChange(TInt aType);
            void ConstructL(void);
            void Draw(const TRect& aRect) const;
private:
            CAknsBasicBackgroundControlContext*         iBgContext;
};

Retrieved from "http://wiki.forum.nokia.com/index.php/Drawing_skins_in_container "

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值