aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
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();
}