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

Update button.cpp

Draw() function updated to work as chess needs it
parent b1b08c4b
No related branches found
No related tags found
No related merge requests found
......@@ -2,36 +2,25 @@
using namespace genv;
struct Color{
int r,g,b;
struct DrawColor{
int r, g, b;
};
const Color BUTTON_BACK{135,206,235}, BUTTON_FRONT_INACTIVE{72,61,139}, BUTTON_FRONT_PRESSED{0,0,255}, BUTTON_TEXT{0,0,100};
const DrawColor BG_BLACK{205, 133,63}, BG_WHITE{255,248,220};
Button::Button(App* parent, int x, int y, int sx, int sy, std::string label, std::function<void ()> f):
Widget(parent,x,y,sx,sy), _label(label), _f(f)
Button::Button(App* parent, int x, int y, int sx, int sy, std::function<void ()> f, Square s):
Widget(parent,x,y,sx,sy), _f(f), _s(s)
{
pressed = 0;
type = button;
}
void Button::Draw() const
{
gout.load_font("fontok/LiberationSans", 10);
//DRAW BACKGROUND
if(_s.color == White) gout<<color(BG_WHITE.r, BG_WHITE.g, BG_WHITE.b);
else gout<<color(BG_BLACK.r,BG_BLACK.g, BG_BLACK.b);
if(!pressed)
{
gout<<move_to(_x, _y)<<color(BUTTON_BACK.r, BUTTON_BACK.g, BUTTON_BACK.b)<<box(_sx,_sy)
<<move_to(_x+2,_y+2)<<color(BUTTON_FRONT_INACTIVE.r, BUTTON_FRONT_INACTIVE.g, BUTTON_FRONT_INACTIVE.b)<<box(_sx-4,_sy-4)
<<move_to(_x+7,_y+_sy/2)<<color(BUTTON_TEXT.r, BUTTON_TEXT.g, BUTTON_TEXT.b)<<text(_label);
}
else{
gout<<move_to(_x, _y)<<color(BUTTON_BACK.r, BUTTON_BACK.g, BUTTON_BACK.b)<<box(_sx,_sy)
<<move_to(_x+2,_y+2)<<color(BUTTON_FRONT_PRESSED.r, BUTTON_FRONT_PRESSED.g, BUTTON_FRONT_PRESSED.b)<<box(_sx-4,_sy-4)
<<move_to(_x+7,_y+_sy/2)<<color(BUTTON_TEXT.r, BUTTON_TEXT.g, BUTTON_TEXT.b)<<text(_label);
gout.load_font("fontok/LiberationSans", 30);
}
gout<<move_to(_x,_y)<<box(_sx,_sy);
}
void Button::Handle(genv::event ev)
......@@ -48,6 +37,88 @@ void Button::Handle(genv::event ev)
Release();
}
}
//If occupied -> draw the piece
if(_s.occupied)
gout.load_font("LUCEFONT.TTF", 40);
{
if(_s.piece.team == Light)
{
switch(_s.piece.type)
{
case Pawn:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('P');
break;
}
case Rook:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('R');
break;
}
case Knight:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('N');
break;
}
case Bishop:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('B');
break;
}
case King:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('K');
break;
}
case Queen:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('Q');
break;
}
case Empty:
break;
}
}
else{
switch(_s.piece.type)
{
case Pawn:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('p');
break;
}
case Rook:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('r');
break;
}
case Knight:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('n');
break;
}
case Bishop:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('b');
break;
}
case King:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('k');
break;
}
case Queen:
{
gout<<move_to(_x+_sx-_sx/10, _y+_sy-_sy/10)<<text('q');
break;
}
case Empty:
break;
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment