public boolean drawBackground(ConstraintWidget widgetToDraw,ViewTransform transform,Graphics2D g,int w,int h){
  boolean needsRepaint=false;
  Color backgroundColor=mColorSet.getBackground();
  Paint backgroundPaint=mColorSet.getBackgroundPaint();
  if (mCurrentAnimation != null) {
    if (mCurrentAnimation.step()) {
      needsRepaint=true;
    }
    backgroundColor=mCurrentAnimation.getColor();
  }
  mColorSet.setBackgroundPaint(backgroundColor);
  int backgroundFactorColor=backgroundColor.getRGB();
  WidgetContainer root=mWidgetsScene.getRoot();
  if (root == null || root != widgetToDraw) {
    return needsRepaint;
  }
  int xr=transform.getSwingX(root.getDrawX());
  int yr=transform.getSwingY(root.getDrawY());
  w=transform.getSwingDimension(root.getWidth());
  h=transform.getSwingDimension(root.getHeight());
  int tileSize=transform.getSwingDimension(8);
  if (!DRAW_GRID) {
    backgroundPaint=backgroundColor;
  }
 else   if (mBackgroundFactorColor != backgroundFactorColor || mBackgroundFactorX != xr || mBackgroundFactorY != yr || mBackgroundFactorSize != tileSize) {
    mBackgroundFactorColor=backgroundFactorColor;
    mBackgroundFactorX=xr;
    mBackgroundFactorY=yr;
    mBackgroundFactorSize=tileSize;
    if (tileSize > 0) {
      GraphicsEnvironment environment=GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice device=environment.getDefaultScreenDevice();
      GraphicsConfiguration config=device.getDefaultConfiguration();
      BufferedImage image=config.createCompatibleImage(tileSize,tileSize);
      Graphics2D graphics=image.createGraphics();
      graphics.setColor(backgroundColor);
      graphics.fillRect(0,0,tileSize,tileSize);
      Color backgroundLines=ColorTheme.updateBrightness(backgroundColor,1.06f);
      graphics.setColor(backgroundLines);
      graphics.drawLine(0,tileSize - 1,tileSize,tileSize - 1);
      graphics.drawLine(tileSize - 1,0,tileSize - 1,tileSize);
      graphics.dispose();
      backgroundPaint=new TexturePaint(image,new Rectangle(xr + 1,yr + 1,tileSize,tileSize));
      mColorSet.setBackgroundPaint(backgroundPaint);
    }
  }
  if (DRAW_ONLY_ROOT_BACKGROUND) {
    Paint paint=g.getPaint();
    g.setPaint(backgroundPaint);
    g.fillRect(xr,yr,w,h);
    g.setPaint(paint);
  }
 else {
    g.fillRect((int)transform.getTranslateX(),(int)transform.getTranslateY(),w,h);
    g.setColor(backgroundColor);
    g.fillRect(0,0,w,h);
    int wr=transform.getSwingDimension(root.getDrawWidth());
    int hr=transform.getSwingDimension(root.getDrawHeight());
    g.setPaint(backgroundPaint);
    g.fillRect((int)transform.getTranslateX(),(int)transform.getTranslateY(),wr,hr);
  }
  return needsRepaint;
}

public boolean drawBackground ( ConstraintWidget widgetToDraw , ViewTransform transform , Graphics2D g , int w , int h ) { boolean needsRepaint = false ; Color backgroundColor = mColorSet . getBackground ( ) ; Paint backgroundPaint = mColorSet . getBackgroundPaint ( ) ; if ( mCurrentAnimation != null ) { if ( mCurrentAnimation . step ( ) ) { needsRepaint = true ; } backgroundColor = mCurrentAnimation . getColor ( ) ; } mColorSet . setBackgroundPaint ( backgroundColor ) ; int backgroundFactorColor = backgroundColor . getRGB ( ) ; WidgetContainer root = mWidgetsScene . getRoot ( ) ; if ( root == null || root != widgetToDraw ) { return needsRepaint ; } int xr = transform . getSwingX ( root . getDrawX ( ) ) ; int yr = transform . getSwingY ( root . getDrawY ( ) ) ; w = transform . getSwingDimension ( root . getWidth ( ) ) ; h = transform . getSwingDimension ( root . getHeight ( ) ) ; int tileSize = transform . getSwingDimension ( 8 ) ; if ( ! DRAW_GRID ) { backgroundPaint = backgroundColor ; } else if ( mBackgroundFactorColor != backgroundFactorColor || mBackgroundFactorX != xr || mBackgroundFactorY != yr || mBackgroundFactorSize != tileSize ) { mBackgroundFactorColor = backgroundFactorColor ; mBackgroundFactorX = xr ; mBackgroundFactorY = yr ; mBackgroundFactorSize = tileSize ; if ( tileSize > 0 ) { GraphicsEnvironment environment = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) ; GraphicsDevice device = environment . getDefaultScreenDevice ( ) ; GraphicsConfiguration config = device . getDefaultConfiguration ( ) ; BufferedImage image = config . createCompatibleImage ( tileSize , tileSize ) ; Graphics2D graphics = image . createGraphics ( ) ; graphics . setColor ( backgroundColor ) ; graphics . fillRect ( 0 , 0 , tileSize , tileSize ) ; Color backgroundLines = ColorTheme . updateBrightness ( backgroundColor , 1.06f ) ; graphics . setColor ( backgroundLines ) ; graphics . drawLine ( 0 , tileSize - 1 , tileSize , tileSize - 1 ) ; graphics . drawLine ( tileSize - 1 , 0 , tileSize - 1 , tileSize ) ; graphics . dispose ( ) ; backgroundPaint = new TexturePaint ( image , new Rectangle ( xr + 1 , yr + 1 , tileSize , tileSize ) ) ; mColorSet . setBackgroundPaint ( backgroundPaint ) ; } } if ( DRAW_ONLY_ROOT_BACKGROUND ) { Paint paint = g . getPaint ( ) ; g . setPaint ( backgroundPaint ) ; g . fillRect ( xr , yr , w , h ) ; g . setPaint ( paint ) ; } else { g . fillRect ( ( int ) transform . getTranslateX ( ) , ( int ) transform . getTranslateY ( ) , w , h ) ; g . setColor ( backgroundColor ) ; g . fillRect ( 0 , 0 , w , h ) ; int wr = transform . getSwingDimension ( root . getDrawWidth ( ) ) ; int hr = transform . getSwingDimension ( root . getDrawHeight ( ) ) ; g . setPaint ( backgroundPaint ) ; g . fillRect ( ( int ) transform . getTranslateX ( ) , ( int ) transform . getTranslateY ( ) , wr , hr ) ; } return needsRepaint ; }
draw a background for the view by creating an caching a texture scaled according to the transform
