-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAnimation.h
161 lines (110 loc) · 4.52 KB
/
Animation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef ANIMATION_H
#define ANIMATION_H
#include <QObject>
#include <QVector>
#include <QImage>
#include <QGraphicsScene>
#include <QMap>
#include <QGraphicsPixmapItem>
#include <QGraphicsRectItem>
#include <QColor>
#include <QPainter>
#include <QGraphicsSimpleTextItem>
#include <QFont>
#include "BalancePos.h"
#include "Frame.h"
#define ANIM_DRAG_SPACINGY 0.2
#define ANIM_BEFORE -1
#define ANIM_AFTER -2
#define ANIM_NONE -3
class Animation : public QObject
{
Q_OBJECT
Animation(){}
QGraphicsScene* scene;
QVector<Frame*> frames;
int offsetX, offsetY; //Position on the screen
int spacingX, spacingY;
int width;
int curHeight; //Last-calculated height for the animation
QColor frameBgCol;
bool frameBgTransparent;
QImage transparentBg;
unsigned int minWidth; //Minimum width for this animation at the current width
QString name;
QGraphicsSimpleTextItem* label;
bool drawLabel;
bool frameBgVisible;
unsigned int heightRecalc(); //Recalculate where each image is on in the sheet
unsigned int widthOfImages();
public:
explicit Animation(QImage bg, QGraphicsScene* s, QObject *parent = 0);
~Animation();
//Insert an image at the end of the animation and hand over control of the memory
void insertImage(QImage img);
//Insert an image at the specified index and hand over control of the memory
void insertImage(QImage img, unsigned int index);
//Insert a list of images at the end of the animation and hand over control of the memory
void insertImages(QVector<QImage>& imgs);
//Insert a list of images at the specified index and hand over control of the memory
void insertImages(QVector<QImage>& imgs, unsigned int index);
//Remove the selected images from the given animation and add them to this one
void addImages(QVector<Frame*>& imgs, unsigned int index);
QVector<Frame*> pullSelected(int* pullLoc = NULL); //Remove selected frames from this anim
//Set the width of the animation. Return the new height
unsigned int setWidth(unsigned int width);
//Set the spacing between animations and frames
void setSpacing(unsigned int x, unsigned int y);
void setXSpacing(unsigned int x);
void setYSpacing(unsigned int y);
//Set the offset to draw this animation at
void setOffset(unsigned int x, unsigned int y);
//Set the background color for each frame
void setFrameBgCol(QColor c);
//Set the background transparency for each frame
void setFrameBgTransparent(bool b);
//Set the visibility of the frame bg (if both sheet and frame bgs are invisible, don't draw the latter)
void setFrameBgVisible(bool b);
//Get the last-calculated height for the animation
unsigned int getCurHeight() {return curHeight;}
//Reverse the animation
void reverse();
//Get the largest width/height out of all animation frames
QPoint getMaxFrameSize();
//Balance sheet to the given size
//TODO don't include BalanceSheetDialog just for this
void balance(QPoint sz, BalancePos::Pos vert, BalancePos::Pos horiz);
//Test if a point is inside the animation
bool isInside(int x, int y);
unsigned int getMinWidth() {return minWidth;} //Get the minimum width for the current width
unsigned int getSmallestImageWidth(); //Get the smallest possible width for this animation
bool toggleSelect(QGraphicsItem* it); //Select the given item as a frame (return selected)
bool toggleSelect(int pos);
bool hasSelected(); //Return true if any frames in this animation are selected
bool isSelected(QGraphicsItem* it); //Return true if this item is in this sheet and selected
QLine getDragPos(int x, int y);
//Get location in the animation this is dropped.
//ANIM_BEFORE if before this animation, ANIM_AFTER if after, ANIM_NONE if not on this animation
int getDropPos(int x, int y);
bool isEmpty() {return frames.isEmpty();}
void deselectAll();
QVector<Frame*>& getFrames() {return frames;}
QVector<Frame*>* getFramePtr() {return &frames;}
void render(QPainter& painter);
QString getName() {return name;}
void setName(QString s);
void setFont(QFont& f);
void setFontColor(QColor c);
void saveGIF(QString saveFilename, int animFPS);
int getPosX() {return offsetX;}
int getPosY() {return offsetY;}
void setNameVisible(bool b);
void clear();
Frame* getFrame(unsigned int index);
void removeFrame(int index);
void selectAll();
signals:
public slots:
private:
};
#endif // ANIMATION_H