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

Upload New File

parent 3bddeb02
No related branches found
No related tags found
No related merge requests found
#include "button.hpp"
using namespace genv;
struct Color{
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};
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)
{
pressed = 0;
type = button;
}
void Button::Draw() const
{
gout.load_font("fontok/LiberationSans", 10);
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);
}
}
void Button::Handle(genv::event ev)
{
if(ev.type == ev_mouse)
{
if( ev.button == btn_left)
{
Press();
action();
}
else if(ev.button == -btn_left)
{
Release();
}
}
}
void Button::Press()
{
pressed = 1;
}
void Button::Release()
{
pressed = 0;
}
bool Button::Pressed()
{
return pressed;
}
std::string Button::GetValue() const
{
return 0;
}
void Button::action()
{
_f();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment