/*------------------------------------------------------------------------------
 src/bin/djview/window.h

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

#ifndef DJVIEW_WINDOW_H
#define DJVIEW_WINDOW_H
#include "base.h"
#include <djImageIo.h>
#include <djImageOpXform.h>
#include <djWindow.h>

namespace dj {
class TextDisplayWidget;
class IntWidget;
class FloatWidget;
class ToolButtonWidget;
class IntSliderWidget;
class MenuItems;
class MenubarWidget;
};

namespace djview {

class ImageRef;
class FrameSliderWidget;
class PlaybackSpeedDisplayWidget;
class ViewWidget;

// Window.
//
class Window : public dj::Window {
public:

  Window();
  ~Window();
  void die();

  void set(Window *);
  
  // Image.
  //
  void imageUpdate();
  void imageMirror(ImageOpMirror::MIRROR);
  void imageRotate(ImageOpRotate90::ROTATE);
  void imageOp(int);
  void imageOpUpdate();
  void imageOpUpdate(int);
  
  // File.
  //
  void fileOpen(const Str &, bool init = false);
  void fileRecentListUpdate();
  void fileReload();
  void fileProxy(int);
  void filePixelFormat(int);
  void filePixelType(int);
  const Str & fileName() const { return _fileName; }
  
  // Window.
  //
  void windowNew();
  void windowCopy();
  void windowDel();
  void windowFit();
  void windowFullscreen();
  void windowControls(bool);
  
  // View.
  //
  void viewBg(const Color &);
  void viewHud(bool);
  
  // Playback.
  //
  void playback(PLAYBACK);
  void playbackFrame(int);
  void playbackFrameStart();
  void playbackFrameEnd();
  void playbackFramePrev(int = 1);
  void playbackFrameNext(int = 1);
  void playbackIn(bool);
  void playbackOut(bool);
  void playbackInFrame(int);
  void playbackOutFrame(int);
  void playbackInMark();
  void playbackOutMark();
  void playbackSpeed(double);
  void playbackEveryFrame(bool);
  
private:

  // File callbacks.
  //
  DJ_CALLBACK(Window, fileOpenCallback, const Str &)
  DJ_CALLBACK(Window, fileOpenCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, fileOpenCallback)
  DJ_FL_WIDGET_CALLBACK(Window, fileRecentListCallback)
  DJ_FL_WIDGET_CALLBACK(Window, fileReloadCallback)
  DJ_CALLBACK(Window, fileCloseCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, fileCloseCallback)
  DJ_FL_WIDGET_CALLBACK(Window, fileProxyCallback)
  DJ_FL_WIDGET_CALLBACK(Window, filePixelFormatCallback)
  DJ_FL_WIDGET_CALLBACK(Window, filePixelTypeCallback)
  
  // Window callbacks.
  //
  DJ_CALLBACK(Window, windowNewCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, windowNewCallback)
  DJ_CALLBACK(Window, windowCopyCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, windowCopyCallback)
  DJ_CALLBACK(Window, windowDelCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, windowDelCallback)
  DJ_CALLBACK(Window, windowFitCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, windowFitCallback)
  DJ_CALLBACK(Window, windowFullscreenCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, windowFullscreenCallback)
  DJ_FL_WIDGET_CALLBACK(Window, windowControlsCallback)
  
  // View callbacks.
  //
  DJ_CALLBACK(Window, viewCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, viewLeftCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewRightCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewUpCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewDownCallback)
  DJ_CALLBACK(Window, viewZoomInCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, viewZoomInCallback)
  DJ_CALLBACK(Window, viewZoomOutCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, viewZoomOutCallback)
  DJ_CALLBACK(Window, viewZoomResetCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, viewZoomResetCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewCenterCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewResetCallback)
  DJ_CALLBACK(Window, viewFitCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, viewFitCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewMirrorCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewRotateCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewImageOpCallback)
  DJ_FL_WIDGET_CALLBACK(Window, viewHudCallback)

  // Playback callbacks.
  //
  DJ_CALLBACK(Window, playbackStopCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackStopCallback)
  DJ_CALLBACK(Window, playbackForwardCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackForwardCallback)
  DJ_CALLBACK(Window, playbackReverseCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackReverseCallback)
  DJ_CALLBACK(Window, playbackShuttleStartCallback, bool)
  DJ_CALLBACK(Window, playbackShuttleStopCallback, bool)
  DJ_CALLBACK(Window, playbackShuttleValueCallback, int)
  DJ_CALLBACK(Window, playbackFrameStartCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFrameStartCallback)
  DJ_CALLBACK(Window, playbackFrameEndCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFrameEndCallback)
  DJ_CALLBACK(Window, playbackFramePrevCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFramePrevCallback)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFramePrev10Callback)
  DJ_CALLBACK(Window, playbackFrameNextCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFrameNextCallback)
  DJ_FL_WIDGET_CALLBACK(Window, playbackFrameNext10Callback)
  DJ_CALLBACK(Window, playbackFrameCallback, int)
  DJ_CALLBACK(Window, playbackFrameShuttleStartCallback, bool)
  DJ_CALLBACK(Window, playbackFrameShuttleValueCallback, int)
  DJ_CALLBACK(Window, playbackSliderCallback, int)
  DJ_CALLBACK(Window, playbackInCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackInCallback)
  DJ_CALLBACK(Window, playbackInFrameCallback, int)
  DJ_CALLBACK(Window, playbackInMarkCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackInMarkCallback)
  DJ_CALLBACK(Window, playbackOutCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackOutCallback)
  DJ_CALLBACK(Window, playbackOutFrameCallback, int)
  DJ_CALLBACK(Window, playbackOutMarkCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackOutMarkCallback)
  DJ_CALLBACK(Window, playbackSpeedCallback, double)
  DJ_CALLBACK(Window, playbackEveryFrameCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, playbackEveryFrameCallback)
  
  // Tool callbacks.
  //
  DJ_CALLBACK(Window, toolModeCallback, bool)
  DJ_FL_WIDGET_CALLBACK(Window, toolModeCallback)
  DJ_FL_WIDGET_CALLBACK(Window, toolMagnifyCallback)
  DJ_FL_WIDGET_CALLBACK(Window, toolColorSampleCallback)
  DJ_FL_WIDGET_CALLBACK(Window, toolImageInfoCallback)
  DJ_FL_WIDGET_CALLBACK(Window, toolImageOpCallback)
  
  // Callbacks.
  //
  DJ_FL_WIDGET_CALLBACK(Window, prefsCallback)
  DJ_FL_WIDGET_CALLBACK(Window, aboutCallback)
  DJ_FL_WIDGET_CALLBACK(Window, exitCallback)
  DJ_FL_CALLBACK(Window, timerCallback)

  // Update.
  //
  void menuUpdate();
  void windowControlsUpdate();
  void viewHudUpdate();
  void playbackUpdate();
  void playbackFrameUpdate();
  void playbackTimeUpdate();
  void playbackSpeedUpdate();
  void toolUpdate();
  void toolModeUpdate();

  ImageLoad * _imageLoad;
  ImageRef * _imageRef;
  Image _imageTmp, * _image;
  ImageOpMirror::MIRROR _imageMirror;
  ImageOpRotate90::ROTATE _imageRotate;
  int _imageOp;
  
  Str _fileName;
  int _fileProxy, _filePixelFormat, _filePixelType;
  
  bool _windowControls;
  
  bool _viewHud;

  PLAYBACK _playback;
  bool _playbackShuttle;
  int _playbackFrame, _playbackFrameTmp;
  int _playbackFrameStart, _playbackFrameEnd;
  bool _playbackIn, _playbackOut;
  int _playbackInFrame, _playbackOutFrame;
  double _playbackSpeed, _playbackShuttleSpeed, _playbackSpeedReal;
  bool _playbackEveryFrame, _playbackDroppedFrames;
  bool _playbackTimerInit;
  Timer _playbackTimer;
  uint64_t _playbackTimerFrame;
  Timer _playbackSpeedTimer;
  int _playbackSpeedCounter;
  
  bool _toolMode;

  MenuItems * _menuItems;
  MenubarWidget * _menubar;
  Widget * _toolbar, * _playbar;
  
  IntList _fileMenuRecentId, _fileMenuProxyId, _fileMenuPixelFormatId,
    _fileMenuPixelTypeId;
  
  ViewWidget * _viewWidget;
  IntList _viewMenuMirrorId, _viewMenuRotateId, _viewMenuImageOpId;
  
  ToolButtonWidget * _playbackButton [3];
  IntList _playbackMenuId;
  ToolButtonWidget * _playbackFrameStartButton, * _playbackFrameEndButton;
  ToolButtonWidget * _playbackFramePrevButton, * _playbackFrameNextButton;
  IntWidget * _playbackFrameWidget;
  FrameSliderWidget * _playbackSlider;
  TextDisplayWidget * _playbackFrameStartWidget, * _playbackFrameEndWidget;
  ToolButtonWidget * _playbackInButton, * _playbackOutButton;
  IntWidget * _playbackInFrameWidget, * _playbackOutFrameWidget;
  FloatWidget * _playbackSpeedWidget;
  PlaybackSpeedDisplayWidget * _playbackSpeedRealWidget;
  ToolButtonWidget * _playbackEveryFrameWidget;
  
  ToolButtonWidget * _toolModeButton;
  
  bool _callbacks;
};

}

#endif
