×
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)
Forum Nokia KB (Talk | contribs)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
 
+
{{KBCS}}
 
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"  
 
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"  
 
|-
 
|-
|'''ID''' ||  
+
|'''ID''' || CS000824
|'''Creation date''' || February 6, 2008
+
|'''Creation date''' || February 15, 2008
 
|-
 
|-
|'''Platform''' || S60 3rd Edition<br />S60 3rd Edition, FP1<br />S60 3rd Edition, FP2  
+
|'''Platform''' || S60 3rd Edition<br>S60 3rd Edition, FP1<br>S60 3rd Edition, FP2  
|'''Tested on devices''' || Nokia E90 Communicator<br />Nokia N95 8 GB
+
|'''Tested on devices''' || Nokia E90 Communicator<br>Nokia N95 8GB
 
|-
 
|-
 
|'''Category''' || Symbian C++
 
|'''Category''' || Symbian C++
Line 14: Line 14:
 
|-
 
|-
 
|'''APIs''' || None
 
|'''APIs''' || None
|'''Classes''' || CWindowGc<br />CGraphicsContext<br />TRect
+
|'''Classes''' || CWindowGc<br>CGraphicsContext<br>TRect
 
|-
 
|-
 
|'''Methods''' || CCoeControl::Draw
 
|'''Methods''' || CCoeControl::Draw
Line 22: Line 22:
 
==Overview==
 
==Overview==
  
In this code snippet, a custom border is drawn around a GUI component.
+
This code snippet demonstrates how to draw a custom border around a GUI component.
  
 
This snippet can be self-signed.
 
This snippet can be self-signed.
 +
  
 
==Header file==
 
==Header file==
  
Override <tt>CCoeControl::Draw</tt> method.
+
Override the <tt>CCoeControl::Draw</tt> method.
  
 
<code>
 
<code>
Line 36: Line 37:
 
     void Draw(const TRect& aRect) const;
 
     void Draw(const TRect& aRect) const;
 
</code>
 
</code>
 +
  
 
==Source file==
 
==Source file==
Line 45: Line 47:
 
</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 <tt>CCoeControl::Draw</tt> method so that the border is drawn every time the view is drawn.
  
 
<code>
 
<code>
Line 56: Line 58:
 
     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.

Revision as of 14:47, 15 February 2008


Template:KBCS

ID CS000824 Creation date February 15, 2008
Platform S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition, FP2
Tested on devices Nokia E90 Communicator
Nokia N95 8GB
Category Symbian C++ Subcategory UI
APIs None Classes CWindowGc
CGraphicsContext
TRect
Methods CCoeControl::Draw    

Overview

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

This snippet can be self-signed.


Header file

Override the CCoeControl::Draw method.

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


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);
}
71 page views in the last 30 days.
×