Blame synfig-studio/src/test/visualization/main.cpp

9ea54a
9ea54a
#include <iostream></iostream>
9ea54a
#include <vector></vector>
9ea54a
9ea54a
#ifdef _WIN32
9ea54a
#include <windows.h></windows.h>
9ea54a
#endif
9ea54a
9ea54a
#include <glibmm.h></glibmm.h>
9ea54a
9ea54a
#include <gtkmm application.h=""></gtkmm>
9ea54a
9ea54a
#include <synfig general.h=""></synfig>
9ea54a
#include <synfig main.h=""></synfig>
9ea54a
#include <synfig loadcanvas.h=""></synfig>
9ea54a
#include <synfig filesystemnative.h=""></synfig>
9ea54a
9ea54a
#include "visualizationwindow.h"
9ea54a
9ea54a
9ea54a
using namespace synfig;
c4ee38
typedef std::map<string, rendering::renderer::handle=""> RendererMap;</string,>
9ea54a
9ea54a
9ea54a
const char commandname[] = "visualization";
9ea54a
9ea54a
9ea54a
class TestCallback: public ProgressCallback {
9ea54a
public:
9ea54a
	virtual bool task(const String &task)
9ea54a
		{ synfig::info("%s", task.c_str()); return true; }
9ea54a
	virtual bool error(const String &task)
9ea54a
		{ synfig::error("%s", task.c_str()); return true; }
9ea54a
	virtual bool warning(const String &task)
9ea54a
		{ synfig::warning("%s", task.c_str()); return true; }
9ea54a
};
9ea54a
9ea54a
c4ee38
void print_renderers(const RendererMap& renderers) {
c4ee38
	std::cout << "available renderers: " << std::endl;
c4ee38
	for(RendererMap::const_iterator i = renderers.begin(); i != renderers.end(); ++i)
c4ee38
		if (i->second)
c4ee38
			std::cout << "  " << i->first << " - " << i->second->get_name() << std::endl;
c4ee38
}
c4ee38
c4ee38
9ea54a
int main(int argc, char **argv)
9ea54a
{
9ea54a
9ea54a
	//// init
9ea54a
9ea54a
9ea54a
#ifdef _WIN32
9ea54a
	//  Enable standard input/output on Windows
9ea54a
	if (AttachConsole(ATTACH_PARENT_PROCESS)) {
9ea54a
		freopen("CON", "r", stdin);
9ea54a
		freopen("CON", "w", stdout);
9ea54a
		freopen("CON", "w", stderr);
9ea54a
	}
9ea54a
#endif
9ea54a
9ea54a
	Glib::init();
9ea54a
9ea54a
	String binary_path = get_binary_path(argv[0]);
9ea54a
	String base_dir = etl::dirname(binary_path);
9ea54a
	TestCallback callback;
9ea54a
9ea54a
	Main main(base_dir, &callback);
9ea54a
9ea54a
	info("Visualization test");
9ea54a
9ea54a
	// copy args
9ea54a
	std::vector<char*> args(argv, argv + argc);</char*>
9ea54a
	argv = &args.front();
9ea54a
9ea54a
9ea54a
	//// parse command line
9ea54a
9ea54a
9ea54a
	const RendererMap& renderers = rendering::Renderer::get_renderers();
9ea54a
	
9ea54a
	if (argc < 3) {
9ea54a
		std::cout << std::endl;
9ea54a
		std::cout << "usage: " << std::endl;
9ea54a
		std::cout << "  " << commandname << " <file.sif|file.sifz> <renderer>" << std::endl;</renderer></file.sif|file.sifz>
9ea54a
		std::cout << std::endl;
c4ee38
		print_renderers(renderers);
9ea54a
		return 0;
9ea54a
	}
9ea54a
9ea54a
	const String filename = argv[1];
9ea54a
	info("filename: %s", filename.c_str());
9ea54a
9ea54a
	const String renderer_name = argv[2];
9ea54a
	info("renderer_name: %s", renderer_name.c_str());
9ea54a
9ea54a
	// remove processed args from argv
9ea54a
	args.erase(args.begin() + 1);
9ea54a
	args.erase(args.begin() + 1);
9ea54a
	argc = (int)args.size();
9ea54a
9ea54a
9ea54a
	//// get renderer
9ea54a
9ea54a
9ea54a
	RendererMap::const_iterator ri = renderers.find(renderer_name);
9ea54a
	if (ri == renderers.end() || !ri->second) {
9ea54a
		error("unknown renderer: %s", renderer_name.c_str());
c4ee38
		print_renderers(renderers);
9ea54a
		return 1;
9ea54a
	}
9ea54a
	rendering::Renderer::Handle renderer = ri->second;
9ea54a
9ea54a
9ea54a
	//// get canvas
9ea54a
9ea54a
9ea54a
	String errors, warnings;
9ea54a
	Canvas::Handle canvas = open_canvas_as(
9ea54a
		FileSystemNative::instance()->get_identifier(filename),
9ea54a
		filename,
9ea54a
		errors,
9ea54a
		warnings );
9ea54a
	if (!canvas)
9ea54a
		return 1;
9ea54a
9ea54a
9ea54a
	//// run Gtk::Application
9ea54a
9ea54a
9ea54a
	info("create Gtk::Application");
9ea54a
	
9ea54a
	Glib::RefPtr<gtk::application> application = Gtk::Application::create(argc, argv);</gtk::application>
9ea54a
	
9ea54a
	info("create window");
9ea54a
	VisualizationWindow window(canvas, renderer);
9ea54a
	
9ea54a
	info("run");
9ea54a
	int result = application->run(window);
9ea54a
	
9ea54a
	if (result) error("Gtk::Application finished with errog code: %d", result);
9ea54a
	info("end");
9ea54a
	return result;
9ea54a
}
9ea54a