Esempio n. 1
0
/** Creates filedialog and returns filepath(s) on succes, empty string on failure.*/
void cbeFileDialog(CBEnchanted * cb) {
	int mode = cb->popValue().getInt();
	string patterns = cb->popValue().toString().getRef();
#ifdef _WIN32
	string title = cb->popValue().toString().getRef();
#else
	string title = cb->popValue().toString().getUtf8Encoded();
#endif
	ALLEGRO_PATH * path = cb->popValue().toString().getPath();

	ALLEGRO_FILECHOOSER * fC = al_create_native_file_dialog(al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP), title.c_str(), patterns.c_str(), mode);
	al_destroy_path(path);

	if(fC == NULL) {
		cb->errors->createError("Can't create FileDialog!");
		cb->pushValue(0);
		return;
	}
	bool retVal = al_show_native_file_dialog(cb->gfxInterface->getWindow(), fC);

	if(retVal) {
		string filePaths = "";
		for(int count = 0; count < al_get_native_file_dialog_count(fC); count++) {
			filePaths += string(al_get_native_file_dialog_path(fC, count)) + string("|");
		}
		cb->pushValue(filePaths.substr(0, filePaths.length()-1));
	} else {
		cb->pushValue(string(""));
	}

	al_destroy_native_file_dialog(fC);

}
Esempio n. 2
0
static int allua_Filechooser_show(lua_State * L)
{
   ALLUA_filechooser d = allua_check_filechooser(L, 1);
   ALLUA_display display = NULL;
   if (!lua_isnoneornil(L, 2))
      display = allua_check_display(L, 2);
   al_show_native_file_dialog(display, d);
   return 0;
}
Esempio n. 3
0
void mapEditor::saveMap() {
	ALLEGRO_FILECHOOSER* fC = al_create_native_file_dialog(al_create_path(""),"Select Location..","*.map",ALLEGRO_FILECHOOSER_SAVE);
	al_show_native_file_dialog(this->display,fC);
	const ALLEGRO_PATH* savePath = al_get_native_file_dialog_path(fC,0);
	const char* pathName = al_path_cstr(savePath, ALLEGRO_NATIVE_PATH_SEP);
	ALLEGRO_FILE* fHandle = al_fopen(pathName,"wb");
	mapSaver* newSaver = new mapSaver(*this->mHandler->mData);
	newSaver->writeData(fHandle);
	al_fclose(fHandle);
}
Esempio n. 4
0
	void Map::SaveMapDialog()
	{
		ALLEGRO_FILECHOOSER *saveDialog;
		saveDialog = al_create_native_file_dialog("..\\Maps\\", "Save Map", "*.*", ALLEGRO_FILECHOOSER_SAVE);
		al_show_native_file_dialog(display_, saveDialog);
		mapPath_ = al_create_path(al_get_native_file_dialog_path(saveDialog,0));
		if(strcmp(al_get_path_extension(mapPath_),"") == 0)
		{
			al_set_path_extension(mapPath_, ".mapa");
		}
		SaveMap();
		al_destroy_native_file_dialog(saveDialog);
	}
Esempio n. 5
0
void equipAligner::saveAlignmentPieceData() {
	ALLEGRO_FILECHOOSER* fC = al_create_native_file_dialog("","Open Image to align..","*.raw",ALLEGRO_FILECHOOSER_SAVE);
	al_show_native_file_dialog(this->display,fC);
	const char* pathName = al_get_native_file_dialog_path(fC,0);
	if (pathName!=NULL) {
		//const char* pathName = al_path_cstr(savePath, ALLEGRO_NATIVE_PATH_SEP);
		std::fstream o(pathName, std::ios::out | std::ios::binary | std::ios::trunc);
		if (o.is_open()) {
			o.write((char*)&aligningImageProperties,sizeof(aligningImageProperties));
			o.close();
		}
	}
}
Esempio n. 6
0
void equipAligner::pickAlignmentPiece() {
	ALLEGRO_FILECHOOSER* fC = al_create_native_file_dialog("","Open Image to align..","*.png",0);
	al_show_native_file_dialog(this->display,fC);
	const char* pathName = al_get_native_file_dialog_path(fC,0);
	if (pathName!=NULL) {
		//const char* pathName = al_path_cstr(savePath, ALLEGRO_NATIVE_PATH_SEP);
		ALLEGRO_BITMAP* image = al_load_bitmap(pathName);
		if (image!=NULL) {
			aligningImage = image;
			aligningImageProperties.offsetX = 0;
			aligningImageProperties.offsetY = 0;
			aligningImageProperties.originX = al_get_bitmap_width(image)/2;
			aligningImageProperties.originY = al_get_bitmap_height(image)/2;
		}
	}

	return;
}
Esempio n. 7
0
	void Map::LoadMapDialog()
	{
		ALLEGRO_FILECHOOSER *loadDialog = NULL;
		loadDialog = al_create_native_file_dialog("..\\Maps\\", "Load Mapx file","*.*",0);	
		al_show_native_file_dialog(display_, loadDialog);
		mapPath_ = al_create_path(al_get_native_file_dialog_path(loadDialog, 0));
		LoadMap();


		//ADJUST offset if a player has been placed but since player placed is false somteimes set it to top left corner as players pos will be created at this point
		mapXoffset_ = width_*Constants::TileSize <= settings_->GetScreenWidth() ? settings_->GetScreenWidth()/2-width_*Constants::TileSize/2 : 0;
		mapYoffset_ = height_*Constants::TileSize <= settings_->GetScreenHeight() ? settings_->GetScreenHeight()/2-height_*Constants::TileSize/2 : 0;

		PreCalc();


		al_destroy_native_file_dialog(loadDialog);

	}
Esempio n. 8
0
char * select_file(const char * initial, const char * title, const char * types, int flags)
{
	al_stop_timer(t3f_timer);
	ALLEGRO_FILECHOOSER * file_selector = NULL;
	const char * rpath = NULL;
	file_selector = al_create_native_file_dialog(initial, title, types, flags);
	al_show_native_file_dialog(t3f_display, file_selector);
	if(al_get_native_file_dialog_count(file_selector))
	{
		rpath = al_get_native_file_dialog_path(file_selector, 0);
	}
	if(rpath)
	{
		strcpy(mapper_filename, rpath);
	}
	al_destroy_native_file_dialog(file_selector);
	al_start_timer(t3f_timer);
	if(rpath)
	{
		return mapper_filename;
	}
	return NULL;
}
Esempio n. 9
0
bool AllegroShell::prompt_for_file(char* buffer,unsigned bufsize,const char* pattern){
	al_rest(0.2); // Hack that i need for it to work!

	// Create a file chooser dialog
	ALLEGRO_FILECHOOSER* d;
	d = al_create_native_file_dialog(NULL,"",pattern,1); // 1 means file must exist
	if(!d){return false;}
	if(!al_show_native_file_dialog(NULL,d)){
		al_destroy_native_file_dialog(d);
		return false;
	}

	// check to make sure something was seleeted
	if( al_get_native_file_dialog_count(d) != 1){
		al_destroy_native_file_dialog(d);
		return false;
	}

	// Get the file that was selected, and copy into 'buffer'
	const char* file = al_get_native_file_dialog_path(d,0);
	strncpy(buffer,file,sizeof(char)*bufsize);
	buffer[bufsize-1] = 0;
	return true;
}
Esempio n. 10
0
 /**
     Shows this dialog on the given display.
     @param display display to show the dialog onto.
     @return true on success.
  */
 bool show(Display &display) {
     return al_show_native_file_dialog(display.get(), get());
 }
