sysperfana/heapanalyser/Libraries/UI/HeapCtrlLib/Renderers/Contents/HeapCellRendererColourByIsolation.cs
changeset 8 15296fd0af4a
equal deleted inserted replaced
7:8e12a575a9b5 8:15296fd0af4a
       
     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 HeapCellRendererColourByIsolation : HeapCellRendererByColour, IHeapCellRendererContent 
       
    57     {
       
    58         #region Constructors & destructor
       
    59         public HeapCellRendererColourByIsolation()
       
    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.CellNumberOfReferencesLowest.RelationshipManager.ReferencedBy.Count + 1;
       
    70                 double logMin = Math.Log( (double) min );
       
    71                 //
       
    72                 int max = aReconstructor.Statistics.StatsAllocated.CellNumberOfReferencesGreatest.RelationshipManager.ReferencedBy.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 
       
   101             // Draw actual cell
       
   102             SymRect boxRect = new SymRect( aPosition, aBoxSize );
       
   103             boxRect.HalfOffset( aPaddingSize );
       
   104             using ( SolidBrush brush = new SolidBrush( aMetaData.CellBoxColor ) )
       
   105             {
       
   106                 aGraphics.FillRectangle( brush, boxRect.Rectangle );
       
   107             }
       
   108 
       
   109             // If first box, we show the number of inwards links to the cell
       
   110             HeapCell.TRegion region = aMetaData.Region;
       
   111             if ( region == HeapCell.TRegion.EHeader && aMetaData.CellBoxIndex == 0 )
       
   112             {
       
   113                 boxRect.Inflate( KShrinkSize, KShrinkSize );
       
   114 
       
   115                 // Draw the fill
       
   116                 Color lightenColor = ColourUtils.LightenMore( 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                 int count = aCell.RelationshipManager.ReferencedBy.Count;
       
   129                 if ( count == 0 )
       
   130                 {
       
   131                     PaintBoxedText( count.ToString(), aGraphics, Color.Red, boxRect );
       
   132                 }
       
   133                 else
       
   134                 {
       
   135                     PaintBoxedTextWithLuminanceHandling( count.ToString(), aGraphics, Color.Black, boxRect );
       
   136                 }
       
   137             }
       
   138         }
       
   139 
       
   140         public bool SupportsFiltering
       
   141         {
       
   142             get { return false; }
       
   143         }
       
   144 
       
   145         public void SetupFilters()
       
   146         {
       
   147         }
       
   148         #endregion
       
   149 
       
   150         #region Internal methods
       
   151         private Color ColourForHeapCell( HeapCell aCell )
       
   152         {
       
   153             float rF = KRampBaselineColourStart.R;
       
   154             float gF = KRampBaselineColourStart.G;
       
   155             float bF = KRampBaselineColourStart.B;
       
   156             //
       
   157             float count = aCell.RelationshipManager.ReferencedBy.Count + 1.0f;
       
   158             float val = (float) Math.Log( count );
       
   159             val /= iDomain;
       
   160             //
       
   161             rF += ( ( KRampBaselineColourEnd.R - KRampBaselineColourStart.R ) * val );
       
   162             gF += ( ( KRampBaselineColourEnd.G - KRampBaselineColourStart.G ) * val );
       
   163             bF += ( ( KRampBaselineColourEnd.B - KRampBaselineColourStart.B ) * val );
       
   164             //
       
   165             int r = Math.Min( Math.Max( 0, (int) rF ), 255 );
       
   166             int g = Math.Min( Math.Max( 0, (int) gF ), 255 );
       
   167             int b = Math.Min( Math.Max( 0, (int) bF ), 255 );
       
   168             //
       
   169             return System.Drawing.Color.FromArgb( r, g, b );
       
   170         }
       
   171         #endregion
       
   172 
       
   173         #region Internal constants
       
   174         private Color KRampBaselineColourStart = Color.DarkBlue;
       
   175         private Color KRampBaselineColourEnd = Color.Coral;
       
   176         private const float KHeaderBoxWidth = 2.0f;
       
   177         private const int KShrinkSize = -3;
       
   178         private const float KBorderLightenAmount = 0.2f;
       
   179         #endregion
       
   180 
       
   181         #region Data members
       
   182         private float iDomain = 0.01f;
       
   183         #endregion
       
   184     }
       
   185 }