2009-04-16 14:14:13 +03:00
# ifndef __ADVENTUREMAPBUTTON_H__
# define __ADVENTUREMAPBUTTON_H__
2009-05-20 13:08:56 +03:00
# include "FunctionList.h"
2009-04-16 14:14:13 +03:00
# include <boost/bind.hpp>
2009-05-20 13:08:56 +03:00
# include "GUIBase.h"
2009-04-16 14:14:13 +03:00
2009-04-15 17:03:31 +03:00
/*
* AdventureMapButton . h , part of VCMI engine
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
2010-01-31 14:10:13 +02:00
*/
extern SDL_Color tytulowy , tlo , zwykly ;
2009-04-16 14:14:13 +03:00
2010-10-18 18:08:59 +03:00
class CAnimation ;
2011-02-20 11:24:53 +02:00
class CAnimImage ;
class CLabel ;
2009-08-07 01:36:51 +03:00
2009-04-16 14:14:13 +03:00
namespace config { struct ButtonInfo ; }
2009-08-17 11:50:31 +03:00
2010-02-07 17:06:14 +02:00
class CButtonBase : public KeyShortcut //basic button class
2009-08-17 11:50:31 +03:00
{
public :
2011-02-20 11:24:53 +02:00
enum ButtonState
2009-08-17 11:50:31 +03:00
{
2011-02-20 11:24:53 +02:00
NORMAL = 0 ,
PRESSED = 1 ,
BLOCKED = 2 ,
HIGHLIGHTED = 3
} ;
private :
int bitmapOffset ; // base offset of visible bitmap from animation
ButtonState state ; //current state of button from enum
public :
bool swappedImages ; //fix for some buttons: normal and pressed image are swapped
void addTextOverlay ( const std : : string & Text , EFonts font , SDL_Color color = zwykly ) ;
void update ( ) ; //to refresh button after image or text change
void setOffset ( int newOffset ) ;
void setState ( ButtonState newState ) ;
ButtonState getState ( ) ;
//just to make code clearer
void block ( bool on ) ;
bool isBlocked ( ) ;
bool isHighlighted ( ) ;
CAnimImage * image ; //image for this button
CLabel * text ; //text overlay
2009-08-17 11:50:31 +03:00
CButtonBase ( ) ; //c-tor
virtual ~ CButtonBase ( ) ; //d-tor
} ;
2009-08-11 19:05:33 +03:00
class AdventureMapButton : public CButtonBase
2009-04-16 14:14:13 +03:00
{
2011-02-20 11:24:53 +02:00
std : : vector < std : : string > imageNames ; //store list of images that can be used by this button
size_t currentImage ;
2009-04-16 14:14:13 +03:00
public :
2011-02-20 11:24:53 +02:00
std : : map < int , std : : string > hoverTexts ; //text for statusbar
2009-04-16 14:14:13 +03:00
std : : string helpBox ; //for right-click help
CFunctionList < void ( ) > callback ;
2011-02-20 11:24:53 +02:00
bool actOnDown , //runs when mouse is pressed down over it, not when up
hoverable ; //if true, button will be highlighted when hovered
2009-04-16 14:14:13 +03:00
2009-08-11 19:05:33 +03:00
void clickRight ( tribool down , bool previousState ) ;
virtual void clickLeft ( tribool down , bool previousState ) ;
2009-04-16 14:14:13 +03:00
void hover ( bool on ) ;
AdventureMapButton ( ) ; //c-tor
AdventureMapButton ( const std : : string & Name , const std : : string & HelpBox , const CFunctionList < void ( ) > & Callback , int x , int y , const std : : string & defName , int key = 0 , std : : vector < std : : string > * add = NULL , bool playerColoredButton = false ) ; //c-tor
2011-02-20 11:24:53 +02:00
AdventureMapButton ( const std : : pair < std : : string , std : : string > & help , const CFunctionList < void ( ) > & Callback , int x , int y , const std : : string & defName , int key = 0 , std : : vector < std : : string > * add = NULL , bool playerColoredButton = false ) ; //c-tor
2009-04-16 14:14:13 +03:00
AdventureMapButton ( const std : : string & Name , const std : : string & HelpBox , const CFunctionList < void ( ) > & Callback , config : : ButtonInfo * info , int key = 0 ) ; //c-tor
void init ( const CFunctionList < void ( ) > & Callback , const std : : map < int , std : : string > & Name , const std : : string & HelpBox , bool playerColoredButton , const std : : string & defName , std : : vector < std : : string > * add , int x , int y , int key ) ;
2011-02-20 11:24:53 +02:00
void setIndex ( size_t index , bool playerColoredButton = false ) ;
void setImage ( CAnimation * anim , bool playerColoredButton = false ) ;
2010-02-20 15:24:38 +02:00
void setPlayerColor ( int player ) ;
2009-04-16 14:14:13 +03:00
} ;
class CHighlightableButton
: public AdventureMapButton
{
public :
2009-05-06 13:14:48 +03:00
CHighlightableButton ( const CFunctionList < void ( ) > & onSelect , const CFunctionList < void ( ) > & onDeselect , const std : : map < int , std : : string > & Name , const std : : string & HelpBox , bool playerColoredButton , const std : : string & defName , std : : vector < std : : string > * add , int x , int y , int key = 0 ) ;
2011-02-20 11:24:53 +02:00
CHighlightableButton ( const std : : pair < std : : string , std : : string > & help , const CFunctionList < void ( ) > & onSelect , int x , int y , const std : : string & defName , int myid , int key = 0 , std : : vector < std : : string > * add = NULL , bool playerColoredButton = false ) ; //c-tor
2009-08-27 11:04:32 +03:00
CHighlightableButton ( const std : : string & Name , const std : : string & HelpBox , const CFunctionList < void ( ) > & onSelect , int x , int y , const std : : string & defName , int myid , int key = 0 , std : : vector < std : : string > * add = NULL , bool playerColoredButton = false ) ; //c-tor
2011-02-20 11:24:53 +02:00
bool onlyOn ; //button can not be de-selected
2010-08-05 14:47:57 +03:00
int ID ; //for identification
2009-08-21 03:59:54 +03:00
CFunctionList < void ( ) > callback2 ; //when de-selecting
2009-04-16 14:14:13 +03:00
void select ( bool on ) ;
2009-08-11 19:05:33 +03:00
void clickLeft ( tribool down , bool previousState ) ;
2009-04-16 14:14:13 +03:00
} ;
2009-08-17 11:50:31 +03:00
class CHighlightableButtonsGroup : public CIntObject
2009-04-16 14:14:13 +03:00
{
public :
CFunctionList2 < void ( int ) > onChange ; //called when changing selected button with new button's id
std : : vector < CHighlightableButton * > buttons ;
2009-05-06 13:14:48 +03:00
bool musicLike ; //determines the behaviour of this group
2009-04-16 14:14:13 +03:00
//void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
void addButton ( CHighlightableButton * bt ) ; //add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
void addButton ( const std : : map < int , std : : string > & tooltip , const std : : string & HelpBox , const std : : string & defName , int x , int y , int uid , const CFunctionList < void ( ) > & OnSelect = 0 , int key = 0 ) ; //creates new button
2009-05-06 13:14:48 +03:00
CHighlightableButtonsGroup ( const CFunctionList2 < void ( int ) > & OnChange , bool musicLikeButtons = false ) ;
2009-04-16 14:14:13 +03:00
~ CHighlightableButtonsGroup ( ) ;
void select ( int id , bool mode ) ; //mode==0: id is serial; mode==1: id is unique button id
void selectionChanged ( int to ) ;
void show ( SDL_Surface * to ) ;
2009-08-17 11:50:31 +03:00
void showAll ( SDL_Surface * to ) ;
2009-08-27 11:04:32 +03:00
void block ( ui8 on ) ;
2009-04-16 14:14:13 +03:00
} ;
2009-08-11 19:05:33 +03:00
class CSlider : public CIntObject
2009-04-16 14:14:13 +03:00
{
public :
2009-08-17 11:50:31 +03:00
AdventureMapButton * left , * right , * slider ; //if vertical then left=up
2009-04-16 14:14:13 +03:00
int capacity , //how many elements can be active at same time
amount , //how many elements
2009-08-17 11:50:31 +03:00
positions , //number of highest position (0 if there is only one)
2009-04-16 14:14:13 +03:00
value ; //first active element
2009-09-13 01:17:23 +03:00
bool horizontal ;
2010-07-06 05:10:26 +03:00
bool wheelScrolling ;
bool keyScrolling ;
2009-04-16 14:14:13 +03:00
boost : : function < void ( int ) > moved ;
void redrawSlider ( ) ;
void sliderClicked ( ) ;
void moveLeft ( ) ;
void moveRight ( ) ;
void moveTo ( int to ) ;
void block ( bool on ) ;
2009-08-17 11:50:31 +03:00
void setAmount ( int to ) ;
2010-07-06 05:10:26 +03:00
void keyPressed ( const SDL_KeyboardEvent & key ) ;
void wheelScrolled ( bool down , bool in ) ;
void clickLeft ( tribool down , bool previousState ) ;
void mouseMoved ( const SDL_MouseMotionEvent & sEvent ) ;
void showAll ( SDL_Surface * to ) ;
2009-04-16 14:14:13 +03:00
CSlider ( int x , int y , int totalw , boost : : function < void ( int ) > Moved , int Capacity , int Amount ,
2009-08-17 11:50:31 +03:00
int Value = 0 , bool Horizontal = true , int style = 0 ) ; //style 0 - brown, 1 - blue
2009-04-16 14:14:13 +03:00
~ CSlider ( ) ;
2010-10-24 14:35:14 +03:00
void moveToMax ( ) ;
2009-04-16 14:14:13 +03:00
} ;
# endif // __ADVENTUREMAPBUTTON_H__