Skip to content
Snippets Groups Projects
Commit 8a340091 authored by Horváth Ádám's avatar Horváth Ádám
Browse files

lehet végleges

parent d423b378
Branches
No related tags found
No related merge requests found
#include "checkbox.hpp"
#include <cmath>
using namespace genv;
CheckBox::CheckBox(Application *parent, int x, int y, int sx, int sy)
: Widget(parent, x, y, sx, sy), _checked(false), _value(0) {}
void CheckBox::draw()
{
gout << move_to(_x, _y) << color(0, 255, 255) << box(_size_x, _size_y);
gout << move_to(_x + 2, _y + 2) << color(0, 0, 0) << box(_size_x - 4, _size_y - 4);
if (_value % 2 == 0 && _value != 0)
{
drawCross(_x + 4, _y + 4, _size_x - 8, _size_y - 8, 255, 0, 0);
}
if (_value % 2 == 1 && _value != 0)
{
drawCircle(_x + _size_x / 2, _y + _size_y / 2, _size_x / 2 - 3, 0, 255, 0);
}
}
void CheckBox::drawCross(int x, int y, int width, int height, int r, int g, int b)
{
gout << color(r, g, b);
gout << move_to(x, y) << line(width, height);
gout << move_to(x + 1, y) << line(width, height);
gout << move_to(x + width, y) << line(-width, height);
gout << move_to(x + width - 1, y) << line(-width, height);
}
void CheckBox::drawCircle(int x, int y, int radius, int r, int g, int b)
{
gout << color(r, g, b);
for (int i = -radius; i < radius; i++)
{
for (int j = -radius; j < radius; j++)
{
if (i * i + j * j < pow(radius, 2))
{
gout << move_to(x + i, y + j) << dot;
}
}
}
}
void CheckBox::handle(event ev)
{
if (ev.type == ev_mouse && is_selected(ev.pos_x, ev.pos_y) && ev.button == btn_left && !_checked)
{
_checked = true;
}
}
bool CheckBox::is_checked()
{
return _checked;
}
void CheckBox::value(int sz)
{
_value = sz;
}
int CheckBox::value_sz()
{
return _value;
}
int CheckBox::getPlayerValue() const {
return playerValue;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment