From 22e60b5b6555b18a1f9bee74074849ae3fcaa8de Mon Sep 17 00:00:00 2001
From: Monoki Dorina <mondo1@cortex.itk.ppke.hu>
Date: Sun, 12 May 2024 01:33:42 +0200
Subject: [PATCH] ujrakezdtem

---
 application.cpp  |  88 +++++++++++----------
 application.hpp  |  42 +++++++---
 checkbox.cpp     |  40 ----------
 checkbox.hpp     |  17 ----
 dropdown.cpp     | 202 -----------------------------------------------
 dropdown.hpp     |  34 --------
 fajl_beolvas.cpp |  18 -----
 fajl_beolvas.hpp |  12 ---
 field.cpp        |  48 +++++++++++
 field.hpp        |  20 +++++
 gamemaster.cpp   | 101 ++++++++++++++++++++++++
 gamemaster.hpp   |  25 ++++++
 main.cpp         |  81 +++++--------------
 multiline.cpp    |  79 ------------------
 multiline.hpp    |  22 ------
 palya.cpp        |  65 ---------------
 palya.hpp        |  29 -------
 spinbox.cpp      | 120 ----------------------------
 spinbox.hpp      |  23 ------
 statictext.cpp   |  33 --------
 statictext.hpp   |  18 -----
 textedit.cpp     |  63 ---------------
 textedit.hpp     |  20 -----
 widget.cpp       |  19 +++++
 widget.hpp       |  30 +++++++
 widgets.cpp      |  28 -------
 widgets.hpp      |  29 -------
 27 files changed, 339 insertions(+), 967 deletions(-)
 delete mode 100644 checkbox.cpp
 delete mode 100644 checkbox.hpp
 delete mode 100644 dropdown.cpp
 delete mode 100644 dropdown.hpp
 delete mode 100644 fajl_beolvas.cpp
 delete mode 100644 fajl_beolvas.hpp
 create mode 100644 field.cpp
 create mode 100644 field.hpp
 create mode 100644 gamemaster.cpp
 create mode 100644 gamemaster.hpp
 delete mode 100644 multiline.cpp
 delete mode 100644 multiline.hpp
 delete mode 100644 palya.cpp
 delete mode 100644 palya.hpp
 delete mode 100644 spinbox.cpp
 delete mode 100644 spinbox.hpp
 delete mode 100644 statictext.cpp
 delete mode 100644 statictext.hpp
 delete mode 100644 textedit.cpp
 delete mode 100644 textedit.hpp
 create mode 100644 widget.cpp
 create mode 100644 widget.hpp
 delete mode 100644 widgets.cpp
 delete mode 100644 widgets.hpp

diff --git a/application.cpp b/application.cpp
index 85579c2..1a3b4bb 100644
--- a/application.cpp
+++ b/application.cpp
@@ -1,72 +1,74 @@
 #include "application.hpp"
-#include "widgets.hpp"
+#include "widget.hpp"
+#include "gamemaster.hpp"
 
 using namespace genv;
 
-Application::Application() {}
+Application::Application(int szel, int mag)
+{
+    gout.open(szel,mag);
+}
 
 void Application::event_loop()
 {
+    GameMaster game("mo1.txt","fe1.txt");
+
+    Index focus(0,0);
     event ev;
-    int focus=-1;
-    while(gin >> ev)
+    widgets[0]->kezel(ev);
+
+    for (Widget *w : widgets)
     {
-        if (ev.type==ev_mouse)
+        w->rajzol();
+    }
+    gout << refresh;
+
+    while(gin>>ev)
+    {
+        if (ev.type==ev_key)
         {
-            if (ev.button==btn_left)
+            if (ev.keycode==key_up || ev.keycode==key_down ||
+                ev.keycode==key_left || ev.keycode==key_right)
             {
-                for (size_t i=0; i<widgets.size(); i++)
+                widgets[9*focus.sor+focus.oszlop]->unfocus();
+
+                if (ev.keycode==key_up)
                 {
-                    if (widgets[i]->belul(ev.pos_x,ev.pos_y))
-                        {
-                            if (focus!=-1)
-                            {
-                                widgets[focus]->unfocus();
-                            }
-                            focus=i;
-                        }
+                    if (focus.sor >0)
+                        focus.sor -= 1;
                 }
-            }
-
-            /*else if (ev.button==btn_right)
-            {
-                if (focus!=-1)
+                else if (ev.keycode==key_down)
                 {
-                    widgets[focus]->fajlba_ki("log.txt");
+                    if (focus.sor <8)
+                        focus.sor += 1;
+                }
+                else if (ev.keycode==key_left)
+                {
+                    if (focus.oszlop >0)
+                        focus.oszlop -= 1;
+                }
+                else if (ev.keycode==key_right)
+                {
+                    if (focus.oszlop <8)
+                        focus.oszlop += 1;
                 }
-            }*/
-
-            if (focus!=-1)
-            {
-                widgets[focus]->kezel(ev);
-            }
-        }
 
-        if (ev.type==ev_key)
-        {
-            if (focus!=-1)
-            {
-                widgets[focus]->kezel(ev);
-            }
-            if (ev.keycode==key_enter)
-            {
-                action("enter");
-            }
-            else if(ev.keycode==key_space)
-            {
-                action("space");
+                widgets[9*focus.sor+focus.oszlop]->kezel(ev);
             }
 
         }
-        for (Widget* w : widgets)
+
+        for (Widget *w : widgets)
         {
             w->rajzol();
         }
         gout << refresh;
+
+        game.save();
     }
 }
 
