Example #1
0
void Object::_add_user_signal(const String& p_name, const Array& p_args) {

	// this version of add_user_signal is meant to be used from scripts or external apis
	// without access to ADD_SIGNAL in bind_methods
	// added events are per instance, as opposed to the other ones, which are global



	MethodInfo mi;
	mi.name=p_name;

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

		Dictionary d=p_args[i];
		PropertyInfo param;

		if (d.has("name"))
			param.name=d["name"];
		if (d.has("type"))
			param.type=(Variant::Type)(int)d["type"];

		mi.arguments.push_back(param);
	}

	add_user_signal(mi);

}
Example #2
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;
    }
}