2009-05-21 03:55:30 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2009-08-07 01:36:51 +03:00
|
|
|
#include <cassert>
|
|
|
|
#include <boost/thread/locks.hpp>
|
|
|
|
#include "GUIBase.h"
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <queue>
|
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "CCursorHandler.h"
|
2009-08-27 11:04:32 +03:00
|
|
|
#include "CBitmapHandler.h"
|
2010-05-08 01:10:32 +03:00
|
|
|
#include "Graphics.h"
|
2011-02-24 15:57:47 +02:00
|
|
|
#include "../CThreadHelper.h"
|
2011-04-06 23:30:59 +03:00
|
|
|
#include "CConfigHandler.h"
|
2011-04-17 21:02:13 +03:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2011-04-03 13:45:39 +03:00
|
|
|
|
2009-05-20 12:02:50 +03:00
|
|
|
/*
|
|
|
|
* GUIBase.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-08-07 01:36:51 +03:00
|
|
|
extern std::queue<SDL_Event*> events;
|
|
|
|
extern boost::mutex eventsM;
|
|
|
|
|
2009-05-20 12:02:50 +03:00
|
|
|
void KeyShortcut::keyPressed(const SDL_KeyboardEvent & key)
|
|
|
|
{
|
|
|
|
if(vstd::contains(assignedKeys,key.keysym.sym))
|
|
|
|
{
|
2009-08-18 11:22:56 +03:00
|
|
|
bool prev = pressedL;
|
|
|
|
if(key.state == SDL_PRESSED)
|
|
|
|
{
|
2009-08-17 16:14:37 +03:00
|
|
|
pressedL = true;
|
2009-08-18 11:22:56 +03:00
|
|
|
clickLeft(true, prev);
|
2010-03-28 00:00:55 +02:00
|
|
|
}
|
|
|
|
else
|
2009-08-18 11:22:56 +03:00
|
|
|
{
|
2009-08-17 16:14:37 +03:00
|
|
|
pressedL = false;
|
2009-08-18 11:22:56 +03:00
|
|
|
clickLeft(false, prev);
|
2009-08-17 16:14:37 +03:00
|
|
|
}
|
2009-05-20 12:02:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-07 01:36:51 +03:00
|
|
|
void CGuiHandler::popInt( IShowActivable *top )
|
|
|
|
{
|
|
|
|
assert(listInt.front() == top);
|
|
|
|
top->deactivate();
|
|
|
|
listInt.pop_front();
|
|
|
|
objsToBlit -= top;
|
|
|
|
if(listInt.size())
|
|
|
|
listInt.front()->activate();
|
|
|
|
totalRedraw();
|
2011-03-22 15:19:07 +02:00
|
|
|
fakeMouseMove();
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::popIntTotally( IShowActivable *top )
|
|
|
|
{
|
|
|
|
assert(listInt.front() == top);
|
|
|
|
popInt(top);
|
|
|
|
delete top;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::pushInt( IShowActivable *newInt )
|
|
|
|
{
|
|
|
|
//a new interface will be present, we'll need to use buffer surface (unless it's advmapint that will alter screenBuf on activate anyway)
|
|
|
|
screenBuf = screen2;
|
|
|
|
|
|
|
|
if(listInt.size())
|
|
|
|
listInt.front()->deactivate();
|
|
|
|
listInt.push_front(newInt);
|
|
|
|
newInt->activate();
|
|
|
|
objsToBlit.push_back(newInt);
|
|
|
|
totalRedraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::popInts( int howMany )
|
|
|
|
{
|
|
|
|
if(!howMany) return; //senseless but who knows...
|
|
|
|
|
2010-05-08 21:56:38 +03:00
|
|
|
assert(listInt.size() >= howMany);
|
2009-08-07 01:36:51 +03:00
|
|
|
listInt.front()->deactivate();
|
|
|
|
for(int i=0; i < howMany; i++)
|
|
|
|
{
|
|
|
|
objsToBlit -= listInt.front();
|
|
|
|
delete listInt.front();
|
|
|
|
listInt.pop_front();
|
|
|
|
}
|
2010-05-08 21:56:38 +03:00
|
|
|
|
|
|
|
if(listInt.size())
|
|
|
|
{
|
|
|
|
listInt.front()->activate();
|
|
|
|
totalRedraw();
|
|
|
|
}
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
IShowActivable * CGuiHandler::topInt()
|
|
|
|
{
|
|
|
|
if(!listInt.size())
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return listInt.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::totalRedraw()
|
2011-04-05 20:38:24 +03:00
|
|
|
{
|
2011-04-13 22:52:56 +03:00
|
|
|
//this->invalidateTotalRedraw = true;
|
|
|
|
internalTotalRedraw();
|
2011-04-05 20:38:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::internalTotalRedraw()
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
for(int i=0;i<objsToBlit.size();i++)
|
|
|
|
objsToBlit[i]->showAll(screen2);
|
|
|
|
|
|
|
|
blitAt(screen2,0,0,screen);
|
|
|
|
|
2011-04-07 20:54:08 +03:00
|
|
|
//Any reason to blit last object second time?
|
|
|
|
//if(objsToBlit.size())
|
|
|
|
// objsToBlit.back()->showAll(screen);
|
2011-04-05 20:38:24 +03:00
|
|
|
|
|
|
|
this->invalidateTotalRedraw = false;
|
|
|
|
this->invalidateSimpleRedraw = false;
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::updateTime()
|
|
|
|
{
|
|
|
|
int tv = th.getDif();
|
2009-08-11 19:05:33 +03:00
|
|
|
std::list<CIntObject*> hlp = timeinterested;
|
|
|
|
for (std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end();i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(timeinterested,*i)) continue;
|
|
|
|
if ((*i)->toNextTick>=0)
|
|
|
|
(*i)->toNextTick-=tv;
|
|
|
|
if ((*i)->toNextTick<0)
|
|
|
|
(*i)->tick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::handleEvents()
|
|
|
|
{
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
SDL_Event *ev = NULL;
|
2010-02-28 14:39:38 +02:00
|
|
|
boost::unique_lock<boost::mutex> lock(eventsM);
|
|
|
|
if(!events.size())
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2010-02-28 14:39:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ev = events.front();
|
|
|
|
events.pop();
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
handleEvent(ev);
|
|
|
|
delete ev;
|
|
|
|
}
|
2009-05-20 12:02:50 +03:00
|
|
|
}
|
|
|
|
|
2009-08-07 01:36:51 +03:00
|
|
|
void CGuiHandler::handleEvent(SDL_Event *sEvent)
|
|
|
|
{
|
|
|
|
current = sEvent;
|
2009-08-11 19:05:33 +03:00
|
|
|
bool prev;
|
2009-08-07 01:36:51 +03:00
|
|
|
|
|
|
|
if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
|
|
|
|
{
|
|
|
|
SDL_KeyboardEvent key = sEvent->key;
|
|
|
|
|
|
|
|
//translate numpad keys
|
2009-09-07 05:29:44 +03:00
|
|
|
if(key.keysym.sym == SDLK_KP_ENTER)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
key.keysym.sym = (SDLKey)SDLK_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool keysCaptured = false;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=keyinterested.begin(); i != keyinterested.end() && current; i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
if((*i)->captureAllKeys)
|
|
|
|
{
|
|
|
|
keysCaptured = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
std::list<CIntObject*> miCopy = keyinterested;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end() && current; i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
if(vstd::contains(keyinterested,*i) && (!keysCaptured || (*i)->captureAllKeys))
|
|
|
|
(**i).keyPressed(key);
|
|
|
|
}
|
|
|
|
else if(sEvent->type==SDL_MOUSEMOTION)
|
|
|
|
{
|
2010-12-19 16:39:56 +02:00
|
|
|
CCS->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
|
2009-08-07 01:36:51 +03:00
|
|
|
handleMouseMotion(sEvent);
|
|
|
|
}
|
2009-08-23 21:01:08 +03:00
|
|
|
else if (sEvent->type==SDL_MOUSEBUTTONDOWN)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-08-23 21:01:08 +03:00
|
|
|
if(sEvent->button.button == SDL_BUTTON_LEFT)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-08-23 21:01:08 +03:00
|
|
|
|
|
|
|
if(lastClick == sEvent->motion && (SDL_GetTicks() - lastClickTime) < 300)
|
|
|
|
{
|
|
|
|
std::list<CIntObject*> hlp = doubleClickInterested;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-23 21:01:08 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(doubleClickInterested,*i)) continue;
|
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
|
|
|
(*i)->onDoubleClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lastClick = sEvent->motion;
|
|
|
|
lastClickTime = SDL_GetTicks();
|
|
|
|
|
|
|
|
std::list<CIntObject*> hlp = lclickable;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-08-23 21:01:08 +03:00
|
|
|
if(!vstd::contains(lclickable,*i)) continue;
|
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
|
|
|
prev = (*i)->pressedL;
|
|
|
|
(*i)->pressedL = true;
|
|
|
|
(*i)->clickLeft(true, prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sEvent->button.button == SDL_BUTTON_RIGHT)
|
|
|
|
{
|
|
|
|
std::list<CIntObject*> hlp = rclickable;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-23 21:01:08 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(rclickable,*i)) continue;
|
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
|
|
|
prev = (*i)->pressedR;
|
|
|
|
(*i)->pressedR = true;
|
|
|
|
(*i)->clickRight(true, prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP)
|
|
|
|
{
|
|
|
|
std::list<CIntObject*> hlp = wheelInterested;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-23 21:01:08 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(wheelInterested,*i)) continue;
|
|
|
|
(*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y));
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
std::list<CIntObject*> hlp = lclickable;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(lclickable,*i)) continue;
|
2009-08-11 19:05:33 +03:00
|
|
|
prev = (*i)->pressedL;
|
|
|
|
(*i)->pressedL = false;
|
2009-08-07 01:36:51 +03:00
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
(*i)->clickLeft(false, prev);
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
else
|
2009-08-11 19:05:33 +03:00
|
|
|
(*i)->clickLeft(boost::logic::indeterminate, prev);
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT))
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
std::list<CIntObject*> hlp = rclickable;
|
2010-02-16 18:35:24 +02:00
|
|
|
for(std::list<CIntObject*>::iterator i=hlp.begin(); i != hlp.end() && current; i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
if(!vstd::contains(rclickable,*i)) continue;
|
2009-08-11 19:05:33 +03:00
|
|
|
prev = (*i)->pressedR;
|
|
|
|
(*i)->pressedR = false;
|
2009-08-07 01:36:51 +03:00
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
2009-08-11 19:05:33 +03:00
|
|
|
(*i)->clickRight(false, prev);
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
else
|
2009-08-11 19:05:33 +03:00
|
|
|
(*i)->clickRight(boost::logic::indeterminate, prev);
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
current = NULL;
|
|
|
|
|
|
|
|
} //event end
|
|
|
|
|
|
|
|
void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
|
|
|
|
{
|
|
|
|
//sending active, hovered hoverable objects hover() call
|
2009-08-11 19:05:33 +03:00
|
|
|
std::vector<CIntObject*> hlp;
|
|
|
|
for(std::list<CIntObject*>::iterator i=hoverable.begin(); i != hoverable.end();i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
|
|
|
if (isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y))
|
|
|
|
{
|
|
|
|
if (!(*i)->hovered)
|
|
|
|
hlp.push_back((*i));
|
|
|
|
}
|
|
|
|
else if ((*i)->hovered)
|
|
|
|
{
|
|
|
|
(*i)->hover(false);
|
2009-08-11 19:05:33 +03:00
|
|
|
(*i)->hovered = false;
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=0; i<hlp.size();i++)
|
2009-08-11 19:05:33 +03:00
|
|
|
{
|
2009-08-07 01:36:51 +03:00
|
|
|
hlp[i]->hover(true);
|
2009-08-11 19:05:33 +03:00
|
|
|
hlp[i]->hovered = true;
|
|
|
|
}
|
|
|
|
|
2009-09-24 16:23:52 +03:00
|
|
|
handleMoveInterested(sEvent->motion);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::simpleRedraw()
|
2011-04-05 20:38:24 +03:00
|
|
|
{
|
2011-04-13 22:52:56 +03:00
|
|
|
//this->invalidateSimpleRedraw = true;
|
|
|
|
internalSimpleRedraw();
|
2011-04-05 20:38:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGuiHandler::internalSimpleRedraw()
|
2009-09-24 16:23:52 +03:00
|
|
|
{
|
|
|
|
//update only top interface and draw background
|
|
|
|
if(objsToBlit.size() > 1)
|
|
|
|
blitAt(screen2,0,0,screen); //blit background
|
|
|
|
objsToBlit.back()->show(screen); //blit active interface/window
|
2011-04-05 20:38:24 +03:00
|
|
|
|
|
|
|
this->invalidateSimpleRedraw = false;
|
2009-09-24 16:23:52 +03:00
|
|
|
}
|
2009-08-07 01:36:51 +03:00
|
|
|
|
2009-09-24 16:23:52 +03:00
|
|
|
void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion )
|
|
|
|
{
|
2009-08-07 01:36:51 +03:00
|
|
|
//sending active, MotionInterested objects mouseMoved() call
|
2009-08-11 19:05:33 +03:00
|
|
|
std::list<CIntObject*> miCopy = motioninterested;
|
|
|
|
for(std::list<CIntObject*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-09-24 16:23:52 +03:00
|
|
|
if ((*i)->strongInterest || isItIn(&(*i)->pos, motion.x, motion.y))
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-09-24 16:23:52 +03:00
|
|
|
(*i)->mouseMoved(motion);
|
2009-08-07 01:36:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 16:23:52 +03:00
|
|
|
void CGuiHandler::fakeMouseMove()
|
2009-08-07 01:36:51 +03:00
|
|
|
{
|
2009-11-14 22:14:15 +02:00
|
|
|
SDL_Event evnt;
|
|
|
|
|
2009-09-24 16:23:52 +03:00
|
|
|
SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0};
|
|
|
|
int x, y;
|
|
|
|
sme.state = SDL_GetMouseState(&x, &y);
|
|
|
|
sme.x = x;
|
|
|
|
sme.y = y;
|
2009-11-14 22:14:15 +02:00
|
|
|
|
|
|
|
evnt.motion = sme;
|
|
|
|
current = &evnt;
|
2011-03-22 15:19:07 +02:00
|
|
|
handleMouseMotion(&evnt);
|
2009-08-11 19:05:33 +03:00
|
|
|
}
|
|
|
|
|
2009-12-28 06:08:24 +02:00
|
|
|
void CGuiHandler::run()
|
|
|
|
{
|
2011-02-24 15:57:47 +02:00
|
|
|
setThreadName(-1, "CGuiHandler::run");
|
2009-12-28 06:08:24 +02:00
|
|
|
try
|
|
|
|
{
|
2011-04-07 20:54:08 +03:00
|
|
|
//CCS->curh->centerCursor();//Is this essential? random crashes on Linux
|
|
|
|
|
2011-04-05 20:38:24 +03:00
|
|
|
mainFPSmng->init(); // resets internal clock, needed for FPS manager
|
2009-12-28 06:08:24 +02:00
|
|
|
while(!terminate)
|
|
|
|
{
|
|
|
|
if(curInt)
|
2011-04-05 20:38:24 +03:00
|
|
|
curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment
|
2011-04-17 21:02:13 +03:00
|
|
|
|
2011-04-05 20:38:24 +03:00
|
|
|
mainFPSmng->framerateDelay(); // holds a constant FPS
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
|
|
|
} HANDLE_EXCEPTION
|
|
|
|
}
|
|
|
|
|
|
|
|
CGuiHandler::CGuiHandler()
|
|
|
|
:lastClick(-500, -500)
|
|
|
|
{
|
|
|
|
curInt = NULL;
|
|
|
|
current = NULL;
|
|
|
|
terminate = false;
|
2010-02-15 08:54:57 +02:00
|
|
|
statusbar = NULL;
|
2011-04-03 13:45:39 +03:00
|
|
|
|
2011-04-05 20:38:24 +03:00
|
|
|
// Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate
|
|
|
|
mainFPSmng = new FPSManager(48);
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CGuiHandler::~CGuiHandler()
|
|
|
|
{
|
2011-04-03 13:45:39 +03:00
|
|
|
delete mainFPSmng;
|
2009-12-28 06:08:24 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 13:09:29 +03:00
|
|
|
void CGuiHandler::breakEventHandling()
|
|
|
|
{
|
|
|
|
current = NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-05 20:38:24 +03:00
|
|
|
void CGuiHandler::drawFPSCounter()
|
|
|
|
{
|
|
|
|
const static SDL_Color yellow = {255, 255, 0, 0};
|
|
|
|
static SDL_Rect overlay = { 0, 0, 64, 32};
|
|
|
|
Uint32 black = SDL_MapRGB(screen->format, 10, 10, 10);
|
|
|
|
SDL_FillRect(screen, &overlay, black);
|
2011-04-17 21:02:13 +03:00
|
|
|
std::string fps = boost::lexical_cast<std::string>(mainFPSmng->fps);
|
2011-04-05 20:38:24 +03:00
|
|
|
CSDL_Ext::printAt(fps, 10, 10, FONT_BIG, yellow, screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-11 19:05:33 +03:00
|
|
|
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()
|
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
pressedL = pressedR = hovered = captureAllKeys = strongInterest = false;
|
|
|
|
toNextTick = active = used = 0;
|
2009-08-17 11:50:31 +03:00
|
|
|
|
|
|
|
recActions = defActions = GH.defActionsDef;
|
|
|
|
|
|
|
|
pos.x = 0;
|
|
|
|
pos.y = 0;
|
|
|
|
pos.w = 0;
|
|
|
|
pos.h = 0;
|
|
|
|
|
|
|
|
if(GH.captureChildren)
|
|
|
|
{
|
|
|
|
assert(GH.createdObj.size());
|
|
|
|
parent = GH.createdObj.front();
|
|
|
|
parent->children.push_back(this);
|
|
|
|
|
|
|
|
if(parent->defActions & SHARE_POS)
|
|
|
|
{
|
|
|
|
pos.x = parent->pos.x;
|
|
|
|
pos.y = parent->pos.y;
|
|
|
|
}
|
|
|
|
}
|
2009-12-28 06:08:24 +02:00
|
|
|
else
|
|
|
|
parent = NULL;
|
2009-08-11 19:05:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::show( SDL_Surface * to )
|
|
|
|
{
|
2009-08-17 11:50:31 +03:00
|
|
|
if(defActions & UPDATE)
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
if(children[i]->recActions & UPDATE)
|
|
|
|
children[i]->show(to);
|
|
|
|
}
|
2009-08-11 19:05:33 +03:00
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
void CIntObject::showAll( SDL_Surface * to )
|
|
|
|
{
|
|
|
|
if(defActions & SHOWALL)
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
if(children[i]->recActions & SHOWALL)
|
|
|
|
children[i]->showAll(to);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
show(to);
|
2009-08-11 19:05:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::activate()
|
|
|
|
{
|
2009-08-17 11:50:31 +03:00
|
|
|
assert(!active);
|
|
|
|
active |= GENERAL;
|
2010-07-06 05:10:26 +03:00
|
|
|
activate(used);
|
|
|
|
|
|
|
|
if(defActions & ACTIVATE)
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
if(children[i]->recActions & ACTIVATE)
|
|
|
|
children[i]->activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::activate(ui16 what)
|
|
|
|
{
|
|
|
|
if(what & LCLICK)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateLClick();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & RCLICK)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateRClick();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & HOVER)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateHover();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & MOVE)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateMouseMove();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & KEYBOARD)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateKeys();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & TIME)
|
2009-08-17 11:50:31 +03:00
|
|
|
activateTimer();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & WHEEL)
|
2009-08-23 21:01:08 +03:00
|
|
|
activateWheel();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & DOUBLECLICK)
|
2009-08-23 21:01:08 +03:00
|
|
|
activateDClick();
|
2009-08-11 19:05:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::deactivate()
|
|
|
|
{
|
2009-08-17 11:50:31 +03:00
|
|
|
assert(active);
|
|
|
|
active &= ~ GENERAL;
|
2010-07-06 05:10:26 +03:00
|
|
|
deactivate(used);
|
|
|
|
|
|
|
|
assert(!active);
|
|
|
|
|
|
|
|
if(defActions & DEACTIVATE)
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
if(children[i]->recActions & DEACTIVATE)
|
|
|
|
children[i]->deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::deactivate(ui16 what)
|
|
|
|
{
|
|
|
|
if(what & LCLICK)
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateLClick();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & RCLICK)
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateRClick();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & HOVER)
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateHover();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & MOVE)
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateMouseMove();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & KEYBOARD)
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateKeys();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & TIME) // TIME is special
|
2009-08-17 11:50:31 +03:00
|
|
|
deactivateTimer();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & WHEEL)
|
2009-08-23 21:01:08 +03:00
|
|
|
deactivateWheel();
|
2010-07-06 05:10:26 +03:00
|
|
|
if(what & DOUBLECLICK)
|
2009-08-23 21:01:08 +03:00
|
|
|
deactivateDClick();
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CIntObject::~CIntObject()
|
|
|
|
{
|
|
|
|
assert(!active); //do not delete active obj
|
|
|
|
|
|
|
|
if(defActions & DISPOSE)
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
if(children[i]->recActions & DISPOSE)
|
|
|
|
delete children[i];
|
2010-02-15 08:54:57 +02:00
|
|
|
|
2010-02-15 13:37:47 +02:00
|
|
|
if(parent && GH.createdObj.size()) //temporary object destroyed
|
2010-02-15 08:54:57 +02:00
|
|
|
parent->children -= this;
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
void CIntObject::printAtLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ )
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::printAt(text, pos.x + x, pos.y + y, font, kolor, dst);
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
void CIntObject::printAtMiddleLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor/*=zwykly*/, SDL_Surface * dst/*=screen*/ )
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::printAtMiddle(text, pos.x + x, pos.y + y, font, kolor, dst);
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
void CIntObject::printAtMiddleLoc(const std::string & text, const Point &p, EFonts font, SDL_Color kolor, SDL_Surface * dst)
|
2010-06-27 19:03:01 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
printAtMiddleLoc(text, p.x, p.y, font, kolor, dst);
|
2010-06-27 19:03:01 +03:00
|
|
|
}
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
void CIntObject::blitAtLoc( SDL_Surface * src, int x, int y, SDL_Surface * dst )
|
|
|
|
{
|
|
|
|
blitAt(src, pos.x + x, pos.y + y, dst);
|
|
|
|
}
|
|
|
|
|
2010-06-27 19:03:01 +03:00
|
|
|
void CIntObject::blitAtLoc(SDL_Surface * src, const Point &p, SDL_Surface * dst)
|
|
|
|
{
|
|
|
|
blitAtLoc(src, p.x, p.y, dst);
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
void CIntObject::printAtMiddleWBLoc( const std::string & text, int x, int y, EFonts font, int charpr, SDL_Color kolor, SDL_Surface * dst)
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::printAtMiddleWB(text, pos.x + x, pos.y + y, font, charpr, kolor, dst);
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
void CIntObject::printToLoc( const std::string & text, int x, int y, EFonts font, SDL_Color kolor, SDL_Surface * dst )
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::printTo(text, pos.x + x, pos.y + y, font, kolor, dst);
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2009-08-18 11:22:56 +03:00
|
|
|
void CIntObject::disable()
|
|
|
|
{
|
|
|
|
if(active)
|
|
|
|
deactivate();
|
|
|
|
|
|
|
|
recActions = DISPOSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::enable(bool activation)
|
|
|
|
{
|
|
|
|
if(!active && activation)
|
|
|
|
activate();
|
|
|
|
|
|
|
|
recActions = 255;
|
|
|
|
}
|
|
|
|
|
2009-08-22 16:59:15 +03:00
|
|
|
bool CIntObject::isItInLoc( const SDL_Rect &rect, int x, int y )
|
|
|
|
{
|
|
|
|
return isItIn(&rect, x - pos.x, y - pos.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CIntObject::isItInLoc( const SDL_Rect &rect, const Point &p )
|
|
|
|
{
|
|
|
|
return isItIn(&rect, p.x - pos.x, p.y - pos.y);
|
|
|
|
}
|
|
|
|
|
2009-08-23 21:01:08 +03:00
|
|
|
void CIntObject::activateWheel()
|
|
|
|
{
|
|
|
|
GH.wheelInterested.push_front(this);
|
|
|
|
active |= WHEEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::deactivateWheel()
|
|
|
|
{
|
|
|
|
std::list<CIntObject*>::iterator hlp = std::find(GH.wheelInterested.begin(),GH.wheelInterested.end(),this);
|
|
|
|
assert(hlp != GH.wheelInterested.end());
|
|
|
|
GH.wheelInterested.erase(hlp);
|
|
|
|
active &= ~WHEEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::wheelScrolled(bool down, bool in)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::activateDClick()
|
|
|
|
{
|
|
|
|
GH.doubleClickInterested.push_front(this);
|
|
|
|
active |= DOUBLECLICK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::deactivateDClick()
|
|
|
|
{
|
|
|
|
std::list<CIntObject*>::iterator hlp = std::find(GH.doubleClickInterested.begin(),GH.doubleClickInterested.end(),this);
|
|
|
|
assert(hlp != GH.doubleClickInterested.end());
|
|
|
|
GH.doubleClickInterested.erase(hlp);
|
|
|
|
active &= ~DOUBLECLICK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::onDoubleClick()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
const Rect & CIntObject::center( const Rect &r, bool propagate )
|
2009-08-27 11:04:32 +03:00
|
|
|
{
|
|
|
|
pos.w = r.w;
|
|
|
|
pos.h = r.h;
|
2011-03-12 23:55:31 +02:00
|
|
|
return center(Point(screen->w/2, screen->h/2), propagate);
|
2009-08-27 11:04:32 +03:00
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
const Rect & CIntObject::center( bool propagate )
|
2009-08-27 11:04:32 +03:00
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
return center(pos, propagate);
|
2009-08-27 11:04:32 +03:00
|
|
|
}
|
|
|
|
|
2011-03-12 23:55:31 +02:00
|
|
|
const Rect & CIntObject::center(const Point &p, bool propagate /*= true*/)
|
|
|
|
{
|
|
|
|
moveBy(Point(p.x - pos.w/2 - pos.x,
|
|
|
|
p.y - pos.h/2 - pos.y),
|
|
|
|
propagate);
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2011-03-20 00:27:05 +02:00
|
|
|
void CIntObject::fitToScreen(int borderWidth, bool propagate)
|
|
|
|
{
|
|
|
|
Point newPos = pos.topLeft();
|
|
|
|
amax(newPos.x, borderWidth);
|
|
|
|
amax(newPos.y, borderWidth);
|
|
|
|
amin(newPos.x, screen->w - borderWidth - pos.w);
|
|
|
|
amin(newPos.y, screen->h - borderWidth - pos.h);
|
|
|
|
if (newPos != pos.topLeft())
|
|
|
|
moveTo(newPos, propagate);
|
|
|
|
}
|
|
|
|
|
2009-09-20 15:47:40 +03:00
|
|
|
void CIntObject::moveBy( const Point &p, bool propagate /*= true*/ )
|
|
|
|
{
|
|
|
|
pos.x += p.x;
|
|
|
|
pos.y += p.y;
|
|
|
|
if(propagate)
|
|
|
|
for(size_t i = 0; i < children.size(); i++)
|
|
|
|
children[i]->moveBy(p, propagate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::moveTo( const Point &p, bool propagate /*= true*/ )
|
|
|
|
{
|
|
|
|
moveBy(Point(p.x - pos.x, p.y - pos.y), propagate);
|
|
|
|
}
|
|
|
|
|
2010-05-08 01:10:32 +03:00
|
|
|
void CIntObject::delChild(CIntObject *child)
|
|
|
|
{
|
|
|
|
children -= child;
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
void CIntObject::addChild(CIntObject *child, bool adjustPosition /*= false*/)
|
|
|
|
{
|
|
|
|
assert(!vstd::contains(children, child));
|
|
|
|
assert(child->parent == NULL);
|
|
|
|
children.push_back(child);
|
|
|
|
child->parent = this;
|
|
|
|
if(adjustPosition)
|
|
|
|
child->pos += pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::removeChild(CIntObject *child, bool adjustPosition /*= false*/)
|
|
|
|
{
|
|
|
|
assert(vstd::contains(children, child));
|
|
|
|
assert(child->parent == this);
|
|
|
|
children -= child;
|
|
|
|
child->parent = NULL;
|
|
|
|
if(adjustPosition)
|
|
|
|
child->pos -= pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIntObject::changeUsedEvents(ui16 what, bool enable, bool adjust /*= true*/)
|
|
|
|
{
|
|
|
|
if(enable)
|
|
|
|
{
|
|
|
|
used |= what;
|
|
|
|
if(adjust && active)
|
|
|
|
activate(what);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
used &= ~what;
|
|
|
|
if(adjust && active)
|
|
|
|
deactivate(what);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
CPicture::CPicture( SDL_Surface *BG, int x, int y, bool Free )
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
init();
|
2009-08-17 11:50:31 +03:00
|
|
|
bg = BG;
|
|
|
|
freeSurf = Free;
|
|
|
|
pos.x += x;
|
|
|
|
pos.y += y;
|
|
|
|
pos.w = BG->w;
|
|
|
|
pos.h = BG->h;
|
|
|
|
}
|
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
CPicture::CPicture( const std::string &bmpname, int x, int y )
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
init();
|
2009-08-27 11:04:32 +03:00
|
|
|
bg = BitmapHandler::loadBitmap(bmpname);
|
|
|
|
freeSurf = true;;
|
|
|
|
pos.x += x;
|
|
|
|
pos.y += y;
|
2009-09-20 15:47:40 +03:00
|
|
|
if(bg)
|
|
|
|
{
|
|
|
|
pos.w = bg->w;
|
|
|
|
pos.h = bg->h;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.w = pos.h = 0;
|
|
|
|
}
|
2009-08-27 11:04:32 +03:00
|
|
|
}
|
|
|
|
|
2010-02-15 08:54:57 +02:00
|
|
|
CPicture::CPicture(const Rect &r, const SDL_Color &color, bool screenFormat /*= false*/)
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
init();
|
2010-02-15 08:54:57 +02:00
|
|
|
createSimpleRect(r, screenFormat, SDL_MapRGB(bg->format, color.r, color.g,color.b));
|
|
|
|
}
|
|
|
|
|
|
|
|
CPicture::CPicture(const Rect &r, ui32 color, bool screenFormat /*= false*/)
|
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
init();
|
2010-02-15 08:54:57 +02:00
|
|
|
createSimpleRect(r, screenFormat, color);
|
|
|
|
}
|
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
CPicture::CPicture(SDL_Surface *BG, const Rect &SrcRect, int x /*= 0*/, int y /*= 0*/, bool free /*= false*/)
|
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
needRefresh = false;
|
2010-07-06 05:10:26 +03:00
|
|
|
srcRect = new Rect(SrcRect);
|
|
|
|
pos.x += x;
|
|
|
|
pos.y += y;
|
2011-04-07 20:54:08 +03:00
|
|
|
pos.w = srcRect->w;
|
|
|
|
pos.h = srcRect->h;
|
2010-07-06 05:10:26 +03:00
|
|
|
bg = BG;
|
|
|
|
freeSurf = free;
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
CPicture::~CPicture()
|
|
|
|
{
|
|
|
|
if(freeSurf)
|
|
|
|
SDL_FreeSurface(bg);
|
2010-07-06 05:10:26 +03:00
|
|
|
delete srcRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPicture::init()
|
|
|
|
{
|
2011-02-06 19:26:27 +02:00
|
|
|
needRefresh = false;
|
2010-07-06 05:10:26 +03:00
|
|
|
srcRect = NULL;
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
void CPicture::show( SDL_Surface * to )
|
|
|
|
{
|
|
|
|
if (needRefresh)
|
|
|
|
showAll(to);
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
void CPicture::showAll( SDL_Surface * to )
|
|
|
|
{
|
2009-09-20 15:47:40 +03:00
|
|
|
if(bg)
|
2010-07-06 05:10:26 +03:00
|
|
|
{
|
|
|
|
if(srcRect)
|
|
|
|
{
|
|
|
|
SDL_Rect srcRectCpy = *srcRect;
|
|
|
|
SDL_Rect dstRect = srcRectCpy;
|
|
|
|
dstRect.x = pos.x;
|
|
|
|
dstRect.y = pos.y;
|
|
|
|
|
2010-08-23 18:16:40 +03:00
|
|
|
CSDL_Ext::blitSurface(bg, &srcRectCpy, to, &dstRect);
|
2010-07-06 05:10:26 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
blitAt(bg, pos, to);
|
|
|
|
}
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2010-02-15 08:54:57 +02:00
|
|
|
void CPicture::convertToScreenBPP()
|
|
|
|
{
|
|
|
|
SDL_Surface *hlp = bg;
|
|
|
|
bg = SDL_ConvertSurface(hlp,screen->format,0);
|
|
|
|
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
|
|
|
|
SDL_FreeSurface(hlp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPicture::createSimpleRect(const Rect &r, bool screenFormat, ui32 color)
|
|
|
|
{
|
|
|
|
pos += r;
|
|
|
|
pos.w = r.w;
|
|
|
|
pos.h = r.h;
|
|
|
|
if(screenFormat)
|
|
|
|
bg = CSDL_Ext::newSurface(r.w, r.h);
|
|
|
|
else
|
|
|
|
bg = SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 8, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
SDL_FillRect(bg, NULL, color);
|
2010-07-06 05:10:26 +03:00
|
|
|
freeSurf = true;
|
2010-02-15 08:54:57 +02:00
|
|
|
}
|
|
|
|
|
2010-05-08 01:10:32 +03:00
|
|
|
void CPicture::colorizeAndConvert(int player)
|
2011-03-20 00:27:05 +02:00
|
|
|
{
|
|
|
|
assert(bg);
|
|
|
|
colorize(player);
|
|
|
|
convertToScreenBPP();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPicture::colorize(int player)
|
2010-05-08 01:10:32 +03:00
|
|
|
{
|
|
|
|
assert(bg);
|
|
|
|
assert(bg->format->BitsPerPixel == 8);
|
|
|
|
graphics->blueToPlayersAdv(bg, player);
|
|
|
|
}
|
|
|
|
|
2009-08-17 11:50:31 +03:00
|
|
|
ObjectConstruction::ObjectConstruction( CIntObject *obj )
|
|
|
|
:myObj(obj)
|
|
|
|
{
|
|
|
|
GH.createdObj.push_front(obj);
|
|
|
|
GH.captureChildren = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectConstruction::~ObjectConstruction()
|
|
|
|
{
|
|
|
|
assert(GH.createdObj.size());
|
|
|
|
assert(GH.createdObj.front() == myObj);
|
|
|
|
GH.createdObj.pop_front();
|
|
|
|
GH.captureChildren = GH.createdObj.size();
|
|
|
|
}
|
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
SetCaptureState::SetCaptureState(bool allow, ui8 actions)
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2009-08-27 11:04:32 +03:00
|
|
|
previousCapture = GH.captureChildren;
|
2009-08-17 11:50:31 +03:00
|
|
|
GH.captureChildren = false;
|
2009-08-27 11:04:32 +03:00
|
|
|
prevActions = GH.defActionsDef;
|
|
|
|
GH.defActionsDef = actions;
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
2009-08-27 11:04:32 +03:00
|
|
|
SetCaptureState::~SetCaptureState()
|
2009-08-17 11:50:31 +03:00
|
|
|
{
|
2009-08-27 11:04:32 +03:00
|
|
|
GH.captureChildren = previousCapture;
|
|
|
|
GH.defActionsDef = prevActions;
|
2009-08-17 11:50:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void IShowable::redraw()
|
|
|
|
{
|
|
|
|
showAll(screenBuf);
|
|
|
|
if(screenBuf != screen)
|
|
|
|
showAll(screen);
|
2009-09-07 05:29:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SDLKey arrowToNum( SDLKey key )
|
|
|
|
{
|
|
|
|
switch(key)
|
|
|
|
{
|
|
|
|
case SDLK_DOWN:
|
|
|
|
return SDLK_KP2;
|
|
|
|
case SDLK_UP:
|
|
|
|
return SDLK_KP8;
|
|
|
|
case SDLK_LEFT:
|
|
|
|
return SDLK_KP4;
|
|
|
|
case SDLK_RIGHT:
|
|
|
|
return SDLK_KP6;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
throw std::string("Wrong key!");
|
|
|
|
}
|
|
|
|
|
|
|
|
SDLKey numToDigit( SDLKey key )
|
|
|
|
{
|
2010-07-21 13:09:29 +03:00
|
|
|
if(key >= SDLK_KP0 && key <= SDLK_KP9)
|
|
|
|
return SDLKey(key - SDLK_KP0 + SDLK_0);
|
|
|
|
|
2010-07-22 03:32:45 +03:00
|
|
|
#define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName;
|
2010-07-21 13:09:29 +03:00
|
|
|
switch(key)
|
|
|
|
{
|
|
|
|
REMOVE_KP(PERIOD)
|
|
|
|
REMOVE_KP(MINUS)
|
|
|
|
REMOVE_KP(PLUS)
|
2010-07-29 20:00:34 +03:00
|
|
|
REMOVE_KP(EQUALS)
|
|
|
|
|
|
|
|
case SDLK_KP_MULTIPLY:
|
|
|
|
return SDLK_ASTERISK;
|
|
|
|
case SDLK_KP_DIVIDE:
|
|
|
|
return SDLK_SLASH;
|
|
|
|
case SDLK_KP_ENTER:
|
2010-07-21 13:09:29 +03:00
|
|
|
return SDLK_RETURN;
|
|
|
|
default:
|
|
|
|
tlog3 << "Illegal numkey conversion!" << std::endl;
|
|
|
|
return SDLK_UNKNOWN;
|
|
|
|
}
|
|
|
|
#undef REMOVE_KP
|
2009-09-07 05:29:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isNumKey( SDLKey key, bool number )
|
|
|
|
{
|
|
|
|
if(number)
|
|
|
|
return key >= SDLK_KP0 && key <= SDLK_KP9;
|
2009-09-09 09:04:42 +03:00
|
|
|
else
|
|
|
|
return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS;
|
2009-09-07 05:29:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isArrowKey( SDLKey key )
|
|
|
|
{
|
|
|
|
return key >= SDLK_UP && key <= SDLK_LEFT;
|
2009-11-01 03:15:16 +02:00
|
|
|
}
|
2009-11-29 04:46:30 +02:00
|
|
|
|
2010-07-06 05:10:26 +03:00
|
|
|
CIntObject * moveChild(CIntObject *obj, CIntObject *from, CIntObject *to, bool adjustPos)
|
2010-02-15 08:54:57 +02:00
|
|
|
{
|
2010-07-06 05:10:26 +03:00
|
|
|
from->removeChild(obj, adjustPos);
|
|
|
|
to->addChild(obj, adjustPos);
|
2010-02-15 08:54:57 +02:00
|
|
|
return obj;
|
|
|
|
}
|
2009-11-29 04:46:30 +02:00
|
|
|
Rect Rect::createCentered( int w, int h )
|
|
|
|
{
|
|
|
|
return Rect(screen->w/2 - w/2, screen->h/2 - h/2, w, h);
|
2010-08-12 08:22:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::around(const Rect &r, int width /*= 1*/) /*creates rect around another */
|
|
|
|
{
|
|
|
|
return Rect(r.x - width, r.y - width, r.w + width * 2, r.h + width * 2);
|
2011-01-06 22:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect Rect::centerIn(const Rect &r)
|
|
|
|
{
|
|
|
|
return Rect(r.x + (r.w - w) / 2, r.y + (r.h - h) / 2, w, h);
|
2009-11-29 04:46:30 +02:00
|
|
|
}
|