2
0
Эх сурвалжийг харах

Add CheckBox control with theme edition and radio icon avaible.

Mariano Javier Suligoy 10 жил өмнө
parent
commit
e8e9f100e5

+ 76 - 0
scene/gui/check_box.cpp

@@ -0,0 +1,76 @@
+/*************************************************************************/
+/*  check_button.cpp                                                     */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                    http://www.godotengine.org                         */
+/*************************************************************************/
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+#include "check_box.h"
+
+#include "servers/visual_server.h"
+#include "button_group.h"
+
+void CheckBox::_bind_methods()
+{
+    ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&CheckBox::toggled);
+}
+
+bool CheckBox::is_radio()
+{
+    Node* parent = this;
+    do {
+        parent = parent->get_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()
+{
+    set_toggle_mode(true);
+    set_text_align(ALIGN_LEFT);
+
+    update_icon(is_pressed());
+
+}
+
+CheckBox::~CheckBox()
+{
+}

+ 58 - 0
scene/gui/check_box.h

@@ -0,0 +1,58 @@
+/*************************************************************************/
+/*  check_box.h                                                       */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                    http://www.godotengine.org                         */
+/*************************************************************************/
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                 */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+#ifndef CHECK_BOX_H
+#define CHECK_BOX_H
+
+
+#include "scene/gui/button.h"
+/**
+@author Mariano Suligoy <[email protected]>
+*/
+class CheckBox : public Button {
+
+    OBJ_TYPE( CheckBox, Button );
+
+
+protected:
+    static void _bind_methods();
+
+    bool is_radio();
+
+    void update_icon(bool p_pressed);
+
+
+public:
+    void toggled(bool p_pressed);
+
+    CheckBox();
+    ~CheckBox();
+
+};
+
+#endif

+ 31 - 1
scene/resources/default_theme/default_theme.cpp

@@ -300,6 +300,36 @@ void make_default_theme() {
 
 	t->set_constant("hseparation","MenuButton", 0 );
 
+    // CheckBox
+
+    Ref<StyleBox> cbx_empty = memnew( StyleBoxEmpty );
+    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_TOP,4);
+    cbx_focus->set_default_margin(MARGIN_BOTTOM,5);
+
+    t->set_stylebox("normal","CheckBox", cbx_empty );
+    t->set_stylebox("pressed","CheckBox", cbx_empty );
+    t->set_stylebox("disabled","CheckBox", cbx_empty );
+    t->set_stylebox("hover","CheckBox", cbx_empty );
+    t->set_stylebox("focus","CheckBox", cbx_focus );
+
+    t->set_icon("checked", "CheckBox", make_icon(checked_png));
+    t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png));
+    t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png));
+    t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png));
+
+    t->set_font("font","CheckBox", default_font );
+
+    t->set_color("font_color","CheckBox", control_font_color );
+    t->set_color("font_color_pressed","CheckBox", control_font_color_pressed );
+    t->set_color("font_color_hover","CheckBox", control_font_color_hover );
+    t->set_color("font_color_disabled","CheckBox", control_font_color_disabled );
+
+    t->set_constant("hseparation","CheckBox",4);
+    t->set_constant("check_vadjust","CheckBox",0);
+
 
 
 	// CheckButton
@@ -308,7 +338,7 @@ void make_default_theme() {
 	cb_empty->set_default_margin(MARGIN_LEFT,6);
 	cb_empty->set_default_margin(MARGIN_RIGHT,70);
 	cb_empty->set_default_margin(MARGIN_TOP,4);
-	cb_empty->set_default_margin(MARGIN_BOTTOM,4);
+    cb_empty->set_default_margin(MARGIN_BOTTOM,4);
 
 	t->set_stylebox("normal","CheckButton", cb_empty );
 	t->set_stylebox("pressed","CheckButton", cb_empty );

BIN
scene/resources/default_theme/radio_checked.png


BIN
scene/resources/default_theme/radio_unchecked.png


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 1 - 0
scene/resources/default_theme/theme_data.h


BIN
tools/editor/icons/icon_check_box.png


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно