Crossfire Server, Trunk  R20513
CREAnimationControl.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 #include "CREAnimationControl.h"
4 #include "CREAnimationWidget.h"
5 #include "face.h"
6 
7 CREAnimationControl::CREAnimationControl(QWidget* parent) : QWidget(parent)
8 {
9  myAnimation = NULL;
10  myStep = 0;
11  myLastStep = 0;
12 
13  CREAnimationWidget* widget;
14  QGridLayout* layout = new QGridLayout(this);
15 
16  for (int dir = 1; dir <= 8; dir++)
17  {
18  widget = new CREAnimationWidget(this);
19  widget->setVisible(false);
20 
21  layout->addWidget(widget, 2 + freearr_y[dir], 2 + freearr_x[dir]);
22  myWidgets.append(widget);
23  }
24 
25  QTimer* timer = new QTimer(this);
26  connect(timer, SIGNAL(timeout()), this, SLOT(step()));
27  timer->start(250);
28 }
29 
30 void CREAnimationControl::setAnimation(const Animations* animation, int facings)
31 {
32  myAnimation = animation;
33  display(animation, facings);
34 }
35 
36 void CREAnimationControl::display(const Animations* animation, int facings)
37 {
38  myFacings = facings == -1 ? animation->facings : facings;
39 
40  int widget, widgetStep, faceCount, face, faceCurrent;
41 
42  for (widget = 0; widget < 8; widget++)
43  myWidgets[widget]->setVisible(false);
44 
45  widget = 0;
46 
47  if (myFacings == 1)
48  {
49  widgetStep = 8;
50  faceCount = animation->num_animations;
51  }
52  else if (myFacings == 2)
53  {
54  widgetStep = 4;
55  faceCount = animation->num_animations / 2;
56  }
57  else if (myFacings == 4)
58  {
59  widgetStep = 2;
60  faceCount = animation->num_animations / 4;
61  }
62  else
63  {
64  widgetStep = 1;
65  faceCount = animation->num_animations / 8;
66  }
67 
68  face = facings == -1 ? 0 : 1;;
69  while (widget < 8)
70  {
71  myWidgets[widget]->setVisible(true);
72  QList<int> faces;
73  for (faceCurrent = 0; faceCurrent < faceCount; faceCurrent++)
74  faces.append(animation->faces[face++]->number);
75  myWidgets[widget]->setAnimation(faces);
76 
77  widget += widgetStep;
78  }
79 }
80 
82 {
83  if (myAnimation == NULL)
84  return;
85 
86  for (int w = 0; w < myWidgets.size(); w++)
87  myWidgets[w]->step();
88 }
const Animations * myAnimation
void display(const Animations *animation, int facings=-1)
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.c:65
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
Definition: object.c:71
uint16_t number
This is the image id.
Definition: face.h:15
This represents one animation.
Definition: face.h:26
uint8_t num_animations
How many different faces to animate, size of the faces array.
Definition: face.h:28
Face-related structures.
void setAnimation(const Animations *animation, int facings=-1)
Define the animation to display.
CREAnimationControl(QWidget *parent)
QList< CREAnimationWidget * > myWidgets
const New_Face ** faces
The actual faces for the animation.
Definition: face.h:31
uint8_t facings
How many facings (1,2,4,8).
Definition: face.h:29
Definition: main.c:88