aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-30 09:19:31 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-30 09:19:34 +0200
commit4aecbda252b71eff9480d73fd8ec5100819da63b (patch)
tree16f2c7feab0d7a626dce7470c7ca45adcecbe171 /src
parentaab52eb9561966977dc158abdc99bb599ea1e989 (diff)
Change font, change text spacing
Diffstat (limited to 'src')
-rw-r--r--src/ChannelSidePanel.cpp2
-rw-r--r--src/ChannelTopPanel.cpp4
-rw-r--r--src/Chatbar.cpp4
-rw-r--r--src/ContextMenu.cpp2
-rw-r--r--src/Message.cpp2
-rw-r--r--src/MessageBoard.cpp20
-rw-r--r--src/Text.cpp18
-rw-r--r--src/UsersSidePanel.cpp2
-rw-r--r--src/WebPagePreview.cpp4
-rw-r--r--src/main.cpp2
10 files changed, 37 insertions, 23 deletions
diff --git a/src/ChannelSidePanel.cpp b/src/ChannelSidePanel.cpp
index 3e01e94..524e504 100644
--- a/src/ChannelSidePanel.cpp
+++ b/src/ChannelSidePanel.cpp
@@ -38,7 +38,7 @@ namespace dchat
rect.setFillColor(ColorScheme::getPanelColor());
window.draw(rect);
- const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *font = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const float fontSize = FONT_SIZE * Settings::getScaling();
const float fontHeight = font->getLineSpacing(fontSize);
const float channelBoxHeight = floor(fontHeight * CHANNEL_NAME_BOX_HEIGHT_RATIO);
diff --git a/src/ChannelTopPanel.cpp b/src/ChannelTopPanel.cpp
index 44ce007..541d333 100644
--- a/src/ChannelTopPanel.cpp
+++ b/src/ChannelTopPanel.cpp
@@ -66,7 +66,7 @@ namespace dchat
sf::String str = "# ";
str += sf::String::fromUtf8(currentChannel->getName().begin(), currentChannel->getName().end());
float fontSize = FONT_SIZE * Settings::getScaling();
- sf::Text text(str, *ResourceCache::getFont("fonts/Roboto-Regular.ttf"), fontSize);
+ sf::Text text(str, *ResourceCache::getFont("fonts/Nunito-Regular.ttf"), fontSize);
auto textBounds = text.getLocalBounds();
text.setPosition(floor(ChannelSidePanel::getWidth() + PADDING_SIDE * Settings::getScaling()), PADDING_TOP);
text.setFillColor(ColorScheme::getTextRegularColor());
@@ -76,6 +76,6 @@ namespace dchat
float ChannelTopPanel::getHeight()
{
float fontSize = FONT_SIZE * Settings::getScaling();
- return floor(ResourceCache::getFont("fonts/Roboto-Regular.ttf")->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM + BOTTOM_LINE_HEIGHT);
+ return floor(ResourceCache::getFont("fonts/Nunito-Regular.ttf")->getLineSpacing(fontSize) + PADDING_TOP + PADDING_BOTTOM + BOTTOM_LINE_HEIGHT);
}
}
diff --git a/src/Chatbar.cpp b/src/Chatbar.cpp
index aab13a0..bb06308 100644
--- a/src/Chatbar.cpp
+++ b/src/Chatbar.cpp
@@ -29,7 +29,7 @@ namespace dchat
unordered_map<string, string> binds;
Chatbar::Chatbar() :
- text("", ResourceCache::getFont("fonts/Roboto-Regular.ttf"), FONT_SIZE * Settings::getScaling(), 0),
+ text("", ResourceCache::getFont("fonts/Nunito-Regular.ttf"), FONT_SIZE * Settings::getScaling(), 0),
focused(true)
{
text.setEditable(true);
@@ -221,7 +221,7 @@ namespace dchat
float Chatbar::getHeight()
{
const float fontSize = FONT_SIZE * Settings::getScaling();
- const float fontHeight = ResourceCache::getFont("fonts/Roboto-Regular.ttf")->getLineSpacing(fontSize);
+ const float fontHeight = ResourceCache::getFont("fonts/Nunito-Regular.ttf")->getLineSpacing(fontSize);
return PADDING_TOP * Settings::getScaling() + floor(fontHeight * 1.7f + BOX_PADDING_Y * Settings::getScaling() * 2.0f) + PADDING_BOTTOM * Settings::getScaling();
}
diff --git a/src/ContextMenu.cpp b/src/ContextMenu.cpp
index da4b8dd..2f922c7 100644
--- a/src/ContextMenu.cpp
+++ b/src/ContextMenu.cpp
@@ -11,7 +11,7 @@ namespace dchat
{
const float PADDING_SIDE = 10.0f;
const float MENU_ITEM_FONT_SIZE = 18.0f;
- const std::string MENU_FONT_PATH = "fonts/Roboto-Regular.ttf";
+ const std::string MENU_FONT_PATH = "fonts/Nunito-Regular.ttf";
ContextMenuItem::ContextMenuItem(const std::string & _text, MenuItemClickCallbackFunc _clickCallbackFunc) :
text(sf::String::fromUtf8(_text.begin(), _text.end()), *ResourceCache::getFont(MENU_FONT_PATH), MENU_ITEM_FONT_SIZE * Settings::getScaling()),
diff --git a/src/Message.cpp b/src/Message.cpp
index 1b42626..ca50821 100644
--- a/src/Message.cpp
+++ b/src/Message.cpp
@@ -9,7 +9,7 @@ namespace dchat
{
Message::Message(User *_user, const std::string &_text, u64 _timestampSeconds, bool plainText) :
user(_user),
- text(sf::String::fromUtf8(_text.begin(), _text.end()), ResourceCache::getFont("fonts/Roboto-Regular.ttf"), 18 * Settings::getScaling(), 0.0f, plainText),
+ text(sf::String::fromUtf8(_text.begin(), _text.end()), ResourceCache::getFont("fonts/Nunito-Regular.ttf"), 18 * Settings::getScaling(), 0.0f, plainText),
timestampSeconds(_timestampSeconds),
type(Type::REGULAR)
{
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index 0152cb5..3e6532c 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -27,12 +27,13 @@ namespace dchat
sf::Color sideColor, centerColor;
};
- const float USERNAME_PADDING_BOTTOM = 5.0f;
+ const float USERNAME_PADDING_BOTTOM = 0.0f;
const float PADDING_SIDE = 40.0f;
const float PADDING_TOP = 0.0f;
const float LINE_SIDE_PADDING = 20.0f;
const float LINE_HEIGHT = 1.0f;
+ const float TEXT_LINE_SPACING = 5.0f;
const float USERNAME_TIMESTAMP_SIDE_PADDING = 15.0f;
const float AVATAR_DIAMETER = 70.0f;
const float AVATAR_PADDING_SIDE = 30.0f;
@@ -82,11 +83,13 @@ namespace dchat
void MessageBoard::addMessage(Message *message, const odhtdb::Hash &id)
{
lock_guard<mutex> lock(messageProcessMutex);
- messages.insert(messages.begin() + findPositionToInsertMessageByTimestamp(message), message);
+ auto positionToAddMessage = findPositionToInsertMessageByTimestamp(message);
+ if(positionToAddMessage == messages.size())
+ scrollToBottom = true;
+ messages.insert(messages.begin() + positionToAddMessage, message);
message->id = id;
messageIdMap[id] = message;
dirty = true;
- scrollToBottom = true;
}
void MessageBoard::deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser)
@@ -124,11 +127,11 @@ namespace dchat
const float MESSAGE_PADDING_TOP = 25.0f;
const float MESSAGE_PADDING_BOTTOM = 30.0f;
- const sf::Font *usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *usernameFont = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const int usernameTextCharacterSize = 20 * Settings::getScaling();
const float usernameTextHeight = usernameFont->getLineSpacing(usernameTextCharacterSize);
- const sf::Font *timestampFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *timestampFont = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const int timestampTextCharacterSize = (float)usernameTextCharacterSize * 0.75f;
const float timestampTextHeight = timestampFont->getLineSpacing(timestampTextCharacterSize);
@@ -228,11 +231,10 @@ namespace dchat
message->text.setCharacterSize(18.0f * Settings::getScaling());
message->text.setMaxWidth(backgroundSize.x - (AVATAR_DIAMETER + AVATAR_PADDING_SIDE) * Settings::getScaling());
message->text.setPosition(sf::Vector2f(floor(position.x + (AVATAR_DIAMETER + AVATAR_PADDING_SIDE) * Settings::getScaling()), floor(position.y)));
- message->text.setLineSpacing(LINE_SPACING);
bool textDrawn = message->text.draw(window, cache);
if(!visible)
visible = textDrawn;
- position.y += message->text.getHeight();
+ position.y += message->text.getHeight() + (TEXT_LINE_SPACING * Settings::getScaling());
if(!mergeTextWithNext)
{
position.y += (MESSAGE_PADDING_BOTTOM * Settings::getScaling());
@@ -263,12 +265,12 @@ namespace dchat
const float MESSAGE_PADDING_TOP = 0.0f;
const float MESSAGE_PADDING_BOTTOM = 0.0f;
- const sf::Font *usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *usernameFont = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const int usernameTextCharacterSize = 20 * Settings::getScaling();
const float usernameTextHeight = usernameFont->getLineSpacing(usernameTextCharacterSize);
const float usernameMaxWidth = usernameTextHeight * 5.0f;
- const sf::Font *timestampFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *timestampFont = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const int timestampTextCharacterSize = 15 * Settings::getScaling();
const float timestampTextHeight = timestampFont->getLineSpacing(timestampTextCharacterSize);
diff --git a/src/Text.cpp b/src/Text.cpp
index 5c8db41..c8ee731 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -33,6 +33,8 @@ namespace dchat
editable(false),
visible(true),
caretMoveDirection(CaretMoveDirection::NONE),
+ lineSpacing(0.0f),
+ characterSpacing(0.0f),
caretIndex(0)
{
@@ -53,6 +55,7 @@ namespace dchat
visible(true),
caretMoveDirection(CaretMoveDirection::NONE),
lineSpacing(0.0f),
+ characterSpacing(0.0f),
caretIndex(0)
{
setString(_str);
@@ -145,6 +148,15 @@ namespace dchat
}
}
+ void Text::setCharacterSpacing(float characterSpacing)
+ {
+ if(fabs(characterSpacing - this->characterSpacing) > 0.001f)
+ {
+ this->characterSpacing = characterSpacing;
+ dirty = true;
+ }
+ }
+
void Text::setEditable(bool editable)
{
if(editable != this->editable)
@@ -320,7 +332,7 @@ namespace dchat
void Text::updateGeometry()
{
vertices.clear();
- float hspace = font->getGlyph(' ', characterSize, false).advance;
+ float hspace = font->getGlyph(' ', characterSize, false).advance + characterSpacing;
float vspace = font->getLineSpacing(characterSize);
boundingBox = sf::FloatRect();
@@ -371,7 +383,7 @@ namespace dchat
{
textElement.position.y = glyphPos.y + vspace * 0.5f - emojiSize * 0.5f;
}
- glyphPos.x += emojiSize + EMOJI_PADDING;
+ glyphPos.x += emojiSize + EMOJI_PADDING + characterSpacing;
if(glyphPos.x > maxWidth)
{
glyphPos.x = 0.0f;
@@ -489,7 +501,7 @@ namespace dchat
vertices[vertexStart + 2] = { vertexBottomRight, fontColor, textureBottomRight };
vertices[vertexStart + 3] = { vertexBottomLeft, fontColor, textureBottomLeft };
- glyphPos.x += glyph.advance;
+ glyphPos.x += glyph.advance + characterSpacing;
}
vertices[vertices.getVertexCount() - 4] = { sf::Vector2f(glyphPos.x, glyphPos.y - vspace), sf::Color::Transparent, sf::Vector2f() };
diff --git a/src/UsersSidePanel.cpp b/src/UsersSidePanel.cpp
index c05a54f..dcfd1dd 100644
--- a/src/UsersSidePanel.cpp
+++ b/src/UsersSidePanel.cpp
@@ -80,7 +80,7 @@ namespace dchat
Channel *currentChannel = Channel::getCurrent();
if(!currentChannel) return;
- const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *font = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
sf::Vector2f position(rect.getPosition().x + 10.0f, posY);
const float textHeight = font->getLineSpacing(FONT_SIZE * Settings::getScaling());
diff --git a/src/WebPagePreview.cpp b/src/WebPagePreview.cpp
index 3922e73..c7b3e7e 100644
--- a/src/WebPagePreview.cpp
+++ b/src/WebPagePreview.cpp
@@ -4,8 +4,8 @@
namespace dchat
{
WebPagePreview::WebPagePreview(const sf::String &_title, const sf::String &_description) :
- title(_title, ResourceCache::getFont("fonts/Roboto-Regular.ttf"), 10, 0),
- description(_description, ResourceCache::getFont("fonts/Roboto-Regular.ttf"), 10, 0)
+ title(_title, ResourceCache::getFont("fonts/Nunito-Regular.ttf"), 10, 0),
+ description(_description, ResourceCache::getFont("fonts/Nunito-Regular.ttf"), 10, 0)
{
}
diff --git a/src/main.cpp b/src/main.cpp
index f83339f..bc46240 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -934,7 +934,7 @@ int main(int argc, char **argv)
shadeRect.setFillColor(sf::Color(0, 0, 0, 200));
window.draw(shadeRect);
- const sf::Font *FONT = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *FONT = ResourceCache::getFont("fonts/Nunito-Regular.ttf");
const float FONT_SIZE = (double)windowSize.x / 40.0;
sf::Text text("Wait until you are added to the channel", *FONT, FONT_SIZE);
text.setPosition(floor((float)windowSize.x * 0.5f - text.getLocalBounds().width * 0.5f), floor((float)windowSize.y * 0.5f - FONT->getLineSpacing(FONT_SIZE) * 0.5f));