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 "masked-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 MaskedImageEditorDialog::MaskedImageEditorDialog(std::string filename)
37 Glib::RefPtr<Gtk::Builder> xml
38 = Gtk::Builder::create_from_file(get_glade_path()
39 + "/masked-image-editor-dialog.ui");
41 xml->get_widget("dialog", dialog);
43 xml->get_widget("filechooserbutton", filechooserbutton);
44 xml->get_widget("image_white", image_white);
45 xml->get_widget("image_green", image_green);
46 xml->get_widget("image_yellow", image_yellow);
47 xml->get_widget("image_light_blue", image_light_blue);
48 xml->get_widget("image_red", image_red);
49 xml->get_widget("image_dark_blue", image_dark_blue);
50 xml->get_widget("image_orange", image_orange);
51 xml->get_widget("image_black", image_black);
52 xml->get_widget("image_neutral", image_neutral);
54 target_filename = filename;
56 filechooserbutton->signal_selection_changed().connect
57 (sigc::mem_fun(*this, &MaskedImageEditorDialog::on_image_chosen));
61 MaskedImageEditorDialog::~MaskedImageEditorDialog()
65 void MaskedImageEditorDialog::set_parent_window(Gtk::Window &parent)
67 dialog->set_transient_for(parent);
68 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
71 int MaskedImageEditorDialog::run()
74 int response = dialog->run();
75 if (response == Gtk::RESPONSE_ACCEPT)
81 void MaskedImageEditorDialog::on_image_chosen()
83 std::string selected_filename = filechooserbutton->get_filename();
84 if (selected_filename.empty())
87 target_filename = selected_filename;
88 show_image(selected_filename);
92 void MaskedImageEditorDialog::update_panel()
94 if (target_filename != "")
95 filechooserbutton->set_filename (target_filename);
98 void MaskedImageEditorDialog::show_image(std::string filename)
102 std::vector<PixMask*> half = disassemble_row(filename, 2);
103 for (unsigned int i = Shield::WHITE; i <= Shield::NEUTRAL; i++)
105 Gtk::Image *image = NULL;
108 case Shield::WHITE: image = image_white; break;
109 case Shield::GREEN: image = image_green; break;
110 case Shield::YELLOW: image = image_yellow; break;
111 case Shield::LIGHT_BLUE: image = image_light_blue; break;
112 case Shield::RED: image = image_red; break;
113 case Shield::DARK_BLUE: image = image_dark_blue; break;
114 case Shield::ORANGE: image = image_orange; break;
115 case Shield::BLACK: image = image_black; break;
116 case Shield::NEUTRAL: image = image_neutral; break;
120 Gdk::Color colour = Shieldsetlist::getInstance()->getColor(1, i);
121 PixMask *army_image = GraphicsCache::applyMask(half[0], half[1],
123 image->property_pixbuf() = army_image->to_pixbuf();