aboutsummaryrefslogtreecommitdiff
path: root/src/Tabs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tabs.cpp')
-rw-r--r--src/Tabs.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/Tabs.cpp b/src/Tabs.cpp
index 3745973..8965a85 100644
--- a/src/Tabs.cpp
+++ b/src/Tabs.cpp
@@ -5,7 +5,6 @@
#include "../include/Theme.hpp"
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
-#include <SFML/OpenGL.hpp>
#include <cmath>
namespace QuickMedia {
@@ -83,6 +82,14 @@ namespace QuickMedia {
}
}
+ static sf::View create_scissor_view(sf::Vector2f pos, sf::Vector2f size, const sf::Vector2f window_size) {
+ sf::View view(sf::FloatRect(0.0f, 0.0f, size.x, size.y));
+ view.setViewport(sf::FloatRect(
+ pos.x / (float)window_size.x, pos.y / (float)window_size.y,
+ size.x / (float)window_size.x, size.y / (float)window_size.y));
+ return view;
+ }
+
void Tabs::draw(sf::RenderWindow &window, sf::Vector2f pos, float width) {
if(width - tab_margin_x < 0.0f || tabs.empty()) return;
@@ -118,6 +125,8 @@ namespace QuickMedia {
bool tabs_cutoff_right = false;
const auto start_pos = pos;
+ const sf::View prev_view = window.getView();
+
pos.x += scroll_fixed;
for(size_t i = 0; i < tabs.size(); ++i) {
const int index = i;
@@ -138,11 +147,10 @@ namespace QuickMedia {
sf::Text &tab_text = tabs[index].text;
float text_pos_x = std::floor(pos.x + i*width_per_tab + width_per_tab*0.5f - tab_text.getLocalBounds().width*0.5f);
text_pos_x = std::max(text_pos_x, background_pos_x);
- tab_text.setPosition(text_pos_x, tab_text_y);
- glEnable(GL_SCISSOR_TEST);
- glScissor(text_pos_x, (int)window_size.y - (int)tab_text_y - (int)tab_height, tab_background_width, tab_height);
+
+ window.setView(create_scissor_view({ text_pos_x, tab_text_y }, { tab_background_width, tab_height }, { (float)window_size.x, (float)window_size.y }));
window.draw(tab_text);
- glDisable(GL_SCISSOR_TEST);
+ window.setView(prev_view);
}
float lw = std::floor(25.0f * get_config().scale);