Ejemplo n.º 1
0
void FileDialog_export_obj(EditorState *state, Node *node)
{
	// Get path
	std::string path = getSaveLoadDirectory(state->settings->get("save_directory"),
			state->isInstalled);

	const char* filters[] = {"*.obj"};

	const char *cfile = tinyfd_saveFileDialog("Export Node to Mesh", path.c_str(),
			1, filters);	

	if (!cfile)
		return;

	std::string filename = cfile;

	if (filename == "")
		return;

	std::string res = nodeToObj(node, filenameWithoutExt(filename));
	std::ofstream file(filename.c_str());
	if (!file)
		return;
	file << res.c_str();
	file.close();
}
Ejemplo n.º 2
0
void FileDialog_export(EditorState *state, int parser)
{
	// Get path
	std::string path = getSaveLoadDirectory(state->settings->get("save_directory"),
			state->isInstalled);

	const char* filters[] = {""};

	if (parser == (int)FILE_FORMAT_LUA)
		filters[0] = "*.lua";
	else if (parser == (int)FILE_FORMAT_CPP)
		filters[0] = "*.cpp";

	const char *cfile = tinyfd_saveFileDialog("Save Project", path.c_str(),
			1, filters);

	if (!cfile)
		return;

	std::string file = cfile;

	if (file == "")
		return;

	std::cerr << file << std::endl;

	FileFormat *writer = getFromType((FileFormatType)parser, state);
	save_file(writer, state, file);
}
Ejemplo n.º 3
0
	std::wstring* FileDialog::SaveFile (std::wstring* title, std::wstring* filter, std::wstring* defaultPath) {

		#ifdef HX_WINDOWS

		std::wstring temp (L"*.");
		const wchar_t* filters[] = { filter ? (temp + *filter).c_str () : NULL };

		const wchar_t* path = tinyfd_saveFileDialogW (title ? title->c_str () : 0, defaultPath ? defaultPath->c_str () : 0, filter ? 1 : 0, filter ? filters : NULL, NULL);

		if (path) {

			std::wstring* _path = new std::wstring (path);
			return _path;

		}

		#else

		std::string* _title = wstring_to_string (title);
		std::string* _filter = wstring_to_string (filter);
		std::string* _defaultPath = wstring_to_string (defaultPath);

		const char* filters[] = { NULL };

		if (_filter) {

			_filter->insert (0, "*.");
			filters[0] = _filter->c_str ();

		}

		const char* path = tinyfd_saveFileDialog (_title ? _title->c_str () : NULL, _defaultPath ? _defaultPath->c_str () : NULL, _filter ? 1 : 0, _filter ? filters : NULL, NULL);

		if (_title) delete _title;
		if (_filter) delete _filter;
		if (_defaultPath) delete _defaultPath;

		if (path) {

			std::string _path = std::string (path);
			std::wstring* __path = new std::wstring (_path.begin (), _path.end ());
			return __path;

		}

		#endif

		return 0;

	}
Ejemplo n.º 4
0
void CAppWindow::AskSaveOutput()
{
    const char *filters[] = { "*.txt" };
    char const *result = tinyfd_saveFileDialog("Select output file", "", 1, filters, "");
    // Пользователь отменил выбор файла.
    if (result == nullptr)
    {
        return;
    }
    std::ofstream out(result);
    if (!out.is_open() || !m_graph->PrintResults(out))
    {
        tinyfd_messageBox("Error", "I/O error when writing output file", "ok", "error", 1);
    }
    else
    {
        tinyfd_messageBox("Success", "File saved OK", "ok", "info", 1);
    }
}
Ejemplo n.º 5
0
  std::tuple<std::vector<std::string>, Window::DialogStatus, std::string> WindowManager::openDialogSync(
      Window::DialogMode mode,
      const std::string& title,
      const std::string& defaultFilePath,
      const std::vector<std::string> filters
  )
  {
    std::vector<std::string> paths;
    Window::DialogStatus status;
    const char* outPath = NULL;

    const char* f[256];
    for(int i = 0; i < filters.size(); i++) {
      f[i] = filters[i].c_str();
    }

    switch(mode) {
      case Window::DialogMode::FILE_DIALOG_OPEN_MULTIPLE:
      case Window::DialogMode::FILE_DIALOG_OPEN:
        outPath = tinyfd_openFileDialog(&title[0], &defaultFilePath[0], filters.size(), &f[0], NULL, mode == Window::DialogMode::FILE_DIALOG_OPEN_MULTIPLE);
        break;
      case Window::DialogMode::FILE_DIALOG_OPEN_FOLDER:
        outPath = tinyfd_selectFolderDialog(&title[0], &defaultFilePath[0]);
        break;
      case Window::DialogMode::FILE_DIALOG_SAVE:
        outPath = tinyfd_saveFileDialog(&title[0], &defaultFilePath[0], filters.size(), &f[0], NULL);
        break;
    }

    std::stringstream err;

    if(outPath == NULL) {
      return std::make_tuple(paths, Window::DialogStatus::CANCEL, "");
    }

    paths = split(std::string(outPath), '|');
    return std::make_tuple(paths, Window::DialogStatus::OKAY, "");
  }
