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

#ifndef DJ_IMAGE_WIDGET_H
#define DJ_IMAGE_WIDGET_H
#include <djImage.h>
#include <djWidget.h>
#include <FL/Fl_Gl_Window.H>

namespace dj {

// Image widget.
//
class ImageWidget : public Fl_Gl_Window, public WidgetBase {
public:

  ImageWidget();
  
  // Set.
  //
  virtual void set(const Image *);
  virtual void viewPosition(const Vec2i &);
  virtual void viewZoom(int, const Vec2i & focus);
  virtual void viewPositionZoom(const Vec2i &, int);
  virtual void viewBg(const Color &);
  
  // Get.
  //
  const Image * image() const { return _image; }
  const Vec2i & viewPosition() const { return _viewPosition; }
  int viewZoom() const { return _viewZoom; }
  const Color & viewBg() const { return _viewBg; }
  
  // Actions.
  //
  virtual void viewLeft(int inc = 10);
  virtual void viewRight(int inc = 10);
  virtual void viewUp(int inc = 10);
  virtual void viewDown(int inc = 10);
  virtual void viewCenter();
  virtual void viewZoomIn(const Vec2i &);
  virtual void viewZoomIn();
  virtual void viewZoomOut(const Vec2i &);
  virtual void viewZoomOut();
  virtual void viewZoomReset();
  virtual void viewReset();
  virtual void viewFit();
  
  // Layout.
  //
  void resize(int x, int y, int w, int h);
  int visible() const;
  
  // Widget.
  //
  virtual void draw();
  
  // Utility.
  //
  const Vec2i imageScreenSize() const;
  const Box2i imageScreenBox() const;
  static double zoomToFloat(int);

private:

  const Image * _image;
  Vec2i _viewPosition;
  int _viewZoom;
  Color _viewBg;

  Image _framebuffer, _scanline;
};

// Image view widget.
//
class ImageViewWidget : public ImageWidget {
public:

  ImageViewWidget();
  
  // Get.
  //
  const Vec2i & mouse() const { return _mouse; }
  
  // Actions.
  //
  virtual void viewZoomIn(const Vec2i &);
  virtual void viewZoomIn();
  virtual void viewZoomOut(const Vec2i &);
  virtual void viewZoomOut();
  virtual void viewZoomReset();
  
  // Widget.
  //
  virtual int handle(int);

private:
  
  Vec2i _viewPositionTmp;
  bool _inside;
  Vec2i _mouse, _mouseTd;
};

// XXX Limit max zoom.
//
static const int imageWidgetZoomMax = 10;

}

#endif
