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

Merge pull request #1460 from MarianoGnu/master

Create Checkbox class with support for Radio Buttons
Juan Linietsky 10 жил өмнө
parent
commit
6d813c81b8

+ 3 - 2
scene/gui/base_button.cpp

@@ -279,12 +279,12 @@ void BaseButton::set_disabled(bool p_disabled) {
 		set_focus_mode(FOCUS_NONE);
 	else
 		set_focus_mode(FOCUS_ALL);
-};
+}
 
 bool BaseButton::is_disabled() const {
 
 	return status.disabled;
-};
+}
 
 void BaseButton::set_pressed(bool p_pressed) {
 	
@@ -391,6 +391,7 @@ void BaseButton::_bind_methods() {
 	ADD_SIGNAL( MethodInfo("toggled", PropertyInfo( Variant::BOOL,"pressed") ) );
 	ADD_PROPERTY( PropertyInfo( Variant::BOOL, "disabled"), _SCS("set_disabled"), _SCS("is_disabled"));
 	ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode"));
+    ADD_PROPERTY( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed"));
 	ADD_PROPERTY( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press"));
 
 

+ 79 - 0
scene/gui/check_box.cpp

@@ -0,0 +1,79 @@
+/*************************************************************************/
+/*  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::_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()
+{
+    Node* parent = this;
+    do {
+        parent = parent->get_parent();
+        if (dynamic_cast< ButtonGroup* >(parent))
+            break;
+    } while (parent);
+
+    return (parent != 0);
+}
+
+CheckBox::CheckBox(const String &p_text):
+    Button(p_text)
+{
+    set_toggle_mode(true);
+    set_text_align(ALIGN_LEFT);
+
+}
+
+CheckBox::~CheckBox()
+{
+}

+ 55 - 0
scene/gui/check_box.h

@@ -0,0 +1,55 @@
+/*************************************************************************/
+/*  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:
+    void _notification(int p_what);
+
+    bool is_radio();
+
+
+public:
+
+    CheckBox(const String& p_text=String());
+    ~CheckBox();
+
+};
+
+#endif

+ 2 - 0
scene/register_scene_types.cpp

@@ -53,6 +53,7 @@
 #include "scene/gui/color_picker.h"
 #include "scene/gui/texture_frame.h"
 #include "scene/gui/menu_button.h"
+#include "scene/gui/check_box.h"
 #include "scene/gui/check_button.h"
 #include "scene/gui/tab_container.h"
 #include "scene/gui/panel_container.h"
@@ -289,6 +290,7 @@ void register_scene_types() {
 	ObjectTypeDB::register_type<Popup>();
 	ObjectTypeDB::register_type<PopupPanel>();
 	ObjectTypeDB::register_type<MenuButton>();
+    ObjectTypeDB::register_type<CheckBox>();
 	ObjectTypeDB::register_type<CheckButton>();
 	ObjectTypeDB::register_type<Panel>();
 	ObjectTypeDB::register_type<Range>();

+ 36 - 2
scene/resources/default_theme/default_theme.cpp

@@ -300,6 +300,40 @@ void make_default_theme() {
 
 	t->set_constant("hseparation","MenuButton", 0 );
 
+    // 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,22);
+    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 +342,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 );
@@ -540,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 );

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


+ 20 - 0
tools/editor/plugins/theme_editor_plugin.cpp

@@ -568,6 +568,26 @@ ThemeEditor::ThemeEditor() {
 	CheckButton *cb = memnew( CheckButton );
 	cb->set_text("CheckButton");
 	first_vb->add_child(cb );
+    CheckBox *cbx = memnew( CheckBox );
+    cbx->set_text("CheckBox");
+    first_vb->add_child(cbx );
+
+    /* TODO: This is not working properly, controls are overlapping*/
+    /*
+    ButtonGroup *bg = memnew( ButtonGroup );
+    bg->set_v_size_flags(SIZE_EXPAND_FILL);
+    VBoxContainer *gbvb = memnew( VBoxContainer );
+    gbvb->set_v_size_flags(SIZE_EXPAND_FILL);
+    CheckBox *rbx1 = memnew( CheckBox );
+    rbx1->set_text("CheckBox Radio1");
+    rbx1->set_pressed(true);
+    gbvb->add_child(rbx1);
+    CheckBox *rbx2 = memnew( CheckBox );
+    rbx2->set_text("CheckBox Radio2");
+    gbvb->add_child(rbx2);
+    bg->add_child(gbvb);
+    first_vb->add_child(bg);
+    */
 
 	MenuButton* test_menu_button = memnew( MenuButton );
 	test_menu_button->set_text("MenuButton");

+ 2 - 0
tools/editor/plugins/theme_editor_plugin.h

@@ -33,6 +33,8 @@
 #include "scene/gui/texture_frame.h"
 #include "scene/gui/option_button.h"
 #include "scene/gui/file_dialog.h"
+#include "scene/gui/check_box.h"
+#include "scene/gui/button_group.h"
 
 #include "tools/editor/editor_node.h"
 

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