TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
	node_sprite = NULL;
	node_patch9 = NULL;
	obj_styleBox = Ref<StyleBoxTexture>(NULL);
	atlas_tex = Ref<AtlasTexture>(NULL);
	editor = p_editor;
	undo_redo = editor->get_undo_redo();

	snap_step = Vector2(10, 10);
	snap_separation = Vector2(0, 0);
	edited_margin = -1;
	drag_index = -1;
	drag = false;

	VBoxContainer *main_vb = memnew(VBoxContainer);
	add_child(main_vb);
	main_vb->set_area_as_parent_rect(0);
	HBoxContainer *hb_tools = memnew(HBoxContainer);
	main_vb->add_child(hb_tools);

	hb_tools->add_child(memnew(Label(TTR("Snap Mode:"))));

	snap_mode_button = memnew(MenuButton);
	hb_tools->add_child(snap_mode_button);
	snap_mode_button->set_text(TTR("<None>"));
	PopupMenu *p = snap_mode_button->get_popup();
	p->set_hide_on_checkable_item_selection(false);
	p->add_item(TTR("<None>"), 0);
	p->add_item(TTR("Pixel Snap"), 1);
	p->add_item(TTR("Grid Snap"), 2);
	p->add_item(TTR("Auto Slice"), 3);
	for (int i = 0; i < 4; i++)
		p->set_item_as_checkable(i, true);
	p->set_item_checked(0, true);
	p->connect("id_pressed", this, "_set_snap_mode");
	hb_grid = memnew(HBoxContainer);
	hb_tools->add_child(hb_grid);
	hb_grid->add_child(memnew(VSeparator));

	hb_grid->add_child(memnew(Label(TTR("Offset:"))));

	sb_off_x = memnew(SpinBox);
	sb_off_x->set_min(-256);
	sb_off_x->set_max(256);
	sb_off_x->set_step(1);
	sb_off_x->set_value(snap_offset.x);
	sb_off_x->set_suffix("px");
	sb_off_x->connect("value_changed", this, "_set_snap_off_x");
	hb_grid->add_child(sb_off_x);

	sb_off_y = memnew(SpinBox);
	sb_off_y->set_min(-256);
	sb_off_y->set_max(256);
	sb_off_y->set_step(1);
	sb_off_y->set_value(snap_offset.y);
	sb_off_y->set_suffix("px");
	sb_off_y->connect("value_changed", this, "_set_snap_off_y");
	hb_grid->add_child(sb_off_y);

	hb_grid->add_child(memnew(VSeparator));
	hb_grid->add_child(memnew(Label(TTR("Step:"))));

	sb_step_x = memnew(SpinBox);
	sb_step_x->set_min(-256);
	sb_step_x->set_max(256);
	sb_step_x->set_step(1);
	sb_step_x->set_value(snap_step.x);
	sb_step_x->set_suffix("px");
	sb_step_x->connect("value_changed", this, "_set_snap_step_x");
	hb_grid->add_child(sb_step_x);

	sb_step_y = memnew(SpinBox);
	sb_step_y->set_min(-256);
	sb_step_y->set_max(256);
	sb_step_y->set_step(1);
	sb_step_y->set_value(snap_step.y);
	sb_step_y->set_suffix("px");
	sb_step_y->connect("value_changed", this, "_set_snap_step_y");
	hb_grid->add_child(sb_step_y);

	hb_grid->add_child(memnew(VSeparator));
	hb_grid->add_child(memnew(Label(TTR("Separation:"))));

	sb_sep_x = memnew(SpinBox);
	sb_sep_x->set_min(0);
	sb_sep_x->set_max(256);
	sb_sep_x->set_step(1);
	sb_sep_x->set_value(snap_separation.x);
	sb_sep_x->set_suffix("px");
	sb_sep_x->connect("value_changed", this, "_set_snap_sep_x");
	hb_grid->add_child(sb_sep_x);

	sb_sep_y = memnew(SpinBox);
	sb_sep_y->set_min(0);
	sb_sep_y->set_max(256);
	sb_sep_y->set_step(1);
	sb_sep_y->set_value(snap_separation.y);
	sb_sep_y->set_suffix("px");
	sb_sep_y->connect("value_changed", this, "_set_snap_sep_y");
	hb_grid->add_child(sb_sep_y);

	hb_grid->hide();

	HBoxContainer *main_hb = memnew(HBoxContainer);
	main_vb->add_child(main_hb);
	edit_draw = memnew(Control);
	main_hb->add_child(edit_draw);
	main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
	edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);

	Control *separator = memnew(Control);
	separator->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	hb_tools->add_child(separator);

	icon_zoom = memnew(TextureRect);
	hb_tools->add_child(icon_zoom);

	zoom_out = memnew(ToolButton);
	zoom_out->connect("pressed", this, "_zoom_out");
	hb_tools->add_child(zoom_out);

	zoom_reset = memnew(ToolButton);
	zoom_reset->connect("pressed", this, "_zoom_reset");
	hb_tools->add_child(zoom_reset);

	zoom_in = memnew(ToolButton);
	zoom_in->connect("pressed", this, "_zoom_in");
	hb_tools->add_child(zoom_in);

	vscroll = memnew(VScrollBar);
	main_hb->add_child(vscroll);
	vscroll->connect("value_changed", this, "_scroll_changed");
	hscroll = memnew(HScrollBar);
	main_vb->add_child(hscroll);
	hscroll->connect("value_changed", this, "_scroll_changed");

	edit_draw->connect("draw", this, "_region_draw");
	edit_draw->connect("gui_input", this, "_region_input");
	draw_zoom = 1.0;
	updating_scroll = false;

	edit_draw->set_clip_contents(true);
}
示例#2
0
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {

	current_option=p_tool;

	switch(p_tool) {

		case TOOL_NEW: {


			//if (!_validate_no_foreign())
			//	break;
			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_INSTANCE: {

			Node *scene = edited_scene;

			if (!scene) {

				current_option=-1;
				//confirmation->get_cancel()->hide();
				accept->get_ok()->set_text("I see..");
				accept->set_text("This operation can't be done without a tree root.");
				accept->popup_centered_minsize();
				break;
			}

			//if (!_validate_no_foreign())
			//	break;

			file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
			List<String> extensions;
			ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions);
			file->clear_filters();
			for(int i=0;i<extensions.size();i++) {

				file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
			}

			//file->set_current_path(current_path);
			file->popup_centered_ratio();

		} break;
		case TOOL_REPLACE: {

			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_CONNECT: {

			Node *current = scene_tree->get_selected();
			if (!current)
				break;

			//if (!_validate_no_foreign())
			//	break;
			connect_dialog->popup_centered_ratio();
			connect_dialog->set_node(current);

		} break;
		case TOOL_GROUP: {

			Node *current = scene_tree->get_selected();
			if (!current)
				break;
			//if (!_validate_no_foreign())
			//	break;
			groups_editor->set_current(current);
			groups_editor->popup_centered_ratio();
		} break;
		case TOOL_SCRIPT: {

			Node *selected = scene_tree->get_selected();
			if (!selected)
				break;

			//if (!_validate_no_foreign())
			//	break;

			Ref<Script> existing = selected->get_script();
			if (existing.is_valid())
				editor->push_item(existing.ptr());
			else {
				String path = selected->get_filename();
				script_create_dialog->config(selected->get_type(),path);
				script_create_dialog->popup_centered(Size2(300,290));
				//script_create_dialog->popup_centered_minsize();

			}

		} break;
		case TOOL_MOVE_UP:
		case TOOL_MOVE_DOWN: {

			if (!scene_tree->get_selected())
				break;


			if (scene_tree->get_selected()==edited_scene) {


				current_option=-1;
				//accept->get_cancel()->hide();
				accept->get_ok()->set_text("I see..");
				accept->set_text("This operation can't be done on the tree root.");
				accept->popup_centered_minsize();
				break;
			}


			if (!_validate_no_foreign())
				break;

			bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN);
			bool MOVING_UP = !MOVING_DOWN;

			Node *common_parent = scene_tree->get_selected()->get_parent();
			List<Node*> selection = editor_selection->get_selected_node_list();
			selection.sort_custom<Node::Comparator>();  // sort by index
			if (MOVING_DOWN)
				selection.invert();

			int lowest_id = common_parent->get_child_count() - 1;
			int highest_id = 0;
			for (List<Node*>::Element *E = selection.front(); E; E = E->next()) {
				int index = E->get()->get_index();

				if (index > highest_id) highest_id = index;
				if (index < lowest_id) lowest_id = index;

				if (E->get()->get_parent() != common_parent)
					common_parent = NULL;
			}

			if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0))
				break; // one or more nodes can not be moved

			if (selection.size() == 1) editor_data->get_undo_redo().create_action("Move Node In Parent");
			if (selection.size() > 1) editor_data->get_undo_redo().create_action("Move Nodes In Parent");

			for (int i = 0; i < selection.size(); i++) {
				Node *top_node = selection[i];
				Node *bottom_node = selection[selection.size() - 1 - i];
				 
				ERR_FAIL_COND(!top_node->get_parent());
				ERR_FAIL_COND(!bottom_node->get_parent());

				int top_node_pos = top_node->get_index();
				int bottom_node_pos = bottom_node->get_index();

				int top_node_pos_next = top_node_pos + (MOVING_DOWN ? 1 : -1);
				int bottom_node_pos_next = bottom_node_pos + (MOVING_DOWN ? 1 : -1);

				editor_data->get_undo_redo().add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next);
				editor_data->get_undo_redo().add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos);
			}

			editor_data->get_undo_redo().commit_action();

		} break;
		case TOOL_DUPLICATE: {

			if (!edited_scene)
				break;


			if (editor_selection->is_selected(edited_scene)) {


				current_option=-1;
				//accept->get_cancel()->hide();
				accept->get_ok()->set_text("I see..");
				accept->set_text("This operation can't be done on the tree root.");
				accept->popup_centered_minsize();
				break;
			}

			if (!_validate_no_foreign())
				break;

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

			List<Node*> reselect;

			editor_data->get_undo_redo().create_action("Duplicate Node(s)");
			editor_data->get_undo_redo().add_do_method(editor_selection,"clear");

			Node *dupsingle=NULL;


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

				Node *node = E->get();
				Node *parent = node->get_parent();

				List<Node*> owned;
				node->get_owned_by(node->get_owner(),&owned);

				Map<Node*,Node*> duplimap;
				Node * dup = _duplicate(node,duplimap);

				ERR_CONTINUE(!dup);

				if (selection.size()==1)
					dupsingle=dup;

				String name = node->get_name();

				String nums;
				for(int i=name.length()-1;i>=0;i--) {
					CharType n=name[i];
					if (n>='0' && n<='9') {
						nums=String::chr(name[i])+nums;
					} else {
						break;
					}
				}

				int num=nums.to_int();
				if (num<1)
					num=1;
				else
					num++;

				String nnsep = _get_name_num_separator();
				name = name.substr(0,name.length()-nums.length()).strip_edges();
				if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) {
					name = name.substr(0,name.length()-nnsep.length());
				}
				String attempt = (name + nnsep + itos(num)).strip_edges();

				while(parent->has_node(attempt)) {
					num++;
					attempt = (name + nnsep + itos(num)).strip_edges();
				}

				dup->set_name(attempt);

				editor_data->get_undo_redo().add_do_method(parent,"add_child",dup);
				for (List<Node*>::Element *F=owned.front();F;F=F->next()) {

					if (!duplimap.has(F->get())) {

						continue;
					}
					Node *d=duplimap[F->get()];
					editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner());
				}
				editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup);
				editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup);								
				editor_data->get_undo_redo().add_do_reference(dup);

				ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();

				editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),attempt);
				editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+attempt));

				//parent->add_child(dup);
				//reselect.push_back(dup);
			}

			editor_data->get_undo_redo().commit_action();

			if (dupsingle)
				editor->push_item(dupsingle);





		} break;
		case TOOL_REPARENT: {


			if (!scene_tree->get_selected())
				break;


			if (editor_selection->is_selected(edited_scene)) {


				current_option=-1;
				//confirmation->get_cancel()->hide();
				accept->get_ok()->set_text("I see..");
				accept->set_text("This operation can't be done on the tree root.");
				accept->popup_centered_minsize();
				break;
			}

			if (!_validate_no_foreign())
				break;

			List<Node*> nodes = editor_selection->get_selected_node_list();
			Set<Node*> nodeset;
			for(List<Node*>::Element *E=nodes.front();E;E=E->next()) {

				nodeset.insert(E->get());
			}
			reparent_dialog->popup_centered_ratio();
			reparent_dialog->set_current( nodeset );

		} break;
		case TOOL_MULTI_EDIT: {

			Node*root=EditorNode::get_singleton()->get_edited_scene();
			if (!root)
				break;
			Ref<MultiNodeEdit> mne = memnew( MultiNodeEdit );
			for (const Map<Node*,Object*>::Element *E=EditorNode::get_singleton()->get_editor_selection()->get_selection().front();E;E=E->next()) {
				mne->add_node(root->get_path_to(E->key()));
			}

			EditorNode::get_singleton()->push_item(mne.ptr());

		} break;
		case TOOL_ERASE: {

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

			if (remove_list.empty())
				return;

			if (!_validate_no_foreign())
				break;

			if (p_confirm_override) {
				_delete_confirm();

				// hack, force 2d editor viewport to refresh after deletion
				if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton())
					editor->get_viewport_control()->update();

			} else {
				delete_dialog->set_text("Delete Node(s)?");
				delete_dialog->popup_centered_minsize();
			}



		} break;

	}

}
示例#3
0
ConnectDialog::ConnectDialog() {

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

	HBoxContainer *main_hb = memnew(HBoxContainer);
	vbc->add_child(main_hb);
	main_hb->set_v_size_flags(SIZE_EXPAND_FILL);

	VBoxContainer *vbc_left = memnew(VBoxContainer);
	main_hb->add_child(vbc_left);
	vbc_left->set_h_size_flags(SIZE_EXPAND_FILL);

	tree = memnew(SceneTreeEditor(false));
	tree->get_scene_tree()->connect("item_activated", this, "_ok");
	tree->connect("node_selected", this, "_tree_node_selected");

	vbc_left->add_margin_child(TTR("Connect To Node:"), tree, true);

	VBoxContainer *vbc_right = memnew(VBoxContainer);
	main_hb->add_child(vbc_right);
	vbc_right->set_h_size_flags(SIZE_EXPAND_FILL);

	HBoxContainer *add_bind_hb = memnew(HBoxContainer);

	type_list = memnew(OptionButton);
	type_list->set_h_size_flags(SIZE_EXPAND_FILL);
	add_bind_hb->add_child(type_list);
	type_list->add_item("bool", Variant::BOOL);
	type_list->add_item("int", Variant::INT);
	type_list->add_item("real", Variant::REAL);
	type_list->add_item("string", Variant::STRING);
	type_list->add_item("Vector2", Variant::VECTOR2);
	type_list->add_item("Rect2", Variant::RECT2);
	type_list->add_item("Vector3", Variant::VECTOR3);
	type_list->add_item("Plane", Variant::PLANE);
	type_list->add_item("Quat", Variant::QUAT);
	type_list->add_item("AABB", Variant::AABB);
	type_list->add_item("Basis", Variant::BASIS);
	type_list->add_item("Transform", Variant::TRANSFORM);
	type_list->add_item("Color", Variant::COLOR);
	type_list->select(0);

	Button *add_bind = memnew(Button);
	add_bind->set_text(TTR("Add"));
	add_bind_hb->add_child(add_bind);
	add_bind->connect("pressed", this, "_add_bind");

	Button *del_bind = memnew(Button);
	del_bind->set_text(TTR("Remove"));
	add_bind_hb->add_child(del_bind);
	del_bind->connect("pressed", this, "_remove_bind");

	vbc_right->add_margin_child(TTR("Add Extra Call Argument:"), add_bind_hb);

	bind_editor = memnew(EditorInspector);

	vbc_right->add_margin_child(TTR("Extra Call Arguments:"), bind_editor, true);

	dst_path = memnew(LineEdit);
	vbc->add_margin_child(TTR("Path to Node:"), dst_path);

	HBoxContainer *dstm_hb = memnew(HBoxContainer);
	vbc->add_margin_child("Method In Node:", dstm_hb);

	dst_method = memnew(LineEdit);
	dst_method->set_h_size_flags(SIZE_EXPAND_FILL);
	dstm_hb->add_child(dst_method);

	/*
	dst_method_list = memnew( MenuButton );
	dst_method_list->set_text("List...");
	dst_method_list->set_anchor( MARGIN_RIGHT, ANCHOR_END );
	dst_method_list->set_anchor( MARGIN_LEFT, ANCHOR_END );
	dst_method_list->set_anchor( MARGIN_TOP, ANCHOR_END );
	dst_method_list->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
	dst_method_list->set_begin( Point2( 70,59) );
	dst_method_list->set_end( Point2( 15,39  ) );
	*/

	make_callback = memnew(CheckButton);
	make_callback->set_toggle_mode(true);
	make_callback->set_pressed(EDITOR_DEF("text_editor/tools/create_signal_callbacks", true));
	make_callback->set_text(TTR("Make Function"));
	dstm_hb->add_child(make_callback);

	deferred = memnew(CheckButton);
	deferred->set_text(TTR("Deferred"));
	dstm_hb->add_child(deferred);

	oneshot = memnew(CheckButton);
	oneshot->set_text(TTR("Oneshot"));
	dstm_hb->add_child(oneshot);

	set_as_toplevel(true);

	cdbinds = memnew(ConnectDialogBinds);

	error = memnew(ConfirmationDialog);
	add_child(error);
	error->get_ok()->set_text(TTR("Close"));
	get_ok()->set_text(TTR("Connect"));
}
示例#4
0
MainLoop* test() {

	return memnew( TestMainLoop );

}
示例#5
0
RES ResourceFormatLoaderWAV::load(const String &p_path,const String& p_original_path) {

	Error err;
	FileAccess *file=FileAccess::open(p_path, FileAccess::READ,&err);

	ERR_FAIL_COND_V( err!=OK, RES() );

	/* CHECK RIFF */
	char riff[5];
	riff[4]=0;
	file->get_buffer((uint8_t*)&riff,4); //RIFF

	if (riff[0]!='R' || riff[1]!='I' || riff[2]!='F' || riff[3]!='F') {

		file->close();
		memdelete(file);
		ERR_FAIL_V( RES() );
	}


	/* GET FILESIZE */
	uint32_t filesize=file->get_32();

	/* CHECK WAVE */

	char wave[4];

	file->get_buffer((uint8_t*)&wave,4); //RIFF

	if (wave[0]!='W' || wave[1]!='A' || wave[2]!='V' || wave[3]!='E') {


		file->close();
		memdelete(file);
		ERR_EXPLAIN("Not a WAV file (no WAVE RIFF Header)")
		ERR_FAIL_V( RES() );
	}

	bool format_found=false;
	bool data_found=false;
	int format_bits=0;
	int format_channels=0;
	int format_freq=0;
	Sample::LoopFormat loop=Sample::LOOP_NONE;
	int loop_begin=0;
	int loop_end=0;


	Ref<Sample> sample( memnew( Sample ) );


	while (!file->eof_reached()) {


		/* chunk */
		char chunkID[4];
		file->get_buffer((uint8_t*)&chunkID,4); //RIFF

		/* chunk size */
		uint32_t chunksize=file->get_32();
		uint32_t file_pos=file->get_pos(); //save file pos, so we can skip to next chunk safely

		if (file->eof_reached()) {

			//ERR_PRINT("EOF REACH");
			break;
		}

		if (chunkID[0]=='f' && chunkID[1]=='m' && chunkID[2]=='t' && chunkID[3]==' ' && !format_found) {
			/* IS FORMAT CHUNK */

			uint16_t compression_code=file->get_16();


			if (compression_code!=1) {
				ERR_PRINT("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
				break;
			}

			format_channels=file->get_16();
			if (format_channels!=1 && format_channels !=2) {

				ERR_PRINT("Format not supported for WAVE file (not stereo or mono)");
				break;

			}

			format_freq=file->get_32(); //sampling rate

			file->get_32(); // average bits/second (unused)
			file->get_16(); // block align (unused)
			format_bits=file->get_16(); // bits per sample

			if (format_bits%8) {

				ERR_PRINT("Strange number of bits in sample (not 8,16,24,32)");
				break;
			}

			/* Dont need anything else, continue */
			format_found=true;
		}


		if (chunkID[0]=='d' && chunkID[1]=='a' && chunkID[2]=='t' && chunkID[3]=='a' && !data_found) {
			/* IS FORMAT CHUNK */
			data_found=true;

			if (!format_found) {
				ERR_PRINT("'data' chunk before 'format' chunk found.");
				break;

			}

			int frames=chunksize;

			frames/=format_channels;
			frames/=(format_bits>>3);

			/*print_line("chunksize: "+itos(chunksize));
			print_line("channels: "+itos(format_channels));
			print_line("bits: "+itos(format_bits));
*/
			sample->create(
					(format_bits==8) ? Sample::FORMAT_PCM8 : Sample::FORMAT_PCM16,
					(format_channels==2)?true:false,
					frames );
			sample->set_mix_rate( format_freq );

			int len=frames;
			if (format_channels==2)
				len*=2;
			if (format_bits>8)
				len*=2;

			DVector<uint8_t> data;
			data.resize(len);
			DVector<uint8_t>::Write dataw = data.write();
			void * data_ptr = dataw.ptr();

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


				for (int c=0;c<format_channels;c++) {


					if (format_bits==8) {
						// 8 bit samples are UNSIGNED

						uint8_t s = file->get_8();
						s-=128;
						int8_t *sp=(int8_t*)&s;

						int8_t *data_ptr8=&((int8_t*)data_ptr)[i*format_channels+c];

						*data_ptr8=*sp;

					} else {
						//16+ bits samples are SIGNED
						// if sample is > 16 bits, just read extra bytes

						uint32_t data=0;
						for (int b=0;b<(format_bits>>3);b++) {

							data|=((uint32_t)file->get_8())<<(b*8);
						}
						data<<=(32-format_bits);


						int32_t s=data;

						int16_t *data_ptr16=&((int16_t*)data_ptr)[i*format_channels+c];

						*data_ptr16=s>>16;
					}
				}

			}

			dataw=DVector<uint8_t>::Write();

			sample->set_data(data);


			if (file->eof_reached()) {
				file->close();
				memdelete(file);
				ERR_EXPLAIN("Premature end of file.");
				ERR_FAIL_V(RES());
			}
		}

		if (chunkID[0]=='s' && chunkID[1]=='m' && chunkID[2]=='p' && chunkID[3]=='l') {
			//loop point info!

			for(int i=0;i<10;i++)
				file->get_32(); // i wish to know why should i do this... no doc!

			loop=file->get_32()?Sample::LOOP_PING_PONG:Sample::LOOP_FORWARD;
			loop_begin=file->get_32();
			loop_end=file->get_32();

		}
		file->seek( file_pos+chunksize );
	}
示例#6
0
	virtual void init() {
	
		SceneMainLoop::init();


#if 0


		Viewport *vp = memnew( Viewport );
		vp->set_world( Ref<World>( memnew( World )));
		get_root()->add_child(vp);

		vp->set_rect(Rect2(0,0,256,256));
		vp->set_as_render_target(true);
		vp->set_render_target_update_mode(Viewport::RENDER_TARGET_UPDATE_ALWAYS);


		Camera *camera = memnew( Camera );
		vp->add_child(camera);
		camera->make_current();

		TestCube *testcube = memnew( TestCube );
		vp->add_child(testcube);
		testcube->set_transform(Transform( Matrix3().rotated(Vector3(0,1,0),Math_PI*0.25), Vector3(0,0,-8)));

		Sprite *sp = memnew( Sprite );
		sp->set_texture( vp->get_render_target_texture() );
//		sp->set_texture( ResourceLoader::load("res://ball.png") );
		sp->set_pos(Point2(300,300));
		get_root()->add_child(sp);


		return;
#endif

		Panel * frame = memnew( Panel );
		frame->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
		frame->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_END );
		frame->set_end( Point2(0,0) );
		
		get_root()->add_child( frame );

		Label *label = memnew( Label );

		label->set_pos( Point2( 80,90 ) );
		label->set_size( Point2( 170,80 ) );
		label->set_align( Label::ALIGN_FILL );
		//label->set_text("There");
		label->set_text("There was once upon a time a beautiful unicorn that loved to play with little girls...");

		frame->add_child(label);

		Button *button = memnew( Button );

		button->set_pos( Point2( 20,20 ) );
		button->set_size( Point2( 1,1 ) );
		button->set_text("This is a biggie button");


		frame->add_child( button );


#if 0
		Sprite *tf = memnew( Sprite );
		frame->add_child(tf);
		Image img;
		ImageLoader::load_image("LarvoClub.png",&img);

		img.resize(512,512);
		img.generate_mipmaps();
		img.compress();
		Ref<Texture> text = memnew( Texture );
		text->create_from_image(img);
		tf->set_texture(text);
		tf->set_pos(Point2(50,50));
		//tf->set_scale(Point2(0.3,0.3));


		return;
#endif

		Tree * tree = memnew( Tree );
		tree->set_columns(2);

		tree->set_pos( Point2( 230,210 ) );
		tree->set_size( Point2( 150,250 ) );


		TreeItem *item = tree->create_item();
		item->set_editable(0,true);
		item->set_text(0,"root");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		item->set_editable(0,true);
		item->set_text(0,"check");
		item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
		item->set_editable(1,true);
		item->set_text(1,"check2");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_range_config(0,0,20,0.1);
		item->set_range(0,2);
		item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog"));
		item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
		item->set_editable(1,true);
		item->set_range_config(1,0,20,0.1);
		item->set_range(1,3);

		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_text(0,"Have,Many,Several,Options!");
		item->set_range(0,2);

		item = tree->create_item( item );
		item->set_editable(0,true);
		item->set_text(0,"Gershwin!");

		frame->add_child(tree);

		//control = memnew( Control );
		//root->add_child( control );


		
		LineEdit *line_edit = memnew( LineEdit );
		
		line_edit->set_pos( Point2( 30,190 ) );
		line_edit->set_size( Point2( 180,1 ) );
		
		frame->add_child(line_edit);
		
		HScrollBar *hscroll = memnew( HScrollBar );
		
		hscroll->set_pos( Point2( 30,290 ) );
		hscroll->set_size( Point2( 180,1 ) );
		hscroll->set_max(10);
		hscroll->set_page(4);
		
		frame->add_child(hscroll);



		SpinBox *spin = memnew( SpinBox );

		spin->set_pos( Point2( 30,260 ) );
		spin->set_size( Point2( 120,1 ) );

		frame->add_child(spin);
		hscroll->share(spin);

		ProgressBar *progress = memnew( ProgressBar );

		progress->set_pos( Point2( 30,330 ) );
		progress->set_size( Point2( 120,1 ) );

		frame->add_child(progress);
		hscroll->share(progress);

		MenuButton *menu_button = memnew( MenuButton );
		
		menu_button->set_text("I'm a menu!");
		menu_button->set_pos( Point2( 30,380 ) );
		menu_button->set_size( Point2( 1,1 ) );
		
		frame->add_child(menu_button);		
		
		PopupMenu *popup = menu_button->get_popup();
		
		popup->add_item("Hello, testing");
		popup->add_item("My Dearest");
		popup->add_separator();
		popup->add_item("Popup");
		popup->add_check_item("Check Popup");
		popup->set_item_checked(4,true);		
				
		OptionButton *options = memnew( OptionButton );
		
		options->add_item("Hello, testing");
		options->add_item("My Dearest");
		
		options->set_pos( Point2( 230,180 ) );
		options->set_size( Point2( 1,1 ) );
		
		frame->add_child(options);		

		/*
		Tree * tree = memnew( Tree );
		tree->set_columns(2);
		
		tree->set_pos( Point2( 230,210 ) );
		tree->set_size( Point2( 150,250 ) );


		TreeItem *item = tree->create_item();
		item->set_editable(0,true);
		item->set_text(0,"root");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
		item->set_editable(0,true);
		item->set_text(0,"check");
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_range_config(0,0,20,0.1);
		item->set_range(0,2);
		item->add_button(0,Theme::get_default()->get_icon("folder","FileDialog"));
		item = tree->create_item( tree->get_root() );
		item->set_cell_mode(0, TreeItem::CELL_MODE_RANGE);
		item->set_editable(0,true);
		item->set_text(0,"Have,Many,Several,Options!");
		item->set_range(0,2);
		
		frame->add_child(tree);
*/


		RichTextLabel *richtext = memnew( RichTextLabel );

		richtext->set_pos( Point2( 600,210 ) );
		richtext->set_size( Point2( 180,250 ) );
		richtext->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,20);

		frame->add_child(richtext);


		richtext->add_text("Hello, My Friends!\n\nWelcome to the amazing world of ");

		richtext->add_newline();
		richtext->add_newline();

		richtext->push_color(Color(1,0.5,0.5));
		richtext->add_text("leprechauns");
		richtext->pop();

		richtext->add_text(" and ");
		richtext->push_color(Color(0,1.0,0.5));
		richtext->add_text("faeries.\n");
		richtext->pop();
		richtext->add_text("In this new episode, we will attemp to ");
		richtext->push_font(richtext->get_font("mono_font","Fonts"));
		richtext->push_color(Color(0.7,0.5,1.0));
		richtext->add_text("deliver something nice");
		richtext->pop();
		richtext->pop();
		richtext->add_text(" to all the viewers! Unfortunately, I need to ");
		richtext->push_underline();
		richtext->add_text("keep writing a lot of text");
		richtext->pop();
		richtext->add_text(" so the label control overflows and the scrollbar appears.\n");
		//richtext->push_indent(1);
		//richtext->add_text("By the way, testing indent levels! Yohohoho! Everything should appear to the right sightly here!\n");
		//richtext->pop();
		richtext->push_meta("http://www.scrollingcapabilities.xz");
		richtext->add_text("This allows to test for the scrolling capabilities ");
		richtext->pop();
		richtext->add_text("of the rich text label for huge text (not like this text will really be huge but, you know).\nAs long as it is so long that it will work nicely for a test/demo, then it's welcomed in my book...\nChanging subject, the day is cloudy today and I'm wondering if I'll get che chance to travel somewhere nice. Sometimes, watching the clouds from satellite images may give a nice insight about how pressure zones in our planet work, althogh it also makes it pretty obvious to see why most weather forecasts get it wrong so often.\nClouds are so difficult to predict!\nBut it's pretty cool how our civilization has adapted to having water falling from the sky each time it rains...");
		//richtext->add_text("Hello!\nGorgeous..");


		//richtext->push_meta("http://www.scrollingcapabilities.xz");
		///richtext->add_text("Hello!\n");
		//richtext->pop();

		richtext->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);


		TabContainer * tabc = memnew( TabContainer );

		Control *ctl= memnew( Control );
		ctl->set_name("tab 1");
		tabc->add_child(ctl);

		ctl= memnew( Control );
		ctl->set_name("tab 2");
		tabc->add_child(ctl);
		label = memnew( Label );
		label->set_text("Some Label");
		label->set_pos( Point2(20,20) );
		ctl->add_child(label);;

		ctl= memnew( Control );
		ctl->set_name("tab 3");
		button = memnew( Button );
		button->set_text("Some Button");
		button->set_pos( Point2(30,50) );
		ctl->add_child(button);;

		tabc->add_child(ctl);

		frame->add_child(tabc);
		
		tabc->set_pos( Point2( 400,210 ) );
		tabc->set_size( Point2( 180,250 ) );

		
		Ref<ImageTexture> text = memnew( ImageTexture );
		text->load("test_data/concave.png");

		Sprite* sprite = memnew(Sprite);
		sprite->set_texture(text);
		sprite->set_pos(Point2(300, 300));
		frame->add_child(sprite);
		sprite->show();

		Sprite* sprite2 = memnew(Sprite);
		sprite->set_texture(text);
		sprite->add_child(sprite2);
		sprite2->set_pos(Point2(50, 50));
		sprite2->show();
	}
