From 7913c19875cd407a1559da66a26906184dcd712b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 31 May 2018 20:00:19 +0200 Subject: Add scrollbar (currently only used in message board) --- include/MessageBoard.hpp | 4 +++- include/Scrollbar.hpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 include/Scrollbar.hpp (limited to 'include') diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp index acdaad4..fdde8c7 100644 --- a/include/MessageBoard.hpp +++ b/include/MessageBoard.hpp @@ -3,6 +3,7 @@ #include "Message.hpp" #include "types.hpp" #include "../include/Cache.hpp" +#include "../include/Scrollbar.hpp" #include #include #include @@ -42,8 +43,8 @@ namespace dchat odhtdb::MapHash messageIdMap; double scroll; double scrollSpeed; - sf::Clock frameTimer; double totalHeight; + sf::Clock frameTimer; bool scrollToBottom; sf::Vector2f backgroundSizeWithoutPadding; sf::Vector2f backgroundSize; @@ -51,5 +52,6 @@ namespace dchat std::mutex messageProcessMutex; usize visibleMessageStartIndex; usize visibleMessageEndIndex; + Scrollbar scrollbar; }; } diff --git a/include/Scrollbar.hpp b/include/Scrollbar.hpp new file mode 100644 index 0000000..7cf625b --- /dev/null +++ b/include/Scrollbar.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include + +namespace dchat +{ + class Scrollbar + { + public: + Scrollbar(); + + void draw(sf::RenderWindow &window); + + float getScrollingForContent() const; + + float width; + double maxHeight; + double scroll; + double maxScroll; + double scrollRelative; + sf::Vector2f position; + + sf::Color backgroundColor; + sf::Color scrollColor; + private: + float height; + bool grabbing; + bool followMouse; + sf::Vector2f grabOffset; + }; +} -- cgit v1.2.3