|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Drawing; |
|
40 using System.Collections; |
|
41 using HeapLib; |
|
42 using HeapLib.Cells; |
|
43 using HeapLib.Array; |
|
44 using HeapLib.Relationships; |
|
45 using HeapLib.Reconstructor; |
|
46 using HeapCtrlLib.Interfaces; |
|
47 using HeapCtrlLib.Utilities; |
|
48 using HeapCtrlLib.Renderers; |
|
49 using HeapCtrlLib.Renderers.Contents.Bases; |
|
50 using SymbianUtils.Colour; |
|
51 using SymbianUtils.Graphics; |
|
52 using SymbianUtils.RawItems; |
|
53 |
|
54 namespace HeapCtrlLib.Renderers.Contents |
|
55 { |
|
56 internal class HeapCellRendererColourByEmbeddedReferences : HeapCellRendererByColour, IHeapCellRendererContent |
|
57 { |
|
58 #region Constructors & destructor |
|
59 public HeapCellRendererColourByEmbeddedReferences() |
|
60 { |
|
61 } |
|
62 #endregion |
|
63 |
|
64 #region From IHeapCellRendererContent |
|
65 public void Initialise( HeapCellArray aCells, HeapReconstructor aReconstructor, HeapDataRenderer aRenderer ) |
|
66 { |
|
67 if ( aReconstructor != null ) |
|
68 { |
|
69 int min = aReconstructor.Statistics.StatsAllocated.CellNumberOfEmbeddedReferencesLeast.RelationshipManager.EmbeddedReferencesTo.Count + 1; |
|
70 double logMin = Math.Log( (double) min ); |
|
71 // |
|
72 int max = aReconstructor.Statistics.StatsAllocated.CellNumberOfEmbeddedReferencesMost.RelationshipManager.EmbeddedReferencesTo.Count + 1; |
|
73 double logMax = Math.Log( (double) max ); |
|
74 |
|
75 iDomain = (float) ( logMax - logMin ); |
|
76 } |
|
77 } |
|
78 |
|
79 public void PrepareToNavigate( HeapRenderingNavigator aNavigator ) |
|
80 { |
|
81 iLargestRectangleCalculator = new HeapCellLargestRectangleCalculator( aNavigator, 1 /* skip first box, start at 2nd box which has index 1 */ ); |
|
82 } |
|
83 |
|
84 public void HeapCellRenderingComplete( Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData ) |
|
85 { |
|
86 Color fillColour = ColourForHeapCell( aCell ); |
|
87 // |
|
88 string text = aCell.SymbolStringWithoutDescriptorPrefix; |
|
89 PaintBoxedTextWithLuminanceHandling( text, aGraphics, fillColour ); |
|
90 } |
|
91 |
|
92 public void RenderingComplete( Graphics aGraphics ) |
|
93 { |
|
94 } |
|
95 |
|
96 public void PaintContent( Graphics aGraphics, HeapCellMetaData aMetaData, HeapCell aCell, uint aAddress, Point aPosition, Size aBoxSize, Size aPaddingSize ) |
|
97 { |
|
98 // Get the cell colour that is associated with the cell symbol object type |
|
99 aMetaData.CellBoxColor = ColourForHeapCell( aCell ); |
|
100 SymRect boxRect = new SymRect( aPosition, aBoxSize ); |
|
101 boxRect.HalfOffset( aPaddingSize ); |
|
102 |
|
103 // Draw actual cell |
|
104 using ( SolidBrush brush = new SolidBrush( aMetaData.CellBoxColor ) ) |
|
105 { |
|
106 aGraphics.FillRectangle( brush, boxRect.Rectangle ); |
|
107 } |
|
108 |
|
109 HeapCell.TRegion region = aMetaData.Region; |
|
110 if ( region == HeapCell.TRegion.EHeader && aMetaData.CellBoxIndex == 0 ) |
|
111 { |
|
112 // If first box, we show the number of inwards links to the cell |
|
113 boxRect.Inflate( KShrinkSize, KShrinkSize ); |
|
114 |
|
115 // Draw the fill |
|
116 Color lightenColor = ColourUtils.Lighten( aMetaData.CellBoxColor ); |
|
117 using ( SolidBrush brush = new SolidBrush( lightenColor ) ) |
|
118 { |
|
119 aGraphics.FillRectangle( brush, boxRect.Rectangle ); |
|
120 } |
|
121 lightenColor = ColourUtils.Lighten( lightenColor ); |
|
122 using ( Pen borderPen = new Pen( lightenColor, KHeaderBoxWidth ) ) |
|
123 { |
|
124 aGraphics.DrawRectangle( borderPen, boxRect.Rectangle ); |
|
125 } |
|
126 |
|
127 // Draw the count |
|
128 PaintBoxedTextWithLuminanceHandling( aCell.RelationshipManager.EmbeddedReferencesTo.Count.ToString(), aGraphics, Color.Black, boxRect ); |
|
129 } |
|
130 else |
|
131 { |
|
132 // If we're in the payload section, then get the raw item corresponding to the address we are drawing |
|
133 RawItem rawItem = aMetaData.RawItem; |
|
134 if ( rawItem != null && rawItem.Tag != null && rawItem.Tag is HeapLib.Relationships.RelationshipInfo ) |
|
135 { |
|
136 RelationshipInfo relInfo = (RelationshipInfo) rawItem.Tag; |
|
137 |
|
138 // Make the box a bit smaller |
|
139 boxRect.Inflate( KShrinkSize, KShrinkSize ); |
|
140 |
|
141 // Draw the fill |
|
142 Color lightenColor = ColourUtils.Lighten( aMetaData.CellBoxColor ); |
|
143 using ( SolidBrush brush = new SolidBrush( lightenColor ) ) |
|
144 { |
|
145 aGraphics.FillRectangle( brush, boxRect.Rectangle ); |
|
146 } |
|
147 lightenColor = ColourUtils.Lighten( lightenColor ); |
|
148 using ( Pen borderPen = new Pen( lightenColor, KHeaderBoxWidth ) ) |
|
149 { |
|
150 aGraphics.DrawRectangle( borderPen, boxRect.Rectangle ); |
|
151 |
|
152 // If it's a clean reference, then draw a diagonal line to decorate the box reference |
|
153 if ( relInfo.IsCleanLink ) |
|
154 { |
|
155 Point linePosStart = boxRect.TopLeft; |
|
156 linePosStart.X += KHeaderBoxLineCornerOffset; |
|
157 Point linePosEnd = boxRect.TopLeft; |
|
158 linePosEnd.Y += KHeaderBoxLineCornerOffset; |
|
159 // |
|
160 aGraphics.DrawLine( borderPen, linePosStart, linePosEnd ); |
|
161 } |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 |
|
167 public bool SupportsFiltering |
|
168 { |
|
169 get { return false; } |
|
170 } |
|
171 |
|
172 public void SetupFilters() |
|
173 { |
|
174 } |
|
175 #endregion |
|
176 |
|
177 #region Internal methods |
|
178 private Color ColourForHeapCell( HeapCell aCell ) |
|
179 { |
|
180 Color ret = KBaselineColourDescriptor; |
|
181 // |
|
182 if ( !aCell.IsDescriptor ) |
|
183 { |
|
184 float rF = KRampBaselineColourStart.R; |
|
185 float gF = KRampBaselineColourStart.G; |
|
186 float bF = KRampBaselineColourStart.B; |
|
187 // |
|
188 float count = aCell.RelationshipManager.EmbeddedReferencesTo.Count + 1.0f; |
|
189 float val = (float) Math.Log( count ); |
|
190 val /= iDomain; |
|
191 // |
|
192 rF += ( ( KRampBaselineColourEnd.R - KRampBaselineColourStart.R ) * val ); |
|
193 gF += ( ( KRampBaselineColourEnd.G - KRampBaselineColourStart.G ) * val ); |
|
194 bF += ( ( KRampBaselineColourEnd.B - KRampBaselineColourStart.B ) * val ); |
|
195 // |
|
196 int r = Math.Min( Math.Max( 0, (int) rF ), 255 ); |
|
197 int g = Math.Min( Math.Max( 0, (int) gF ), 255 ); |
|
198 int b = Math.Min( Math.Max( 0, (int) bF ), 255 ); |
|
199 // |
|
200 return System.Drawing.Color.FromArgb( r, g, b ); |
|
201 } |
|
202 // |
|
203 return ret; |
|
204 } |
|
205 #endregion |
|
206 |
|
207 #region Internal constants |
|
208 private const int KHeaderBoxLineCornerOffset = 5; |
|
209 private const int KShrinkSize = -3; |
|
210 private const float KBorderLightenAmount = 0.2f; |
|
211 private const float KHeaderBoxWidth = 2.0f; |
|
212 private Color KRampBaselineColourStart = Color.LightBlue; |
|
213 private Color KRampBaselineColourEnd = Color.Red; |
|
214 private Color KBaselineColourDescriptor = Color.Gold; |
|
215 #endregion |
|
216 |
|
217 #region Data members |
|
218 private float iDomain = 0.01f; |
|
219 #endregion |
|
220 } |
|
221 } |