1 // Copyright (C) 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
21 #include <sigc++/functors/mem_fun.h>
24 #include "image-editor-dialog.h"
26 #include "glade-helpers.h"
27 #include "gui/image-helpers.h"
28 #include "ucompose.hpp"
31 #include "shieldsetlist.h"
32 #include "GraphicsCache.h"
35 ImageEditorDialog::ImageEditorDialog(std::string filename, int frames)
38 Glib::RefPtr<Gtk::Builder> xml
39 = Gtk::Builder::create_from_file(get_glade_path()
40 + "/image-editor-dialog.ui");
42 xml->get_widget("dialog", dialog);
44 xml->get_widget("filechooserbutton", filechooserbutton);
45 xml->get_widget("image", image);
47 target_filename = filename;
49 filechooserbutton->signal_selection_changed().connect
50 (sigc::mem_fun(*this, &ImageEditorDialog::on_image_chosen));
54 ImageEditorDialog::~ImageEditorDialog()
58 void ImageEditorDialog::set_parent_window(Gtk::Window &parent)
60 dialog->set_transient_for(parent);
61 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
64 int ImageEditorDialog::run()
67 int response = dialog->run();
68 if (response == Gtk::RESPONSE_ACCEPT)
74 void ImageEditorDialog::on_image_chosen()
76 std::string selected_filename = filechooserbutton->get_filename();
77 if (selected_filename.empty())
80 target_filename = selected_filename;
81 show_image(selected_filename);
85 void ImageEditorDialog::update_panel()
87 if (target_filename != "")
88 filechooserbutton->set_filename (target_filename);
91 void ImageEditorDialog::show_image(std::string filename)
96 if (heartbeat.connected())
97 heartbeat.disconnect();
99 frames = disassemble_row(filename, num_frames);
103 heartbeat = Glib::signal_timeout().connect
105 (sigc::mem_fun (*this, &ImageEditorDialog::on_heartbeat),
111 void ImageEditorDialog::on_heartbeat()
113 image->property_pixbuf() = frames[active_frame]->to_pixbuf();
115 if (active_frame >= num_frames)