Skip to content
main.cpp 4.3 KiB
Newer Older
3dsman's avatar
3dsman committed
//
// Copyright (c) 2013 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty.  In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would be
//    appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
//    misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//

#include <stdio.h>
#include <string.h>
#include <float.h>
#include <GLFW/glfw3.h>
#include <algorithm>

#include "OE_document.h"
#include "OE_svgParser.h"
#include "OE_controller.h"
3dsman's avatar
3dsman committed
#include <iostream>

//#include "nanosvg.h"

//NSVGimage* g_image = NULL;
OE_document* document = NULL;
OE_display* display = NULL;
OE_interfaceDisplay* interfaceDisplay = NULL;
OE_controller* controller = NULL;
3dsman's avatar
3dsman committed

//static unsigned char bgColor[4] = {205,202,200,255};
3dsman's avatar
3dsman committed

void drawframe(GLFWwindow* window)
{
	//NSVGshape* shape;
	//NSVGpath* path;

	glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
3dsman's avatar
3dsman committed
	glfwSwapBuffers(window);
}


static void My_Mouse_Pos_Callback(GLFWwindow* window, double x, double y)
{
	if (display) display->mouse_Pos(x, y);
3dsman's avatar
3dsman committed
}

static void My_Mouse_Button_Callback(GLFWwindow* window, int button, int action, int mods)
{
	if (display) display->mouse_Button(button, action, mods);
3dsman's avatar
3dsman committed
}

void My_Scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
	if (display) display->scroll(xoffset, yoffset);
3dsman's avatar
3dsman committed
}

void My_key_callback(GLFWwindow* window,  int key, int scancode, int action, int mods)
{
	if (display) display->key(key, scancode, action, mods);
}

3dsman's avatar
3dsman committed

void resizecb(GLFWwindow* window, int width, int height)
{
	if (display)
	{
		int width = 0, height = 0;
		glfwGetFramebufferSize(window, &width, &height);
		display->resize(width, height);
		drawframe(window);
	}
3dsman's avatar
3dsman committed
}

int main()
{
	GLFWwindow* window;
	const GLFWvidmode* mode;

	if (!glfwInit())
		return -1;

	mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    window = glfwCreateWindow(mode->width - 40, mode->height - 80, "Open embroider", NULL, NULL);
	if (!window)
	{
		printf("Could not open window\n");
		glfwTerminate();
		return -1;
	}

	glfwSetFramebufferSizeCallback(window, resizecb);
    glfwSetCursorPosCallback(window, My_Mouse_Pos_Callback);
    glfwSetMouseButtonCallback(window, My_Mouse_Button_Callback);
    glfwSetScrollCallback(window, My_Scroll_callback);
	glfwSetKeyCallback(window, My_key_callback);
3dsman's avatar
3dsman committed

    // Enable sticky keys
    glfwSetInputMode(window, GLFW_STICKY_KEYS, true);

    // Disable vertical sync (on cards that support it)
    glfwSwapInterval( 1 );

	glfwMakeContextCurrent(window);
	glEnable(GL_POINT_SMOOTH);
    glEnable(GL_LINE_SMOOTH);
    OE_svgParser * parser = new OE_svgParser();
    document = parser->ParseFile("../motifs/logo3.svg", "px", 96.0f);
    //document = parser->ParseFile("../motifs/open_embroider_em2.svg", "px", 96.0f);
    //document = parser->ParseFile("../motifs/startrek_small.svg", "px", 96.0f);
    delete parser;

    if (document == NULL) {
        printf("Could not open SVG image.\n");
        glfwTerminate();
        return -1;
    }
    interfaceDisplay = new OE_interfaceDisplay();
    interfaceDisplay->setDocument(document);
    display = interfaceDisplay;

	controller = new OE_controller(display, document);
        controller->testLogo2();
        //controller->testOpenEmbroider();
        //controller->testStarTrek();

    if ((controller == NULL)||(display == NULL) ) {
        glfwTerminate();
        return -1;
    }
    display->setController(controller);
3dsman's avatar
3dsman committed
		
	
	{
		int width = 0, height = 0;
		glfwGetFramebufferSize(window, &width, &height);
		display->resize(width, height);
		display->draw();
		display->showAll();
	}
3dsman's avatar
3dsman committed

	while (!glfwWindowShouldClose(window))
	{
		drawframe(window);
		glfwPollEvents();
	}

	glfwTerminate();
	return 0;
}