示例#7
0
DirAccess *DirAccessJAndroid::create_fs() {

	return memnew(DirAccessJAndroid);
}
示例#8
0
Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {

	FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);

	if (r_err) {
		*r_err = ERR_CANT_OPEN;
	}

	ERR_FAIL_COND_V(!f, NULL);

	if (r_err) {
		*r_err = OK;
	}

	Spatial *scene = memnew(Spatial);

	Ref<ArrayMesh> mesh;
	mesh.instance();

	Map<String, Ref<Material> > name_map;

	bool generate_tangents = p_flags & IMPORT_GENERATE_TANGENT_ARRAYS;
	bool flip_faces = false;
	//bool flip_faces = p_options["force/flip_faces"];
	//bool force_smooth = p_options["force/smooth_shading"];
	//bool weld_vertices = p_options["force/weld_vertices"];
	//float weld_tolerance = p_options["force/weld_tolerance"];

	Vector<Vector3> vertices;
	Vector<Vector3> normals;
	Vector<Vector2> uvs;
	String name;

	Map<String, Map<String, Ref<SpatialMaterial> > > material_map;

	Ref<SurfaceTool> surf_tool = memnew(SurfaceTool);
	surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);

	String current_material_library;
	String current_material;
	String current_group;

	while (true) {

		String l = f->get_line().strip_edges();

		if (l.begins_with("v ")) {
			//vertex
			Vector<String> v = l.split(" ", false);
			ERR_FAIL_COND_V(v.size() < 4, NULL);
			Vector3 vtx;
			vtx.x = v[1].to_float();
			vtx.y = v[2].to_float();
			vtx.z = v[3].to_float();
			vertices.push_back(vtx);
		} else if (l.begins_with("vt ")) {
			//uv
			Vector<String> v = l.split(" ", false);
			ERR_FAIL_COND_V(v.size() < 3, NULL);
			Vector2 uv;
			uv.x = v[1].to_float();
			uv.y = 1.0 - v[2].to_float();
			uvs.push_back(uv);

		} else if (l.begins_with("vn ")) {
			//normal
			Vector<String> v = l.split(" ", false);
			ERR_FAIL_COND_V(v.size() < 4, NULL);
			Vector3 nrm;
			nrm.x = v[1].to_float();
			nrm.y = v[2].to_float();
			nrm.z = v[3].to_float();
			normals.push_back(nrm);
		} else if (l.begins_with("f ")) {
			//vertex

			Vector<String> v = l.split(" ", false);
			ERR_FAIL_COND_V(v.size() < 4, NULL);

			//not very fast, could be sped up

			Vector<String> face[3];
			face[0] = v[1].split("/");
			face[1] = v[2].split("/");
			ERR_FAIL_COND_V(face[0].size() == 0, NULL);
			ERR_FAIL_COND_V(face[0].size() != face[1].size(), NULL);
			for (int i = 2; i < v.size() - 1; i++) {

				face[2] = v[i + 1].split("/");
				ERR_FAIL_COND_V(face[0].size() != face[2].size(), NULL);
				for (int j = 0; j < 3; j++) {

					int idx = j;

					if (!flip_faces && idx < 2) {
						idx = 1 ^ idx;
					}

					if (face[idx].size() == 3) {
						int norm = face[idx][2].to_int() - 1;
						if (norm < 0)
							norm += normals.size() + 1;
						ERR_FAIL_INDEX_V(norm, normals.size(), NULL);
						surf_tool->add_normal(normals[norm]);
					}

					if (face[idx].size() >= 2 && face[idx][1] != String()) {
						int uv = face[idx][1].to_int() - 1;
						if (uv < 0)
							uv += uvs.size() + 1;
						ERR_FAIL_INDEX_V(uv, uvs.size(), NULL);
						surf_tool->add_uv(uvs[uv]);
					}

					int vtx = face[idx][0].to_int() - 1;
					if (vtx < 0)
						vtx += vertices.size() + 1;
					ERR_FAIL_INDEX_V(vtx, vertices.size(), NULL);

					Vector3 vertex = vertices[vtx];
					//if (weld_vertices)
					//	vertex.snap(Vector3(weld_tolerance, weld_tolerance, weld_tolerance));
					surf_tool->add_vertex(vertex);
				}

				face[1] = face[2];
			}
		} else if (l.begins_with("s ")) { //smoothing
			String what = l.substr(2, l.length()).strip_edges();
			if (what == "off")
				surf_tool->add_smooth_group(false);
			else
				surf_tool->add_smooth_group(true);
		} else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh
			//groups are too annoying
			if (surf_tool->get_vertex_array().size()) {
				//another group going on, commit it
				if (normals.size() == 0) {
					surf_tool->generate_normals();
				}

				if (generate_tangents && uvs.size()) {
					surf_tool->generate_tangents();
				}

				surf_tool->index();

				print_line("current material library " + current_material_library + " has " + itos(material_map.has(current_material_library)));
				print_line("current material " + current_material + " has " + itos(material_map.has(current_material_library) && material_map[current_material_library].has(current_material)));

				if (material_map.has(current_material_library) && material_map[current_material_library].has(current_material)) {
					surf_tool->set_material(material_map[current_material_library][current_material]);
				}

				mesh = surf_tool->commit(mesh);

				if (current_material != String()) {
					mesh->surface_set_name(mesh->get_surface_count() - 1, current_material.get_basename());
				} else if (current_group != String()) {
					mesh->surface_set_name(mesh->get_surface_count() - 1, current_group);
				}

				print_line("Added surface :" + mesh->surface_get_name(mesh->get_surface_count() - 1));
				surf_tool->clear();
				surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
			}

			if (l.begins_with("o ") || f->eof_reached()) {

				MeshInstance *mi = memnew(MeshInstance);
				mi->set_name(name);
				mi->set_mesh(mesh);

				scene->add_child(mi);
				mi->set_owner(scene);

				mesh.instance();
				current_group = "";
				current_material = "";
			}

			if (f->eof_reached()) {
				break;
			}

			if (l.begins_with("o ")) {
				name = l.substr(2, l.length()).strip_edges();
			}

			if (l.begins_with("usemtl ")) {

				current_material = l.replace("usemtl", "").strip_edges();
			}

			if (l.begins_with("g ")) {

				current_group = l.substr(2, l.length()).strip_edges();
			}

		} else if (l.begins_with("mtllib ")) { //parse material

			current_material_library = l.replace("mtllib", "").strip_edges();
			if (!material_map.has(current_material_library)) {
				Map<String, Ref<SpatialMaterial> > lib;
				Error err = _parse_material_library(current_material_library, lib, r_missing_deps);
				if (err == ERR_CANT_OPEN) {
					String dir = p_path.get_base_dir();
					err = _parse_material_library(dir.plus_file(current_material_library), lib, r_missing_deps);
				}
				if (err == OK) {
					material_map[current_material_library] = lib;
				}
			}
		}
	}

	/*
	TODO, check existing materials and merge?
	//re-apply materials if exist
	for(int i=0;i<mesh->get_surface_count();i++) {

		String n = mesh->surface_get_name(i);
		if (name_map.has(n))
			mesh->surface_set_material(i,name_map[n]);
	}
*/

	return scene;
}
Ref<JavaClass> JavaClassWrapper::wrap(const String& p_class) {

	if (class_cache.has(p_class))
		return class_cache[p_class];


	JNIEnv *env = ThreadAndroid::get_env();

	jclass bclass = env->FindClass(p_class.utf8().get_data());
	ERR_FAIL_COND_V(!bclass,Ref<JavaClass>());

	//jmethodID getDeclaredMethods = env->GetMethodID(bclass,"getDeclaredMethods", "()[Ljava/lang/reflect/Method;");

	//ERR_FAIL_COND_V(!getDeclaredMethods,Ref<JavaClass>());

	jobjectArray methods = (jobjectArray)env->CallObjectMethod(bclass, getDeclaredMethods);

	ERR_FAIL_COND_V(!methods,Ref<JavaClass>());


	Ref<JavaClass> java_class = memnew( JavaClass );

	int count = env->GetArrayLength(methods);

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

		jobject obj = env->GetObjectArrayElement(methods, i);
		ERR_CONTINUE(!obj);


		jstring name = (jstring)env->CallObjectMethod(obj, getName);
		String str_method = env->GetStringUTFChars( name, NULL );
		env->DeleteLocalRef(name);

		Vector<String> params;

		jint mods = env->CallIntMethod(obj,getModifiers);

		if (!(mods&0x0001)) {
			env->DeleteLocalRef(obj);
			continue; //not public bye
		}



		jobjectArray param_types = (jobjectArray)env->CallObjectMethod(obj, getParameterTypes);
		int count2=env->GetArrayLength(param_types);

		if (!java_class->methods.has(str_method)) {
			java_class->methods[str_method]=List<JavaClass::MethodInfo>();
		}

		JavaClass::MethodInfo mi;
		mi._static = (mods&0x8)!=0;
		bool valid=true;
		String signature="(";

		for(int j=0;j<count2;j++) {

			jobject obj2 = env->GetObjectArrayElement(param_types, j);
			String strsig;
			uint32_t sig=0;
			if (!_get_type_sig(env,obj2,sig,strsig)) {
				valid=false;
				env->DeleteLocalRef(obj2);
				break;
			}
			signature+=strsig;
			mi.param_types.push_back(sig);
			mi.param_sigs.push_back(strsig);
			env->DeleteLocalRef(obj2);

		}

		if (!valid) {
			print_line("Method Can't be bound (unsupported arguments): "+p_class+"::"+str_method);
			env->DeleteLocalRef(obj);
			env->DeleteLocalRef(param_types);
			continue;
		}

		signature+=")";

		jobject return_type = (jobject)env->CallObjectMethod(obj, getReturnType);


		String strsig;
		uint32_t sig=0;
		if (!_get_type_sig(env,return_type,sig,strsig)) {
			print_line("Method Can't be bound (unsupported return type): "+p_class+"::"+str_method);
			env->DeleteLocalRef(obj);
			env->DeleteLocalRef(param_types);
			env->DeleteLocalRef(return_type);
			continue;
		}

		signature+=strsig;
		mi.return_type=sig;

		print_line("METHOD: "+str_method+" SIG: "+signature+" static: "+itos(mi._static));

		bool discard=false;

		for(List<JavaClass::MethodInfo>::Element *E=java_class->methods[str_method].front();E;E=E->next()) {

			float new_likeliness=0;
			float existing_likeliness=0;

			if (E->get().param_types.size()!=mi.param_types.size())
				continue;
			bool valid=true;
			for(int j=0;j<E->get().param_types.size();j++) {

				Variant::Type _new;
				float new_l;
				Variant::Type existing;
				float existing_l;
				JavaClass::_convert_to_variant_type(E->get().param_types[j],existing,existing_l);
				JavaClass::_convert_to_variant_type(mi.param_types[j],_new,new_l);
				if (_new!=existing) {
					valid=false;
					break;
				}
				new_likeliness+=new_l;
				existing_likeliness=existing_l;

			}

			if (!valid)
				continue;

			if (new_likeliness>existing_likeliness) {
				java_class->methods[str_method].erase(E);
				print_line("replace old");
				break;
			} else {
				discard=true;
				print_line("old is better");
			}


		}

		if (!discard) {
			if (mi._static)
				mi.method = env->GetStaticMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data());
			else
				mi.method = env->GetMethodID(bclass, str_method.utf8().get_data(), signature.utf8().get_data());

			ERR_CONTINUE(!mi.method);

			java_class->methods[str_method].push_back(mi);
		}

		env->DeleteLocalRef(obj);
		env->DeleteLocalRef(param_types);
		env->DeleteLocalRef(return_type);




		//args[i] = _jobject_to_variant(env, obj);
