aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-20 04:25:14 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-20 04:25:41 +0200
commitde059e317e43fa1b94d77fd981be68b86bf6de6e (patch)
treeaade82ecfb2dab7441de122d72485a4c71b29be0 /src/main.cpp
parent391f7fd6d832cb40f74fb37f9e0af7ff33db202f (diff)
Add chatbar. No mouse editing but keyboard editing is supported
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 85f1075..481f73a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,7 +1,11 @@
-#include <SFML/Graphics.hpp>
#include "../include/MessageBoard.hpp"
#include "../include/User.hpp"
+#include "../include/Chatbar.hpp"
+#include <string>
+#include <SFML/Graphics.hpp>
+#include <cstring>
+using namespace std;
using namespace dchat;
int main()
@@ -31,6 +35,8 @@ int main()
message->addText(u8"hello, world!");
messageBoard.addMessage(message);
}
+
+ Chatbar chatbar;
while (window.isOpen())
{
@@ -44,11 +50,44 @@ int main()
sf::View view(sf::FloatRect(0.0f, 0.0f, event.size.width, event.size.height));
window.setView(view);
}
+ else if(event.type == sf::Event::TextEntered)
+ {
+ if(event.text.unicode == 8) // backspace
+ chatbar.removePreviousChar();
+ else if(event.text.unicode == 13) // enter
+ {
+ Message *message = new Message(localOfflineUser);
+ auto chatbarMsgUtf8 = chatbar.getString().toUtf8();
+ string msg;
+ msg.resize(chatbarMsgUtf8.size());
+ memcpy(&msg[0], chatbarMsgUtf8.data(), chatbarMsgUtf8.size());
+
+ message->addText(msg);
+ messageBoard.addMessage(message);
+ chatbar.clear();
+ }
+ else if(event.text.unicode == 127) // delete
+ {
+ chatbar.removeNextChar();
+ }
+ else
+ {
+ chatbar.addChar(event.text.unicode);
+ }
+ }
+ else if(event.type == sf::Event::KeyPressed)
+ {
+ if(event.key.code == sf::Keyboard::Left)
+ chatbar.moveCaretLeft();
+ else if(event.key.code == sf::Keyboard::Right)
+ chatbar.moveCaretRight();
+ }
messageBoard.processEvent(event);
}
window.clear();
messageBoard.draw(window);
+ chatbar.draw(window);
window.display();
}