1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

genWindow can center on the last mouse event instead of the screen. Fixes bug 188.

This commit is contained in:
Frank Zago 2009-10-22 00:25:39 +00:00
parent ad0848f1d2
commit 5a9752fb8c
3 changed files with 16 additions and 5 deletions

View File

@ -1900,7 +1900,7 @@ void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * c
{
if (down)
{
CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID);
CSimpleWindow * temp = CMessage::genWindow(text,LOCPLINT->playerID,true);
CRClickPopupInt *rcpi = new CRClickPopupInt(temp,true);
GH.pushInt(rcpi);
}

View File

@ -311,7 +311,7 @@ std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::st
} //ends for(int i=0; i<brtext->size();i++)
return txtg;
}
CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
CSimpleWindow * CMessage::genWindow(std::string text, int player, bool centerOnMouse, int Lmar, int Rmar, int Tmar, int Bmar)
{
CSimpleWindow * ret = new CSimpleWindow();
int fontHeight;
@ -321,8 +321,19 @@ CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int
ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,player);
ret->pos.h = ret->bitmap->h;
ret->pos.w = ret->bitmap->w;
ret->pos.x = screen->w/2 - (ret->pos.w/2);
ret->pos.y = screen->h/2 - (ret->pos.h/2);
if (centerOnMouse) {
ret->pos.x = GH.current->motion.x - ret->pos.w/2;
ret->pos.y = GH.current->motion.y - ret->pos.h/2;
// Put the window back on screen if necessary
amax(ret->pos.x, 0);
amax(ret->pos.y, 0);
amin(ret->pos.x, conf.cc.resx - ret->pos.w);
amin(ret->pos.y, conf.cc.resy - ret->pos.h);
} else {
// Center on screen
ret->pos.x = screen->w/2 - (ret->pos.w/2);
ret->pos.y = screen->h/2 - (ret->pos.h/2);
}
int curh = ret->bitmap->h/2 - (fontHeight*txtg->size())/2;
blitTextOnSur(txtg,fontHeight,curh,ret->bitmap);
delete brtext;

View File

@ -62,7 +62,7 @@ public:
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext, int &fontHeigh, TTF_Font *font = NULL);
static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int fontHeight, int & curh, SDL_Surface * ret, int xCenterPos=-1); //xPos==-1 works as if ret->w/2
static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
static CSimpleWindow * genWindow(std::string text, int player, bool centerOnMouse=false, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
static SDL_Surface * drawBox1(int w, int h, int playerColor=1);