diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-29 09:31:06 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-29 09:31:10 +0200 |
commit | e7caed2208893723181892d5e197b924311373fb (patch) | |
tree | 1a92cd65f23537eb57b4d80646e84bd359bc0ee2 /src | |
parent | f90a5705bd65a4ebb5edc9df003a383039fec555 (diff) |
Improve scaling, start implementing color scheme
Diffstat (limited to 'src')
-rw-r--r-- | src/ChannelSidePanel.cpp | 11 | ||||
-rw-r--r-- | src/ChannelTopPanel.cpp | 30 | ||||
-rw-r--r-- | src/Chatbar.cpp | 30 | ||||
-rw-r--r-- | src/Message.cpp | 3 | ||||
-rw-r--r-- | src/MessageBoard.cpp | 15 | ||||
-rw-r--r-- | src/UsersSidePanel.cpp | 9 | ||||
-rw-r--r-- | src/main.cpp | 7 |
7 files changed, 53 insertions, 52 deletions
diff --git a/src/ChannelSidePanel.cpp b/src/ChannelSidePanel.cpp index 18b581c..cbda247 100644 --- a/src/ChannelSidePanel.cpp +++ b/src/ChannelSidePanel.cpp @@ -3,6 +3,7 @@ #include "../include/ResourceCache.hpp" #include "../include/Settings.hpp" #include "../include/Channel.hpp" +#include "../include/ColorScheme.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Text.hpp> #include <vector> @@ -32,9 +33,9 @@ namespace dchat { float posY = ChannelTopPanel::getHeight(); auto windowSize = window.getSize(); - sf::RectangleShape rect(sf::Vector2f(WIDTH, windowSize.y)); + sf::RectangleShape rect(sf::Vector2f(getWidth(), windowSize.y)); rect.setPosition(0.0f, posY); - rect.setFillColor(sf::Color(35, 35, 35)); + rect.setFillColor(ColorScheme::getPanelColor()); window.draw(rect); //posY += 10.0f; @@ -48,8 +49,8 @@ namespace dchat { if(channel == Channel::getCurrent()) { - rect.setFillColor(sf::Color(50, 50, 50)); - rect.setSize(sf::Vector2f(WIDTH, channelBoxHeight)); + rect.setFillColor(ColorScheme::getPanelColor() + sf::Color(15, 15, 15)); + rect.setSize(sf::Vector2f(getWidth(), channelBoxHeight)); rect.setPosition(sf::Vector2f(0.0f, position.y)); window.draw(rect); } @@ -66,6 +67,6 @@ namespace dchat float ChannelSidePanel::getWidth() { - return WIDTH; + return WIDTH * Settings::getScaling(); } } diff --git a/src/ChannelTopPanel.cpp b/src/ChannelTopPanel.cpp index 534f989..9f57d27 100644 --- a/src/ChannelTopPanel.cpp +++ b/src/ChannelTopPanel.cpp @@ -2,6 +2,7 @@ #include "../include/Settings.hpp" #include "../include/ResourceCache.hpp" #include "../include/Channel.hpp" +#include "../include/ColorScheme.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <cmath> @@ -37,21 +38,14 @@ namespace dchat void ChannelTopPanel::draw(sf::RenderWindow &window) { - const sf::Color backgroundColor(40, 40, 40); - const sf::Color lineSideColor(40, 40, 40); - const sf::Color lineCenterColor(80, 40, 40); + const sf::Color lineSideColor = ColorScheme::getBackgroundColor(); + const sf::Color lineCenterColor = lineSideColor + sf::Color(40, 0, 0); auto windowSize = window.getSize(); sf::RectangleShape rect(sf::Vector2f(windowSize.x, getHeight() - BOTTOM_LINE_HEIGHT)); - rect.setFillColor(backgroundColor); + rect.setFillColor(ColorScheme::getBackgroundColor()); window.draw(rect); - /* - rect.setFillColor(sf::Color(70, 40, 40)); - rect.setSize(sf::Vector2f(windowSize.x, BOTTOM_LINE_HEIGHT)); - rect.setPosition(0.0f, getHeight() - BOTTOM_LINE_HEIGHT); - window.draw(rect); - */ sf::Vector2f bottomLinePos(0.0f, getHeight() - BOTTOM_LINE_HEIGHT); sf::Vector2f bottomLineSize(windowSize.x, BOTTOM_LINE_HEIGHT); @@ -71,22 +65,8 @@ namespace dchat sf::Text text(str, *FONT, fontSize); auto textBounds = text.getLocalBounds(); text.setPosition(floor((float)windowSize.x * 0.5f - textBounds.width * 0.5f), PADDING_TOP); - text.setFillColor(sf::Color(240, 240, 240)); + text.setFillColor(ColorScheme::getTextRegularColor()); window.draw(text); - /* - const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf"); - sf::Vector2f position(10.0f, 10.0f); - for(Channel *channel : channels) - { - // TODO: Remove this shit - sf::String str = "# "; - str += sf::String::fromUtf8(channel->getName().begin(), channel->getName().end()); - sf::Text text(str, *font, FONT_SIZE * Settings::getScaling()); - text.setPosition(position); - window.draw(text); - position.y += font->getLineSpacing(FONT_SIZE * Settings::getScaling()); - } - */ } float ChannelTopPanel::getHeight() diff --git a/src/Chatbar.cpp b/src/Chatbar.cpp index 8c4083b..e88986a 100644 --- a/src/Chatbar.cpp +++ b/src/Chatbar.cpp @@ -5,6 +5,7 @@ #include "../include/ChannelSidePanel.hpp" #include "../include/UsersSidePanel.hpp" #include "../include/Command.hpp" +#include "../include/ColorScheme.hpp" #include <cmath> #include <cstring> #include <process.hpp> @@ -13,12 +14,14 @@ using namespace std; namespace dchat { - const float FONT_SIZE = 24; + const float FONT_SIZE = 20; const float BOX_PADDING_X = 15.0f; const float BOX_PADDING_Y = 5.0f; const int BLINK_TIME_VISIBLE_MS = 500; const int BLINK_TIME_INVISIBLE_MS = 500; const float PADDING_SIDE = 20.0f; + const float PADDING_TOP = 30.0f; + const float PADDING_BOTTOM = 30.0f; Chatbar::Chatbar() : text("", *ResourceCache::getFont("fonts/Roboto-Regular.ttf"), FONT_SIZE * Settings::getScaling()), @@ -26,7 +29,8 @@ namespace dchat focused(true) { text.setFillColor(sf::Color(240, 240, 240)); - background.setFillColor(sf::Color(60, 60, 60)); + background.setFillColor(ColorScheme::getBackgroundColor()); + inputBackground.setFillColor(ColorScheme::getBackgroundColor() + sf::Color(10, 10, 10)); } void Chatbar::addChar(sf::Uint32 codePoint) @@ -268,20 +272,28 @@ namespace dchat { auto windowSize = window.getSize(); - sf::Vector2f backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(text.getCharacterSize() * 1.7f + BOX_PADDING_Y * 2.0f)); - sf::Vector2f backgroundPos(floor(ChannelSidePanel::getWidth() + PADDING_SIDE), floor(windowSize.y - backgroundSize.y - 20.0f)); - background.setSize(backgroundSize); - background.setPosition(backgroundPos); - text.setPosition(floor(backgroundPos.x + BOX_PADDING_X), floor(backgroundPos.y + backgroundSize.y * 0.5f - text.getCharacterSize() * 0.5f)); + text.setCharacterSize(FONT_SIZE * Settings::getScaling()); + const float fontHeight = text.getFont()->getLineSpacing(text.getCharacterSize()); + sf::Vector2f inputBackgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(fontHeight * 1.7f + BOX_PADDING_Y * 2.0f)); + sf::Vector2f backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()), floor(PADDING_TOP + inputBackgroundSize.y + PADDING_BOTTOM)); + background.setSize(backgroundSize); + background.setPosition(ChannelSidePanel::getWidth(), floor(windowSize.y - backgroundSize.y)); window.draw(background); + + sf::Vector2f inputBackgroundPos(floor(ChannelSidePanel::getWidth() + PADDING_SIDE), floor(windowSize.y - inputBackgroundSize.y - PADDING_BOTTOM)); + inputBackground.setSize(inputBackgroundSize); + inputBackground.setPosition(inputBackgroundPos); + text.setPosition(floor(inputBackgroundPos.x + BOX_PADDING_X), floor(inputBackgroundPos.y + inputBackgroundSize.y * 0.5f - fontHeight * 0.5f)); + + window.draw(inputBackground); window.draw(text); int blinkElapsedTime = blinkTimer.getElapsedTime().asMilliseconds(); if(focused && blinkElapsedTime <= BLINK_TIME_VISIBLE_MS) { - sf::RectangleShape caretShape(sf::Vector2f(2.0f, backgroundSize.y - BOX_PADDING_Y * 2.0f)); - caretShape.setPosition(floor(text.getPosition().x + caretOffset.x), (caretOffset.y + backgroundPos.y + BOX_PADDING_Y)); + sf::RectangleShape caretShape(sf::Vector2f(2.0f, inputBackgroundSize.y - BOX_PADDING_Y * 2.0f)); + caretShape.setPosition(floor(text.getPosition().x + caretOffset.x), floor(caretOffset.y + inputBackgroundPos.y + BOX_PADDING_Y)); window.draw(caretShape); } diff --git a/src/Message.cpp b/src/Message.cpp index 2d7cb86..5cd8445 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,6 +1,7 @@ #include "../include/Message.hpp" #include "../include/ResourceCache.hpp" #include "../include/Settings.hpp" +#include "../include/ColorScheme.hpp" using namespace std; @@ -10,6 +11,6 @@ namespace dchat user(_user), text(sf::String::fromUtf8(_text.begin(), _text.end()), ResourceCache::getFont("fonts/Roboto-Regular.ttf"), 18 * Settings::getScaling(), 0.0f, false) { - + text.setFillColor(ColorScheme::getTextRegularColor()); } } diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp index 58d54f2..fbc7484 100644 --- a/src/MessageBoard.cpp +++ b/src/MessageBoard.cpp @@ -5,6 +5,7 @@ #include "../include/ChannelSidePanel.hpp" #include "../include/UsersSidePanel.hpp" #include "../include/ChannelTopPanel.hpp" +#include "../include/ColorScheme.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Sprite.hpp> #include <SFML/Window/Mouse.hpp> @@ -21,7 +22,6 @@ namespace dchat sf::Color sideColor, centerColor; }; - const sf::Color BACKGROUND_COLOR(40, 40, 40); const float USERNAME_PADDING_BOTTOM = 0.0f; const float MESSAGE_PADDING_TOP = 25.0f; const float MESSAGE_PADDING_BOTTOM = 30.0f; @@ -33,8 +33,8 @@ namespace dchat const LineColor LINE_COLOR { - .sideColor = sf::Color(50, 50, 50), - .centerColor = sf::Color(50, 50, 50) + .sideColor = ColorScheme::getBackgroundColor() + sf::Color(10, 10, 10), + .centerColor = ColorScheme::getBackgroundColor() + sf::Color(10, 10, 10) }; static void drawGradientLine(const sf::Vector2f &position, const sf::Vector2f &size, const LineColor &color, sf::RenderWindow &window) @@ -133,7 +133,7 @@ namespace dchat void MessageBoard::draw(sf::RenderWindow &window, Cache &cache) { auto windowSize = window.getSize(); - const float backgroundWidthWithoutPadding = floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()); + sf::Vector2f backgroundSizeWithoutPadding(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth()), floor(windowSize.y - ChannelTopPanel::getHeight())); sf::Vector2u backgroundSize(floor(windowSize.x - ChannelSidePanel::getWidth() - UsersSidePanel::getWidth() - PADDING_SIDE * 2.0f), floor(windowSize.y)); //if(backgroundSize != staticContentTexture.getSize()) @@ -144,6 +144,11 @@ namespace dchat //if(dirty) // staticContentTexture.clear(BACKGROUND_COLOR); + sf::RectangleShape backgroundRect(backgroundSizeWithoutPadding); + backgroundRect.setFillColor(ColorScheme::getBackgroundColor()); + backgroundRect.setPosition(ChannelSidePanel::getWidth(), ChannelTopPanel::getHeight()); + window.draw(backgroundRect); + const sf::Font *usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf"); double deltaTimeMicro = (double)frameTimer.getElapsedTime().asMicroseconds(); @@ -177,7 +182,7 @@ namespace dchat position.y += message->text.getHeight() + MESSAGE_PADDING_BOTTOM; if(position.y + LINE_HEIGHT > 0.0f && position.y < backgroundSize.y) - drawGradientLine(sf::Vector2f(position.x + LINE_SIDE_PADDING, floor(position.y)), sf::Vector2f(backgroundWidthWithoutPadding - LINE_SIDE_PADDING * 2.0f, LINE_HEIGHT), LINE_COLOR, window); + drawGradientLine(sf::Vector2f(position.x + LINE_SIDE_PADDING, floor(position.y)), sf::Vector2f(backgroundSizeWithoutPadding.x - LINE_SIDE_PADDING * 2.0f, LINE_HEIGHT), LINE_COLOR, window); } } diff --git a/src/UsersSidePanel.cpp b/src/UsersSidePanel.cpp index 74b58cf..bea6296 100644 --- a/src/UsersSidePanel.cpp +++ b/src/UsersSidePanel.cpp @@ -3,6 +3,7 @@ #include "../include/ResourceCache.hpp" #include "../include/Settings.hpp" #include "../include/Channel.hpp" +#include "../include/ColorScheme.hpp" #include <SFML/Graphics/RectangleShape.hpp> #include <SFML/Graphics/Text.hpp> #include <vector> @@ -19,9 +20,9 @@ namespace dchat { float posY = ChannelTopPanel::getHeight(); auto windowSize = window.getSize(); - sf::RectangleShape rect(sf::Vector2f(WIDTH, windowSize.y)); - rect.setFillColor(sf::Color(35, 35, 35)); - rect.setPosition(windowSize.x - WIDTH, posY); + sf::RectangleShape rect(sf::Vector2f(getWidth(), windowSize.y)); + rect.setFillColor(ColorScheme::getPanelColor()); + rect.setPosition(windowSize.x - getWidth(), posY); window.draw(rect); posY += 10.0f; @@ -43,6 +44,6 @@ namespace dchat float UsersSidePanel::getWidth() { - return WIDTH; + return WIDTH * Settings::getScaling(); } } diff --git a/src/main.cpp b/src/main.cpp index 580b362..dff2328 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include "../include/Video.hpp" #include "../include/Command.hpp" #include "../include/Settings.hpp" +#include "../include/ColorScheme.hpp" #include <string> #include <SFML/Graphics.hpp> #include <cstring> @@ -280,11 +281,11 @@ int main(int argc, char **argv) #endif }); - Command::add("scaling", [](const vector<string> &args) + Command::add("scale", [](const vector<string> &args) { if(args.size() != 1) { - fprintf(stderr, "Expected 1 argument for command scaling, got %u argument(s)\n", args.size()); + fprintf(stderr, "Expected 1 argument for command scale, got %u argument(s)\n", args.size()); return; } @@ -316,7 +317,7 @@ int main(int argc, char **argv) Channel::getCurrent()->processEvent(event); } - window.clear(sf::Color(40, 40, 40)); + window.clear(ColorScheme::getBackgroundColor()); ChannelSidePanel::draw(window); Channel::getCurrent()->draw(window, cache); UsersSidePanel::draw(window); |