-void Application::widget_hozzaado(Widget* w)
+void Application::register_widget(Widget *w)
 {
     widgets.push_back(w);
 }
diff --git a/application.hpp b/application.hpp
index dac48dd..ebf3bf9 100644
--- a/application.hpp
+++ b/application.hpp
@@ -1,23 +1,41 @@
-#ifndef APPLICATION_HPP_INCLUDED
-#define APPLICATION_HPP_INCLUDED
+#ifndef APPLICATION_HPP
+#define APPLICATION_HPP
 
+#include "graphics.hpp"
 #include <vector>
-#include <string>
 
 class Widget;
 
-class Application
+class GameMaster;
+
+struct Index
 {
-protected:
-    std::vector<Widget*> widgets;
+    public:
+        Index(int s, int o) : sor(s), oszlop(o)
+        {
+            if (sor>8)
+                sor=8;
+            else if (sor<0)
+                sor=0;
+
+            if (oszlop>8)
+                oszlop=8;
+            else if (oszlop<0)
+                oszlop=0;
+        }
+        int sor,oszlop;
+};
 
-public:
-    Application();
+class Application
+{
+    public:
+        Application(int szel, int mag);
 
-    virtual void event_loop();
-    virtual void widget_hozzaado(Widget*);
+        virtual void event_loop();
+        virtual void register_widget(Widget*);
 
-    virtual void action(std::string) = 0;
+    protected:
+        std::vector<Widget*> widgets;
 };
 
