1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-13 01:20:34 +02:00

Second part of GUI reorganization. Some things may not work properly.

This commit is contained in:
Michał W. Urbańczyk
2009-08-11 16:05:33 +00:00
parent 4653396d76
commit 1d765e8f29
20 changed files with 649 additions and 618 deletions

View File

@ -60,7 +60,7 @@ AdventureMapButton::AdventureMapButton( const std::pair<std::string, std::string
pom[0] = help.first; pom[0] = help.first;
init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key); init(Callback, pom, help.second, playerColoredButton, defName, add, x, y, key);
} }
void AdventureMapButton::clickLeft (boost::logic::tribool down) void AdventureMapButton::clickLeft(tribool down, bool previousState)
{ {
if(blocked) if(blocked)
return; return;
@ -71,23 +71,15 @@ void AdventureMapButton::clickLeft (boost::logic::tribool down)
show(screenBuf); show(screenBuf);
if (actOnDown && down) if (actOnDown && down)
{ {
pressedL=state;
//if(!callback.empty())
callback(); callback();
} }
else if (!actOnDown && pressedL && (down==false)) else if (!actOnDown && previousState && (down==false))
{ {
pressedL=state;
//if(!callback.empty())
callback(); callback();
} }
else
{
pressedL=state;
}
} }
void AdventureMapButton::clickRight (boost::logic::tribool down) void AdventureMapButton::clickRight(tribool down, bool previousState)
{ {
if(helpBox.size()) //there is no point to show window with nothing inside... if(helpBox.size()) //there is no point to show window with nothing inside...
LOCPLINT->adventureInt->handleRightClick(helpBox,down,this); LOCPLINT->adventureInt->handleRightClick(helpBox,down,this);
@ -95,7 +87,7 @@ void AdventureMapButton::clickRight (boost::logic::tribool down)
void AdventureMapButton::hover (bool on) void AdventureMapButton::hover (bool on)
{ {
Hoverable::hover(on); ////Hoverable::hover(on);
std::string *name = (vstd::contains(hoverTexts,state)) std::string *name = (vstd::contains(hoverTexts,state))
? (&hoverTexts[state]) ? (&hoverTexts[state])
: (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL); : (vstd::contains(hoverTexts,0) ? (&hoverTexts[0]) : NULL);
@ -128,19 +120,19 @@ void AdventureMapButton::activate()
{ {
if (active) return; if (active) return;
active=true; active=true;
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
KeyInterested::activate(); activateKeys();
} }
void AdventureMapButton::deactivate() void AdventureMapButton::deactivate()
{ {
if (!active) return; if (!active) return;
active=false; active=false;
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
KeyInterested::deactivate(); deactivateKeys();
} }
void AdventureMapButton::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) void AdventureMapButton::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)
@ -216,7 +208,7 @@ void CHighlightableButton::select(bool on)
} }
} }
void CHighlightableButton::clickLeft( tribool down ) void CHighlightableButton::clickLeft(tribool down, bool previousState)
{ {
if(blocked) if(blocked)
return; return;
@ -225,16 +217,11 @@ void CHighlightableButton::clickLeft( tribool down )
else else
state = selected ? 3 : 0; state = selected ? 3 : 0;
show(screenBuf); show(screenBuf);
if (pressedL && (down==false)) if(previousState && down == false)
{ {
pressedL=state;
if(!onlyOn || !selected) if(!onlyOn || !selected)
select(!selected); select(!selected);
} }
else
{
pressedL=state;
}
} }
CHighlightableButton::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) CHighlightableButton::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)
@ -328,7 +315,7 @@ void CSlider::sliderClicked()
{ {
if(!moving) if(!moving)
{ {
MotionInterested::activate(); activateMouseMove();
moving = true; moving = true;
} }
} }
@ -386,7 +373,7 @@ void CSlider::activate() // makes button active
left.activate(); left.activate();
right.activate(); right.activate();
slider.activate(); slider.activate();
ClickableL::activate(); activateLClick();
} }
void CSlider::deactivate() // makes button inactive (but doesn't delete) void CSlider::deactivate() // makes button inactive (but doesn't delete)
@ -394,10 +381,10 @@ void CSlider::deactivate() // makes button inactive (but doesn't delete)
left.deactivate(); left.deactivate();
right.deactivate(); right.deactivate();
slider.deactivate(); slider.deactivate();
ClickableL::deactivate(); deactivateLClick();
} }
void CSlider::clickLeft (tribool down) void CSlider::clickLeft(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -410,7 +397,7 @@ void CSlider::clickLeft (tribool down)
} }
if(moving) if(moving)
{ {
MotionInterested::deactivate(); deactivateMouseMove();
moving = false; moving = false;
} }
} }

View File

