1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "ControlAnimation.h"
26 #include "Interface.h"
27 #include "Palette.h" /* needed only for paperdoll palettes */
28 #include "Video.h" /* needed only for paperdoll palettes */
29 #include "GUI/Button.h"
31 ControlAnimation::ControlAnimation(Control
* ctl
, const ieResRef ResRef
, int Cycle
)
39 bam
= ( AnimationFactory
* ) gamedata
->GetFactoryResource( ResRef
,
40 IE_BAM_CLASS_ID
, IE_NORMAL
);
46 control
->animation
= this;
50 //freeing the bitmaps only once, but using an intelligent algorithm
51 ControlAnimation::~ControlAnimation(void)
53 //removing from timer first
54 core
->timer
->RemoveAnimation( this );
59 bool ControlAnimation::SameResource(const ieResRef ResRef
, int Cycle
)
61 if (!control
) return false;
62 if (!bam
) return false;
63 if (strnicmp(ResRef
, bam
->ResRef
, sizeof(ieResRef
) )) return false;
65 if (control
->Flags
&IE_GUI_BUTTON_PLAYRANDOM
) {
68 if (Cycle
!=c
) return false;
72 void ControlAnimation::UpdateAnimation(void)
77 if (control
->Flags
& IE_GUI_BUTTON_PLAYRANDOM
) {
78 // simple Finite-State Machine
79 if (anim_phase
== 0) {
82 time
= 500 + 500 * (rand() % 20);
85 } else if (anim_phase
== 1) {
86 if (rand() % 30 == 0) {
99 time
= 100; //hack for slower movement
105 Sprite2D
* pic
= bam
->GetFrame( (unsigned short) frame
, (unsigned char) Cycle
);
108 //stopping at end frame
109 if (control
->Flags
& IE_GUI_BUTTON_PLAYONCE
) {
110 core
->timer
->RemoveAnimation( this );
115 pic
= bam
->GetFrame( 0, (unsigned char) Cycle
);
123 Palette
* palette
= pic
->GetPalette();
124 palette
->SetupPaperdollColours(colors
, 0);
125 pic
->SetPalette(palette
);
129 control
->SetAnimPicture( pic
);
130 core
->timer
->AddAnimation( this, time
);
133 void ControlAnimation::SetPaletteGradients(ieDword
*col
)
135 memcpy(colors
, col
, 8*sizeof(ieDword
));