Thread: [Balder-cvs] balder2d/src/menu samplemapwidget.cpp,1.1,1.2
Status: Beta
Brought to you by:
holomorph
From: Reuben <col...@us...> - 2006-04-07 22:43:59
|
Update of /cvsroot/balder/balder2d/src/menu In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1687/src/menu Modified Files: samplemapwidget.cpp Log Message: 7-Apr-2006 - Reuben got scaling to work for the sample map. Must work on scaling proportions to get them to return the proper value. Index: samplemapwidget.cpp =================================================================== RCS file: /cvsroot/balder/balder2d/src/menu/samplemapwidget.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** samplemapwidget.cpp 6 Apr 2006 17:55:44 -0000 1.1 --- samplemapwidget.cpp 7 Apr 2006 22:43:53 -0000 1.2 *************** *** 19,24 **** ***************************************************************************/ ! #include <guichan/rectangle.hpp> ! #include <guichan/widgets/icon.hpp> #include <guichan/sdl/sdlgraphics.hpp> #include <SDL/SDL.h> --- 19,24 ---- ***************************************************************************/ ! //#include <guichan/rectangle.hpp> ! //#include <guichan/widgets/icon.hpp> #include <guichan/sdl/sdlgraphics.hpp> #include <SDL/SDL.h> *************** *** 26,33 **** #include <SDL/SDL_rotozoom.h> #include "../../include/menu/samplemapwidget.h" using namespace Balder; ! SampleMapWidget::SampleMapWidget(std::string iniMapName, unsigned int X, unsigned int Y, unsigned int W, unsigned int H): sampleMapName(iniMapName) { setX(X); --- 26,34 ---- #include <SDL/SDL_rotozoom.h> #include "../../include/menu/samplemapwidget.h" + #include "../../include/log.h" using namespace Balder; ! SampleMapWidget::SampleMapWidget(std::string iniMapName, unsigned int X, unsigned int Y, unsigned int W, unsigned int H) { setX(X); *************** *** 35,42 **** setWidth(W); setHeight(H); } ! SDL_Surface* SampleMapWidget::LoadSampleMap(std::string name) { std::string mapFileName = "maps/" + name + "/background.png"; SDL_Surface* tempSurf = IMG_Load(mapFileName.c_str()); --- 36,52 ---- setWidth(W); setHeight(H); + setSampleMap(iniMapName); } ! SampleMapWidget::~SampleMapWidget() { + if (map != 0) { + SDL_FreeSurface(map); + } + } + + void SampleMapWidget::setSampleMap(std::string name) + { + // load map background. std::string mapFileName = "maps/" + name + "/background.png"; SDL_Surface* tempSurf = IMG_Load(mapFileName.c_str()); *************** *** 44,63 **** throw "could not load sample background!"; } ! //must figure out why zoom isn't working. ! //return zoomSurface(tempSurf, getWidth(), getHeight(), /* anit-aliasing off=0 on=1 */0); ! return tempSurf; } void SampleMapWidget::draw(gcn::Graphics* graphics) { ! // looks like we still have to draw directly to the screen here... ! // no doubt this will choke if the obect is not an SDLGraphics object SDL_Surface *screen = dynamic_cast<gcn::SDLGraphics*>(graphics)->getTarget(); ! SDL_Surface *map = LoadSampleMap(sampleMapName); int x,y; gcn::Widget::getAbsolutePosition(x,y); ! if (getWidth() > map->w) { ! //must make exception to rectSource size if map background is smaller then widget. ! } SDL_Rect rectSource = {0, 0, getWidth(), getHeight()}; SDL_Rect rectDestination = {x, y, /*width is ignored*/0, /*height is ignored*/0}; --- 54,110 ---- throw "could not load sample background!"; } ! ! // get percentage to scale map size down to based off of widget size. ! double scaledX; ! double scaledY; ! double scaled; ! double src_pix_perc; ! double trg_pix_perc; ! char logtext[255]; ! ! src_pix_perc = tempSurf->w / 100; ! sprintf(logtext, "samplemap - width src_pix_perc = %f", src_pix_perc); ! Log::output(logtext); ! trg_pix_perc = getWidth() / 100; ! sprintf(logtext, "samplemap - width trg_pix_perc = %f", trg_pix_perc); ! Log::output(logtext); ! ! scaledX = trg_pix_perc / src_pix_perc; ! sprintf(logtext, "samplemap - width scaledX = %f", scaledX); ! Log::output(logtext); ! ! src_pix_perc = tempSurf->h / 100; ! sprintf(logtext, "samplemap - height src_pix_perc = %f", src_pix_perc); ! Log::output(logtext); ! trg_pix_perc = /*getHeight()*/80 / 100; ! sprintf(logtext, "samplemap - height trg_pix_perc = %f", trg_pix_perc); ! Log::output(logtext); ! ! scaledY = trg_pix_perc / src_pix_perc; ! sprintf(logtext, "samplemap - width scaledY = %f", scaledY); ! Log::output(logtext); ! ! if (scaledX > scaledY) scaled = scaledY; ! else scaled = scaledX; ! sprintf(logtext, "samplemap - scaled = %f", scaled); ! Log::output(logtext); ! ! // scale down map to widget size. ! //zoom to square. ! //map = zoomSurface(tempSurf, scaled, scaled, /* anti-aliasing SMOOTHING_OFF=0 SMOOTHING_ON=1 */SMOOTHING_OFF); ! //zoom to rect. ! map = zoomSurface(tempSurf, scaledX, scaledY, /* anti-aliasing SMOOTHING_OFF=0 SMOOTHING_ON=1 */SMOOTHING_OFF); } void SampleMapWidget::draw(gcn::Graphics* graphics) { ! // get screen that the menu is drawn on. SDL_Surface *screen = dynamic_cast<gcn::SDLGraphics*>(graphics)->getTarget(); ! ! // get location of the widget on the menu screen. int x,y; gcn::Widget::getAbsolutePosition(x,y); ! ! // draw widget onto menu screen at widget location. SDL_Rect rectSource = {0, 0, getWidth(), getHeight()}; SDL_Rect rectDestination = {x, y, /*width is ignored*/0, /*height is ignored*/0}; |