/*Cria uma interface grafica nativa para o usuario selecionar um arquivo
@param
	ALLEGRO_DISPLAY *janela - janela onde ira mostrar a interface 
*/
char * uiGetDiretorio(ALLEGRO_DISPLAY *janela, const char *msg, int flag){
    ALLEGRO_FILECHOOSER *file_dialog;
    file_dialog = al_create_native_file_dialog("c:/", msg, "*.*",flag);
    al_show_native_file_dialog(janela, file_dialog);
    return (char*)al_get_native_file_dialog_path(file_dialog, 0);
}
Esempio n. 12
0
void Editor_controller::Handle_event(const Ustring& event_handle, const Event& event) {
	Layout& layout = layout_controller->Get_layout();
	if(event_handle == "save") {
		ALLEGRO_FILECHOOSER* fc = al_create_native_file_dialog(
			layout.Get_filename().Cstring(),
			"Save",
			"*",
			ALLEGRO_FILECHOOSER_SAVE);
		al_show_native_file_dialog(NULL, fc);
		if(al_get_native_file_dialog_count(fc) > 0) {
			const char *filename = al_get_native_file_dialog_path(fc, 0);
			layout.Set_filename(filename);

			bool s = layout.Save_yaml();
			std::cout<<(s?"Saved":"Save failed")<<std::endl;
		}
		al_destroy_native_file_dialog(fc);
	}
	if(event_handle == "load") {
		ALLEGRO_FILECHOOSER* fc = al_create_native_file_dialog(
			layout.Get_filename().Cstring(),
			"Load",
			"*",
			ALLEGRO_FILECHOOSER_FILE_MUST_EXIST);
		al_show_native_file_dialog(NULL, fc);
		if(al_get_native_file_dialog_count(fc) > 0) {
			const char *filename = al_get_native_file_dialog_path(fc, 0);
			layout.Set_filename(filename);

			layout_controller->Clear();
			if(layout.Load_yaml())
			{
				std::cout<<"Loaded"<<std::endl;
				const Name_to_widget& layout_widgets = layout.Get_widgets();

				layout_controller->Set_root(layout.Get_root());
				layout_controller->Get_root()->Set_size(Vector2(al_get_display_width(layout_display), al_get_display_height(layout_display)));
				layout_controller->Set_tree(layout_controller->Get_root_tree(), layout.Get_root());

				typedef std::stack<Tree*> Trees_todo;
				Trees_todo trees_todo;
				trees_todo.push(layout_controller->Get_root_tree());
				
				while(!trees_todo.empty())
				{
					Tree* current_tree = trees_todo.top();
					trees_todo.pop();

					Container* parent = dynamic_cast<Container*>(layout_controller->Get_widget(current_tree));

					if(parent)
					{
						Widgets children = parent->Get_children();
						for(Widgets::iterator i = children.begin(); i != children.end(); ++i)
						{
							Tree* tree_child = layout_controller->Get_skin().Clone<Tree>("tree");
							tree_child->Set_text((*i)->Get_name());
							layout_controller->Set_tree(tree_child, *i);
							current_tree->Add_child(tree_child);
							events[Event(tree_child, "selected")] = "select";
							trees_todo.push(tree_child);
						}
					}
				}
			}
			else
			{
				layout_controller->Set_root(layout_controller->Get_skin().Clone<Desktop>("desktop"));
				layout_controller->Get_root()->Set_position(Vector2(0, 0));
				layout_controller->Get_root()->Set_size(Vector2(al_get_display_width(layout_display), al_get_display_height(layout_display)));
				
				layout.Add_widget("root", layout_controller->Get_root(), NULL);
				layout_controller->Set_tree(layout_controller->Get_root_tree(), layout_controller->Get_root());
			}
			layout_controller->Select_tree(NULL);
		}
		al_destroy_native_file_dialog(fc);
	}
	if(event_handle == "remove") {
		Tree* parent = dynamic_cast<Tree*>(layout_controller->Get_current_tree()->Get_parent());
		if(parent)
		{
			dynamic_cast<Container*>(layout_controller->Get_widget(parent))->Remove_child(layout_controller->Get_current_widget());

			parent->Remove_child(layout_controller->Get_current_tree());
			Trees deadlist;
			deadlist.push_back(layout_controller->Get_current_tree());
			layout_controller->Select_tree(NULL);
			int count = 0;
			while(!deadlist.empty())
			{
				Tree* current = deadlist.back();
				deadlist.erase(--deadlist.end());
				Trees& children = current->Get_children();
				for(Trees::iterator i = children.begin(); i != children.end(); ++i)
				{
					deadlist.push_back(*i);
				}
				layout.Remove_widget(layout_controller->Get_widget(current));
				layout_controller->Destroy_widget(current);
				++count;
			}
			layout_controller->Select_tree(parent);
			parent->Select();
		}
	}
	if(event_handle == "create") {
		std::cout<<"Create"<<std::endl;
		if(layout_controller->Get_current_tree())
		{
			std::cout<<"Current tree"<<std::endl;
			Menu* create_menu = dynamic_cast<Menu*>(controller_layout.Get_widget("create menu"));
			int option = create_menu->Get_selected_option();
			if(option != -1){
				Widget* child = layout_controller->Get_skin().Clone<Widget>(create_menu->Get_option(option));
				Container* parent = dynamic_cast<Container*>(layout_controller->Get_current_widget());
				std::cout<<"parent: "<<parent<<std::endl;

				if(parent && parent->Add_child(child))
				{
					Ustring name = layout.Add_widget(create_menu->Get_option(option), child, parent);
					Tree* tree_child = layout_controller->Get_skin().Clone<Tree>("tree");
					tree_child->Set_text(name);
					layout_controller->Get_current_tree()->Add_child(tree_child);
					layout_controller->Set_tree(tree_child, child);
					layout_controller->Get_current_tree()->Open();
					Text_interface* has_text = dynamic_cast<Text_interface*>(child);
					if(has_text)
						has_text->Set_text(name);
					events[Event(tree_child, "selected")] = "select";
				}
				else
					delete child;
			}
		}
	}

	if(event_handle == "select")
	{
		Tree* newsel = dynamic_cast<Tree*>(event.source);
		if(newsel)
		{
			Widget* tw = layout_controller->Get_widget(newsel);
			if(tw)
			{
				Container* attributes_vbox = dynamic_cast<Container*>(controller_layout.Get_widget("attribute vbox"));
				layout_controller->Select_tree(newsel);
				Widgets widgets = attributes_vbox->Get_children();
				for(Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) {
					attributes_vbox->Remove_child(*i);
				}
				attributes_vbox->Add_child(attribute_controllers["widget"]->Get_root());
				attribute_controllers["widget"]->Synchronize_values();
				Attribute_controllers::iterator ac = attribute_controllers.find(tw->Get_prototype_name().Cstring());
				if(ac != attribute_controllers.end()) {
					attributes_vbox->Add_child(ac->second->Get_root());
					ac->second->Synchronize_values();
				}
			}
		}
	}
	if(event_handle == "move up") {
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			Widgets children = parent->Get_children();
			Widgets::iterator i = std::find(children.begin(), children.end(), widget);
			Trees treechildren = parenttree->Get_children();
			Trees::iterator itree = std::find(treechildren.begin(), treechildren.end(), currenttree);
			if(i != children.begin()) {
				i = children.erase(i);
				itree = treechildren.erase(itree);
				if(i != children.begin()){
					--i;
					--itree;
				}
				children.insert(i, widget);
				treechildren.insert(itree, currenttree);
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Remove_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Remove_child(*i);
				}
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Add_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Add_child(*i);
				}
			}
		}
	}
	if(event_handle == "move down") {
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			Widgets children = parent->Get_children();
			Widgets::iterator i = std::find(children.begin(), children.end(), widget);
			Trees treechildren = parenttree->Get_children();
			Trees::iterator itree = std::find(treechildren.begin(), treechildren.end(), currenttree);
			if(i+1 != children.end()) {
				i = children.erase(i);
				itree = treechildren.erase(itree);
				++i;
				++itree;
				children.insert(i, widget);
				treechildren.insert(itree, currenttree);
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Remove_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Remove_child(*i);
				}
				for(Widgets::iterator i = children.begin(); i != children.end(); ++i) {
					parent->Add_child(*i);
				}
				for(Trees::iterator i = treechildren.begin(); i != treechildren.end(); ++i) {
					parenttree->Add_child(*i);
				}
			}
		}
	}
	if(event_handle == "cut") {
		std::cout<<"Cut"<<std::endl;
		Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
		Tree* parenttree = dynamic_cast<Tree*>(currenttree->Get_parent());
		if(currenttree && parenttree)
		{
			Widget* widget = layout_controller->Get_current_widget();
			Container* parent = dynamic_cast<Container*>(widget->Get_parent());
			
			parent->Remove_child(widget);
			parenttree->Remove_child(currenttree);

			layout_controller->Select_tree(NULL);
			layout_controller->Select_tree(parenttree);
			parenttree->Select();

			if(cut_widget) {
				Trees deadlist;
				deadlist.push_back(cut_tree);
				int count = 0;
				while(!deadlist.empty())
				{
					Tree* current = deadlist.back();
					deadlist.erase(--deadlist.end());
					Trees& children = current->Get_children();
					for(Trees::iterator i = children.begin(); i != children.end(); ++i)
					{
						deadlist.push_back(*i);
					}
					layout.Remove_widget(layout_controller->Get_widget(current));
					layout_controller->Destroy_widget(current);
					++count;
				}
				std::cout<<"Deleted "<<count<<" widgets in cut buffer"<<std::endl;
			}
			
			cut_widget = widget;
			cut_tree = currenttree;
		}
	}
	if(event_handle == "paste") {
		Container* parent = dynamic_cast<Container*>(layout_controller->Get_current_widget());
		if(cut_widget && parent)
		{
			Tree* currenttree = dynamic_cast<Tree*>(layout_controller->Get_current_tree());
			parent->Add_child(cut_widget);
			currenttree->Add_child(cut_tree);
			layout_controller->Select_tree(cut_tree);
			cut_tree->Select();
			cut_widget = NULL;
			cut_tree = NULL;
		}
	}
}