Jaroslav 203cc8
#pragma once
Jaroslav 203cc8
Jaroslav 203cc8
#ifndef ORIENTATION_INCLUDED
Jaroslav 203cc8
#define ORIENTATION_INCLUDED
Jaroslav 203cc8
Jaroslav 203cc8
#undef DVAPI
Jaroslav 203cc8
#undef DVVAR
Jaroslav 203cc8
#ifdef TOONZLIB_EXPORTS
Jaroslav 203cc8
#define DVAPI DV_EXPORT_API
Jaroslav 203cc8
#define DVVAR DV_EXPORT_VAR
Jaroslav 203cc8
#else
Jaroslav 203cc8
#define DVAPI DV_IMPORT_API
Jaroslav 203cc8
#define DVVAR DV_IMPORT_VAR
Jaroslav 203cc8
#endif
Jaroslav 203cc8
Jaroslav 203cc8
#include "tcommon.h"
Jaroslav 203cc8
#include "cellposition.h"
Jaroslav 203cc8
#include "toonz/cellpositionratio.h"
Jaroslav 203cc8
#include <qpoint></qpoint>
Jaroslav 203cc8
#include <qline></qline>
Jaroslav 203cc8
#include <qrect></qrect>
Jaroslav 203cc8
#include <qpainterpath></qpainterpath>
Jaroslav 203cc8
#include <map></map>
Jaroslav 203cc8
#include <vector></vector>
Jaroslav 203cc8
Jaroslav 203cc8
using std::vector;
Jaroslav 203cc8
using std::map;
Jaroslav 203cc8
Jaroslav 203cc8
// Defines timeline direction: top to bottom;  left to right.
Jaroslav 203cc8
// old (vertical timeline) = new (universal)    = old (kept)
Jaroslav 203cc8
//                x        =   layer axis       =   column
Jaroslav 203cc8
//                y        =   frame axis       =    row
Jaroslav 203cc8
Jaroslav 203cc8
// A pair of numbers
Jaroslav 203cc8
class DVAPI NumberRange {
Jaroslav 203cc8
  int _from, _to;  // _from <= _to
Jaroslav 203cc8
Jaroslav 203cc8
  NumberRange() : _from(0), _to(0) {}
Jaroslav 203cc8
Jaroslav 203cc8
public:
Jaroslav 203cc8
  NumberRange(int from, int to) : _from(min(from, to)), _to(max(from, to)) {}
Jaroslav 203cc8
Jaroslav 203cc8
  int from() const { return _from; }
Jaroslav 203cc8
  int to() const { return _to; }
Jaroslav 203cc8
Jaroslav 203cc8
  int length() const { return _to - _from; }
Jaroslav 203cc8
  int middle() const { return (_to + _from) / 2; }
Jaroslav 203cc8
  int weight(double toWeight) const;
Jaroslav 203cc8
  double ratio(int at) const;
Jaroslav 203cc8
Jaroslav 203cc8
  NumberRange adjusted(int addFrom, int addTo) const;
Jaroslav 203cc8
};
Jaroslav 203cc8
Jaroslav 203cc8
class ColumnFan;
Jaroslav 203cc8
class QPixmap;
Jaroslav 203cc8
class QPainterPath;
Jaroslav 203cc8
Jaroslav 203cc8
//! lists predefined rectangle sizes and positions (relative to top left corner
Jaroslav 203cc8
//! of a cell)
Jaroslav 203cc8
enum class PredefinedRect {
Jaroslav 203cc8
  CELL,                     //! size of a cell
Jaroslav 203cc8
  DRAG_HANDLE_CORNER,       //! area for dragging a cell
Jaroslav 203cc8
  KEY_ICON,                 //! position of key icon
Jaroslav 203cc8
  CELL_NAME,                //! cell name box
Jaroslav 203cc8
  CELL_NAME_WITH_KEYFRAME,  //! cell name box when keyframe is displayed
Jaroslav 203cc8
  END_EXTENDER,             //! bottom / right extender
Jaroslav 203cc8
  BEGIN_EXTENDER,           //! top / left extender
Jaroslav 203cc8
  KEYFRAME_AREA,            //! part of cell dedicated to key frames
Jaroslav 203cc8
  DRAG_AREA,                //! draggable side bar
Jaroslav 203cc8
  SOUND_TRACK,              //! area dedicated to waveform display
Jaroslav 203cc8
  PREVIEW_TRACK,            //! sound preview area
Jaroslav 203cc8
  BEGIN_SOUND_EDIT,         //! top sound resize
Jaroslav 203cc8
  END_SOUND_EDIT,           //! bottom sound resize
Jaroslav 203cc8
  NOTE_AREA,                //! size of top left note controls
Jaroslav 203cc8
  NOTE_ICON,                //! size of note icons that appear in cells area
Jaroslav 203cc8
  FRAME_LABEL,              //! area for writing frame number
Jaroslav 203cc8
  FRAME_HEADER,
Jaroslav 203cc8
  LAYER_HEADER,
shun_iwasawa 0cae24
  FOLDED_LAYER_HEADER,  //! size of layer header when it is folded
shun_iwasawa 0cae24
  PLAY_RANGE,           //! area for play range marker within frame header
shun_iwasawa 0cae24
  ONION,                //! onion handle placement
shun_iwasawa 0cae24
  ONION_DOT,            //! moveable dot placement
shun_iwasawa 0cae24
  ONION_DOT_FIXED,      //! fixed dot placement
shun_iwasawa 0cae24
  ONION_AREA,           //! area where mouse events will alter onion
Jaroslav 203cc8
  ONION_FIXED_DOT_AREA,
Jaroslav 203cc8
  ONION_DOT_AREA,
Jaroslav 203cc8
  PINNED_CENTER_KEY,   //! displays a small blue number
Jaroslav 203cc8
  RENAME_COLUMN,       //! where column rename control appears after clicking
Jaroslav 203cc8
  EYE_AREA,            //! clickable area larger than the eye, containing it
Jaroslav 203cc8
  EYE,                 //! the eye itself
Jaroslav 203cc8
  PREVIEW_LAYER_AREA,  //! clickable area larger than preview icon, containing
Jaroslav 203cc8
                       //! it
Jaroslav 203cc8
  PREVIEW_LAYER,
shun_iwasawa 0cae24
  LOCK_AREA,     //! clickable area larger than lock icon, containing it
shun_iwasawa 0cae24
  LOCK,          //! the lock icon itself
shun_iwasawa 0cae24
  DRAG_LAYER,    //! draggable area in layer header
shun_iwasawa 0cae24
  LAYER_NAME,    //! where to display column name. clicking will rename
Jaroslav 203cc8
  LAYER_NUMBER,  //! where to display column number.
Jaroslav 203cc8
  SOUND_ICON,
shun_iwasawa 0cae24
  VOLUME_TRACK,        //! area where track is displayed
shun_iwasawa 0cae24
  VOLUME_AREA,         //! active area for volume control
shun_iwasawa 0cae24
  LOOP_ICON,           //! area for repeat animation icon
shun_iwasawa 0cae24
  LAYER_HEADER_PANEL,  //! panel displaying headers for the layer rows in
shun_iwasawa 0cae24
                       //! timeline mode
shun_iwasawa 0cae24
  THUMBNAIL_AREA,      //! area for header thumbnails and other icons
shun_iwasawa 0cae24
  THUMBNAIL,           //! the actual thumbnail, if there is one
shun_iwasawa 0cae24
  PEGBAR_NAME,         //! where to display pegbar name
shun_iwasawa 0cae24
  PARENT_HANDLE_NAME,  //! where to display parent handle number
manongjohn 399e7d
  FILTER_COLOR,        //! where to show layer's filter color
manongjohn e71b98
  CONFIG_AREA,  //! clickable area larger than the config icon, containing it
manongjohn e71b98
  CONFIG,       //! the config icon itself
manongjohn a21b06
  FRAME_MARKER_AREA,  //! Cell's frame indicator
manongjohn a21b06
  FRAME_INDICATOR,    //! Row # indicator
manongjohn e71b98
  ZOOM_SLIDER_AREA,
manongjohn e71b98
  ZOOM_SLIDER,
manongjohn e71b98
  ZOOM_IN_AREA,
manongjohn e71b98
  ZOOM_IN,
manongjohn e71b98
  ZOOM_OUT_AREA,
manongjohn e71b98
  ZOOM_OUT,
manongjohn a21b06
  LAYER_FOOTER_PANEL,
manongjohn a21b06
  PREVIEW_FRAME_AREA
Jaroslav 203cc8
};
Jaroslav 203cc8
enum class PredefinedLine {
Jaroslav 203cc8
  LOCKED,              //! dotted vertical line when cell is locked
Jaroslav 203cc8
  SEE_MARKER_THROUGH,  //! horizontal marker visible through drag handle
Jaroslav 203cc8
  CONTINUE_LEVEL,      //! level with the same name represented by vertical line
Jaroslav 203cc8
  CONTINUE_LEVEL_WITH_NAME,  //! adjusted when level name is on each marker
Jaroslav 203cc8
  EXTENDER_LINE              //! see grid through extender handle
Jaroslav 203cc8
};
Jaroslav 203cc8
enum class PredefinedDimension {
Jaroslav 203cc8
  LAYER,                 //! width of a layer column / height of layer row
Jaroslav 203cc8
  FRAME,                 //! height of frame row / width of frame column
Jaroslav 203cc8
  INDEX,                 //! index of this orientation in the array of all
Jaroslav 203cc8
  SOUND_AMPLITUDE,       //! amplitude of sound track, in pixels
Jaroslav 203cc8
  FRAME_LABEL_ALIGN,     //! alignment flag for frame number
Jaroslav 203cc8
  ONION_TURN,            //! onion handle turn in degrees
Jaroslav 203cc8
  QBOXLAYOUT_DIRECTION,  //! direction of QBoxLayout
Jaroslav 203cc8
  CENTER_ALIGN,          //! horizontal / vertical align
Jaroslav 203cc8
};
Jaroslav 203cc8
enum class PredefinedPath {
Jaroslav 203cc8
  DRAG_HANDLE_CORNER,   //! triangle corner at drag sidebar
Jaroslav 203cc8
  BEGIN_EASE_TRIANGLE,  //! triangle marking beginning of ease range
Jaroslav 203cc8
  END_EASE_TRIANGLE,    //! triangle marking end of ease range
Jaroslav 203cc8
  BEGIN_PLAY_RANGE,     //! play range markers
Jaroslav 203cc8
  END_PLAY_RANGE,
Jaroslav 203cc8
  VOLUME_SLIDER_TRACK,  //! slider track
manongjohn 1be264
  VOLUME_SLIDER_HEAD,   //! slider head
manongjohn a21b06
  TIME_INDICATOR_HEAD,  //! current time indicator head
manongjohn a21b06
  FRAME_MARKER_DIAMOND
Jaroslav 203cc8
};
Jaroslav 203cc8
enum class PredefinedPoint {
Jaroslav 203cc8
  KEY_HIDDEN,  //! move extender handle that much if key icons are disabled
Jaroslav 203cc8
  EXTENDER_XY_RADIUS,        //! x and y radius for rounded rectangle
Jaroslav 203cc8
  VOLUME_DIVISIONS_TOP_LEFT  //! where to draw volume slider
Jaroslav 203cc8
};
Jaroslav 203cc8
enum class PredefinedRange {
Jaroslav 203cc8
  HEADER_FRAME,  //! size of of column header height(v) / row header width(h)
Jaroslav 203cc8
  HEADER_LAYER,  //! size of row header width(v) / column header height(h)
Jaroslav 203cc8
};
manongjohn 399e7d
enum class PredefinedFlag {
manongjohn 399e7d
  DRAG_LAYER_BORDER,
manongjohn 399e7d
  DRAG_LAYER_VISIBLE,
manongjohn 399e7d
  LAYER_NAME_BORDER,
manongjohn 399e7d
  LAYER_NAME_VISIBLE,
manongjohn 399e7d
  LAYER_NUMBER_BORDER,
manongjohn 399e7d
  LAYER_NUMBER_VISIBLE,
manongjohn 399e7d
  EYE_AREA_BORDER,
manongjohn 399e7d
  EYE_AREA_VISIBLE,
manongjohn 399e7d
  LOCK_AREA_BORDER,
manongjohn 399e7d
  LOCK_AREA_VISIBLE,
manongjohn 399e7d
  PREVIEW_LAYER_AREA_BORDER,
manongjohn 399e7d
  PREVIEW_LAYER_AREA_VISIBLE,
manongjohn 399e7d
  CONFIG_AREA_BORDER,
manongjohn 399e7d
  CONFIG_AREA_VISIBLE,
manongjohn 399e7d
  PEGBAR_NAME_BORDER,
manongjohn 399e7d
  PEGBAR_NAME_VISIBLE,
manongjohn 399e7d
  PARENT_HANDLE_NAME_BORDER,
manongjohn 399e7d
  PARENT_HANDLE_NAME_VISIBILE,
manongjohn 399e7d
  THUMBNAIL_AREA_BORDER,
manongjohn 399e7d
  THUMBNAIL_AREA_VISIBLE,
manongjohn 399e7d
  VOLUME_AREA_VERTICAL
manongjohn 399e7d
};
Jaroslav 203cc8
Jaroslav 203cc8
// Knows everything about geometry of a particular orientation.
Jaroslav 203cc8
class DVAPI Orientation {
Jaroslav 203cc8
protected:
Jaroslav 203cc8
  map<predefinedrect, qrect=""> _rects;</predefinedrect,>
Jaroslav 203cc8
  map<predefinedline, qline=""> _lines;</predefinedline,>
Jaroslav 203cc8
  map<predefineddimension, int=""> _dimensions;</predefineddimension,>
Jaroslav 203cc8
  map<predefinedpath, qpainterpath=""> _paths;</predefinedpath,>
Jaroslav 203cc8
  map<predefinedpoint, qpoint=""> _points;</predefinedpoint,>
Jaroslav 203cc8
  map<predefinedrange, numberrange=""> _ranges;</predefinedrange,>
manongjohn 399e7d
  map<predefinedflag, bool=""> _flags;</predefinedflag,>
Jaroslav 203cc8
Jaroslav 203cc8
public:
Jaroslav 203cc8
  virtual CellPosition xyToPosition(const QPoint &xy,
Jaroslav 203cc8
                                    const ColumnFan *fan) const = 0;
Jaroslav 203cc8
  virtual QPoint positionToXY(const CellPosition &position,
Jaroslav 203cc8
                              const ColumnFan *fan) const                = 0;
Jaroslav 203cc8
  virtual CellPositionRatio xyToPositionRatio(const QPoint &xy) const    = 0;
Jaroslav 203cc8
  virtual QPoint positionRatioToXY(const CellPositionRatio &ratio) const = 0;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual int colToLayerAxis(int layer, const ColumnFan *fan) const = 0;
Jaroslav 203cc8
  virtual int rowToFrameAxis(int frame) const = 0;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QPoint frameLayerToXY(int frameAxis, int layerAxis) const = 0;
Jaroslav 203cc8
  QRect frameLayerRect(const NumberRange &frameAxis,
Jaroslav 203cc8
                       const NumberRange &layerAxis) const;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual NumberRange layerSide(const QRect &area) const = 0;
Jaroslav 203cc8
  virtual NumberRange frameSide(const QRect &area) const = 0;
Jaroslav 203cc8
  virtual int layerAxis(const QPoint &xy) const          = 0;
Jaroslav 203cc8
  virtual int frameAxis(const QPoint &xy) const          = 0;
Jaroslav 203cc8
  //! top right corner in vertical layout. bottom left in horizontal
Jaroslav 203cc8
  virtual QPoint topRightCorner(const QRect &area) const = 0;
Jaroslav 203cc8
  QRect foldedRectangle(int layerAxis, const NumberRange &frameAxis,
Jaroslav 203cc8
                        int i) const;
Jaroslav 203cc8
  QLine foldedRectangleLine(int layerAxis, const NumberRange &frameAxis,
Jaroslav 203cc8
                            int i) const;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual CellPosition arrowShift(int direction) const = 0;
Jaroslav 203cc8
Jaroslav 203cc8
  //! line was vertical in vertical timeline. adjust accordingly
Jaroslav 203cc8
  QLine verticalLine(int layerAxis, const NumberRange &frameAxis) const;
Jaroslav 203cc8
  QLine horizontalLine(int frameAxis, const NumberRange &layerAxis) const;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual bool isVerticalTimeline() const = 0;
Jaroslav 203cc8
  virtual bool flipVolume() const         = 0;
Jaroslav 203cc8
Jaroslav 203cc8
  virtual QString name() const            = 0;
Jaroslav 203cc8
  virtual QString caption() const         = 0;
Jaroslav 203cc8
  virtual const Orientation *next() const = 0;
Jaroslav 203cc8
Jaroslav 203cc8
  const QRect &rect(PredefinedRect which) const { return _rects.at(which); }
Jaroslav 203cc8
  const QLine &line(PredefinedLine which) const { return _lines.at(which); }
Jaroslav 203cc8
  int dimension(PredefinedDimension which) const {
Jaroslav 203cc8
    return _dimensions.at(which);
Jaroslav 203cc8
  }
Jaroslav 203cc8
  const QPainterPath &path(PredefinedPath which) const {
Jaroslav 203cc8
    return _paths.at(which);
Jaroslav 203cc8
  }
Jaroslav 203cc8
  const QPoint &point(PredefinedPoint which) const { return _points.at(which); }
Jaroslav 203cc8
  const NumberRange &range(PredefinedRange which) const {
Jaroslav 203cc8
    return _ranges.at(which);
Jaroslav 203cc8
  }
manongjohn 399e7d
  const bool &flag(PredefinedFlag which) const { return _flags.at(which); }
Jaroslav 203cc8
manongjohn 2e094e
  virtual int cellWidth() const      = 0;
manongjohn 2e094e
  virtual int cellHeight() const     = 0;
manongjohn 2e094e
  virtual int foldedCellSize() const = 0;
Jaroslav 203cc8
Jaroslav 203cc8
protected:
Jaroslav 203cc8
  void addRect(PredefinedRect which, const QRect &rect);
Jaroslav 203cc8
  void addLine(PredefinedLine which, const QLine &line);
Jaroslav 203cc8
  void addDimension(PredefinedDimension which, int dimension);
Jaroslav 203cc8
  void addPath(PredefinedPath which, const QPainterPath &path);
Jaroslav 203cc8
  void addPoint(PredefinedPoint which, const QPoint &point);
Jaroslav 203cc8
  void addRange(PredefinedRange which, const NumberRange &range);
manongjohn 399e7d
  void addFlag(PredefinedFlag which, const bool &flag);
Jaroslav 203cc8
};
Jaroslav 203cc8
Jaroslav 203cc8
// Enumerates all orientations available in the system as global const objects.
Jaroslav 203cc8
class DVAPI Orientations {
Jaroslav 203cc8
  const Orientation *_topToBottom, *_leftToRight;
Jaroslav 203cc8
  vector<const *="" orientation=""> _all;</const>
Jaroslav 203cc8
Jaroslav 203cc8
  Orientations();
Jaroslav 203cc8
Jaroslav 203cc8
public:
Jaroslav 203cc8
  ~Orientations();
Jaroslav 203cc8
Jaroslav 203cc8
  static const Orientations &instance();
Jaroslav 203cc8
Jaroslav 203cc8
  static const int COUNT = 2;
Jaroslav 203cc8
Jaroslav 203cc8
  static const Orientation *topToBottom();
Jaroslav 203cc8
  static const Orientation *leftToRight();
Jaroslav 203cc8
Jaroslav 203cc8
  static const vector<const *="" orientation=""> &all();</const>
Jaroslav 203cc8
Jaroslav 203cc8
  static const Orientation *byName(const QString &name);
Jaroslav 203cc8
};
Jaroslav 203cc8
Jaroslav 203cc8
#endif