1 // Copyright (C) 2007 Ole Laursen
2 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include "stack-info-tip.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
28 #include "ucompose.hpp"
32 #include "GraphicsCache.h"
33 #include "map-tip-position.h"
34 #include "decorated.h"
36 #include "stacktile.h"
38 StackInfoTip::StackInfoTip(Gtk::Widget *target, MapTipPosition mpos, StackTile *stile)
40 GraphicsCache *gc = GraphicsCache::getInstance();
41 Glib::RefPtr<Gtk::Builder> xml
42 = Gtk::Builder::create_from_file(get_glade_path()
43 + "/stack-info-window.ui");
45 xml->get_widget("window", window);
47 decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
49 xml->get_widget("image_hbox", image_hbox);
51 //fill up the hbox with images of the armies in the stack
53 Player *active = Playerlist::getActiveplayer();
54 std::list<Stack *> stks = stile->getFriendlyStacks(active);
55 for (std::list<Stack *>::iterator i = stks.begin(); i != stks.end(); i++)
56 for (Stack::iterator it = (*i)->begin(); it != (*i)->end(); it++)
58 Gtk::Image *image = new Gtk::Image();
59 image->property_pixbuf() = gc->getArmyPic(*it)->to_pixbuf();
60 image_hbox->add(*manage(image));
63 image_hbox->show_all();
65 // move into correct position
66 window->get_child()->show();
68 target->get_window()->get_origin(p.x, p.y);
69 if (target->has_no_window())
71 Gtk::Allocation a = target->get_allocation();
75 Vector<int> size(0, 0);
76 window->get_size(size.x, size.y);
77 switch (mpos.justification)
79 case MapTipPosition::LEFT:
80 window->set_gravity(Gdk::GRAVITY_NORTH_WEST);
82 case MapTipPosition::RIGHT:
83 window->set_gravity(Gdk::GRAVITY_NORTH_EAST);
86 case MapTipPosition::TOP:
87 window->set_gravity(Gdk::GRAVITY_NORTH_WEST);
89 case MapTipPosition::BOTTOM:
90 window->set_gravity(Gdk::GRAVITY_SOUTH_WEST);
97 window->move(p.x, p.y);
100 StackInfoTip::~StackInfoTip()