|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include "HgVgButton.h" |
|
21 #include "HgVgHelper.h" |
|
22 #include <VG/vgu.h> |
|
23 #include <gulicon.h> |
|
24 |
|
25 |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CHgVgButton::NewL() |
|
30 // Two-phased constructor. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CHgVgButton* CHgVgButton::NewL( const TSize& aSize, const TPoint& aPosition, |
|
34 const CGulIcon& aIcon ) |
|
35 { |
|
36 CHgVgButton* self = new ( ELeave ) CHgVgButton( aSize, aPosition ); |
|
37 CleanupStack::PushL (self ); |
|
38 self->ConstructL(aIcon); |
|
39 CleanupStack::Pop ( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CHgVgButton::ConstructL() |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CHgVgButton::ConstructL (const CGulIcon& aIcon) |
|
49 { |
|
50 iImage = HgVgHelper::CreateVgImageFromIconL(aIcon); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CHgVgButton::CHgVgButton() |
|
55 // C++ default constructor can NOT contain any code, that might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CHgVgButton::CHgVgButton( const TSize& aSize, const TPoint& aPosition ) : |
|
59 iSize(aSize), |
|
60 iPosition(aPosition), |
|
61 iImage(VG_INVALID_HANDLE), |
|
62 iEnabled(ETrue), |
|
63 iPointerDown(EFalse) |
|
64 { |
|
65 |
|
66 |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CHgVgButton::~CHgVgButton() |
|
71 // Destructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CHgVgButton::~CHgVgButton ( ) |
|
75 { |
|
76 |
|
77 |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CHgVgButton::HandlePointerEvent() |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 TBool CHgVgButton::HandlePointerEvent(const TPointerEvent& aEvent) |
|
85 { |
|
86 if (!iEnabled) |
|
87 return EFalse; |
|
88 |
|
89 TRect rect(iPosition, iSize); |
|
90 TBool result = EFalse; |
|
91 |
|
92 if( aEvent.iType == TPointerEvent::EButton1Down && |
|
93 rect.Contains(aEvent.iPosition) && !iPointerDown ) |
|
94 { |
|
95 iPointerDown = ETrue; |
|
96 result = ETrue; |
|
97 } |
|
98 else if( aEvent.iType == TPointerEvent::EButton1Up ) |
|
99 { |
|
100 iPointerDown = EFalse; |
|
101 result = EFalse; |
|
102 } |
|
103 |
|
104 return result; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CHgVgButton::Enabled() |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TBool CHgVgButton::IsEnabled() const |
|
112 { |
|
113 return iEnabled; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CHgVgButton::Position() |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 const TPoint& CHgVgButton::Position() const |
|
121 { |
|
122 return iPosition; |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CHgVgButton::Size() |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 const TSize& CHgVgButton::Size() const |
|
130 { |
|
131 return iSize; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CHgVgButton::SetEnabled() |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CHgVgButton::SetEnabled(TBool aEnabled) |
|
139 { |
|
140 iEnabled = aEnabled; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CHgVgButton::SetPosition() |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CHgVgButton::SetPosition(const TPoint& aPosition) |
|
148 { |
|
149 iPosition = aPosition; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CHgVgButton::SetSize() |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CHgVgButton::SetSize(const TSize& aSize) |
|
157 { |
|
158 iSize = aSize; |
|
159 } |
|
160 |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CHgVgButton::SetIconL() |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CHgVgButton::Draw(const TRect& aWindowRect, TReal aAlpha) |
|
167 { |
|
168 if (iEnabled) |
|
169 { |
|
170 TRgb color(KRgbWhite); |
|
171 color.SetAlpha(aAlpha * 255.0f); |
|
172 HgVgHelper::DrawImageColorized(iImage, color, iPosition, aWindowRect, EFalse, iLandscape); |
|
173 } |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CHgVgButton::EnableLanscapeRendering() |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CHgVgButton::EnableLandscapeRendering(TBool aEnabled) |
|
181 { |
|
182 iLandscape = aEnabled; |
|
183 } |
|
184 |
|
185 |
|
186 // End of File |