コード例 #1
0
ファイル: dialogs.cpp プロジェクト: AutonomicStudios/godot
void WindowDialog::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_DRAW: {

			RID ci = get_canvas_item();
			Size2 s = get_size();
			Ref<StyleBox> st = get_stylebox("panel","WindowDialog");
			st->draw(ci,Rect2(Point2(),s));
			int th = get_constant("title_height","WindowDialog");
			Color tc = get_color("title_color","WindowDialog");
			Ref<Font> font = get_font("title_font","WindowDialog");
			int ofs = (s.width-font->get_string_size(title).width)/2;
			//int ofs = st->get_margin(MARGIN_LEFT);
			draw_string(font,Point2(ofs,-th+font->get_ascent()),title,tc,s.width - st->get_minimum_size().width);


		} break;
		case NOTIFICATION_THEME_CHANGED:
		case NOTIFICATION_ENTER_TREE: {

			close_button->set_normal_texture( get_icon("close","WindowDialog"));
			close_button->set_pressed_texture( get_icon("close","WindowDialog"));
			close_button->set_hover_texture( get_icon("close_hilite","WindowDialog"));
			close_button->set_anchor(MARGIN_LEFT,ANCHOR_END);
			close_button->set_begin( Point2( get_constant("close_h_ofs","WindowDialog"), -get_constant("close_v_ofs","WindowDialog") ));

		} break;
	}

}
コード例 #2
0
ファイル: option_button.cpp プロジェクト: 93i/godot
void OptionButton::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		if (!has_icon("arrow"))
			return;

		RID ci = get_canvas_item();
		Ref<Texture> arrow = Control::get_icon("arrow");
		Ref<StyleBox> normal = get_stylebox("normal");
		Color clr = Color(1, 1, 1);
		if (get_constant("modulate_arrow")) {
			switch (get_draw_mode()) {
				case DRAW_PRESSED:
					clr = get_color("font_color_pressed");
					break;
				case DRAW_HOVER:
					clr = get_color("font_color_hover");
					break;
				case DRAW_DISABLED:
					clr = get_color("font_color_disabled");
					break;
				default:
					clr = get_color("font_color");
			}
		}

		Size2 size = get_size();

		Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
		arrow->draw(ci, ofs, clr);
	}
}
コード例 #3
0
ファイル: dialogs.cpp プロジェクト: AutonomicStudios/godot
AcceptDialog::AcceptDialog() {

	int margin = get_constant("margin","Dialogs");
	int button_margin = get_constant("button_margin","Dialogs");


	label = memnew( Label );
	label->set_anchor(MARGIN_RIGHT,ANCHOR_END);
	label->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
	label->set_begin( Point2( margin, margin) );
	label->set_end( Point2( margin, button_margin+10) );
	//label->set_autowrap(true);
	add_child(label);

	hbc = memnew( HBoxContainer );
	hbc->set_area_as_parent_rect(margin);
	hbc->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,button_margin);
	add_child(hbc);

	hbc->add_spacer();
	ok = memnew( Button );
	ok->set_text("OK");
	hbc->add_child(ok);
	hbc->add_spacer();
	//add_child(ok);


	ok->connect("pressed", this,"_ok");
	set_as_toplevel(true);

	hide_on_ok=true;
	set_title("Alert!");
}
コード例 #4
0
ファイル: graph_edit.cpp プロジェクト: UgisBrekis/godot
void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color) {

	//cubic bezier code
	float diff = p_to.x - p_from.x;
	float cp_offset;
	int cp_len = get_constant("bezier_len_pos");
	int cp_neg_len = get_constant("bezier_len_neg");

	if (diff > 0) {
		cp_offset = MIN(cp_len, diff * 0.5);
	} else {
		cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
	}

	Vector2 c1 = Vector2(cp_offset * zoom, 0);
	Vector2 c2 = Vector2(-cp_offset * zoom, 0);

	int lines = 0;

	Vector<Point2> points;
	Vector<Color> colors;
	points.push_back(p_from);
	colors.push_back(p_color);
	_bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 3, p_color, p_to_color, lines);
	points.push_back(p_to);
	colors.push_back(p_to_color);

