|
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.Reconstructor; |
|
45 using SymbianUtils.Graphics; |
|
46 using SymbianUtils.Colour; |
|
47 using HeapCtrlLib.Interfaces; |
|
48 using HeapCtrlLib.Utilities; |
|
49 using HeapCtrlLib.Renderers; |
|
50 using HeapCtrlLib.Renderers.Contents.Bases; |
|
51 |
|
52 namespace HeapCtrlLib.Renderers.Contents |
|
53 { |
|
54 internal class HeapCellRendererColourByAge : HeapCellRendererByColour, IHeapCellRendererContent |
|
55 { |
|
56 #region Constructors & destructor |
|
57 public HeapCellRendererColourByAge() |
|
58 { |
|
59 } |
|
60 #endregion |
|
61 |
|
62 #region From IHeapCellRendererContent |
|
63 public void Initialise( HeapCellArray aCells, HeapReconstructor aReconstructor, HeapDataRenderer aRenderer ) |
|
64 { |
|
65 if ( aReconstructor != null ) |
|
66 { |
|
67 iHighestCellAllocationNumber = aReconstructor.Statistics.StatsAllocated.CellAllocationNumberLargest.AllocationNumber; |
|
68 } |
|
69 } |
|
70 |
|
71 public void PrepareToNavigate( HeapRenderingNavigator aNavigator ) |
|
72 { |
|
73 iLargestRectangleCalculator = new HeapCellLargestRectangleCalculator( aNavigator ); |
|
74 } |
|
75 |
|
76 public void HeapCellRenderingComplete( Graphics aGraphics, HeapCell aCell, HeapCellMetaData aMetaData ) |
|
77 { |
|
78 Color fillColour = CellColour( aCell ); |
|
79 // |
|
80 string text = aCell.SymbolStringWithoutDescriptorPrefix; |
|
81 PaintBoxedTextWithLuminanceHandling( text, aGraphics, fillColour ); |
|
82 } |
|
83 |
|
84 public void RenderingComplete( Graphics aGraphics ) |
|
85 { |
|
86 } |
|
87 |
|
88 public void PaintContent( Graphics aGraphics, HeapCellMetaData aMetaData, HeapCell aCell, uint aAddress, Point aPosition, Size aBoxSize, Size aPaddingSize ) |
|
89 { |
|
90 // Get the cell colour that is associated with the cell symbol object type. This |
|
91 // makes oldest cells very light and youngest cells very dark. We really want |
|
92 // it the other way around... |
|
93 aMetaData.CellBoxColor = CellColour( aCell ); |
|
94 |
|
95 // Draw actual cell |
|
96 SymRect boxRect = new SymRect( aPosition, aBoxSize ); |
|
97 boxRect.HalfOffset( aPaddingSize ); |
|
98 |
|
99 using ( SolidBrush brush = new SolidBrush( aMetaData.CellBoxColor ) ) |
|
100 { |
|
101 aGraphics.FillRectangle( brush, boxRect.Rectangle ); |
|
102 } |
|
103 } |
|
104 |
|
105 public bool SupportsFiltering |
|
106 { |
|
107 get { return false; } |
|
108 } |
|
109 |
|
110 public void SetupFilters() |
|
111 { |
|
112 } |
|
113 #endregion |
|
114 |
|
115 #region Internal methods |
|
116 public Color CellColour( HeapCell aCell ) |
|
117 { |
|
118 Color fillColour = Color.LightGray; |
|
119 // |
|
120 if ( aCell.Type == HeapCell.TType.EAllocated ) |
|
121 { |
|
122 // Get the cell colour that is associated with the cell symbol object type. This |
|
123 // makes oldest cells very light and youngest cells very dark. We really want |
|
124 // it the other way around... |
|
125 // |
|
126 float maxBrightness = KRampBaselineColour.GetBrightness(); |
|
127 float allocationNumberPercentage = ((float) aCell.AllocationNumber / (float) iHighestCellAllocationNumber ); |
|
128 float targetBrightness = allocationNumberPercentage * maxBrightness; |
|
129 float amountToDarkenBy = maxBrightness - targetBrightness; |
|
130 fillColour = ColourUtils.Darken( KRampBaselineColour, amountToDarkenBy ); |
|
131 } |
|
132 // |
|
133 return fillColour; |
|
134 } |
|
135 #endregion |
|
136 |
|
137 #region Internal constants |
|
138 private Color KRampBaselineColour = Color.LightBlue; |
|
139 #endregion |
|
140 |
|
141 #region Data members |
|
142 private uint iHighestCellAllocationNumber = 0; |
|
143 private Hashtable iColourHashes = new Hashtable(); |
|
144 #endregion |
|
145 } |
|
146 } |