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
22 #include "city-info-tip.h"
24 #include "glade-helpers.h"
25 #include "image-helpers.h"
27 #include "ucompose.hpp"
30 #include "GraphicsCache.h"
31 #include "playerlist.h"
33 #include "decorated.h"
37 CityInfoTip::CityInfoTip(Gtk::Widget *target, MapTipPosition mpos, const City *city)
39 GraphicsCache *gc = GraphicsCache::getInstance();
40 Glib::RefPtr<Gtk::Builder> xml
41 = Gtk::Builder::create_from_file(get_glade_path()
42 + "/city-info-window.ui");
44 xml->get_widget("window", window);
46 decorator.decorate(window,File::getMiscFile("various/background.png"), 200);
48 Gtk::Image *left_shield_image;
49 xml->get_widget("left_shield_image", left_shield_image);
50 Gtk::Image *right_shield_image;
51 xml->get_widget("right_shield_image", right_shield_image);
52 Gtk::Image *income_image;
53 xml->get_widget("income_image", income_image);
54 Gtk::Image *defense_image;
55 xml->get_widget("defense_image", defense_image);
56 Gtk::Label *name_label;
57 xml->get_widget("name_label", name_label);
58 Gtk::Label *income_label;
59 xml->get_widget("income_label", income_label);
60 Gtk::Label *defense_label;
61 xml->get_widget("defense_label", defense_label);
62 Gtk::Label *capital_label;
63 xml->get_widget("capital_label", capital_label);
64 Gtk::Image *capital_image;
65 xml->get_widget("capital_image", capital_image);
66 Gtk::Label *razed_label;
67 xml->get_widget("razed_label", razed_label);
69 if (city->isBurnt() == true)
70 razed_label->set_markup("<b>" + std::string(_("Razed!")) + "</b>");
72 name_label->set_markup("<b>" + city->getName() + "</b>");
73 left_shield_image->property_pixbuf() =
74 gc->getShieldPic(1, city->getOwner())->to_pixbuf();
75 right_shield_image->property_pixbuf() =
76 gc->getShieldPic(1, city->getOwner())->to_pixbuf();
77 income_image->property_file() =
78 File::getMiscFile("various/smallincome.png");
79 defense_image->property_file() =
80 File::getMiscFile("various/smalldefense.png");
81 income_label->set_markup(String::ucompose("<b>%1</b>",
83 defense_label->set_markup(String::ucompose("<b>%1</b>",
84 city->getDefenseLevel()));
86 if (city->isCapital())
88 Glib::ustring s = _("Capital of\n");
89 s += city->getCapitalOwner()->getName();
90 capital_label->set_text (s);
91 capital_image->property_pixbuf() =
92 gc->getShieldPic(1, city->getCapitalOwner())->to_pixbuf();
96 Glib::RefPtr<Gdk::Pixbuf> empty_pic
97 = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, 1, 1);
98 empty_pic->fill(0x00000000);
99 capital_image->property_pixbuf() = empty_pic;
102 // move into correct position
103 window->get_child()->show();
105 target->get_window()->get_origin(p.x, p.y);
106 if (target->has_no_window())
108 Gtk::Allocation a = target->get_allocation();
112 Vector<int> size(0, 0);
113 window->get_size(size.x, size.y);
114 switch (mpos.justification)
116 case MapTipPosition::LEFT:
117 window->set_gravity(Gdk::GRAVITY_NORTH_WEST);
119 case MapTipPosition::RIGHT:
120 window->set_gravity(Gdk::GRAVITY_NORTH_EAST);
123 case MapTipPosition::TOP:
124 window->set_gravity(Gdk::GRAVITY_NORTH_WEST);
126 case MapTipPosition::BOTTOM:
127 window->set_gravity(Gdk::GRAVITY_SOUTH_WEST);
134 window->move(p.x, p.y);
138 CityInfoTip::~CityInfoTip()