summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariano Javier Suligoy <marianognu.easyrpg@gmail.com>2015-03-01 16:45:13 -0300
committerMariano Javier Suligoy <marianognu.easyrpg@gmail.com>2015-03-01 16:45:13 -0300
commit205ed6c9f5d6680608765dde17cbcabedfbbffa9 (patch)
tree9d85eeb09ce6727b2fb97a2b6e7527bbdadaca8d
parente8e9f100e57d6b68915fc6df5ed153384b026371 (diff)
Improve mechanism and fix radio icon rendering.
-rw-r--r--scene/gui/check_box.cpp45
-rw-r--r--scene/gui/check_box.h7
-rw-r--r--scene/resources/default_theme/default_theme.cpp8
3 files changed, 32 insertions, 28 deletions
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index 1f37833618..ac156f5144 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()
diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h
index 1f0d1ed7ed..171fd55351 100644
--- a/scene/gui/check_box.h
+++ b/scene/gui/check_box.h
@@ -40,17 +40,14 @@ class CheckBox : public Button {
protected:
- static void _bind_methods();
+ void _notification(int p_what);
bool is_radio();
- void update_icon(bool p_pressed);
-
public:
- void toggled(bool p_pressed);
- CheckBox();
+ CheckBox(const String& p_text=String());
~CheckBox();
};
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index ab0688af81..7d5981522e 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -303,9 +303,13 @@ void make_default_theme() {
// CheckBox
Ref<StyleBox> cbx_empty = memnew( StyleBoxEmpty );
+ cbx_empty->set_default_margin(MARGIN_LEFT,22);
+ cbx_empty->set_default_margin(MARGIN_RIGHT,4);
+ cbx_empty->set_default_margin(MARGIN_TOP,4);
+ cbx_empty->set_default_margin(MARGIN_BOTTOM,5);
Ref<StyleBox> cbx_focus = focus;
cbx_focus->set_default_margin(MARGIN_LEFT,4);
- cbx_focus->set_default_margin(MARGIN_RIGHT,4);
+ cbx_focus->set_default_margin(MARGIN_RIGHT,22);
cbx_focus->set_default_margin(MARGIN_TOP,4);
cbx_focus->set_default_margin(MARGIN_BOTTOM,5);
@@ -570,7 +574,7 @@ void make_default_theme() {
// Tree
Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0);
- Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0);
+ Ref<StyleBoxTexture> tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0);
t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) );
t->set_stylebox("bg_focus","Tree", focus );