aboutsummaryrefslogtreecommitdiff
path: root/scene/gui/check_box.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/check_box.cpp')
-rw-r--r--scene/gui/check_box.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index 1f3783361..ac156f514 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -31,9 +31,27 @@
#include "servers/visual_server.h"
#include "button_group.h"
-void CheckBox::_bind_methods()
-{
- ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&CheckBox::toggled);
+
+void CheckBox::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_DRAW) {
+
+ RID ci = get_canvas_item();
+
+ Ref<Texture> on=Control::get_icon(is_radio() ? "radio_checked" : "checked");
+ Ref<Texture> off=Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked");
+
+ Vector2 ofs;
+ ofs.x = 0;
+ ofs.y = int((get_size().height - on->get_height())/2);
+
+ if (is_pressed())
+ on->draw(ci,ofs);
+ else
+ off->draw(ci,ofs);
+
+
+ }
}
bool CheckBox::is_radio()
@@ -41,34 +59,19 @@ bool CheckBox::is_radio()
Node* parent = this;
do {
parent = parent->get_parent();
- if (dynamic_cast< ButtonGroup* >( parent))
+ if (dynamic_cast< ButtonGroup* >(parent))
break;
} while (parent != nullptr);
return (parent != nullptr);
}
-void CheckBox::update_icon(bool p_pressed)
-{
- if (is_radio())
- set_icon(Control::get_icon(p_pressed ? "radio_checked" : "radio_unchecked"));
- else
- set_icon(Control::get_icon(p_pressed ? "checked" : "unchecked"));
-}
-
-void CheckBox::toggled(bool p_pressed)
-{
- update_icon();
- BaseButton::toggled(p_pressed);
-}
-
-CheckBox::CheckBox()
+CheckBox::CheckBox(const String &p_text):
+ Button(p_text)
{
set_toggle_mode(true);
set_text_align(ALIGN_LEFT);
- update_icon(is_pressed());
-
}
CheckBox::~CheckBox()