//		print_line("\targ"+itos(i)+": "+Variant::get_type_name(args[i].get_type()));

	};

	env->DeleteLocalRef(methods);

	jobjectArray fields = (jobjectArray)env->CallObjectMethod(bclass, getFields);

	count = env->GetArrayLength(fields);

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

		jobject obj = env->GetObjectArrayElement(fields, i);
		ERR_CONTINUE(!obj);

		jstring name = (jstring)env->CallObjectMethod(obj, Field_getName);
		String str_field = env->GetStringUTFChars( name, NULL );
		env->DeleteLocalRef(name);
		print_line("FIELD: "+str_field);
		int mods = env->CallIntMethod(obj,Field_getModifiers);
		if ((mods&0x8) && (mods&0x10) && (mods&0x1)) { //static final public!

			jobject objc = env->CallObjectMethod(obj, Field_get,NULL);
			if (objc) {


				uint32_t sig;
				String strsig;
				jclass cl = env->GetObjectClass(objc);
				if (JavaClassWrapper::_get_type_sig(env,cl,sig,strsig)) {

					if ((sig&JavaClass::ARG_TYPE_MASK)<=JavaClass::ARG_TYPE_STRING) {

						Variant value;
						if (JavaClass::_convert_object_to_variant(env,objc,value,sig)) {

							java_class->constant_map[str_field]=value;
						}
					}
				}

				env->DeleteLocalRef(cl);
			}


			env->DeleteLocalRef(objc);

		}
		env->DeleteLocalRef(obj);
	}

	env->DeleteLocalRef(fields);


	return Ref<JavaClass>();
}
示例#10
0
ExportTemplateManager::ExportTemplateManager() {

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

	current_hb = memnew(HBoxContainer);
	main_vb->add_margin_child(TTR("Current Version:"), current_hb, false);

	installed_scroll = memnew(ScrollContainer);
	main_vb->add_margin_child(TTR("Installed Versions:"), installed_scroll, true);

	installed_vb = memnew(VBoxContainer);
	installed_scroll->add_child(installed_vb);
	installed_scroll->set_enable_v_scroll(true);
	installed_scroll->set_enable_h_scroll(false);
	installed_vb->set_h_size_flags(SIZE_EXPAND_FILL);

	get_cancel()->set_text(TTR("Close"));
	get_ok()->set_text(TTR("Install From File"));

	remove_confirm = memnew(ConfirmationDialog);
	remove_confirm->set_title(TTR("Remove Template"));
	add_child(remove_confirm);
	remove_confirm->connect("confirmed", this, "_uninstall_template_confirm");

	template_open = memnew(FileDialog);
	template_open->set_title(TTR("Select template file"));
	template_open->add_filter("*.tpz ; Godot Export Templates");
	template_open->set_access(FileDialog::ACCESS_FILESYSTEM);
	template_open->set_mode(FileDialog::MODE_OPEN_FILE);
	template_open->connect("file_selected", this, "_install_from_file");
	add_child(template_open);

	set_title(TTR("Export Template Manager"));
	set_hide_on_ok(false);

	request_mirror = memnew(HTTPRequest);
	add_child(request_mirror);
	request_mirror->connect("request_completed", this, "_http_download_mirror_completed");

	download_templates = memnew(HTTPRequest);
	add_child(download_templates);
	download_templates->connect("request_completed", this, "_http_download_templates_completed");

	template_downloader = memnew(AcceptDialog);
	template_downloader->set_title(TTR("Download Templates"));
	template_downloader->get_ok()->set_text(TTR("Close"));
	add_child(template_downloader);

	VBoxContainer *vbc = memnew(VBoxContainer);
	template_downloader->add_child(vbc);
	ScrollContainer *sc = memnew(ScrollContainer);
	sc->set_custom_minimum_size(Size2(400, 200) * EDSCALE);
	vbc->add_margin_child(TTR("Select mirror from list: "), sc);
	template_list = memnew(VBoxContainer);
	sc->add_child(template_list);
	sc->set_enable_v_scroll(true);
	sc->set_enable_h_scroll(false);
	template_list_state = memnew(Label);
	vbc->add_child(template_list_state);
	template_download_progress = memnew(ProgressBar);
	vbc->add_child(template_download_progress);

	update_countdown = 0;
}
示例#11
0
FileDialog::FileDialog() {

	show_hidden_files=default_show_hidden_files;

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


	mode=MODE_SAVE_FILE;
	set_title(RTR("Save a File"));

	dir = memnew(LineEdit);
	HBoxContainer *pathhb = memnew( HBoxContainer );
	pathhb->add_child(dir);
	dir->set_h_size_flags(SIZE_EXPAND_FILL);

	refresh = memnew( ToolButton );
	refresh->connect("pressed",this,"_update_file_list");
	pathhb->add_child(refresh);

	drives = memnew( OptionButton );
	pathhb->add_child(drives);
	drives->connect("item_selected",this,"_select_drive");

	makedir = memnew( Button );
	makedir->set_text(RTR("Create Folder"));
	makedir->connect("pressed",this,"_make_dir");
	pathhb->add_child(makedir);

	vbc->add_margin_child(RTR("Path:"),pathhb);

	tree = memnew(Tree);
	tree->set_hide_root(true);
	vbc->add_margin_child(RTR("Directories & Files:"),tree,true);

	file = memnew(LineEdit);
	//add_child(file);
	vbc->add_margin_child(RTR("File:"),file);


	filter = memnew( OptionButton );
	//add_child(filter);
	vbc->add_margin_child(RTR("Filter:"),filter);
	filter->set_clip_text(true);//too many extensions overflow it

	dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
	access=ACCESS_RESOURCES;
	_update_drives();


	connect("confirmed", this,"_action_pressed");
	//cancel->connect("pressed", this,"_cancel_pressed");
	tree->connect("cell_selected", this,"_tree_selected",varray(),CONNECT_DEFERRED);
	tree->connect("item_activated", this,"_tree_db_selected",varray());
	dir->connect("text_entered", this,"_dir_entered");
	file->connect("text_entered", this,"_file_entered");
	filter->connect("item_selected", this,"_filter_selected");


	confirm_save = memnew( ConfirmationDialog );
	confirm_save->set_as_toplevel(true);
	add_child(confirm_save);


	confirm_save->connect("confirmed", this,"_save_confirm_pressed");

	makedialog = memnew( ConfirmationDialog );
	makedialog->set_title(RTR("Create Folder"));
	VBoxContainer *makevb= memnew( VBoxContainer );
	makedialog->add_child(makevb);

	makedirname = memnew( LineEdit );
	makevb->add_margin_child(RTR("Name:"),makedirname);
	add_child(makedialog);
	makedialog->register_text_enter(makedirname);
	makedialog->connect("confirmed",this,"_make_dir_confirm");
	mkdirerr = memnew( AcceptDialog );
	mkdirerr->set_text(RTR("Could not create folder."));
	add_child(mkdirerr);

	exterr = memnew( AcceptDialog );
	exterr->set_text(RTR("Must use a valid extension."));
	add_child(exterr);


	//update_file_list();
	update_filters();
	update_dir();

	set_hide_on_ok(false);
	vbox=vbc;


	invalidated=true;
	if (register_func)
		register_func(this);

}
示例#12
0
void ExportTemplateManager::_update_template_list() {

	while (current_hb->get_child_count()) {
		memdelete(current_hb->get_child(0));
	}

	while (installed_vb->get_child_count()) {
		memdelete(installed_vb->get_child(0));
	}

	DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());

	d->list_dir_begin();
	Set<String> templates;

	if (err == OK) {

		bool isdir;
		String c = d->get_next(&isdir);
		while (c != String()) {
			if (isdir && !c.begins_with(".")) {
				templates.insert(c);
			}
			c = d->get_next(&isdir);
		}
	}
	d->list_dir_end();

	memdelete(d);

	String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS) + VERSION_MODULE_CONFIG;

	Label *current = memnew(Label);
	current->set_h_size_flags(SIZE_EXPAND_FILL);
	current_hb->add_child(current);

	if (templates.has(current_version)) {
		current->add_color_override("font_color", get_color("success_color", "Editor"));
		Button *redownload = memnew(Button);
		redownload->set_text(TTR("Re-Download"));
		current_hb->add_child(redownload);
		redownload->connect("pressed", this, "_download_template", varray(current_version));

		Button *uninstall = memnew(Button);
		uninstall->set_text(TTR("Uninstall"));
		current_hb->add_child(uninstall);
		current->set_text(current_version + " " + TTR("(Installed)"));
		uninstall->connect("pressed", this, "_uninstall_template", varray(current_version));

	} else {
		current->add_color_override("font_color", get_color("error_color", "Editor"));
		Button *redownload = memnew(Button);
		redownload->set_text(TTR("Download"));
		redownload->connect("pressed", this, "_download_template", varray(current_version));
		current_hb->add_child(redownload);
		current->set_text(current_version + " " + TTR("(Missing)"));
	}

	for (Set<String>::Element *E = templates.back(); E; E = E->prev()) {

		HBoxContainer *hbc = memnew(HBoxContainer);
		Label *version = memnew(Label);
		version->set_modulate(get_color("disabled_font_color", "Editor"));
		String text = E->get();
		if (text == current_version) {
			text += " " + TTR("(Current)");
		}
		version->set_text(text);
		version->set_h_size_flags(SIZE_EXPAND_FILL);
		hbc->add_child(version);

		Button *uninstall = memnew(Button);

		uninstall->set_text(TTR("Uninstall"));
		hbc->add_child(uninstall);
		uninstall->connect("pressed", this, "_uninstall_template", varray(E->get()));

		installed_vb->add_child(hbc);
	}
}
示例#13
0
Rasterizer *RasterizerGLES3::_create_current() {

	return memnew(RasterizerGLES3);
}
示例#14
0
ScriptCreateDialog::ScriptCreateDialog() {

	/* DIALOG */

	/* Main Controls */

	GridContainer *gc = memnew(GridContainer);
	gc->set_columns(2);

	/* Error Messages Field */

	VBoxContainer *vb = memnew(VBoxContainer);

	HBoxContainer *hb = memnew(HBoxContainer);
	Label *l = memnew(Label);
	l->set_text(" - ");
	hb->add_child(l);
	error_label = memnew(Label);
	error_label->set_text(TTR("Error!"));
	error_label->set_align(Label::ALIGN_LEFT);
	hb->add_child(error_label);
	vb->add_child(hb);

	hb = memnew(HBoxContainer);
	l = memnew(Label);
	l->set_text(" - ");
	hb->add_child(l);
	path_error_label = memnew(Label);
	path_error_label->set_text(TTR("Error!"));
	path_error_label->set_align(Label::ALIGN_LEFT);
	hb->add_child(path_error_label);
	vb->add_child(hb);

	PanelContainer *pc = memnew(PanelContainer);
	pc->set_h_size_flags(Control::SIZE_FILL);
	pc->add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("bg", "Tree"));
	pc->add_child(vb);

	/* Margins */

	Control *empty_h = memnew(Control);
	empty_h->set_name("empty_h"); //duplicate() doesn't like nodes without a name
	empty_h->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	empty_h->set_v_size_flags(Control::SIZE_EXPAND_FILL);
	empty_h->set_custom_minimum_size(Size2(0, 10 * EDSCALE));
	Control *empty_v = memnew(Control);
	empty_v->set_name("empty_v");
	empty_v->set_h_size_flags(Control::SIZE_EXPAND_FILL);
	empty_v->set_v_size_flags(Control::SIZE_EXPAND_FILL);
	empty_v->set_custom_minimum_size(Size2(10, 0 * EDSCALE));

	vb = memnew(VBoxContainer);
	vb->add_child(empty_h->duplicate());
	vb->add_child(gc);
	vb->add_child(empty_h->duplicate());
	vb->add_child(pc);
	vb->add_child(empty_h->duplicate());
	hb = memnew(HBoxContainer);
	hb->add_child(empty_v->duplicate());
	hb->add_child(vb);
	hb->add_child(empty_v->duplicate());

	memdelete(empty_h);
	memdelete(empty_v);

	add_child(hb);

	/* Language */

	language_menu = memnew(OptionButton);
	language_menu->set_custom_minimum_size(Size2(250, 0) * EDSCALE);
	language_menu->set_h_size_flags(SIZE_EXPAND_FILL);
	l = memnew(Label);
	l->set_text(TTR("Language"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(language_menu);

	int default_lang = 0;
	for (int i = 0; i < ScriptServer::get_language_count(); i++) {

		String lang = ScriptServer::get_language(i)->get_name();
		language_menu->add_item(lang);
		if (lang == "GDScript") {
			default_lang = i;
		}
	}

	String last_selected_language = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", "");
	if (last_selected_language != "") {
		for (int i = 0; i < language_menu->get_item_count(); i++) {
			if (language_menu->get_item_text(i) == last_selected_language) {
				language_menu->select(i);
				current_language = i;
				break;
			}
		}
	} else {
		language_menu->select(default_lang);
		current_language = default_lang;
	}

	language_menu->connect("item_selected", this, "_lang_changed");

	/* Inherits */

	hb = memnew(HBoxContainer);
	hb->set_h_size_flags(SIZE_EXPAND_FILL);
	parent_name = memnew(LineEdit);
	parent_name->connect("text_changed", this, "_parent_name_changed");
	parent_name->set_h_size_flags(SIZE_EXPAND_FILL);
	hb->add_child(parent_name);
	parent_browse_button = memnew(Button);
	parent_browse_button->set_flat(true);
	parent_browse_button->connect("pressed", this, "_browse_path", varray(true));
	hb->add_child(parent_browse_button);
	l = memnew(Label);
	l->set_text(TTR("Inherits"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(hb);
	is_browsing_parent = false;

	/* Class Name */

	class_name = memnew(LineEdit);
	class_name->connect("text_changed", this, "_class_name_changed");
	class_name->set_h_size_flags(SIZE_EXPAND_FILL);
	l = memnew(Label);
	l->set_text(TTR("Class Name"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(class_name);

	/* Templates */

	template_menu = memnew(OptionButton);
	l = memnew(Label);
	l->set_text(TTR("Template"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(template_menu);
	template_menu->connect("item_selected", this, "_template_changed");

	/* Built-in Script */

	internal = memnew(CheckButton);
	internal->connect("pressed", this, "_built_in_pressed");
	hb = memnew(HBoxContainer);
	hb->add_child(internal);
	l = memnew(Label);
	l->set_text(TTR("Built-in Script"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(hb);

	/* Path */

	hb = memnew(HBoxContainer);
	file_path = memnew(LineEdit);
	file_path->connect("text_changed", this, "_path_changed");
	file_path->set_h_size_flags(SIZE_EXPAND_FILL);
	hb->add_child(file_path);
	path_button = memnew(Button);
	path_button->set_flat(true);
	path_button->connect("pressed", this, "_browse_path", varray(false));
	hb->add_child(path_button);
	l = memnew(Label);
	l->set_text(TTR("Path"));
	l->set_align(Label::ALIGN_RIGHT);
	gc->add_child(l);
	gc->add_child(hb);

	/* Dialog Setup */

	file_browse = memnew(EditorFileDialog);
	file_browse->connect("file_selected", this, "_file_selected");
	add_child(file_browse);
	get_ok()->set_text(TTR("Create"));
	alert = memnew(AcceptDialog);
	alert->set_as_minsize();
	alert->get_label()->set_autowrap(true);
	alert->get_label()->set_align(Label::ALIGN_CENTER);
	alert->get_label()->set_valign(Label::VALIGN_CENTER);
	alert->get_label()->set_custom_minimum_size(Size2(325, 60) * EDSCALE);
	add_child(alert);

	set_as_minsize();
	set_hide_on_ok(false);
	set_title(TTR("Attach Node Script"));

	is_parent_name_valid = false;
	is_class_name_valid = false;
	is_path_valid = false;

	has_named_classes = false;
	supports_built_in = false;
	can_inherit_from_file = false;
	is_built_in = false;

	is_new_script_created = true;
}
示例#15
0
文件: label.cpp 项目: zz676/godot
void Label::regenerate_word_cache() {
	
	while (word_cache) {
		
		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}
	
	
	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");

	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int space_count=0;
	int space_width=font->get_char_size(' ').width;
	line_count=1;
	total_char_cache=0;
	
	WordCache *last=NULL;
	
	for (int i=0;i<text.size()+1;i++) {
		
		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works

		if (uppercase)
			current=String::char_uppercase(current);

		bool not_latin = current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
		bool insert_newline=false;
		int char_width;

		if (current<33) {

			if (current_word_size>0) {
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;

				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				wc->space_count = space_count;
				current_word_size=0;
				space_count=0;

			}


			if (current=='\n') {
				insert_newline=true;
			} else {
				total_char_cache++;
			}

			if (i<text.length() && text[i] == ' ') {
				total_char_cache--;  // do not count spaces
				if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
					space_count++;
					line_width+=space_width;
				}else {
					space_count=0;
				}
			}


		} else {
			// latin characters
			if (current_word_size==0) {
				word_pos=i;
			}
			
			char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;
			
		}

		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || not_latin)) || insert_newline) {
			if (not_latin) {
				if (current_word_size>0) {
					WordCache *wc = memnew( WordCache );
					if (word_cache) {
						last->next=wc;
					} else {
						word_cache=wc;
					}
					last=wc;

					wc->pixel_width=current_word_size-char_width;
					wc->char_pos=word_pos;
					wc->word_len=i-word_pos;
					wc->space_count = space_count;
					current_word_size=char_width;
					space_count=0;
					word_pos=i;
				}
			}

			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;

			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;
			space_count=0;

		}
		
	}
	
	//total_char_cache -= line_count + 1; // do not count new lines (including the first one)
	
	if (!autowrap) {
		
		minsize.width=width;
		minsize.height=font->get_height()*line_count;
		set_page( line_count );
		
	} else {
	
		set_page( get_size().height / font->get_height() );
	}
	
	set_max(line_count);
	
	word_cache_dirty=false;

}
示例#16
0
Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {

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

	snap_step=Vector2(10,10);
	use_snap=false;
	snap_show_grid=false;

	add_child( memnew( VSeparator ));
	button_create = memnew( ToolButton );
	add_child(button_create);
	button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE));
	button_create->set_toggle_mode(true);

	button_edit = memnew( ToolButton );
	add_child(button_edit);
	button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT));
	button_edit->set_toggle_mode(true);

	button_uv = memnew( ToolButton );
	add_child(button_uv);
	button_uv->connect("pressed",this,"_menu_option",varray(MODE_EDIT_UV));

	//add_constant_override("separation",0);

#if 0
	options = memnew( MenuButton );
	add_child(options);
	options->set_area_as_parent_rect();
	options->set_text("Polygon");
	//options->get_popup()->add_item("Parse BBCode",PARSE_BBCODE);
	options->get_popup()->connect("item_pressed", this,"_menu_option");
#endif

	mode = MODE_EDIT;
	wip_active=false;

	uv_mode=UV_MODE_EDIT_POINT;
	uv_edit = memnew( AcceptDialog );
	add_child(uv_edit);
	uv_edit->set_title(TTR("Polygon 2D UV Editor"));
	uv_edit->set_self_opacity(0.9);

	VBoxContainer *uv_main_vb = memnew( VBoxContainer );
	uv_edit->add_child(uv_main_vb);
	uv_edit->set_child_rect(uv_main_vb);
	HBoxContainer *uv_mode_hb = memnew( HBoxContainer );
	uv_main_vb->add_child(uv_mode_hb);
	for(int i=0;i<UV_MODE_MAX;i++) {

		uv_button[i]=memnew( ToolButton );
		uv_button[i]->set_toggle_mode(true);
		uv_mode_hb->add_child(uv_button[i]);
		uv_button[i]->connect("pressed",this,"_uv_mode",varray(i));
		uv_button[i]->set_focus_mode(FOCUS_NONE);
	}

	uv_button[0]->set_tooltip(TTR("Move Point")+"\n"+TTR("Ctrl: Rotate")+"\n"+TTR("Shift: Move All")+"\n"+TTR("Shift+Ctrl: Scale"));
	uv_button[1]->set_tooltip(TTR("Move Polygon"));
	uv_button[2]->set_tooltip(TTR("Rotate Polygon"));
	uv_button[3]->set_tooltip(TTR("Scale Polygon"));

	uv_button[0]->set_pressed(true);
	HBoxContainer *uv_main_hb = memnew( HBoxContainer );
	uv_main_vb->add_child(uv_main_hb);
	uv_edit_draw = memnew( Control );
	uv_main_hb->add_child(uv_edit_draw);
	uv_main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
	uv_edit_draw->set_h_size_flags(SIZE_EXPAND_FILL);
	uv_menu = memnew( MenuButton );
	uv_mode_hb->add_child(uv_menu);
	uv_menu->set_text(TTR("Edit"));
	uv_menu->get_popup()->add_item(TTR("Polygon->UV"),UVEDIT_POLYGON_TO_UV);
	uv_menu->get_popup()->add_item(TTR("UV->Polygon"),UVEDIT_UV_TO_POLYGON);
	uv_menu->get_popup()->add_separator();
	uv_menu->get_popup()->add_item(TTR("Clear UV"),UVEDIT_UV_CLEAR);
	uv_menu->get_popup()->connect("item_pressed",this,"_menu_option");

	uv_mode_hb->add_child( memnew( VSeparator ));

	b_snap_enable = memnew( ToolButton );
	uv_mode_hb->add_child(b_snap_enable);
	b_snap_enable->set_text(TTR("Snap"));
	b_snap_enable->set_focus_mode(FOCUS_NONE);
	b_snap_enable->set_toggle_mode(true);
	b_snap_enable->set_pressed(use_snap);
	b_snap_enable->set_tooltip(TTR("Enable Snap"));
	b_snap_enable->connect("toggled",this,"_set_use_snap");

	b_snap_grid = memnew( ToolButton );
	uv_mode_hb->add_child(b_snap_grid);
	b_snap_grid->set_text(TTR("Grid"));
	b_snap_grid->set_focus_mode(FOCUS_NONE);
	b_snap_grid->set_toggle_mode(true);
	b_snap_grid->set_pressed(snap_show_grid);
	b_snap_grid->set_tooltip(TTR("Show Grid"));
	b_snap_grid->connect("toggled",this,"_set_show_grid");

	uv_mode_hb->add_child( memnew( VSeparator ));
	uv_mode_hb->add_child( memnew( Label(TTR("Grid Offset:")) ) );

	SpinBox *sb_off_x = memnew( SpinBox );
	sb_off_x->set_min(-256);
	sb_off_x->set_max(256);
	sb_off_x->set_step(1);
	sb_off_x->set_val(snap_offset.x);
	sb_off_x->set_suffix("px");
	sb_off_x->connect("value_changed", this, "_set_snap_off_x");
	uv_mode_hb->add_child(sb_off_x);

	SpinBox *sb_off_y = memnew( SpinBox );
	sb_off_y->set_min(-256);
	sb_off_y->set_max(256);
	sb_off_y->set_step(1);
	sb_off_y->set_val(snap_offset.y);
	sb_off_y->set_suffix("px");
	sb_off_y->connect("value_changed", this, "_set_snap_off_y");
	uv_mode_hb->add_child(sb_off_y);

	uv_mode_hb->add_child( memnew( VSeparator ));
	uv_mode_hb->add_child( memnew( Label(TTR("Grid Step:")) ) );

	SpinBox *sb_step_x = memnew( SpinBox );
	sb_step_x->set_min(-256);
	sb_step_x->set_max(256);
	sb_step_x->set_step(1);
	sb_step_x->set_val(snap_step.x);
	sb_step_x->set_suffix("px");
	sb_step_x->connect("value_changed", this, "_set_snap_step_x");
	uv_mode_hb->add_child(sb_step_x);

	SpinBox *sb_step_y = memnew( SpinBox );
	sb_step_y->set_min(-256);
	sb_step_y->set_max(256);
	sb_step_y->set_step(1);
	sb_step_y->set_val(snap_step.y);
	sb_step_y->set_suffix("px");
	sb_step_y->connect("value_changed", this, "_set_snap_step_y");
	uv_mode_hb->add_child(sb_step_y);

	uv_mode_hb->add_child( memnew( VSeparator ));
	uv_icon_zoom = memnew( TextureFrame );
	uv_mode_hb->add_child( uv_icon_zoom );
	uv_zoom = memnew( HSlider );
	uv_zoom->set_min(0.01);
	uv_zoom->set_max(4);
	uv_zoom->set_val(1);
	uv_zoom->set_step(0.01);
	uv_mode_hb->add_child(uv_zoom);
	uv_zoom->set_custom_minimum_size(Size2(200,0));
	uv_zoom_value = memnew( SpinBox );
	uv_zoom->share(uv_zoom_value);
	uv_zoom_value->set_custom_minimum_size(Size2(50,0));
	uv_mode_hb->add_child(uv_zoom_value);
	uv_zoom->connect("value_changed",this,"_uv_scroll_changed");



	uv_vscroll = memnew( VScrollBar);
	uv_main_hb->add_child(uv_vscroll);
	uv_vscroll->connect("value_changed",this,"_uv_scroll_changed");
	uv_hscroll = memnew( HScrollBar );
	uv_main_vb->add_child(uv_hscroll);
	uv_hscroll->connect("value_changed",this,"_uv_scroll_changed");

	uv_edit_draw->connect("draw",this,"_uv_draw");
	uv_edit_draw->connect("input_event",this,"_uv_input");
	uv_draw_zoom=1.0;
	uv_drag_index=-1;
	uv_drag=false;
	updating_uv_scroll=false;

	error = memnew( AcceptDialog);
	add_child(error);

}
示例#17
0
MainLoop* test() {

	print_line("this is test io");
	DirAccess* da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
	da->change_dir(".");
	print_line("Opening current dir "+ da->get_current_dir());
	String entry;
	da->list_dir_begin();
	while ( (entry = da->get_next()) != "") {

		print_line("entry "+entry+" is dir: " + Variant(da->current_is_dir()));
	};
	da->list_dir_end();

	RES texture = ResourceLoader::load("test_data/rock.png");
	ERR_FAIL_COND_V(texture.is_null(), NULL);

	ResourceSaver::save("test_data/rock.xml",texture);

	print_line("localize paths");
	print_line(Globals::get_singleton()->localize_path("algo.xml"));
	print_line(Globals::get_singleton()->localize_path("c:\\windows\\algo.xml"));
	print_line(Globals::get_singleton()->localize_path(Globals::get_singleton()->get_resource_path()+"/something/something.xml"));
	print_line(Globals::get_singleton()->localize_path("somedir/algo.xml"));

	{

		FileAccess* z = FileAccess::open("test_data/archive.zip", FileAccess::READ);
		int len = z->get_len();
		Vector<uint8_t> zip;
		zip.resize(len);
		z->get_buffer(&zip[0], len);
		z->close();
		memdelete(z);

		FileAccessMemory::register_file("a_package", zip);
		FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_RESOURCES);
		FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_FILESYSTEM);
		FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_USERDATA);

		print_line("archive test");