@ -19,8 +19,7 @@ class CDefEssential;
namespace config{struct ButtonInfo;} namespace config{struct ButtonInfo;}
class AdventureMapButton class AdventureMapButton : public CButtonBase
: public ClickableR, public Hoverable, public KeyShortcut, public CButtonBase
{ {
public: public:
std::map<int,std::string> hoverTexts; //state -> text for statusbar std::map<int,std::string> hoverTexts; //state -> text for statusbar
@ -30,8 +29,8 @@ public:
actOnDown; //runs when mouse is pressed down over it, not when up actOnDown; //runs when mouse is pressed down over it, not when up
ui8 blocked; ui8 blocked;
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
virtual void clickLeft (boost::logic::tribool down); virtual void clickLeft(tribool down, bool previousState);
void hover (bool on); void hover (bool on);
void block(ui8 on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks void block(ui8 on); //if button is blocked then it'll change it's graphic to inactive (offset==2) and won't react on l-clicks
void activate(); // makes button active void activate(); // makes button active
@ -55,7 +54,7 @@ public:
bool selected, onlyOn; bool selected, onlyOn;
CFunctionList<void()> callback2; //when disselecting CFunctionList<void()> callback2; //when disselecting
void select(bool on); void select(bool on);
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
}; };
class CHighlightableButtonsGroup class CHighlightableButtonsGroup
@ -78,7 +77,7 @@ public:
}; };
class CSlider : public IShowable, public MotionInterested, public ClickableL class CSlider : public CIntObject
{ {
public: public:
AdventureMapButton left, right, slider; //if vertical then left=up AdventureMapButton left, right, slider; //if vertical then left=up
@ -96,7 +95,7 @@ public:
void sliderClicked(); void sliderClicked();
void moveLeft(); void moveLeft();
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void moveRight(); void moveRight();
void moveTo(int to); void moveTo(int to);

View File

@ -267,21 +267,21 @@ void CMinimap::initFlaggableObjs(int level)
void CMinimap::updateRadar() void CMinimap::updateRadar()
{} {}
void CMinimap::clickRight (tribool down) void CMinimap::clickRight(tribool down, bool previousState)
{ {
LOCPLINT->adventureInt->handleRightClick(rcText,down,this); LOCPLINT->adventureInt->handleRightClick(rcText,down,this);
} }
void CMinimap::clickLeft (tribool down) void CMinimap::clickLeft(tribool down, bool previousState)
{ {
if (down && (!pressedL)) if (down && (!previousState))
MotionInterested::activate(); activateMouseMove();
else if (!down) else if (!down)
{ {
if (std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this)!=GH.motioninterested.end()) if (std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this)!=GH.motioninterested.end())
MotionInterested::deactivate(); deactivateMouseMove();
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
if (!((bool)down)) if (!((bool)down))
return; return;
@ -297,7 +297,7 @@ void CMinimap::clickLeft (tribool down)
void CMinimap::hover (bool on) void CMinimap::hover (bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if (on) if (on)
LOCPLINT->adventureInt->statusbar.print(statusbarTxt); LOCPLINT->adventureInt->statusbar.print(statusbarTxt);
else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt) else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt)
@ -308,25 +308,25 @@ void CMinimap::mouseMoved (const SDL_MouseMotionEvent & sEvent)
{ {
if (pressedL) if (pressedL)
{ {
clickLeft(true); clickLeft(true, true);
} }
} }
void CMinimap::activate() void CMinimap::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
if (pressedL) if (pressedL)
MotionInterested::activate(); activateMouseMove();
} }
void CMinimap::deactivate() void CMinimap::deactivate()
{ {
if (pressedL) if (pressedL)
MotionInterested::deactivate(); deactivateMouseMove();
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
void CMinimap::showTile(const int3 &pos) void CMinimap::showTile(const int3 &pos)
@ -426,6 +426,11 @@ void CMinimap::hideTile(const int3 &pos)
{ {
} }
void CMinimap::show( SDL_Surface * to )
{
}
CTerrainRect::CTerrainRect() CTerrainRect::CTerrainRect()
:currentPath(NULL) :currentPath(NULL)
{ {
@ -448,19 +453,19 @@ CTerrainRect::~CTerrainRect()
} }
void CTerrainRect::activate() void CTerrainRect::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
MotionInterested::activate(); activateMouseMove();
}; };
void CTerrainRect::deactivate() void CTerrainRect::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
MotionInterested::deactivate(); deactivateMouseMove();
}; };
void CTerrainRect::clickLeft(tribool down) void CTerrainRect::clickLeft(tribool down, bool previousState)
{ {
if ((down==false) || indeterminate(down)) if ((down==false) || indeterminate(down))
return; return;
@ -549,7 +554,7 @@ void CTerrainRect::clickLeft(tribool down)
} }
} //end of hero is selected "case" } //end of hero is selected "case"
} }
void CTerrainRect::clickRight(tribool down) void CTerrainRect::clickRight(tribool down, bool previousState)
{ {
int3 mp = whichTileIsIt(); int3 mp = whichTileIsIt();
if ((mp.x<0) if ((mp.x<0)
@ -680,7 +685,7 @@ void CTerrainRect::hover(bool on)
LOCPLINT->adventureInt->statusbar.clear(); LOCPLINT->adventureInt->statusbar.clear();
CGI->curh->changeGraphic(0,0); CGI->curh->changeGraphic(0,0);
} }
Hoverable::hover(on); //Hoverable::hover(on);
} }
void CTerrainRect::showPath(const SDL_Rect * extRect) void CTerrainRect::showPath(const SDL_Rect * extRect)
{ {
@ -1051,16 +1056,16 @@ int3 CTerrainRect::whichTileIsIt()
return whichTileIsIt(GH.current->motion.x,GH.current->motion.y); return whichTileIsIt(GH.current->motion.x,GH.current->motion.y);
} }
void CResDataBar::clickRight (tribool down) void CResDataBar::clickRight(tribool down, bool previousState)
{ {
} }
void CResDataBar::activate() void CResDataBar::activate()
{ {
ClickableR::activate(); activateRClick();
} }
void CResDataBar::deactivate() void CResDataBar::deactivate()
{ {
ClickableR::deactivate(); deactivateRClick();
} }
CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist) CResDataBar::CResDataBar(const std::string &defname, int x, int y, int offx, int offy, int resdist, int datedist)
{ {
@ -1119,6 +1124,11 @@ void CResDataBar::draw(SDL_Surface * to)
//updateRect(&pos,screen); //updateRect(&pos,screen);
delete[] buf; delete[] buf;
} }
void CResDataBar::show( SDL_Surface * to )
{
}
CInfoBar::CInfoBar() CInfoBar::CInfoBar()
{ {
toNextTick = mode = pom = -1; toNextTick = mode = pom = -1;
@ -1241,7 +1251,7 @@ void CInfoBar::newDay(int Day)
} }
} }
pom = 0; pom = 0;
TimeInterested::activate(); activateTimer();
toNextTick = 500; toNextTick = 500;
blitAnim(mode); blitAnim(mode);
//blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10); //blitAt(day->ourImages[pom].bitmap,pos.x+10,pos.y+10);
@ -1255,7 +1265,7 @@ void CInfoBar::showComp(SComponent * comp, int time)
printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly); printAtMiddle(comp->subtitle,pos.x+91,pos.y+158,GEOR13,zwykly);
printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly); printAtMiddleWB(comp->description,pos.x+94,pos.y+31,GEOR13,26,zwykly);
SDL_FreeSurface(b); SDL_FreeSurface(b);
TimeInterested::activate(); activateTimer();
mode = 6; mode = 6;
toNextTick = time; toNextTick = time;
} }
@ -1267,7 +1277,7 @@ void CInfoBar::tick()
pom++; pom++;
if (pom >= getAnim(mode)->ourImages.size()) if (pom >= getAnim(mode)->ourImages.size())
{ {
TimeInterested::deactivate(); deactivateTimer();
toNextTick = -1; toNextTick = -1;
mode = 5; mode = 5;
draw(screen2); draw(screen2);
@ -1278,7 +1288,7 @@ void CInfoBar::tick()
} }
else if (mode == 6) else if (mode == 6)
{ {
TimeInterested::deactivate(); deactivateTimer();
toNextTick = -1; toNextTick = -1;
mode = 5; mode = 5;
draw(screen2); draw(screen2);
@ -1286,6 +1296,10 @@ void CInfoBar::tick()
} }
void CInfoBar::show( SDL_Surface * to )
{
}
CAdvMapInt::CAdvMapInt(int Player) CAdvMapInt::CAdvMapInt(int Player)
:player(Player), :player(Player),
statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG), statusbar(ADVOPT.statusbarX,ADVOPT.statusbarY,ADVOPT.statusbarG),
@ -1323,7 +1337,6 @@ heroList(ADVOPT.hlistSize),
townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372), townList(ADVOPT.tlistSize,ADVOPT.tlistX,ADVOPT.tlistY,ADVOPT.tlistAU,ADVOPT.tlistAD)//(5,&genRect(192,48,747,196),747,196,747,372),
{ {
active = 0; active = 0;
subInt = NULL;
selection = NULL; selection = NULL;
townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this);
LOCPLINT->adventureInt=this; LOCPLINT->adventureInt=this;

View File

@ -25,8 +25,7 @@ class CHeroWindow;
* *
*/ */
class CMinimap class CMinimap : public CIntObject
: public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
{ {
public: public:
SDL_Surface * radar; SDL_Surface * radar;
@ -38,6 +37,7 @@ public:
CMinimap(bool draw=true); CMinimap(bool draw=true);
~CMinimap(); ~CMinimap();
void show(SDL_Surface * to);
void draw(SDL_Surface * to); void draw(SDL_Surface * to);
void redraw(int level=-1);// (level==-1) => redraw all levels void redraw(int level=-1);// (level==-1) => redraw all levels
void initMap(int level=-1);// (level==-1) => redraw all levels void initMap(int level=-1);// (level==-1) => redraw all levels
@ -46,8 +46,8 @@ public:
void updateRadar(); void updateRadar();
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void hover (bool on); void hover (bool on);
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void activate(); // makes button active void activate(); // makes button active
@ -57,7 +57,7 @@ public:
void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels void showVisibleTiles(int level=-1);// (level==-1) => redraw all levels
}; };
class CTerrainRect class CTerrainRect
: public ClickableL, public ClickableR, public Hoverable, public MotionInterested : public CIntObject
{ {
public: public:
int tilesw, tilesh; //width and height of terrain to blit in tiles int tilesw, tilesh; //width and height of terrain to blit in tiles
@ -70,8 +70,8 @@ public:
CPath * currentPath; CPath * currentPath;
void activate(); void activate();
void deactivate(); void deactivate();
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void hover(bool on); void hover(bool on);
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -80,14 +80,14 @@ public:
int3 whichTileIsIt(); //uses current cursor pos int3 whichTileIsIt(); //uses current cursor pos
}; };
class CResDataBar class CResDataBar
:public ClickableR, public virtual CIntObject : public CIntObject
{ {
public: public:
SDL_Surface * bg; SDL_Surface * bg;
std::vector<std::pair<int,int> > txtpos; std::vector<std::pair<int,int> > txtpos;
std::string datetext; std::string datetext;
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
CResDataBar(); CResDataBar();
@ -95,9 +95,9 @@ public:
~CResDataBar(); ~CResDataBar();
void draw(SDL_Surface * to); void draw(SDL_Surface * to);
void show(SDL_Surface * to);
}; };
class CInfoBar class CInfoBar : public CIntObject
:public virtual CIntObject, public TimeInterested
{ {
public: public:
CDefHandler *day, *week1, *week2, *week3, *week4; CDefHandler *day, *week1, *week2, *week3, *week4;
@ -113,9 +113,10 @@ public:
void draw(SDL_Surface * to, const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town void draw(SDL_Surface * to, const CGObjectInstance * specific=NULL); // if specific==0 function draws info about selected hero/town
void blitAnim(int mode);//0 - day, 1 - week void blitAnim(int mode);//0 - day, 1 - week
CDefHandler * getAnim(int mode); CDefHandler * getAnim(int mode);
void show(SDL_Surface * to);
}; };
/*****************************/ /*****************************/
class CAdvMapInt : public CMainInterface, public KeyInterested, public MotionInterested //adventure map interface class CAdvMapInt : public CIntObject //adventure map interface
{ {
public: public:
CAdvMapInt(int Player); CAdvMapInt(int Player);
@ -183,7 +184,7 @@ public:
void selectionChanged(); void selectionChanged();
void centerOn(int3 on); void centerOn(int3 on);
int3 verifyPos(int3 ver); int3 verifyPos(int3 ver);
void handleRightClick(std::string text, boost::logic::tribool down, CIntObject * client); void handleRightClick(std::string text, tribool down, CIntObject * client);
void keyPressed(const SDL_KeyboardEvent & key); void keyPressed(const SDL_KeyboardEvent & key);
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
}; };

View File

@ -301,10 +301,9 @@ void CBattleInterface::setPrintMouseShadow(bool set)
void CBattleInterface::activate() void CBattleInterface::activate()
{ {
KeyInterested::activate(); activateKeys();
MotionInterested::activate(); activateMouseMove();
ClickableR::activate(); activateRClick();
subInt = NULL;
bOptions->activate(); bOptions->activate();
bSurrender->activate(); bSurrender->activate();
bFlee->activate(); bFlee->activate();
@ -328,9 +327,9 @@ void CBattleInterface::activate()
void CBattleInterface::deactivate() void CBattleInterface::deactivate()
{ {
KeyInterested::deactivate(); deactivateKeys();
MotionInterested::deactivate(); deactivateMouseMove();
ClickableR::deactivate(); deactivateRClick();
bOptions->deactivate(); bOptions->deactivate();
bSurrender->deactivate(); bSurrender->deactivate();
bFlee->deactivate(); bFlee->deactivate();
@ -862,7 +861,7 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
} }
} }
void CBattleInterface::clickRight(boost::logic::tribool down) void CBattleInterface::clickRight(tribool down, bool previousState)
{ {
if(!down && spellDestSelectMode) if(!down && spellDestSelectMode)
{ {
@ -2342,11 +2341,11 @@ void CBattleHero::show(SDL_Surface *to)
void CBattleHero::activate() void CBattleHero::activate()
{ {
ClickableL::activate(); activateLClick();
} }
void CBattleHero::deactivate() void CBattleHero::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
} }
void CBattleHero::setPhase(int newPhase) void CBattleHero::setPhase(int newPhase)
@ -2362,7 +2361,7 @@ void CBattleHero::setPhase(int newPhase)
} }
} }
void CBattleHero::clickLeft(boost::logic::tribool down) void CBattleHero::clickLeft(tribool down, bool previousState)
{ {
if(!down && myHero && LOCPLINT->cb->battleCanCastSpell()) //check conditions if(!down && myHero && LOCPLINT->cb->battleCanCastSpell()) //check conditions
{ {
@ -2442,24 +2441,24 @@ std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & a
} }
void CBattleHex::activate() void CBattleHex::activate()
{ {
Hoverable::activate(); activateHover();
MotionInterested::activate(); activateMouseMove();
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
} }
void CBattleHex::deactivate() void CBattleHex::deactivate()
{ {
Hoverable::deactivate(); deactivateHover();
MotionInterested::deactivate(); deactivateMouseMove();
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
} }
void CBattleHex::hover(bool on) void CBattleHex::hover(bool on)
{ {
hovered = on; hovered = on;
Hoverable::hover(on); //Hoverable::hover(on);
if(!on && setAlterText) if(!on && setAlterText)
{ {
myInterface->console->alterTxt = std::string(); myInterface->console->alterTxt = std::string();
@ -2506,7 +2505,7 @@ void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
} }
} }
void CBattleHex::clickLeft(boost::logic::tribool down) void CBattleHex::clickLeft(tribool down, bool previousState)
{ {
if(!down && hovered && strictHovered) //we've been really clicked! if(!down && hovered && strictHovered) //we've been really clicked!
{ {
@ -2514,7 +2513,7 @@ void CBattleHex::clickLeft(boost::logic::tribool down)
} }
} }
void CBattleHex::clickRight(boost::logic::tribool down) void CBattleHex::clickRight(tribool down, bool previousState)
{ {
int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile int stID = LOCPLINT->cb->battleGetStack(myNumber); //id of stack being on this tile
if(hovered && strictHovered && stID!=-1) if(hovered && strictHovered && stID!=-1)

View File

@ -31,7 +31,7 @@ struct BattleAction;
class CBattleInterface; class CBattleInterface;
class CBattleHero : public IShowable, public ClickableL class CBattleHero : public CIntObject
{ {
public: public:
bool flip; //false if it's attacking hero, true otherwise bool flip; //false if it's attacking hero, true otherwise
@ -46,12 +46,12 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void setPhase(int newPhase); //sets phase of hero animation void setPhase(int newPhase); //sets phase of hero animation
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(tribool down, bool previousState); //call-in
CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor
~CBattleHero(); //d-tor ~CBattleHero(); //d-tor
}; };
class CBattleHex : public Hoverable, public MotionInterested, public ClickableL, public ClickableR class CBattleHex : public CIntObject
{ {
private: private:
bool setAlterText; //if true, this hex has set alternative text in console and will clean it bool setAlterText; //if true, this hex has set alternative text in console and will clean it
@ -67,8 +67,8 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
CBattleHex(); CBattleHex();
}; };
@ -77,7 +77,7 @@ class CBattleObstacle
std::vector<int> lockedHexes; std::vector<int> lockedHexes;
}; };
class CBattleConsole : public IShowable, public CIntObject class CBattleConsole : public CIntObject
{ {
private: private:
std::vector< std::string > texts; //a place where texts are stored std::vector< std::string > texts; //a place where texts are stored
@ -96,7 +96,7 @@ public:
void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions void scrollDown(unsigned int by = 1); //scrolls console up by 'by' positions
}; };
class CBattleResultWindow : public IShowActivable, public CIntObject class CBattleResultWindow : public CIntObject
{ {
private: private:
SDL_Surface * background; SDL_Surface * background;
@ -112,7 +112,7 @@ public:
void show(SDL_Surface * to = 0); void show(SDL_Surface * to = 0);
}; };
class CBattleOptionsWindow : public IShowActivable, public CIntObject class CBattleOptionsWindow : public CIntObject
{ {
private: private:
CBattleInterface * myInt; CBattleInterface * myInt;
@ -153,7 +153,7 @@ struct BattleSettings
} }
}; };
class CBattleInterface : public CMainInterface, public MotionInterested, public KeyInterested, public ClickableR class CBattleInterface : public CIntObject
{ {
private: private:
SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes; SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;
@ -265,7 +265,7 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
void keyPressed(const SDL_KeyboardEvent & key); void keyPressed(const SDL_KeyboardEvent & key);
void mouseMoved(const SDL_MouseMotionEvent &sEvent); void mouseMoved(const SDL_MouseMotionEvent &sEvent);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
void handleStartMoving(int number); //animation of starting move; some units don't have this animation (ie. halberdier) void handleStartMoving(int number); //animation of starting move; some units don't have this animation (ie. halberdier)

View File

@ -88,18 +88,18 @@ CBuildingRect::~CBuildingRect()
} }
void CBuildingRect::activate() void CBuildingRect::activate()
{ {
Hoverable::activate(); activateHover();
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
} }
void CBuildingRect::deactivate() void CBuildingRect::deactivate()
{ {
Hoverable::deactivate(); deactivateHover();
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
if(moi) if(moi)
MotionInterested::deactivate(); deactivateMouseMove();
moi=false; moi=false;
} }
bool CBuildingRect::operator<(const CBuildingRect & p2) const bool CBuildingRect::operator<(const CBuildingRect & p2) const
@ -111,17 +111,17 @@ bool CBuildingRect::operator<(const CBuildingRect & p2) const
} }
void CBuildingRect::hover(bool on) void CBuildingRect::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(on) if(on)
{ {
if(!moi) if(!moi)
MotionInterested::activate(); activateMouseMove();
moi = true; moi = true;
} }
else else
{ {
if(moi) if(moi)
MotionInterested::deactivate(); deactivateMouseMove();
moi = false; moi = false;
if(LOCPLINT->castleInt->hBuild == this) if(LOCPLINT->castleInt->hBuild == this)
{ {
@ -134,20 +134,16 @@ void CBuildingRect::hover(bool on)
} }
} }
} }
void CBuildingRect::clickLeft (tribool down) void CBuildingRect::clickLeft(tribool down, bool previousState)
{ {
if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu if(area && (LOCPLINT->castleInt->hBuild==this) && !(indeterminate(down)) && (CSDL_Ext::SDL_GetPixel(area,GH.current->motion.x-pos.x,GH.current->motion.y-pos.y) != 0)) //na polu
{ {
if(pressedL && !down) if(previousState && !down)
LOCPLINT->castleInt->buildingClicked(str->ID); LOCPLINT->castleInt->buildingClicked(str->ID);
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
//todo - handle
} }
void CBuildingRect::clickRight (tribool down) void CBuildingRect::clickRight(tribool down, bool previousState)
{ {
if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild)) if((!area) || (!((bool)down)) || (this!=LOCPLINT->castleInt->hBuild))
return; return;
@ -254,12 +250,11 @@ void CHeroGSlot::hover (bool on)
LOCPLINT->statusbar->print(temp); LOCPLINT->statusbar->print(temp);
} }
void CHeroGSlot::clickRight (boost::logic::tribool down) void CHeroGSlot::clickRight(tribool down, bool previousState)
{ {
} }
void CHeroGSlot::clickLeft(boost::logic::tribool down) void CHeroGSlot::clickLeft(tribool down, bool previousState)
{ {
CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown; CHeroGSlot *other = upg ? &owner->hslotup : &owner->hslotdown;
if(!down) if(!down)
@ -310,17 +305,17 @@ void CHeroGSlot::clickLeft(boost::logic::tribool down)
void CHeroGSlot::activate() void CHeroGSlot::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void CHeroGSlot::deactivate() void CHeroGSlot::deactivate()
{ {
highlight = false; highlight = false;
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
void CHeroGSlot::show(SDL_Surface * to) void CHeroGSlot::show(SDL_Surface * to)
@ -793,7 +788,7 @@ void CCastleInterface::activate()
} }
hslotdown.activate(); hslotdown.activate();
hslotup.activate(); hslotup.activate();
KeyInterested::activate(); activateKeys();
} }
void CCastleInterface::deactivate() void CCastleInterface::deactivate()
@ -809,7 +804,7 @@ void CCastleInterface::deactivate()
} }
hslotdown.deactivate(); hslotdown.deactivate();
hslotup.deactivate(); hslotup.deactivate();
KeyInterested::deactivate(); deactivateKeys();
} }
void CCastleInterface::addBuilding(int bid) void CCastleInterface::addBuilding(int bid)
@ -1028,7 +1023,7 @@ void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key )
void CHallInterface::CBuildingBox::hover(bool on) void CHallInterface::CBuildingBox::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(on) if(on)
{ {
std::string toPrint; std::string toPrint;
@ -1043,21 +1038,21 @@ void CHallInterface::CBuildingBox::hover(bool on)
else else
LOCPLINT->statusbar->clear(); LOCPLINT->statusbar->clear();
} }
void CHallInterface::CBuildingBox::clickLeft (tribool down) void CHallInterface::CBuildingBox::clickLeft(tribool down, bool previousState)
{ {
if(pressedL && (!down)) if(previousState && (!down))
{ {
GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0)); GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,0));
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void CHallInterface::CBuildingBox::clickRight (tribool down) void CHallInterface::CBuildingBox::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1)); GH.pushInt(new CHallInterface::CBuildWindow(LOCPLINT->castleInt->town->subID,BID,state,1));
} }
ClickableR::clickRight(down); //ClickableR::clickRight(down);
} }
void CHallInterface::CBuildingBox::show(SDL_Surface * to) void CHallInterface::CBuildingBox::show(SDL_Surface * to)
{ {
@ -1092,15 +1087,15 @@ void CHallInterface::CBuildingBox::show(SDL_Surface * to)
} }
void CHallInterface::CBuildingBox::activate() void CHallInterface::CBuildingBox::activate()
{ {
Hoverable::activate(); activateHover();
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
} }
void CHallInterface::CBuildingBox::deactivate() void CHallInterface::CBuildingBox::deactivate()
{ {
Hoverable::deactivate(); deactivateHover();
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
} }
CHallInterface::CBuildingBox::~CBuildingBox() CHallInterface::CBuildingBox::~CBuildingBox()
{ {
@ -1236,7 +1231,7 @@ void CHallInterface::deactivate()
void CHallInterface::CBuildWindow::activate() void CHallInterface::CBuildWindow::activate()
{ {
ClickableR::activate(); activateRClick();
if(mode) if(mode)
return; return;
if(state==7) if(state==7)
@ -1246,7 +1241,7 @@ void CHallInterface::CBuildWindow::activate()
void CHallInterface::CBuildWindow::deactivate() void CHallInterface::CBuildWindow::deactivate()
{ {
ClickableR::deactivate(); deactivateRClick();
if(mode) if(mode)
return; return;
if(state==7) if(state==7)
@ -1266,7 +1261,7 @@ void CHallInterface::CBuildWindow::close()
GH.popIntTotally(this); GH.popIntTotally(this);
} }
void CHallInterface::CBuildWindow::clickRight (tribool down) void CHallInterface::CBuildWindow::clickRight(tribool down, bool previousState)
{ {
if((!down || indeterminate(down)) && mode) if((!down || indeterminate(down)) && mode)
close(); close();
@ -1558,28 +1553,28 @@ void CFortScreen::draw( CCastleInterface * owner, bool first)
} }
SDL_FreeSurface(icons); SDL_FreeSurface(icons);
} }
void CFortScreen::RecArea::clickLeft (tribool down) void CFortScreen::RecArea::clickLeft(tribool down, bool previousState)
{ {
if(!down && pressedL) if(!down && previousState)
{ {
LOCPLINT->castleInt->showRecruitmentWindow(bid); LOCPLINT->castleInt->showRecruitmentWindow(bid);
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void CFortScreen::RecArea::activate() void CFortScreen::RecArea::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
} }
void CFortScreen::RecArea::deactivate() void CFortScreen::RecArea::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
} }
void CFortScreen::RecArea::clickRight( tribool down ) void CFortScreen::RecArea::clickRight(tribool down, bool previousState)
{ {
clickLeft(down);; //r-click does same as l-click - opens recr. window clickLeft(down, false); //r-click does same as l-click - opens recr. window
} }
CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner) CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
{ {
@ -1664,7 +1659,7 @@ void CMageGuildScreen::deactivate()
} }
} }
void CMageGuildScreen::Scroll::clickLeft (tribool down) void CMageGuildScreen::Scroll::clickLeft(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -1675,7 +1670,7 @@ void CMageGuildScreen::Scroll::clickLeft (tribool down)
} }
} }
void CMageGuildScreen::Scroll::clickRight (tribool down) void CMageGuildScreen::Scroll::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -1693,7 +1688,7 @@ void CMageGuildScreen::Scroll::clickRight (tribool down)
void CMageGuildScreen::Scroll::hover(bool on) void CMageGuildScreen::Scroll::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(on) if(on)
LOCPLINT->statusbar->print(spell->name); LOCPLINT->statusbar->print(spell->name);
else else
@ -1703,16 +1698,16 @@ void CMageGuildScreen::Scroll::hover(bool on)
void CMageGuildScreen::Scroll::activate() void CMageGuildScreen::Scroll::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void CMageGuildScreen::Scroll::deactivate() void CMageGuildScreen::Scroll::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid) CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, int hid)

