#include "stdafx.h"

#include "mdc_rectangle.h"
#include "mdc_draw_util.h"

using namespace mdc;


RectangleFigure::RectangleFigure(Layer *layer)
: Figure(layer)
{
  _corner_radius= 0.0;
  _corners= CNone;
  _filled= false;
}


void RectangleFigure::stroke_outline(CairoCtx *cr, float offset)
{
  stroke_rounded_rectangle(cr, get_bounds(), _corners, _corner_radius, offset);
}


void RectangleFigure::draw_contents(CairoCtx *cr)
{ 
  cr->set_line_width(_line_width);
  stroke_outline(cr);

  if (_filled)
  {
    if (_fill_color.a != 1.0)
      cr->set_operator(CAIRO_OPERATOR_SOURCE);
    cr->set_color(_fill_color);
    cr->fill_preserve();
    cr->set_color(_pen_color);
    cr->stroke();
  }
  else
  {
    cr->set_color(_pen_color);
    cr->stroke();
  }
}


void RectangleFigure::draw_contents_gl(CairoCtx *cr)
{ 
  //cr->set_line_width(_line_width);

  if (_filled)
  {
    //XXX rounded rect not supported yet

    gl_setcolor(_fill_color);
    gl_rectangle(GL_QUADS, get_bounds());

    gl_setcolor(_pen_color);
    gl_rectangle(GL_LINE_LOOP, get_bounds());
  }
  else
  {
    gl_setcolor(_pen_color);
    gl_rectangle(GL_LINE_LOOP, get_bounds());
  }
}


void RectangleFigure::set_rounded_corners(float radius, CornerMask corners)
{
  _corner_radius= radius;
  _corners= corners;
  set_needs_render();
}


void RectangleFigure::set_filled(bool flag)
{
  _filled= flag;
  set_needs_render();
}

