/*------------------------------------------------------------------------------
 src/bin/djview/windowView.cxx

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

//#define DJ_DBG
#include "window.h"
#include "widget.h"
#include "app.h"
#include <djMenuWidget.h>

namespace djview {

void Window::viewCallback(bool)
{
  if (! _callbacks) return;
  toolUpdate();
}

void Window::viewLeftCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewLeft();
}

void Window::viewRightCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewRight();
}

void Window::viewUpCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewUp();
}

void Window::viewDownCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewDown();
}

void Window::viewZoomInCallback(bool)
{
  if (! _callbacks) return;
  _viewWidget->viewZoomIn();
}

void Window::viewZoomInCallback() { viewZoomInCallback(true); }

void Window::viewZoomOutCallback(bool)
{
  if (! _callbacks) return;
  _viewWidget->viewZoomOut();
}

void Window::viewZoomOutCallback() { viewZoomOutCallback(true); }

void Window::viewZoomResetCallback(bool)
{
  if (! _callbacks) return;
  _viewWidget->viewZoomReset();
}

void Window::viewZoomResetCallback() { viewZoomResetCallback(true); }

void Window::viewCenterCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewCenter();
}

void Window::viewResetCallback()
{
  if (! _callbacks) return;
  _viewWidget->viewReset();
}

void Window::viewFitCallback(bool)
{
  if (! _callbacks) return;
  _viewWidget->viewFit();
}

void Window::viewFitCallback() { viewFitCallback(true); }

void Window::viewMirrorCallback()
{
  if (! _callbacks) return;
  imageMirror(
    ImageOpMirror::MIRROR(dj::find(_viewMenuMirrorId, _menubar->value()))
  );
}

void Window::viewRotateCallback()
{
  if (! _callbacks) return;
  imageRotate(
    ImageOpRotate90::ROTATE(dj::find(_viewMenuRotateId, _menubar->value()))
  );
}

void Window::viewImageOpCallback()
{
  if (! _callbacks) return;
  imageOp(dj::find(_viewMenuImageOpId, _menubar->value()));
}

void Window::viewBg(const Color & in)
{
  _viewWidget->viewBg(in);
  _viewWidget->redraw();
}

void Window::viewHud(bool in)
{
  if (in == _viewHud) return;
  _viewHud = in;
  viewHudUpdate();
  menuUpdate();
  _viewWidget->redraw();
}

void Window::viewHudCallback()
{
  if (! _callbacks) return;
  viewHud(! _viewHud);
}

void Window::viewHudUpdate()
{
  _callbacks = false;

  _viewWidget->hud(_viewHud);
  _viewWidget->fileName(_fileName);
  _viewWidget->pixelDataInfo(_image ? PixelDataInfo(*_image) : PixelDataInfo());
  _viewWidget->imageTagList(_image ? _image->tagList() : ImageTagList());
  _viewWidget->playbackFrame(
    _playbackFrame, _playbackFrameStart, _playbackFrameEnd
  );
  _viewWidget->playbackSpeed(
    _playbackSpeed, _playbackSpeedReal, _playbackDroppedFrames
  );

  _callbacks = true;
}

}
