1 #pragma once 2 3 #ifndef ORIENTATION_INCLUDED 4 #define ORIENTATION_INCLUDED 5 6 #undef DVAPI 7 #undef DVVAR 8 #ifdef TOONZLIB_EXPORTS 9 #define DVAPI DV_EXPORT_API 10 #define DVVAR DV_EXPORT_VAR 11 #else 12 #define DVAPI DV_IMPORT_API 13 #define DVVAR DV_IMPORT_VAR 14 #endif 15 16 #include "tcommon.h" 17 #include "cellposition.h" 18 #include "toonz/cellpositionratio.h" 19 #include <QPoint> 20 #include <QLine> 21 #include <QRect> 22 #include <QPainterPath> 23 #include <map> 24 #include <vector> 25 26 // Defines timeline direction: top to bottom; left to right. 27 // old (vertical timeline) = new (universal) = old (kept) 28 // x = layer axis = column 29 // y = frame axis = row 30 31 // A pair of numbers 32 class DVAPI NumberRange { 33 int _from, _to; // _from <= _to 34 NumberRange()35 NumberRange() : _from(0), _to(0) {} 36 37 public: NumberRange(int from,int to)38 NumberRange(int from, int to) 39 : _from(std::min(from, to)), _to(std::max(from, to)) {} 40 from()41 int from() const { return _from; } to()42 int to() const { return _to; } 43 length()44 int length() const { return _to - _from; } middle()45 int middle() const { return (_to + _from) / 2; } 46 int weight(double toWeight) const; 47 double ratio(int at) const; 48 49 NumberRange adjusted(int addFrom, int addTo) const; 50 }; 51 52 class ColumnFan; 53 class QPixmap; 54 class QPainterPath; 55 56 //! lists predefined rectangle sizes and positions (relative to top left corner 57 //! of a cell) 58 enum class PredefinedRect { 59 CELL, //! size of a cell 60 CAMERA_CELL, //! size of a cell of the camera column 61 DRAG_HANDLE_CORNER, //! area for dragging a cell 62 KEY_ICON, //! position of key icon 63 CAMERA_KEY_ICON, //! position of key icon in the camera column 64 CELL_NAME, //! cell name box 65 CELL_NAME_WITH_KEYFRAME, //! cell name box when keyframe is displayed 66 END_EXTENDER, //! bottom / right extender 67 BEGIN_EXTENDER, //! top / left extender 68 KEYFRAME_AREA, //! part of cell dedicated to key frames 69 DRAG_AREA, //! draggable side bar 70 SOUND_TRACK, //! area dedicated to waveform display 71 PREVIEW_TRACK, //! sound preview area 72 BEGIN_SOUND_EDIT, //! top sound resize 73 END_SOUND_EDIT, //! bottom sound resize 74 NOTE_AREA, //! size of top left note controls 75 NOTE_ICON, //! size of note icons that appear in cells area 76 FRAME_LABEL, //! area for writing frame number 77 FRAME_HEADER, 78 LAYER_HEADER, 79 FOLDED_LAYER_HEADER, //! size of layer header when it is folded 80 CAMERA_LAYER_HEADER, 81 PLAY_RANGE, //! area for play range marker within frame header 82 ONION, //! onion handle placement 83 ONION_DOT, //! moveable dot placement 84 ONION_DOT_FIXED, //! fixed dot placement 85 ONION_AREA, //! area where mouse events will alter onion 86 ONION_FIXED_DOT_AREA, 87 ONION_DOT_AREA, 88 PINNED_CENTER_KEY, //! displays a small blue number 89 RENAME_COLUMN, //! where column rename control appears after clicking 90 EYE_AREA, //! clickable area larger than the eye, containing it 91 EYE, //! the eye itself 92 PREVIEW_LAYER_AREA, //! clickable area larger than preview icon, containing 93 //! it 94 PREVIEW_LAYER, 95 LOCK_AREA, //! clickable area larger than lock icon, containing it 96 LOCK, //! the lock icon itself 97 CAMERA_LOCK_AREA, //! lock area for the camera column 98 CAMERA_LOCK, //! the lock icon for camera column 99 DRAG_LAYER, //! draggable area in layer header 100 LAYER_NAME, //! where to display column name. clicking will rename 101 CAMERA_LAYER_NAME, //! where to display the camera column name 102 LAYER_NUMBER, //! where to display column number. 103 SOUND_ICON, 104 VOLUME_TRACK, //! area where track is displayed 105 VOLUME_AREA, //! active area for volume control 106 LOOP_ICON, //! area for repeat animation icon 107 CAMERA_LOOP_ICON, //! area for repeat icon in the camera column 108 LAYER_HEADER_PANEL, //! panel displaying headers for the layer rows in 109 //! timeline mode 110 THUMBNAIL_AREA, //! area for header thumbnails and other icons 111 THUMBNAIL, //! the actual thumbnail, if there is one 112 CAMERA_ICON_AREA, //! area for the camera column icon 113 CAMERA_ICON, //! the actual camera column icon 114 PEGBAR_NAME, //! where to display pegbar name 115 PARENT_HANDLE_NAME, //! where to display parent handle number 116 FILTER_COLOR, //! where to show layer's filter color 117 CONFIG_AREA, //! clickable area larger than the config icon, containing it 118 CONFIG, //! the config icon itself 119 CAMERA_CONFIG_AREA, //! config area for the camera column 120 CAMERA_CONFIG, //! the config icon for camera column 121 FRAME_MARKER_AREA, //! Cell's frame indicator 122 FRAME_INDICATOR, //! Row # indicator 123 ZOOM_SLIDER_AREA, 124 ZOOM_SLIDER, 125 ZOOM_IN_AREA, 126 ZOOM_IN, 127 ZOOM_OUT_AREA, 128 ZOOM_OUT, 129 LAYER_FOOTER_PANEL, 130 PREVIEW_FRAME_AREA, 131 SHIFTTRACE_DOT, 132 SHIFTTRACE_DOT_AREA, 133 PANEL_EYE, 134 PANEL_PREVIEW_LAYER, 135 PANEL_LOCK, 136 PANEL_LAYER_NAME 137 }; 138 enum class PredefinedLine { 139 LOCKED, //! dotted vertical line when cell is locked 140 SEE_MARKER_THROUGH, //! horizontal marker visible through drag handle 141 CONTINUE_LEVEL, //! level with the same name represented by vertical line 142 CONTINUE_LEVEL_WITH_NAME, //! adjusted when level name is on each marker 143 EXTENDER_LINE //! see grid through extender handle 144 }; 145 enum class PredefinedDimension { 146 LAYER, //! width of a layer column / height of layer row 147 FRAME, //! height of frame row / width of frame column 148 INDEX, //! index of this orientation in the array of all 149 SOUND_AMPLITUDE, //! amplitude of sound track, in pixels 150 FRAME_LABEL_ALIGN, //! alignment flag for frame number 151 ONION_TURN, //! onion handle turn in degrees 152 QBOXLAYOUT_DIRECTION, //! direction of QBoxLayout 153 CENTER_ALIGN, //! horizontal / vertical align 154 CAMERA_LAYER //! width of a camera column / height of camera row 155 }; 156 enum class PredefinedPath { 157 DRAG_HANDLE_CORNER, //! triangle corner at drag sidebar 158 BEGIN_EASE_TRIANGLE, //! triangle marking beginning of ease range 159 END_EASE_TRIANGLE, //! triangle marking end of ease range 160 BEGIN_PLAY_RANGE, //! play range markers 161 END_PLAY_RANGE, 162 VOLUME_SLIDER_TRACK, //! slider track 163 VOLUME_SLIDER_HEAD, //! slider head 164 TIME_INDICATOR_HEAD, //! current time indicator head 165 FRAME_MARKER_DIAMOND 166 }; 167 enum class PredefinedPoint { 168 KEY_HIDDEN, //! move extender handle that much if key icons are disabled 169 EXTENDER_XY_RADIUS, //! x and y radius for rounded rectangle 170 VOLUME_DIVISIONS_TOP_LEFT //! where to draw volume slider 171 }; 172 enum class PredefinedRange { 173 HEADER_FRAME, //! size of of column header height(v) / row header width(h) 174 HEADER_LAYER, //! size of row header width(v) / column header height(h) 175 }; 176 enum class PredefinedFlag { 177 DRAG_LAYER_BORDER, 178 DRAG_LAYER_VISIBLE, 179 LAYER_NAME_BORDER, 180 LAYER_NAME_VISIBLE, 181 LAYER_NUMBER_BORDER, 182 LAYER_NUMBER_VISIBLE, 183 EYE_AREA_BORDER, 184 EYE_AREA_VISIBLE, 185 LOCK_AREA_BORDER, 186 LOCK_AREA_VISIBLE, 187 PREVIEW_LAYER_AREA_BORDER, 188 PREVIEW_LAYER_AREA_VISIBLE, 189 CONFIG_AREA_BORDER, 190 CAMERA_CONFIG_AREA_BORDER, 191 CONFIG_AREA_VISIBLE, 192 CAMERA_CONFIG_AREA_VISIBLE, 193 PEGBAR_NAME_BORDER, 194 PEGBAR_NAME_VISIBLE, 195 PARENT_HANDLE_NAME_BORDER, 196 PARENT_HANDLE_NAME_VISIBILE, 197 THUMBNAIL_AREA_BORDER, 198 THUMBNAIL_AREA_VISIBLE, 199 CAMERA_ICON_VISIBLE, 200 VOLUME_AREA_VERTICAL 201 }; 202 203 // Knows everything about geometry of a particular orientation. 204 class DVAPI Orientation { 205 protected: 206 std::map<PredefinedRect, QRect> _rects; 207 std::map<PredefinedLine, QLine> _lines; 208 std::map<PredefinedDimension, int> _dimensions; 209 std::map<PredefinedPath, QPainterPath> _paths; 210 std::map<PredefinedPoint, QPoint> _points; 211 std::map<PredefinedRange, NumberRange> _ranges; 212 std::map<PredefinedFlag, bool> _flags; 213 214 public: 215 virtual CellPosition xyToPosition(const QPoint &xy, 216 const ColumnFan *fan) const = 0; 217 virtual QPoint positionToXY(const CellPosition &position, 218 const ColumnFan *fan) const = 0; 219 virtual CellPositionRatio xyToPositionRatio(const QPoint &xy) const = 0; 220 virtual QPoint positionRatioToXY(const CellPositionRatio &ratio) const = 0; 221 222 virtual int colToLayerAxis(int layer, const ColumnFan *fan) const = 0; 223 virtual int rowToFrameAxis(int frame) const = 0; 224 225 virtual QPoint frameLayerToXY(int frameAxis, int layerAxis) const = 0; 226 QRect frameLayerRect(const NumberRange &frameAxis, 227 const NumberRange &layerAxis) const; 228 229 virtual NumberRange layerSide(const QRect &area) const = 0; 230 virtual NumberRange frameSide(const QRect &area) const = 0; 231 virtual int layerAxis(const QPoint &xy) const = 0; 232 virtual int frameAxis(const QPoint &xy) const = 0; 233 //! top right corner in vertical layout. bottom left in horizontal 234 virtual QPoint topRightCorner(const QRect &area) const = 0; 235 QRect foldedRectangle(int layerAxis, const NumberRange &frameAxis, 236 int i) const; 237 QLine foldedRectangleLine(int layerAxis, const NumberRange &frameAxis, 238 int i) const; 239 240 virtual CellPosition arrowShift(int direction) const = 0; 241 242 //! line was vertical in vertical timeline. adjust accordingly 243 QLine verticalLine(int layerAxis, const NumberRange &frameAxis) const; 244 QLine horizontalLine(int frameAxis, const NumberRange &layerAxis) const; 245 246 virtual bool isVerticalTimeline() const = 0; 247 virtual bool flipVolume() const = 0; 248 249 virtual QString name() const = 0; 250 virtual QString caption() const = 0; 251 virtual const Orientation *next() const = 0; 252 rect(PredefinedRect which)253 const QRect &rect(PredefinedRect which) const { return _rects.at(which); } line(PredefinedLine which)254 const QLine &line(PredefinedLine which) const { return _lines.at(which); } dimension(PredefinedDimension which)255 int dimension(PredefinedDimension which) const { 256 return _dimensions.at(which); 257 } path(PredefinedPath which)258 const QPainterPath &path(PredefinedPath which) const { 259 return _paths.at(which); 260 } point(PredefinedPoint which)261 const QPoint &point(PredefinedPoint which) const { return _points.at(which); } range(PredefinedRange which)262 const NumberRange &range(PredefinedRange which) const { 263 return _ranges.at(which); 264 } flag(PredefinedFlag which)265 const bool &flag(PredefinedFlag which) const { return _flags.at(which); } 266 267 virtual int cellWidth() const = 0; 268 virtual int cellHeight() const = 0; 269 virtual int foldedCellSize() const = 0; 270 ~Orientation()271 virtual ~Orientation() {} 272 273 protected: 274 void addRect(PredefinedRect which, const QRect &rect); 275 void addLine(PredefinedLine which, const QLine &line); 276 void addDimension(PredefinedDimension which, int dimension); 277 void addPath(PredefinedPath which, const QPainterPath &path); 278 void addPoint(PredefinedPoint which, const QPoint &point); 279 void addRange(PredefinedRange which, const NumberRange &range); 280 void addFlag(PredefinedFlag which, const bool &flag); 281 }; 282 283 // Enumerates all orientations available in the system as global const objects. 284 class DVAPI Orientations { 285 const Orientation *_topToBottom, *_leftToRight; 286 std::vector<const Orientation *> _all; 287 288 Orientations(); 289 290 public: 291 ~Orientations(); 292 293 static const Orientations &instance(); 294 295 static const int COUNT = 2; 296 297 static const Orientation *topToBottom(); 298 static const Orientation *leftToRight(); 299 300 static const std::vector<const Orientation *> &all(); 301 302 static const Orientation *byName(const QString &name); 303 }; 304 305 #endif 306