示例#1
0
void Container::_child_minsize_changed() {

	Size2 ms = get_combined_minimum_size();
	if (ms.width > get_size().width || ms.height > get_size().height)
		minimum_size_changed();
	queue_sort();
}
示例#2
0
void ColorPicker::_notification(int p_what) {

	switch (p_what) {
		case NOTIFICATION_THEME_CHANGED: {

			btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
			bt_add_preset->set_icon(get_icon("add_preset"));

			_update_controls();
		} break;
		case NOTIFICATION_ENTER_TREE: {

			btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
			bt_add_preset->set_icon(get_icon("add_preset"));

			_update_color();

#ifdef TOOLS_ENABLED
			if (Engine::get_singleton()->is_editor_hint()) {
				PoolColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PoolColorArray());

				for (int i = 0; i < saved_presets.size(); i++) {
					add_preset(saved_presets[i]);
				}
			}
#endif
		} break;
		case NOTIFICATION_PARENTED: {

			for (int i = 0; i < 4; i++)
				set_margin((Margin)i, get_constant("margin"));
		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: {

			Popup *p = Object::cast_to<Popup>(get_parent());
			if (p)
				p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2));
		} break;
		case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {

			if (screen != NULL) {
				if (screen->is_visible()) {
					screen->hide();
				}
			}
		} break;
	}
}
示例#3
0
void ButtonArray::_notification(int p_what) {

    switch(p_what) {
    case NOTIFICATION_MOUSE_EXIT: {
        hover=-1;
        update();
    }
    break;
    case NOTIFICATION_READY: {
        MethodInfo mi;
        mi.name="mouse_sub_enter";

        add_user_signal(mi);

    }
    break;
    case NOTIFICATION_DRAW: {

        Size2 size=get_size();
        Size2 minsize=get_combined_minimum_size();
        Ref<StyleBox> style_normal = get_stylebox("normal");
        Ref<StyleBox> style_selected = get_stylebox("selected");
        Ref<StyleBox> style_focus = get_stylebox("focus");
        Ref<StyleBox> style_hover = get_stylebox("hover");
        Ref<Font> font_normal = get_font("font");
        Ref<Font> font_selected = get_font("font_selected");
        int icon_sep = get_constant("icon_separator");
        int button_sep = get_constant("button_separator");
        Color color_normal = get_color("font_color");
        Color color_selected = get_color("font_color_selected");

        int sep=button_sep;
        int ofs=0;
        int expand=0;

        switch(align) {
        case ALIGN_BEGIN: {

            ofs=0;
        }
        break;
        case ALIGN_CENTER: {

            ofs=Math::floor((size[orientation] - minsize[orientation])/2);
        }
        break;
        case ALIGN_END: {

            ofs=Math::floor((size[orientation] - minsize[orientation]));
        }
        break;
        case ALIGN_FILL: {

            if (buttons.size()>1)
                sep+=Math::floor((size[orientation]- minsize[orientation])/(buttons.size()-1.0));
            ofs=0;
        }
        break;
        case ALIGN_EXPAND_FILL: {

            ofs=0;
            expand=size[orientation] - minsize[orientation];
        }
        break;



        }

        int op_size = orientation==VERTICAL ? size.width : size.height;


        for(int i=0; i<buttons.size(); i++) {

            int ms = buttons[i]._ms_cache;
            int s=ms;
            if (expand>0) {
                s+=expand/buttons.size();
            }
            if(min_button_size != -1 && s < min_button_size) {
                s = min_button_size;
            }

            Rect2 r;
            r.pos[orientation]=ofs;
            r.pos[!orientation]=0;
            r.size[orientation]=s;
            r.size[!orientation]=op_size;

            Ref<Font> f;
            Color c;
            Point2 sbsize;
            Point2 sbofs;
            if (i==selected) {
                draw_style_box(style_selected,r);
                sbsize=style_selected->get_minimum_size();
                sbofs=style_selected->get_offset();
                f=font_selected;
                c=color_selected;
                if (has_focus())
                    draw_style_box(style_focus,r);
            } else {
                if (hover==i)
                    draw_style_box(style_hover,r);
                else if (!flat)
                    draw_style_box(style_normal,r);
                sbsize=style_normal->get_minimum_size();
                sbofs=style_normal->get_offset();
                f=font_normal;
                c=color_normal;
            }

            Size2 ssize = f->get_string_size(buttons[i].text);
            if (buttons[i].icon.is_valid()) {

                ssize.x+=buttons[i].icon->get_width();
            }
            Point2 text_ofs=((r.size-ssize-sbsize)/2.0+Point2(0,f->get_ascent())).floor()+sbofs;
            if (buttons[i].icon.is_valid()) {

                draw_texture(buttons[i].icon,r.pos+Point2(text_ofs.x,Math::floor((r.size.height-buttons[i].icon->get_height())/2.0)));
                text_ofs.x+=buttons[i].icon->get_width()+icon_sep;

            }
            draw_string(f,text_ofs+r.pos,buttons[i].text,c);
            buttons[i]._pos_cache=ofs;
            buttons[i]._size_cache=s;

            ofs+=s;
            ofs+=sep;
        }

    }
    break;
    }
}