#ifdef TOOLS_ENABLED
	p_where->draw_polyline_colors(points, colors, Math::floor(2 * EDSCALE), true);
#else
	p_where->draw_polyline_colors(points, colors, 2, true);
#endif
}
コード例 #5
0
ファイル: dialogs.cpp プロジェクト: AutonomicStudios/godot
void AcceptDialog::set_child_rect(Control *p_child) {

	ERR_FAIL_COND(p_child->get_parent()!=this);

	p_child->set_area_as_parent_rect(get_constant("margin","Dialogs"));
	p_child->set_margin(MARGIN_BOTTOM, get_constant("button_margin","Dialogs")+10);
}
コード例 #6
0
ファイル: popup_menu.cpp プロジェクト: rrrfffrrr/godot
Size2 PopupMenu::get_minimum_size() const {

	int vseparation = get_constant("vseparation");
	int hseparation = get_constant("hseparation");

	Size2 minsize = get_stylebox("panel")->get_minimum_size();
	Ref<Font> font = get_font("font");

	float max_w = 0;
	int font_h = font->get_height();
	int check_w = get_icon("checked")->get_width();
	int accel_max_w = 0;

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

		Size2 size;
		if (!items[i].icon.is_null()) {

			Size2 icon_size = items[i].icon->get_size();
			size.height = MAX(icon_size.height, font_h);
			size.width += icon_size.width;
			size.width += hseparation;
		} else {

			size.height = font_h;
		}

		size.width += items[i].h_ofs;

		if (items[i].checkable) {

			size.width += check_w + hseparation;
		}

		String text = items[i].shortcut.is_valid() ? String(tr(items[i].shortcut->get_name())) : items[i].xl_text;
		size.width += font->get_string_size(text).width;
		if (i > 0)
			size.height += vseparation;

		if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {

			int accel_w = hseparation * 2;
			accel_w += font->get_string_size(_get_accel_text(i)).width;
			accel_max_w = MAX(accel_w, accel_max_w);
		}

		if (items[i].submenu != "") {

			size.width += get_icon("submenu")->get_width();
		}

		minsize.height += size.height;
		max_w = MAX(max_w, size.width);
	}

	minsize.width += max_w + accel_max_w;

	return minsize;
}
コード例 #7
0
ファイル: graph_node.cpp プロジェクト: AMG194/godot
void GraphNode::_connpos_update() {


	int edgeofs=get_constant("port_offset");
	int sep=get_constant("separation");

	Ref<StyleBox> sb=get_stylebox("frame");
	Ref<Texture> port =get_icon("port");
	conn_input_cache.clear();
	conn_output_cache.clear();
	int vofs=0;

	int idx=0;

	for(int i=0;i<get_child_count();i++) {
		Control *c=get_child(i)->cast_to<Control>();
		if (!c)
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size=c->get_combined_minimum_size();

		int y = sb->get_margin(MARGIN_TOP)+vofs;
		int h = size.y;


		if (slot_info.has(idx)) {

			if (slot_info[idx].enable_left) {
				ConnCache cc;
				cc.pos=Point2i(edgeofs,y+h/2);
				cc.type=slot_info[idx].type_left;
				cc.color=slot_info[idx].color_left;
				conn_input_cache.push_back(cc);
			}
			if (slot_info[idx].enable_right) {
				ConnCache cc;
				cc.pos=Point2i(get_size().width-edgeofs,y+h/2);
				cc.type=slot_info[idx].type_right;
				cc.color=slot_info[idx].color_right;
				conn_output_cache.push_back(cc);
			}
		}

		if (vofs>0)
			vofs+=sep;
		vofs+=size.y;
		idx++;

	}


	connpos_dirty=false;
}
コード例 #8
0
ファイル: graph_node.cpp プロジェクト: AMG194/godot
void GraphNode::_notification(int p_what) {

	if (p_what==NOTIFICATION_DRAW) {

		Ref<StyleBox> sb=get_stylebox("frame");
		Ref<Texture> port =get_icon("port");
		Ref<Texture> close =get_icon("close");
		int close_offset = get_constant("close_offset");
		Ref<Font> title_font = get_font("title_font");
		int title_offset = get_constant("title_offset");
		Color title_color = get_color("title_color");
		Point2i icofs = -port->get_size()*0.5;
		int edgeofs=get_constant("port_offset");
		icofs.y+=sb->get_margin(MARGIN_TOP);
		draw_style_box(sb,Rect2(Point2(),get_size()));

		int w = get_size().width-sb->get_minimum_size().x;

		if (show_close)
			w-=close->get_width();

		draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
		if (show_close) {
			Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
			draw_texture(close,cpos);
			close_rect.pos=cpos;
			close_rect.size=close->get_size();
		} else {
			close_rect=Rect2();
		}

		for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {

			if (E->key() < 0 || E->key()>=cache_y.size())
				continue;
			if (!slot_info.has(E->key()))
				continue;
			const Slot &s=slot_info[E->key()];
			//left
			if (s.enable_left)
				port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left);
			if (s.enable_right)
				port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right);

		}
	}

	if (p_what==NOTIFICATION_SORT_CHILDREN) {

		_resort();
	}

}
コード例 #9
0
ファイル: graph_edit.cpp プロジェクト: MattUV/godot
void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color) {

#if 1

	//cubic bezier code
	float diff = p_to.x - p_from.x;
	float cp_offset;
	int cp_len = get_constant("bezier_len_pos");
	int cp_neg_len = get_constant("bezier_len_neg");

	if (diff > 0) {
		cp_offset = MAX(cp_len, diff * 0.5);
	} else {
		cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
	}

	Vector2 c1 = Vector2(cp_offset * zoom, 0);
	Vector2 c2 = Vector2(-cp_offset * zoom, 0);

	int lines = 0;
	_bake_segment2d(p_where, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);

#else

	static const int steps = 20;

	//old cosine code
	Rect2 r;
	r.pos = p_from;
	r.expand_to(p_to);
	Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1);
	bool flip = sign.x * sign.y < 0;

	Vector2 prev;
	for (int i = 0; i <= steps; i++) {

		float d = i / float(steps);
		float c = -Math::cos(d * Math_PI) * 0.5 + 0.5;
		if (flip)
			c = 1.0 - c;
		Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height);

		if (i > 0) {

			p_where->draw_line(prev, p, p_color.linear_interpolate(p_to_color, d), 2);
		}

		prev = p;
	}
