1 // Copyright (C) 2008, 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 #include <sigc++/functors/mem_fun.h>
22 #include "tile-preview-scene.h"
24 #include "glade-helpers.h"
25 #include "gui/image-helpers.h"
26 #include "ucompose.hpp"
31 TilePreviewScene::TilePreviewScene (Tile *tile,
32 std::vector<PixMask* >
34 guint32 height, guint32 width,
37 std::list<TileStyle::Type> tilescene;
38 for (const char *letter = scene.c_str(); *letter != '\0'; letter++)
39 if (*letter - 'a' >=0 && *letter - 'a' <= TileStyle::OTHER)
40 tilescene.push_back(TileStyle::Type(*letter - 'a'));
42 if (height * width != tilescene.size())
46 d_standard_images = standard_images;
53 Glib::RefPtr<Gdk::Pixbuf> TilePreviewScene::getTileStylePixbuf(int x, int y)
55 return d_view[x * d_width + y];
58 TileStyle* TilePreviewScene::getTileStyle(int x, int y)
60 return d_tilestyles[x * d_width + y];
63 void TilePreviewScene::regenerate()
67 for (std::list<TileStyle::Type>::iterator it = d_model.begin();
68 it != d_model.end(); it++)
70 TileStyle::Type type = *it;
71 TileStyle *tilestyle = NULL;
74 tilestyle = d_tile->getRandomTileStyle(type);
75 d_tilestyles.push_back(tilestyle);
79 d_view.push_back(tilestyle->getImage()->to_pixbuf());
81 d_view.push_back(d_standard_images[type]->to_pixbuf());
85 Glib::RefPtr<Gdk::Pixbuf> TilePreviewScene::renderScene(guint32 tilesize)
87 Glib::RefPtr<Gdk::Pixbuf> dest;
88 dest = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,true, 8, (int)(d_height * tilesize), (int)(d_width * tilesize));
89 for (unsigned int i = 0; i < d_width; i++)
90 for (unsigned int j = 0; j < d_height; j++)
92 getTileStylePixbuf(i,j)->copy_area (0, 0, tilesize, tilesize, dest, j * tilesize, i *tilesize);