diff --git a/client/CAdvmapInterface.cpp b/client/CAdvmapInterface.cpp index 4a7b1b60a..0f0f3f927 100644 --- a/client/CAdvmapInterface.cpp +++ b/client/CAdvmapInterface.cpp @@ -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); } diff --git a/client/CMessage.cpp b/client/CMessage.cpp index cc1b56c0a..10f948a47 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -311,7 +311,7 @@ std::vector > * CMessage::drawText(std::vectorsize();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; diff --git a/client/CMessage.h b/client/CMessage.h index 9a743beb4..168790984 100644 --- a/client/CMessage.h +++ b/client/CMessage.h @@ -62,7 +62,7 @@ public: static std::vector > * drawText(std::vector * brtext, int &fontHeigh, TTF_Font *font = NULL); static SDL_Surface * blitTextOnSur(std::vector > * 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 *addPics=NULL, void * cb=NULL); static SDL_Surface * drawBox1(int w, int h, int playerColor=1);