aboutsummaryrefslogtreecommitdiff
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
parentaab52eb9561966977dc158abdc99bb599ea1e989 (diff)
Change font, change text spacing
-rw-r--r--fonts/Nunito License.txt93
-rw-r--r--fonts/Nunito-Regular.ttfbin0 -> 113832 bytes
-rw-r--r--include/Text.hpp2
-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
13 files changed, 132 insertions, 23 deletions
diff --git a/fonts/Nunito License.txt b/fonts/Nunito License.txt
new file mode 100644
index 0000000..2b5a16a
--- /dev/null
+++ b/fonts/Nunito License.txt
@@ -0,0 +1,93 @@
+Copyright 2014 The Nunito Project Authors (contact@sansoxygen.com)
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git a/fonts/Nunito-Regular.ttf b/fonts/Nunito-Regular.ttf
new file mode 100644
index 0000000..93a3f3e
--- /dev/null
+++ b/fonts/Nunito-Regular.ttf
Binary files differ
diff --git a/include/Text.hpp b/include/Text.hpp
index 286a0b1..24ea02a 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -53,6 +53,7 @@ namespace dchat
void setFillColor(sf::Color color);
void setLineSpacing(float lineSpacing);
+ void setCharacterSpacing(float characterSpacing);
void setEditable(bool editable);
// Warning: won't update until @draw is called
@@ -103,6 +104,7 @@ namespace dchat
CaretMoveDirection caretMoveDirection;
sf::FloatRect boundingBox;
float lineSpacing;
+ float characterSpacing;
std::vector<TextElement> textElements;
int caretIndex;
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));