#if 0
		Archive arch;

		Archive::get_singleton()->add_package("a_package");
		FileAccessArchive f;

		print_line("opening for read");
		f._open("file.txt", FileAccess::READ);
		int pos = f.get_pos();
		printf("file has %i bytes, initial pos %i\n", (int)f.get_len(), pos);

		do {
			printf("%c", f.get_8());

		} while (!f.eof_reached());

		print_line("opening for stored seek");
		f.open("seek.bin", FileAccess::READ);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		f.seek(128);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());

		print_line("opening for deflated seek");
		f.open("seek_deflated.bin", FileAccess::READ);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		f.seek(128);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		f.seek(256);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		f.seek(4);
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());
		pos = f.get_pos();
		printf("byte at pos %i is %i\n", pos, (int)f.get_8());

		f.close();

		DirAccessArchive d;
		String dir = "../blah1/blah2/blahask/../blah3/.//blah4/";
		printf("changing dir to %s\n", dir.utf8().get_data());
		d.change_dir(dir);
		printf("current dir is %s\n", d.get_current_dir().utf8().get_data());

		FileAccessMemory::cleanup();
#endif
	};

	print_line("test done");


	return memnew( TestMainLoop );

}
示例#18
0
文件: export.cpp 项目: Martho42/godot
void EditorExportPlatformBB10::_fix_descriptor(Vector<uint8_t>& p_descriptor) {

	String fpath =  EditorSettings::get_singleton()->get_settings_path().plus_file("tmp_bar-settings.xml");
	{
		FileAccessRef f = FileAccess::open(fpath,FileAccess::WRITE);
		f->store_buffer(p_descriptor.ptr(),p_descriptor.size());
	}

	Ref<XMLParser> parser = memnew( XMLParser );
	Error err = parser->open(fpath);
	ERR_FAIL_COND(err!=OK);

	String txt;
	err = parser->read();
	Vector<String> depth;

	while(err!=ERR_FILE_EOF) {

		ERR_FAIL_COND(err!=OK);

		switch(parser->get_node_type()) {

			case XMLParser::NODE_NONE: {
				print_line("???");
			} break;
			case XMLParser::NODE_ELEMENT: {
				String e="<";
				e+=parser->get_node_name();
				for(int i=0;i<parser->get_attribute_count();i++) {
					e+=" ";
					e+=parser->get_attribute_name(i)+"=\"";
					e+=parser->get_attribute_value(i)+"\" ";
				}



				if (parser->is_empty()) {
					e+="/";
				} else {
					depth.push_back(parser->get_node_name());
				}

				e+=">";
				txt+=e;

			} break;
			case XMLParser::NODE_ELEMENT_END: {

				txt+="</"+parser->get_node_name()+">";
				if (depth.size() && depth[depth.size()-1]==parser->get_node_name()) {
					depth.resize(depth.size()-1);
				}


			} break;
			case XMLParser::NODE_TEXT: {
				if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="id") {

					txt+=package;
				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="name") {

					String aname;
					if (this->name!="") {
						aname=this->name;
					} else {
						aname = Globals::get_singleton()->get("application/name");

					}

					if (aname=="") {
						aname=_MKSTR(VERSION_NAME);
					}

					txt+=aname;

				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="versionNumber") {
					txt+=itos(version_code);
				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="description") {
					txt+=description;
				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="author") {
					txt+=author_name;
				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="authorId") {
					txt+=author_id;
				} else if (depth.size()==2 && depth[0]=="qnx" && depth[1]=="category") {
					txt+=category;
				} else {
					txt+=parser->get_node_data();
				}
			} break;
			case XMLParser::NODE_COMMENT: {
				txt+="<!--"+parser->get_node_name()+"-->";
			} break;
			case XMLParser::NODE_CDATA: {
				//ignore
				//print_line("cdata");
			} break;
			case XMLParser::NODE_UNKNOWN: {
				//ignore
				txt+="<"+parser->get_node_name()+">";
			} break;
		}

		err = parser->read();
	}


	CharString cs = txt.utf8();
	p_descriptor.resize(cs.length());
	for(int i=0;i<cs.length();i++)
		p_descriptor[i]=cs[i];

}
示例#19
0
文件: label.cpp 项目: 03050903/godot
void Label::regenerate_word_cache() {

	while (word_cache) {

		WordCache *current=word_cache;
		word_cache=current->next;
		memdelete( current );
	}


	int width=autowrap?get_size().width:get_longest_line_width();
	Ref<Font> font = get_font("font");

	int current_word_size=0;
	int word_pos=0;
	int line_width=0;
	int space_count=0;
	int space_width=font->get_char_size(' ').width;
	int line_spacing = get_constant("line_spacing");
	line_count=1;
	total_char_cache=0;

	WordCache *last=NULL;

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

		CharType current=i<text.length()?text[i]:' '; //always a space at the end, so the algo works

		if (uppercase)
			current=String::char_uppercase(current);

		// ranges taken from http://www.unicodemap.org/
		// if your language is not well supported, consider helping improve
		// the unicode support in Godot.
		bool separatable = (current>=0x2E08 && current<=0xFAFF) || (current>=0xFE30 && current<=0xFE4F);
				//current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57);
		bool insert_newline=false;
		int char_width;

		if (current<33) {

			if (current_word_size>0) {
				WordCache *wc = memnew( WordCache );
				if (word_cache) {
					last->next=wc;
				} else {
					word_cache=wc;
				}
				last=wc;

				wc->pixel_width=current_word_size;
				wc->char_pos=word_pos;
				wc->word_len=i-word_pos;
				wc->space_count = space_count;
				current_word_size=0;
				space_count=0;

			}


			if (current=='\n') {
				insert_newline=true;
			} else {
				total_char_cache++;
			}

			if (i<text.length() && text[i] == ' ') {
				total_char_cache--;  // do not count spaces
				if (line_width > 0 || last==NULL || last->char_pos!=WordCache::CHAR_WRAPLINE) {
					space_count++;
					line_width+=space_width;
				}else {
					space_count=0;
				}
			}


		} else {
			// latin characters
			if (current_word_size==0) {
				word_pos=i;
			}

			char_width=font->get_char_size(current).width;
			current_word_size+=char_width;
			line_width+=char_width;
			total_char_cache++;

		}

		if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) {
			if (separatable) {
				if (current_word_size>0) {
					WordCache *wc = memnew( WordCache );
					if (word_cache) {
						last->next=wc;
					} else {
						word_cache=wc;
					}
					last=wc;

					wc->pixel_width=current_word_size-char_width;
					wc->char_pos=word_pos;
					wc->word_len=i-word_pos;
					wc->space_count = space_count;
					current_word_size=char_width;
					space_count=0;
					word_pos=i;
				}
			}

			WordCache *wc = memnew( WordCache );
			if (word_cache) {
				last->next=wc;
			} else {
				word_cache=wc;
			}
			last=wc;

			wc->pixel_width=0;
			wc->char_pos=insert_newline?WordCache::CHAR_NEWLINE:WordCache::CHAR_WRAPLINE;

			line_width=current_word_size;
			line_count++;
			space_count=0;

		}

	}

	if (!autowrap) {
		minsize.width=width;
		if (max_lines_visible > 0 && line_count > max_lines_visible) {
			minsize.height=(font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
		} else {
			minsize.height=(font->get_height() * line_count)+(line_spacing * (line_count - 1));
		}
	}

	word_cache_dirty=false;

}
示例#20
0
void register_core_types() {

	
	_global_mutex=Mutex::create();


	StringName::setup();


	register_variant_methods();


	CoreStringNames::create();
	
#ifdef XML_ENABLED
#ifdef OLD_SCENE_FORMAT_ENABLED
	object_format_saver_xml = memnew( ObjectFormatSaverInstancerXML );
	ObjectSaver::add_object_format_saver_instancer( object_format_saver_xml );
	
	object_format_loader_xml = memnew( ObjectFormatLoaderInstancerXML );
	ObjectLoader::add_object_format_loader_instancer( object_format_loader_xml );
#endif
#endif
#ifdef OLD_SCENE_FORMAT_ENABLED
	object_format_saver_binary = memnew( ObjectFormatSaverInstancerBinary );
	ObjectSaver::add_object_format_saver_instancer( object_format_saver_binary );


	object_format_loader_binary = memnew( ObjectFormatLoaderInstancerBinary );
	ObjectLoader::add_object_format_loader_instancer( object_format_loader_binary );
#endif
	resource_format_po = memnew( TranslationLoaderPO );
	ResourceLoader::add_resource_format_loader( resource_format_po );


	resource_saver_binary = memnew( ResourceFormatSaverBinary );
	ResourceSaver::add_resource_format_saver(resource_saver_binary);
	resource_loader_binary = memnew( ResourceFormatLoaderBinary );
	ResourceLoader::add_resource_format_loader(resource_loader_binary);

	resource_saver_xml = memnew( ResourceFormatSaverXML );
	ResourceSaver::add_resource_format_saver(resource_saver_xml);
	resource_loader_xml = memnew( ResourceFormatLoaderXML );
	ResourceLoader::add_resource_format_loader(resource_loader_xml);

	ObjectTypeDB::register_type<Object>();


	ObjectTypeDB::register_type<Reference>();
	ObjectTypeDB::register_type<ResourceImportMetadata>();
	ObjectTypeDB::register_type<Resource>();
	ObjectTypeDB::register_type<FuncRef>();
	ObjectTypeDB::register_virtual_type<StreamPeer>();
	ObjectTypeDB::register_create_type<StreamPeerTCP>();
	ObjectTypeDB::register_create_type<TCP_Server>();
	ObjectTypeDB::register_virtual_type<IP>();
	ObjectTypeDB::register_virtual_type<PacketPeer>();
	ObjectTypeDB::register_type<PacketPeerStream>();
	ObjectTypeDB::register_type<MainLoop>();
//	ObjectTypeDB::register_type<OptimizedSaver>();
	ObjectTypeDB::register_type<Translation>();
	ObjectTypeDB::register_type<PHashTranslation>();

	ObjectTypeDB::register_type<HTTPClient>();

	ObjectTypeDB::register_virtual_type<ResourceInteractiveLoader>();

	ObjectTypeDB::register_type<_File>();
	ObjectTypeDB::register_type<_Directory>();
	ObjectTypeDB::register_type<_Thread>();
	ObjectTypeDB::register_type<_Mutex>();
	ObjectTypeDB::register_type<_Semaphore>();

	ObjectTypeDB::register_type<XMLParser>();

	ObjectTypeDB::register_type<ConfigFile>();

	ObjectTypeDB::register_type<PackedDataContainer>();
	ObjectTypeDB::register_virtual_type<PackedDataContainerRef>();

	ip = IP::create();


	_geometry = memnew(_Geometry);


	_resource_loader=memnew(_ResourceLoader);
	_resource_saver=memnew(_ResourceSaver);
	_os=memnew(_OS);
	_marshalls = memnew(_Marshalls);



}
示例#21
0
void LineEdit::_input_event(InputEvent p_event) {


    switch(p_event.type) {

    case InputEvent::MOUSE_BUTTON: {

        const InputEventMouseButton &b = p_event.mouse_button;

        if (b.pressed && b.button_index==BUTTON_RIGHT) {
            menu->set_pos(get_global_transform().xform(get_local_mouse_pos()));
            menu->set_size(Vector2(1,1));
            menu->popup();
            grab_focus();
            return;
        }

        if (b.button_index!=BUTTON_LEFT)
            break;

        _reset_caret_blink_timer();
        if (b.pressed) {

            shift_selection_check_pre(b.mod.shift);

            set_cursor_at_pixel_pos(b.x);

            if (b.mod.shift) {

                selection_fill_at_cursor();
                selection.creating=true;

            } else {

                if (b.doubleclick) {

                    selection.enabled=true;
                    selection.begin=0;
                    selection.end=text.length();
                    selection.doubleclick=true;
                }

                selection.drag_attempt=false;

                if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled)  {

                    selection_clear();
                    selection.cursor_start=cursor_pos;
                    selection.creating=true;
                } else if (selection.enabled) {

                    selection.drag_attempt=true;
                }
            }

            //			if (!editable)
            //	non_editable_clicked_signal.call();
            update();

        } else {

            if ( (!selection.creating) && (!selection.doubleclick)) {
                selection_clear();
            }
            selection.creating=false;
            selection.doubleclick=false;

            if (OS::get_singleton()->has_virtual_keyboard())
                OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
        }

        update();
    }
    break;
    case InputEvent::MOUSE_MOTION: {

        const InputEventMouseMotion& m=p_event.mouse_motion;

        if (m.button_mask&BUTTON_LEFT) {

            if (selection.creating) {
                set_cursor_at_pixel_pos(m.x);
                selection_fill_at_cursor();
            }
        }

    }
    break;
    case InputEvent::KEY: {

        const InputEventKey &k =p_event.key;

        if (!k.pressed)
            return;
        unsigned int code  = k.scancode;


        if (k.mod.command) {

            bool handled=true;

            switch (code) {

            case (KEY_X): { // CUT

                if(editable) {
                    cut_text();
                }

            }
            break;

            case (KEY_C): { // COPY

                copy_text();

            }
            break;

            case (KEY_V): { // PASTE

                if(editable) {

                    paste_text();
                }

            }
            break;

            case (KEY_Z): { // Simple One level undo

                if(editable) {

                    undo();

                }


            }
            break;

            case (KEY_U): { // Delete from start to cursor

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(cursor_pos,text.length()-cursor_pos);

                    Ref<Font> font = get_font("font");

                    cached_width = 0;
                    if (font != NULL) {
                        for (int i = 0; i < text.length(); i++)
                            cached_width += font->get_char_size(text[i]).width;
                    }

                    set_cursor_pos(0);
                    _text_changed();

                }


            }
            break;

            case (KEY_Y): { // PASTE (Yank for unix users)

                if(editable) {

                    paste_text();
                }

            }
            break;
            case (KEY_K): { // Delete from cursor_pos to end

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(0,cursor_pos);
                    _text_changed();
                }

            }
            break;
            case (KEY_A): { //Select All
                select();
            }
            break;
            default: {
                handled=false;
            }
            }

            if (handled) {
                accept_event();
                return;
            }
        }

        _reset_caret_blink_timer();
        if (!k.mod.meta) {

            bool handled=true;
            switch (code) {

            case KEY_ENTER:
            case KEY_RETURN: {

                emit_signal( "text_entered",text );
                if (OS::get_singleton()->has_virtual_keyboard())
                    OS::get_singleton()->hide_virtual_keyboard();

                return;
            }
            break;

            case KEY_BACKSPACE: {

                if (!editable)
                    break;

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;
                    bool prev_char=false;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    delete_text(cc, cursor_pos);

                    set_cursor_pos(cc);

                } else {
                    undo_text=text;
                    delete_char();
                }

            }
            break;
            case KEY_KP_4: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_left
            }
            case KEY_LEFT: {

#ifndef APPLE_STYLE_KEYS
                if (!k.mod.alt)
#endif
                    shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(0);
                } else if (k.mod.alt) {

#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()-1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_KP_6: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_right
            }
            case KEY_RIGHT: {

                shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(text.length());
                } else if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc<text.length()) {
                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc++;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()+1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_DELETE: {

                if (!editable)
                    break;

                if (k.mod.shift && !k.mod.command && !k.mod.alt) {
                    cut_text();
                    break;
                }

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

                int text_len = text.length();

                if (cursor_pos==text_len)
                    break; // nothing to do

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;

                    bool prev_char=false;

                    while (cc<text.length()) {

                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;
                        prev_char=ischar;
                        cc++;
                    }

                    delete_text(cursor_pos,cc);

                } else {
                    undo_text=text;
                    set_cursor_pos(cursor_pos+1);
                    delete_char();
                }

            }
            break;
            case KEY_KP_7: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_home
            }
            case KEY_HOME: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(0);
                shift_selection_check_post(k.mod.shift);
            }
            break;
            case KEY_KP_1: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_end
            }
            case KEY_END: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(text.length());
                shift_selection_check_post(k.mod.shift);
            }
            break;


            default: {

                handled=false;
            }
            break;
        }

        if (handled) {
            accept_event();
        } else if (!k.mod.alt && !k.mod.command) {
            if (k.unicode>=32 && k.scancode!=KEY_DELETE) {

                if (editable) {
                    selection_delete();
                    CharType ucodestr[2]= {(CharType)k.unicode,0};
                    append_at_cursor(ucodestr);
                    _text_changed();
                    accept_event();
                }

            } else {
                return;
            }
        }

        update();

    }


    return;

}
break;

    }
}