-#endif // APPLICATION_HPP_INCLUDED
+#endif // APPLICATION_HPP
diff --git a/checkbox.cpp b/checkbox.cpp
deleted file mode 100644
index 9fbd27b..0000000
--- a/checkbox.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include "checkbox.hpp"
-
-using namespace genv;
-
-Checkbox::Checkbox(Application* parent, int x, int y, int szel, int mag):
-    Widget(parent,x,y,szel,mag)
-    {
-        _xelt=false;
-    }
-
-void Checkbox::rajzol()
-{
-    g0 color(black) << move_to(_x,_y) << box(_szel,_mag);
-
-    g0 color(light_purple);
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);  //korvonal
-
-    if (_xelt)
-    {
-        g0 move_to(_x,_y) << line_to(_x+_szel,_y+_mag)
-            <<  move_to(_x,_y+_mag) << line_to(_x+_szel,_y);
-    }
-}
-
-void Checkbox::kezel(event ev)
-{
-    if (ev.type==ev_mouse && belul(ev.pos_x,ev.pos_y) && ev.button==btn_left)
-    {
-        _xelt = !_xelt;
-    }
-}
-
-bool Checkbox::xelt_e()
-{
-    return _xelt;
-}
diff --git a/checkbox.hpp b/checkbox.hpp
deleted file mode 100644
index 7da8dd4..0000000
--- a/checkbox.hpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef CHECKBOX_HPP_INCLUDED
-#define CHECKBOX_HPP_INCLUDED
-
-#include "widgets.hpp"
-
-class Checkbox : public Widget
-{
-protected:
-    bool _xelt;
-public:
-    Checkbox(Application*,int,int,int,int);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event ev) override;
-    bool xelt_e();
-};
-
-#endif // CHECKBOX_HPP_INCLUDED
diff --git a/dropdown.cpp b/dropdown.cpp
deleted file mode 100644
index 29976d9..0000000
--- a/dropdown.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-#include "dropdown.hpp"
-#include <iostream>
-#include <fstream>
-
-using namespace genv;
-using namespace std;
-
-Dropdown::Dropdown(Application* parent, int x, int y, int szel, int mag, int doboz_mag, vector<string> ertekek):
-    Widget(parent,x,y,szel,mag), _doboz_mag(doboz_mag), _ertekek(ertekek)
-    {
-        _doboz_mag_ertekado();
-        _honnan=0;
-        _doboz_db=_mag/_doboz_mag;
-        _futas_db=_futas_db_ertekado();
-        _csuszka_szel=10;
-        _csuszka_mag=_csuszka_mag_ertekado();
-        _ertek_index=-1;
-    }
-
-void Dropdown::_doboz_mag_ertekado()
-{
-    if (_doboz_mag < gout.cascent()+gout.cdescent())
-    {
-        _doboz_mag=gout.cascent()+gout.cdescent();
-    }
-    if (_mag%_doboz_mag != 0)
-    {
-        _mag-=_mag%_doboz_mag;
-    }
-}
-
-int Dropdown::_futas_db_ertekado()
-{
-    if (_doboz_db > _ertekek.size())
-    {
-        return _ertekek.size();
-    }
-    else
-    {
-        return _doboz_db;
-    }
-}
-
-int Dropdown::_csuszka_mag_ertekado()
-{
-    if (_doboz_db > _ertekek.size())
-    {
-        return _mag;
-    }
-    else
-    {
-        return _mag/_ertekek.size()*_doboz_db;
-    }
-}
-
-void Dropdown::rajzol()
-{
-    if (_kijelolt)
-    {
-        g0 color(light_purple);
-    }
-    else
-    {
-        g0 color(dark_purple);
-    }
-
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);  // korvonal
-    g0 move_to(_x+_szel-_csuszka_szel, _y) << line(0,_mag);
-
-    int vonal_y=_y;
-    for(int i=0; i<_doboz_db-1; i++)
-    {
-        vonal_y+=_doboz_mag;
-        g0 move_to(_x,vonal_y) << line(_szel-_csuszka_szel,0);  // vizszintes vonalak
-    }
-
-    elemrajzolo();
-    csuszkarajzolo();
-}
-
-void Dropdown::elemrajzolo()
-{
-    for(int i=0; i<_futas_db; i++)
-    {
-        g0 color(black) << move_to(_x+1, _y+1+i*_doboz_mag) << box(_szel-_csuszka_szel-1,_doboz_mag-2);
-    }
-
-    kijelolesrajzolo();
-
-    if (_kijelolt)
-    {
-        g0 color(light_purple);
-    }
-    else
-    {
-        g0 color(dark_purple);
-    }
-
-    int doboz_index=0;
-    for(int i=_honnan; i<_futas_db+_honnan; i++)
-    {
-        g0 move_to(_x+5, _y + _doboz_mag/2+gout.cascent()/2 + doboz_index*_doboz_mag)
-            << text(_ertekek[i]);
-        doboz_index++;
-    }
-}
-
-void Dropdown::csuszkarajzolo()
-{
-    g0 color(black) << move_to(_x+_szel-_csuszka_szel+1,_y+1) << box(_csuszka_szel-2,_mag-2);
-
-    if (_kijelolt)
-    {
-        g0 color(light_purple);
-    }
-    else
-    {
-        g0 color(dark_purple);
-    }
-    g0 move_to(_x+_szel-_csuszka_szel, _y+_mag/_ertekek.size()*_honnan) << box(_csuszka_szel,_csuszka_mag);
-}
-
-void Dropdown::dobozkijelolo(int eger_x, int eger_y)
-{
-    int _kijelolt_doboz_szama=-1;
-
-    for(int i=0; i<_futas_db;i++)
-    {
-        if (eger_x>_x && eger_x<_x+_szel &&
-            eger_y>_y+i*_doboz_mag && eger_y<_y+i*_doboz_mag+_doboz_mag)
-        {
-            _kijelolt_doboz_szama=i+_honnan;
-        }
-    }
-
-    if (_kijelolt_doboz_szama!=-1)
-    {
-        _ertek_index=_kijelolt_doboz_szama;
-
-        cout << _ertekek[_ertek_index] << endl;
-    }
-}
-
-void Dropdown::kijelolesrajzolo()
-{
-    if (_ertek_index!=-1)
-    {
-        if ((_y+1 + _ertek_index*_doboz_mag - _honnan*_doboz_mag) > _y &&
-            (_y+1 + _ertek_index*_doboz_mag - _honnan*_doboz_mag) < _y+_mag)
-        {
-            g0 color(white)
-            << move_to(_x+1, _y+1 + _ertek_index*_doboz_mag - _honnan*_doboz_mag)
-            << box(_szel-1-_csuszka_szel,_doboz_mag-2);
-        }
-    }
-}
-
-void Dropdown::kezel(event ev)
-{
-    if (ev.type == ev_mouse)
-    {
-        if (ev.button==btn_left)
-        {
-            if (belul(ev.pos_x, ev.pos_y))
-            {
-                _kijelolt = !_kijelolt;
-                dobozkijelolo(ev.pos_x,ev.pos_y);
-
-            }
-            else if (!belul(ev.pos_x, ev.pos_y))
-            {
-                _kijelolt = false;
-            }
-        }
-
-        if (_ertekek.size()!=_futas_db)
-        {
-            if (ev.button==btn_wheelup && _honnan>0)
-            {
-                _honnan--;
-                cout << _honnan << endl;
-                elemrajzolo();
-            }
-            if (ev.button==btn_wheeldown && _honnan<_ertekek.size()-_doboz_db)
-            {
-                _honnan++;
-                cout << _honnan << endl;
-                elemrajzolo();
-            }
-        }
-    }
-}
-
-std::string Dropdown::get_ertek()
-{
-    return _ertekek[_ertek_index];
-}
-
diff --git a/dropdown.hpp b/dropdown.hpp
deleted file mode 100644
index 34fdf0f..0000000
--- a/dropdown.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef DROPDOWN_HPP_INCLUDED
-#define DROPDOWN_HPP_INCLUDED
-
-#include "graphics.hpp"
-#include "widgets.hpp"
-#include <vector>
-#include <string>
-
-class Dropdown : public Widget
-{
-protected:
-    std::vector<std::string> _ertekek;
-    int _doboz_mag, _doboz_db;
-    int _futas_db, _honnan;
-    int _csuszka_szel, _csuszka_mag;
-    int _ertek_index;
-
-    int _futas_db_ertekado();
-    int _csuszka_mag_ertekado();
-    void _doboz_mag_ertekado();
-
-public:
-    Dropdown(Application*, int x, int y, int szel, int mag, int doboz_mag, std::vector<std::string> ertekek);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event ev) override;
-
-    virtual void dobozkijelolo(int,int);
-    virtual void kijelolesrajzolo();
-    virtual void elemrajzolo();
-    virtual void csuszkarajzolo();
-    std::string get_ertek();
-};
-
-#endif // DROPDOWN_HPP_INCLUDED
diff --git a/fajl_beolvas.cpp b/fajl_beolvas.cpp
deleted file mode 100644
index 7791f59..0000000
--- a/fajl_beolvas.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "fajl_beolvas.hpp"
-
-std::vector<std::vector<int>> fajl_beolvas(std::ifstream& fajlnev)
-{
-    std::vector<std::vector<int>> teljes;
-    for (int i=0; i<9; i++)
-    {
-        std::vector<int> sor;
-        for (int j=0; i<9; i++)
-        {
-            int szam;
-            fajlnev >> szam;
-            sor.pushback(szam);
-        }
-        teljes.push_back(sor)
-    }
-    return teljes;
-}
diff --git a/fajl_beolvas.hpp b/fajl_beolvas.hpp
deleted file mode 100644
index f1512cf..0000000
--- a/fajl_beolvas.hpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef FAJL_BEOLVAS_HPP_INCLUDED
-#define FAJL_BEOLVAS_HPP_INCLUDED
-
-#include <vector>
-#include <fstream>
-
-std::vector<std::vector<int>> fajl_beolvas(std::ifstream& fajlnev)
-{
-
-}
-
-#endif // FAJL_BEOLVAS_HPP_INCLUDED
diff --git a/field.cpp b/field.cpp
new file mode 100644
index 0000000..0931e4b
--- /dev/null
+++ b/field.cpp
@@ -0,0 +1,48 @@
+#include "field.hpp"
+
+using namespace genv;
+
+Field::Field(Application* parent, int x, int y, int meret):
+    Widget(parent, x, y, meret, meret) {}
+
+void Field::rajzol() const
+{
+    if (_kijelolt)  //keret
+        gout << color(light_purple);
+    else
+        gout << color(dark_purple);
+
+    gout << move_to(_x,_y) << box(_szel,_mag);
+
+    if (_kijelolt)  //belul
+        gout << color(dark_purple);
+    else
+        gout << color(bg_purple);
+
+    gout << move_to(_x+1,_y+1) << box(_szel-2,_mag-2);
+
+    if (_kijelolt)  //szoveg
+    {
+        if (_fix)
+            gout << color(white);
+        else
+            gout << color(light_purple);
+    }
+    else
+    {
+        if (_fix)
+            gout << color(black);
+        else
+            gout << color(dark_purple);
+    }
+
+    gout << move_to(_x+(_szel-gout.twidth(_cimke))/2,
+                    _y+(_mag-gout.cascent()-gout.cdescent())/2)
+         << text(_cimke);
+
+}
+
+void Field::kezel(genv::event ev)
+{
+    _kijelolt=!_kijelolt;
+}
diff --git a/field.hpp b/field.hpp
new file mode 100644
index 0000000..3d31337
--- /dev/null
+++ b/field.hpp
@@ -0,0 +1,20 @@
+#ifndef FIELD_HPP
+#define FIELD_HPP
+
+#include "widget.hpp"
+
+
+class Field : public Widget
+{
+    public:
+        Field(Application* parent, int x, int y, int meret);
+        virtual void rajzol() const override;
+        virtual void kezel(genv::event) override;
+
+    protected:
+        std::string _cimke;
+        bool _fix;
+
+};
+
+#endif // FIELD_HPP
diff --git a/gamemaster.cpp b/gamemaster.cpp
new file mode 100644
index 0000000..4b29808
--- /dev/null
+++ b/gamemaster.cpp
@@ -0,0 +1,101 @@
+#include "gamemaster.hpp"
+
+using namespace std;
+
+GameMaster::GameMaster(std::string mo, std::string fe) :
+    _fajl_megoldas(mo), _fajl_feladat(fe)
+{
+    _megoldas = fajl_beolvasas(_fajl_megoldas);
+    _feladat = fajl_beolvasas(_fajl_feladat);
+    _save = _feladat;
+    _fajl_save = "save.txt";
+}
+
+
+
+vector<Index> GameMaster::aura(Index jelenlegi)
+{
+
+}
+
+int GameMaster::negyzet_szama(Index jelenlegi)
+{
+    if (jelenlegi.sor <= 2)
+    {
+        if (jelenlegi.oszlop <= 2)
+            return 0;
+        else if (jelenlegi.oszlop <= 5)
+            return 1;
+        else
+            return 2;
+    }
+    else if (jelenlegi.sor <= 5)
+    {
+        if (jelenlegi.oszlop <= 2)
+            return 3;
+        else if (jelenlegi.oszlop <= 5)
+            return 4;
+        else
+            return 5;
+    }
+    else
+    {
+        if (jelenlegi.oszlop <= 2)
+            return 6;
+        else if (jelenlegi.oszlop <= 5)
+            return 7;
+        else
+            return 8;
+    }
+}
+
+void GameMaster::action()
+{
+
+}
+
+bool GameMaster::szabalyos_e(Index jelenlegi)
+{
+
+}
+
+std::vector<std::vector<int>> GameMaster::fajl_beolvasas(std::string fajlnev)
+{
+    std::ifstream fajl(fajlnev);
+
+    std::vector<std::vector<int>> teljes;
+    for (int i=0; i<9; i++)
+    {
+        std::vector<int> sor;
+        for (int j=0; i<9; i++)
+        {
+            int szam;
+            fajl >> szam;
+            sor.push_back(szam);
+        }
+        fajl >> ws;
+        teljes.push_back(sor);
+    }
+    fajl.close();
+    return teljes;
+}
+
+void GameMaster::save()
+{
+    fajl_kiiras(_fajl_save,_save);
+}
+
+void GameMaster::fajl_kiiras(std::string fajlnev,std::vector<std::vector<int>> v) const
+{
+    std::ofstream fajl(fajlnev);
+
+    for (vector<int> sor : v)
+    {
+        for (int ertek : sor)
+        {
+            fajl << ertek;
+        }
+        fajl << endl;
+    }
+    fajl.close();
+}
diff --git a/gamemaster.hpp b/gamemaster.hpp
new file mode 100644
index 0000000..2ccfa76
--- /dev/null
+++ b/gamemaster.hpp
@@ -0,0 +1,25 @@
+#ifndef GAMEMASTER_HPP
+#define GAMEMASTER_HPP
+
+#include "application.hpp"
+#include <vector>
+#include <fstream>
+
+class GameMaster
+{
+    public:
+        GameMaster(std::string mo, std::string fe);
+        std::vector<std::vector<int>> fajl_beolvasas(std::string fajlnev);
+        void fajl_kiiras(std::string fajlnev, std::vector<std::vector<int>> v) const;
+        void save();
+        std::vector<Index> aura(Index);
+        virtual int negyzet_szama(Index);
+        virtual bool szabalyos_e(Index);
+        virtual void action();
+
+    protected:
+        std::string _fajl_megoldas, _fajl_feladat, _fajl_save;
+        std::vector<std::vector<int>> _megoldas, _feladat, _save;
+};
+
+#endif // GAMEMASTER_HPP
diff --git a/main.cpp b/main.cpp
index 26b4516..7b4e8c6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,78 +1,39 @@
 #include "graphics.hpp"
