From 8a34009173049069b93a820cc830d16422d2fa36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Horv=C3=A1th=20=C3=81d=C3=A1m?=
 <horvath.adam.7@hallgato.ppke.hu>
Date: Mon, 20 May 2024 00:00:17 +0000
Subject: [PATCH] =?UTF-8?q?lehet=20v=C3=A9gleges?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 checkbox.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 checkbox.cpp

diff --git a/checkbox.cpp b/checkbox.cpp
new file mode 100644
index 0000000..9c6f282
--- /dev/null
+++ b/checkbox.cpp
@@ -0,0 +1,74 @@
+#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;
+}
-- 
GitLab