Crossfire Server, Branch 1.12  R12190
CREAnimationControl.cpp
Go to the documentation of this file.
00001 #include <Qt>
00002 
00003 #include "CREAnimationControl.h"
00004 #include "CREAnimationWidget.h"
00005 
00006 CREAnimationControl::CREAnimationControl(QWidget* parent) : QWidget(parent)
00007 {
00008     myAnimation = NULL;
00009     myStep = 0;
00010     myLastStep = 0;
00011 
00012     CREAnimationWidget* widget;
00013     QGridLayout* layout = new QGridLayout(this);
00014 
00015     for (int dir = 1; dir <= 8; dir++)
00016     {
00017         widget = new CREAnimationWidget(this);
00018         widget->setVisible(false);
00019 
00020         layout->addWidget(widget, 2 + freearr_y[dir], 2 + freearr_x[dir]);
00021         myWidgets.append(widget);
00022     }
00023 
00024     QTimer* timer = new QTimer(this);
00025     connect(timer, SIGNAL(timeout()), this, SLOT(step()));
00026     timer->start(250);
00027 }
00028 
00029 void CREAnimationControl::setAnimation(const Animations* animation)
00030 {
00031     myAnimation = animation;
00032     display(animation);
00033 }
00034 
00035 void CREAnimationControl::display(const Animations* animation)
00036 {
00037     myFacings = animation->facings;
00038 
00039     int widget, widgetStep, faceCount, face, faceCurrent;
00040 
00041     for (widget = 0; widget < 8; widget++)
00042         myWidgets[widget]->setVisible(false);
00043 
00044     widget = 0;
00045 
00046     if (myFacings == 1)
00047     {
00048         widgetStep = 8;
00049         faceCount = animation->num_animations;
00050     }
00051     else if (myFacings == 2)
00052     {
00053         widgetStep = 4;
00054         faceCount = animation->num_animations / 2;
00055     }
00056     else if (myFacings == 4)
00057     {
00058         widgetStep = 2;
00059         faceCount = animation->num_animations / 4;
00060     }
00061     else
00062     {
00063         widgetStep = 1;
00064         faceCount = animation->num_animations / 8;
00065     }
00066 
00067     face = 0;
00068     while (widget < 8)
00069     {
00070         myWidgets[widget]->setVisible(true);
00071         QList<int> faces;
00072         for (faceCurrent = 0; faceCurrent < faceCount; faceCurrent++)
00073             faces.append(animation->faces[face++]);
00074         myWidgets[widget]->setAnimation(faces);
00075 
00076         widget += widgetStep;
00077     }
00078 }
00079 
00080 void CREAnimationControl::step()
00081 {
00082     if (myAnimation == NULL)
00083         return;
00084 
00085     for (int w = 0; w < myWidgets.size(); w++)
00086         myWidgets[w]->step();
00087 }