// Copyright (C) 1999-2015
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#ifndef __colorbar_h__
#define __colorbar_h__

#include "colorbarbase.h"
#include "colormap.h"
#include "colortag.h"
#include "list.h"

// Colormap(s) are X window Colormap ID's. ColorMapInfo(s) contain a fixed 
// number of real RGB color cells. RGB Values of ColorMapInfo(s) are 
// never altered. Colormap(s) are initialized from ColorMapInfo values. 
// Colormap RGB values will changed, based on user input.

class Filter;

class Colorbar : public virtual ColorbarBase {
 public:
  enum ColorTagAction {NONE,CREATE,START,STOP,MOVE};

 protected:
  List<ColorMapInfo> cmaps;
  List<ColorTag> ctags;
  unsigned short* colorIndex;
  float bias;
  float contrast;

  ColorTag* tag;
  ColorTagAction tagaction;
  int taginit;

 private:
  ColorMapInfo* newColorMap(const char*, const char*);

  void psHorz(Filter&, int, int);
  void psVert(Filter&, int, int);

 protected:
  void loadDefaultCMaps();
  void reset();
  int calcContrastBias(int);

#ifdef MAC_OSX_TK
  void macosx(float, int, int, const Vector&, const Vector&);
#endif
#ifdef __WIN32
  void win32(float, int, int, const Vector&, const Vector&);
#endif

 public:
  Colorbar(Tcl_Interp*, Tk_Canvas, Tk_Item*);
  virtual ~Colorbar();

  // commands

  void adjustCmd(float, float);
  void getBiasCmd();
  void getColorbarCmd();
  void getColormapCmd();
  void getColormapNameCmd(int);
  void getColormapFileNameCmd(int);
  void getContrastCmd();
  void getCurrentFileNameCmd();
  void getCurrentIDCmd();
  void getCurrentNameCmd();
  void listIDCmd();
  void listNameCmd();
  void loadCmd(const char*, const char*);
  void loadCmd(const char*, const char*, const char*);
  void mapCmd(char*);
  void mapCmd(int);
  void saveCmd(const char*);
  void saveCmd(int, const char*);
  void setColorbarCmd(int, float, float, int);

  void getTagCmd();
  void getTagCmd(int,int);
  void tagCmd(const char*);
  void tagCmd(int, const Vector&, const char*);
  void tagDeleteCmd();
  void tagDeleteCmd(int,int);
  void tagEditBeginCmd(int,int,const char*);
  void tagEditMotionCmd(int,int);
  void tagEditEndCmd(int,int);
  void tagLoadCmd(const char*);
  void tagSaveCmd(const char*);

  void getRGBChannelCmd();
};

#endif