void LineEdit::set_align(Align p_align) {

ERR_FAIL_INDEX(p_align, 4);
align = p_align;
update();
}

LineEdit::Align LineEdit::get_align() const {

return align;
}

Variant LineEdit::get_drag_data(const Point2& p_point) {

if (selection.drag_attempt && selection.enabled) {
    String t = text.substr(selection.begin, selection.end - selection.begin);
    Label *l = memnew( Label );
    l->set_text(t);
    set_drag_preview(l);
    return 	t;
}

return Variant();

}
bool LineEdit::can_drop_data(const Point2& p_point,const Variant& p_data) const {

return p_data.get_type()==Variant::STRING;
}
void LineEdit::drop_data(const Point2& p_point,const Variant& p_data) {

if (p_data.get_type()==Variant::STRING) {
    set_cursor_at_pixel_pos(p_point.x);
    int selected = selection.end - selection.begin;

    Ref<Font> font = get_font("font");
    if (font != NULL) {
        for (int i = selection.begin; i < selection.end; i++)
            cached_width -= font->get_char_size(text[i]).width;
    }

    text.erase(selection.begin, selected);

    append_at_cursor(p_data);
    selection.begin = cursor_pos-selected;
    selection.end = cursor_pos;
}
}


void LineEdit::_notification(int p_what) {

switch(p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
    if (get_tree()->is_editor_hint()) {
        cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false));
        cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65));

        if (!EditorSettings::get_singleton()->is_connected("settings_changed",this,"_editor_settings_changed")) {
            EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
        }
    }
}
break;
#endif
case NOTIFICATION_RESIZED: {

    set_cursor_pos( get_cursor_pos() );

}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
    window_has_focus = true;
    draw_caret = true;
    update();
}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
    window_has_focus = false;
    draw_caret = false;
    update();
}
break;
case NOTIFICATION_DRAW: {

    if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
        draw_caret = false;
    }

    int width,height;

    Size2 size=get_size();
    width=size.width;
    height=size.height;

    RID ci = get_canvas_item();

    Ref<StyleBox> style = get_stylebox("normal");
    if (!is_editable())
        style=get_stylebox("read_only");

    Ref<Font> font=get_font("font");

    style->draw( ci, Rect2( Point2(), size ) );

    if (has_focus()) {

        get_stylebox("focus")->draw( ci, Rect2( Point2(), size ) );
    }

    int x_ofs=0;

    switch (align) {

    case ALIGN_FILL:
    case ALIGN_LEFT: {

        x_ofs=style->get_offset().x;
    }
    break;
    case ALIGN_CENTER: {

        x_ofs=int(size.width-(cached_width))/2;
    }
    break;
    case ALIGN_RIGHT: {

        x_ofs=int(size.width-style->get_offset().x-(cached_width));
    }
    break;
    }

    int ofs_max=width-style->get_minimum_size().width;
    int char_ofs=window_pos;

    int y_area=height-style->get_minimum_size().height;
    int y_ofs=style->get_offset().y;

    int font_ascent=font->get_ascent();

    Color selection_color=get_color("selection_color");
    Color font_color=get_color("font_color");
    Color font_color_selected=get_color("font_color_selected");
    Color cursor_color=get_color("cursor_color");

    const String& t = text.empty() ? placeholder : text;
    // draw placeholder color
    if(text.empty())
        font_color.a *= placeholder_alpha;

    int caret_height = font->get_height() > y_area ? y_area : font->get_height();
    while(true) {

        //end of string, break!
        if (char_ofs>=t.length())
            break;

        CharType cchar=pass?'*':t[char_ofs];
        CharType next=pass?'*':t[char_ofs+1];
        int char_width=font->get_char_size( cchar,next ).width;

        // end of widget, break!
        if ((x_ofs + char_width) > ofs_max)
            break;


        bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end;

        if (selected)
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);


        font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);

        if (char_ofs==cursor_pos && draw_caret) {
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                        Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
        }

        x_ofs+=char_width;
        char_ofs++;
    }

    if (char_ofs==cursor_pos && draw_caret) {//may be at the end
        VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                    Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
    }
}
break;
case NOTIFICATION_FOCUS_ENTER: {

    if (!caret_blink_enabled) {
        draw_caret = true;
    }

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());

}
break;
case NOTIFICATION_FOCUS_EXIT: {

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->hide_virtual_keyboard();

}
break;

}
}

