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

#ifndef DJ_COLOR_WIDGET_H
#define DJ_COLOR_WIDGET_H
#include <djColor.h>
#include <djWidget.h>
#include <FL/Fl_Box.H>

namespace dj {

class LabelWidget;
class IntWidget;
class FloatWidget;
class _IntSliderColorWidget;
class _FloatSliderColorWidget;
class PixelWidget;

// Color swatch widget.
//
class ColorSwatchWidget : public Fl_Box, public WidgetBase {
public:

  ColorSwatchWidget();

  // Value.
  //
  void set(const Color &);
  const Color & get() const { return _value; }
  
  // Signals.
  //
  Signal<const Color &> & sig() { return _sig; }
  
  // Layout.
  //
  const Vec2i sizeHint() const { return Vec2i(layoutThumbnailSize()); }
  void resize(int, int, int, int);
  int visible() const;
  
  // Widget.
  //
  void draw();
  
private:

  Color _value;
  
  Signal<const Color &> _sig;
};

// Color widget.
//
class ColorWidget : public Widget {
public:

  ColorWidget();
  
  // Value.
  //
  void set(const Color &);
  const Color & get() const { return _value; }
  
  // Maximum floating point value.
  //
  void floatMax(double);
  double floatMax() const { return _floatMax; }

  // Signals.
  //
  Signal<const Color &> & sig() { return _sig; }
  
private:

  DJ_CALLBACK(ColorWidget, intCallback, int)
  DJ_CALLBACK(ColorWidget, intSliderCallback, int)
  DJ_CALLBACK(ColorWidget, floatCallback, double)
  DJ_CALLBACK(ColorWidget, floatSliderCallback, double)
  DJ_CALLBACK(ColorWidget, pixelCallback, const Pixel &)

  void widgetUpdate();
  void valueUpdate();

  Color _value;
  double _floatMax;

  Signal<const Color &> _sig;

  //ColorSwatchWidget * _swatchWidget;
  LabelWidget * _labelWidget [pixelFormatMax];
  IntWidget * _intWidget [pixelFormatMax];
  _IntSliderColorWidget * _intSliderWidget [pixelFormatMax];
  FloatWidget * _floatWidget [pixelFormatMax];
  _FloatSliderColorWidget * _floatSliderWidget [pixelFormatMax];
  PixelWidget * _pixelWidget;
  bool _callbacks;
};

}

#endif
