|
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 |
|
19 // INCLUDE FILES |
|
20 #include "perfmon_graphscontainer.h" |
|
21 #include "perfmon.hrh" |
|
22 #include "perfmon_document.h" |
|
23 #include "perfmon_appui.h" |
|
24 #include "perfmon_model.h" |
|
25 |
|
26 #include <AknUtils.h> |
|
27 |
|
28 const TInt KAmountOfMicroSecondsFitsScreen = 20 * 1000000; |
|
29 #define KRgbCustomGrey TRgb(0x808080) |
|
30 |
|
31 _LIT(K100p, "100%"); |
|
32 _LIT(K50p, "50%"); |
|
33 _LIT(K0p, "0%"); |
|
34 |
|
35 _LIT(KPercentageFormat,"%S %d%%"); |
|
36 |
|
37 const TInt KMicroToSecondMultiplier = 1000000; |
|
38 |
|
39 // ===================================== MEMBER FUNCTIONS ===================================== |
|
40 |
|
41 void CPerfMonGraphsContainer::ConstructL(const TRect& aRect) |
|
42 { |
|
43 iModel = static_cast<CPerfMonDocument*>(reinterpret_cast<CEikAppUi*>(iEikonEnv->AppUi())->Document())->Model(); |
|
44 //iFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont); |
|
45 iFont = LatinBold12(); |
|
46 |
|
47 CreateWindowL(); |
|
48 SetRect(aRect); |
|
49 SetBlank(); |
|
50 |
|
51 ActivateL(); |
|
52 } |
|
53 |
|
54 // -------------------------------------------------------------------------------------------- |
|
55 |
|
56 CPerfMonGraphsContainer::~CPerfMonGraphsContainer() |
|
57 { |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------------------------- |
|
61 |
|
62 void CPerfMonGraphsContainer::Draw(const TRect& aRect) const |
|
63 { |
|
64 // draw black background |
|
65 CWindowGc& gc = SystemGc(); |
|
66 gc.SetBrushColor(KRgbBlack); |
|
67 gc.Clear(aRect); |
|
68 |
|
69 // activate font and get size |
|
70 gc.UseFont(iFont); |
|
71 TUint fontSize = iFont->FontMaxHeight(); |
|
72 //TInt fontBaseOffset = iFont->DescentInPixels(); |
|
73 |
|
74 |
|
75 // calculate time factor |
|
76 TReal scaleFactor = (TReal) aRect.Width() / (TReal) KAmountOfMicroSecondsFitsScreen; |
|
77 |
|
78 // calculate area height which is used to draw the grpahs |
|
79 TInt drawAreaHeight = aRect.Height() - fontSize - fontSize; |
|
80 |
|
81 |
|
82 // check if sample array has been constructed |
|
83 if (iModel->SampleEntryArray()) |
|
84 { |
|
85 |
|
86 // draw vertical time lines first |
|
87 TInt verticalBarPeriodInSecs = iModel->Settings().iGraphsVerticalBarPeriod; |
|
88 |
|
89 if (verticalBarPeriodInSecs >= 1 && iModel->SampleEntryArray()->At(0).iSampleDataArray->Count() > 0) |
|
90 { |
|
91 // get time from the first sample |
|
92 TSampleData& firstSample = iModel->SampleEntryArray()->At(0).iSampleDataArray->At(0); |
|
93 TInt64 currentMicroSeconds = firstSample.iTimeFromStart.Int64(); |
|
94 |
|
95 // calculate amount of microseconds exceeding value by using the modulo operator |
|
96 TInt remainderInMicroSeconds = currentMicroSeconds % (verticalBarPeriodInSecs * 1000000); |
|
97 |
|
98 // calculate first x pos |
|
99 TInt vbarXpos = aRect.Width() - (remainderInMicroSeconds * scaleFactor); |
|
100 |
|
101 // calculate the amount in seconds |
|
102 TInt barSeconds = (currentMicroSeconds - remainderInMicroSeconds) / KMicroToSecondMultiplier; |
|
103 |
|
104 |
|
105 // continue drawing periodically the vertical lines |
|
106 while (vbarXpos >= 0 && barSeconds >= 0) |
|
107 { |
|
108 // draw vertical line |
|
109 gc.SetPenColor(KRgbDarkRed); |
|
110 gc.DrawLine(TPoint(vbarXpos,fontSize+1), TPoint(vbarXpos,aRect.Height()-fontSize)); |
|
111 |
|
112 // draw seconds value |
|
113 gc.SetPenColor(KRgbCustomGrey); |
|
114 TBuf<16> secsBuf; |
|
115 secsBuf.AppendNum(barSeconds); |
|
116 secsBuf.Append(_L("s")); |
|
117 gc.DrawText(secsBuf, TPoint(vbarXpos-(iFont->TextWidthInPixels(secsBuf)/2), aRect.Height())); |
|
118 |
|
119 // calculate new position |
|
120 vbarXpos -= verticalBarPeriodInSecs * 1000000 * scaleFactor; |
|
121 barSeconds -= verticalBarPeriodInSecs; |
|
122 } |
|
123 } |
|
124 |
|
125 // draw the basic grid |
|
126 gc.SetPenColor(KRgbCustomGrey); |
|
127 |
|
128 gc.DrawLine(TPoint(0,fontSize), TPoint(aRect.Width(),fontSize)); // upper line |
|
129 gc.DrawText(K100p, TPoint(0,fontSize)); |
|
130 |
|
131 gc.DrawLine(TPoint(0,aRect.Height()/2), TPoint(aRect.Width(),aRect.Height()/2)); // mid line |
|
132 gc.DrawText(K50p, TPoint(0,aRect.Height()/2)); |
|
133 |
|
134 gc.DrawLine(TPoint(0,aRect.Height()-fontSize), TPoint(aRect.Width(),aRect.Height()-fontSize)); // bottom line |
|
135 gc.DrawText(K0p, TPoint(0,aRect.Height()-fontSize)); |
|
136 |
|
137 TInt c(0); |
|
138 |
|
139 // draw graphs for each sampled type |
|
140 for (TInt i=0; i<iModel->SampleEntryArray()->Count(); i++) |
|
141 { |
|
142 // check if this setting has been enabled and it has some data |
|
143 if (iModel->Settings().iGraphsSources.iSrcEnabled[i] && iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() > 0) |
|
144 { |
|
145 // set pen color for the graph |
|
146 gc.SetPenColor(iModel->SampleEntryArray()->At(i).iGraphColor); |
|
147 |
|
148 // remember the position where drawing started |
|
149 /*TReal*/TInt currentXPos(aRect.Width()); // start drawing from right |
|
150 /*TReal*/TInt currentYPos(0); |
|
151 |
|
152 // draw samples |
|
153 for (TInt j=0; j<iModel->SampleEntryArray()->At(i).iSampleDataArray->Count() - 1; j++) |
|
154 { |
|
155 TSampleData& currentSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(j); |
|
156 TSampleData& previousSample = iModel->SampleEntryArray()->At(i).iSampleDataArray->At(j+1); |
|
157 |
|
158 // calculate X position for previous (j+1) |
|
159 /*TReal*/TInt previousXPos = currentXPos - |
|
160 ( (Abs(previousSample.iTimeFromStart.Int64() - currentSample.iTimeFromStart.Int64())) * scaleFactor ); |
|
161 |
|
162 |
|
163 // calculate initial Y position |
|
164 if (j==0) |
|
165 { |
|
166 currentYPos = currentSample.iSize > 0 ? (TReal)(currentSample.iFree) / (TReal)currentSample.iSize * drawAreaHeight + fontSize : aRect.Height()-fontSize; |
|
167 } |
|
168 |
|
169 // calculate Y position for previous (j+1) |
|
170 /*TReal*/TInt previousYPos = previousSample.iSize > 0 ? (TReal)(previousSample.iFree) / (TReal)previousSample.iSize * drawAreaHeight + fontSize : aRect.Height()-fontSize; |
|
171 |
|
172 |
|
173 // draw a line between the previous and current |
|
174 gc.DrawLine(TPoint((TInt)previousXPos,(TInt)previousYPos), TPoint((TInt)currentXPos,(TInt)currentYPos)); |
|
175 |
|
176 |
|
177 // draw current value in % |
|
178 if (j==0) // draw the value of first sample |
|
179 { |
|
180 TBuf<16> buf; |
|
181 buf.Format(KPercentageFormat, &iModel->SampleEntryArray()->At(i).iDescription, currentSample.iSize > 0 ? TInt( (1 - ((TReal)(currentSample.iFree) / (TReal)currentSample.iSize)) * 100) : 0 ); |
|
182 |
|
183 gc.DrawText(buf, TPoint(0,fontSize+fontSize+c*fontSize)); |
|
184 c++; |
|
185 } |
|
186 |
|
187 |
|
188 // stop drawing if we have run out of space |
|
189 if (previousXPos < 0) |
|
190 break; |
|
191 |
|
192 // remeber previous values |
|
193 currentXPos = previousXPos; |
|
194 currentYPos = previousYPos; |
|
195 } |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 gc.DiscardFont(); |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------------------------- |
|
204 |
|
205 TKeyResponse CPerfMonGraphsContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
206 { |
|
207 return CCoeControl::OfferKeyEventL(aKeyEvent, aType); |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------------------------- |
|
211 |
|
212 void CPerfMonGraphsContainer::HandleResourceChange(TInt aType) |
|
213 { |
|
214 if (aType == KEikDynamicLayoutVariantSwitch) |
|
215 { |
|
216 TRect mainPaneRect; |
|
217 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
218 SetRect(mainPaneRect); |
|
219 } |
|
220 else |
|
221 CCoeControl::HandleResourceChange(aType); |
|
222 } |
|
223 |
|
224 // -------------------------------------------------------------------------------------------- |
|
225 |
|
226 void CPerfMonGraphsContainer::DrawUpdate() |
|
227 { |
|
228 DrawDeferred(); |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------------------------- |
|
232 |
|
233 // End of File |