Newer
Older
//
// 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_interfaceDisplay.h"
#include <iostream>
//#include "nanosvg.h"
//NSVGimage* g_image = NULL;
OE_display* display = NULL;
OE_interfaceDisplay* interfaceDisplay = NULL;
void drawframe(GLFWwindow* window)
{
//NSVGshape* shape;
//NSVGpath* path;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
if (display)
{
display->draw();
}
glfwSwapBuffers(window);
}
static void My_Mouse_Pos_Callback(GLFWwindow* window, double x, double y)
{
if (display) display->mouse_Pos(x, y);
}
static void My_Mouse_Button_Callback(GLFWwindow* window, int button, int action, int mods)
{
if (display) display->mouse_Button(button, action, mods);
}
void My_Scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
if (display) display->scroll(xoffset, yoffset);
void My_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (display) display->key(key, scancode, action, mods);
}
if (display)
{
int width = 0, height = 0;
glfwGetFramebufferSize(window, &width, &height);
display->resize(width, height);
drawframe(window);
}
}
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);
// 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);
controller = new OE_controller(display, document);
controller->testLogo2();
//controller->testOpenEmbroider();
//controller->testStarTrek();
if ((controller == NULL)||(display == NULL) ) {
glfwTerminate();
return -1;
}
display->setController(controller);
{
int width = 0, height = 0;
glfwGetFramebufferSize(window, &width, &height);
display->resize(width, height);
display->draw();
display->showAll();
}