diff --git a/application.cpp b/application.cpp index 61440d3212d1710167cd47bced8971065245efb5..d7533d94c2019a374814225b25b1329ecda66a87 100644 --- a/application.cpp +++ b/application.cpp @@ -1,9 +1,10 @@ #include "application.hpp" #include "graphics.hpp" #include "widget.hpp" - +#include <iostream> using namespace genv; +using namespace std; Application::Application() { @@ -11,9 +12,20 @@ Application::Application() } +void ellenoriz(vector<Widget> v) +{ + +} + +void Application::registerWidget(Widget* w) +{ + // Az új widgetet közvetlenül hozzáadjuk a widgets vektorhoz + widgets.push_back(w); +} void Application::event_loop() { + int wrongi = -1; event ev; int focus = -1; while(gin >> ev ) @@ -28,19 +40,57 @@ void Application::event_loop() } } } - if (focus!=-1) - { + wrongi = -1; + + for (int k = 0; k < 81; k += 9) { + for (int i = k; i < 9+k; ++i) { + for (size_t j = i+1; j < 9+k; ++j) { + if (widgets[i]->getter() == widgets[j]->getter()) { + wrongi = j; + break; + } + } + if (wrongi != -1) { + break; + } + } + if (wrongi != -1) { + break; + } + } + + for (int k = 0; k < 9; ++k) { + for (int i = k; i < 81; i += 9) { + for (size_t j = i+9; j < 81; j += 9) { + if (widgets[i]->getter() == widgets[j]->getter()) { + wrongi = j; + break; + } + } + if (wrongi != -1) { + break; + } + } + if (wrongi != -1) { + break; + } + } + + + if (focus != -1) { widgets[focus]->handle(ev); } - for (Widget * w : widgets) - { - w->draw2(); + + for (int i = 0; i < widgets.size(); ++i) { + if( i == wrongi){ + widgets[i]->draw(); + } + else { + widgets[i]->draw2(); + } } gout << refresh; + std::cout << widgets[11]->getter() << std::endl; } } -void Application::registerWidget(Widget* w) -{ - widgets.push_back(w); -} diff --git a/application.hpp b/application.hpp index 573e605030f3ab0f68f4692697457080b93de41a..2e9875fb2b813f6a264bab00a82aa45e547c16f6 100644 --- a/application.hpp +++ b/application.hpp @@ -1,5 +1,6 @@ #ifndef APPLICATION_HPP #define APPLICATION_HPP +#include <vector> #include "vector" #include <iostream> @@ -13,7 +14,7 @@ public: virtual void event_loop(); virtual void registerWidget(Widget*); - + void ellenoriz(std::vector<Widget> v); protected: diff --git a/main.cpp b/main.cpp index 2f19eda56003998a245b106eff3be287119430e8..b1c9ef4641098de54e97cd7d0f641455632fa1be 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,4 @@ - +#include <iostream> #include "application.hpp" #include "spinbox.hpp" #include <vector> @@ -9,35 +9,31 @@ using namespace std; class MyApp : public Application { - public: MyApp() { - } + void palya() { - for (int i = 5; i < 890; i+=100) + for (int i = 0; i < 9; ++i) { + vector<SpinBox*> rowWidgets; // Az adott sorhoz tartozó SpinBox-ok - for (int j = 5; j < 890; j+=100) + for (int j = 0; j < 9; ++j) { - sp = new SpinBox(this, i,j,100,0,9); - - + SpinBox* sp = new SpinBox(this, 5 + j * 100, 5 + i * 100, 100, 0, 9); + rowWidgets.push_back(sp); // Hozzáadjuk az új SpinBox-ot az aktuális sorhoz } + + // Hozzáadjuk az aktuális sorhoz tartozó widgeteket a teljes widget listához + widgets.push_back(rowWidgets); } } - - protected: - - vector<Widget*> widgets; - SpinBox * sp; - - + vector<vector<SpinBox*>> widgets; // Kétdimenziós vektor a sorok és oszlopok kezelésére }; int main() @@ -48,5 +44,6 @@ int main() + return 0; } diff --git a/spinbox.cpp b/spinbox.cpp index 1ad8b04b507b6471faf3937150da54810c859348..8c45bd27e48c0c38e3746b6cfd3563c23101ab8a 100644 --- a/spinbox.cpp +++ b/spinbox.cpp @@ -16,9 +16,8 @@ SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max) void SpinBox::draw() { - gout.load_font("LiberationSans-Regular",20); - - gout << move_to (_x,_y) << color(255,255,255) << box(_sizex,_sizey); + _sizex = _sizey; + gout << move_to (_x,_y) << color(50,50,50) << box(_sizex,_sizey); gout << move_to(_x + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); @@ -26,24 +25,13 @@ void SpinBox::draw() gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); - gout << move_to(_x + _sizey / 2, _y + _sizey / 2 + _sizey / 6) - << color(255, 0, 0) - << line_to(_x + _sizey / 2 + _sizey / 6, _y + _sizey / 2 - _sizey / 6) - << line_to(_x + _sizey / 2 - _sizey / 6, _y + _sizey / 2 - _sizey / 6) - << line_to(_x + _sizey / 2, _y + _sizey / 2 + _sizey / 6); - int text_width = gout.twidth(to_string(_num)); int text_height = gout.cascent() + gout.cdescent(); gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent()) - << color(255, 255, 255) + << color(255, 0, 0) << text(to_string(_num)); - gout << move_to(_x + _sizex - _sizey / 2, _y + _sizey / 2 - _sizey / 6) - << color(0, 255, 0) - << line_to(_x + _sizex - _sizey / 2 + _sizey / 6, _y + _sizey / 2 + _sizey / 6) - << line_to(_x + _sizex - _sizey / 2 - _sizey / 6, _y + _sizey / 2 + _sizey / 6) - << line_to(_x + _sizex - _sizey / 2, _y + _sizey / 2 - _sizey / 6); } void SpinBox::draw2() { @@ -61,7 +49,7 @@ void SpinBox::draw2() int text_height = gout.cascent() + gout.cdescent(); gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent()) - << color(255, 255, 255) + << color(0, 255, 0) << text(to_string(_num)); } @@ -76,9 +64,9 @@ bool SpinBox::isover(int ms_x, int ms_y) -string SpinBox::getter() +int SpinBox::getter() { - return to_string(_num); + return _num; } @@ -99,37 +87,16 @@ void SpinBox::handle(event ev) } } - if(_isselected) - { - if(isover(ev.pos_x, ev.pos_y) and ev.pos_x < _x + _sizex/3 and ev.button == btn_left and _num >= _min) - { - _num -= 1; - } - - if(isover(ev.pos_x, ev.pos_y) and ev.pos_x > _x + 2*_sizex/3 and ev.button == btn_left and _num <= _max) - { - _num += 1; - - } - } - } else if(ev.type == ev_key) { if(_isselected) { - if( ev.keycode == key_pgdn and _num >= _min + 10) - { - _num -= 10; - } - else if(ev.keycode == key_pgup and _num <= _max - 10) - { - _num += 10; - } - else if( ev.keycode == key_down and _num >= _min + 1 ) + + if( ev.keycode == key_down and _num >= _min + 1 ) { _num -= 1; } diff --git a/spinbox.hpp b/spinbox.hpp index 41583d1b673e2260202af229846d0bc9659b770d..31ccf4134431df2bb2aa6c05d0bec54ffbace3c7 100644 --- a/spinbox.hpp +++ b/spinbox.hpp @@ -15,8 +15,8 @@ public: void draw() override; void handle(genv::event) override; bool isover(int mouse_x,int mouse_y) override; - std::string getter() override; - void draw2(); + int getter() override; + void draw2() override; diff --git a/widget.hpp b/widget.hpp index 90e5d183b6614b1f9f1e809704697554118d1571..cd390f352010bdc05eb2f6c69e568256d69b5470 100644 --- a/widget.hpp +++ b/widget.hpp @@ -15,7 +15,7 @@ public: virtual void draw() = 0; virtual void handle(genv::event ev) = 0; virtual bool isover(int ms_x, int ms_y) = 0; - virtual std::string getter() = 0; + virtual int getter() = 0; virtual void draw2() = 0; };