Skip to content
Snippets Groups Projects
Commit e23fa524 authored by Bolla Péter's avatar Bolla Péter
Browse files

Update button.cpp

parent 4526871a
No related branches found
No related tags found
No related merge requests found
...@@ -6,59 +6,68 @@ struct DrawColor{ ...@@ -6,59 +6,68 @@ struct DrawColor{
int r, g, b; int r, g, b;
}; };
const DrawColor BG_BLACK{205, 133,63}, BG_WHITE{255,248,220}; const DrawColor BG_BLACK{205, 133,63}, BG_WHITE{255,248,220}, BG_ACTIVE{255,255,51}, BG_CHECK{255,99,71}, BG_MATE{220,20,60};
Button::Button(App* parent, int x, int y, int sx, int sy, std::function<void ()> f, Square s): Button::Button(App* parent, int x, int y, int sx, int sy, std::function<void ()> f, Chess* chb, int i):
Widget(parent,x,y,sx,sy), _f(f), _s(s) Widget(parent,x,y,sx,sy), _f(f), _ind(i), _cb(chb)
{ {
pressed = 0; pressed = 0;
active = 0;
} }
void Button::Draw() const void Button::Draw() const
{ {
//DRAW BACKGROUND //DRAW BACKGROUND
if(_s.color == White) gout<<color(BG_WHITE.r, BG_WHITE.g, BG_WHITE.b); if(pressed || active)
{
gout<<color(BG_ACTIVE.r,BG_ACTIVE.g,BG_ACTIVE.b);
}
else if(_cb->GetColor(_ind) == White) gout<<color(BG_WHITE.r, BG_WHITE.g, BG_WHITE.b);
else gout<<color(BG_BLACK.r,BG_BLACK.g, BG_BLACK.b); else gout<<color(BG_BLACK.r,BG_BLACK.g, BG_BLACK.b);
gout<<move_to(_x,_y)<<box(_sx,_sy); gout<<move_to(_x,_y)<<box(_sx,_sy);
//If occupied -> draw the piece //If occupied -> draw the piece
if(_s.occupied) if(_cb->Occupied(_ind))
//gout.load_font("LUCEFONT.TTF", 40); {
gout<<move_to(_x+2, _y+2*_sy); gout.load_font("CASEFONT.TTF", 60);
gout<<color(0,0,0);
}
gout<<move_to(_x+_sx/8, _y+_sy/8);
{ {
if(_s.piece.team == Light) if(_cb->GetSquare(_ind).piece.team == Light)
{ {
switch(_s.piece.type) switch(_cb->GetSquare(_ind).piece.type)
{ {
case Pawn: case Pawn:
{ {
gout<<text('P'); gout<<text('p');
break; break;
} }
case Rook: case Rook:
{ {
gout<<text('R'); gout<<text('r');
break; break;
} }
case Knight: case Knight:
{ {
gout<<text('N'); gout<<text('n');
break; break;
} }
case Bishop: case Bishop:
{ {
gout<<text('B'); gout<<text('b');
break; break;
} }
case King: case King:
{ {
gout<<text('K'); gout<<text('k');
break; break;
} }
case Queen: case Queen:
{ {
gout<<text('Q'); gout<<text('q');
break; break;
} }
case Empty: case Empty:
...@@ -66,37 +75,37 @@ void Button::Draw() const ...@@ -66,37 +75,37 @@ void Button::Draw() const
} }
} }
else{ else{
switch(_s.piece.type) switch(_cb->GetSquare(_ind).piece.type)
{ {
case Pawn: case Pawn:
{ {
gout<<text('p'); gout<<text('o');
break; break;
} }
case Rook: case Rook:
{ {
gout<<text('r'); gout<<text('t');
break; break;
} }
case Knight: case Knight:
{ {
gout<<text('n'); gout<<text('m');
break; break;
} }
case Bishop: case Bishop:
{ {
gout<<text('b'); gout<<text('v');
break; break;
} }
case King: case King:
{ {
gout<<text('k'); gout<<text('l');
break; break;
} }
case Queen: case Queen:
{ {
gout<<text('q'); gout<<text('w');
break; break;
} }
case Empty: case Empty:
...@@ -106,26 +115,30 @@ void Button::Draw() const ...@@ -106,26 +115,30 @@ void Button::Draw() const
} }
} }
void Button::Handle(genv::event ev) void Button::Handle(genv::event ev, Operation op)
{ {
if(ev.type == ev_mouse) if(op == PRESS)
{
if( ev.button == btn_left)
{ {
Press(); Press();
action(); action();
} }
else if(ev.button == -btn_left) else if(op == RELEASE)
{ {
Release(); Release();
} }
else if(op == ACTIVATE)
{
Activate();
}
else if(op == DEACTIVATE)
{
Deactivate();
} }
} }
void Button::Press() void Button::Press()
{ {
if(_cb->Occupied(_ind))
pressed = 1; pressed = 1;
} }
...@@ -139,11 +152,22 @@ bool Button::Pressed() ...@@ -139,11 +152,22 @@ bool Button::Pressed()
return pressed; return pressed;
} }
std::string Button::GetValue() const void Button::Activate()
{ {
return 0; active = 1;
} }
void Button::Deactivate()
{
active = 0;
}
bool Button::Active()
{
return active;
}
void Button::action() void Button::action()
{ {
_f(); _f();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment