1
// Copyright (C) 2008 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 2 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 <libglademm/xml.h>
21
#include <sigc++/functors/mem_fun.h>
23
#include "tile-preview-dialog.h"
25
#include "glade-helpers.h"
26
#include "../gui/image-helpers.h"
27
#include "../ucompose.hpp"
32
TilePreviewDialog::TilePreviewDialog(Tile *tile, Uint32 tileSize)
34
Glib::RefPtr<Gnome::Glade::Xml> xml
35
= Gnome::Glade::Xml::create(get_glade_path()
36
+ "/tile-preview-dialog.glade");
39
xml->get_widget("dialog", d);
42
xml->get_widget("next_button", next_button);
43
next_button->signal_clicked().connect
44
(sigc::mem_fun(this, &TilePreviewDialog::on_next_clicked));
45
xml->get_widget("previous_button", previous_button);
46
previous_button->signal_clicked().connect
47
(sigc::mem_fun(this, &TilePreviewDialog::on_previous_clicked));
48
xml->get_widget("refresh_button", refresh_button);
49
refresh_button->signal_clicked().connect
50
(sigc::mem_fun(this, &TilePreviewDialog::on_refresh_clicked));
51
xml->get_widget("scene_box", scene_box);
53
std::vector<Glib::RefPtr<Gdk::Pixbuf> > base_tilestyles;
55
disassemble_row(File::getMiscFile("various/editor/tilestyles.png"), 17);
57
d_tileSize = tileSize;
58
std::vector<Glib::RefPtr<Gdk::Pixbuf> >::iterator it;
59
for (it = base_tilestyles.begin(); it != base_tilestyles.end(); it++)
60
tilestyle_images.push_back((*it)->scale_simple((int)d_tileSize,
62
Gdk::INTERP_BILINEAR));
69
switch (tile->getType())
78
s = new TilePreviewScene(tile, tilestyle_images, 5, 5, scene);
86
s = new TilePreviewScene(tile, tilestyle_images, 3, 3,scene);
94
s = new TilePreviewScene(tile, tilestyle_images, 5, 5,scene);
102
s = new TilePreviewScene(tile, tilestyle_images, 5, 4,scene);
110
s = new TilePreviewScene(tile, tilestyle_images, 3, 3,scene);
118
s = new TilePreviewScene(tile, tilestyle_images, 3, 3,scene);
126
s = new TilePreviewScene(tile, tilestyle_images, 3, 3,scene);
135
s = new TilePreviewScene(tile, tilestyle_images, 5, 5,scene);
141
current_scene = scenes.begin();
143
update_scene(*current_scene);
148
void TilePreviewDialog::set_parent_window(Gtk::Window &parent)
150
dialog->set_transient_for(parent);
151
//dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
154
void TilePreviewDialog::run()
163
void TilePreviewDialog::on_next_clicked()
165
if (scenes.end() != current_scene)
168
TilePreviewScene *scene = *current_scene;
177
void TilePreviewDialog::on_previous_clicked()
179
if (scenes.begin() != current_scene)
182
TilePreviewScene *scene = *current_scene;
191
void TilePreviewDialog::on_refresh_clicked()
193
TilePreviewScene *scene = *current_scene;
201
void TilePreviewDialog::update_scene(TilePreviewScene *scene)
207
scene_table = new Gtk::Table(scene->getHeight(), scene->getWidth());
208
scene_box->add(*manage(scene_table));
209
for (int i = 0; i < scene->getHeight(); i++)
211
for (int j = 0; j < scene->getWidth(); j++)
213
Glib::RefPtr<Gdk::Pixbuf> pixbuf = scene->getTileStylePixbuf(i, j);
214
Gtk::Image *image = new Gtk::Image(pixbuf);
215
TileStyle *style = scene->getTileStyle(i, j);
219
snprintf (buf, sizeof (buf), "0x%02x", style->getId());
220
image->set_tooltip_text(buf);
222
scene_table->attach(*image, j, j + 1, i, i + 1,
223
Gtk::SHRINK, Gtk::SHRINK);
227
scene_table->show_all();
230
void TilePreviewDialog::update_buttons()
232
std::list<TilePreviewScene*>::iterator it = current_scene;
233
next_button->set_sensitive(++it != scenes.end());
234
previous_button->set_sensitive(current_scene != scenes.begin());