1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
|
Description: Port to SFML 3
Author: James Cowgill <jcowgill@debian.org>
Forwarded: https://github.com/thelaui/M.A.R.S./pull/38
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,11 +31,8 @@ set(mars_EXE_DEST_DIR ${CMAKE_INSTALL_PR
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
-# find the sfml2 headers and library
-include(FindPkgConfig)
-pkg_check_modules(SFML REQUIRED sfml-audio>=2.0 sfml-graphics>=2.0
- sfml-window>=2.0 sfml-system>=2.0)
-include_directories(${SFML_INCLUDE_DIRS})
+# find the sfml3 headers and library
+find_package(SFML 3 REQUIRED Audio Graphics)
# Foundation library needed for apple
if(APPLE)
--- a/include/Interface/Tab.hpp
+++ b/include/Interface/Tab.hpp
@@ -32,7 +32,7 @@ class Tab: public UiElement {
void mouseWheelMoved(Vector2f const& position, int delta);
void mouseLeft(bool down);
void keyEvent(bool down, Key const& key);
- void textEntered(sf::Uint32 keyCode);
+ void textEntered(char32_t keyCode);
bool tabNext();
bool tabPrevious();
--- a/include/Interface/TabList.hpp
+++ b/include/Interface/TabList.hpp
@@ -32,7 +32,7 @@ class TabList: public UiElement {
void mouseWheelMoved(Vector2f const& position, int delta);
void mouseLeft(bool down);
void keyEvent(bool down, Key const& key);
- void textEntered(sf::Uint32 keyCode);
+ void textEntered(char32_t keyCode);
bool tabNext();
bool tabPrevious();
--- a/include/Interface/TextEdit.hpp
+++ b/include/Interface/TextEdit.hpp
@@ -33,7 +33,7 @@ class TextEdit: public UiElement {
void mouseMoved(Vector2f const& position);
void mouseLeft(bool down);
void keyEvent(bool down, Key const& key);
- void textEntered(sf::Uint32 keyCode);
+ void textEntered(char32_t keyCode);
void draw() const;
--- a/include/Interface/UiElement.hpp
+++ b/include/Interface/UiElement.hpp
@@ -32,7 +32,7 @@ class UiElement {
virtual void mouseWheelMoved(Vector2f const& position, int delta) {}
virtual void mouseLeft(bool down);
virtual void keyEvent(bool down, Key const& key) {}
- virtual void textEntered(sf::Uint32 keyCode) {}
+ virtual void textEntered(char32_t keyCode) {}
virtual bool tabNext() {return true;}
virtual bool tabPrevious() {return true;}
--- a/include/Interface/UiWindow.hpp
+++ b/include/Interface/UiWindow.hpp
@@ -31,7 +31,7 @@ class UiWindow: public UiElement {
void mouseWheelMoved(Vector2f const& position, int delta);
void mouseLeft(bool down);
void keyEvent(bool down, Key const& key);
- void textEntered(sf::Uint32 keyCode);
+ void textEntered(char32_t keyCode);
bool tabNext();
bool tabPrevious();
--- a/include/Menu/menus.hpp
+++ b/include/Menu/menus.hpp
@@ -36,7 +36,7 @@ namespace menus {
void mouseWheelMoved(Vector2f const& position, int delta);
void mouseLeft(bool down);
void keyEvent(bool down, Key const& key);
- void textEntered(sf::Uint32 keyCode);
+ void textEntered(char32_t keyCode);
void showMain();
void showPause();
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,7 +52,7 @@ endif(APPLE)
target_link_libraries(
marsshooter
${FOUNDATION_LIBRARY}
- ${SFML_LIBRARIES}
+ SFML::Graphics SFML::Audio
${OPENGL_LIBRARIES}
${XRANDR_LIBRARY}
${FRIBIDI_LIBRARY}
--- a/src/Interface/ColorPickerWindow.cpp
+++ b/src/Interface/ColorPickerWindow.cpp
@@ -48,7 +48,7 @@ void ColorPickerWindow::draw() const {
// update color according to mouse
Vector2f mouse = window::PixelToCoord(window::getMousePosition());
int x(mouse.x_), y(mouse.y_);
- if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && x>origin.x_ && x<origin.x_+190 && y>origin.y_ && y<origin.y_+150) {
+ if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) && x>origin.x_ && x<origin.x_+190 && y>origin.y_ && y<origin.y_+150) {
if (x>origin.x_+140) {
float offset(y-origin.y_-10.f);
if (offset > 119.9f) offset = 119.9f;
--- a/src/Interface/Tab.cpp
+++ b/src/Interface/Tab.cpp
@@ -41,13 +41,13 @@ void Tab::mouseMoved(Vector2f const& pos
int mirror(locales::getCurrentLocale().LTR_ ? 1 : -1);
Vector2f topLeftAbs(getTopLeft() + topLeft_*mirror-Vector2f(0.f, 10.f));
if (locales::getCurrentLocale().LTR_) {
- if ((!sf::Mouse::isButtonPressed(sf::Mouse::Left) || pressed_) && topLeftAbs.x_+width_ > position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ < position.x_ && topLeftAbs.y_ < position.y_)
+ if ((!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) || pressed_) && topLeftAbs.x_+width_ > position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ < position.x_ && topLeftAbs.y_ < position.y_)
hovered_ = true;
else
hovered_ = false;
}
else {
- if ((!sf::Mouse::isButtonPressed(sf::Mouse::Left) || pressed_) && topLeftAbs.x_-width_ < position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ > position.x_ && topLeftAbs.y_ < position.y_)
+ if ((!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) || pressed_) && topLeftAbs.x_-width_ < position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ > position.x_ && topLeftAbs.y_ < position.y_)
hovered_ = true;
else
hovered_ = false;
@@ -145,7 +145,7 @@ bool Tab::tabPrevious() {
}
-void Tab::textEntered(sf::Uint32 keyCode) {
+void Tab::textEntered(char32_t keyCode) {
if (active_ && focusedWidget_)
focusedWidget_->textEntered(keyCode);
}
--- a/src/Interface/TabList.cpp
+++ b/src/Interface/TabList.cpp
@@ -114,7 +114,7 @@ bool TabList::tabPrevious() {
return true;
}
-void TabList::textEntered(sf::Uint32 keyCode) {
+void TabList::textEntered(char32_t keyCode) {
if (focusedTab_)
focusedTab_->textEntered(keyCode);
}
--- a/src/Interface/TextEdit.cpp
+++ b/src/Interface/TextEdit.cpp
@@ -56,7 +56,7 @@ void TextEdit::mouseMoved(Vector2f const
UiElement::mouseMoved(position);
if (label_)
label_->mouseMoved(position);
- if (pressed_ && sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
+ if (pressed_ && sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
cursorPos_ = 0;
cursorTimer_ = 0;
int mirror(locales::getCurrentLocale().LTR_ ? 1 : -1);
@@ -87,25 +87,25 @@ void TextEdit::keyEvent(bool down, Key c
if (pressed_) {
if (down) {
// backspace
- if (key.code_.keyBoard_ == sf::Keyboard::BackSpace && cursorPos_ > 0) {
+ if (key.code_.keyBoard_ == sf::Keyboard::Key::Backspace && cursorPos_ > 0) {
value_->erase(cursorPos_-1, 1);
--cursorPos_;
cursorTimer_ = 0;
}
// delete
- else if (key.code_.keyBoard_ == sf::Keyboard::Delete && cursorPos_ < value_->getSize()) {
+ else if (key.code_.keyBoard_ == sf::Keyboard::Key::Delete && cursorPos_ < value_->getSize()) {
value_->erase(cursorPos_, 1);
}
// move cursor
- else if (key.code_.keyBoard_ == sf::Keyboard::Left && cursorPos_ > 0) {
+ else if (key.code_.keyBoard_ == sf::Keyboard::Key::Left && cursorPos_ > 0) {
--cursorPos_;
cursorTimer_ = 0;
}
- else if (key.code_.keyBoard_ == sf::Keyboard::Right && cursorPos_ < value_->getSize()) {
+ else if (key.code_.keyBoard_ == sf::Keyboard::Key::Right && cursorPos_ < value_->getSize()) {
++cursorPos_;
cursorTimer_ = 0;
}
- else if (key.navi_ == Key::nAbort || key.code_.keyBoard_ == sf::Keyboard::Up || key.code_.keyBoard_ == sf::Keyboard::Down || key.navi_ == Key::nConfirm) {
+ else if (key.navi_ == Key::nAbort || key.code_.keyBoard_ == sf::Keyboard::Key::Up || key.code_.keyBoard_ == sf::Keyboard::Key::Down || key.navi_ == Key::nConfirm) {
if (*value_ == "")
*value_ = fallBack_;
menus::unFixKeyboard();
@@ -120,7 +120,7 @@ void TextEdit::keyEvent(bool down, Key c
}
}
-void TextEdit::textEntered(sf::Uint32 keyCode) {
+void TextEdit::textEntered(char32_t keyCode) {
if (pressed_) {
if (type_ == TEXT_EDIT) {
if (value_->getSize() < maxLength_ && keyCode != 8 && keyCode != 13 && keyCode != 32 && keyCode != 127) {
--- a/src/Interface/UiElement.cpp
+++ b/src/Interface/UiElement.cpp
@@ -40,13 +40,13 @@ UiElement::UiElement(Vector2f const& top
void UiElement::mouseMoved(Vector2f const& position) {
Vector2f topLeftAbs(getTopLeft());
if (locales::getCurrentLocale().LTR_) {
- if ((!sf::Mouse::isButtonPressed(sf::Mouse::Left) || pressed_) && topLeftAbs.x_+width_ > position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ < position.x_ && topLeftAbs.y_ < position.y_)
+ if ((!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) || pressed_) && topLeftAbs.x_+width_ > position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ < position.x_ && topLeftAbs.y_ < position.y_)
hovered_ = true;
else
hovered_ = false;
}
else {
- if ((!sf::Mouse::isButtonPressed(sf::Mouse::Left) || pressed_) && topLeftAbs.x_-width_ < position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ > position.x_ && topLeftAbs.y_ < position.y_)
+ if ((!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left) || pressed_) && topLeftAbs.x_-width_ < position.x_ && topLeftAbs.y_+height_ > position.y_ && topLeftAbs.x_ > position.x_ && topLeftAbs.y_ < position.y_)
hovered_ = true;
else
hovered_ = false;
--- a/src/Interface/UiWindow.cpp
+++ b/src/Interface/UiWindow.cpp
@@ -84,7 +84,7 @@ bool UiWindow::tabPrevious() {
return false;
}
-void UiWindow::textEntered(sf::Uint32 keyCode) {
+void UiWindow::textEntered(char32_t keyCode) {
if (focusedWidget_)
focusedWidget_->textEntered(keyCode);
}
--- a/src/Media/announcer.cpp
+++ b/src/Media/announcer.cpp
@@ -33,7 +33,8 @@ namespace announcer {
COUNT};
std::vector<sf::SoundBuffer*> sounds_(COUNT);
- sf::Sound soundChannel_;
+ const sf::SoundBuffer emptyBuffer_;
+ sf::Sound soundChannel_(emptyBuffer_);
void loadSound_(SoundType sound, std::string fileName) {
sounds_[sound] = new sf::SoundBuffer;
@@ -44,11 +45,11 @@ namespace announcer {
void playSound(SoundType sound) {
// check if sound is already loaded
if (sounds_[sound] != NULL) {
- if (soundChannel_.getStatus() != sf::Sound::Playing) {
+ if (soundChannel_.getStatus() != sf::Sound::Status::Playing) {
// play sound
soundChannel_.setBuffer(*sounds_[sound]);
soundChannel_.setVolume(static_cast<float>(settings::C_announcerVolume));
- soundChannel_.setPosition(SPACE_X_RESOLUTION*0.5f, 0.f, 0.f);
+ soundChannel_.setPosition({SPACE_X_RESOLUTION*0.5f, 0.f, 0.f});
soundChannel_.setAttenuation(0.f);
soundChannel_.play();
}
--- a/src/Media/file.cpp
+++ b/src/Media/file.cpp
@@ -65,7 +65,7 @@ namespace file {
line = std::string(outstring.data());
- std::basic_string<sf::Uint32> utf32line;
+ std::u32string utf32line;
sf::Utf8::toUtf32(line.begin(), line.end(), back_inserter(utf32line));
strings.push_back(utf32line);
--- a/src/Media/font.cpp
+++ b/src/Media/font.cpp
@@ -21,6 +21,7 @@ this program. If not, see <http://www.g
# include "Locales/locales.hpp"
# include <iostream>
+# include <map>
namespace font {
namespace {
@@ -32,7 +33,7 @@ namespace font {
if (it == fonts_.end()) {
// load it from file and...
sf::Font* font = new sf::Font();
- font->loadFromFile(settings::C_dataPath + "fonts/" + locales::getLocales()[languageID].font_);
+ font->openFromFile((settings::C_dataPath + "fonts/" + locales::getLocales()[languageID].font_).toUtf32());
fonts_.insert(std::make_pair(languageID, font));
// ... return it afterwards
return font;
--- a/src/Media/music.cpp
+++ b/src/Media/music.cpp
@@ -55,9 +55,9 @@ namespace music {
}
closedir(dp);
- musicChannel_.setLoop(false);
+ musicChannel_.setLooping(false);
musicChannel_.setRelativeToListener(true);
- sf::Listener::setPosition(SPACE_X_RESOLUTION*0.5f, 0.f, 300.f);
+ sf::Listener::setPosition({SPACE_X_RESOLUTION*0.5f, 0.f, 300.f});
setGlobalVolume();
initialized_ = true;
}
@@ -75,7 +75,7 @@ namespace music {
musicChannel_.setVolume(settings::C_musicVolume*fadeOutTimer_*2.5f);
}
- if (musicChannel_.getStatus() == sf::Music::Stopped && files_.size() > 0) {
+ if (musicChannel_.getStatus() == sf::Music::Status::Stopped && files_.size() > 0) {
if (games::type() == games::gMenu) play(settings::C_dataPath + "audio/menu.ogg");
else play();
}
@@ -96,7 +96,7 @@ namespace music {
if (games::type() != games::gMenu && games::type() != games::gTutorial && window::isKeyDown(settings::C_statisticsKey))
musicNotify::show(settings::C_dataPath + "/audio/music/" + files_[playList_.back()]);
}
- else if (musicChannel_.getStatus() == sf::Music::Playing)
+ else if (musicChannel_.getStatus() == sf::Music::Status::Playing)
stop();
}
--- a/src/Media/sound.cpp
+++ b/src/Media/sound.cpp
@@ -20,13 +20,15 @@ this program. If not, see <http://www.g
# include "System/settings.hpp"
# include "Games/games.hpp"
+# include <optional>
+
# define CHANNELCOUNT 64
namespace sound {
namespace {
std::vector<sf::SoundBuffer*> sounds_(COUNT);
- sf::Sound soundChannel_[CHANNELCOUNT];
+ std::optional<sf::Sound> soundChannel_[CHANNELCOUNT];
bool initialized_(false);
void loadSound_(SoundType sound, std::string fileName) {
@@ -36,7 +38,7 @@ namespace sound {
}
void init_() {
- sf::Listener::setPosition(SPACE_X_RESOLUTION*0.5f, 0.f, 300.f);
+ sf::Listener::setPosition({SPACE_X_RESOLUTION*0.5f, 0.f, 300.f});
initialized_ = true;
}
}
@@ -48,16 +50,20 @@ namespace sound {
if (sounds_[sound] != NULL) {
// if its already loaded search for free soundChannel_
int i(0);
- while (soundChannel_[i].getStatus() == sf::Sound::Playing && i<CHANNELCOUNT) ++i;
+ while((i < CHANNELCOUNT) && soundChannel_[i] && (soundChannel_[i]->getStatus() == sf::Sound::Status::Playing)) i++;
if (i < CHANNELCOUNT) {
// play sound with random pitch
- soundChannel_[i].setBuffer(*sounds_[sound]);
+ if (soundChannel_[i])
+ soundChannel_[i]->setBuffer(*sounds_[sound]);
+ else
+ soundChannel_[i] = sf::Sound(*sounds_[sound]);
+
if (sound != Click && sound != Tab && sound != Check && sound != Countdown && sound != Start )
- soundChannel_[i].setPitch(1 + static_cast<float>(rand()%100)/200.f - 0.25f);
- soundChannel_[i].setVolume((volume < 0.f ? -volume : volume)*static_cast<float>(settings::C_soundVolume)/100.f);
- soundChannel_[i].setPosition(position.x_, 0.f, 0.f);
- soundChannel_[i].setAttenuation(0.f);
- soundChannel_[i].play();
+ soundChannel_[i]->setPitch(1 + static_cast<float>(rand()%100)/200.f - 0.25f);
+ soundChannel_[i]->setVolume((volume < 0.f ? -volume : volume)*static_cast<float>(settings::C_soundVolume)/100.f);
+ soundChannel_[i]->setPosition({position.x_, 0.f, 0.f});
+ soundChannel_[i]->setAttenuation(0.f);
+ soundChannel_[i]->play();
}
}
else {
--- a/src/Media/text.cpp
+++ b/src/Media/text.cpp
@@ -29,26 +29,26 @@ namespace text {
void drawText(sf::String const& text, Vector2f const& location,
float size, int align, Color3f const& color, float alpha, sf::Font* font) {
- sf::Text drawString(text, font ? *font : *font::getFont(), size);
- drawString.setColor(sf::Color(color.r()*255, color.g()*255, color.b()*255, alpha<0 ? 0 : alpha*255));
+ sf::Text drawString(font ? *font : *font::getFont(), text, size);
+ drawString.setFillColor(sf::Color(color.r()*255, color.g()*255, color.b()*255, alpha<0 ? 0 : alpha*255));
Vector2f loc(location);
sf::FloatRect boundingBox = drawString.getGlobalBounds();
if (align == TEXT_ALIGN_CENTER)
- loc.x_ -= static_cast<int>(boundingBox.width*0.5f);
+ loc.x_ -= static_cast<int>(boundingBox.size.x*0.5f);
else if ((align == TEXT_ALIGN_RIGHT && locales::getCurrentLocale().LTR_) || (align == TEXT_ALIGN_LEFT && !locales::getCurrentLocale().LTR_))
- loc.x_ -= static_cast<int>(boundingBox.width);
+ loc.x_ -= static_cast<int>(boundingBox.size.x);
// prevent text from being outside of screen
Vector2f const& port = window::getViewPort();
if (loc.x_ < 0.f) loc.x_ = 0.f;
if (loc.y_ < 0.f) loc.y_ = 0.f;
- if (loc.x_ + boundingBox.width > port.x_) loc.x_ = port.x_ - static_cast<int>(boundingBox.width);
- if (loc.y_ + boundingBox.height > port.y_) loc.y_ = port.y_ - static_cast<int>(boundingBox.height);
+ if (loc.x_ + boundingBox.size.x > port.x_) loc.x_ = port.x_ - static_cast<int>(boundingBox.size.x);
+ if (loc.y_ + boundingBox.size.y > port.y_) loc.y_ = port.y_ - static_cast<int>(boundingBox.size.y);
- drawString.setPosition(loc.x_, loc.y_);
+ drawString.setPosition({loc.x_, loc.y_});
window::draw(drawString, sf::RenderStates(sf::BlendAlpha));
}
@@ -78,18 +78,18 @@ namespace text {
}
float getCharacterPos(sf::String const& text, int pos, float size, int align, sf::Font* font) {
- sf::Text drawString(text, font ? *font : *font::getFont(), size);
+ sf::Text drawString(font ? *font : *font::getFont(), text, size);
float result = drawString.findCharacterPos(pos).x;
switch (align) {
case TEXT_ALIGN_CENTER: {
sf::FloatRect boundingBox = drawString.getLocalBounds();
- result -= boundingBox.width*0.5f;
+ result -= boundingBox.size.x*0.5f;
break;
}
case TEXT_ALIGN_RIGHT: {
sf::FloatRect boundingBox = drawString.getLocalBounds();
- result -= boundingBox.width;
+ result -= boundingBox.size.x;
break;
}
default: break;
--- a/src/Media/texture.cpp
+++ b/src/Media/texture.cpp
@@ -35,7 +35,7 @@ namespace texture {
img.loadFromFile(fileName);
// convert sf::Image to GLuint
- const sf::Uint8* ptr = img.getPixelsPtr();
+ const std::uint8_t* ptr = img.getPixelsPtr();
glGenTextures(1, textures_[type]);
glBindTexture(GL_TEXTURE_2D, *textures_[type]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.getSize().x, img.getSize().y, 0, GL_RGBA,GL_UNSIGNED_BYTE, ptr);
--- a/src/Menu/OptionsMenu.cpp
+++ b/src/Menu/OptionsMenu.cpp
@@ -109,9 +109,9 @@ UiWindow* OptionsMenu::get() {
std::vector<sf::String> resolutions;
std::vector<sf::String> colorDepths;
for (std::vector<sf::VideoMode>::iterator it = modes.begin(); it != modes.end(); ++it) {
- if (it->width >= 800 && it->bitsPerPixel >= 8) {
+ if (it->size.x >= 800 && it->bitsPerPixel >= 8) {
std::stringstream res, depth;
- res << it->width << " x " << it->height;
+ res << it->size.x << " x " << it->size.y;
depth << it->bitsPerPixel;
sf::String resString(res.str()), depthString(depth.str());
@@ -266,12 +266,12 @@ void OptionsMenu::onShow() {
else if (settings::C_screenShotFormat == "png") format_ = "PNG(*.png)";
else if (settings::C_screenShotFormat == "jpg") format_ = "JPEG (*.jpg)";
- sf::VideoMode mode(settings::C_resX, settings::C_resY);
+ sf::VideoMode mode({settings::C_resX, settings::C_resY});
std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes();
if (modes.size() > 0 && !mode.isValid()) {
mode = sf::VideoMode::getFullscreenModes().front();
- settings::C_resX = mode.width;
- settings::C_resY = mode.height;
+ settings::C_resX = mode.size.x;
+ settings::C_resY = mode.size.y;
}
std::stringstream sstr1;
--- a/src/Menu/menus.cpp
+++ b/src/Menu/menus.cpp
@@ -128,7 +128,7 @@ namespace menus {
showPause();
}
- void textEntered(sf::Uint32 keyCode) {
+ void textEntered(char32_t keyCode) {
if (visible())
windowStack_.back()->textEntered(keyCode);
}
--- a/src/Shaders/postFX.cpp
+++ b/src/Shaders/postFX.cpp
@@ -57,7 +57,7 @@ namespace postFX {
exposure_ = 1.f;
}
- postFX_.setParameter("Exposure", exposure_);
+ postFX_.setUniform("Exposure", exposure_);
}
}
@@ -75,14 +75,14 @@ namespace postFX {
void load() {
if (supported()) {
- postFX_.loadFromFile(settings::C_dataPath + "shaders/bump.frag", sf::Shader::Fragment);
- bumpMap_.create(SPACE_X_RESOLUTION*0.5f, SPACE_Y_RESOLUTION*0.5f);
+ postFX_.loadFromFile(settings::C_dataPath + "shaders/bump.frag", sf::Shader::Type::Fragment);
+ bumpMap_.resize({SPACE_X_RESOLUTION / 2, SPACE_Y_RESOLUTION / 2});
glViewport(0,0,SPACE_X_RESOLUTION*0.5f,SPACE_Y_RESOLUTION*0.5f);
glOrtho(0, SPACE_X_RESOLUTION, SPACE_Y_RESOLUTION, 0, -1, 1);
glEnable(GL_BLEND);
glMatrixMode(GL_MODELVIEW);
- postFX_.setParameter("BumpMap", bumpMap_.getTexture());
- postFX_.setParameter("Exposure", exposure_);
+ postFX_.setUniform("BumpMap", bumpMap_.getTexture());
+ postFX_.setUniform("Exposure", exposure_);
}
else
std::cout << "Shaders are not supported on your hardware! There will be no fancy graphics..." << std::endl;
--- a/src/System/Key.cpp
+++ b/src/System/Key.cpp
@@ -27,19 +27,19 @@ Key::Key(sf::Keyboard::Key code):
code_.keyBoard_ = code;
- if (code == sf::Keyboard::Return || code == sf::Keyboard::Space)
+ if (code == sf::Keyboard::Key::Enter || code == sf::Keyboard::Key::Space)
navi_ = nConfirm;
- else if (code == sf::Keyboard::Escape)
+ else if (code == sf::Keyboard::Key::Escape)
navi_ = nAbort;
- else if ((code == sf::Keyboard::Tab && (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::RControl)))
- || (code == sf::Keyboard::Tab && (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift)))
- || (code == sf::Keyboard::Up))
+ else if ((code == sf::Keyboard::Key::Tab && (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::RControl)))
+ || (code == sf::Keyboard::Key::Tab && (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::RShift)))
+ || (code == sf::Keyboard::Key::Up))
navi_ = nUp;
- else if (code == sf::Keyboard::Tab || code == sf::Keyboard::Down)
+ else if (code == sf::Keyboard::Key::Tab || code == sf::Keyboard::Key::Down)
navi_ = nDown;
- else if (code == sf::Keyboard::Left)
+ else if (code == sf::Keyboard::Key::Left)
navi_ = nLeft;
- else if (code == sf::Keyboard::Right)
+ else if (code == sf::Keyboard::Key::Right)
navi_ = nRight;
}
@@ -54,25 +54,25 @@ Key::Key(unsigned int joyID, sf::Joystic
code_.joyButton_ = tmp.first;
strength_ = tmp.second;
- if ((joyAxis == 7 && strength == -100) || (joyAxis == 1 && strength == -100) ||
+ if ((joyAxis == sf::Joystick::Axis::PovY && strength == -100) || (joyAxis == sf::Joystick::Axis::Y && strength == -100) ||
# if defined __WIN32__
- (joyAxis == 3 && strength == -100)
+ (joyAxis == sf::Joystick::Axis::R && strength == -100)
# else
- (joyAxis == 5 && strength == -100)
+ (joyAxis == sf::Joystick::Axis::V && strength == -100)
# endif
)
navi_ = nUp;
- else if ((joyAxis == 7 && strength == 100) || (joyAxis == 1 && strength == 100) ||
+ else if ((joyAxis == sf::Joystick::Axis::PovY && strength == 100) || (joyAxis == sf::Joystick::Axis::Y && strength == 100) ||
# if defined __WIN32__
- (joyAxis == 3 && strength == 100)
+ (joyAxis == sf::Joystick::Axis::R && strength == 100)
# else
- (joyAxis == 5 && strength == 100)
+ (joyAxis == sf::Joystick::Axis::V && strength == 100)
# endif
)
navi_ = nDown;
- else if ((joyAxis == 6 && strength == -100) || (joyAxis == 0 && strength == -100) || (joyAxis == 4 && strength == -100))
+ else if ((joyAxis == sf::Joystick::Axis::PovX && strength == -100) || (joyAxis == sf::Joystick::Axis::X && strength == -100) || (joyAxis == sf::Joystick::Axis::U && strength == -100))
navi_ = nLeft;
- else if ((joyAxis == 6 && strength == 100) || (joyAxis == 0 && strength == 100) || (joyAxis == 4 && strength == 100))
+ else if ((joyAxis == sf::Joystick::Axis::PovX && strength == 100) || (joyAxis == sf::Joystick::Axis::X && strength == 100) || (joyAxis == sf::Joystick::Axis::U && strength == 100))
navi_ = nRight;
}
@@ -104,16 +104,16 @@ std::pair<Key::AxisType, int> Key::conve
std::pair<AxisType, int> result;
result.second = std::abs(strength);
switch (joyAxis) {
- case sf::Joystick::X:
+ case sf::Joystick::Axis::X:
if (strength < 0) result.first = aALleft;
else result.first = aALright;
break;
- case sf::Joystick::Y:
+ case sf::Joystick::Axis::Y:
if (strength < 0) result.first = aALup;
else result.first = aALdown;
break;
- case sf::Joystick::Z:
+ case sf::Joystick::Axis::Z:
# if defined __WIN32__
if (strength > 0) {
result.first = aLT;
@@ -129,7 +129,7 @@ std::pair<Key::AxisType, int> Key::conve
# endif
break;
- case sf::Joystick::R:
+ case sf::Joystick::Axis::R:
# if defined __WIN32__
if (strength < 0) result.first = aARup;
else result.first = aARdown;
@@ -139,21 +139,21 @@ std::pair<Key::AxisType, int> Key::conve
# endif
break;
- case sf::Joystick::U:
+ case sf::Joystick::Axis::U:
if (strength < 0) result.first = aARleft;
else result.first = aARright;
break;
- case sf::Joystick::V:
+ case sf::Joystick::Axis::V:
# if !defined __WIN32__
if (strength < 0) result.first = aARup;
else result.first = aARdown;
# endif
break;
- case sf::Joystick::PovX:
+ case sf::Joystick::Axis::PovX:
if (strength < 0) result.first = aPOVleft;
else result.first = aPOVright;
break;
- case sf::Joystick::PovY:
+ case sf::Joystick::Axis::PovY:
if (strength < 0) result.first = aPOVup;
else result.first = aPOVdown;
break;
@@ -166,27 +166,27 @@ std::pair<Key::AxisType, int> Key::conve
sf::Joystick::Axis Key::convertToSFML(AxisType joyAxis) {
if(joyAxis == aALleft || joyAxis == aALright)
- return sf::Joystick::X;
+ return sf::Joystick::Axis::X;
else if(joyAxis == aALup || joyAxis == aALdown)
- return sf::Joystick::Y;
+ return sf::Joystick::Axis::Y;
else if(joyAxis == aLT)
- return sf::Joystick::Z;
+ return sf::Joystick::Axis::Z;
else if(joyAxis == aRT) {
# if defined __WIN32__
- return sf::Joystick::Z;
+ return sf::Joystick::Axis::Z;
# else
- return sf::Joystick::R;
+ return sf::Joystick::Axis::R;
# endif
}
else if(joyAxis == aARleft || joyAxis == aARright)
- return sf::Joystick::U;
+ return sf::Joystick::Axis::U;
else if(joyAxis == aARup || joyAxis == aARdown)
# if defined __WIN32__
- return sf::Joystick::R;
+ return sf::Joystick::Axis::R;
# else
- return sf::Joystick::V;
+ return sf::Joystick::Axis::V;
# endif
- else return sf::Joystick::PovX;
+ else return sf::Joystick::Axis::PovX;
}
bool operator== (Key const& lhs, Key const& rhs) {
--- a/src/System/generateName.cpp
+++ b/src/System/generateName.cpp
@@ -162,71 +162,73 @@ namespace generateName {
case Key::kKeyBoard: {
sf::Keyboard::Key keyCode(key.code_.keyBoard_);
// "normal" character
- if (static_cast<int>(keyCode) >= 0 && static_cast<int>(keyCode) <= 25) result = static_cast<char>(keyCode+65);
+ if (keyCode >= sf::Keyboard::Key::A && keyCode <= sf::Keyboard::Key::Z)
+ result = static_cast<char>(static_cast<int>(keyCode) - static_cast<int>(sf::Keyboard::Key::A) + 'A');
// numbers
- if (static_cast<int>(keyCode) >= 26 && static_cast<int>(keyCode) <= 35) result = static_cast<char>(keyCode+22);
+ if (keyCode >= sf::Keyboard::Key::Num0 && keyCode <= sf::Keyboard::Key::Num9)
+ result = static_cast<char>(static_cast<int>(keyCode) - static_cast<int>(sf::Keyboard::Key::Num0) + '0');
- else if (keyCode == sf::Keyboard::Add) result = *locales::getLocale(locales::Add);
- else if (keyCode == sf::Keyboard::BackSlash) result = *locales::getLocale(locales::BackSlash);
- else if (keyCode == sf::Keyboard::Comma) result = *locales::getLocale(locales::Comma);
- else if (keyCode == sf::Keyboard::Dash) result = *locales::getLocale(locales::Dash);
- else if (keyCode == sf::Keyboard::Delete) result = *locales::getLocale(locales::Delete);
- else if (keyCode == sf::Keyboard::Divide) result = *locales::getLocale(locales::Divide);
- else if (keyCode == sf::Keyboard::Down) result = *locales::getLocale(locales::Down);
- else if (keyCode == sf::Keyboard::End) result = *locales::getLocale(locales::End);
- else if (keyCode == sf::Keyboard::Equal) result = *locales::getLocale(locales::Equal);
- else if (keyCode == sf::Keyboard::F1) result = "F1";
- else if (keyCode == sf::Keyboard::F2) result = "F2";
- else if (keyCode == sf::Keyboard::F3) result = "F3";
- else if (keyCode == sf::Keyboard::F4) result = "F4";
- else if (keyCode == sf::Keyboard::F5) result = "F5";
- else if (keyCode == sf::Keyboard::F6) result = "F6";
- else if (keyCode == sf::Keyboard::F7) result = "F7";
- else if (keyCode == sf::Keyboard::F8) result = "F8";
- else if (keyCode == sf::Keyboard::F9) result = "F9";
- else if (keyCode == sf::Keyboard::F10) result = "F10";
- else if (keyCode == sf::Keyboard::F11) result = "F11";
- else if (keyCode == sf::Keyboard::F12) result = "F12";
- else if (keyCode == sf::Keyboard::Home) result = *locales::getLocale(locales::Home);
- else if (keyCode == sf::Keyboard::Insert) result = *locales::getLocale(locales::Insert);
- else if (keyCode == sf::Keyboard::LAlt) result = *locales::getLocale(locales::LeftAlt);
- else if (keyCode == sf::Keyboard::LBracket) result = *locales::getLocale(locales::LeftBracket);
- else if (keyCode == sf::Keyboard::LControl) result = *locales::getLocale(locales::LeftControl);
- else if (keyCode == sf::Keyboard::Left) result = *locales::getLocale(locales::Left);
- else if (keyCode == sf::Keyboard::LShift) result = *locales::getLocale(locales::LeftShift);
- else if (keyCode == sf::Keyboard::LSystem) result = *locales::getLocale(locales::LeftSuper);
- else if (keyCode == sf::Keyboard::Menu) result = *locales::getLocale(locales::Menu);
- else if (keyCode == sf::Keyboard::Multiply) result = *locales::getLocale(locales::Multiply);
- else if (keyCode == sf::Keyboard::Numpad0) result = "Num 0";
- else if (keyCode == sf::Keyboard::Numpad1) result = "Num 1";
- else if (keyCode == sf::Keyboard::Numpad2) result = "Num 2";
- else if (keyCode == sf::Keyboard::Numpad3) result = "Num 3";
- else if (keyCode == sf::Keyboard::Numpad4) result = "Num 4";
- else if (keyCode == sf::Keyboard::Numpad5) result = "Num 5";
- else if (keyCode == sf::Keyboard::Numpad6) result = "Num 6";
- else if (keyCode == sf::Keyboard::Numpad7) result = "Num 7";
- else if (keyCode == sf::Keyboard::Numpad8) result = "Num 8";
- else if (keyCode == sf::Keyboard::Numpad9) result = "Num 9";
- else if (keyCode == sf::Keyboard::PageDown) result = *locales::getLocale(locales::PageDown);
- else if (keyCode == sf::Keyboard::PageUp) result = *locales::getLocale(locales::PageUp);
- else if (keyCode == sf::Keyboard::Pause) result = *locales::getLocale(locales::Pause);
- else if (keyCode == sf::Keyboard::Period) result = *locales::getLocale(locales::Period);
- else if (keyCode == sf::Keyboard::Quote) result = *locales::getLocale(locales::Quote);
- else if (keyCode == sf::Keyboard::RAlt) result = *locales::getLocale(locales::RightAlt);
- else if (keyCode == sf::Keyboard::RBracket) result = *locales::getLocale(locales::RightBracket);
- else if (keyCode == sf::Keyboard::RControl) result = *locales::getLocale(locales::RightControl);
- else if (keyCode == sf::Keyboard::Return) result = *locales::getLocale(locales::Return);
- else if (keyCode == sf::Keyboard::Right) result = *locales::getLocale(locales::Right);
- else if (keyCode == sf::Keyboard::RShift) result = *locales::getLocale(locales::RightShift);
- else if (keyCode == sf::Keyboard::RSystem) result = *locales::getLocale(locales::RightSuper);
- else if (keyCode == sf::Keyboard::SemiColon) result = *locales::getLocale(locales::SemiColon);
- else if (keyCode == sf::Keyboard::Slash) result = *locales::getLocale(locales::Slash);
- else if (keyCode == sf::Keyboard::Space) result = *locales::getLocale(locales::Space);
- else if (keyCode == sf::Keyboard::Subtract) result = *locales::getLocale(locales::Subtract);
- else if (keyCode == sf::Keyboard::Tilde) result = *locales::getLocale(locales::Tilde);
- else if (keyCode == sf::Keyboard::Tab) result = *locales::getLocale(locales::Tab);
- else if (keyCode == sf::Keyboard::Up) result = *locales::getLocale(locales::Up);
+ else if (keyCode == sf::Keyboard::Key::Add) result = *locales::getLocale(locales::Add);
+ else if (keyCode == sf::Keyboard::Key::Backslash) result = *locales::getLocale(locales::BackSlash);
+ else if (keyCode == sf::Keyboard::Key::Comma) result = *locales::getLocale(locales::Comma);
+ else if (keyCode == sf::Keyboard::Key::Hyphen) result = *locales::getLocale(locales::Dash);
+ else if (keyCode == sf::Keyboard::Key::Delete) result = *locales::getLocale(locales::Delete);
+ else if (keyCode == sf::Keyboard::Key::Divide) result = *locales::getLocale(locales::Divide);
+ else if (keyCode == sf::Keyboard::Key::Down) result = *locales::getLocale(locales::Down);
+ else if (keyCode == sf::Keyboard::Key::End) result = *locales::getLocale(locales::End);
+ else if (keyCode == sf::Keyboard::Key::Equal) result = *locales::getLocale(locales::Equal);
+ else if (keyCode == sf::Keyboard::Key::F1) result = "F1";
+ else if (keyCode == sf::Keyboard::Key::F2) result = "F2";
+ else if (keyCode == sf::Keyboard::Key::F3) result = "F3";
+ else if (keyCode == sf::Keyboard::Key::F4) result = "F4";
+ else if (keyCode == sf::Keyboard::Key::F5) result = "F5";
+ else if (keyCode == sf::Keyboard::Key::F6) result = "F6";
+ else if (keyCode == sf::Keyboard::Key::F7) result = "F7";
+ else if (keyCode == sf::Keyboard::Key::F8) result = "F8";
+ else if (keyCode == sf::Keyboard::Key::F9) result = "F9";
+ else if (keyCode == sf::Keyboard::Key::F10) result = "F10";
+ else if (keyCode == sf::Keyboard::Key::F11) result = "F11";
+ else if (keyCode == sf::Keyboard::Key::F12) result = "F12";
+ else if (keyCode == sf::Keyboard::Key::Home) result = *locales::getLocale(locales::Home);
+ else if (keyCode == sf::Keyboard::Key::Insert) result = *locales::getLocale(locales::Insert);
+ else if (keyCode == sf::Keyboard::Key::LAlt) result = *locales::getLocale(locales::LeftAlt);
+ else if (keyCode == sf::Keyboard::Key::LBracket) result = *locales::getLocale(locales::LeftBracket);
+ else if (keyCode == sf::Keyboard::Key::LControl) result = *locales::getLocale(locales::LeftControl);
+ else if (keyCode == sf::Keyboard::Key::Left) result = *locales::getLocale(locales::Left);
+ else if (keyCode == sf::Keyboard::Key::LShift) result = *locales::getLocale(locales::LeftShift);
+ else if (keyCode == sf::Keyboard::Key::LSystem) result = *locales::getLocale(locales::LeftSuper);
+ else if (keyCode == sf::Keyboard::Key::Menu) result = *locales::getLocale(locales::Menu);
+ else if (keyCode == sf::Keyboard::Key::Multiply) result = *locales::getLocale(locales::Multiply);
+ else if (keyCode == sf::Keyboard::Key::Numpad0) result = "Num 0";
+ else if (keyCode == sf::Keyboard::Key::Numpad1) result = "Num 1";
+ else if (keyCode == sf::Keyboard::Key::Numpad2) result = "Num 2";
+ else if (keyCode == sf::Keyboard::Key::Numpad3) result = "Num 3";
+ else if (keyCode == sf::Keyboard::Key::Numpad4) result = "Num 4";
+ else if (keyCode == sf::Keyboard::Key::Numpad5) result = "Num 5";
+ else if (keyCode == sf::Keyboard::Key::Numpad6) result = "Num 6";
+ else if (keyCode == sf::Keyboard::Key::Numpad7) result = "Num 7";
+ else if (keyCode == sf::Keyboard::Key::Numpad8) result = "Num 8";
+ else if (keyCode == sf::Keyboard::Key::Numpad9) result = "Num 9";
+ else if (keyCode == sf::Keyboard::Key::PageDown) result = *locales::getLocale(locales::PageDown);
+ else if (keyCode == sf::Keyboard::Key::PageUp) result = *locales::getLocale(locales::PageUp);
+ else if (keyCode == sf::Keyboard::Key::Pause) result = *locales::getLocale(locales::Pause);
+ else if (keyCode == sf::Keyboard::Key::Period) result = *locales::getLocale(locales::Period);
+ else if (keyCode == sf::Keyboard::Key::Apostrophe) result = *locales::getLocale(locales::Quote);
+ else if (keyCode == sf::Keyboard::Key::RAlt) result = *locales::getLocale(locales::RightAlt);
+ else if (keyCode == sf::Keyboard::Key::RBracket) result = *locales::getLocale(locales::RightBracket);
+ else if (keyCode == sf::Keyboard::Key::RControl) result = *locales::getLocale(locales::RightControl);
+ else if (keyCode == sf::Keyboard::Key::Enter) result = *locales::getLocale(locales::Return);
+ else if (keyCode == sf::Keyboard::Key::Right) result = *locales::getLocale(locales::Right);
+ else if (keyCode == sf::Keyboard::Key::RShift) result = *locales::getLocale(locales::RightShift);
+ else if (keyCode == sf::Keyboard::Key::RSystem) result = *locales::getLocale(locales::RightSuper);
+ else if (keyCode == sf::Keyboard::Key::Semicolon) result = *locales::getLocale(locales::SemiColon);
+ else if (keyCode == sf::Keyboard::Key::Slash) result = *locales::getLocale(locales::Slash);
+ else if (keyCode == sf::Keyboard::Key::Space) result = *locales::getLocale(locales::Space);
+ else if (keyCode == sf::Keyboard::Key::Subtract) result = *locales::getLocale(locales::Subtract);
+ else if (keyCode == sf::Keyboard::Key::Grave) result = *locales::getLocale(locales::Tilde);
+ else if (keyCode == sf::Keyboard::Key::Tab) result = *locales::getLocale(locales::Tab);
+ else if (keyCode == sf::Keyboard::Key::Up) result = *locales::getLocale(locales::Up);
break;
}
--- a/src/System/settings.cpp
+++ b/src/System/settings.cpp
@@ -73,11 +73,11 @@ namespace settings {
int C_resY = INITIAL_WINDOW_Y;
int C_colorDepth = 32;
bool C_shaders = false;
- Key C_screenShotKey = Key(sf::Keyboard::F12);
+ Key C_screenShotKey = Key(sf::Keyboard::Key::F12);
bool C_audioRandom = true;
- Key C_audioNextKey = Key(sf::Keyboard::F8);
- Key C_audioPreviousKey = Key(sf::Keyboard::F7);
- Key C_statisticsKey = Key(sf::Keyboard::Tab);
+ Key C_audioNextKey = Key(sf::Keyboard::Key::F8);
+ Key C_audioPreviousKey = Key(sf::Keyboard::Key::F7);
+ Key C_statisticsKey = Key(sf::Keyboard::Key::Tab);
std::string C_configPath = "";
std::string C_dataPath = "";
std::string C_screenShotFormat = "jpg";
@@ -92,11 +92,11 @@ namespace settings {
sf::String C_playerIName = "PlayerI";
Color3f C_playerIColor = Color3f(1.f, 0.87f, 0.0125f);
Color3f C_playerITeamColor = Color3f(0.94f, 0.24f, 1.f);
- Key C_playerIup = Key(sf::Keyboard::Up);
- Key C_playerIleft = Key(sf::Keyboard::Left);
- Key C_playerIright = Key(sf::Keyboard::Right);
- Key C_playerIfire = Key(sf::Keyboard::RControl);
- Key C_playerISpecialKey = Key(sf::Keyboard::RShift);
+ Key C_playerIup = Key(sf::Keyboard::Key::Up);
+ Key C_playerIleft = Key(sf::Keyboard::Key::Left);
+ Key C_playerIright = Key(sf::Keyboard::Key::Right);
+ Key C_playerIfire = Key(sf::Keyboard::Key::RControl);
+ Key C_playerISpecialKey = Key(sf::Keyboard::Key::RShift);
bool C_playerIteamL = false;
bool C_playerIteamR = true;
int C_playerIShip = 0;
@@ -105,11 +105,11 @@ namespace settings {
sf::String C_playerIIName = "PlayerII";
Color3f C_playerIIColor = Color3f(0.5f, 0.4f, 0.82f);
Color3f C_playerIITeamColor = Color3f(0.05f, 1.f, 0.785f);
- Key C_playerIIup = Key(sf::Keyboard::W);
- Key C_playerIIleft = Key(sf::Keyboard::A);
- Key C_playerIIright = Key(sf::Keyboard::D);
- Key C_playerIIfire = Key(sf::Keyboard::LControl);
- Key C_playerIISpecialKey = Key(sf::Keyboard::LShift);
+ Key C_playerIIup = Key(sf::Keyboard::Key::W);
+ Key C_playerIIleft = Key(sf::Keyboard::Key::A);
+ Key C_playerIIright = Key(sf::Keyboard::Key::D);
+ Key C_playerIIfire = Key(sf::Keyboard::Key::LControl);
+ Key C_playerIISpecialKey = Key(sf::Keyboard::Key::LShift);
bool C_playerIIteamL = true;
bool C_playerIIteamR = false;
int C_playerIIShip = 0;
@@ -497,22 +497,22 @@ namespace settings {
}
else if (inputLine == "[playerIName]") {
sf::String tmp;
- sf::Uint32 character(0);
+ uint32_t character(0);
iss >> character;
int i(0);
while (character != 0 && i++ < 12) {
- tmp.insert(tmp.getSize(), character);
+ tmp.insert(tmp.getSize(), static_cast<char32_t>(character));
iss >> character;
}
C_playerIName = tmp;
}
else if (inputLine == "[playerIIName]") {
sf::String tmp;
- sf::Uint32 character(0);
+ uint32_t character(0);
iss >> character;
int i(0);
while (character != 0 && i++ < 12) {
- tmp.insert(tmp.getSize(), character);
+ tmp.insert(tmp.getSize(), static_cast<char32_t>(character));
iss >> character;
}
C_playerIIName = tmp;
--- a/src/System/window.cpp
+++ b/src/System/window.cpp
@@ -47,7 +47,6 @@ namespace window {
sf::RenderWindow window_;
sf::Clock clock_;
sf::RenderTexture backBuffer_;
- sf::Sprite fxImage_;
Vector2f viewPort_;
float scale_(static_cast<float>(settings::C_resX)/SPACE_X_RESOLUTION);
@@ -57,14 +56,14 @@ namespace window {
void setViewPort() {
const int windowHeight(window_.getSize().y), windowWidth(window_.getSize().x);
- sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
+ sf::View view(sf::FloatRect({0,0}, {windowWidth, windowHeight}));
if (static_cast<float>(windowWidth)/windowHeight > ratio) {
- view.setViewport(sf::FloatRect((windowWidth-viewPort_.x_)*0.5f / windowWidth, 0, 1, 1));
+ view.setViewport(sf::FloatRect({(windowWidth-viewPort_.x_)*0.5f / windowWidth, 0}, {1, 1}));
glViewport((windowWidth-viewPort_.x_)*0.5f, 0, viewPort_.x_, viewPort_.y_);
}
else {
- view.setViewport(sf::FloatRect(0, (windowHeight-viewPort_.y_)*0.5f / windowHeight, 1, 1));
+ view.setViewport(sf::FloatRect({0, (windowHeight-viewPort_.y_)*0.5f / windowHeight}, {1, 1}));
glViewport(0, (windowHeight-viewPort_.y_)*0.5f, viewPort_.x_, viewPort_.y_);
}
@@ -93,7 +92,7 @@ namespace window {
if (settings::C_shaders) {
backBuffer_.setActive(true);
backBuffer_.clear();
- backBuffer_.create(viewPort_.x_, viewPort_.y_);
+ backBuffer_.resize({viewPort_.x_, viewPort_.y_});
glViewport(0,0,viewPort_.x_, viewPort_.y_);
backBuffer_.setSmooth(false);
}
@@ -101,48 +100,47 @@ namespace window {
void update() {
timer::update(clock_.restart().asSeconds());
- sf::Event event;
- while (window_.pollEvent(event)) {
- if (event.type == sf::Event::Resized)
+ while (const auto event = window_.pollEvent()) {
+ if (event->is<sf::Event::Resized>())
resized();
- else if (event.type == sf::Event::Closed)
+ else if (event->is<sf::Event::Closed>())
close();
- else if (event.type == sf::Event::KeyPressed) {
+ else if (auto *keyPressed = event->getIf<sf::Event::KeyPressed>()) {
if (!menus::visible())
- controllers::singleKeyEvent(Key(event.key.code));
- menus::keyEvent(true, Key(event.key.code));
+ controllers::singleKeyEvent(Key(keyPressed->code));
+ menus::keyEvent(true, Key(keyPressed->code));
}
- else if (event.type == sf::Event::KeyReleased) {
- menus::keyEvent(false, Key(event.key.code));
+ else if (auto *keyReleased = event->getIf<sf::Event::KeyReleased>()) {
+ menus::keyEvent(false, Key(keyReleased->code));
}
- else if (event.type == sf::Event::TextEntered) {
+ else if (auto *textEntered = event->getIf<sf::Event::TextEntered>()) {
if (menus::visible())
- menus::textEntered(event.text.unicode);
+ menus::textEntered(textEntered->unicode);
}
- else if (event.type == sf::Event::MouseMoved) {
+ else if (auto *mouseMoved = event->getIf<sf::Event::MouseMoved>()) {
if (menus::visible())
- menus::mouseMoved(Vector2f(event.mouseMove.x - (window_.getSize().x - viewPort_.x_)/2, event.mouseMove.y - (window_.getSize().y - viewPort_.y_)/2));
+ menus::mouseMoved(Vector2f(mouseMoved->position.x - (window_.getSize().x - viewPort_.x_)/2, mouseMoved->position.y - (window_.getSize().y - viewPort_.y_)/2));
}
- else if (event.type == sf::Event::MouseButtonPressed) {
- if (menus::visible() && event.mouseButton.button == sf::Mouse::Left)
+ else if (auto *mousePressed = event->getIf<sf::Event::MouseButtonPressed>()) {
+ if (menus::visible() && mousePressed->button == sf::Mouse::Button::Left)
menus::mouseLeft(true);
}
- else if (event.type == sf::Event::MouseButtonReleased) {
- if (menus::visible() && event.mouseButton.button == sf::Mouse::Left)
+ else if (auto *mouseReleased = event->getIf<sf::Event::MouseButtonReleased>()) {
+ if (menus::visible() && mouseReleased->button == sf::Mouse::Button::Left)
menus::mouseLeft(false);
}
- else if (event.type == sf::Event::JoystickButtonPressed) {
+ else if (auto *joystickPressed = event->getIf<sf::Event::JoystickButtonPressed>()) {
if (timer::realTotalTime() - joyButtonTimer_ > 0.1f) {
if (!menus::visible())
- controllers::singleKeyEvent(Key(event.joystickButton.joystickId, event.joystickButton.button));
- menus::keyEvent(true, Key(event.joystickButton.joystickId, event.joystickButton.button));
+ controllers::singleKeyEvent(Key(joystickPressed->joystickId, joystickPressed->button));
+ menus::keyEvent(true, Key(joystickPressed->joystickId, joystickPressed->button));
joyButtonTimer_ = timer::realTotalTime();
}
}
- else if (event.type == sf::Event::JoystickButtonReleased)
- menus::keyEvent(false, Key(event.joystickButton.joystickId, event.joystickButton.button));
- else if (event.type == sf::Event::JoystickMoved) {
- Key key(event.joystickMove.joystickId, event.joystickMove.axis, event.joystickMove.position);
+ else if (auto *joystickReleased = event->getIf<sf::Event::JoystickButtonReleased>())
+ menus::keyEvent(false, Key(joystickReleased->joystickId, joystickReleased->button));
+ else if (auto *joystickMoved = event->getIf<sf::Event::JoystickMoved>()) {
+ Key key(joystickMoved->joystickId, joystickMoved->axis, joystickMoved->position);
if (key.strength_ >= 95 && timer::realTotalTime() - joyButtonTimer_ > 0.1f) {
if (!menus::visible())
controllers::singleKeyEvent(key);
@@ -151,9 +149,9 @@ namespace window {
joyButtonTimer_ = timer::realTotalTime();
}
}
- else if (event.type == sf::Event::MouseWheelMoved) {
+ else if (auto *mouseScrolled = event->getIf<sf::Event::MouseWheelScrolled>()) {
if (menus::visible())
- menus::mouseWheelMoved(Vector2f(event.mouseWheel.x - (window_.getSize().x - viewPort_.x_)/2, event.mouseWheel.y - (window_.getSize().y - viewPort_.y_)/2), event.mouseWheel.delta);
+ menus::mouseWheelMoved(Vector2f(mouseScrolled->position.x - (window_.getSize().x - viewPort_.x_)/2, mouseScrolled->position.y - (window_.getSize().y - viewPort_.y_)/2), mouseScrolled->delta);
}
}
}
@@ -196,10 +194,10 @@ namespace window {
}
void create() {
- sf::VideoMode mode(settings::C_resX, settings::C_resY, settings::C_colorDepth);
+ sf::VideoMode mode({settings::C_resX, settings::C_resY}, settings::C_colorDepth);
if (settings::C_fullScreen && mode.isValid())
- window_.create(mode, "M.A.R.S. - a " + generateName::game(), sf::Style::Fullscreen);
+ window_.create(mode, "M.A.R.S. - a " + generateName::game(), sf::State::Fullscreen);
else
window_.create(mode, "M.A.R.S. - a " + generateName::game());
window_.setVerticalSyncEnabled(settings::C_vsync);
@@ -209,7 +207,7 @@ namespace window {
// apple uses bundle icon instead
sf::Image icon;
icon.loadFromFile(settings::C_dataPath + "tex/icon.png");
- window_.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
+ window_.setIcon(icon);
# endif
resized();
@@ -275,8 +273,7 @@ namespace window {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
- fxImage_.setTexture(backBuffer_.getTexture(), true);
-
+ sf::Sprite fxImage_(backBuffer_.getTexture());
sf::Shader* shader = postFX::get();
draw(fxImage_, sf::RenderStates(sf::BlendNone), shader);
@@ -345,7 +342,9 @@ namespace window {
}
void screenShot() {
- sf::Image shot = window_.capture();
+ sf::Texture shot_texture(window_.getSize());
+ shot_texture.update(window_);
+ sf::Image shot = shot_texture.copyToImage();
// const int windowHeight(window_.GetHeight()), windowWidth(window_.GetWidth());
// if (static_cast<float>(windowWidth)/windowHeight > ratio)
// shot.Copy(window_, sf::IntRect((windowWidth-viewPort_.x_)*0.5f, 0, viewPort_.x_, viewPort_.y_));
|