View File

@ -31,7 +31,7 @@ class CMinorResDataBar;
* *
*/ */
class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested class CBuildingRect : public CIntObject
{ {
public: public:
bool moi; //motion interested is active bool moi; //motion interested is active
@ -46,11 +46,11 @@ public:
void deactivate(); void deactivate();
bool operator<(const CBuildingRect & p2) const; bool operator<(const CBuildingRect & p2) const;
void hover(bool on); void hover(bool on);
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void mouseMoved (const SDL_MouseMotionEvent & sEvent); void mouseMoved (const SDL_MouseMotionEvent & sEvent);
}; };
class CHeroGSlot : public ClickableL, public ClickableR, public Hoverable class CHeroGSlot : public CIntObject
{ {
public: public:
CCastleInterface *owner; CCastleInterface *owner;
@ -59,8 +59,8 @@ public:
bool highlight; //indicates id the slot is highlighted bool highlight; //indicates id the slot is highlighted
void hover (bool on); void hover (bool on);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -68,7 +68,7 @@ public:
~CHeroGSlot(); //d-tor ~CHeroGSlot(); //d-tor
}; };
class CCastleInterface : public CWindowWithGarrison, public KeyInterested class CCastleInterface : public CWindowWithGarrison
{ {
public: public:
SDL_Rect pos; //why not inherit this member from CIntObject ? SDL_Rect pos; //why not inherit this member from CIntObject ?
@ -121,15 +121,15 @@ public:
CMinorResDataBar * resdatabar; CMinorResDataBar * resdatabar;
SDL_Rect pos; SDL_Rect pos;
class CBuildingBox : public Hoverable, public ClickableL, public ClickableR class CBuildingBox : public CIntObject
{ {
public: public:
int BID; int BID;
int state;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements int state;// 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
//(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists //(-1) - forbidden in this town, 0 - possible, 1 - lack of res, 2 - requirements/buildings per turn limit, (3) - already exists
void hover(bool on); void hover(bool on);
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void show(SDL_Surface * to); void show(SDL_Surface * to);
void activate(); void activate();
void deactivate(); void deactivate();
@ -138,7 +138,7 @@ public:
~CBuildingBox(); //d-tor ~CBuildingBox(); //d-tor
}; };
class CBuildWindow: public IShowActivable, public ClickableR class CBuildWindow: public CIntObject
{ {
public: public:
int tid, bid, state; //town id, building id, state int tid, bid, state; //town id, building id, state
@ -149,7 +149,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
std::string getTextForState(int state); std::string getTextForState(int state);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void show(SDL_Surface * to); void show(SDL_Surface * to);
void Buy(); void Buy();
void close(); void close();
@ -172,15 +172,15 @@ public:
void deactivate(); void deactivate();
}; };
class CFortScreen : public IShowActivable, public CIntObject class CFortScreen : public CIntObject
{ {
class RecArea : public ClickableL, public ClickableR class RecArea : public CIntObject
{ {
public: public:
int bid; int bid;
RecArea(int BID):bid(BID){}; //c-tor RecArea(int BID):bid(BID){}; //c-tor
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
}; };
@ -202,17 +202,17 @@ public:
void deactivate(); void deactivate();
}; };
class CMageGuildScreen : public IShowActivable, public CIntObject class CMageGuildScreen : public CIntObject
{ {
public: public:
class Scroll : public ClickableL, public Hoverable, public ClickableR class Scroll : public CIntObject
{ {
public: public:
CSpell *spell; CSpell *spell;
Scroll(CSpell *Spell):spell(Spell){}; Scroll(CSpell *Spell):spell(Spell){};
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void hover(bool on); void hover(bool on);
void activate(); void activate();
void deactivate(); void deactivate();
@ -234,7 +234,7 @@ public:
void deactivate(); void deactivate();
}; };
class CBlacksmithDialog : public IShowActivable, public CIntObject class CBlacksmithDialog : public CIntObject
{ {
public: public:
AdventureMapButton *buy, *cancel; AdventureMapButton *buy, *cancel;

View File

@ -27,7 +27,7 @@ class CArtifactsOfHero;
class CHeroWindow: public CWindowWithGarrison, public virtual CIntObject class CHeroWindow: public CWindowWithGarrison
{ {
SDL_Surface * background, * curBack; SDL_Surface * background, * curBack;
CStatusBar * ourBar; //heroWindow's statusBar CStatusBar * ourBar; //heroWindow's statusBar
@ -70,7 +70,7 @@ public:
void switchHero(); //changes displayed hero void switchHero(); //changes displayed hero
//friends //friends
friend void CArtPlace::clickLeft(tribool down); friend void CArtPlace::clickLeft(tribool down, bool previousState);
friend class CPlayerInterface; friend class CPlayerInterface;
}; };

View File

@ -443,11 +443,6 @@ void dispose()
static void setScreenRes(int w, int h, int bpp, bool fullscreen) static void setScreenRes(int w, int h, int bpp, bool fullscreen)
{ {
if(screen) //screen has been already initialized
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
// VCMI will only work with 3 or 4 bytes per pixel // VCMI will only work with 3 or 4 bytes per pixel
if (bpp < 24) bpp = 24; if (bpp < 24) bpp = 24;
if (bpp > 32) bpp = 32; if (bpp > 32) bpp = 32;
@ -456,14 +451,22 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen)
int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0)); int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
if(suggestedBpp == 0) if(suggestedBpp == 0)
{ {
tlog2 << "Warning: SDL says that " << w << "x" << h << " resolution is not available!\n"; tlog1 << "Error: SDL says that " << w << "x" << h << " resolution is not available!\n";
suggestedBpp = bpp; return;
} }
else if(suggestedBpp != bpp)
if(suggestedBpp != bpp)
{ {
tlog2 << "Warning: SDL says that " << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl; tlog2 << "Warning: SDL says that " << bpp << "bpp is wrong and suggests " << suggestedBpp << std::endl;
} }
if(screen) //screen has been already initialized
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL) if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL)
{ {

View File

@ -170,7 +170,7 @@ void CPlayerInterface::yourTurn()
adventureInt->showAll(screen); adventureInt->showAll(screen);
GH.pushInt(adventureInt); GH.pushInt(adventureInt);
adventureInt->KeyInterested::activate(); adventureInt->activateKeys();
while(makingTurn) // main loop while(makingTurn) // main loop
{ {
@ -201,7 +201,7 @@ void CPlayerInterface::yourTurn()
SDL_framerateDelay(mainFPSmng); SDL_framerateDelay(mainFPSmng);
} }
adventureInt->KeyInterested::deactivate(); adventureInt->deactivateKeys();
GH.popInt(adventureInt); GH.popInt(adventureInt);
cb->endTurn(); cb->endTurn();
@ -1269,7 +1269,7 @@ void CPlayerInterface::showBlockingDialog( const std::string &text, const std::v
CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom,askID); CSelWindow * temp = new CSelWindow(text,playerID,35,intComps,pom,askID);
GH.pushInt(temp); GH.pushInt(temp);
intComps[0]->clickLeft(true); intComps[0]->clickLeft(true, false);
} }
} }

View File

@ -37,7 +37,7 @@ SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boos
onHoverOff = funcHoff; onHoverOff = funcHoff;
} }
void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down) void SpellbookInteractiveArea::clickLeft(tribool down, bool previousState)
{ {
if(!down) if(!down)
{ {
@ -45,14 +45,14 @@ void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down)
} }
} }
void SpellbookInteractiveArea::clickRight(boost::logic::tribool down) void SpellbookInteractiveArea::clickRight(tribool down, bool previousState)
{ {
LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this); LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this);
} }
void SpellbookInteractiveArea::hover(bool on) void SpellbookInteractiveArea::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(on) if(on)
{ {
onHoverOn(); onHoverOn();
@ -65,16 +65,16 @@ void SpellbookInteractiveArea::hover(bool on)
void SpellbookInteractiveArea::activate() void SpellbookInteractiveArea::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void SpellbookInteractiveArea::deactivate() void SpellbookInteractiveArea::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, bool openOnBattleSpells): CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, bool openOnBattleSpells):
@ -581,7 +581,7 @@ void CSpellWindow::computeSpellsPerArea()
void CSpellWindow::activate() void CSpellWindow::activate()
{ {
KeyInterested::activate(); activateKeys();
exitBtn->activate(); exitBtn->activate();
battleSpells->activate(); battleSpells->activate();
adventureSpells->activate(); adventureSpells->activate();
@ -604,7 +604,7 @@ void CSpellWindow::activate()
void CSpellWindow::deactivate() void CSpellWindow::deactivate()
{ {
KeyInterested::deactivate(); deactivateKeys();
exitBtn->deactivate(); exitBtn->deactivate();
battleSpells->deactivate(); battleSpells->deactivate();
adventureSpells->deactivate(); adventureSpells->deactivate();
@ -647,7 +647,7 @@ CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
this->owner = owner; this->owner = owner;
} }
void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down) void CSpellWindow::SpellArea::clickLeft(tribool down, bool previousState)
{ {
if(!down && mySpell!=-1) if(!down && mySpell!=-1)
{ {
@ -660,7 +660,7 @@ void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
} }
} }
void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down) void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState)
{ {
if(down && mySpell != -1) if(down && mySpell != -1)
{ {
@ -678,7 +678,7 @@ void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
void CSpellWindow::SpellArea::hover(bool on) void CSpellWindow::SpellArea::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(mySpell != -1) if(mySpell != -1)
{ {
if(on) if(on)
@ -696,14 +696,14 @@ void CSpellWindow::SpellArea::hover(bool on)
void CSpellWindow::SpellArea::activate() void CSpellWindow::SpellArea::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void CSpellWindow::SpellArea::deactivate() void CSpellWindow::SpellArea::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }

View File

@ -22,7 +22,7 @@ struct SDL_Rect;
class CGHeroInstance; class CGHeroInstance;
class CStatusBar; class CStatusBar;
class SpellbookInteractiveArea : public ClickableL, public ClickableR, public Hoverable class SpellbookInteractiveArea : public CIntObject
{ {
private: private:
boost::function<void()> onLeft; boost::function<void()> onLeft;
@ -30,8 +30,8 @@ private:
boost::function<void()> onHoverOn; boost::function<void()> onHoverOn;
boost::function<void()> onHoverOff; boost::function<void()> onHoverOff;
public: public:
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void hover(bool on); void hover(bool on);
void activate(); void activate();
void deactivate(); void deactivate();
@ -39,18 +39,18 @@ public:
SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff);//c-tor SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff);//c-tor
}; };
class CSpellWindow : public IShowActivable, public KeyInterested class CSpellWindow : public CIntObject
{ {
private: private:
class SpellArea : public ClickableL, public ClickableR, public Hoverable class SpellArea : public CIntObject
{ {
public: public:
int mySpell; int mySpell;
CSpellWindow * owner; CSpellWindow * owner;
SpellArea(SDL_Rect pos, CSpellWindow * owner); SpellArea(SDL_Rect pos, CSpellWindow * owner);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void hover(bool on); void hover(bool on);
void activate(); void activate();
void deactivate(); void deactivate();

View File

@ -24,9 +24,9 @@ void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
if(vstd::contains(assignedKeys,key.keysym.sym)) if(vstd::contains(assignedKeys,key.keysym.sym))
{ {
if(key.state == SDL_PRESSED) if(key.state == SDL_PRESSED)
clickLeft(true); clickLeft(true, pressedL);
else else
clickLeft(false); clickLeft(false, pressedL);
} }
} }
@ -67,108 +67,6 @@ void CButtonBase::show(SDL_Surface * to)
} }
} }
ClickableL::ClickableL()
{
pressedL=false;
}
ClickableL::~ClickableL()
{
}
void ClickableL::clickLeft(boost::logic::tribool down)
{
if (down)
pressedL=true;
else
pressedL=false;
}
void ClickableL::activate()
{
GH.lclickable.push_front(this);
}
void ClickableL::deactivate()
{
GH.lclickable.erase(std::find(GH.lclickable.begin(),GH.lclickable.end(),this));
}
ClickableR::ClickableR()
{
pressedR=false;
}
ClickableR::~ClickableR()
{}
void ClickableR::clickRight(boost::logic::tribool down)
{
if (down)
pressedR=true;
else
pressedR=false;
}
void ClickableR::activate()
{
GH.rclickable.push_front(this);
}
void ClickableR::deactivate()
{
GH.rclickable.erase(std::find(GH.rclickable.begin(),GH.rclickable.end(),this));
}
//ClickableR
Hoverable::~Hoverable()
{}
void Hoverable::activate()
{
GH.hoverable.push_front(this);
}
void Hoverable::deactivate()
{
GH.hoverable.erase(std::find(GH.hoverable.begin(),GH.hoverable.end(),this));
}
void Hoverable::hover(bool on)
{
hovered=on;
}
//Hoverable
KeyInterested::~KeyInterested()
{}
void KeyInterested::activate()
{
GH.keyinterested.push_front(this);
}
void KeyInterested::deactivate()
{
GH.keyinterested.erase(std::find(GH.keyinterested.begin(),GH.keyinterested.end(),this));
}
//KeyInterested
void MotionInterested::activate()
{
GH.motioninterested.push_front(this);
}
void MotionInterested::deactivate()
{
GH.motioninterested.erase(std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this));
}
void TimeInterested::activate()
{
GH.timeinterested.push_back(this);
}
void TimeInterested::deactivate()
{
GH.timeinterested.erase(std::find(GH.timeinterested.begin(),GH.timeinterested.end(),this));
}
void CGuiHandler::popInt( IShowActivable *top ) void CGuiHandler::popInt( IShowActivable *top )
{ {
assert(listInt.front() == top); assert(listInt.front() == top);
@ -238,8 +136,8 @@ void CGuiHandler::totalRedraw()
void CGuiHandler::updateTime() void CGuiHandler::updateTime()
{ {
int tv = th.getDif(); int tv = th.getDif();
std::list<TimeInterested*> hlp = timeinterested; std::list<CIntObject*> hlp = timeinterested;
for (std::list<TimeInterested*>::iterator i=hlp.begin(); i != hlp.end();i++) for (std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
{ {
if(!vstd::contains(timeinterested,*i)) continue; if(!vstd::contains(timeinterested,*i)) continue;
if ((*i)->toNextTick>=0) if ((*i)->toNextTick>=0)
@ -274,6 +172,7 @@ void CGuiHandler::handleEvents()
void CGuiHandler::handleEvent(SDL_Event *sEvent) void CGuiHandler::handleEvent(SDL_Event *sEvent)
{ {
current = sEvent; current = sEvent;
bool prev;
if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP) if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
{ {
@ -290,7 +189,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
} }
bool keysCaptured = false; bool keysCaptured = false;
for(std::list<KeyInterested*>::iterator i=keyinterested.begin(); i != keyinterested.end();i++) for(std::list<CIntObject*>::iterator i=keyinterested.begin(); i != keyinterested.end();i++)
{ {
if((*i)->captureAllKeys) if((*i)->captureAllKeys)
{ {
@ -299,8 +198,8 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
} }
} }
std::list<KeyInterested*> miCopy = keyinterested; std::list<CIntObject*> miCopy = keyinterested;
for(std::list<KeyInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++) for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys)) if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys))
(**i).keyPressed(key); (**i).keyPressed(key);
} }
@ -311,54 +210,62 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
} }
else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT)) else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
{ {
std::list<ClickableL*> hlp = lclickable; std::list<CIntObject*> hlp = lclickable;
for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++) for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
{ {
if(!vstd::contains(lclickable,*i)) continue; if(!vstd::contains(lclickable,*i)) continue;
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
(*i)->clickLeft(true); prev = (*i)->pressedL;
(*i)->pressedL = true;
(*i)->clickLeft(true, prev);
} }
} }
} }
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
{ {
std::list<ClickableL*> hlp = lclickable; std::list<CIntObject*> hlp = lclickable;
for(std::list<ClickableL*>::iterator i=hlp.begin(); i != hlp.end();i++) for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
{ {
if(!vstd::contains(lclickable,*i)) continue; if(!vstd::contains(lclickable,*i)) continue;
prev = (*i)->pressedL;
(*i)->pressedL = false;
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
(*i)->clickLeft(false); (*i)->clickLeft(false, prev);
} }
else else
(*i)->clickLeft(boost::logic::indeterminate); (*i)->clickLeft(boost::logic::indeterminate, prev);
} }
} }
else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT)) else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_RIGHT))
{ {
std::list<ClickableR*> hlp = rclickable; std::list<CIntObject*> hlp = rclickable;
for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++) for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
{ {
if(!vstd::contains(rclickable,*i)) continue; if(!vstd::contains(rclickable,*i)) continue;
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
(*i)->clickRight(true); prev = (*i)->pressedR;
(*i)->pressedR = true;
(*i)->clickRight(true, prev);
} }
} }
} }
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT)) else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
{ {
std::list<ClickableR*> hlp = rclickable; std::list<CIntObject*> hlp = rclickable;
for(std::list<ClickableR*>::iterator i=hlp.begin(); i != hlp.end();i++) for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
{ {
if(!vstd::contains(rclickable,*i)) continue; if(!vstd::contains(rclickable,*i)) continue;
prev = (*i)->pressedR;
(*i)->pressedR = false;
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
(*i)->clickRight(false); (*i)->clickRight(false, prev);
} }
else else
(*i)->clickRight(boost::logic::indeterminate); (*i)->clickRight(boost::logic::indeterminate, prev);
} }
} }
current = NULL; current = NULL;
@ -368,8 +275,8 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
void CGuiHandler::handleMouseMotion(SDL_Event *sEvent) void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
{ {
//sending active, hovered hoverable objects hover() call //sending active, hovered hoverable objects hover() call
std::vector<Hoverable*> hlp; std::vector<CIntObject*> hlp;
for(std::list<Hoverable*>::iterator i=hoverable.begin(); i != hoverable.end();i++) for(std::list<CIntObject*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
{ {
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
@ -379,14 +286,19 @@ void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
else if ((*i)->hovered) else if ((*i)->hovered)
{ {
(*i)->hover(false); (*i)->hover(false);
(*i)->hovered = false;
} }
} }
for(int i=0; i<hlp.size();i++) for(int i=0; i<hlp.size();i++)
{
hlp[i]->hover(true); hlp[i]->hover(true);
hlp[i]->hovered = true;
}
//sending active, MotionInterested objects mouseMoved() call //sending active, MotionInterested objects mouseMoved() call
std::list<MotionInterested*> miCopy = motioninterested; std::list<CIntObject*> miCopy = motioninterested;
for(std::list<MotionInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++) for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
{ {
if ((*i)->strongInterest || isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y)) if ((*i)->strongInterest || isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
{ {
@ -402,3 +314,131 @@ void CGuiHandler::simpleRedraw()
blitAt(screen2,0,0,screen); //blit background blitAt(screen2,0,0,screen); //blit background
objsToBlit.back()->show(screen); //blit active interface/window objsToBlit.back()->show(screen); //blit active interface/window
} }
void CIntObject::activateLClick()
{
GH.lclickable.push_front(this);
active |= LCLICK;
}
void CIntObject::deactivateLClick()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.lclickable.begin(),GH.lclickable.end(),this);
assert(hlp != GH.lclickable.end());
GH.lclickable.erase(hlp);
active &= ~LCLICK;
}
void CIntObject::clickLeft(tribool down, bool previousState)
{
}
void CIntObject::activateRClick()
{
GH.rclickable.push_front(this);
active |= RCLICK;
}
void CIntObject::deactivateRClick()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.rclickable.begin(),GH.rclickable.end(),this);
assert(hlp != GH.rclickable.end());
GH.rclickable.erase(hlp);
active &= ~RCLICK;
}
void CIntObject::clickRight(tribool down, bool previousState)
{
}
void CIntObject::activateHover()
{
GH.hoverable.push_front(this);
active |= HOVER;
}
void CIntObject::deactivateHover()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.hoverable.begin(),GH.hoverable.end(),this);
assert(hlp != GH.hoverable.end());
GH.hoverable.erase(hlp);
active &= ~HOVER;
}
void CIntObject::hover( bool on )
{
}
void CIntObject::activateKeys()
{
GH.keyinterested.push_front(this);
active |= KEYBOARD;
}
void CIntObject::deactivateKeys()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.keyinterested.begin(),GH.keyinterested.end(),this);
assert(hlp != GH.keyinterested.end());
GH.keyinterested.erase(hlp);
active &= ~KEYBOARD;
}
void CIntObject::keyPressed( const SDL_KeyboardEvent & key )
{
}
void CIntObject::activateMouseMove()
{
GH.motioninterested.push_front(this);
active |= MOVE;
}
void CIntObject::deactivateMouseMove()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.motioninterested.begin(),GH.motioninterested.end(),this);
assert(hlp != GH.motioninterested.end());
GH.motioninterested.erase(hlp);
active &= ~MOVE;
}
void CIntObject::mouseMoved( const SDL_MouseMotionEvent & sEvent )
{
}
void CIntObject::activateTimer()
{
GH.timeinterested.push_back(this);
active |= TIME;
}
void CIntObject::deactivateTimer()
{
std::list<CIntObject*>::iterator hlp = std::find(GH.timeinterested.begin(),GH.timeinterested.end(),this);
assert(hlp != GH.timeinterested.end());
GH.timeinterested.erase(hlp);
active &= ~TIME;
}
void CIntObject::tick()
{
}
CIntObject::CIntObject()
{
pressedL = pressedR = hovered = captureAllKeys = strongInterest = toNextTick = active = defActivation = 0;
}
void CIntObject::show( SDL_Surface * to )
{
}
void CIntObject::activate()
{
}
void CIntObject::deactivate()
{
}

