1 /********************************************************************** 2 * 3 * FreeDoko a Doppelkopf-Game 4 * 5 * Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * You can find this license in the file 'gpl.txt'. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 * MA 02111-1307 USA 22 * 23 * Contact: 24 * Diether Knof dknof@posteo.de 25 * 26 **********************************************************************/ 27 28 #ifdef USE_UI_GTKMM 29 30 #pragma once 31 32 #include "base.h" 33 34 #include "widgets/scaled_pixbuf_rotations.h" 35 36 #include "../../basetypes.h" 37 #include "../../card/card.h" 38 39 class Player; 40 41 #include <glibmm/refptr.h> 42 namespace Gtk { 43 class Image; 44 }; // namespace Gtk 45 46 namespace UI_GTKMM_NS { 47 48 /** 49 ** the icons 50 **/ 51 class Icons : public Base, public sigc::trackable { 52 friend class Icongroup; 53 public: 54 enum class Type { 55 none = 0, 56 re, 57 contra, 58 thrown_nines, 59 thrown_kings, 60 thrown_nines_and_kings, 61 thrown_richness, 62 redistribute, 63 fox_highest_trump, 64 marriage, 65 marriage_solo, 66 marriage_foreign, 67 marriage_trump, 68 marriage_color, 69 marriage_club, 70 marriage_spade, 71 marriage_heart, 72 marriage_partner, 73 genscher, 74 poverty, 75 poverty_trumps_0, 76 poverty_trumps_1, 77 poverty_trumps_2, 78 poverty_trumps_3, 79 poverty_partner, 80 swines_club, 81 swines_spade, 82 swines_heart, 83 swines_diamond, 84 swines = swines_diamond, 85 hyperswines_club, 86 hyperswines_spade, 87 hyperswines_heart, 88 hyperswines_diamond, 89 hyperswines = hyperswines_diamond, 90 hyperswines_king_club, 91 hyperswines_king_spade, 92 hyperswines_king_heart, 93 hyperswines_king_diamond, 94 swines_hyperswines_club, 95 swines_hyperswines_spade, 96 swines_hyperswines_heart, 97 swines_hyperswines_diamond, 98 swines_hyperswines = swines_hyperswines_diamond, 99 swines_hyperswines_king_club, 100 swines_hyperswines_king_spade, 101 swines_hyperswines_king_heart, 102 swines_hyperswines_king_diamond, 103 dullen, 104 doppelkopf, 105 solo_club, 106 solo_spade, 107 solo_heart, 108 solo_diamond, 109 solo_jack, 110 solo_queen, 111 solo_king, 112 solo_queen_jack, 113 solo_king_jack, 114 solo_king_queen, 115 solo_koehler, 116 solo_meatless, 117 no_120_reply, 118 no_90_reply, 119 no_60_reply, 120 no_30_reply, 121 no_0_reply, 122 no_120, 123 no_90, 124 no_60, 125 no_30, 126 no_0, 127 last = no_0 128 }; // enum Type 129 static size_t const number_of_types; // number of icons 130 131 static Type type(GameType gametype); 132 static Type type(MarriageSelector marriage_selector); 133 static Type type(Team team); 134 static Type type(Announcement announcement); 135 static Type type_swines(Card::Color color); 136 Type type_hyperswines(Card::Color color); 137 Type type_swines_hyperswines(Card::Color color); 138 139 public: 140 explicit Icons(Base* base); 141 ~Icons() override; 142 143 double scaling() const; 144 void update_scaling(); 145 146 int max_width(Rotation rotation = Rotation::up) const; 147 int max_height(Rotation rotation = Rotation::up) const; 148 int max_width(vector<Glib::RefPtr<Gdk::Pixbuf>> const& icons, 149 Rotation rotation = Rotation::up) const; 150 int max_height(vector<Glib::RefPtr<Gdk::Pixbuf>> const& icons, 151 Rotation rotation = Rotation::up) const; 152 153 // the specific icon 154 Glib::RefPtr<Gdk::Pixbuf> const& 155 icon(Type type, Rotation rotation = Rotation::up) ; 156 157 // the specific gametype icon 158 Glib::RefPtr<Gdk::Pixbuf> const& 159 icon(GameType gametype, Rotation rotation = Rotation::up) 160 { return this->icon(this->type(gametype), rotation); } 161 // the specific marriage selector icon 162 Glib::RefPtr<Gdk::Pixbuf> const& 163 icon(MarriageSelector marriage_selector, Rotation rotation = Rotation::up) 164 { return this->icon(this->type(marriage_selector), rotation); } 165 // the specific team icon 166 Glib::RefPtr<Gdk::Pixbuf> const& 167 icon(Team team, Rotation rotation = Rotation::up) 168 { return this->icon(this->type(team), rotation); } 169 // the specific announcement icon 170 Glib::RefPtr<Gdk::Pixbuf> const& 171 icon(Announcement announcement, Rotation rotation = Rotation::up) 172 { return this->icon(this->type(announcement), rotation); } 173 // the specific swines icon 174 Glib::RefPtr<Gdk::Pixbuf> const& 175 swines(Card::Color color, Rotation rotation = Rotation::up) 176 { return this->icon(this->type_swines(color), rotation); } 177 // the specific hyperswines icon 178 Glib::RefPtr<Gdk::Pixbuf> const& 179 hyperswines(Card::Color color, Rotation rotation = Rotation::up) 180 { return this->icon(this->type_hyperswines(color), rotation); } 181 // the specific swines-hyperswines icon 182 Glib::RefPtr<Gdk::Pixbuf> const& 183 swines_hyperswines(Card::Color color, Rotation rotation = Rotation::up) 184 { return this->icon(this->type_swines_hyperswines(color), rotation); } 185 186 187 // managed images 188 Gtk::Image* new_managed_image(Type type = Type::none, double scaling = 1); 189 190 void change_managed(Gtk::Image* image, Type type); change_managed(Gtk::Image * image,GameType gametype)191 void change_managed(Gtk::Image* image, 192 GameType gametype) 193 { this->change_managed(image, this->type(gametype)); return ; } change_managed(Gtk::Image * image,MarriageSelector marriage_selector)194 void change_managed(Gtk::Image* image, 195 MarriageSelector marriage_selector) 196 { this->change_managed(image, this->type(marriage_selector)); return ; } change_managed(Gtk::Image * image,Team team)197 void change_managed(Gtk::Image* image, 198 Team team) 199 { this->change_managed(image, this->type(team)); return ; } change_managed(Gtk::Image * image,Announcement announcement)200 void change_managed(Gtk::Image* image, 201 Announcement announcement) 202 { this->change_managed(image, this->type(announcement)); return ; } change_managed_swines(Gtk::Image * image,Card::Color color)203 void change_managed_swines(Gtk::Image* image, 204 Card::Color color) 205 { this->change_managed(image, this->type_swines(color)); return ; } change_managed_hyperswines(Gtk::Image * image,Card::Color color)206 void change_managed_hyperswines(Gtk::Image* image, 207 Card::Color color) 208 { this->change_managed(image, this->type_hyperswines(color)); return ; } 209 void change_scaling(Gtk::Image* image, double scaling); 210 211 void remove_managed(Gtk::Image const* image); 212 213 void update_managed(); 214 215 // update the maximal width and height 216 void update_max_values(); 217 218 void load(); 219 220 Gdk::ScaledPixbufRotations load(Type type); 221 private: 222 Gdk::ScaledPixbufRotations load_from_file(string const& name_a, 223 string const& name_b = ""); 224 Gdk::ScaledPixbufRotations load_from_file_or_construct(string const& file, 225 vector<Card> const& cards); 226 Gdk::ScaledPixbufRotations load_from_file_or_construct(string const& name_a, 227 string const& name_b, 228 vector<Card> const& cards); 229 Gdk::ScaledPixbufRotations construct(vector<Card> const& cards); 230 231 private: 232 // the icons 233 vector<Gdk::ScaledPixbufRotations> icon_; 234 // maximal width of the icons 235 int max_width_; 236 // maximal height of the icons 237 int max_height_; 238 239 #ifdef OUTDATED 240 // a reference to a drawable 241 Glib::RefPtr<Gdk::Drawable> drawable_ref; 242 #endif 243 244 // the managed images 245 vector<Gtk::Image*> managed_image_; 246 247 private: // unused 248 Icons() = delete; 249 Icons(Icons const&) = delete; 250 Icons& operator=(Icons const&) = delete; 251 }; // class Icons : public Base 252 253 bool operator!(Icons::Type type); 254 255 } // namespace UI_GTKMM_NS 256 257 #endif // #ifdef USE_UI_GTKMM 258