From 1f324c3b31d9cf1ae34a8474dd59df88d80368e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Wed, 23 Jan 2008 22:15:33 +0000 Subject: [PATCH] * improved borders * minor changes --- CCastleInterface.cpp | 68 ++++++++++++++++++++++++++++---------------- CCastleInterface.h | 4 ++- SDL_Extensions.cpp | 8 ++++++ SDL_Extensions.h | 2 ++ 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index ba5e7b64b..5a9022f29 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -56,17 +56,17 @@ bool CBuildingRect::operator<(const CBuildingRect & p2) const } void CBuildingRect::hover(bool on) { - if(area) - { - if(CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) == 0) - { - Hoverable::hover(false); - return; - } - } Hoverable::hover(on); - if(border) - blitAt(border,pos.x,pos.y); + if(on) + { + MotionInterested::activate(); + } + else + { + MotionInterested::deactivate(); + if(LOCPLINT->castleInt->hBuild == this) + LOCPLINT->castleInt->hBuild = NULL; + } } void CBuildingRect::clickLeft (tribool down) { @@ -76,6 +76,35 @@ void CBuildingRect::clickRight (tribool down) { //todo - handle } + +void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent) +{ + if(area) + { + if(CSDL_Ext::SDL_GetPixel(area,sEvent.x-pos.x,sEvent.y-pos.y) == 0) //najechany piksel jest poza polem + { + if(LOCPLINT->castleInt->hBuild == this) + LOCPLINT->castleInt->hBuild = NULL; + } + else //w polu + { + if(LOCPLINT->castleInt->hBuild) //jakis budynek jest zaznaczony + { + if((*LOCPLINT->castleInt->hBuild)<(*this)) //ustawiamy sie, jesli jestesmy na wierzchu + { + LOCPLINT->castleInt->hBuild = this; + } + } + else //nie ma budynku, wiec damy nasz + { + LOCPLINT->castleInt->hBuild = this; + } + } + } + //if(border) + // blitAt(border,pos.x,pos.y); +} + std::string getBgName(int type) //TODO - co z tym zrobić? { switch (type) @@ -115,12 +144,7 @@ public: CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) { - int t = 600; - while(t--) - { - CDefHandler* defik = CGI->spriteh->giveDef("ITMTL.DEF"); - delete defik; - } + hBuild = NULL; count=0; town = Town; townInt = CGI->bitmaph->loadBitmap("TOWNSCRN.bmp"); @@ -140,13 +164,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) { if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end()) { - //CDefHandler *b = CGI->spriteh->giveDef(CGI->townh->structures[town->subID][*i]->defName); buildings.push_back(new CBuildingRect(CGI->townh->structures[town->subID][*i])); - //boost::tuples::tuple *t - // = new boost::tuples::tuple - // (*i,b,CGI->townh->structures[town->subID][*i],NULL,NULL); - ////TODO: obwódki i pola - //buildings.push_back(t); } else continue; } @@ -300,8 +318,10 @@ void CCastleInterface::show(SDL_Surface * to) } else blitAt(buildings[i]->def->ourImages[(animval)%(buildings[i]->def->ourImages.size())].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to); - if(buildings[i]->hovered && buildings[i]->border) - blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y); + //if(buildings[i]->hovered && buildings[i]->border) + // blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y); + if(hBuild==buildings[i] && hBuild->border) + blitAt(hBuild->border,hBuild->pos,to); } //for(int i=0;i class AdventureMapButton; -class CBuildingRect : public Hoverable, public ClickableL, public ClickableR//, public TimeInterested +class CBuildingRect : public Hoverable, public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested { public: Structure* str; @@ -22,11 +22,13 @@ public: void hover(bool on); void clickLeft (tribool down); void clickRight (tribool down); + void mouseMoved (SDL_MouseMotionEvent & sEvent); }; class CCastleInterface : public IShowable, public IActivable { public: + CBuildingRect * hBuild; //highlighted building SDL_Surface * townInt; SDL_Surface * cityBg; const CGTownInstance * town; diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index f9c46853a..966895b3c 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -43,6 +43,14 @@ void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst) SDL_Rect pom = genRect(src->h,src->w,x,y); SDL_BlitSurface(src,NULL,dst,&pom); } +void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst) +{ + blitAtWR(src,pos.x,pos.y,dst); +} +void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst) +{ + blitAt(src,pos.x,pos.y,dst); +} SDL_Color genRGB(int r, int g, int b, int a=0) { SDL_Color ret; diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 0217fe06c..babea5735 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -9,6 +9,8 @@ extern SDL_Color tytulowy, tlo, zwykly ; extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran); void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran); +void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=ekran); +void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=ekran); void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran); bool isItIn(const SDL_Rect * rect, int x, int y); SDL_Rect genRect(int hh, int ww, int xx, int yy);