From 38ef7e3bab370f4dc7c1c86e43b3f847fdfc70f4 Mon Sep 17 00:00:00 2001 From: "fodor.agoston" <fodor.agoston@hallgato.ppke.hu> Date: Wed, 15 May 2024 22:12:32 +0200 Subject: [PATCH] =?UTF-8?q?p=C3=A1lya=20kirajzol=C3=A1sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application.cpp | 8 ++++++-- application.hpp | 2 +- listbox.cpp | 1 + main.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++------ spinbox.cpp | 21 +++++++++++++++++++- spinbox.hpp | 1 + widget.cpp | 5 ++++- widget.hpp | 1 + 8 files changed, 79 insertions(+), 11 deletions(-) diff --git a/application.cpp b/application.cpp index a0e6a90..61440d3 100644 --- a/application.cpp +++ b/application.cpp @@ -1,11 +1,15 @@ #include "application.hpp" #include "graphics.hpp" #include "widget.hpp" + + using namespace genv; Application::Application() { - gout.open(900,900); + gout.open(910,910); + + } void Application::event_loop() @@ -30,7 +34,7 @@ void Application::event_loop() } for (Widget * w : widgets) { - w->draw(); + w->draw2(); } gout << refresh; } diff --git a/application.hpp b/application.hpp index 82c04f0..573e605 100644 --- a/application.hpp +++ b/application.hpp @@ -14,7 +14,7 @@ public: virtual void event_loop(); virtual void registerWidget(Widget*); - virtual void action(std::string) = 0; + protected: std::vector<Widget*> widgets; diff --git a/listbox.cpp b/listbox.cpp index 0141044..4fd000d 100644 --- a/listbox.cpp +++ b/listbox.cpp @@ -117,3 +117,4 @@ string ListBox::getter() } + diff --git a/main.cpp b/main.cpp index 40aad37..2f19eda 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,52 @@ -#include "graphics.hpp" + +#include "application.hpp" +#include "spinbox.hpp" +#include <vector> +#include "widget.hpp" + using namespace genv; +using namespace std; + +class MyApp : public Application +{ + +public: + MyApp() + { + + } + void palya() + { + for (int i = 5; i < 890; i+=100) + { + + for (int j = 5; j < 890; j+=100) + { + sp = new SpinBox(this, i,j,100,0,9); + + + } + } + } + + + +protected: + + vector<Widget*> widgets; + SpinBox * sp; + + +}; int main() { - gout.open(400,400); - gout <<text("hello world")<< refresh; - event ev; - while(gin >> ev) { - } + MyApp app; + app.palya(); + app.event_loop(); + + + return 0; } diff --git a/spinbox.cpp b/spinbox.cpp index 3d6417b..1ad8b04 100644 --- a/spinbox.cpp +++ b/spinbox.cpp @@ -11,7 +11,7 @@ int mouse_y = 0; SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max) : Widget(parent,x,y,sizey*3,sizey), _min(min), _max(max), _isselected(0) { - _num = (_min + _max)/2; + _num = 0; } void SpinBox::draw() @@ -45,6 +45,25 @@ void SpinBox::draw() << 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() +{ + _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); + + gout << move_to(_x + _sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); + + gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); + + 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) + << text(to_string(_num)); +} bool SpinBox::isover(int ms_x, int ms_y) { diff --git a/spinbox.hpp b/spinbox.hpp index 7fed940..41583d1 100644 --- a/spinbox.hpp +++ b/spinbox.hpp @@ -16,6 +16,7 @@ public: void handle(genv::event) override; bool isover(int mouse_x,int mouse_y) override; std::string getter() override; + void draw2(); diff --git a/widget.cpp b/widget.cpp index 79bce8e..90f65ae 100644 --- a/widget.cpp +++ b/widget.cpp @@ -1,6 +1,5 @@ #include "widget.hpp" #include "application.hpp" -#include "graphics.hpp" using namespace genv; Widget::Widget(Application * parent,int x, int y, int sizex, int sizey) : _x(x), _y(y), _sizex(sizex), _sizey(sizey), _parent(parent) @@ -8,3 +7,7 @@ Widget::Widget(Application * parent,int x, int y, int sizex, int sizey) : _x(x), { _parent->registerWidget(this); } +void draw2() +{ + +} diff --git a/widget.hpp b/widget.hpp index d61c2cd..90e5d18 100644 --- a/widget.hpp +++ b/widget.hpp @@ -16,6 +16,7 @@ public: virtual void handle(genv::event ev) = 0; virtual bool isover(int ms_x, int ms_y) = 0; virtual std::string getter() = 0; + virtual void draw2() = 0; }; -- GitLab