summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2019-01-20 01:19:26 +0100
committerancarola <raffaele.ancarola@epfl.ch>2019-01-20 01:19:26 +0100
commit6c0c2f6f10e86986087c71a2964974ebcd939a3f (patch)
tree0a16aff4380188c6ee222579dbb55392a230dbc0 /test
parentIgnore swap files (diff)
downloadflatland-6c0c2f6f10e86986087c71a2964974ebcd939a3f.tar.gz
flatland-6c0c2f6f10e86986087c71a2964974ebcd939a3f.zip
Test 3 partially executed
Diffstat (limited to 'test')
-rw-r--r--test/main.cpp105
-rwxr-xr-xtest/testbin14656 -> 37408 bytes
-rw-r--r--test/test2.cpp31
3 files changed, 128 insertions, 8 deletions
diff --git a/test/main.cpp b/test/main.cpp
index 2b16838..0edd682 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -2,30 +2,119 @@
#include "flatwindow.h"
#include "exceptions/forcequit.h"
+#include "serial/keyfocusable.h"
+#include <SDL2/SDL.h>
+
+#include <iostream>
+#include <string>
+
+#include "flatsignal.h"
+
+using namespace std;
+
int count = 0;
void loop(float);
+class KeyPrinter : public KeyFocusable
+{
+ virtual void key_cb(const SDL_KeyboardEvent* key) override
+ {
+ string msg = (key->type == SDL_KEYDOWN) ? "pressed" : "released";
+ cout << "KeyPrinter: key " << (char)key->keysym.sym << " " << msg << endl;
+ };
+
+public:
+
+ using KeyFocusable::KeyFocusable;
+};
+
+class KeyCaller : public KeyFocusable
+{
+ int counter;
+ char last;
+
+ virtual void key_cb(const SDL_KeyboardEvent* key) override
+ {
+ if (key->type == SDL_KEYDOWN) {
+
+ char c = key->keysym.sym;
+
+ if (c == last)
+ ++counter;
+ else {
+ last = c;
+ counter = 0;
+ cout << "KeyCaller: Counter set to 0" << endl;
+ }
+ }
+
+ if (counter == 20)
+ {
+ FlatSignal signal(this, "char", (void*)&last);
+ signal.emit("alpha");
+
+ cout << "KeyCaller: 20 times reached" << endl;
+ cout << "KeyCaller: sending " << last << endl;
+ }
+
+ if (counter == 50)
+ {
+ cout << "KeyCaller: 50 times pressed " << last << endl;
+
+ /* Exit application */
+ FlatSignal signal(this, "quit");
+ signal.emit("core");
+ }
+ };
+
+public:
+
+ KeyCaller() : counter(0), last('\0')
+ {
+ setID("CALLER");
+ }
+};
+
+class TwentyListener : public FlatListener
+{
+ virtual void callback(FlatObject *sender, void *data) override
+ {
+ char c = *(char*)data;
+ cout << "TwentyListener: received " << c << " from " << sender->getID() << endl;
+ }
+
+public:
+
+ TwentyListener() : FlatListener({"char"}) {}
+};
+
+KeyPrinter printer;
+KeyCaller caller;
+TwentyListener twlistener;
+
+SignalChannel alpha("alpha");
+
int main()
{
- FlatWindow win(600, 900, "Stocazzo");
+ FlatWindow win(600, 900, "Test 3");
flat_status status;
+ /* Connect listener to alpha channel */
+ alpha.connect(&twlistener);
+
init_flatland(&win, loop, status, 60);
return 0;
}
-#include <iostream>
-
-using namespace std;
-
void loop(float dt)
{
++count;
- if (count == 1000)
- throw ForceQuit("1000 steps reached");
+ if (count == 10000)
+ throw ForceQuit("10000 steps reached");
- cout << "Loop number: " << count << endl;
+ //cout << "Loop number: " << count << endl;
}
+
diff --git a/test/test b/test/test
index 0f34b3c..364259d 100755
--- a/test/test
+++ b/test/test
Binary files differ
diff --git a/test/test2.cpp b/test/test2.cpp
new file mode 100644
index 0000000..2b16838
--- /dev/null
+++ b/test/test2.cpp
@@ -0,0 +1,31 @@
+#include "flatland.h"
+#include "flatwindow.h"
+#include "exceptions/forcequit.h"
+
+int count = 0;
+
+void loop(float);
+
+int main()
+{
+ FlatWindow win(600, 900, "Stocazzo");
+ flat_status status;
+
+ init_flatland(&win, loop, status, 60);
+
+ return 0;
+}
+
+#include <iostream>
+
+using namespace std;
+
+void loop(float dt)
+{
+ ++count;
+
+ if (count == 1000)
+ throw ForceQuit("1000 steps reached");
+
+ cout << "Loop number: " << count << endl;
+}