#endif
}
コード例 #10
0
ファイル: grid_container.cpp プロジェクト: BenjaDev/godot
Size2 GridContainer::get_minimum_size() const {

	Map<int,int> col_minw;
	Map<int,int> row_minh;

	int hsep=get_constant("hseparation");
	int vsep=get_constant("vseparation");

	int idx=0;
	int max_row=0;
	int max_col=0;

	for(int i=0;i<get_child_count();i++) {

		Control *c = get_child(i)->cast_to<Control>();
		if (!c || !c->is_visible())
			continue;
		int row = idx / columns;
		int col = idx % columns;
		Size2i ms = c->get_combined_minimum_size();
		if (col_minw.has(col))
			col_minw[col] = MAX(col_minw[col],ms.width);
		else
			col_minw[col]=ms.width;

		if (row_minh.has(row))
			row_minh[row] = MAX(row_minh[row],ms.height);
		else
			row_minh[row]=ms.height;
		max_col=MAX(col,max_col);
		max_row=MAX(row,max_row);
		idx++;
	}

	Size2 ms;

	for (Map<int,int>::Element *E=col_minw.front();E;E=E->next()) {
		ms.width+=E->get();
	}

	for (Map<int,int>::Element *E=row_minh.front();E;E=E->next()) {
		ms.height+=E->get();
	}

	ms.height+=vsep*max_row;
	ms.width+=hsep*max_col;

	return ms;

}
コード例 #11
0
ファイル: color_picker.cpp プロジェクト: ialex32x/godot
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;
	}
}
コード例 #12
0
ファイル: dialogs.cpp プロジェクト: lonesurvivor/godot
void AcceptDialog::_update_child_rect() {
	Size2 label_size=label->get_minimum_size();
	if (label->get_text().empty()) {
		label_size.height = 0;
	}
	int margin = get_constant("margin","Dialogs");
	Size2 size = get_size();
	Size2 hminsize = hbc->get_combined_minimum_size();

	Vector2 cpos(margin,margin+label_size.height);
	Vector2 csize(size.x-margin*2,size.y-margin*3-hminsize.y-label_size.height);

	if (child) {

		child->set_pos(cpos);
		child->set_size(csize);
	}

	cpos.y+=csize.y+margin;
	csize.y=hminsize.y;

	hbc->set_pos(cpos);
	hbc->set_size(csize);

}
コード例 #13
0
Point2 ShaderEditor::_get_slot_pos(int p_node_id,bool p_input,int p_slot) {

	Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
	float w = get_node_size(p_node_id).width;
	Ref<Font> font = get_font("font","PopupMenu");
	float h = font->get_height()+get_constant("vseparation","PopupMenu");
	Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons");
	Point2 pos = Point2( shader_graph.node_get_pos_x(p_node_id), shader_graph.node_get_pos_y(p_node_id) )-offset;
	pos+=style->get_offset();
	pos.y+=h;

	if(p_input) {

		pos.y+=p_slot*h;
		pos+=Point2( -vec_icon->get_width()/2.0, h/2.0).floor();
		return pos;
	} else {

		pos.y+=VisualServer::shader_get_input_count( shader_graph.node_get_type(p_node_id ) )*h;
	}

	pos.y+=p_slot*h;
	pos+=Point2( w-style->get_minimum_size().width+vec_icon->get_width()/2.0, h/2.0).floor();

	return pos;

}
コード例 #14
0
ファイル: tabs.cpp プロジェクト: 3miu/godot
Size2 Tabs::get_minimum_size() const {


	Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
	Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
	Ref<Font> font = get_font("font");

	Size2 ms(0, MAX( tab_bg->get_minimum_size().height,tab_fg->get_minimum_size().height)+font->get_height() );

//	h+=MIN( get_constant("label_valign_fg"), get_constant("label_valign_bg") );

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

		Ref<Texture> tex = tabs[i].icon;
		if (tex.is_valid()) {
			ms.height = MAX( ms.height, tex->get_size().height );
			if (tabs[i].text!="")
				ms.width+=get_constant("hseparation");

		}
		ms.width+=font->get_string_size(tabs[i].text).width;
		if (current==i)
			ms.width+=tab_fg->get_minimum_size().width;
		else
			ms.width+=tab_bg->get_minimum_size().width;


	}

	return ms;
}
コード例 #15
0
ファイル: tab_container.cpp プロジェクト: rrrfffrrr/godot
int TabContainer::_get_tab_width(int p_index) const {
	Control *control = _get_tabs()[p_index]->cast_to<Control>();
	if (!control || control->is_set_as_toplevel())
		return 0;

	// Get the width of the text displayed on the tab.
	Ref<Font> font = get_font("font");
	String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name());
	int width = font->get_string_size(text).width;

	// Add space for a tab icon.
	if (control->has_meta("_tab_icon")) {
		Ref<Texture> icon = control->get_meta("_tab_icon");
		if (icon.is_valid()) {
			width += icon->get_width();
			if (text != "")
				width += get_constant("hseparation");
		}
	}

	// Respect a minimum size.
	Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
	Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
	Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
	if (get_tab_disabled(p_index)) {
		width += tab_disabled->get_minimum_size().width;
	} else if (p_index == current) {
		width += tab_fg->get_minimum_size().width;
	} else {
		width += tab_bg->get_minimum_size().width;
	}

	return width;
}
コード例 #16
0
ファイル: theme.cpp プロジェクト: nitpum/godot
bool Theme::_get(const StringName& p_name,Variant &r_ret) const {

    String sname=p_name;

    if (sname.find("/")!=-1) {

        String type=sname.get_slicec('/',1);
        String node_type=sname.get_slicec('/',0);
        String name=sname.get_slicec('/',2);

        if (type=="icons") {

            r_ret= get_icon(name,node_type);
        } else if (type=="styles") {

            r_ret= get_stylebox(name,node_type);
        } else if (type=="fonts") {

            r_ret= get_font(name,node_type);
        } else if (type=="colors") {

            r_ret= get_color(name,node_type);
        } else if (type=="constants") {

            r_ret= get_constant(name,node_type);
        } else
            return false;

        return true;
    }

    return false;
}
コード例 #17
0
ファイル: device.c プロジェクト: Synapseware/avra
// Pre-define devices. B.A. : Return value change from void to int 
int predef_dev(struct prog_info *pi) 
{
	int i;
	char temp[MAX_DEV_NAME+1];
	def_dev(pi);
	for (i=0;(!i)||(device_list[i].name);i++) {
		strncpy(temp,DEV_PREFIX,MAX_DEV_NAME);
		if (!i) strncat(temp,DEF_DEV_NAME,MAX_DEV_NAME);
		else strncat(temp,device_list[i].name,MAX_DEV_NAME);
		strncat(temp,DEV_SUFFIX,MAX_DEV_NAME);
		/* B.A. : New. Forward references allowed. But check, if everything is ok ... */
		if(pi->pass==PASS_1) { /* Pass 1 */
      if(test_constant(pi,temp,NULL)!=NULL) {
        fprintf(stderr,"Error: Can't define symbol %s twice. Please don't use predefined symbols !\n", temp);
        return(False);
      }
      if(def_const(pi, temp, i)==False)
        return(False);
	  } else { /* Pass 2 */
			int j;
			if(get_constant(pi, temp, &j)==False) {   /* Defined in Pass 1 and now missing ? */
   	    fprintf(stderr,"Constant %s is missing in pass 2\n",temp);
 	      return(False);
			}
		  if(i != j) {
 	      fprintf(stderr,"Constant %s changed value from %d in pass1 to %d in pass 2\n",temp,j,i);
 	      return(False);
			}
			/* OK. definition is unchanged */
	  }
	}
	return(True);
}
コード例 #18
0
ファイル: split_container.cpp プロジェクト: AMG194/godot
Control::CursorShape SplitContainer::get_cursor_shape(const Point2& p_pos) {

	if (collapsed)
		return Control::get_cursor_shape(p_pos);

	if (dragging)
		return (vertical?CURSOR_VSIZE:CURSOR_HSIZE);

	int sep=get_constant("separation");

	if (vertical) {


		if (p_pos.y > middle_sep && p_pos.y < middle_sep+sep) {
			return CURSOR_VSIZE;
		}
	} else {

		if (p_pos.x > middle_sep && p_pos.x < middle_sep+sep) {
			return CURSOR_HSIZE;
		}
	}

	return Control::get_cursor_shape(p_pos);

}
コード例 #19
0
ファイル: tabs.cpp プロジェクト: brakhane/godot
Size2 Tabs::get_minimum_size() const {

	Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
	Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
	Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
	Ref<Font> font = get_font("font");

	Size2 ms(0, MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height) + font->get_height());

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

		Ref<Texture> tex = tabs[i].icon;
		if (tex.is_valid()) {
			ms.height = MAX(ms.height, tex->get_size().height);
			if (tabs[i].text != "")
				ms.width += get_constant("hseparation");
		}

		ms.width += font->get_string_size(tabs[i].text).width;

		if (tabs[i].disabled)
			ms.width += tab_disabled->get_minimum_size().width;
		else if (current == i)
			ms.width += tab_fg->get_minimum_size().width;
		else
			ms.width += tab_bg->get_minimum_size().width;

		if (tabs[i].right_button.is_valid()) {
			Ref<Texture> rb = tabs[i].right_button;
			Size2 bms = rb->get_size();
			bms.width += get_constant("hseparation");
			ms.width += bms.width;
			ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
		}

		if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
			Ref<Texture> cb = get_icon("close");
			Size2 bms = cb->get_size();
			bms.width += get_constant("hseparation");
			ms.width += bms.width;
			ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
		}
	}

	ms.width = 0; //TODO: should make this optional
	return ms;
}
コード例 #20
0
ShaderEditor::ClickType ShaderEditor::_locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const {

	Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
	Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons");
	Ref<Font> font = get_font("font","PopupMenu");
	float h = font->get_height()+get_constant("vseparation","PopupMenu");
	float extra_left=MAX( real_icon->get_width()-style->get_margin(MARGIN_LEFT), 0 );
	float extra_right=MAX( real_icon->get_width()-style->get_margin(MARGIN_RIGHT), 0 );


	for(const List<int>::Element *E=order.back();E;E=E->prev()) {

		Size2 size=get_node_size(E->get());
		size.width+=extra_left+extra_right;
		Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) )-offset;
		pos.x-=extra_left;

		Rect2 rect( pos, size );
		if (!rect.has_point(p_click))
			continue;
		VisualServer::ShaderNodeType type=shader_graph.node_get_type(E->get());
		if (p_node_id)
			*p_node_id=E->get();
		float y=p_click.y-(pos.y+style->get_margin(MARGIN_TOP));
		if (y<h)
			return CLICK_NODE;
		y-=h;

		for(int i=0;i<VisualServer::shader_get_input_count(type);i++) {

			if (y<h) {
				if (p_slot_index)
					*p_slot_index=i;
				return CLICK_INPUT_SLOT;
			}
			y-=h;
		}

		for(int i=0;i<VisualServer::shader_get_output_count(type);i++) {

			if (y<h) {
				if (p_slot_index)
					*p_slot_index=i;
				return CLICK_OUTPUT_SLOT;
			}
			y-=h;
		}

		if (p_click.y<(rect.pos.y+rect.size.height-style->get_margin(MARGIN_BOTTOM)))
			return CLICK_PARAMETER;
		else
			return CLICK_NODE;

	}

	return CLICK_NONE;

}
コード例 #21
0
ファイル: option_button.cpp プロジェクト: 93i/godot
Size2 OptionButton::get_minimum_size() const {

	Size2 minsize = Button::get_minimum_size();

	if (has_icon("arrow"))
		minsize.width += Control::get_icon("arrow")->get_width() + get_constant("hseparation");

	return minsize;
}
コード例 #22
0
ファイル: split_container.cpp プロジェクト: AMG194/godot
void SplitContainer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_SORT_CHILDREN: {

			_resort();
		} break;
		case NOTIFICATION_MOUSE_ENTER: {
			mouse_inside=true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {
			mouse_inside=false;
			update();
		} break;
		case NOTIFICATION_DRAW: {

			if (!_getch(0) || !_getch(1))
				return;

			if (collapsed || (!mouse_inside && get_constant("autohide")))
				return;
			int sep=dragger_visible?get_constant("separation"):0;
			Ref<Texture> tex = get_icon("grabber");
			Size2 size=get_size();
			if (vertical) {

				//draw_style_box( get_stylebox("bg"), Rect2(0,middle_sep,get_size().width,sep));
				if (dragger_visible)
					draw_texture(tex,Point2i((size.x-tex->get_width())/2,middle_sep+(sep-tex->get_height())/2));

			} else {

				//draw_style_box( get_stylebox("bg"), Rect2(middle_sep,0,sep,get_size().height));
				if (dragger_visible)
					draw_texture(tex,Point2i(middle_sep+(sep-tex->get_width())/2,(size.y-tex->get_height())/2));

			}

		} break;
	}
}
コード例 #23
0
ファイル: dialogs.cpp プロジェクト: AutonomicStudios/godot
bool WindowDialog::has_point(const Point2& p_point) const {


	int extra = get_constant("titlebar_height","WindowDialog");
	Rect2 r( Point2(), get_size() );
	r.pos.y-=extra;
	r.size.y+=extra;
	return r.has_point(p_point);

}
コード例 #24
0
ファイル: tabs.cpp プロジェクト: brakhane/godot
int Tabs::get_tab_width(int p_idx) const {

	ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0);

	Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
	Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
	Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
	Ref<Font> font = get_font("font");

	int x = 0;

	Ref<Texture> tex = tabs[p_idx].icon;
	if (tex.is_valid()) {
		x += tex->get_width();
		if (tabs[p_idx].text != "")
			x += get_constant("hseparation");
	}

	x += font->get_string_size(tabs[p_idx].text).width;

	if (tabs[p_idx].disabled)
		x += tab_disabled->get_minimum_size().width;
	else if (current == p_idx)
		x += tab_fg->get_minimum_size().width;
	else
		x += tab_bg->get_minimum_size().width;

	if (tabs[p_idx].right_button.is_valid()) {
		Ref<Texture> rb = tabs[p_idx].right_button;
		x += rb->get_width();
		x += get_constant("hseparation");
	}

	if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) {
		Ref<Texture> cb = get_icon("close");
		x += cb->get_width();
		x += get_constant("hseparation");
	}

	return x;
}
コード例 #25
0
ファイル: ef_encode.c プロジェクト: Aishinjiaolo/ettercap
/*
 * assing the value of the const to the fop.value
 *
 * all the value are integer32 and are saved in host order
 */
