package de.lessvoid.nifty.elements.render;

import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.render.NiftyRenderEngine;
import de.lessvoid.nifty.tools.Color;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Random;

/**
 * The ElementRenderer for a Panel.
 *
 * @author void
 */
public class PanelRenderer implements ElementRenderer {
  /**
   * the background color when used otherwise null.
   */
  @Nullable
  private Color backgroundColor;

  @Nullable
  private Color debugColor;

  /**
   * Default constructor.
   */
  public PanelRenderer() {
  }

  /**
   * render it.
   *
   * @param element the widget we're connected to
   * @param r       the renderDevice we should use
   */
  @Override
  public void render(@Nonnull final Element element, @Nonnull final NiftyRenderEngine r) {
    if (element.getNifty().isDebugOptionPanelColors()) {
      r.saveStates();
      r.setColor(getDebugColor());
      r.renderQuad(element.getX(), element.getY(), element.getWidth(), element.getHeight());
      r.restoreStates();
      return;
    }

    if (backgroundColor != null) {
      r.saveStates();
      if (!r.isColorChanged()) {
        if (r.isColorAlphaChanged()) {
          r.setColorIgnoreAlpha(backgroundColor);
        } else {
          r.setColor(backgroundColor);
        }
      }
      r.renderQuad(element.getX(), element.getY(), element.getWidth(), element.getHeight());
      r.restoreStates();
    }
  }

  @Nonnull
  private Color getDebugColor() {
    if (debugColor != null) {
      return debugColor;
    }
    final Random rnd = new Random();
    debugColor = new Color(rnd.nextFloat(), rnd.nextFloat(), rnd.nextFloat(), .5f);
    return debugColor;
  }

  /**
   * set a background color.
   *
   * @param newBackgroundColor background color
   */
  public void setBackgroundColor(@Nullable final Color newBackgroundColor) {
    this.backgroundColor = newBackgroundColor;
  }
}

@@ -1807,25 +1807,24 @@
 %0D%0A  
-/**%0D%0A   * set a b
+public void setB
 ackg
@@ -1832,54 +1832,65 @@
 ound
- c
+C
 olor
-.%0D%0A   *%0D%0A   * @param newBackgroundColor 
+(@Nullable final Color backgroundColor) %7B%0D%0A    this.
 back
@@ -1899,81 +1899,72 @@
 ound
- c
+C
 olor
-%0D%0A   */%0D%0A  public void setBackgroundColor(@Nullable final
+ = backgroundColor;%0D%0A  %7D%0D%0A%0D%0A  @Nullable%0D%0A  public
  Color 
-new
+get
 Back
@@ -1966,32 +1966,33 @@
 tBackgroundColor
+(
 ) %7B%0D%0A    this.ba
@@ -1988,35 +1988,16 @@
     
-this.backgroundColor = newB
+return b
 ackg

Add method to get panel background color.