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 "Progressbar.h"
25 #include "Interface.h"
30 Progressbar::Progressbar( unsigned short KnobStepsCount
, bool Clear
)
35 this->KnobStepsCount
= KnobStepsCount
;
38 KnobXPos
= KnobYPos
= 0;
39 CapXPos
= CapYPos
= 0;
40 ResetEventHandler( EndReached
);
43 Progressbar::~Progressbar()
48 core
->GetVideoDriver()->FreeSprite( BackGround
);
49 core
->GetVideoDriver()->FreeSprite( BackGround2
);
51 core
->GetVideoDriver()->FreeSprite( PBarCap
);
54 /** Draws the Control on the Output Display */
55 void Progressbar::Draw(unsigned short x
, unsigned short y
)
57 //it is unlikely that a floating window is above us, but...
58 if (!Changed
&& !(Owner
->Flags
&WF_FLOAT
) ) {
67 if((Value
>= 100) && KnobStepsCount
&& BackGround2
) {
68 bcksprite
=BackGround2
; //animated progbar end stage
74 Region
r( x
+ XPos
, y
+ YPos
, Width
, Height
);
75 core
->GetVideoDriver()->BlitSprite( bcksprite
,
76 x
+ XPos
, y
+ YPos
, true, &r
);
77 if( bcksprite
==BackGround2
) {
78 return; //done for animated progbar
85 //linear progressbar (pst, iwd)
86 int w
= BackGround2
->Width
;
87 int h
= BackGround2
->Height
;
88 //this is the PST/IWD specific part
90 Region
r( x
+ XPos
+ KnobXPos
, y
+ YPos
+ KnobYPos
, Count
, h
);
91 core
->GetVideoDriver()->BlitSprite( BackGround2
,
94 core
->GetVideoDriver()->BlitSprite( PBarCap
,
95 x
+XPos
+CapXPos
+Count
-PBarCap
->Width
, y
+YPos
+CapYPos
, true );
99 //animated progressbar (bg2)
100 Count
=Value
*KnobStepsCount
/100;
101 for(unsigned int i
=0; i
<Count
;i
++ ) {
102 Sprite2D
*Knob
= PBarAnim
->GetFrame(i
);
103 core
->GetVideoDriver()->BlitSprite( Knob
, x
, y
, true );
107 /** Returns the actual Progressbar Position */
108 unsigned int Progressbar::GetPosition()
113 /** Sets the actual Progressbar Position trimming to the Max and Min Values */
114 void Progressbar::SetPosition(unsigned int pos
)
123 void Progressbar::RedrawProgressbar(const char* VariableName
, int Sum
)
125 if (strnicmp( VarName
, VariableName
, MAX_VARIABLE_LENGTH
)) {
128 SetPosition((unsigned int) Sum
);
129 if((Value
==100) && Changed
)
130 RunEventHandler( EndReached
);
133 /** Sets the selected image */
134 void Progressbar::SetImage(Sprite2D
* img
, Sprite2D
* img2
)
136 if (BackGround
&& Clear
)
137 core
->GetVideoDriver()->FreeSprite( BackGround
);
139 if (BackGround2
&& Clear
)
140 core
->GetVideoDriver()->FreeSprite( BackGround2
);
145 void Progressbar::SetBarCap(Sprite2D
* img3
)
147 core
->GetVideoDriver()->FreeSprite( PBarCap
);
151 void Progressbar::SetAnimation(Animation
*arg
)
157 void Progressbar::SetSliderPos(int x
, int y
, int x2
, int y2
)
165 /* dummy virtual function */
166 int Progressbar::SetText(const char* /*string*/, int /*pos*/)
171 bool Progressbar::SetEvent(int eventType
, EventHandler handler
)
176 case IE_GUI_PROGRESS_END_REACHED
:
177 EndReached
= handler
;