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