Exemple #1
0
Size2 ViewportContainer::get_minimum_size() const {

	if (stretch)
		return Size2();
	Size2 ms;
	for (int i = 0; i < get_child_count(); i++) {

		Viewport *c = Object::cast_to<Viewport>(get_child(i));
		if (!c)
			continue;

		Size2 minsize = c->get_size();
		ms.width = MAX(ms.width, minsize.width);
		ms.height = MAX(ms.height, minsize.height);
	}

	return ms;
}
Exemple #2
0
void Font::_set_chars(const DVector<int>& p_chars) {

	int len = p_chars.size();
	//char 1 charsize 1 texture, 4 rect, 2 align, advance 1
	ERR_FAIL_COND(len%9);
	if (!len)
		return; //none to do
	int chars = len/9;


	DVector<int>::Read r=p_chars.read();
	for(int i=0;i<chars;i++) {

		const int* data = &r[i*9];
		add_char(data[0],data[1],Rect2(data[2],data[3],data[4],data[5]), Size2(data[6],data[7]),data[8]);
	}

}
Exemple #3
0
void ProjectExportDialog::_export_project_to_path(const String &p_path) {
	// Save this name for use in future exports (but drop the file extension)
	default_filename = p_path.get_basename().get_file();
	EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);

	Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
	ERR_FAIL_COND(current.is_null());
	Ref<EditorExportPlatform> platform = current->get_platform();
	ERR_FAIL_COND(platform.is_null());

	Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
	if (err != OK) {
		error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted: ") + platform->get_name());
		error_dialog->show();
		error_dialog->popup_centered_minsize(Size2(300, 80));
		ERR_PRINT("Failed to export project");
	}
}
SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) {

    editor=p_node;
    sample_library_editor = memnew( SampleLibraryEditor );

    //editor->get_viewport()->add_child(sample_library_editor);
    sample_library_editor->set_custom_minimum_size(Size2(0,250));
    button=p_node->add_bottom_panel_item("SampleLibrary",sample_library_editor);
    button->hide();

    //sample_library_editor->set_area_as_parent_rect();
//	sample_library_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
//	sample_library_editor->set_margin( MARGIN_TOP, 120 );
    //sample_library_editor->hide();



}
Exemple #5
0
bool SceneTreeDock::_validate_no_foreign() {

	List<Node*> selection = editor_selection->get_selected_node_list();

	for (List<Node*>::Element *E=selection.front();E;E=E->next()) {

		if (E->get()!=edited_scene && E->get()->get_owner()!=edited_scene) {

			accept->get_ok()->set_text("Makes Sense!");
			accept->set_text("Can't operate on nodes from a foreign scene!");
			accept->popup_centered(Size2(300,70));;
			return false;

		}
	}

	return true;
}
Exemple #6
0
void EditorPath::_gui_input(const InputEvent& p_event) {

	if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) {


		Object *obj = ObjectDB::get_instance(history->get_path_object( history->get_path_size()-1));
		if (!obj)
			return;



		objects.clear();
		popup->clear();
		_add_children_to_popup(obj);
		popup->set_pos( get_global_pos() + Vector2(0,get_size().height));
		popup->set_size( Size2(get_size().width,1));
		popup->popup();
	}
}
Exemple #7
0
bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {

	if (p_name == "image_data") {

	} else if (p_name == "image")
		r_ret = get_data();
	else if (p_name == "flags")
		r_ret = flags;
	else if (p_name == "size")
		r_ret = Size2(w, h);
	else if (p_name == "storage")
		r_ret = storage;
	else if (p_name == "lossy_quality")
		r_ret = lossy_storage_quality;
	else
		return false;

	return true;
}
	void popup_import(const String& p_path) {

		popup_centered(Size2(400, 100)*EDSCALE);
		if (p_path != "") {

			Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
			ERR_FAIL_COND(!rimd.is_valid());

			save_path->set_text(p_path.get_base_dir());

			String src = "";
			for (int i = 0; i<rimd->get_source_count(); i++) {
				if (i>0)
					src += ",";
				src += EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
			}
			import_path->set_text(src);
		}
	}
