Skip to content
Snippets Groups Projects
Commit 4de67ed3 authored by Fodor Ágoston's avatar Fodor Ágoston
Browse files

kezdetleges ellenőrzés és pálya kkirajzolása máshogyan

parent 33325714
No related branches found
No related tags found
No related merge requests found
#include "application.hpp" #include "application.hpp"
#include "graphics.hpp" #include "graphics.hpp"
#include "widget.hpp" #include "widget.hpp"
#include <iostream>
using namespace genv; using namespace genv;
using namespace std;
Application::Application() Application::Application()
{ {
...@@ -11,9 +12,20 @@ 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() void Application::event_loop()
{ {
int wrongi = -1;
event ev; event ev;
int focus = -1; int focus = -1;
while(gin >> ev ) while(gin >> ev )
...@@ -28,19 +40,57 @@ void Application::event_loop() ...@@ -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); widgets[focus]->handle(ev);
} }
for (Widget * w : widgets)
{ for (int i = 0; i < widgets.size(); ++i) {
w->draw2(); if( i == wrongi){
widgets[i]->draw();
}
else {
widgets[i]->draw2();
}
} }
gout << refresh; gout << refresh;
std::cout << widgets[11]->getter() << std::endl;
} }
} }
void Application::registerWidget(Widget* w)
{
widgets.push_back(w);
}
#ifndef APPLICATION_HPP #ifndef APPLICATION_HPP
#define APPLICATION_HPP #define APPLICATION_HPP
#include <vector>
#include "vector" #include "vector"
#include <iostream> #include <iostream>
...@@ -13,7 +14,7 @@ public: ...@@ -13,7 +14,7 @@ public:
virtual void event_loop(); virtual void event_loop();
virtual void registerWidget(Widget*); virtual void registerWidget(Widget*);
void ellenoriz(std::vector<Widget> v);
protected: protected:
......
#include <iostream>
#include "application.hpp" #include "application.hpp"
#include "spinbox.hpp" #include "spinbox.hpp"
#include <vector> #include <vector>
...@@ -9,35 +9,31 @@ using namespace std; ...@@ -9,35 +9,31 @@ using namespace std;
class MyApp : public Application class MyApp : public Application
{ {
public: public:
MyApp() MyApp()
{ {
} }
void palya() 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: protected:
vector<vector<SpinBox*>> widgets; // Kétdimenziós vektor a sorok és oszlopok kezelésére
vector<Widget*> widgets;
SpinBox * sp;
}; };
int main() int main()
...@@ -48,5 +44,6 @@ int main() ...@@ -48,5 +44,6 @@ int main()
return 0; return 0;
} }
...@@ -16,9 +16,8 @@ SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max) ...@@ -16,9 +16,8 @@ SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max)
void SpinBox::draw() void SpinBox::draw()
{ {
gout.load_font("LiberationSans-Regular",20); _sizex = _sizey;
gout << move_to (_x,_y) << color(50,50,50) << box(_sizex,_sizey);
gout << move_to (_x,_y) << color(255,255,255) << box(_sizex,_sizey);
gout << move_to(_x + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); gout << move_to(_x + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
...@@ -26,24 +25,13 @@ void SpinBox::draw() ...@@ -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 +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_width = gout.twidth(to_string(_num));
int text_height = gout.cascent() + gout.cdescent(); int text_height = gout.cascent() + gout.cdescent();
gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent()) 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)); << 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() void SpinBox::draw2()
{ {
...@@ -61,7 +49,7 @@ void SpinBox::draw2() ...@@ -61,7 +49,7 @@ void SpinBox::draw2()
int text_height = gout.cascent() + gout.cdescent(); int text_height = gout.cascent() + gout.cdescent();
gout << move_to(_x + (_sizex - text_width) / 2, _y + (_sizey - text_height) / 2 + gout.cascent()) 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)); << text(to_string(_num));
} }
...@@ -76,9 +64,9 @@ bool SpinBox::isover(int ms_x, int ms_y) ...@@ -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) ...@@ -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) else if(ev.type == ev_key)
{ {
if(_isselected) if(_isselected)
{ {
if( ev.keycode == key_pgdn and _num >= _min + 10)
{ if( ev.keycode == key_down and _num >= _min + 1 )
_num -= 10;
}
else if(ev.keycode == key_pgup and _num <= _max - 10)
{
_num += 10;
}
else if( ev.keycode == key_down and _num >= _min + 1 )
{ {
_num -= 1; _num -= 1;
} }
......
...@@ -15,8 +15,8 @@ public: ...@@ -15,8 +15,8 @@ public:
void draw() override; void draw() override;
void handle(genv::event) override; void handle(genv::event) override;
bool isover(int mouse_x,int mouse_y) override; bool isover(int mouse_x,int mouse_y) override;
std::string getter() override; int getter() override;
void draw2(); void draw2() override;
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
virtual void draw() = 0; virtual void draw() = 0;
virtual void handle(genv::event ev) = 0; virtual void handle(genv::event ev) = 0;
virtual bool isover(int ms_x, int ms_y) = 0; virtual bool isover(int ms_x, int ms_y) = 0;
virtual std::string getter() = 0; virtual int getter() = 0;
virtual void draw2() = 0; virtual void draw2() = 0;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment