/*------------------------------------------------------------------------------
 src/lib/djWidget/colorSwatchWidget.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djColorWidget.h"
#include <FL/fl_draw.h>

namespace dj {

ColorSwatchWidget::ColorSwatchWidget() :
  Fl_Box(0, 0, 0, 0)
{
  box(FL_DOWN_FRAME);
}

void ColorSwatchWidget::set(const Color & in)
{
  if (in == _value) return;
  _value = in;
  _sig.emit(_value);
  redraw();
}

void ColorSwatchWidget::resize(int x, int y, int w, int h)
{
  Fl_Box::resize(x, y, w, h);
  WidgetBase::resize(x, y, w, h);
}

int ColorSwatchWidget::visible() const { return Fl_Box::visible(); }

void ColorSwatchWidget::draw()
{
  Color tmp(PIXEL_RGB, PIXEL_U8);
  convert(_value, &tmp);
  fl_rectf(x(), y(), w(), h(), tmp.u8(0), tmp.u8(1), tmp.u8(2));
  Fl_Box::draw();
}

}
