From b8b82252279ddcf7f4905b73cef4d9afa5b9f204 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Papp=20Benj=C3=A1min?= <papbe5@cortex.itk.ppke.hu>
Date: Sat, 18 May 2024 15:03:46 +0200
Subject: [PATCH] =?UTF-8?q?p=C3=A1lya;=20teszt=20az=20egyes=20indexek=20fe?=
 =?UTF-8?q?lismer=C3=A9s=C3=A9re?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 main.cpp      | 18 ++++++++++++++++++
 palya.cpp     | 28 ++++++++++++++++++++++++++++
 palya.h       | 17 +++++++++++++++++
 palyamezo.cpp | 15 +++++++++++++++
 palyamezo.h   | 15 +++++++++++++++
 widget.cpp    | 21 +++++++++++++++++++++
 widget.h      | 18 ++++++++++++++++++
 7 files changed, 132 insertions(+)
 create mode 100644 main.cpp
 create mode 100644 palya.cpp
 create mode 100644 palya.h
 create mode 100644 palyamezo.cpp
 create mode 100644 palyamezo.h
 create mode 100644 widget.cpp
 create mode 100644 widget.h

diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..e3c00ae
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,18 @@
+#include "palya.h"
+
+using namespace std;
+using namespace genv;
+
+int main()
+{
+    Palya* tictac = new Palya();
+
+    event ev;
+    while (gin >> ev && ev.keycode!=key_escape)
+    {
+        tictac->proba(ev);
+        gout << refresh;
+    }
+}
+
+//Papp Benjamin (I8KQEC)
diff --git a/palya.cpp b/palya.cpp
new file mode 100644
index 0000000..28ea398
--- /dev/null
+++ b/palya.cpp
@@ -0,0 +1,28 @@
+#include <iostream>
+#include "palya.h"
+
+using namespace std;
+using namespace genv;
+
+Palya::Palya()
+{
+    gout.open(XX,YY);
+    for(int i = 0; i<20; i++){
+        for(int j = 0; j<20; j++){
+            Palyamezo* proba = new Palyamezo(this, 100+(i*40), 100+(j*40), 40, 40, i, j);
+            palyaterulet.push_back(proba);
+        }
+    }
+    for(Widget* r : palyaterulet)
+        r->draw();
+}
+
+void Palya::proba(event ev)
+{
+    for(Palyamezo* r : palyaterulet){
+        if(r->hozzaer(ev))
+            cout << r->index_m << " - " << r->index_n << endl;
+    }
+}
+
+Palya::~Palya() {}
diff --git a/palya.h b/palya.h
new file mode 100644
index 0000000..198ef99
--- /dev/null
+++ b/palya.h
@@ -0,0 +1,17 @@
+#ifndef PALYA_H
+#define PALYA_H
+#include <vector>
+#include "palyamezo.h"
+
+class Palya
+{
+    std::vector<Palyamezo*> palyaterulet;
+public:
+    const int XX = 1000;
+    const int YY = 1000;
+    Palya();
+    void proba(genv:: event ev);
+    ~Palya();
+};
+
+#endif // PALYA_H
diff --git a/palyamezo.cpp b/palyamezo.cpp
new file mode 100644
index 0000000..b6bf45e
--- /dev/null
+++ b/palyamezo.cpp
@@ -0,0 +1,15 @@
+#include "palyamezo.h"
+
+using namespace genv;
+
+Palyamezo::Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n) :
+    Widget(_p, _x, _y, _w, _h), index_m(_m), index_n(_n) {}
+
+Palyamezo::~Palyamezo() {}
+
+void Palyamezo::draw(){
+    int t = 255;
+    gout << move_to(x,y) << color(t,t,t) << box(w,h);
+    t = 0;
+    gout << move_to(x+1,y+1) << color(t,t,t) << box(w-2,h-2);
+}
diff --git a/palyamezo.h b/palyamezo.h
new file mode 100644
index 0000000..a2ea4f0
--- /dev/null
+++ b/palyamezo.h
@@ -0,0 +1,15 @@
+#ifndef PALYAMEZO_H
+#define PALYAMEZO_H
+#include "widget.h"
+
+class Palyamezo : public Widget
+{
+public:
+    Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n);
+    ~Palyamezo();
+    int index_m;
+    int index_n;
+    void draw() override;
+};
+
+#endif // PALYAMEZO_H
diff --git a/widget.cpp b/widget.cpp
new file mode 100644
index 0000000..7684c8e
--- /dev/null
+++ b/widget.cpp
@@ -0,0 +1,21 @@
+#include "widget.h"
+
+using namespace genv;
+
+Widget::Widget(Palya* _p, int _x, int _y, int _w, int _h) : p(_p), x(_x), y(_y), w(_w), h(_h){}
+
+bool Widget::hozzaer(event ev)
+{
+    if(ev.pos_x > x && ev.pos_x < x+w && ev.pos_y < y+h && ev.pos_y > y)
+        return true;
+    else
+        return false;
+}
+
+bool Widget::select(event ev)
+{
+    if(hozzaer(ev) && ev.button==btn_left)
+        return true;
+    if(!hozzaer(ev) && ev.button==btn_left)
+        return false;
+}
diff --git a/widget.h b/widget.h
new file mode 100644
index 0000000..fedfd3a
--- /dev/null
+++ b/widget.h
@@ -0,0 +1,18 @@
+#ifndef WIDGET_H
+#define WIDGET_H
+#include "graphics.hpp"
+
+class Palya;
+
+class Widget{
+protected:
+    int x,y,w,h;
+    Palya* p;
+public:
+    Widget(Palya* _p, int _x, int _y, int _w, int _h);
+    bool hozzaer(genv::event ev);
+    bool select(genv::event ev);
+    virtual void draw() = 0;
+};
+
+#endif
-- 
GitLab