From d0572cdf95a7753bebb4db5c8dbfb1ce3cced4fc Mon Sep 17 00:00:00 2001 From: Monoki Dorina <mondo1@cortex.itk.ppke.hu> Date: Mon, 6 May 2024 13:08:12 +0200 Subject: [PATCH] elso mentes --- application.cpp | 72 +++++++++++++++++ application.hpp | 23 ++++++ checkbox.cpp | 40 ++++++++++ checkbox.hpp | 17 ++++ dropdown.cpp | 202 +++++++++++++++++++++++++++++++++++++++++++++++ dropdown.hpp | 34 ++++++++ fajl_beolvas.cpp | 18 +++++ fajl_beolvas.hpp | 12 +++ 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 +++++ widgets.cpp | 28 +++++++ widgets.hpp | 29 +++++++ 20 files changed, 947 insertions(+) create mode 100644 application.cpp create mode 100644 application.hpp create mode 100644 checkbox.cpp create mode 100644 checkbox.hpp create mode 100644 dropdown.cpp create mode 100644 dropdown.hpp create mode 100644 fajl_beolvas.cpp create mode 100644 fajl_beolvas.hpp create mode 100644 multiline.cpp create mode 100644 multiline.hpp create mode 100644 palya.cpp create mode 100644 palya.hpp create mode 100644 spinbox.cpp create mode 100644 spinbox.hpp create mode 100644 statictext.cpp create mode 100644 statictext.hpp create mode 100644 textedit.cpp create mode 100644 textedit.hpp create mode 100644 widgets.cpp create mode 100644 widgets.hpp diff --git a/application.cpp b/application.cpp new file mode 100644 index 0000000..85579c2 --- /dev/null +++ b/application.cpp @@ -0,0 +1,72 @@ +#include "application.hpp" +#include "widgets.hpp" + +using namespace genv; + +Application::Application() {} + +void Application::event_loop() +{ + event ev; + int focus=-1; + while(gin >> ev) + { + if (ev.type==ev_mouse) + { + if (ev.button==btn_left) + { + for (size_t i=0; i<widgets.size(); i++) + { + if (widgets[i]->belul(ev.pos_x,ev.pos_y)) + { + if (focus!=-1) + { + widgets[focus]->unfocus(); + } + focus=i; + } + } + } + + /*else if (ev.button==btn_right) + { + if (focus!=-1) + { + widgets[focus]->fajlba_ki("log.txt"); + } + }*/ + + 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"); + } + + } + for (Widget* w : widgets) + { + w->rajzol(); + } + gout << refresh; + } +} + +void Application::widget_hozzaado(Widget* w) +{ + widgets.push_back(w); +} diff --git a/application.hpp b/application.hpp new file mode 100644 index 0000000..dac48dd --- /dev/null +++ b/application.hpp @@ -0,0 +1,23 @@ +#ifndef APPLICATION_HPP_INCLUDED +#define APPLICATION_HPP_INCLUDED + +#include <vector> +#include <string> + +class Widget; + +class Application +{ +protected: + std::vector<Widget*> widgets; + +public: + Application(); + + virtual void event_loop(); + virtual void widget_hozzaado(Widget*); + + virtual void action(std::string) = 0; +}; + +#endif // APPLICATION_HPP_INCLUDED diff --git a/checkbox.cpp b/checkbox.cpp new file mode 100644 index 0000000..9fbd27b --- /dev/null +++ b/checkbox.cpp @@ -0,0 +1,40 @@ +#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 new file mode 100644 index 0000000..7da8dd4 --- /dev/null +++ b/checkbox.hpp @@ -0,0 +1,17 @@ +#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 new file mode 100644 index 0000000..29976d9 --- /dev/null +++ b/dropdown.cpp @@ -0,0 +1,202 @@ +#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 new file mode 100644 index 0000000..34fdf0f --- /dev/null +++ b/dropdown.hpp @@ -0,0 +1,34 @@ +#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 new file mode 100644 index 0000000..7791f59 --- /dev/null +++ b/fajl_beolvas.cpp @@ -0,0 +1,18 @@ +#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 new file mode 100644 index 0000000..f1512cf --- /dev/null +++ b/fajl_beolvas.hpp @@ -0,0 +1,12 @@ +#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/multiline.cpp b/multiline.cpp new file mode 100644 index 0000000..42d21c2 --- /dev/null +++ b/multiline.cpp @@ -0,0 +1,79 @@ +#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 new file mode 100644 index 0000000..9504067 --- /dev/null +++ b/multiline.hpp @@ -0,0 +1,22 @@ +#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 new file mode 100644 index 0000000..e3b1c42 --- /dev/null +++ b/palya.cpp @@ -0,0 +1,65 @@ +#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 new file mode 100644 index 0000000..a0a4a7d --- /dev/null +++ b/palya.hpp @@ -0,0 +1,29 @@ +#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 new file mode 100644 index 0000000..e355561 --- /dev/null +++ b/spinbox.cpp @@ -0,0 +1,120 @@ +#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 new file mode 100644 index 0000000..a72b5ab --- /dev/null +++ b/spinbox.hpp @@ -0,0 +1,23 @@ +#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 new file mode 100644 index 0000000..2cb0c32 --- /dev/null +++ b/statictext.cpp @@ -0,0 +1,33 @@ +#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 new file mode 100644 index 0000000..66dcc1b --- /dev/null +++ b/statictext.hpp @@ -0,0 +1,18 @@ +#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 new file mode 100644 index 0000000..6e4f38d --- /dev/null +++ b/textedit.cpp @@ -0,0 +1,63 @@ +#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 new file mode 100644 index 0000000..e27c3f0 --- /dev/null +++ b/textedit.hpp @@ -0,0 +1,20 @@ +#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/widgets.cpp b/widgets.cpp new file mode 100644 index 0000000..c8ecefb --- /dev/null +++ b/widgets.cpp @@ -0,0 +1,28 @@ +#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 new file mode 100644 index 0000000..668de3e --- /dev/null +++ b/widgets.hpp @@ -0,0 +1,29 @@ +#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