void LineEdit::copy_text() {

if(selection.enabled) {

    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
}
}

void LineEdit::cut_text() {

if(selection.enabled) {
    undo_text = text;
    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
    selection_delete();
}
}

void LineEdit::paste_text() {

String paste_buffer = OS::get_singleton()->get_clipboard();

if(paste_buffer != "") {

    if(selection.enabled) selection_delete();
    append_at_cursor(paste_buffer);

    _text_changed();
}



}

void LineEdit::undo() {

int old_cursor_pos = cursor_pos;
text = undo_text;

Ref<Font> font = get_font("font");

cached_width = 0;
for (int i = 0; i<text.length(); i++)
    cached_width += font->get_char_size(text[i]).width;

if(old_cursor_pos > text.length()) {
    set_cursor_pos(text.length());
} else {
    set_cursor_pos(old_cursor_pos);
}

_text_changed();
}
示例#22
0
void OSBB10::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {

	data_dir = getenv("HOME");

	//Create a screen context that will be used to create an EGL surface to to receive libscreen events
	screen_create_context(&screen_cxt,0);

	//Initialize BPS library
	bps_initialize();

	//Use utility code to initialize EGL for 2D rendering with GL ES 1.1
	enum RENDERING_API api = GL_ES_2;
	#ifdef BB10_LGLES_OVERRIDE
	api = GL_ES_1;
	#endif
	if (EXIT_SUCCESS != bbutil_init(screen_cxt, api)) {
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return;
	};

	EGLint surface_width, surface_height;

	eglQuerySurface(egl_disp, egl_surf, EGL_WIDTH, &surface_width);
	eglQuerySurface(egl_disp, egl_surf, EGL_HEIGHT, &surface_height);
	printf("screen size: %ix%i\n", surface_width, surface_height);
	VideoMode mode;
	mode.width = surface_width;
	mode.height = surface_height;
	mode.fullscreen = true;
	mode.resizable = false;
	set_video_mode(mode);

	//Signal BPS library that navigator and screen events will be requested
	screen_request_events(screen_cxt);
	navigator_request_events(0);
	virtualkeyboard_request_events(0);
	audiodevice_request_events(0);

	#ifdef DEBUG_ENABLED
	bps_set_verbosity(3);
	#endif

	accel_supported = accelerometer_is_supported();
	if (accel_supported)
		accelerometer_set_update_frequency(FREQ_40_HZ);
	pitch = 0;
	roll = 0;

	#ifdef BB10_LGLES_OVERRIDE
	rasterizer = memnew( RasterizerGLES1(false) );
	#else
	rasterizer = memnew( RasterizerGLES2(false, false) );
	#endif

	visual_server = memnew( VisualServerRaster(rasterizer) );
	visual_server->init();
	visual_server->cursor_set_visible(false, 0);

	audio_driver = memnew(AudioDriverBB10);
	audio_driver->set_singleton();
	audio_driver->init(NULL);

	sample_manager = memnew( SampleManagerMallocSW );
	audio_server = memnew( AudioServerSW(sample_manager) );
	audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,false);
	audio_server->init();

	spatial_sound_server = memnew( SpatialSoundServerSW );
	spatial_sound_server->init();

	spatial_sound_2d_server = memnew( SpatialSound2DServerSW );
	spatial_sound_2d_server->init();

	//
	physics_server = memnew( PhysicsServerSW );
	physics_server->init();
	physics_2d_server = memnew( Physics2DServerSW );
	physics_2d_server->init();

	input = memnew( InputDefault );

	#ifdef PAYMENT_SERVICE_ENABLED
	payment_service = memnew(PaymentService);
	Globals::get_singleton()->add_singleton(Globals::Singleton("InAppStore", payment_service));
	#endif

}
示例#23
0
CreateDialog::CreateDialog() {

	is_replace_mode = false;

	set_resizable(true);

	HSplitContainer *hsc = memnew(HSplitContainer);
	add_child(hsc);

	VSplitContainer *vsc = memnew(VSplitContainer);
	hsc->add_child(vsc);

	VBoxContainer *fav_vb = memnew(VBoxContainer);
	vsc->add_child(fav_vb);
	fav_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
	fav_vb->set_v_size_flags(SIZE_EXPAND_FILL);

	favorites = memnew(Tree);
	fav_vb->add_margin_child(TTR("Favorites:"), favorites, true);
	favorites->set_hide_root(true);
	favorites->set_hide_folding(true);
	favorites->connect("cell_selected", this, "_favorite_selected");
	favorites->connect("item_activated", this, "_favorite_activated");
	favorites->set_drag_forwarding(this);

	VBoxContainer *rec_vb = memnew(VBoxContainer);
	vsc->add_child(rec_vb);
	rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE);
	rec_vb->set_v_size_flags(SIZE_EXPAND_FILL);

	recent = memnew(Tree);
	rec_vb->add_margin_child(TTR("Recent:"), recent, true);
	recent->set_hide_root(true);
	recent->set_hide_folding(true);
	recent->connect("cell_selected", this, "_history_selected");
	recent->connect("item_activated", this, "_history_activated");

	VBoxContainer *vbc = memnew(VBoxContainer);
	hsc->add_child(vbc);
	vbc->set_custom_minimum_size(Size2(300, 0) * EDSCALE);
	vbc->set_h_size_flags(SIZE_EXPAND_FILL);
	HBoxContainer *search_hb = memnew(HBoxContainer);
	search_box = memnew(LineEdit);
	search_box->set_h_size_flags(SIZE_EXPAND_FILL);
	search_hb->add_child(search_box);
	favorite = memnew(Button);
	favorite->set_flat(true);
	favorite->set_toggle_mode(true);
	search_hb->add_child(favorite);
	favorite->connect("pressed", this, "_favorite_toggled");
	vbc->add_margin_child(TTR("Search:"), search_hb);
	search_box->connect("text_changed", this, "_text_changed");
	search_box->connect("gui_input", this, "_sbox_input");
	search_options = memnew(Tree);
	vbc->add_margin_child(TTR("Matches:"), search_options, true);
	get_ok()->set_disabled(true);
	register_text_enter(search_box);
	set_hide_on_ok(false);
	search_options->connect("item_activated", this, "_confirmed");
	search_options->connect("cell_selected", this, "_item_selected");
	base_type = "Object";
	preferred_search_result_type = "";

	help_bit = memnew(EditorHelpBit);
	vbc->add_margin_child(TTR("Description:"), help_bit);
	help_bit->connect("request_hide", this, "_closed");

	type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here
	type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix.

	EDITOR_DEF("interface/editors/derive_script_globals_by_name", true);
}
示例#24
0
Path2D::Path2D() {

	set_curve(Ref<Curve2D>(memnew(Curve2D))); //create one by default
	set_self_modulate(Color(0.5, 0.6, 1.0, 0.7));
}
示例#25
0
SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelection *p_editor_selection,EditorData &p_editor_data)  {

	editor=p_editor;
	edited_scene=NULL;
	editor_data=&p_editor_data;
	editor_selection=p_editor_selection;
	scene_root=p_scene_root;

	VBoxContainer *vbc = this;

	HBoxContainer *hbc_top = memnew( HBoxContainer );
	vbc->add_child(hbc_top);

	ToolButton *tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW, false));
	tb->set_tooltip("Add/Create a New Node\n("+keycode_get_string(KEY_MASK_CMD|KEY_A)+")");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_NEW]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_INSTANCE, false));
	tb->set_tooltip("Instance a scene file as a Node.");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_INSTANCE]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_REPLACE, false));
	tb->set_tooltip("Replace a Node by Another Node Type");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_REPLACE]=tb;

	hbc_top->add_spacer();

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_CONNECT, false));
	tb->set_tooltip("Edit the Node Connections");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_CONNECT]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_GROUP, false));
	tb->set_tooltip("Edit the Node Groups");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_GROUP]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_SCRIPT, false));
	tb->set_tooltip("Edit/Create the Node Script");
	hbc_top->add_child(tb);
	tool_buttons[TOOL_SCRIPT]=tb;


	scene_tree = memnew( SceneTreeEditor(false,true,true ));
	vbc->add_child(scene_tree);
	scene_tree->set_v_size_flags(SIZE_EXPAND|SIZE_FILL);

	scene_tree->connect("node_selected", this,"_node_selected",varray(),CONNECT_DEFERRED);
	scene_tree->connect("node_renamed", this,"_node_renamed",varray(),CONNECT_DEFERRED);
	scene_tree->connect("node_prerename", this,"_node_prerenamed");
	scene_tree->connect("open",this,"_load_request");
	scene_tree->connect("open_script",this,"_script_open_request");
	scene_tree->set_undo_redo(&editor_data->get_undo_redo());
	scene_tree->set_editor_selection(editor_selection);

	HBoxContainer *hbc_bottom = memnew( HBoxContainer );
	vbc->add_child(hbc_bottom);


	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_UP, false));
	tb->set_tooltip("Move Node Up\n("+keycode_get_string(KEY_MASK_CMD|KEY_UP)+")");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_MOVE_UP]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_DOWN, false));
	tb->set_tooltip("Move Node Down\n("+keycode_get_string(KEY_MASK_CMD|KEY_DOWN)+")");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_MOVE_DOWN]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_DUPLICATE, false));
	tb->set_tooltip("Duplicate Selected Node(s)\n("+keycode_get_string(KEY_MASK_CMD|KEY_D)+")");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_DUPLICATE]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_REPARENT, false));
	tb->set_tooltip("Reparent Selected Node(s)");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_REPARENT]=tb;

	hbc_bottom->add_spacer();

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MULTI_EDIT, false));
	tb->set_tooltip("Multi-Edit Selected Nodes");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_MULTI_EDIT]=tb;

	tb = memnew( ToolButton );
	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_ERASE, false));
	tb->set_tooltip("Erase Selected Node(s)");
	hbc_bottom->add_child(tb);
	tool_buttons[TOOL_ERASE]=tb;

	create_dialog = memnew( CreateDialog );
	create_dialog->set_base_type("Node");
	add_child(create_dialog);
	create_dialog->connect("create",this,"_create");

	groups_editor = memnew( GroupsEditor );
	add_child(groups_editor);
	groups_editor->set_undo_redo(&editor_data->get_undo_redo());
	connect_dialog = memnew( ConnectionsDialog(p_editor) );
	add_child(connect_dialog);
	connect_dialog->set_undoredo(&editor_data->get_undo_redo());
	script_create_dialog = memnew( ScriptCreateDialog );
	add_child(script_create_dialog);
	script_create_dialog->connect("script_created",this,"_script_created");
	reparent_dialog = memnew( ReparentDialog );
	add_child(reparent_dialog);
	reparent_dialog->connect("reparent",this,"_node_reparent");

	accept = memnew( AcceptDialog );
	add_child(accept);

	file = memnew( EditorFileDialog );
	add_child(file);
	file->connect("file_selected",this,"instance");
	set_process_unhandled_key_input(true);

	delete_dialog = memnew( ConfirmationDialog );
	add_child(delete_dialog);
	delete_dialog->connect("confirmed",this,"_delete_confirm");
	import_subscene_dialog = memnew( EditorSubScene );
	add_child(import_subscene_dialog);
	import_subscene_dialog->connect("subscene_selected",this,"_import_subscene");

	first_enter=true;


}
示例#26
0
Ref<Texture> EditorScriptPreviewPlugin::generate(const RES& p_from) {


	Ref<Script> scr = p_from;
	if (scr.is_null())
		return Ref<Texture>();

	String code = scr->get_source_code().strip_edges();
	if (code=="")
		return Ref<Texture>();

	List<String> kwors;
	scr->get_language()->get_reserved_words(&kwors);

	Set<String> keywords;

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

		keywords.insert(E->get());

	}


	int line = 0;
	int col=0;
	int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
	thumbnail_size*=EDSCALE;
	Image img(thumbnail_size,thumbnail_size,0,Image::FORMAT_RGBA);



	Color bg_color = EditorSettings::get_singleton()->get("text_editor/background_color");
	bg_color.a=1.0;
	Color keyword_color = EditorSettings::get_singleton()->get("text_editor/keyword_color");
	Color text_color = EditorSettings::get_singleton()->get("text_editor/text_color");
	Color symbol_color = EditorSettings::get_singleton()->get("text_editor/symbol_color");
	Color comment_color = EditorSettings::get_singleton()->get("text_editor/comment_color");


	for(int i=0;i<thumbnail_size;i++) {
		for(int j=0;j<thumbnail_size;j++) {
			img.put_pixel(i,j,bg_color);
		}

	}

	bool prev_is_text=false;
	bool in_keyword=false;
	for(int i=0;i<code.length();i++) {

		CharType c = code[i];
		if (c>32) {
			if (col<thumbnail_size) {
				Color color = text_color;

				if (c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t')) {
					//make symbol a little visible
					color=symbol_color;
					in_keyword=false;
				} else if (!prev_is_text && _is_text_char(c)) {
					int pos = i;

					while(_is_text_char(code[pos])) {
						pos++;
					}
					///print_line("from "+itos(i)+" to "+itos(pos));
					String word = code.substr(i,pos-i);
					//print_line("found word: "+word);
					if (keywords.has(word))
						in_keyword=true;

				} else if (!_is_text_char(c)) {
					in_keyword=false;
				}

				if (in_keyword)
					color=keyword_color;

				Color ul=color;
				ul.a*=0.5;
				img.put_pixel(col,line*2,bg_color.blend(ul));
				img.put_pixel(col,line*2+1,color);

				prev_is_text=_is_text_char(c);
			}
		} else {

			prev_is_text=false;
			in_keyword=false;

			if (c=='\n') {
				col=0;
				line++;
				if (line>=thumbnail_size/2)
					break;
			} else if (c=='\t') {
				col+=3;
			}
		}
		col++;
	}

	Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture));

	ptex->create_from_image(img,0);
	return ptex;

}
示例#27
0
ScriptCreateDialog::ScriptCreateDialog() {

	/* SNAP DIALOG */

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


	class_name = memnew( LineEdit );
	VBoxContainer *vb2 = memnew( VBoxContainer );
	vb2->add_child(class_name);
	class_name->connect("text_changed", this,"_class_name_changed");
	error_label = memnew(Label);
	error_label->set_text("valid chars: a-z A-Z 0-9 _");
	error_label->set_align(Label::ALIGN_CENTER);
	vb2->add_child(error_label);
	vb->add_margin_child("Class Name:",vb2);

	parent_name = memnew( LineEdit );
	vb->add_margin_child("Inherits:",parent_name);
	parent_name->connect("text_changed", this,"_class_name_changed");

	language_menu = memnew( OptionButton );
	vb->add_margin_child("Language",language_menu);

	for(int i=0;i<ScriptServer::get_language_count();i++) {

		language_menu->add_item(ScriptServer::get_language(i)->get_name());
	}

	language_menu->select(0);
	language_menu->connect("item_selected",this,"_lang_changed");

	//parent_name->set_text();

	vb2 = memnew( VBoxContainer );
	path_vb = memnew( VBoxContainer );
	vb2->add_child(path_vb);

	HBoxContainer *hbc = memnew( HBoxContainer );
	file_path = memnew( LineEdit );
	file_path->connect("text_changed",this,"_path_changed");
	hbc->add_child(file_path);
	file_path->set_h_size_flags(SIZE_EXPAND_FILL);
	Button *b = memnew( Button );
	b->set_text(" .. ");
	b->connect("pressed",this,"_browse_path");
	hbc->add_child(b);
	path_vb->add_child(hbc);
	path_error_label = memnew( Label );
	path_vb->add_child( path_error_label );
	path_error_label->set_text("Error!");
	path_error_label->set_align(Label::ALIGN_CENTER);


	internal = memnew( CheckButton );
	internal->set_text("Built-In Script");
	vb2->add_child(internal);
	internal->connect("pressed",this,"_built_in_pressed");

	vb->add_margin_child("Path:",vb2);

	set_size(Size2(200,150));
	set_hide_on_ok(false);
	set_title("Create Script for Node");

	file_browse = memnew( EditorFileDialog );
	file_browse->connect("file_selected",this,"_file_selected");
	add_child(file_browse);
	get_ok()->set_text("Create");
	alert = memnew( AcceptDialog );
	add_child(alert);
	_lang_changed(0);
}
示例#28
0
Ref<Texture> EditorBitmapPreviewPlugin::generate(const RES& p_from) {

	Ref<BitMap> bm =p_from;

	if (bm->get_size()==Size2()) {
		return Ref<Texture>();
	}

	DVector<uint8_t> data;

	data.resize(bm->get_size().width*bm->get_size().height);

	{
		DVector<uint8_t>::Write w=data.write();

		for(int i=0;i<bm->get_size().width;i++) {
			for(int j=0;j<bm->get_size().height;j++) {
				if (bm->get_bit(Point2i(i,j))) {
					w[j*bm->get_size().width+i]=255;
				} else {
					w[j*bm->get_size().width+i]=0;

				}
			}

		}
	}


	Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_GRAYSCALE,data);

	int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
	thumbnail_size*=EDSCALE;
	if (img.is_compressed()) {
		if (img.decompress()!=OK)
			return Ref<Texture>();
	} else if (img.get_format()!=Image::FORMAT_RGB && img.get_format()!=Image::FORMAT_RGBA) {
		img.convert(Image::FORMAT_RGBA);
	}

	int width,height;
	if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) {

		width=thumbnail_size;
		height = img.get_height() * thumbnail_size / img.get_width();
	} else if (img.get_height() > thumbnail_size &&  img.get_height() >= img.get_width()) {

		height=thumbnail_size;
		width = img.get_width() * thumbnail_size / img.get_height();
	}  else {

		width=img.get_width();
		height=img.get_height();
	}

	img.resize(width,height);

	Ref<ImageTexture> ptex = Ref<ImageTexture>( memnew( ImageTexture ));

	ptex->create_from_image(img,0);
	return ptex;

}
示例#29
0
ConnectionsDock::ConnectionsDock(EditorNode *p_editor) {

	editor = p_editor;
	set_name(TTR("Signals"));

	VBoxContainer *vbc = this;

	tree = memnew(Tree);
	tree->set_columns(1);
	tree->set_select_mode(Tree::SELECT_ROW);
	tree->set_hide_root(true);
	vbc->add_child(tree);
	tree->set_v_size_flags(SIZE_EXPAND_FILL);
	tree->set_allow_rmb_select(true);

	connect_button = memnew(Button);
	connect_button->set_text(TTR("Connect"));
	HBoxContainer *hb = memnew(HBoxContainer);
	vbc->add_child(hb);
	hb->add_spacer();
	hb->add_child(connect_button);
	connect_button->connect("pressed", this, "_connect_pressed");

	connect_dialog = memnew(ConnectDialog);
	connect_dialog->set_as_toplevel(true);
	add_child(connect_dialog);

	disconnect_all_dialog = memnew(ConfirmationDialog);
	disconnect_all_dialog->set_as_toplevel(true);
	add_child(disconnect_all_dialog);
	disconnect_all_dialog->connect("confirmed", this, "_disconnect_all");
	disconnect_all_dialog->set_text(TTR("Are you sure you want to remove all connections from this signal?"));

	signal_menu = memnew(PopupMenu);
	add_child(signal_menu);
	signal_menu->connect("id_pressed", this, "_handle_signal_menu_option");
	signal_menu->add_item(TTR("Connect..."), CONNECT);
	signal_menu->add_item(TTR("Disconnect All"), DISCONNECT_ALL);

	slot_menu = memnew(PopupMenu);
	add_child(slot_menu);
	slot_menu->connect("id_pressed", this, "_handle_slot_menu_option");
	slot_menu->add_item(TTR("Edit..."), EDIT);
	slot_menu->add_item(TTR("Go To Method"), GO_TO_SCRIPT);
	slot_menu->add_item(TTR("Disconnect"), DISCONNECT);

	/*
	node_only->set_anchor( MARGIN_TOP, ANCHOR_END );
	node_only->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
	node_only->set_anchor( MARGIN_RIGHT, ANCHOR_END );

	node_only->set_begin( Point2( 20,51) );
	node_only->set_end( Point2( 10,44) );
	*/

	connect_dialog->connect("connected", this, "_make_or_edit_connection");
	tree->connect("item_selected", this, "_tree_item_selected");
	tree->connect("item_activated", this, "_tree_item_activated");
	tree->connect("item_rmb_selected", this, "_rmb_pressed");

	add_constant_override("separation", 3 * EDSCALE);
}
示例#30
0
BroadPhaseSW *BroadPhaseOctree::_create() {

	return memnew(BroadPhaseOctree);
}