StyleBoxEditor::StyleBoxEditor() {

	panel = memnew( Panel );
	add_child(panel);
	panel->set_area_as_parent_rect();

	Label *l = memnew( Label );
	l->set_text(TTR("StyleBox Preview:"));
	l->set_pos(Point2(5,5));
	panel->add_child(l);


	preview = memnew( Panel );
	panel->add_child(preview);
	preview->set_pos(Point2(50,50));
	preview->set_size(Size2(200,100));


}
void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {

	if (p_image.is_null() || p_image->empty())
		return;

	int window_w = OS::get_singleton()->get_video_mode(0).width;
	int window_h = OS::get_singleton()->get_video_mode(0).height;

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glViewport(0, 0, window_w, window_h);
	glDisable(GL_BLEND);
	glDepthMask(GL_FALSE);
	if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
		glClearColor(0.0, 0.0, 0.0, 0.0);
	} else {
		glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
	}
	glClear(GL_COLOR_BUFFER_BIT);

	canvas->canvas_begin();

	RID texture = storage->texture_create();
	storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_FILTER);
	storage->texture_set_data(texture, p_image);

	Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
	Rect2 screenrect;

	screenrect = imgrect;
	screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();

	RasterizerStorageGLES2::Texture *t = storage->texture_owner.get(texture);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, t->tex_id);
	canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
	glBindTexture(GL_TEXTURE_2D, 0);
	canvas->canvas_end();

	storage->free(texture);

	end_frame(true);
}
void TileSetEditor::_name_dialog_confirm(const String &name) {

	switch (option) {

		case MENU_OPTION_REMOVE_ITEM: {

			int id = tileset->find_tile_by_name(name);

			if (id < 0 && name.is_valid_integer())
				id = name.to_int();

			if (tileset->has_tile(id)) {
				tileset->remove_tile(id);
			} else {
				err_dialog->set_text(TTR("Could not find tile:") + " " + name);
				err_dialog->popup_centered(Size2(300, 60));
			}
		} break;
	}
}
Exemple #12
0
void BitMap::create_from_image_alpha(const Image &p_image) {

	ERR_FAIL_COND(p_image.empty());
	Image img = p_image;
	img.convert(Image::FORMAT_LA8);
	ERR_FAIL_COND(img.get_format() != Image::FORMAT_LA8);

	create(Size2(img.get_width(), img.get_height()));

	PoolVector<uint8_t>::Read r = img.get_data().read();
	uint8_t *w = bitmask.ptr();

	for (int i = 0; i < width * height; i++) {

		int bbyte = i / 8;
		int bbit = i % 8;
		if (r[i * 2])
			w[bbyte] |= (1 << bbit);
	}
}
Exemple #13
0
Size2 TextureButton::get_minimum_size() const {

	Size2 rscale;
	if (normal.is_null()) {
		if (pressed.is_null()) {
			if (hover.is_null())
				if (click_mask.is_null())
					rscale= Size2();
				else
					rscale= click_mask->get_size();
			else
				rscale= hover->get_size();
		} else
			rscale= pressed->get_size()*scale;

	} else
		rscale= normal->get_size();

	return rscale*scale;
}
void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) {

	polygon=p_polygon;

	for(int i=0;i<polygon.size();i++) {
		if (i==0)
			aabb=Rect2(polygon[i],Size2());
		else
			aabb.expand_to(polygon[i]);
	}
	if (aabb==Rect2()) {

		aabb=Rect2(-10,-10,20,20);
	} else {
		aabb.pos-=aabb.size*0.3;
		aabb.size+=aabb.size*0.6;
	}
	_update_parent();
	update();
}
void EditorTextureImportDialog::popup_import(const String& p_from) {

	popup_centered(Size2(400,400));
	if (p_from!="") {
		Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
		ERR_FAIL_COND(!rimd.is_valid());

		save_path->set_text(p_from.get_base_dir());
		texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("format"))));
		texture_options->set_flags(rimd->get_option("flags"));
		texture_options->set_quality(rimd->get_option("quality"));
		String src = "";
		for(int i=0;i<rimd->get_source_count();i++) {
			if (i>0)
				src+=",";
			src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
		}
		import_path->set_text(src);
	}
}
Exemple #16
0
bool SceneTree::idle(float p_time){


//	print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage()));
//	print_line("node count: "+itos(get_node_count()));
//	print_line("TEXTURE RAM: "+itos(VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED)));

	root_lock++;

	MainLoop::idle(p_time);

	idle_process_time=p_time;

	emit_signal("idle_frame");

	_flush_transform_notifications();

	_notify_group_pause("idle_process",Node::NOTIFICATION_PROCESS);

	Size2 win_size=Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
	if(win_size!=last_screen_size) {


		last_screen_size=win_size;
		_update_root_rect();


		emit_signal("screen_resized");

	}

	_flush_ugc();
	_flush_transform_notifications(); //transforms after world update, to avoid unnecesary enter/exit notifications
	call_group(GROUP_CALL_REALTIME,"_viewports","update_worlds");

	root_lock--;

	_flush_delete_queue();

	return _quit;
}
void CPUParticles2D::_update_mesh_texture() {

	Size2 tex_size;
	if (texture.is_valid()) {
		tex_size = texture->get_size();
	} else {
		tex_size = Size2(1, 1);
	}
	PoolVector<Vector2> vertices;
	vertices.push_back(-tex_size * 0.5);
	vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0));
	vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, tex_size.y));
	vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y));
	PoolVector<Vector2> uvs;
	uvs.push_back(Vector2(0, 0));
	uvs.push_back(Vector2(1, 0));
	uvs.push_back(Vector2(1, 1));
	uvs.push_back(Vector2(0, 1));
	PoolVector<Color> colors;
	colors.push_back(Color(1, 1, 1, 1));
	colors.push_back(Color(1, 1, 1, 1));
	colors.push_back(Color(1, 1, 1, 1));
	colors.push_back(Color(1, 1, 1, 1));
	PoolVector<int> indices;
	indices.push_back(0);
	indices.push_back(1);
	indices.push_back(2);
	indices.push_back(2);
	indices.push_back(3);
	indices.push_back(0);

	Array arr;
	arr.resize(VS::ARRAY_MAX);
	arr[VS::ARRAY_VERTEX] = vertices;
	arr[VS::ARRAY_TEX_UV] = uvs;
	arr[VS::ARRAY_COLOR] = colors;
	arr[VS::ARRAY_INDEX] = indices;

	VS::get_singleton()->mesh_clear(mesh);
	VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VS::PRIMITIVE_TRIANGLES, arr);
}
Exemple #18
0
void BitMap::create_from_image_alpha(const Ref<Image> &p_image, float p_threshold) {

	ERR_FAIL_COND(p_image.is_null() || p_image->empty());
	Ref<Image> img = p_image->duplicate();
	img->convert(Image::FORMAT_LA8);
	ERR_FAIL_COND(img->get_format() != Image::FORMAT_LA8);

	create(Size2(img->get_width(), img->get_height()));

	PoolVector<uint8_t>::Read r = img->get_data().read();
	uint8_t *w = bitmask.ptrw();

	for (int i = 0; i < width * height; i++) {

		int bbyte = i / 8;
		int bbit = i % 8;
		if (r[i * 2 + 1] / 255.0 > p_threshold) {
			w[bbyte] |= (1 << bbit);
		}
	}
}
Exemple #19
0
void EditorDirDialog::_make_dir_confirm() {

	TreeItem *ti = tree->get_selected();
	if (!ti)
		return;

	String dir = ti->get_metadata(0);

	DirAccessRef d = DirAccess::open(dir);
	ERR_FAIL_COND(!d);
	Error err = d->make_dir(makedirname->get_text());

	if (err != OK) {
		mkdirerr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
	} else {
		opened_paths.insert(dir);
		//reload(dir.plus_file(makedirname->get_text()));
		EditorFileSystem::get_singleton()->scan_changes(); //we created a dir, so rescan changes
	}
	makedirname->set_text(""); // reset label
}
Exemple #20
0
Size2 CenterContainer::get_minimum_size() const {

	if (use_top_left)
		return Size2();
	Size2 ms;
	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;
		if (!c->is_visible())
			continue;
		Size2 minsize = c->get_combined_minimum_size();
		ms.width = MAX(ms.width, minsize.width);
		ms.height = MAX(ms.height, minsize.height);
	}

	return ms;
}
Exemple #21
0
DependencyErrorDialog::DependencyErrorDialog() {

	VBoxContainer *vb = memnew(VBoxContainer);
	add_child(vb);

	files = memnew(Tree);
	files->set_hide_root(true);
	vb->add_margin_child(TTR("Scene failed to load due to missing dependencies:"), files, true);
	files->set_v_size_flags(SIZE_EXPAND_FILL);
	files->set_custom_minimum_size(Size2(1, 200));
	get_ok()->set_text(TTR("Open Anyway"));
	get_cancel()->set_text(TTR("Close"));

	text = memnew(Label);
	vb->add_child(text);
	text->set_text(TTR("Which action should be taken?"));

	fdep = add_button(TTR("Fix Dependencies"), true, "fixdeps");

	set_title(TTR("Errors loading!"));
}
void AnimationPlayerEditor::_animation_blend() {

	if (updating_blends)
		return;

	blend_editor.tree->clear();

	if (animation->get_item_count()==0)
		return;

	String current = animation->get_item_text(animation->get_selected());

	blend_editor.dialog->popup_centered(Size2(400,400));

	blend_editor.tree->set_hide_root(true);
	blend_editor.tree->set_column_min_width(0,10);
	blend_editor.tree->set_column_min_width(1,3);

	List<StringName> anims;
	player->get_animation_list(&anims);
	TreeItem *root = blend_editor.tree->create_item();
	updating_blends=true;

	for(List<StringName>::Element *E=anims.front();E;E=E->next()) {

		String to=E->get();
		TreeItem *blend=blend_editor.tree->create_item(root);
		blend->set_editable(0,false);
		blend->set_editable(1,true);
		blend->set_text(0,to);
		blend->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
		blend->set_range_config(1,0,3600,0.001);
		blend->set_range(1,player->get_blend_time(current,to));
	}

	blend_editor.next->set_text( player->animation_get_next(current) );

	updating_blends=false;
}
Exemple #23
0
Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next) const {

	const_cast<DynamicFontAtSize *>(this)->_update_char(p_char);

	const Character *c = char_map.getptr(p_char);
	ERR_FAIL_COND_V(!c, Size2());

	Size2 ret(c->advance, get_height());

	if (p_next) {
		DynamicFontData::KerningPairKey kpk;
		kpk.A = p_char;
		kpk.B = p_next;

		const Map<DynamicFontData::KerningPairKey, int>::Element *K = font->kerning_map.find(kpk);
		if (K) {
			ret.x += K->get() * scale;
		}
	}

	return ret;
}
Exemple #24
0
void ControlToolBar::MakeLoopImage()
{
   // JKC: See ToolBar::MakeButton() for almost identical code.  Condense??

   wxSize Size1( theTheme.ImageSize( bmpRecoloredUpLarge ));
   wxSize Size2( theTheme.ImageSize( bmpLoop ));

   int xoff = (Size1.GetWidth()  - Size2.GetWidth())/2;
   int yoff = (Size1.GetHeight() - Size2.GetHeight())/2;

   wxImage * up2        = OverlayImage(bmpRecoloredUpLarge,     bmpLoop, xoff, yoff);
   wxImage * hilite2    = OverlayImage(bmpRecoloredHiliteLarge, bmpLoop, xoff, yoff);
   wxImage * down2      = OverlayImage(bmpRecoloredDownLarge,   bmpLoop, xoff + 1, yoff + 1);
   wxImage * disable2   = OverlayImage(bmpRecoloredUpLarge,     bmpLoopDisabled, xoff, yoff);

   mPlay->SetAlternateImages(*up2, *hilite2, *down2, *disable2);

   delete up2;
   delete hilite2;
   delete down2;
   delete disable2;
}
void ProjectExportDialog::_export_all(bool p_debug) {

	String mode = p_debug ? TTR("Debug") : TTR("Release");
	EditorProgress ep("exportall", TTR("Exporting All") + " " + mode, EditorExport::get_singleton()->get_export_preset_count());

	for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
		Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
		ERR_FAIL_COND(preset.is_null());
		Ref<EditorExportPlatform> platform = preset->get_platform();
		ERR_FAIL_COND(platform.is_null());

		ep.step(preset->get_name(), i);

		Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0);
		if (err != OK) {
			error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " " + platform->get_name());
			error_dialog->show();
			error_dialog->popup_centered_minsize(Size2(300, 80));
			ERR_PRINT("Failed to export project");
		}
	}
}
Exemple #26
0
ScenesDockFilter::ScenesDockFilter() {

	_current_filter = FILTER_PATH;

	filter_option = memnew( OptionButton );
	filter_option->set_custom_minimum_size(Size2(60,10));
	filter_option->set_clip_text(true);
	filter_option->connect("item_selected", this, "_file_filter_selected");
	add_child(filter_option);

	_setup_filters();

	search_box = memnew( LineEdit );
	search_box->connect("text_changed",this,"_search_text_changed");
	search_box->set_h_size_flags(SIZE_EXPAND_FILL);
	add_child(search_box);

	clear_search_button = memnew( ToolButton );
	clear_search_button->connect("pressed",this,"_command",make_binds(CMD_CLEAR_FILTER));
	add_child(clear_search_button);

}
void BakedLightEditor::_bake_pressed() {

	ERR_FAIL_COND(!node);
	if (node->get_baked_light().is_null()) {
		err_dialog->set_text("BakedLightInstance does not contain a BakedLight resource.");
		err_dialog->popup_centered(Size2(350,70));
		button_bake->set_pressed(false);
		return;
	}

	if (baker->is_baking()) {

		baker->set_pause(!button_bake->is_pressed());
		if (baker->is_paused()) {

			set_process(false);
			bake_info->set_text("");
			button_reset->show();
			button_make_lightmaps->show();

		} else {

			update_timeout=0;
			set_process(true);
			button_make_lightmaps->hide();
			button_reset->hide();
		}
	} else {
		baker->bake(node->get_baked_light(),node);
		node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE);
		update_timeout=0;

		last_rays_time=0;

		set_process(true);
	}

}
Exemple #28
0
Size2 TextureButton::get_minimum_size() const {

	Size2 rscale = Control::get_minimum_size();

	if (!expand) {
		if (normal.is_null()) {
			if (pressed.is_null()) {
				if (hover.is_null())
					if (click_mask.is_null())
						rscale = Size2();
					else
						rscale = click_mask->get_size();
				else
					rscale = hover->get_size();
			} else
				rscale = pressed->get_size();

		} else
			rscale = normal->get_size();
	}

	return rscale.abs();
}
Exemple #29
0
void Popup::popup_centered(const Size2 &p_size) {

	Point2 window_size = get_viewport_rect().size;

	emit_signal("about_to_show");
	Rect2 rect;
	rect.size = p_size == Size2() ? get_size() : p_size;

	rect.position = ((window_size - rect.size) / 2.0).floor();
	set_position(rect.position);
	set_size(rect.size);

	show_modal(exclusive);
	_fix_size();

	Control *focusable = find_next_valid_focus();
	if (focusable)
		focusable->grab_focus();

	_post_popup();
	notification(NOTIFICATION_POST_POPUP);
	popped_up = true;
}
TileMapEditor::TileMapEditor(EditorNode *p_editor) {

	node=NULL;
	canvas_item_editor=NULL;
	editor=p_editor;
	undo_redo = editor->get_undo_redo();

	int mw = EDITOR_DEF("tile_map/palette_min_width",80);
	Control *ec = memnew( Control);
	ec->set_custom_minimum_size(Size2(mw,0));
	add_child(ec);

	// Add tile palette
	palette = memnew( Tree );
	palette->set_v_size_flags(SIZE_EXPAND_FILL);
	add_child(palette);

	// Add menu items
	canvas_item_editor_hb = memnew( HBoxContainer );
	CanvasItemEditor::get_singleton()->add_control_to_menu_panel(canvas_item_editor_hb);
	canvas_item_editor_hb->add_child( memnew( VSeparator ));
	mirror_x = memnew( ToolButton );
	mirror_x->set_toggle_mode(true);
	mirror_x->set_tooltip("Mirror X (A)");
	mirror_x->set_focus_mode(FOCUS_NONE);
	canvas_item_editor_hb->add_child(mirror_x);
	mirror_y = memnew( ToolButton );
	mirror_y->set_toggle_mode(true);
	mirror_y->set_tooltip("Mirror Y (S)");
	mirror_y->set_focus_mode(FOCUS_NONE);
	canvas_item_editor_hb->add_child(mirror_y);
	canvas_item_editor_hb->hide();

	tool=TOOL_NONE;
	selection_active=false;
	mouse_over=false;
}