aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/odhtdb0
-rw-r--r--include/ResourceCache.hpp2
-rw-r--r--include/Text.hpp6
-rw-r--r--src/ChannelSidePanel.cpp6
-rw-r--r--src/Chatbar.cpp2
-rw-r--r--src/MessageBoard.cpp8
-rw-r--r--src/ResourceCache.cpp6
-rw-r--r--src/Text.cpp16
-rw-r--r--src/UsersSidePanel.cpp6
-rw-r--r--src/main.cpp1
10 files changed, 27 insertions, 26 deletions
diff --git a/depends/odhtdb b/depends/odhtdb
-Subproject 97fd90f4c3319e3e789416155c1a462ab179875
+Subproject 92e22dd7f1f918ef92a31f5526bac263ef409f1
diff --git a/include/ResourceCache.hpp b/include/ResourceCache.hpp
index 7361862..de35500 100644
--- a/include/ResourceCache.hpp
+++ b/include/ResourceCache.hpp
@@ -17,7 +17,7 @@ namespace dchat
{
public:
// Throws FailedToLoadResourceException on failure
- static const sf::Font& getFont(const std::string &filepath);
+ static const sf::Font* getFont(const std::string &filepath);
// Throws FailedToLoadResourceException on failure
static sf::Texture* getTexture(const std::string &filepath);
diff --git a/include/Text.hpp b/include/Text.hpp
index 93ec0c1..4bb5ec0 100644
--- a/include/Text.hpp
+++ b/include/Text.hpp
@@ -13,8 +13,8 @@ namespace dchat
class Text
{
public:
- Text(const sf::Font &font);
- Text(const sf::String &str, const sf::Font &font, unsigned int characterSize, float maxWidth, bool plainText = true);
+ Text(const sf::Font *font);
+ Text(const sf::String &str, const sf::Font *font, unsigned int characterSize, float maxWidth, bool plainText = true);
void setString(const sf::String &str);
void appendStringNewLine(const sf::String &str);
@@ -52,7 +52,7 @@ namespace dchat
};
sf::String str;
- sf::Font font;
+ const sf::Font *font;
unsigned int characterSize;
sf::VertexArray vertices;
float maxWidth;
diff --git a/src/ChannelSidePanel.cpp b/src/ChannelSidePanel.cpp
index eb5c74c..f5a4063 100644
--- a/src/ChannelSidePanel.cpp
+++ b/src/ChannelSidePanel.cpp
@@ -32,17 +32,17 @@ namespace dchat
rect.setFillColor(sf::Color(30, 30, 30));
window.draw(rect);
- const sf::Font &font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ 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());
+ sf::Text text(str, *font, FONT_SIZE * Settings::getScaling());
text.setPosition(position);
window.draw(text);
- position.y += font.getLineSpacing(FONT_SIZE * Settings::getScaling());
+ position.y += font->getLineSpacing(FONT_SIZE * Settings::getScaling());
}
}
diff --git a/src/Chatbar.cpp b/src/Chatbar.cpp
index 241a808..8c4083b 100644
--- a/src/Chatbar.cpp
+++ b/src/Chatbar.cpp
@@ -21,7 +21,7 @@ namespace dchat
const float PADDING_SIDE = 20.0f;
Chatbar::Chatbar() :
- text("", ResourceCache::getFont("fonts/Roboto-Regular.ttf"), FONT_SIZE * Settings::getScaling()),
+ text("", *ResourceCache::getFont("fonts/Roboto-Regular.ttf"), FONT_SIZE * Settings::getScaling()),
caretIndex(0),
focused(true)
{
diff --git a/src/MessageBoard.cpp b/src/MessageBoard.cpp
index a0d1ab2..a0f1e20 100644
--- a/src/MessageBoard.cpp
+++ b/src/MessageBoard.cpp
@@ -40,8 +40,8 @@ namespace dchat
void MessageBoard::updateStaticContentTexture(const sf::Vector2u &newSize)
{
- if(!staticContentTexture.create(newSize.x, newSize.y))
- throw std::runtime_error("Failed to create render target for message board!");
+ //if(!staticContentTexture.create(newSize.x, newSize.y))
+ // throw std::runtime_error("Failed to create render target for message board!");
dirty = true;
}
@@ -110,7 +110,7 @@ namespace dchat
//if(dirty)
// staticContentTexture.clear(BACKGROUND_COLOR);
- const sf::Font &usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *usernameFont = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
double deltaTimeMicro = (double)frameTimer.getElapsedTime().asMicroseconds();
frameTimer.restart();
@@ -125,7 +125,7 @@ namespace dchat
position.y += scroll;
for(Message *message : messages)
{
- sf::Text usernameText(message->user->getName(), usernameFont, 24 * Settings::getScaling());
+ sf::Text usernameText(message->user->getName(), *usernameFont, 24 * Settings::getScaling());
float usernameTextHeight = usernameText.getFont()->getLineSpacing(usernameText.getCharacterSize());
if(position.y + usernameTextHeight > 0.0f && position.y < backgroundSize.y)
{
diff --git a/src/ResourceCache.cpp b/src/ResourceCache.cpp
index ab583bb..3f73189 100644
--- a/src/ResourceCache.cpp
+++ b/src/ResourceCache.cpp
@@ -8,11 +8,11 @@ namespace dchat
unordered_map<string, sf::Font*> fonts;
unordered_map<string, sf::Texture*> textures;
- const sf::Font& ResourceCache::getFont(const string &filepath)
+ const sf::Font* ResourceCache::getFont(const string &filepath)
{
auto it = fonts.find(filepath);
if(it != fonts.end())
- return *it->second;
+ return it->second;
sf::Font *font = new sf::Font();
if(!font->loadFromFile(filepath))
@@ -24,7 +24,7 @@ namespace dchat
}
fonts[filepath] = font;
- return *font;
+ return font;
}
sf::Texture* ResourceCache::getTexture(const string &filepath)
diff --git a/src/Text.cpp b/src/Text.cpp
index fa46277..c8da55c 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -11,7 +11,7 @@ namespace dchat
const float EMOJI_SCALE_WITH_TEXT = 1.0f;
const float EMOJI_SCALE_STANDALONE = 5.0f;
- Text::Text(const sf::Font &_font) :
+ Text::Text(const sf::Font *_font) :
font(_font),
characterSize(0),
maxWidth(0.0f),
@@ -23,7 +23,7 @@ namespace dchat
}
- Text::Text(const sf::String &_str, const sf::Font &_font, unsigned int _characterSize, float _maxWidth, bool _plainText) :
+ Text::Text(const sf::String &_str, const sf::Font *_font, unsigned int _characterSize, float _maxWidth, bool _plainText) :
font(_font),
characterSize(_characterSize),
vertices(sf::PrimitiveType::Quads),
@@ -150,8 +150,8 @@ namespace dchat
void Text::updateGeometry()
{
vertices.clear();
- float hspace = font.getGlyph(' ', characterSize, false).advance;
- float vspace = font.getLineSpacing(characterSize);
+ float hspace = font->getGlyph(' ', characterSize, false).advance;
+ float vspace = font->getLineSpacing(characterSize);
sf::Vector2f glyphPos;
sf::Uint32 prevCodePoint = 0;
@@ -215,7 +215,7 @@ namespace dchat
for(size_t i = 0; i < textElement.text.size; ++i)
{
sf::Uint32 codePoint = textElement.text[i];
- float kerning = font.getKerning(prevCodePoint, codePoint, characterSize);
+ float kerning = font->getKerning(prevCodePoint, codePoint, characterSize);
prevCodePoint = codePoint;
glyphPos.x += kerning;
@@ -254,7 +254,7 @@ namespace dchat
}
}
- const sf::Glyph &glyph = font.getGlyph(codePoint, characterSize, false);
+ const sf::Glyph &glyph = font->getGlyph(codePoint, characterSize, false);
if(glyphPos.x + glyph.advance > maxWidth)
{
// If there was a space in the text and text width is too long, then we need to word wrap at space index instead,
@@ -311,7 +311,7 @@ namespace dchat
dirty = false;
}
- float vspace = font.getLineSpacing(characterSize);
+ float vspace = font->getLineSpacing(characterSize);
sf::RenderStates states;
sf::Vector2f pos = position;
@@ -325,7 +325,7 @@ namespace dchat
if(pos.y + totalHeight <= 0.0f || pos.y >= target.getSize().y) return;
states.transform.translate(pos);
- states.texture = &font.getTexture(characterSize);
+ states.texture = &font->getTexture(characterSize);
target.draw(vertices, states);
for(TextElement &textElement : textElements)
diff --git a/src/UsersSidePanel.cpp b/src/UsersSidePanel.cpp
index 39c0b86..766539b 100644
--- a/src/UsersSidePanel.cpp
+++ b/src/UsersSidePanel.cpp
@@ -35,16 +35,16 @@ namespace dchat
if(!currentChannel) return;
- const sf::Font &font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
+ const sf::Font *font = ResourceCache::getFont("fonts/Roboto-Regular.ttf");
sf::Vector2f position(rect.getPosition().x + 10.0f, 10.0f);
for(User *user : currentChannel->getUsers())
{
// TODO: Remove this shit
sf::String str = sf::String::fromUtf8(user->getName().begin(), user->getName().end());
- sf::Text text(str, font, FONT_SIZE * Settings::getScaling());
+ sf::Text text(str, *font, FONT_SIZE * Settings::getScaling());
text.setPosition(position);
window.draw(text);
- position.y += font.getLineSpacing(FONT_SIZE * Settings::getScaling());
+ position.y += font->getLineSpacing(FONT_SIZE * Settings::getScaling());
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 6f54820..61319fa 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -249,6 +249,7 @@ int main(int argc, char **argv)
odhtdb::DatabaseNode databaseNode = createDatabaseNodeFromJoinKey(args[0]);
database.seed(databaseNode);
+ // TODO: Continue this...
});
sf::Event event;