-#include "widgets.hpp"
 #include "application.hpp"
-#include "checkbox.hpp"
-//#include "spinbox.hpp"
-//#include "dropdown.hpp"
-//#include "statictext.hpp"
-#include "textedit.hpp"
-//#include "multiline.hpp"
-#include "palya.hpp"
+#include "widget.hpp"
+#include "field.hpp"
+#include "gamemaster.hpp"
 
-#include <iostream>
-#include <fstream>
 #include <vector>
-#include <string>
 
 using namespace std;
-using namespace genv;
-
-const int ablak_szel=702;
-const int ablak_mag=702;
 
 class MyApp : public Application
 {
-public:
-    MyApp()
-    {
-        p = new Palya(this, 0, 0, 702, "mo1.txt", "fe1.txt");
-    }
-
-    void action(string id)
-    {
-        /*if (id=="enter")
-            save();
-
-        else if (id=="space" && cb->xelt_e())
-            save2();*/
-    }
-
-    /*void save()
-    {
-        std::ofstream file(te1->get_szoveg());
-        file << te2->get_szoveg();
-        file.close();
-    }
-
-    void save2()
-    {
-        std::ofstream file(te2->get_szoveg());
-        file << te1->get_szoveg();
-        file.close();
-    }*/
+    public:
+        MyApp(int szel, int mag) : Application(szel,mag)
+        {
+            for (int i=0; i<9; i++)
+            {
+                vector<Field*> sor;
+                for (int j=0; j<9; j++)
+                {
+                    Field *f = new Field(this,j*78,i*78,78);
+                    sor.push_back(f);
+                }
+                palya.push_back(sor);
+            }
+        }
 
-protected:
-    Palya* p;
+    protected:
+        vector<vector<Field*>> palya;
 };
 
 int main()
 {
-    gout.open(ablak_szel,ablak_mag);
-
-    /*std::ofstream file("mentes.txt");
-    for (int i=0; i<9; i++)
-    {
-        for (int j=0; j<9; j++)
-        {
-            file << "0";
-        }
-        file << endl;
-    }
-    file.close();*/
-
-    MyApp app;
+    MyApp sudoku(702,702);
 
-    app.event_loop();
+    sudoku.event_loop();
 
     return 0;
 }
