1
/***************************************************************************
2
* Copyright (C) 2006 by Bjorn Hansen *
3
* holomorph@users.sourceforge.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
21
//#include <guichan/rectangle.hpp>
22
//#include <guichan/widgets/icon.hpp>
23
#include <guichan/sdl/sdlgraphics.hpp>
25
#include <SDL/SDL_image.h>
26
#include <SDL/SDL_rotozoom.h>
27
#include "../../include/menu/samplemapwidget.h"
29
using namespace Balder;
31
SampleMapWidget::SampleMapWidget(std::string iniMapName, unsigned int X, unsigned int Y, unsigned int W, unsigned int H)
37
setSampleMap(iniMapName);
40
SampleMapWidget::~SampleMapWidget()
47
void SampleMapWidget::setSampleMap(std::string name)
49
// load map background.
50
std::string mapFileName = "maps/" + name + "/background.png";
51
SDL_Surface* tempSurf = IMG_Load(mapFileName.c_str());
53
throw "could not load sample background!";
56
// get percentage to scale map size down to based off of widget size.
63
src_pix_perc = tempSurf->w; // must convert int to double before preforming division to allow for floating point.
65
trg_pix_perc = getWidth(); // must convert int to double before preforming division to allow for floating point.
68
scaledX = trg_pix_perc / src_pix_perc;
70
src_pix_perc = tempSurf->h; // must convert int to double before preforming division to allow for floating point.
72
trg_pix_perc = getHeight(); // must convert int to double before preforming division to allow for floating point.
75
scaledY = trg_pix_perc / src_pix_perc;
77
if (scaledX < scaledY) scaled = scaledX;
78
else scaled = scaledY;
80
// scale down map to widget size.
82
map = zoomSurface(tempSurf, scaled, scaled, /* anti-aliasing SMOOTHING_OFF=0 SMOOTHING_ON=1 */SMOOTHING_OFF);
85
void SampleMapWidget::draw(gcn::Graphics* graphics)
87
// get screen that the menu is drawn on.
88
SDL_Surface *screen = dynamic_cast<gcn::SDLGraphics*>(graphics)->getTarget();
90
// get location of the widget on the menu screen.
92
gcn::Widget::getAbsolutePosition(x,y);
94
// draw widget onto menu screen at widget location.
95
SDL_Rect rectSource = {0, 0, getWidth(), getHeight()};
96
SDL_Rect rectDestination = {x+((getWidth()-map->w)/2), y+((getHeight()-map->h)/2), /*width is ignored*/0, /*height is ignored*/0};
97
SDL_BlitSurface(map, &rectSource, screen, &rectDestination);