Ejemplo n.º 6
0
void FileDialog_save_project(EditorState *state)
{
	// Get path
	std::string path = getSaveLoadDirectory(state->settings->get("save_directory"),
			state->isInstalled);

	const char* filters[] = {"*.nbe"};
	const char *cfile = tinyfd_saveFileDialog("Save Project", path.c_str(),
			1, filters);

	if (!cfile)
		return;

	std::string file = cfile;

	if (file == "")
		return;
	
	std::cerr << file << std::endl;

	FileFormat *writer = getFromType(FILE_FORMAT_NBE, state);
	save_file(writer, state, file);
}
Ejemplo n.º 7
0
bool TextureDialog::OnEvent(const SEvent &event)
{
    if (event.EventType != EET_GUI_EVENT)
        return false;

    if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) {
        switch (event.GUIEvent.Caller->getID()) {
        case ETD_GUI_ID_APPLY: {
            if (lb->getSelected() == 0) {
                node->setTexture(face, NULL);
                node->remesh();
                return true;
            }

            int count = 0;
            Media *media = &state->project->media;
            std::map<std::string, Media::Image*>& images = media->getList();
            for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                    it != images.end();
                    ++it) {
                if (count == lb->getSelected()-1) {
                    node->setTexture(face, it->second);
                    node->remesh();
                    break;
                }
                count++;
            }


            close();
            return true;
        }
        case ETD_GUI_ID_IMPORT: {
            ImageDialog::show(state, node, face);
            return false;
        }
        case ETD_GUI_ID_ACTIONS:
            context->setVisible(true);
            state->device->getGUIEnvironment()->setFocus(context);
            return false;
        }
    } else if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) {
        IGUIContextMenu *menu = (IGUIContextMenu *)event.GUIEvent.Caller;
        switch (menu->getItemCommandId(menu->getSelectedItem())) {
        case ETD_GUI_ID_EXPORT: {
            if (lb->getSelected() == 0)
                return true;

            int count = 0;
            Media *media = &state->project->media;
            Media::Image *image = NULL;
            std::map<std::string, Media::Image*>& images = media->getList();
            for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                    it != images.end();
                    ++it) {
                if (count == lb->getSelected() - 1) {
                    image = it->second;
                    break;
                }
                count++;
            }

            if (!image)
                return true;

            std::string path = getSaveLoadDirectory(state->settings->get("save_directory"),
                                                    state->isInstalled);
            path += image->name;

            const char *filters[] = {"*.png"};
            const char *cfilename = tinyfd_saveFileDialog("Save Image", path.c_str(),
                                    1, filters);
            if (!cfilename)
                return true;

            std::string filename = cfilename;

            if (filename == "")
                return true;

            state->device->getVideoDriver()->writeImageToFile(image->get(),
                    filename.c_str());

            return true;
        }
        } // end of switch
    } else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED && event.GUIEvent.Caller == lb) {
        if (lb->getSelected() == 0) {
            the_image = NULL;
            return true;
        }

        int count = 0;
        Media *media = &state->project->media;
        std::map<std::string, Media::Image*>& images = media->getList();
        for (std::map<std::string, Media::Image*>::const_iterator it = images.begin();
                it != images.end();
                ++it) {
            if (count == lb->getSelected()-1) {
                the_image = state->device->getVideoDriver()->addTexture("tmpicon.png", it->second->get());
                break;
            }
            count++;
        }
        return true;
    } else if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED && event.GUIEvent.Caller == win) {
        if (canClose())
            close();
        return true;
    }
    return false;
}
		static FS::path SaveFileDialog(const char* title, const char* defaultPathAndFile = "", const int numberOfFilterPatterns = 0, const char * const * filterPatterns = nullptr)
		{
			const auto path = tinyfd_saveFileDialog(title, defaultPathAndFile, numberOfFilterPatterns, filterPatterns, "");
			return path == nullptr ? "" : path;
		}