|
17 | 17 |
|
18 | 18 | #include <cassert>
|
19 | 19 | #include <cmath> // abs
|
20 |
| -#include <cstddef> // offsetof, nullptr, size_t |
21 |
| -#include <cstdint> // uint8_t |
22 | 20 | #include <cstring> // memcpy
|
23 | 21 |
|
24 | 22 | #include <algorithm>
|
@@ -673,18 +671,16 @@ void Image(const sf::RenderTexture& texture, const sf::Vector2f& size, const sf:
|
673 | 671 | /////////////// Image Overloads for sf::Sprite
|
674 | 672 |
|
675 | 673 | void Image(const sf::Sprite& sprite, const sf::Color& tintColor, const sf::Color& borderColor) {
|
676 |
| - const sf::FloatRect bounds = sprite.getGlobalBounds(); |
677 |
| - Image(sprite, sf::Vector2f(bounds.width, bounds.height), tintColor, borderColor); |
| 674 | + Image(sprite, sprite.getGlobalBounds().size, tintColor, borderColor); |
678 | 675 | }
|
679 | 676 |
|
680 | 677 | void Image(const sf::Sprite& sprite, const sf::Vector2f& size, const sf::Color& tintColor,
|
681 | 678 | const sf::Color& borderColor) {
|
682 | 679 | const sf::Texture& texture = sprite.getTexture();
|
683 | 680 | const sf::Vector2f textureSize(texture.getSize());
|
684 | 681 | const sf::FloatRect textureRect(sprite.getTextureRect());
|
685 |
| - const ImVec2 uv0(textureRect.left / textureSize.x, textureRect.top / textureSize.y); |
686 |
| - const ImVec2 uv1((textureRect.left + textureRect.width) / textureSize.x, |
687 |
| - (textureRect.top + textureRect.height) / textureSize.y); |
| 682 | + const ImVec2 uv0(textureRect.position.cwiseDiv(textureSize)); |
| 683 | + const ImVec2 uv1((textureRect.position + textureRect.size).cwiseDiv(textureSize)); |
688 | 684 |
|
689 | 685 | ImTextureID textureID = convertGLTextureHandleToImTextureID(texture.getNativeHandle());
|
690 | 686 |
|
@@ -722,9 +718,8 @@ bool ImageButton(const char* id, const sf::Sprite& sprite, const sf::Vector2f& s
|
722 | 718 | const sf::Texture& texture = sprite.getTexture();
|
723 | 719 | const sf::Vector2f textureSize(texture.getSize());
|
724 | 720 | const sf::FloatRect textureRect(sprite.getTextureRect());
|
725 |
| - const ImVec2 uv0(textureRect.left / textureSize.x, textureRect.top / textureSize.y); |
726 |
| - const ImVec2 uv1((textureRect.left + textureRect.width) / textureSize.x, |
727 |
| - (textureRect.top + textureRect.height) / textureSize.y); |
| 721 | + const ImVec2 uv0(textureRect.position.cwiseDiv(textureSize)); |
| 722 | + const ImVec2 uv1((textureRect.position + textureRect.size).cwiseDiv(textureSize)); |
728 | 723 |
|
729 | 724 | ImTextureID textureID = convertGLTextureHandleToImTextureID(texture.getNativeHandle());
|
730 | 725 | return ImGui::ImageButton(id, textureID, ImVec2(size.x, size.y), uv0, uv1, toImColor(bgColor),
|
@@ -764,12 +759,10 @@ ImColor toImColor(sf::Color c) {
|
764 | 759 | static_cast<int>(c.a)};
|
765 | 760 | }
|
766 | 761 | ImVec2 getTopLeftAbsolute(const sf::FloatRect& rect) {
|
767 |
| - const ImVec2 pos = ImGui::GetCursorScreenPos(); |
768 |
| - return {rect.left + pos.x, rect.top + pos.y}; |
| 762 | + return sf::Vector2f(ImGui::GetCursorScreenPos()) + rect.position; |
769 | 763 | }
|
770 | 764 | ImVec2 getDownRightAbsolute(const sf::FloatRect& rect) {
|
771 |
| - const ImVec2 pos = ImGui::GetCursorScreenPos(); |
772 |
| - return {rect.left + rect.width + pos.x, rect.top + rect.height + pos.y}; |
| 765 | + return sf::Vector2f(ImGui::GetCursorScreenPos()) + rect.position + rect.size; |
773 | 766 | }
|
774 | 767 |
|
775 | 768 | ImTextureID convertGLTextureHandleToImTextureID(GLuint glTextureHandle) {
|
|
0 commit comments