diff --git a/multiline.cpp b/multiline.cpp
deleted file mode 100644
index 42d21c2..0000000
--- a/multiline.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "multiline.hpp"
-
-#include <fstream>
-
-using namespace genv;
-
-Multiline::Multiline(Application* parent, int x, int y, int szel, int mag, std::string filenev):
-    Widget(parent,x,y,szel,mag), _elso(0)
-    {
-        std::ifstream file(filenev);
-
-        while (file.good())
-        {
-            std::string sor;
-            getline(file,sor) >> std::ws;
-
-            _sorok.push_back(sor);
-        }
-
-        file.close();
-    }
-
-void Multiline::rajzol()
-{
-    //gout.load_font("LiberationsSans-Regular.ttf",10);
-
-    if (_kijelolt)
-        g0 color(light_purple);
-    else
-        g0 color(dark_purple);
-
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);
-
-    int height = gout.cascent()+gout.cdescent()+5;
-
-    for(int i=_elso; i<_sorok.size(); i++)
-    {
-        g0 move_to(_x + 5, _y + 5 + (i-_elso)*height)
-            << text(_sorok[i]);
-    }
-}
-
-void Multiline::kezel(event ev)
-{
-    if (ev.type == ev_mouse)
-    {
-        if (ev.button == btn_wheelup)
-            fel();
-        else if (ev.button == btn_wheeldown)
-            le();
-    }
-
-    if (ev.type==ev_mouse && ev.button==btn_left)
-    {
-        if(belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = !_kijelolt;
-        }
-        else if (!belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = false;
-        }
-    }
-}
-
-void Multiline::fel()
-{
-    if (_elso > 0)
-        _elso--;
-}
-
-void Multiline::le()
-{
-    _elso++;
-}
diff --git a/multiline.hpp b/multiline.hpp
deleted file mode 100644
index 9504067..0000000
--- a/multiline.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef MULTILINE_HPP_INCLUDED
-#define MULTILINE_HPP_INCLUDED
-
-#include "widgets.hpp"
-
-class Multiline : public Widget
-{
-protected:
-    std::vector<std::string> _sorok;
-    int _elso;
-
-public:
-    Multiline(Application*,int,int,int,int, std::string);
-
-    void rajzol() override;
-    void kezel(genv::event) override;
-
-    void fel();
-    void le();
-};
-
-#endif // MULTILINE_HPP_INCLUDED
diff --git a/palya.cpp b/palya.cpp
deleted file mode 100644
index e3b1c42..0000000
--- a/palya.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "palya.hpp"
-
-using namespace genv;
-using namespace std;
-
-Palya::Palya(Application* parent,int x,int y,int meret,
-             std::string mo, std::string fe):
-                 Widget(parent,x,y,meret,meret), _fajl_megoldas(mo), _fajl_feladat(fe)
-{
-    _megoldas = fajl_beolvas(_fajl_megoldas);
-    _feladat = fajl_beolvas(_fajl_feladat);
-    _mentes = _feladat;
-    _fajl_mentes = "mentes.txt"
-}
-
-void Palya::rajzol()
-{
-    g0 color(bg_color) << move_to(_x,_y) << box(_szel,_mag);
-
-    g0 color(dark_purple);
-    for (int i=1; i<9; i++)
-    {
-        g0 move_to(_x+i*(_szel/9),_y) << line(0,_mag);
-        if (i%3==0)
-        {
-            g0 move_to(_x+i*(_szel/9)-1,_y) << line(0,_mag);
-            g0 move_to(_x+i*(_szel/9)+1,_y) << line(0,_mag);
-        }
-    }
-    for (int i=1; i<9; i++)
-    {
-        g0 move_to(_x,_y+i*(_mag/9)) << line(_szel,0);
-        if (i%3==0)
-        {
-            g0 move_to(_x,_y+i*(_mag/9)-1) << line(_szel,0);
-            g0 move_to(_x,_y+i*(_mag/9)+1) << line(_szel,0);
-        }
-    }
-
-}
-
-void Palya::kezel(event ev)
-{
-
-}
-
-std::vector<std::vector<int>> Palya::fajl_beolvas(std::string fajlnev)
-{
-    ifstream& fajl(fajlnev);
-
-    std::vector<std::vector<int>> teljes;
-    for (int i=0; i<9; i++)
-    {
-        std::vector<int> sor;
-        for (int j=0; i<9; i++)
-        {
-            int szam;
-            fajl >> szam;
-            sor.push_back(szam);
-        }
-        teljes.push_back(sor);
-    }
-    return teljes;
-}
-
diff --git a/palya.hpp b/palya.hpp
deleted file mode 100644
index a0a4a7d..0000000
--- a/palya.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef PALYA_HPP_INCLUDED
-#define PALYA_HPP_INCLUDED
-
-#include "widgets.hpp"
-#include <vector>
-#include <fstream>
-#include <iostream>
-
-#define bg_color 246,232,255
-
-class Palya : public Widget
-{
-protected:
-    std::string _fajl_megoldas, _fajl_feladat, _fajl_mentes;
-    std::vector<std::vector<int>> _megoldas;
-    std::vector<std::vector<int>> _feladat;
-    std::vector<std::vector<int>> _mentes;
-
-public:
-    Palya(Application* parent,int x,int y,int meret,
-          std::vector<std::vector<int>> mo, std::vector<std::vector<int>> fe);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event) override;
-
-    std::vector<std::vector<int>> fajl_beolvas(std::ifstream& fajlnev);
-};
-
-
-#endif // PALYA_HPP_INCLUDED
diff --git a/spinbox.cpp b/spinbox.cpp
deleted file mode 100644
index e355561..0000000
--- a/spinbox.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "spinbox.hpp"
-#include <iostream>
-#include <fstream>
-#define g0 gout<<
-using namespace genv;
-using namespace std;
-
-Spinbox::Spinbox(Application* parent,int x, int y, int szel, int mag, int min_ertek, int max_ertek):
-    Widget(parent,x,y,szel,mag), _min(min_ertek), _max(max_ertek)
-{
-    _ertek=_min;
-
-    _alsogomb_y = _y+_mag/2;
-    _gomb_x = _x+_szel-_mag/2;
-    _gomb_meret = _mag/2;
-}
-
-void Spinbox::rajzol()
-{
-    if (_kijelolt)
-        g0 color(light_purple);
-    else
-        g0 color(dark_purple);
-
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);   // doboz
-    g0 move_to(_gomb_x,_y) << line(0,_mag);  // fuggoleges vonal
-    g0 move_to(_gomb_x,_alsogomb_y) << line(_gomb_meret,0);  // gombok k�zti v�zszintes vonal
-
-    g0 move_to(_gomb_x+_gomb_meret/4, _alsogomb_y-_gomb_meret/4)
-        << line(_gomb_meret/4,-_gomb_meret/2)
-        << line(_gomb_meret/4,_gomb_meret/2);  // felfele nyil
-
-    g0 move_to(_gomb_x+_gomb_meret/4, _alsogomb_y+_gomb_meret/4)
-        << line(_gomb_meret/4,_gomb_meret/2)
-        << line(_gomb_meret/4,-_gomb_meret/2);  // lefele nyil
-
-    g0 move_to(_x+5,_y+_mag/2+gout.cascent()/2)
-        << text(to_string(_ertek));  // ertekkiiras
-}
-
-void Spinbox::szamnovelo(int mennyivel)
-{
-    if (_ertek+mennyivel <= _max)
-    {
-        _ertek+=mennyivel;
-        cout << _ertek << endl;
-        g0 color(black) << move_to(_x+1,_y+1) << box(_szel-2,_mag-2);
-    }
-}
-
-void Spinbox::szamcsokkento(int mennyivel)
-{
-    if (_ertek-mennyivel >= _min)
-    {
-        _ertek-=mennyivel;
-        cout << _ertek << endl;
-        g0 color(black) << move_to(_x+1,_y+1) << box(_szel-2,_mag-2);
-    }
-}
-
-void Spinbox::kezel(event ev)
-{
-    if (ev.type == ev_mouse && ev.button==btn_left)
-    {
-        if (belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = !_kijelolt;
-
-            if (ev.pos_x>_gomb_x && ev.pos_x<_x+_szel &&
-                ev.pos_y>_y && ev.pos_y<_alsogomb_y)
-            {
-                szamnovelo(1);
-                _kijelolt=true;
-            }
-            else if (ev.pos_x>_gomb_x && ev.pos_x<_x+_szel &&
-                ev.pos_y>_alsogomb_y && ev.pos_y<_y+_mag)
-            {
-                szamcsokkento(1);
-                _kijelolt=true;
-            }
-        }
-        else if (!belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = false;
-        }
-
-    }
-
-    if (ev.type == ev_key && _kijelolt)
-    {
-
-        if (ev.keycode==key_up)
-        {
-            szamnovelo(1);
-        }
-        if (ev.keycode==key_pgup)
-        {
-            szamnovelo(10);
-        }
-        if (ev.keycode==key_down)
-        {
-            szamcsokkento(1);
-        }
-        if (ev.keycode==key_pgdn)
-        {
-            szamcsokkento(10);
-        }
-    }
-
-}
-
-int Spinbox::get_ertek()
-{
-    return _ertek;
-}
-
diff --git a/spinbox.hpp b/spinbox.hpp
deleted file mode 100644
index a72b5ab..0000000
--- a/spinbox.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef SPINBOX_HPP_INCLUDED
-#define SPINBOX_HPP_INCLUDED
-
-#include "graphics.hpp"
-#include "widgets.hpp"
-
-class Spinbox : public Widget
-{
-protected:
-    int _ertek, _min, _max;
-    int _alsogomb_y, _gomb_x, _gomb_meret;
-
-public:
-    Spinbox(Application*, int x, int y, int szel, int mag, int min_ertek, int max_ertek);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event ev) override;
-
-    virtual void szamnovelo(int mennyivel);
-    virtual void szamcsokkento(int mennyivel);
-    int get_ertek();
-};
-
-#endif // SPINBOX_HPP_INCLUDED
diff --git a/statictext.cpp b/statictext.cpp
deleted file mode 100644
index 2cb0c32..0000000
--- a/statictext.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-#include "statictext.hpp"
-#include <string>
-#define g0 gout<<
-
-using namespace genv;
-using namespace std;
-
-Statictext::Statictext(Application* parent, int x, int y, int szel, int mag, std::string szoveg):
-    Widget(parent,x,y,szel,mag), _szoveg(szoveg)
-{
-    _kijelolt=false;
-}
-
-void Statictext::rajzol()
-{
-    if (_kijelolt)
-        g0 color(light_purple);
-    else
-        g0 color(dark_purple);
-
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);
-
-    g0 move_to(_x+5,_y+_mag/2+gout.cascent()/2)
-        << text(_szoveg);
-}
-
-void Statictext::kezel(event ev)
-{
-}
diff --git a/statictext.hpp b/statictext.hpp
deleted file mode 100644
index 66dcc1b..0000000
--- a/statictext.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef STATICTEXT_HPP_INCLUDED
-#define STATICTEXT_HPP_INCLUDED
-
-#include "graphics.hpp"
-#include "widgets.hpp"
-
-class Statictext : public Widget
-{
-protected:
-    std::string _szoveg;
-
-public:
-    Statictext(Application*, int, int, int, int, std::string);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event ev) override;
-};
-
-#endif // STATICTEXT_HPP_INCLUDED
diff --git a/textedit.cpp b/textedit.cpp
deleted file mode 100644
index 6e4f38d..0000000
--- a/textedit.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "textedit.hpp"
-
-using namespace genv;
-using namespace std;
-
-Textedit::Textedit(Application* parent, int x, int y, int szel, int mag, std::string szoveg): Widget(parent,x,y,szel,mag), _szoveg(szoveg)
-{
-}
-
-void Textedit::rajzol()
-{
-    g0 color(black) << move_to(_x,_y) << box(_szel,_mag);
-
-    if (_kijelolt)
-    {
-        g0 color(light_purple);
-    }
-    else
-    {
-        g0 color(dark_purple);
-    }
-
-    g0 move_to(_x,_y)
-        << line(_szel,0)
-        << line(0,_mag)
-        << line(-_szel,0)
-        << line(0,-_mag);  // korvonal
-    g0 move_to(_x+5,_y+gout.cascent()) << text(_szoveg);
-}
-
-void Textedit::kezel(event ev)
-{
-    if (ev.type == ev_key && _kijelolt)
-    {
-        if (ev.keycode == key_backspace)
-        {
-            _szoveg = utf8_remove_last(_szoveg);
-        }
-        else
-        {
-            if (gout.twidth(_szoveg + ev.keyutf8) < _szel-10)
-            {
-                _szoveg += ev.keyutf8;
-            }
-        }
-    }
-    if (ev.type==ev_mouse && ev.button==btn_left)
-    {
-        if(belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = !_kijelolt;
-        }
-        else if (!belul(ev.pos_x, ev.pos_y))
-        {
-            _kijelolt = false;
-        }
-    }
-}
-
-std::string Textedit::get_szoveg()
-{
-    return _szoveg;
-}
diff --git a/textedit.hpp b/textedit.hpp
deleted file mode 100644
index e27c3f0..0000000
--- a/textedit.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef TEXTEDIT_HPP_INCLUDED
-#define TEXTEDIT_HPP_INCLUDED
-
-#include "widgets.hpp"
-
-class Textedit : public Widget
-{
-protected:
-    std::string _szoveg;
-
-public:
-    Textedit(Application*, int, int ,int ,int , std::string);
-    virtual void rajzol() override;
-    virtual void kezel(genv::event) override;
-    std::string get_szoveg();
-
-};
-
-
-#endif // TEXTEDIT_HPP_INCLUDED
diff --git a/widget.cpp b/widget.cpp
new file mode 100644
index 0000000..63f63e4
--- /dev/null
+++ b/widget.cpp
@@ -0,0 +1,19 @@
+#include "widget.hpp"
+
+Widget::Widget(Application* parent, int x, int y, int szel, int mag) :
+    _parent(parent),_x(x), _y(y), _szel(szel), _mag(mag)
+{
+    _kijelolt=false;
+    _parent->register_widget(this);
+}
+
+bool Widget::belul(int eger_x, int eger_y) const
+{
+    return (eger_x>_x && eger_x<_x+_szel &&
+        eger_y>_y && eger_y<_y+_mag);
+}
+
+void Widget::unfocus()
+{
+    _kijelolt=false;
+}
diff --git a/widget.hpp b/widget.hpp
new file mode 100644
index 0000000..2fd3ea5
--- /dev/null
+++ b/widget.hpp
@@ -0,0 +1,30 @@
+#ifndef WIDGET_HPP
+#define WIDGET_HPP
+
+#include "graphics.hpp"
+#include "application.hpp"
+
+#define dark_purple 130,37,184
+#define light_purple 210,145,255
+#define bg_purple 246,232,255
+#define white 255,255,255
+#define black 0,0,0
+
+class Widget
+{
+    public:
+        Widget(Application*, int x, int y, int szel, int mag);
+        virtual bool belul(int eger_x, int eger_y) const;
+        virtual void unfocus();
+
+        virtual void rajzol() const = 0;
+        virtual void kezel(genv::event) = 0;
+
+    protected:
+        int _x, _y, _szel, _mag;
+        Application *_parent;
+        bool _kijelolt;
+
+};
+
+#endif // WIDGET_HPP
diff --git a/widgets.cpp b/widgets.cpp
deleted file mode 100644
index c8ecefb..0000000
--- a/widgets.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "graphics.hpp"
-#include "widgets.hpp"
-
-
-
-using namespace genv;
-
-Widget::Widget(Application* parent, int x, int y, int szel, int mag):
-    _parent(parent),_x(x), _y(y), _szel(szel), _mag(mag)
-{
-    _kijelolt=false;
-    _parent->widget_hozzaado(this);
-}
-
-bool Widget::belul(int eger_x, int eger_y)
-{
-    if (eger_x>_x && eger_x<_x+_szel &&
-        eger_y>_y && eger_y<_y+_mag)
-        return true;
-    else
-        return false;
-}
-
-void Widget::unfocus()
-{
-    _kijelolt=false;
-}
-
diff --git a/widgets.hpp b/widgets.hpp
deleted file mode 100644
index 668de3e..0000000
--- a/widgets.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef WIDGETS_HPP_INCLUDED
-#define WIDGETS_HPP_INCLUDED
-
-#include "graphics.hpp"
-#include "application.hpp"
-
-#define g0 gout<<
-#define dark_purple 130,37,184
-#define light_purple 210,145,255
-#define white 255,255,255
-#define black 0,0,0
-
-class Widget
-{
-protected:
-    int _x, _y, _szel, _mag;
-    Application* _parent;
-    bool _kijelolt;
-
-public:
-    Widget(Application*, int x, int y, int szel, int mag);
-    virtual bool belul(int eger_x, int eger_y);
-    virtual void unfocus();
-
-    virtual void rajzol() = 0;
-    virtual void kezel(genv::event ev) = 0;
-};
-
-#endif // WIDGETS_HPP_INCLUDED
-- 
GitLab