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.
23 #include "Progressbar.h"
24 #include "Interface.h"
27 Progressbar::Progressbar( unsigned short KnobStepsCount
, bool Clear
)
32 this->KnobStepsCount
= KnobStepsCount
;
35 KnobXPos
= KnobYPos
= 0;
36 CapXPos
= CapYPos
= 0;
37 ResetEventHandler( EndReached
);
40 Progressbar::~Progressbar()
45 core
->GetVideoDriver()->FreeSprite( BackGround
);
46 core
->GetVideoDriver()->FreeSprite( BackGround2
);
48 core
->GetVideoDriver()->FreeSprite( PBarCap
);
51 /** Draws the Control on the Output Display */
52 void Progressbar::Draw(unsigned short x
, unsigned short y
)
54 //it is unlikely that a floating window is above us, but...
55 if (!Changed
&& !(Owner
->Flags
&WF_FLOAT
) ) {
64 if((Value
>= 100) && KnobStepsCount
&& BackGround2
) {
65 bcksprite
=BackGround2
; //animated progbar end stage
71 Region
r( x
+ XPos
, y
+ YPos
, Width
, Height
);
72 core
->GetVideoDriver()->BlitSprite( bcksprite
,
73 x
+ XPos
, y
+ YPos
, true, &r
);
74 if( bcksprite
==BackGround2
) {
75 return; //done for animated progbar
82 //linear progressbar (pst, iwd)
83 int w
= BackGround2
->Width
;
84 int h
= BackGround2
->Height
;
85 //this is the PST/IWD specific part
87 Region
r( x
+ XPos
+ KnobXPos
, y
+ YPos
+ KnobYPos
, Count
, h
);
88 core
->GetVideoDriver()->BlitSprite( BackGround2
,
91 core
->GetVideoDriver()->BlitSprite( PBarCap
,
92 x
+XPos
+CapXPos
+Count
-PBarCap
->Width
, y
+YPos
+CapYPos
, true );
96 //animated progressbar (bg2)
97 Count
=Value
*KnobStepsCount
/100;
98 for(unsigned int i
=0; i
<Count
;i
++ ) {
99 Sprite2D
*Knob
= PBarAnim
->GetFrame(i
);
100 core
->GetVideoDriver()->BlitSprite( Knob
, x
, y
, true );
104 /** Returns the actual Progressbar Position */
105 unsigned int Progressbar::GetPosition()
110 /** Sets the actual Progressbar Position trimming to the Max and Min Values */
111 void Progressbar::SetPosition(unsigned int pos
)
120 void Progressbar::RedrawProgressbar(const char* VariableName
, int Sum
)
122 if (strnicmp( VarName
, VariableName
, MAX_VARIABLE_LENGTH
)) {
125 SetPosition((unsigned int) Sum
);
126 if((Value
==100) && Changed
)
127 RunEventHandler( EndReached
);
130 /** Sets the selected image */
131 void Progressbar::SetImage(Sprite2D
* img
, Sprite2D
* img2
)
133 if (BackGround
&& Clear
)
134 core
->GetVideoDriver()->FreeSprite( BackGround
);
136 if (BackGround2
&& Clear
)
137 core
->GetVideoDriver()->FreeSprite( BackGround2
);
142 void Progressbar::SetBarCap(Sprite2D
* img3
)
144 core
->GetVideoDriver()->FreeSprite( PBarCap
);
148 void Progressbar::SetAnimation(Animation
*arg
)
154 void Progressbar::SetSliderPos(int x
, int y
, int x2
, int y2
)
162 /* dummy virtual function */
163 int Progressbar::SetText(const char* /*string*/, int /*pos*/)
168 bool Progressbar::SetEvent(int eventType
, const char *handler
)
173 case IE_GUI_PROGRESS_END_REACHED
:
174 SetEventHandler( EndReached
, handler
);