@@ -8,6 +8,7 @@ AnimationEditor::AnimationEditor(QWidget *parent) : QWidget(parent)
8
8
BiggestAnimation = 0 ;
9
9
MouseHoverIndex =-1 ;
10
10
PlusIconImg = new QPixmap (" :/new/prefix1/add.png" );
11
+ DeleteIconImg = new QPixmap (" :/new/prefix1/ics/1455649000_Erase.png" );
11
12
}
12
13
13
14
AnimationEditor::~AnimationEditor ()
@@ -28,34 +29,50 @@ void AnimationEditor::setAnimationBuffer(AnimationBuffer *animbuffer)
28
29
{
29
30
AnimBuffer = animbuffer;
30
31
CursorTiles.clear ();
32
+ this ->setMinimumHeight (TileSizeY*(AnimBuffer->Animations .size ()+1 ));
33
+
34
+ BiggestAnimation=0 ;
35
+ for (int i=0 ;i<AnimBuffer->Animations .count ();i++)
36
+ if ( BiggestAnimation < AnimBuffer->Animations [i].Frames .size () )
37
+ BiggestAnimation = AnimBuffer->Animations [i].Frames .size ();
38
+
39
+ this ->setMinimumWidth (TileSizeX*2 + 5 + BiggestAnimation*TileSizeX);
31
40
this ->repaint ();
32
41
}
33
42
34
43
void AnimationEditor::paintEvent (QPaintEvent *)
35
44
{
36
45
37
46
QPainter pt (this );
47
+ QPixmap *frame;
38
48
39
49
pt.fillRect (this ->rect (),Qt::SolidPattern);
40
50
41
51
pt.drawLine (TileSizeX + 3 , 0 , TileSizeX + 2 , this ->height ());
42
52
43
53
if (Buffer->getCount () > 0 )
44
54
{
45
- if (AnimBuffer->Animations .size () > 0 ){
46
-
55
+ if (AnimBuffer->Animations .size () > 0 )
56
+ {
47
57
for (int i=0 ;i<AnimBuffer->Animations .size (); i++)
48
58
{
49
59
if (AnimBuffer->Animations [i].Frames .size () > 0 )
50
- pt.drawPixmap (0 ,i*TileSizeY, *AnimBuffer->getFramePixmap (i));
60
+ {
61
+ frame = AnimBuffer->getFramePixmap (i);
62
+ if (frame != NULL )
63
+ pt.drawPixmap (0 ,i*TileSizeY, *frame);
64
+ }
51
65
52
66
for (int j=0 ;j<AnimBuffer->Animations [i].Frames .size (); j++)
53
67
{
54
- pt.drawPixmap (j*TileSizeX + TileSizeX + 5 , i*TileSizeY, *Buffer->getTilePixmapAt ( AnimBuffer->Animations [i].Frames [j] ) );
68
+ frame = Buffer->getTilePixmapAt ( AnimBuffer->Animations [i].Frames [j] );
69
+ if (frame != NULL )
70
+ pt.drawPixmap (j*TileSizeX + TileSizeX + 5 , i*TileSizeY, *frame );
55
71
}
56
72
}
57
73
58
74
pt.setPen (Qt::red);
75
+ pt.setBrush (QColor (255 ,250 ,250 ,45 ));
59
76
pt.drawRect (GrabbedAreaRect);
60
77
if (isMouseHovering && ! isMouseDown)
61
78
{
@@ -64,16 +81,30 @@ void AnimationEditor::paintEvent(QPaintEvent *)
64
81
}
65
82
}
66
83
}
84
+
67
85
if (MouseHoverIndex >= 0 )
68
86
{
87
+
69
88
if (MouseHoverIndex >= AnimBuffer->Animations .size ())
89
+ {
70
90
pt.drawPixmap (TileSizeX + 5 +TileSizeX/2 - PlusIconImg->width ()/2
71
91
, AnimBuffer->Animations .size ()*TileSizeY + TileSizeY/2 - PlusIconImg->height ()/2 ,
72
92
*PlusIconImg);
93
+ }
73
94
else
74
- pt.drawPixmap (AnimBuffer->Animations [MouseHoverIndex].Frames .size ()*TileSizeX+TileSizeX+5 + TileSizeX/2 - PlusIconImg->width ()/2 ,
75
- MouseHoverIndex*TileSizeY + TileSizeY/2 - PlusIconImg->height ()/2 ,
76
- *PlusIconImg);
95
+ {
96
+ if ((RemoveIndex < AnimBuffer->Animations [MouseHoverIndex].Frames .size ()))
97
+ {
98
+ if ((RemoveIndex >=0 ))
99
+ pt.drawPixmap (TileSizeX+5 + RemoveIndex*TileSizeX + TileSizeX/2 - DeleteIconImg->width ()/2 ,
100
+ MouseHoverIndex*TileSizeY + TileSizeY/2 - DeleteIconImg->height ()/2 ,
101
+ *DeleteIconImg);
102
+ }
103
+ else
104
+ pt.drawPixmap (AnimBuffer->Animations [MouseHoverIndex].Frames .size ()*TileSizeX+TileSizeX+5 + TileSizeX/2 - PlusIconImg->width ()/2 ,
105
+ MouseHoverIndex*TileSizeY + TileSizeY/2 - PlusIconImg->height ()/2 ,
106
+ *PlusIconImg);
107
+ }
77
108
}
78
109
}
79
110
@@ -82,7 +113,9 @@ void AnimationEditor::mouseMoveEvent(QMouseEvent *ev)
82
113
if (ev->pos ().y ()/TileSizeY >= AnimBuffer->Animations .size ())
83
114
{
84
115
MouseHoverIndex = AnimBuffer->Animations .size ();
116
+ HiglightRect.moveTo (-1000 ,-1000 );
85
117
} else
118
+ {
86
119
if (ev->pos ().x () <= TileSizeX)
87
120
{
88
121
if (isMouseDown)
@@ -100,9 +133,15 @@ void AnimationEditor::mouseMoveEvent(QMouseEvent *ev)
100
133
}
101
134
isMouseHovering = true ;
102
135
isMouseDown = ev->buttons () & Qt::LeftButton;
103
- MouseHoverIndex = -1 ;
136
+ // MouseHoverIndex = -1;
137
+ RemoveIndex = -1 ;
104
138
} else
105
- MouseHoverIndex = (ev->y ()/TileSizeY);
139
+ {
140
+ RemoveIndex = ((ev->x ()-TileSizeX-5 )/TileSizeX);
141
+ HiglightRect.moveTo (-1000 ,-1000 );
142
+ }
143
+ MouseHoverIndex = (ev->y ()/TileSizeY);
144
+ }
106
145
this ->repaint ();
107
146
}
108
147
@@ -117,24 +156,52 @@ void AnimationEditor::mousePressEvent(QMouseEvent *ev)
117
156
GrabbedAreaRect.setHeight (TileSizeY);
118
157
isMouseDown = true ;
119
158
} else
120
- if (CursorTiles.size () > 0 )
159
+ {
160
+ int index = ev->pos ().y ()/TileSizeY;
161
+
162
+ if (index < AnimBuffer->Animations .size ())
121
163
{
122
- int index = ev->pos ().y ()/TileSizeY;
164
+ if (RemoveIndex >= AnimBuffer->Animations [index ].Frames .size () )
165
+ {
166
+ if (CursorTiles.size () > 0 )
167
+ {
168
+ AddFramesFromCursorTo (index );
169
+ emit editingFinished ();
123
170
124
- if (index >= AnimBuffer->Animations .size ())
171
+ if ( BiggestAnimation < AnimBuffer->Animations [index ].Frames .size () )
172
+ BiggestAnimation = AnimBuffer->Animations [index ].Frames .size ();
173
+ }
174
+ }
175
+ else
176
+ {
177
+ if (RemoveIndex >= 0 )
178
+ {
179
+ AnimBuffer->Animations [index ].Frames .remove (RemoveIndex);
180
+ if (AnimBuffer->Animations [index ].Frames .size () <= 0 )
181
+ {
182
+ AnimBuffer->Animations .remove (index );
183
+ }
184
+ emit editingFinished ();
185
+ AnimBuffer->syncAllAnimations ();
186
+ }
187
+ }
188
+ }
189
+ else
190
+ {
191
+ // if (index >= AnimBuffer->Animations.size())
125
192
{
126
193
AddAnimation ();
127
194
index = AnimBuffer->Animations .size ()-1 ;
195
+ AddFramesFromCursorTo (index );
196
+ emit editingFinished ();
197
+ if ( BiggestAnimation < AnimBuffer->Animations [index ].Frames .size () )
198
+ BiggestAnimation = AnimBuffer->Animations [index ].Frames .size ();
128
199
}
129
-
130
- AddFramesFromCursorTo (index );
131
-
132
- if ( BiggestAnimation < AnimBuffer->Animations [index ].Frames .size () )
133
- BiggestAnimation = AnimBuffer->Animations [index ].Frames .size ();
134
200
}
201
+ }
135
202
136
203
this ->setMinimumHeight (TileSizeY*(AnimBuffer->Animations .size ()+1 ));
137
- this ->setMinimumWidth (TileSizeX + 5 + BiggestAnimation*TileSizeX);
204
+ this ->setMinimumWidth (TileSizeX* 2 + 5 + BiggestAnimation*TileSizeX);
138
205
139
206
MouseHoverIndex =-1 ;
140
207
this ->repaint ();
@@ -148,6 +215,7 @@ void AnimationEditor::mouseReleaseEvent(QMouseEvent *ev)
148
215
emit onAnimationSelected ();
149
216
}
150
217
MouseHoverIndex =-1 ;
218
+ mouseMoveEvent (ev);
151
219
this ->repaint ();
152
220
}
153
221
@@ -190,5 +258,6 @@ void AnimationEditor::AddFramesFromCursorTo(int AnimationIndex)
190
258
AnimBuffer->Animations [AnimationIndex].Frames .append (CursorTiles[j][i]);
191
259
}
192
260
AnimBuffer->syncAllAnimations ();
261
+ emit editingFinished ();
193
262
}
194
263
0 commit comments