From 7cad2364febfb9fda7f5509d56c8c28ed1dce71f Mon Sep 17 00:00:00 2001 From: mateuszb Date: Mon, 23 Aug 2010 16:13:30 +0000 Subject: [PATCH] * minor fixes for screen scrolling --- client/AdventureMapButton.cpp | 2 +- client/CMT.cpp | 2 ++ client/CMessage.cpp | 2 +- client/CPlayerInterface.cpp | 3 +++ client/GUIBase.cpp | 26 ++++++++++++++------------ client/SDL_Extensions.cpp | 19 +++++++++++++++++++ client/SDL_Extensions.h | 1 + 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/client/AdventureMapButton.cpp b/client/AdventureMapButton.cpp index 6db365cc3..2e5977af7 100644 --- a/client/AdventureMapButton.cpp +++ b/client/AdventureMapButton.cpp @@ -647,7 +647,7 @@ void CSlider::setAmount( int to ) void CSlider::showAll(SDL_Surface * to) { - SDL_FillRect(to, &pos, 0); + CSDL_Ext::fillRect(to, &pos, 0); CIntObject::showAll(to); } diff --git a/client/CMT.cpp b/client/CMT.cpp index bffa8bbc6..e58864c67 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -528,6 +528,8 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen) SDL_ShowCursor(SDL_DISABLE); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + screenLT = Point(0, 0); + #ifdef _WIN32 SDL_SysWMinfo wm; SDL_VERSION(&wm.version); diff --git a/client/CMessage.cpp b/client/CMessage.cpp index da36b7237..e6404388d 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -279,7 +279,7 @@ SDL_Surface * FNT_RenderText (EFonts font, std::string text, SDL_Color kolor= zw int w = f->getWidth(text.c_str()), h = f->height; SDL_Surface * ret = CSDL_Ext::newSurface(w, h, screen); - SDL_FillRect (ret, NULL, SDL_MapRGB(ret->format,128,128,128));//if use default black - no shadowing + CSDL_Ext::fillRect (ret, NULL, SDL_MapRGB(ret->format,128,128,128));//if use default black - no shadowing SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,128,128,128)); CSDL_Ext::printAt(text.c_str(), 0, 0, font, kolor, ret); return ret; diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 439b8fe34..85fe08ef4 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -66,6 +66,7 @@ using namespace boost::assign; using namespace CSDL_Ext; void processCommand(const std::string &message, CClient *&client); +void updateScreenLT(int maxW, int maxH); extern std::queue events; extern boost::mutex eventsM; @@ -1331,6 +1332,8 @@ void CPlayerInterface::update() CSDL_Ext::update(screen); CGI->curh->draw2(); + updateScreenLT(conf.cc.resx, conf.cc.resy); + pim->unlock(); SDL_framerateDelay(mainFPSmng); diff --git a/client/GUIBase.cpp b/client/GUIBase.cpp index 6ce7acc60..5291140b3 100644 --- a/client/GUIBase.cpp +++ b/client/GUIBase.cpp @@ -150,6 +150,16 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) current = sEvent; bool prev; + struct HLP + { + static void adjustMousePos(SDL_Event * ev) + { + //adjust mouse position according to screenLT + ev->motion.x -= screenLT.x; + ev->motion.y -= screenLT.y; + } + }; + if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP) { SDL_KeyboardEvent key = sEvent->key; @@ -178,16 +188,12 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) else if(sEvent->type==SDL_MOUSEMOTION) { CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y); - //adjust mouse position according to screenLT - sEvent->motion.x -= screenLT.x; - sEvent->motion.y -= screenLT.y; + HLP::adjustMousePos(sEvent); handleMouseMotion(sEvent); } else if (sEvent->type==SDL_MOUSEBUTTONDOWN) { - //adjust mouse position according to screenLT - sEvent->motion.x -= screenLT.x; - sEvent->motion.y -= screenLT.y; + HLP::adjustMousePos(sEvent); if(sEvent->button.button == SDL_BUTTON_LEFT) { @@ -247,9 +253,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) { - //adjust mouse position according to screenLT - sEvent->motion.x -= screenLT.x; - sEvent->motion.y -= screenLT.y; + HLP::adjustMousePos(sEvent); std::list hlp = lclickable; for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) @@ -267,9 +271,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent) } else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_RIGHT)) { - //adjust mouse position according to screenLT - sEvent->motion.x -= screenLT.x; - sEvent->motion.y -= screenLT.y; + HLP::adjustMousePos(sEvent); std::list hlp = rclickable; for(std::list::iterator i=hlp.begin(); i != hlp.end() && current; i++) diff --git a/client/SDL_Extensions.cpp b/client/SDL_Extensions.cpp index a9a9b7f7c..b2dd5920d 100644 --- a/client/SDL_Extensions.cpp +++ b/client/SDL_Extensions.cpp @@ -1277,4 +1277,23 @@ void CSDL_Ext::blitSurface( SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * } } +void CSDL_Ext::fillRect( SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color ) +{ + SDL_Rect newRect; + if (dstrect) + { + newRect = *dstrect; + } + else + { + newRect = Rect(0, 0, dst->w, dst->h); + } + if (dst == screen) + { + newRect.x += screenLT.x; + newRect.y += screenLT.y; + } + SDL_FillRect(dst, &newRect, color); +} + SDL_Surface * CSDL_Ext::std32bppSurface = NULL; diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index 01fb63d67..4726eb545 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -114,6 +114,7 @@ typedef void (*BlitterWithRotationVal)(SDL_Surface *src,SDL_Rect srcRect, SDL_Su namespace CSDL_Ext { void blitSurface(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); + void fillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color); extern SDL_Surface * std32bppSurface; void SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255);