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 #include "constants.h" 29 30 #ifdef USE_UI_GTKMM 31 32 #include "table.h" 33 #include "cards_distribution.h" 34 #include "poverty.h" 35 #include "trick.h" 36 #include "hand.h" 37 #include "trickpile.h" 38 #include "icongroup.h" 39 #include "name.h" 40 41 #include "ui.h" 42 #include "cards.h" 43 44 #include "../../player/player.h" 45 #include "../../player/human/human.h" 46 #include "../../party/party.h" 47 #include "../../game/game.h" 48 #include "../../misc/preferences.h" 49 50 #include <gtkmm/drawingarea.h> 51 52 namespace UI_GTKMM_NS { 53 54 /** @return the party points 55 **/ 56 PartyPoints& party_points()57 Table::party_points() 58 { 59 return *this->party_points_; 60 } 61 62 /** @return the cards distribution 63 **/ 64 CardsDistribution& cards_distribution()65 Table::cards_distribution() 66 { 67 return *this->cards_distribution_; 68 } 69 70 /** @return the poverty 71 **/ 72 Poverty& poverty()73 Table::poverty() 74 { 75 return *this->poverty_; 76 } 77 78 /** @return the trick 79 **/ 80 Trick& trick()81 Table::trick() 82 { 83 return *this->trick_; 84 } 85 86 /** -> result 87 ** 88 ** @param player the player 89 ** 90 ** @return the hand object of 'player' 91 **/ 92 Hand& hand(Player const & player)93 Table::hand(Player const& player) 94 { 95 return this->hand(this->position(player)); 96 } 97 98 /** -> result 99 ** 100 ** @param player the player 101 ** 102 ** @return the hand object of 'player' 103 **/ 104 Hand const& hand(Player const & player) const105 Table::hand(Player const& player) const 106 { 107 return this->hand(this->position(player)); 108 } 109 110 /** -> result 111 ** 112 ** @param position the position 113 ** 114 ** @return the hand object at 'position' 115 **/ 116 Hand& hand(Position const position)117 Table::hand(Position const position) 118 { 119 //return *this->hand_[position]; // see corresponding const-function 120 return *this->hand_.find(position)->second; 121 } 122 123 /** -> result 124 ** 125 ** @param position the position 126 ** 127 ** @return the hand object at 'position' 128 **/ 129 Hand const& hand(Position const position) const130 Table::hand(Position const position) const 131 { 132 //return *this->hand_[position]; // needs write access 133 return *this->hand_.find(position)->second; 134 } 135 136 /** -> result 137 ** 138 ** @param player the player 139 ** 140 ** @return the trickpile object of 'player' 141 **/ 142 TrickPile& trickpile(Player const & player)143 Table::trickpile(Player const& player) 144 { 145 return this->trickpile(this->position(player)); 146 } 147 148 /** -> result 149 ** 150 ** @param player the player 151 ** 152 ** @return the trickpile object of 'player' 153 **/ 154 TrickPile const& trickpile(Player const & player) const155 Table::trickpile(Player const& player) const 156 { 157 return this->trickpile(this->position(player)); 158 } 159 160 /** -> result 161 ** 162 ** @param position the position 163 ** 164 ** @return the trickpile object at 'position' 165 **/ 166 TrickPile& trickpile(Position const position)167 Table::trickpile(Position const position) 168 { 169 //return *this->trickpile_[position]; // see corresponding const-function 170 return *this->trickpile_.find(position)->second; 171 } 172 173 /** -> result 174 ** 175 ** @param position the position 176 ** 177 ** @return the trickpile object at 'position' 178 **/ 179 TrickPile const& trickpile(Position const position) const180 Table::trickpile(Position const position) const 181 { 182 //return *this->trickpile_[position]; // needs write access 183 return *this->trickpile_.find(position)->second; 184 } 185 186 /** -> result 187 ** 188 ** @param player the player 189 ** 190 ** @return the icongroup object of 'player' 191 **/ 192 Icongroup& icongroup(Player const & player)193 Table::icongroup(Player const& player) 194 { 195 return this->icongroup(this->position(player)); 196 } 197 198 /** -> result 199 ** 200 ** @param player the player 201 ** 202 ** @return the icongroup object of 'player' 203 **/ 204 Icongroup const& icongroup(Player const & player) const205 Table::icongroup(Player const& player) const 206 { 207 return this->icongroup(this->position(player)); 208 } 209 210 /** -> result 211 ** 212 ** @param position the position 213 ** 214 ** @return the icongroup object at 'position' 215 **/ 216 Icongroup& icongroup(Position const position)217 Table::icongroup(Position const position) 218 { 219 //return *this->icongroup_[position]; // see corresponding const-function 220 return *this->icongroup_.find(position)->second; 221 } 222 223 /** -> result 224 ** 225 ** @param position the position 226 ** 227 ** @return the icongroup object at 'position' 228 **/ 229 Icongroup const& icongroup(Position const position) const230 Table::icongroup(Position const position) const 231 { 232 //return *this->icongroup_[position]; // needs write access 233 return *this->icongroup_.find(position)->second; 234 } 235 236 /** -> result 237 ** 238 ** @param player the player 239 ** 240 ** @return the name object of 'player' 241 **/ 242 Name& name(Player const & player)243 Table::name(Player const& player) 244 { 245 return this->name(this->position(player)); 246 } 247 248 /** -> result 249 ** 250 ** @param player the player 251 ** 252 ** @return the name object of 'player' 253 **/ 254 Name const& name(Player const & player) const255 Table::name(Player const& player) const 256 { 257 return this->name(this->position(player)); 258 } 259 260 /** -> result 261 ** 262 ** @param position the position 263 ** 264 ** @return the name object at 'position' 265 **/ 266 Name& name(Position const position)267 Table::name(Position const position) 268 { 269 //return *this->name_[position]; // see corresponding const-function 270 return *this->name_.find(position)->second; 271 } 272 273 /** -> result 274 ** 275 ** @param position the position 276 ** 277 ** @return the name object at 'position' 278 **/ 279 Name const& name(Position const position) const280 Table::name(Position const position) const 281 { 282 //return *this->name_[position]; // needs write access 283 return *this->name_.find(position)->second; 284 } 285 286 /** -> result 287 ** 288 ** @param player the player 289 ** 290 ** @return the reservation object of 'player' 291 **/ 292 Reservation& reservation(Player const & player)293 Table::reservation(Player const& player) 294 { 295 return this->reservation(this->position(player)); 296 } 297 298 /** -> result 299 ** 300 ** @param player the player 301 ** 302 ** @return the reservation object of 'player' 303 **/ 304 Reservation const& reservation(Player const & player) const305 Table::reservation(Player const& player) const 306 { 307 return this->reservation(this->position(player)); 308 } 309 310 /** -> result 311 ** 312 ** @param position the position 313 ** 314 ** @return the reservation object at 'position' 315 **/ 316 Reservation& reservation(Position const position)317 Table::reservation(Position const position) 318 { 319 //return *this->reservation_[position]; // see corresponding const-function 320 return *this->reservation_.find(position)->second; 321 } 322 323 /** -> result 324 ** 325 ** @param position the position 326 ** 327 ** @return the reservation object at 'position' 328 **/ 329 Reservation const& reservation(Position const position) const330 Table::reservation(Position const position) const 331 { 332 //return *this->reservation_[position]; // needs write access 333 return *this->reservation_.find(position)->second; 334 } 335 336 /** @return whether a human player shall get a card 337 **/ 338 bool get_card() const339 Table::get_card() const 340 { return this->get_card_; } 341 342 343 /** -> result 344 ** 345 ** @param player the player 346 ** 347 ** @return the position of 'player' 348 **/ 349 Position position(Player const & player) const350 Table::position(Player const& player) const 351 { 352 return ::preferences.position(player.no()); 353 } // Position Table::position(Player player) const 354 355 /** -> result 356 ** 357 ** @param position position of the player 358 ** 359 ** @return the player at 'position' 360 ** 361 ** @todo remove the for-loop 362 **/ 363 Player const& player(Position const position) const364 Table::player(Position const position) const 365 { 366 for (auto const& p : this->ui->game().players()) 367 if (::preferences.position(p.no()) == position) 368 return p; 369 370 DEBUG_ASSERTION(false, 371 "Table::player(position)\n" 372 " could not find player at position " 373 << "'" << position << "'"); 374 375 return this->ui->game().player(0); 376 } 377 378 /** -> result 379 ** 380 ** @param player the player 381 ** 382 ** @return the rotation of 'player' 383 **/ 384 Rotation rotation(Player const & player) const385 Table::rotation(Player const& player) const 386 { 387 return this->rotation(this->position(player)); 388 } 389 390 /** -> result 391 ** 392 ** @param position the position 393 ** 394 ** @return the rotation of the player at 'position' 395 **/ 396 Rotation rotation(Position const position) const397 Table::rotation(Position const position) const 398 { 399 switch (position) { 400 case Position::north: 401 return Rotation::down; 402 case Position::south: 403 return Rotation::up; 404 case Position::west: 405 return Rotation::right; 406 case Position::east: 407 return Rotation::left; 408 case Position::center: 409 DEBUG_ASSERTION(false, 410 "Table::rotation(position):\n" 411 " wrong position center (" << position << ")"); 412 } // switch(this->position()) 413 414 return Rotation::up; 415 } 416 417 /** @return cairo context 418 **/ 419 Cairo::RefPtr<Cairo::Context> create_cairo_context()420 Table::create_cairo_context() 421 { 422 return Cairo::Context::create(this->surface_); 423 } 424 425 /** @return the width of the table 426 **/ 427 int width() const428 Table::width() const 429 { 430 return this->get_width(); 431 } 432 433 /** @return the height of the table 434 **/ 435 int height() const436 Table::height() const 437 { 438 return this->get_height(); 439 } 440 441 /** @return the width of the table 442 **/ 443 Table::Layout layout() const444 Table::layout() const 445 { 446 return this->layout_; 447 } 448 449 /** @return border on the left and right 450 **/ 451 int border_x() const452 Table::border_x() const 453 { 454 return (this->ui->cards->height() / 10); 455 } 456 457 /** @return border on the top and bottom 458 **/ 459 int border_y() const460 Table::border_y() const 461 { 462 return (this->ui->cards->height() / 10); 463 } 464 465 } 466 467 #endif // #ifdef USE_UI_GTKMM 468