View File

@ -258,31 +258,87 @@ public:
virtual ~IShowActivable(){}; //d-tor virtual ~IShowActivable(){}; //d-tor
}; };
class CWindowWithGarrison : public IShowActivable class CIntObject : public IShowActivable //interface object
{
public:
CIntObject *parent; //parent object
std::vector<CIntObject *> children;
Rect pos, //position of object on the screen
posRelative; //position of object in the parent (not used if no parent)
int ID; //object ID, rarely used by some classes for identification / internal info
CIntObject();
virtual ~CIntObject(){}; //d-tor
//l-clicks handling
bool pressedL; //for determining if object is L-pressed
void activateLClick();
void deactivateLClick();
virtual void clickLeft(tribool down, bool previousState);
//r-clicks handling
bool pressedR; //for determining if object is R-pressed
void activateRClick();
void deactivateRClick();
virtual void clickRight(tribool down, bool previousState);
//hover handling
bool hovered; //for determining if object is hovered
void activateHover();
void deactivateHover();
virtual void hover (bool on);
//keyboard handling
bool captureAllKeys; //if true, only this object should get info about pressed keys
void activateKeys();
void deactivateKeys();
virtual void keyPressed(const SDL_KeyboardEvent & key);
//mouse movement handling
bool strongInterest; //if true - report all mouse movements, if not - only when hovered
void activateMouseMove();
void deactivateMouseMove();
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent);
//time handling
int toNextTick;
void activateTimer();
void deactivateTimer();
virtual void tick();
enum {LCLICK=1, RCLICK=2, HOVER=4, MOVE=8, KEYBOARD=16, TIME=32};
ui8 active;
ui8 defActivation;
void defActivate();
void defDeactivate();
void activate();
void deactivate();
void show(SDL_Surface * to);
};
//class for binding keys to left mouse button clicks
//classes wanting use it should have it as one of their base classes
class KeyShortcut : public virtual CIntObject
{
public:
std::set<int> assignedKeys;
KeyShortcut(){}; //c-tor
KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor
KeyShortcut(std::set<int> Keys):assignedKeys(Keys){}; //c-tor
virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in
};
class CWindowWithGarrison : public CIntObject
{ {
public: public:
CGarrisonInt *garr; CGarrisonInt *garr;
CWindowWithGarrison(); CWindowWithGarrison();
}; };
class CMainInterface : public IShowActivable class CSimpleWindow : public CIntObject
{
public:
IShowActivable *subInt;
};
class CIntObject //interface object
{
public:
Rect pos; //position of object on the screen
int ID; //object unique ID, rarely (if at all) used
//virtual bool isIn(int x, int y)
//{
// return pos.isIn(x,y);
//}
virtual ~CIntObject(){}; //d-tor
};
class CSimpleWindow : public IShowActivable, public virtual CIntObject
{ {
public: public:
SDL_Surface * bitmap; //background SDL_Surface * bitmap; //background
@ -293,7 +349,8 @@ public:
void activate(){}; void activate(){};
void deactivate(){}; void deactivate(){};
}; };
class CButtonBase : public virtual CIntObject, public IShowable, public IActivable //basic buttton class
class CButtonBase : public KeyShortcut//basic buttton class
{ {
public: public:
int bitmapOffset; //TODO: comment me int bitmapOffset; //TODO: comment me
@ -311,78 +368,6 @@ public:
CButtonBase(); //c-tor CButtonBase(); //c-tor
virtual ~CButtonBase(); //d-tor virtual ~CButtonBase(); //d-tor
}; };
class ClickableL : public virtual CIntObject //for left-clicks
{
public:
bool pressedL; //for determining if object is L-pressed
ClickableL(); //c-tor
virtual ~ClickableL();//{};//d-tor
virtual void clickLeft (boost::logic::tribool down)=0;
virtual void activate();
virtual void deactivate();
};
class ClickableR : public virtual CIntObject //for right-clicks
{
public:
bool pressedR; //for determining if object is R-pressed
ClickableR(); //c-tor
virtual ~ClickableR();//{};//d-tor
virtual void clickRight (boost::logic::tribool down)=0;
virtual void activate()=0;
virtual void deactivate()=0;
};
class Hoverable : public virtual CIntObject
{
public:
Hoverable() : hovered(false){} //c-tor
virtual ~Hoverable();//{}; //d-tor
bool hovered; //for determining if object is hovered
virtual void hover (bool on)=0;
virtual void activate()=0;
virtual void deactivate()=0;
};
class KeyInterested : public virtual CIntObject
{
public:
bool captureAllKeys; //if true, only this object should get info about pressed keys
KeyInterested(): captureAllKeys(false){}
virtual ~KeyInterested();//{};//d-tor
virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
virtual void activate()=0;
virtual void deactivate()=0;
};
//class for binding keys to left mouse button clicks
//classes wanting use it should have it as one of their base classes
class KeyShortcut : public KeyInterested, public ClickableL
{
public:
std::set<int> assignedKeys;
KeyShortcut(){}; //c-tor
KeyShortcut(int key){assignedKeys.insert(key);}; //c-tor
KeyShortcut(std::set<int> Keys):assignedKeys(Keys){}; //c-tor
virtual void keyPressed(const SDL_KeyboardEvent & key); //call-in
};
class MotionInterested: public virtual CIntObject
{
public:
bool strongInterest; //if true - report all mouse movements, if not - only when hovered
MotionInterested(){strongInterest=false;};
virtual ~MotionInterested(){};//d-tor
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0;
virtual void activate()=0;
virtual void deactivate()=0;
};
class TimeInterested: public virtual CIntObject
{
public:
virtual ~TimeInterested(){}; //d-tor
int toNextTick;
virtual void tick()=0;
virtual void activate();
virtual void deactivate();
};
class CGuiHandler class CGuiHandler
{ {
@ -391,12 +376,12 @@ public:
std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on) std::list<IShowActivable *> listInt; //list of interfaces - front=foreground; back = background (includes adventure map, window interfaces, all kind of active dialogs, and so on)
//active GUI elements (listening for events //active GUI elements (listening for events
std::list<ClickableL*> lclickable; std::list<CIntObject*> lclickable;
std::list<ClickableR*> rclickable; std::list<CIntObject*> rclickable;
std::list<Hoverable*> hoverable; std::list<CIntObject*> hoverable;
std::list<KeyInterested*> keyinterested; std::list<CIntObject*> keyinterested;
std::list<MotionInterested*> motioninterested; std::list<CIntObject*> motioninterested;
std::list<TimeInterested*> timeinterested; std::list<CIntObject*> timeinterested;
//objs to blit //objs to blit
std::vector<IShowable*> objsToBlit; std::vector<IShowable*> objsToBlit;

View File

@ -82,7 +82,7 @@ static StackState* getStackState(const CGObjectInstance *obj, int pos, bool town
void CGarrisonSlot::hover (bool on) void CGarrisonSlot::hover (bool on)
{ {
Hoverable::hover(on); ////Hoverable::hover(on);
if(on) if(on)
{ {
std::string temp; std::string temp;
@ -166,7 +166,7 @@ const CArmedInstance * CGarrisonSlot::getObj()
return (!upg)?(owner->oup):(owner->odown); return (!upg)?(owner->oup):(owner->odown);
} }
void CGarrisonSlot::clickRight (tribool down) void CGarrisonSlot::clickRight(tribool down, bool previousState)
{ {
StackState *pom = getStackState(getObj(),ID, GH.topInt() == LOCPLINT->castleInt); StackState *pom = getStackState(getObj(),ID, GH.topInt() == LOCPLINT->castleInt);
if(down && creature) if(down && creature)
@ -175,7 +175,7 @@ void CGarrisonSlot::clickRight (tribool down)
} }
delete pom; delete pom;
} }
void CGarrisonSlot::clickLeft(tribool down) void CGarrisonSlot::clickLeft(tribool down, bool previousState)
{ {
if(owner->ignoreEvent) if(owner->ignoreEvent)
{ {
@ -277,17 +277,17 @@ void CGarrisonSlot::activate()
{ {
if(!active) active=true; if(!active) active=true;
else return; else return;
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void CGarrisonSlot::deactivate() void CGarrisonSlot::deactivate()
{ {
if(active) active=false; if(active) active=false;
else return; else return;
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count) CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
{ {
@ -636,7 +636,7 @@ void CInfoWindow::deactivate()
for(int i=0;i<buttons.size();i++) for(int i=0;i<buttons.size();i++)
buttons[i]->deactivate(); buttons[i]->deactivate();
} }
void CRClickPopup::clickRight (tribool down) void CRClickPopup::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
return; return;
@ -645,12 +645,12 @@ void CRClickPopup::clickRight (tribool down)
void CRClickPopup::activate() void CRClickPopup::activate()
{ {
ClickableR::activate(); activateRClick();
} }
void CRClickPopup::deactivate() void CRClickPopup::deactivate()
{ {
ClickableR::deactivate(); deactivateRClick();
} }
void CRClickPopup::close() void CRClickPopup::close()
@ -815,21 +815,21 @@ SDL_Surface * SComponent::getImg()
} }
return NULL; return NULL;
} }
void SComponent::clickRight (tribool down) void SComponent::clickRight(tribool down, bool previousState)
{ {
if(description.size()) if(description.size())
LOCPLINT->adventureInt->handleRightClick(description,down,this); LOCPLINT->adventureInt->handleRightClick(description,down,this);
} }
void SComponent::activate() void SComponent::activate()
{ {
ClickableR::activate(); activateRClick();
} }
void SComponent::deactivate() void SComponent::deactivate()
{ {
ClickableR::deactivate(); deactivateRClick();
} }
void CSelectableComponent::clickLeft(tribool down) void CSelectableComponent::clickLeft(tribool down, bool previousState)
{ {
if (down) if (down)
{ {
@ -885,15 +885,15 @@ CSelectableComponent::~CSelectableComponent()
} }
void CSelectableComponent::activate() void CSelectableComponent::activate()
{ {
KeyInterested::activate(); activateKeys();
SComponent::activate(); SComponent::activate();
ClickableL::activate(); activateLClick();
} }
void CSelectableComponent::deactivate() void CSelectableComponent::deactivate()
{ {
KeyInterested::deactivate(); deactivateKeys();
SComponent::deactivate(); SComponent::deactivate();
ClickableL::deactivate(); deactivateLClick();
} }
SDL_Surface * CSelectableComponent::getImg() SDL_Surface * CSelectableComponent::getImg()
{ {
@ -1042,23 +1042,23 @@ std::string CStatusBar::getCurrent()
void CList::activate() void CList::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
KeyInterested::activate(); activateKeys();
MotionInterested::activate(); activateMouseMove();
}; };
void CList::deactivate() void CList::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
KeyInterested::deactivate(); deactivateKeys();
MotionInterested::deactivate(); deactivateMouseMove();
}; };
void CList::clickLeft(tribool down) void CList::clickLeft(tribool down, bool previousState)
{ {
}; };
@ -1130,7 +1130,7 @@ void CHeroList::select(int which)
LOCPLINT->adventureInt->select(heroes[which]); LOCPLINT->adventureInt->select(heroes[which]);
} }
void CHeroList::clickLeft(tribool down) void CHeroList::clickLeft(tribool down, bool previousState)
{ {
if (down) if (down)
{ {
@ -1234,7 +1234,7 @@ void CHeroList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
//select(ny+from); //select(ny+from);
} }
void CHeroList::clickRight(tribool down) void CHeroList::clickRight(tribool down, bool previousState)
{ {
if (down) if (down)
{ {
@ -1357,6 +1357,10 @@ int CHeroList::getPosOfHero(const CGHeroInstance* h)
return vstd::findPos(heroes, h, std::equal_to<const CGHeroInstance*>()); return vstd::findPos(heroes, h, std::equal_to<const CGHeroInstance*>());
} }
void CHeroList::show( SDL_Surface * to )
{
}
CTownList::~CTownList() CTownList::~CTownList()
{ {
delete arrup; delete arrup;
@ -1439,7 +1443,7 @@ void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
LOCPLINT->statusbar->print(items[from+ny]->name); LOCPLINT->statusbar->print(items[from+ny]->name);
} }
void CTownList::clickLeft(tribool down) void CTownList::clickLeft(tribool down, bool previousState)
{ {
if (down) if (down)
{ {
@ -1513,7 +1517,7 @@ void CTownList::clickLeft(tribool down)
} }
} }
void CTownList::clickRight(tribool down) void CTownList::clickRight(tribool down, bool previousState)
{ {
if (down) if (down)
{ {
@ -1588,6 +1592,10 @@ void CTownList::draw(SDL_Surface * to)
blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y,to); blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y,to);
} }
void CTownList::show( SDL_Surface * to )
{
}
CCreaturePic::CCreaturePic(const CCreature *cre, bool Big) CCreaturePic::CCreaturePic(const CCreature *cre, bool Big)
:c(cre),big(Big) :c(cre),big(Big)
@ -1665,7 +1673,7 @@ void CRecruitmentWindow::sliderMoved(int to)
{ {
buy->block(!to); buy->block(!to);
} }
void CRecruitmentWindow::clickLeft(tribool down) void CRecruitmentWindow::clickLeft(tribool down, bool previousState)
{ {
int curx = 192 + 51 - (CREATURE_WIDTH*creatures.size()/2) - (SPACE_BETWEEN*(creatures.size()-1)/2); int curx = 192 + 51 - (CREATURE_WIDTH*creatures.size()/2) - (SPACE_BETWEEN*(creatures.size()-1)/2);
for(int i=0;i<creatures.size();i++) for(int i=0;i<creatures.size();i++)
@ -1694,7 +1702,7 @@ void CRecruitmentWindow::clickLeft(tribool down)
curx += TOTAL_CREATURE_WIDTH; curx += TOTAL_CREATURE_WIDTH;
} }
} }
void CRecruitmentWindow::clickRight( boost::logic::tribool down ) void CRecruitmentWindow::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -1715,8 +1723,8 @@ void CRecruitmentWindow::clickRight( boost::logic::tribool down )
void CRecruitmentWindow::activate() void CRecruitmentWindow::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
buy->activate(); buy->activate();
max->activate(); max->activate();
cancel->activate(); cancel->activate();
@ -1726,8 +1734,8 @@ void CRecruitmentWindow::activate()
void CRecruitmentWindow::deactivate() void CRecruitmentWindow::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
buy->deactivate(); buy->deactivate();
max->deactivate(); max->deactivate();
cancel->deactivate(); cancel->deactivate();
@ -1917,8 +1925,8 @@ CSplitWindow::~CSplitWindow() //d-tor
void CSplitWindow::activate() void CSplitWindow::activate()
{ {
ClickableL::activate(); activateLClick();
KeyInterested::activate(); activateKeys();
ok->activate(); ok->activate();
cancel->activate(); cancel->activate();
slider->activate(); slider->activate();
@ -1926,8 +1934,8 @@ void CSplitWindow::activate()
void CSplitWindow::deactivate() void CSplitWindow::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
KeyInterested::deactivate(); deactivateKeys();
ok->deactivate(); ok->deactivate();
cancel->deactivate(); cancel->deactivate();
slider->deactivate(); slider->deactivate();
@ -1998,7 +2006,7 @@ void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key)
slider->moveTo(which ? ncur : a1+a2-ncur); slider->moveTo(which ? ncur : a1+a2-ncur);
} }
void CSplitWindow::clickLeft( boost::logic::tribool down ) void CSplitWindow::clickLeft(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -2230,7 +2238,7 @@ void CCreInfoWindow::activate()
//if(active) return; //if(active) return;
//active = true; //active = true;
if(!type) if(!type)
ClickableR::activate(); activateRClick();
if(ok) if(ok)
ok->activate(); ok->activate();
if(dismiss) if(dismiss)
@ -2244,7 +2252,7 @@ void CCreInfoWindow::close()
GH.popIntTotally(this); GH.popIntTotally(this);
} }
void CCreInfoWindow::clickRight(boost::logic::tribool down) void CCreInfoWindow::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
return; return;
@ -2265,7 +2273,7 @@ void CCreInfoWindow::deactivate()
//if(!active) return; //if(!active) return;
//active = false; //active = false;
if(!type) if(!type)
ClickableR::deactivate(); deactivateRClick();
if(ok) if(ok)
ok->deactivate(); ok->deactivate();
if(dismiss) if(dismiss)
@ -2452,7 +2460,7 @@ void CMarketplaceWindow::CTradeableItem::show(SDL_Surface * to)
blitAt(hlp,pos.x+19,pos.y+9,to); blitAt(hlp,pos.x+19,pos.y+9,to);
} }
void CMarketplaceWindow::CTradeableItem::clickLeft( boost::logic::tribool down ) void CMarketplaceWindow::CTradeableItem::clickLeft(tribool down, bool previousState)
{ {
CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(GH.topInt()); CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(GH.topInt());
assert(mw); assert(mw);
@ -2478,12 +2486,12 @@ void CMarketplaceWindow::CTradeableItem::clickLeft( boost::logic::tribool down )
void CMarketplaceWindow::CTradeableItem::activate() void CMarketplaceWindow::CTradeableItem::activate()
{ {
ClickableL::activate(); activateLClick();
} }
void CMarketplaceWindow::CTradeableItem::deactivate() void CMarketplaceWindow::CTradeableItem::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
} }
SDL_Surface * CMarketplaceWindow::CTradeableItem::getSurface() SDL_Surface * CMarketplaceWindow::CTradeableItem::getSurface()
@ -2965,25 +2973,25 @@ void CTavernWindow::show(SDL_Surface * to)
} }
} }
void CTavernWindow::HeroPortrait::clickLeft(boost::logic::tribool down) void CTavernWindow::HeroPortrait::clickLeft(tribool down, bool previousState)
{ {
if(pressedL && !down) if(previousState && !down)
as(); as();
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void CTavernWindow::HeroPortrait::activate() void CTavernWindow::HeroPortrait::activate()
{ {
ClickableL::activate(); activateLClick();
ClickableR::activate(); activateRClick();
Hoverable::activate(); activateHover();
} }
void CTavernWindow::HeroPortrait::deactivate() void CTavernWindow::HeroPortrait::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
ClickableR::deactivate(); deactivateRClick();
Hoverable::deactivate(); deactivateHover();
} }
void CTavernWindow::HeroPortrait::clickRight(boost::logic::tribool down) void CTavernWindow::HeroPortrait::clickRight(tribool down, bool previousState)
{ {
if(down) if(down)
{ {
@ -3022,7 +3030,7 @@ void CTavernWindow::HeroPortrait::show(SDL_Surface * to)
void CTavernWindow::HeroPortrait::hover( bool on ) void CTavernWindow::HeroPortrait::hover( bool on )
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if(on) if(on)
LOCPLINT->statusbar->print(hoverName); LOCPLINT->statusbar->print(hoverName);
else else
@ -3031,12 +3039,12 @@ void CTavernWindow::HeroPortrait::hover( bool on )
void CInGameConsole::activate() void CInGameConsole::activate()
{ {
KeyInterested::activate(); activateKeys();
} }
void CInGameConsole::deactivate() void CInGameConsole::deactivate()
{ {
KeyInterested::deactivate(); deactivateKeys();
} }
void CInGameConsole::show(SDL_Surface * to) void CInGameConsole::show(SDL_Surface * to)
@ -3325,16 +3333,16 @@ void CArtPlace::activate()
{ {
if(!active) if(!active)
{ {
//ClickableL::activate(); //activateLClick();
LRClickableAreaWTextComp::activate(); LRClickableAreaWTextComp::activate();
active = true; active = true;
} }
} }
void CArtPlace::clickLeft(boost::logic::tribool down) void CArtPlace::clickLeft(tribool down, bool previousState)
{ {
//LRClickableAreaWTextComp::clickLeft(down); //LRClickableAreaWTextComp::clickLeft(down);
if(ourArt && !down && pressedL) //we are spellbook if(ourArt && !down && previousState) //we are spellbook
{ {
if(ourArt->id == 0) if(ourArt->id == 0)
{ {
@ -3342,7 +3350,7 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
GH.pushInt(spellWindow); GH.pushInt(spellWindow);
} }
} }
if(!down && !clicked && pressedL) //not clicked before if(!down && !clicked && previousState) //not clicked before
{ {
if(ourArt && ourArt->id == 0) if(ourArt && ourArt->id == 0)
return; //this is handled separately return; //this is handled separately
@ -3381,19 +3389,19 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
clicked = false; clicked = false;
ourOwner->commonInfo->activeArtPlace = NULL; ourOwner->commonInfo->activeArtPlace = NULL;
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void CArtPlace::clickRight(boost::logic::tribool down) void CArtPlace::clickRight(tribool down, bool previousState)
{ {
if(text.size()) //if there is no description, do nothing ;] if(text.size()) //if there is no description, do nothing ;]
LRClickableAreaWTextComp::clickRight(down); LRClickableAreaWTextComp::clickRight(down, previousState);
} }
void CArtPlace::deactivate() void CArtPlace::deactivate()
{ {
if(active) if(active)
{ {
active = false; active = false;
//ClickableL::deactivate(); //deactivateLClick();
LRClickableAreaWTextComp::deactivate(); LRClickableAreaWTextComp::deactivate();
} }
} }
@ -3432,13 +3440,13 @@ CArtPlace::~CArtPlace()
void LClickableArea::activate() void LClickableArea::activate()
{ {
ClickableL::activate(); activateLClick();
} }
void LClickableArea::deactivate() void LClickableArea::deactivate()
{ {
ClickableL::deactivate(); deactivateLClick();
} }
void LClickableArea::clickLeft(boost::logic::tribool down) void LClickableArea::clickLeft(tribool down, bool previousState)
{ {
//if(!down) //if(!down)
//{ //{
@ -3448,13 +3456,13 @@ void LClickableArea::clickLeft(boost::logic::tribool down)
void RClickableArea::activate() void RClickableArea::activate()
{ {
ClickableR::activate(); activateRClick();
} }
void RClickableArea::deactivate() void RClickableArea::deactivate()
{ {
ClickableR::deactivate(); deactivateRClick();
} }
void RClickableArea::clickRight(boost::logic::tribool down) void RClickableArea::clickRight(tribool down, bool previousState)
{ {
//if(!down) //if(!down)
//{ //{
@ -3462,15 +3470,15 @@ void RClickableArea::clickRight(boost::logic::tribool down)
//} //}
} }
void LRClickableAreaWText::clickLeft(boost::logic::tribool down) void LRClickableAreaWText::clickLeft(tribool down, bool previousState)
{ {
if(!down && pressedL) if(!down && previousState)
{ {
LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(), soundBase::sound_todo); LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(), soundBase::sound_todo);
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void LRClickableAreaWText::clickRight(boost::logic::tribool down) void LRClickableAreaWText::clickRight(tribool down, bool previousState)
{ {
LOCPLINT->adventureInt->handleRightClick(text, down, this); LOCPLINT->adventureInt->handleRightClick(text, down, this);
} }
@ -3478,24 +3486,24 @@ void LRClickableAreaWText::activate()
{ {
LClickableArea::activate(); LClickableArea::activate();
RClickableArea::activate(); RClickableArea::activate();
Hoverable::activate(); activateHover();
} }
void LRClickableAreaWText::deactivate() void LRClickableAreaWText::deactivate()
{ {
LClickableArea::deactivate(); LClickableArea::deactivate();
RClickableArea::deactivate(); RClickableArea::deactivate();
Hoverable::deactivate(); deactivateHover();
} }
void LRClickableAreaWText::hover(bool on) void LRClickableAreaWText::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if (on) if (on)
LOCPLINT->statusbar->print(hoverText); LOCPLINT->statusbar->print(hoverText);
else if (LOCPLINT->statusbar->getCurrent()==hoverText) else if (LOCPLINT->statusbar->getCurrent()==hoverText)
LOCPLINT->statusbar->clear(); LOCPLINT->statusbar->clear();
} }
void LClickableAreaHero::clickLeft(boost::logic::tribool down) void LClickableAreaHero::clickLeft(tribool down, bool previousState)
{ {
if(!down) if(!down)
{ {
@ -3507,16 +3515,16 @@ void LClickableAreaHero::clickLeft(boost::logic::tribool down)
} }
} }
void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down) void LRClickableAreaWTextComp::clickLeft(tribool down, bool previousState)
{ {
if((!down) && pressedL) if((!down) && previousState)
{ {
std::vector<SComponent*> comp(1, new SComponent(SComponent::Etype(baseType), type, bonus)); std::vector<SComponent*> comp(1, new SComponent(SComponent::Etype(baseType), type, bonus));
LOCPLINT->showInfoDialog(text, comp, soundBase::sound_todo); LOCPLINT->showInfoDialog(text, comp, soundBase::sound_todo);
} }
ClickableL::clickLeft(down); //ClickableL::clickLeft(down);
} }
void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down) void LRClickableAreaWTextComp::clickRight(tribool down, bool previousState)
{ {
LOCPLINT->adventureInt->handleRightClick(text, down, this); LOCPLINT->adventureInt->handleRightClick(text, down, this);
} }
@ -3524,17 +3532,17 @@ void LRClickableAreaWTextComp::activate()
{ {
LClickableArea::activate(); LClickableArea::activate();
RClickableArea::activate(); RClickableArea::activate();
Hoverable::activate(); activateHover();
} }
void LRClickableAreaWTextComp::deactivate() void LRClickableAreaWTextComp::deactivate()
{ {
LClickableArea::deactivate(); LClickableArea::deactivate();
RClickableArea::deactivate(); RClickableArea::deactivate();
Hoverable::deactivate(); deactivateHover();
} }
void LRClickableAreaWTextComp::hover(bool on) void LRClickableAreaWTextComp::hover(bool on)
{ {
Hoverable::hover(on); //Hoverable::hover(on);
if (on) if (on)
LOCPLINT->statusbar->print(hoverText); LOCPLINT->statusbar->print(hoverText);
else if (LOCPLINT->statusbar->getCurrent()==hoverText) else if (LOCPLINT->statusbar->getCurrent()==hoverText)

View File

@ -85,13 +85,13 @@ public:
//notification - this class inherits important destructor from CInfoWindow //notification - this class inherits important destructor from CInfoWindow
}; };
class CRClickPopup : public IShowActivable, public ClickableR //popup displayed on R-click class CRClickPopup : public CIntObject //popup displayed on R-click
{ {
public: public:
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
virtual void close(); virtual void close();
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
virtual ~CRClickPopup(){}; //d-tor virtual ~CRClickPopup(){}; //d-tor
}; };
@ -118,7 +118,7 @@ public:
~CInfoPopup(){}; //d-tor ~CInfoPopup(){}; //d-tor
}; };
class SComponent : public ClickableR //common popup window component class SComponent : public virtual CIntObject //common popup window component
{ {
public: public:
enum Etype enum Etype
@ -137,7 +137,7 @@ public:
SComponent(){}; //c-tor SComponent(){}; //c-tor
virtual ~SComponent(){}; //d-tor virtual ~SComponent(){}; //d-tor
void clickRight (boost::logic::tribool down); //call-in void clickRight(tribool down, bool previousState); //call-in
virtual SDL_Surface * getImg(); virtual SDL_Surface * getImg();
virtual void show(SDL_Surface * to); virtual void show(SDL_Surface * to);
virtual void activate(); virtual void activate();
@ -163,7 +163,7 @@ public:
SDL_Surface * border, *myBitmap; SDL_Surface * border, *myBitmap;
boost::function<void()> onSelect; //function called on selection change boost::function<void()> onSelect; //function called on selection change
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(tribool down, bool previousState); //call-in
void init(SDL_Surface * Border); void init(SDL_Surface * Border);
CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor CSelectableComponent(const Component &c, boost::function<void()> OnSelect = 0, SDL_Surface * Border=NULL); //c-tor
@ -175,7 +175,7 @@ public:
SDL_Surface * getImg(); //returns myBitmap SDL_Surface * getImg(); //returns myBitmap
}; };
class CGarrisonInt; class CGarrisonInt;
class CGarrisonSlot : public ClickableL, public ClickableR, public Hoverable class CGarrisonSlot : public CIntObject
{ {
public: public:
CGarrisonInt *owner; CGarrisonInt *owner;
@ -186,8 +186,8 @@ public:
virtual void hover (bool on); //call-in virtual void hover (bool on); //call-in
const CArmedInstance * getObj(); const CArmedInstance * getObj();
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -246,8 +246,7 @@ public:
std::string getCurrent(); //getter for current std::string getCurrent(); //getter for current
}; };
class CList class CList : public CIntObject
: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public virtual CIntObject, public MotionInterested
{ {
public: public:
SDL_Surface * bg; //background bitmap SDL_Surface * bg; //background bitmap
@ -258,10 +257,10 @@ public:
int selected, //id of selected position, <0 if none int selected, //id of selected position, <0 if none
from; from;
const int SIZE; //size of list const int SIZE; //size of list
boost::logic::tribool pressed; //true=up; false=down; indeterminate=none tribool pressed; //true=up; false=down; indeterminate=none
CList(int Size = 5); //c-tor CList(int Size = 5); //c-tor
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in virtual void mouseMoved (const SDL_MouseMotionEvent & sEvent)=0; //call-in
@ -282,13 +281,14 @@ public:
void genList(); void genList();
void select(int which); //call-in void select(int which); //call-in
void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(tribool down, bool previousState); //call-in
void clickRight(boost::logic::tribool down); //call-in void clickRight(tribool down, bool previousState); //call-in
void hover (bool on); //call-in void hover (bool on); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it void updateHList(const CGHeroInstance *toRemove=NULL); //removes specific hero from the list or recreates it
void updateMove(const CGHeroInstance* which); //draws move points bar void updateMove(const CGHeroInstance* which); //draws move points bar
void draw(SDL_Surface * to); void draw(SDL_Surface * to);
void show(SDL_Surface * to);
void init(); void init();
}; };
@ -305,11 +305,12 @@ public:
void genList(); void genList();
void select(int which); //call-in void select(int which); //call-in
void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in void mouseMoved (const SDL_MouseMotionEvent & sEvent); //call-in
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(tribool down, bool previousState); //call-in
void clickRight(boost::logic::tribool down); //call-in void clickRight(tribool down, bool previousState); //call-in
void hover (bool on); //call-in void hover (bool on); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void draw(SDL_Surface * to); void draw(SDL_Surface * to);
void show(SDL_Surface * to);
}; };
class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation class CCreaturePic //draws picture with creature on background, use nextFrame=true to get animation
@ -324,7 +325,7 @@ public:
SDL_Surface * getPic(bool nextFrame); //returns frame of animation SDL_Surface * getPic(bool nextFrame); //returns frame of animation
}; };
class CRecruitmentWindow : public IShowActivable, public ClickableL, public ClickableR class CRecruitmentWindow : public CIntObject
{ {
public: public:
static const int SPACE_BETWEEN = 8; static const int SPACE_BETWEEN = 8;
@ -356,8 +357,8 @@ public:
void Buy(); void Buy();
void Cancel(); void Cancel();
void sliderMoved(int to); void sliderMoved(int to);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -367,7 +368,7 @@ public:
~CRecruitmentWindow(); //d-tor ~CRecruitmentWindow(); //d-tor
}; };
class CSplitWindow : public IShowActivable, public KeyInterested, public ClickableL class CSplitWindow : public CIntObject
{ {
public: public:
CGarrisonInt *gar; CGarrisonInt *gar;
@ -386,12 +387,12 @@ public:
void close(); void close();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down); //call-in void clickLeft(tribool down, bool previousState); //call-in
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void sliderMoved(int to); void sliderMoved(int to);
}; };
class CCreInfoWindow : public IShowActivable, public KeyInterested, public ClickableR class CCreInfoWindow : public CIntObject
{ {
public: public:
//bool active; //TODO: comment me //bool active; //TODO: comment me
@ -410,14 +411,14 @@ public:
~CCreInfoWindow(); //d-tor ~CCreInfoWindow(); //d-tor
void activate(); void activate();
void close(); void close();
void clickRight(boost::logic::tribool down); //call-in void clickRight(tribool down, bool previousState); //call-in
void dismissF(); void dismissF();
void keyPressed (const SDL_KeyboardEvent & key); //call-in void keyPressed (const SDL_KeyboardEvent & key); //call-in
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
}; };
class CLevelWindow : public IShowActivable, public CIntObject class CLevelWindow : public CIntObject
{ {
public: public:
int heroType; int heroType;
@ -435,7 +436,7 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
}; };
class CMinorResDataBar : public IShowable, public CIntObject class CMinorResDataBar : public CIntObject
{ {
public: public:
SDL_Surface *bg; //background bitmap SDL_Surface *bg; //background bitmap
@ -444,10 +445,10 @@ public:
~CMinorResDataBar(); //d-tor ~CMinorResDataBar(); //d-tor
}; };
class CMarketplaceWindow : public IShowActivable, public CIntObject class CMarketplaceWindow : public CIntObject
{ {
public: public:
class CTradeableItem : public ClickableL class CTradeableItem : public CIntObject
{ {
public: public:
int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag int type; //0 - res, 1 - artif big, 2 - artif small, 3 - player flag
@ -458,7 +459,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
SDL_Surface *getSurface(); SDL_Surface *getSurface();
CTradeableItem(int Type, int ID, bool Left); CTradeableItem(int Type, int ID, bool Left);
}; };
@ -486,7 +487,7 @@ public:
void clear(); void clear();
}; };
class CSystemOptionsWindow : public IShowActivable, public CIntObject class CSystemOptionsWindow : public CIntObject
{ {
private: private:
SDL_Surface * background; //background of window SDL_Surface * background; //background of window
@ -508,10 +509,10 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
}; };
class CTavernWindow : public IShowActivable, public CIntObject class CTavernWindow : public CIntObject
{ {
public: public:
class HeroPortrait : public ClickableL, public ClickableR, public Hoverable class HeroPortrait : public CIntObject
{ {
public: public:
std::string hoverName; std::string hoverName;
@ -519,8 +520,8 @@ public:
const CGHeroInstance *h; const CGHeroInstance *h;
void activate(); void activate();
void deactivate(); void deactivate();
void clickLeft(boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight(boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void hover (bool on); void hover (bool on);
HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H); HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H);
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -544,7 +545,7 @@ public:
void show(SDL_Surface * to); void show(SDL_Surface * to);
}; };
class CInGameConsole : public IShowActivable, public KeyInterested class CInGameConsole : public CIntObject
{ {
private: private:
std::list< std::pair< std::string, int > > texts; //<text to show, time of add> std::list< std::pair< std::string, int > > texts; //<text to show, time of add>
@ -569,18 +570,18 @@ public:
}; };
class LClickableArea: public ClickableL class LClickableArea: public virtual CIntObject
{ {
public: public:
virtual void clickLeft (boost::logic::tribool down); virtual void clickLeft(tribool down, bool previousState);
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
}; };
class RClickableArea: public ClickableR class RClickableArea: public virtual CIntObject
{ {
public: public:
virtual void clickRight (boost::logic::tribool down); virtual void clickRight(tribool down, bool previousState);
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
}; };
@ -590,21 +591,21 @@ class LClickableAreaHero : public LClickableArea
public: public:
int id; int id;
CHeroWindow * owner; CHeroWindow * owner;
virtual void clickLeft (boost::logic::tribool down); virtual void clickLeft(tribool down, bool previousState);
}; };
class LRClickableAreaWText: public LClickableArea, public RClickableArea, public Hoverable class LRClickableAreaWText: public LClickableArea, public RClickableArea
{ {
public: public:
std::string text, hoverText; std::string text, hoverText;
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
virtual void clickLeft (boost::logic::tribool down); virtual void clickLeft(tribool down, bool previousState);
virtual void clickRight (boost::logic::tribool down); virtual void clickRight(tribool down, bool previousState);
virtual void hover(bool on); virtual void hover(bool on);
}; };
class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea, public Hoverable class LRClickableAreaWTextComp: public LClickableArea, public RClickableArea
{ {
public: public:
std::string text, hoverText; std::string text, hoverText;
@ -612,12 +613,12 @@ public:
int bonus, type; int bonus, type;
virtual void activate(); virtual void activate();
virtual void deactivate(); virtual void deactivate();
virtual void clickLeft (boost::logic::tribool down); virtual void clickLeft(tribool down, bool previousState);
virtual void clickRight (boost::logic::tribool down); virtual void clickRight(tribool down, bool previousState);
virtual void hover(bool on); virtual void hover(bool on);
}; };
class CArtPlace: public IShowable, public LRClickableAreaWTextComp class CArtPlace: public LRClickableAreaWTextComp
{ {
private: private:
bool active; bool active;
@ -631,8 +632,8 @@ public:
CArtifactsOfHero * ourOwner; CArtifactsOfHero * ourOwner;
const CArtifact * ourArt; const CArtifact * ourArt;
CArtPlace(const CArtifact * Art); //c-tor CArtPlace(const CArtifact * Art); //c-tor
void clickLeft (boost::logic::tribool down); void clickLeft(tribool down, bool previousState);
void clickRight (boost::logic::tribool down); void clickRight(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -641,7 +642,7 @@ public:
}; };
class CArtifactsOfHero : public IShowActivable, public CIntObject class CArtifactsOfHero : public CIntObject
{ {
const CGHeroInstance * curHero; const CGHeroInstance * curHero;
@ -672,7 +673,7 @@ public:
friend class CArtPlace; friend class CArtPlace;
}; };
class CGarrisonWindow : public CWindowWithGarrison, public CIntObject class CGarrisonWindow : public CWindowWithGarrison
{ {
public: public:
SDL_Surface *bg; //background surface SDL_Surface *bg; //background surface
@ -686,7 +687,7 @@ public:
~CGarrisonWindow(); //d-tor ~CGarrisonWindow(); //d-tor
}; };
class CExchangeWindow : public CIntObject, public CWindowWithGarrison class CExchangeWindow : public CWindowWithGarrison
{ {
CStatusBar * ourBar; //internal statusbar CStatusBar * ourBar; //internal statusbar
@ -715,7 +716,7 @@ public:
~CExchangeWindow(); //d-tor ~CExchangeWindow(); //d-tor
}; };
class CShipyardWindow : public CIntObject, public IShowActivable class CShipyardWindow : public CIntObject
{ {
public: public:
CStatusBar *bar; CStatusBar *bar;

View File

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <algorithm> //std::find #include <algorithm> //std::find
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
using boost::logic::tribool;
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes) typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes) typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)

View File

@ -24,7 +24,6 @@
* *
*/ */
using boost::logic::tribool;
class IGameCallback; class IGameCallback;
struct BattleResult; struct BattleResult;
class CCPPObjectScript; class CCPPObjectScript;

View File

@ -1368,7 +1368,7 @@ bool CGameHandler::moveHero( si32 hid, int3 dst, ui8 instant, ui8 asker /*= 255*
if(obj->tempOwner==h->tempOwner) if(obj->tempOwner==h->tempOwner)
{ {
heroExchange(h->id, dh->id); heroExchange(dh->id, h->id);
return true; return true;
} }
//TODO: check for ally //TODO: check for ally