int encode_const(char *string, struct filter_op *fop)
{
   char *p;
   
   memset(fop, 0, sizeof(struct filter_op));
   
   /* it is an hexadecimal value */
   if (!strncmp(string, "0x", 2) && isdigit((int)string[2])) {
      fop->op.test.value = strtoul(string, NULL, 16);
      return ESUCCESS;
      
   /* it is an integer value */
   } else if (isdigit((int)string[0])) {
      fop->op.test.value = strtoul(string, NULL, 10);
      return ESUCCESS;
      
   /* it is an ip address */
   } else if (string[0] == '\'' && string[strlen(string) - 1] == '\'') {
      struct in_addr ipaddr;
      
      /* remove the single quote */
      p = strchr(string + 1, '\'');
      *p = '\0';

      if (inet_aton(string + 1, &ipaddr) == 0)
         return -EFATAL;
      
      fop->op.test.value = ntohl(ipaddr.s_addr);
      return ESUCCESS;
      
   /* it is a string */
   } else if (string[0] == '\"' && string[strlen(string) - 1] == '\"') {
  
      /* remove the quotes */
      p = strchr(string + 1, '\"');
      *p = '\0';

      /* copy the string */
      fop->op.test.string = (u_char*)strdup(string + 1);
         
      /* escape it in the structure */
      fop->op.test.slen = strescape((char*)fop->op.test.string, (char*)fop->op.test.string);
     
      return ESUCCESS;
      
   /* it is a constant */
   } else if (isalpha((int)string[0])) {
      return get_constant(string, &fop->op.test.value);
   }
   
   /* anything else is an error */
   return -ENOTFOUND;
}
コード例 #26
0
ファイル: graph_node.cpp プロジェクト: Max-Might/godot
void GraphNode::_resort() {

	int sep = get_constant("separation");
	Ref<StyleBox> sb = get_stylebox("frame");
	bool first = true;

	Size2 minsize;

	for (int i = 0; i < get_child_count(); i++) {
		Control *c = get_child(i)->cast_to<Control>();
		if (!c)
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size = c->get_combined_minimum_size();

		minsize.y += size.y;
		minsize.x = MAX(minsize.x, size.x);

		if (first)
			first = false;
		else
			minsize.y += sep;
	}

	int vofs = 0;
	int w = get_size().x - sb->get_minimum_size().x;

	cache_y.clear();
	for (int i = 0; i < get_child_count(); i++) {
		Control *c = get_child(i)->cast_to<Control>();
		if (!c)
			continue;
		if (c->is_set_as_toplevel())
			continue;

		Size2i size = c->get_combined_minimum_size();

		Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y);

		fit_child_in_rect(c, r);
		cache_y.push_back(vofs + size.y * 0.5);

		if (vofs > 0)
			vofs += sep;
		vofs += size.y;
	}

	_change_notify();
	update();
	connpos_dirty = true;
}
コード例 #27
0
ファイル: button_array.cpp プロジェクト: jay3d/godot
Size2 ButtonArray::get_minimum_size() const {

    Ref<StyleBox> style_normal = get_stylebox("normal");
    Ref<StyleBox> style_selected = get_stylebox("selected");
    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");

    Size2 minsize;

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

        Ref<StyleBox> sb = i==selected ? style_selected : style_normal;
        Ref<Font> f = i==selected ? font_selected : font_normal;

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

            Size2 bs = buttons[i].icon->get_size();
            ms.height = MAX(ms.height,bs.height);
            ms.width+=bs.width+icon_sep;
        }

        ms+=sb->get_minimum_size();

        buttons[i]._ms_cache=ms[orientation];

        minsize[orientation]+=ms[orientation];
        if (i>0)
            minsize[orientation]+=button_sep;
        minsize[!orientation] = MAX(minsize[!orientation],ms[!orientation]);

    }

    return minsize;


}
コード例 #28
0
SwitchMethodPartitioning::SwitchMethodPartitioning(IRCode* code,
                                                   bool verify_default_case)
    : m_code(code) {
  m_code->build_cfg(/* editable */ true);
  auto& cfg = m_code->cfg();
  // Note that a single-case switch can be compiled as either a switch opcode or
  // a series of if-* opcodes. We can use constant propagation to handle these
  // cases uniformly: to determine the case key, we use the inferred value of
  // the operand to the branching opcode in the successor blocks.
  cp::intraprocedural::FixpointIterator fixpoint(
      cfg, cp::ConstantPrimitiveAnalyzer());
  fixpoint.run(ConstantEnvironment());

  auto determining_reg =
      compute_prologue_blocks(&cfg, fixpoint, verify_default_case);

  // Find all the outgoing edges from the prologue blocks
  std::vector<cfg::Edge*> cases;
  for (const cfg::Block* prologue : m_prologue_blocks) {
    for (cfg::Edge* e : prologue->succs()) {
      if (std::find(m_prologue_blocks.begin(), m_prologue_blocks.end(),
                    e->target()) == m_prologue_blocks.end()) {
        cases.push_back(e);
      }
    }
  }

  for (auto edge : cases) {
    auto case_block = edge->target();
    auto env = fixpoint.get_entry_state_at(case_block);
    auto case_key = env.get<SignedConstantDomain>(*determining_reg);
    if (case_key.is_top() && verify_default_case) {
      auto last_insn_it = case_block->get_last_insn();
      always_assert_log(last_insn_it != case_block->end() &&
                            last_insn_it->insn->opcode() == OPCODE_THROW,
                        "Could not determine key for block that does not look "
                        "like it throws an IllegalArgumentException: %d in %s",
                        case_block->id(), SHOW(cfg));
    } else if (!case_key.is_top()) {
      const auto& c = case_key.get_constant();
      if (c != boost::none) {
        m_key_to_block[*c] = case_block;
      } else {
        // handle multiple case keys that map to a single block
        always_assert(edge->type() == cfg::EDGE_BRANCH);
        const auto& edge_case_key = edge->case_key();
        always_assert(edge_case_key != boost::none);
        m_key_to_block[*edge_case_key] = case_block;
      }
    }
  }
}
コード例 #29
0
ファイル: split_container.cpp プロジェクト: brakhane/godot
void SplitContainer::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_SORT_CHILDREN: {

			_resort();
		} break;
		case NOTIFICATION_MOUSE_ENTER: {

			mouse_inside = true;
			update();
		} break;
		case NOTIFICATION_MOUSE_EXIT: {

			mouse_inside = false;
			update();
		} break;
		case NOTIFICATION_DRAW: {

			if (!_getch(0) || !_getch(1))
				return;

			if (collapsed || (!mouse_inside && get_constant("autohide")))
				return;

			int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0;
			Ref<Texture> tex = get_icon("grabber");
			Size2 size = get_size();
			if (dragger_visibility == DRAGGER_VISIBLE) {

				if (vertical)
					draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
				else
					draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
			}
		} break;
	}
}
コード例 #30
0
ファイル: check_box.cpp プロジェクト: angjminer/godot
Size2 CheckBox::get_minimum_size() const {

	Size2 minsize = Button::get_minimum_size();
	Size2 tex_size = get_icon_size();
	minsize.width += tex_size.width;
	if (get_text().length() > 0) {
		minsize.width += get_constant("hseparation");
	}
	Ref<StyleBox> sb = get_stylebox("normal");
	minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM));

	return minsize;
}