diff --git a/application.cpp b/application.cpp index a0e6a90a4951474563e29c55ecf367ba152530bf..61440d3212d1710167cd47bced8971065245efb5 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 82c04f05dea3bae7db1e36f3ce1ba951fa0787c6..573e605030f3ab0f68f4692697457080b93de41a 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 0141044f1e43ee764fe8a31a887168e509cdba6f..4fd000d8441db0c858222ca670c131f3bf92b21e 100644 --- a/listbox.cpp +++ b/listbox.cpp @@ -117,3 +117,4 @@ string ListBox::getter() } + diff --git a/main.cpp b/main.cpp index 40aad3738ef158db6150498bfd0c48313ed57f16..2f19eda56003998a245b106eff3be287119430e8 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 3d6417b91455a6d0ca3a6a5f817e4549574b0f22..1ad8b04b507b6471faf3937150da54810c859348 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 7fed94086b2bcb528eb554ca1b10c1449c7471d5..41583d1b673e2260202af229846d0bc9659b770d 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 79bce8eebc4409390e9fb4aac5484f4cd362af04..90f65ae8c5e5e704bafddcc5413adfcbce159004 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 d61c2cd05ab23fdb79bd68c6c25c43d5a2989680..90e5d183b6614b1f9f1e809704697554118d1571 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; };