#include "MiniMapPanel.h" using namespace graphic; // constructor MiniMapPanel::MiniMapPanel(IsoMiniMap * mm, Image * view_rect, SDL_Rect mm_limits) { // store the minimap pointer _mm = mm; // minimap scale _mm_scale = mm->GetScale(); // store the view rect image pointer _view_rect = view_rect; // store minimap limits _mm_limits.x = mm_limits.x; _mm_limits.y = mm_limits.y; _mm_limits.w = mm_limits.w; _mm_limits.h = mm_limits.h; } // blit the panel on a dest surface void MiniMapPanel::Blit(Surface * dest) { _mm->BlitLayer(_mm_limits, dest); blitter->Blit(_view_rect, dest); } // blit the panel on a dest surface in the dest_rect position void MiniMapPanel::Blit(SDL_Rect dest_rect, Surface * dest) { _mm->BlitLayer(_mm_limits, dest_rect, dest); _view_rect->SetPosition(_view_rect->GetX() + dest_rect.x, _view_rect->GetY() + dest_rect.y); blitter->Blit(_view_rect, dest); _view_rect->SetPosition(_view_rect->GetX() - dest_rect.x, _view_rect->GetY() - dest_rect.y); } // mouse has been clicked on the panel at (x,y) point void MiniMapPanel::MouseClicked(Sint16 x, Sint16 y) { Sint16 vx, vy; vx = x - (_view_rect->GetW() / 2) + _mm_limits.x; vy = y - (_view_rect->GetH() / 2) + _mm_limits.y; // update minimap rect limits _mm_limits.x += x - (_mm_limits.w / 2); _mm_limits.y += y - (_mm_limits.h / 2); // check for limits exceeded if(_mm_limits.y < (_u_rlimit / _mm_scale)) _mm_limits.y = (_u_rlimit / _mm_scale); if(_mm_limits.y + (_mm_limits.h / 2) > (_b_rlimit / _mm_scale)) _mm_limits.y = (_b_rlimit / _mm_scale) - (_mm_limits.w / 2); if(_mm_limits.x < (_l_rlimit / _mm_scale)) _mm_limits.x = (_l_rlimit / _mm_scale); if(_mm_limits.x + (_mm_limits.w / 2) > (_r_rlimit / _mm_scale)) _mm_limits.x = (_r_rlimit / _mm_scale) - (_mm_limits.w / 2); _view_rect->SetPosition(vx - _mm_limits.x, vy - _mm_limits.y); } // update the view of the minimap according to scene view position void MiniMapPanel::UpdateView(Sint16 x, Sint16 y) { IntPoint rect_p; // update view rect position rect_p.x = (x / _mm_scale) - _mm_limits.x; rect_p.y = (y / _mm_scale) - _mm_limits.y; // update minimap limits if(rect_p.y < 0 || (rect_p.y + _view_rect->GetH()) > _mm_limits.h) { _mm_limits.y = (y / _mm_scale) - _view_rect->GetY(); rect_p.y = (y / _mm_scale) - _mm_limits.y; } if(rect_p.x < 0 || (rect_p.x + _view_rect->GetW()) > _mm_limits.w) { _mm_limits.x = (x / _mm_scale) - _view_rect->GetX(); rect_p.x = (x / _mm_scale) - _mm_limits.x; } _view_rect->SetPosition(rect_p); }