×
Namespaces

Variants
Actions
(Difference between revisions)

Drawing custom borders around a Symbian control

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:UI]][[Category:S60 3rd Edition (initial release)]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]][[Category:Symbian^3]][[Category:Symbian Anna]][[Category:Nokia Belle]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
 
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|-
+
|devices= Nokia E90 Communicator<br/>Nokia N95 8GB
|'''ID''' || &nbsp;
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''Creation date''' || February 6, 2008
+
|platform= S60 3rd Edition and later
|-
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|'''Platform''' || S60 3rd Edition<br />S60 3rd Edition, FP1<br />S60 3rd Edition, FP2  
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Tested on devices''' || Nokia E90 Communicator<br />Nokia N95 8 GB
+
|signing= Self Signed
|-
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|'''Category''' || Symbian C++
+
|keywords= CWindowGc, CGraphicsContext, TRect, CCoeControl::Draw
|'''Subcategory''' || UI
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
|-
+
|translated-by= <!-- [[User:XXXX]] -->
|'''APIs''' || None
+
|translated-from-title= <!-- Title only -->
|'''Classes''' || CWindowGc<br />CGraphicsContext<br />TRect
+
|translated-from-id= <!-- Id of translated revision -->
|-
+
|review-by= <!-- After re-review: [[User:username]] -->
|'''Methods''' || CCoeControl::Draw
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|&nbsp; ||&nbsp;
+
|update-by= <!-- After significant update: [[User:username]]-->
|}
+
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080206
 +
|author= [[User:Tapiolaitinen]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS000824
 +
}}
  
 
==Overview==
 
==Overview==
  
In this code snippet, a custom border is drawn around a GUI component.
+
{{Abstract|This code snippet demonstrates how to draw a custom border around a GUI component.}}
 
+
This snippet can be self-signed.
+
  
 
==Header file==
 
==Header file==
  
Override <tt>CCoeControl::Draw</tt> method.
+
Override the {{Icode|CCoeControl::Draw}} method.
  
<code>
+
<code cpp>
 
// From CCoeControl
 
// From CCoeControl
 
public:
 
public:
Line 36: Line 39:
 
     void Draw(const TRect& aRect) const;
 
     void Draw(const TRect& aRect) const;
 
</code>
 
</code>
 +
  
 
==Source file==
 
==Source file==
Line 41: Line 45:
 
Define the color of the border:
 
Define the color of the border:
  
<code>
+
<code cpp>
#define KBorderColor   TRgb(180, 0, 0)
+
#define KBorderColor TRgb(180, 0, 0)
 
</code>
 
</code>
  
The drawing is implemented in <tt>CCoeControl::Draw</tt> method so that the border is drawn every time the view is drawn.
+
The drawing is implemented in the {{Icode|CCoeControl::Draw}} method so that the border is drawn every time the view is drawn.
  
<code>
+
<code cpp>
 
// Draws the view.
 
// Draws the view.
 
void CAppView::Draw(const TRect& aRect) const
 
void CAppView::Draw(const TRect& aRect) const
Line 56: Line 60:
 
     gc.SetBrushColor(KBorderColor);
 
     gc.SetBrushColor(KBorderColor);
 
     TRect rect = iComponent->Rect();
 
     TRect rect = iComponent->Rect();
     // Grow the border rectangle so that it becomes visible. Without this,
+
     // Enlarge the border rectangle so that it becomes visible. Without this,
 
     // the rect would only contain the innards of the component, which will
 
     // the rect would only contain the innards of the component, which will
 
     // be obscured by the component itself.
 
     // be obscured by the component itself.
Line 64: Line 68:
 
</code>
 
</code>
  
[[Category:Symbian C++]][[Category:UI]][[Category:Code Examples]]
+
{{VersionHint}}
 +
<!-- Translation --> [[zh-hans:如何绘制自定义边框]]

Latest revision as of 08:57, 18 September 2012

Article Metadata
Tested with
Devices(s): Nokia E90 Communicator
Nokia N95 8GB
CompatibilityPlatform Security
Signing Required: Self Signed
Article
Keywords: CWindowGc, CGraphicsContext, TRect, CCoeControl::Draw
Created: tapiolaitinen (06 Feb 2008)
Last edited: hamishwillee (18 Sep 2012)

Contents

[edit] Overview

This code snippet demonstrates how to draw a custom border around a GUI component.

[edit] Header file

Override the CCoeControl::Draw method.

// From CCoeControl
public:
// Draws the view.
void Draw(const TRect& aRect) const;


[edit] Source file

Define the color of the border:

#define KBorderColor TRgb(180, 0, 0)

The drawing is implemented in the CCoeControl::Draw method so that the border is drawn every time the view is drawn.

// Draws the view.
void CAppView::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
 
// Draw the border around the component (iComponent)
gc.SetBrushColor(KBorderColor);
TRect rect = iComponent->Rect();
// Enlarge the border rectangle so that it becomes visible. Without this,
// the rect would only contain the innards of the component, which will
// be obscured by the component itself.
rect.Grow(3, 3);
gc.DrawRect(rect);
}

[edit] Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 18 September 2012, at 08:57.
80 page views in the last 30 days.
×