topical media & game development

talk show tell print

actionscript-book-FilterWorkbench-flexapp-controls-BGColorCellRenderer.ax

actionscript-book-FilterWorkbench-flexapp-controls-BGColorCellRenderer.ax [swf] flex


  package 
  {
          //import com.example.programmingas3.filterWorkbench.GradientColor;
          
          import mx.controls.DataGrid;
          import mx.controls.Label;
          import mx.controls.dataGridClasses.DataGridListData;
  
          public class @ax-actionscript-book-FilterWorkbench-flexapp-controls-BGColorCellRenderer extends Label
          {
                  public function @ax-actionscript-book-FilterWorkbench-flexapp-controls-BGColorCellRenderer()
                  {
                          super();
                  }
                  
                  
                  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                  { 
                          super.updateDisplayList(unscaledWidth, unscaledHeight);
                          
                          graphics.clear();
                          
                          var grid:DataGrid = DataGrid(DataGridListData(listData).owner);
                          
                          if (grid.isItemSelected(data) || grid.isItemHighlighted(data))
                          {
                                  return;
                          }
                          
                          var gColor:actionscript_book_FilterWorkbench_com_example_programmingas3_filterWorkbench_GradientColor = data as actionscript_book_FilterWorkbench_com_example_programmingas3_filterWorkbench_GradientColor;
                          if (gColor != null)
                          {
                                  // calculate the foreground color
                                  var r:Number = (gColor.color >> 16) & 0xFF;
                                  var g:Number = (gColor.color >> 8) & 0xFF;
                                  var b:Number = gColor.color & 0xFF;
                                  var avg:int = Math.round((r + g + b) / 3);
                                  var foreground:uint = (avg > 0x99 || gColor.alpha < .6) ? 0x000000 : 0xFFFFFF;
                                  setStyle("color", foreground);
                                  
                                  // draw the background
                                  graphics.beginFill(data.color, data.alpha);
                                  graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
                                  graphics.endFill();
                          }
                  }
          }
  }


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.