Newer
Older
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <GLFW/glfw3.h>
#include <algorithm>
#include "OE_interfaceDisplay.h"
#include <chrono>
#include <thread>
// TODO: fix qwerty mapping
// TODO: handlers, qui a besoin de qui et quand, pas de redondance ? chemins les + simples ?
// TODO: lock pour la modif, histoire de péter tout le backend sans que l'ihm explose
void drawframe(GLFWwindow* window)
{
//NSVGshape* shape;
//NSVGpath* path;
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
static void OE_Mouse_Pos_Callback(GLFWwindow* window, double x, double y)
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if (root->display)
root->display->mouse_Pos(x, y);
static void OE_Mouse_Button_Callback(GLFWwindow* window, int button, int action, int mods)
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if (root->display)
root->display->mouse_Button(button, action, mods);
static void OE_Mouse_Scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if (root->display)
root->display->scroll(xoffset, yoffset);
static void OE_Key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if (root->display)
root->display->key(key, scancode, action, mods);
static void OE_Window_Resize_callback(GLFWwindow* window, int, int)
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if (root->display)
{
int width = 0, height = 0;
glfwGetFramebufferSize(window, &width, &height);
root->display->resize(width, height);
drawframe(window);
}
#include <sstream>
void showFPS(GLFWwindow *pWindow)
{
static unsigned nbFrames = 0;
static double lastTime = 0;
double currentTime = glfwGetTime();
double delta = currentTime - lastTime;
nbFrames++;
if ( delta >= 1.0 ) {
double fps = double(nbFrames) / delta;
std::stringstream ss;
ss << "Open embroider" << " [" << fps << " FPS]";
glfwSetWindowTitle(pWindow, ss.str().c_str());
nbFrames = 0;
lastTime = currentTime;
}
}
void startMain()
{
#ifdef SWINGING
int mainIhm();
std::thread newThread(mainIhm);
newThread.detach();
#endif
}
#ifdef SWINGING
int mainIhm()
#else
std::chrono::high_resolution_clock::time_point t0 = std::chrono::high_resolution_clock::now();
#define SHOWTIME() printf("%u: %ldms\n",\
__LINE__,\
std::chrono::duration_cast<std::chrono::milliseconds>(\
std::chrono::high_resolution_clock::now()-t0).count())
window = glfwCreateWindow(mode->width - 40, mode->height - 80, "Open embroider", NULL, NULL);
printf("Could not open window : %s\n", strerror(errno));
glfwSetWindowUserPointer(window, &root);
glfwSetFramebufferSizeCallback(window, OE_Window_Resize_callback);
glfwSetCursorPosCallback(window, OE_Mouse_Pos_Callback);
glfwSetMouseButtonCallback(window, OE_Mouse_Button_Callback);
glfwSetScrollCallback(window, OE_Mouse_Scroll_callback);
glfwSetKeyCallback(window, OE_Key_callback);
SHOWTIME();
// 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);
SHOWTIME();
#if 0
root.document = OE_svgParser::fromFile("../motifs/logo3.svg", "px", 96.0f);
root.document->saveToFile("../roger.oe");
#else
root.document = new OE_document();
root.document->loadFromFile("../roger.oe");
#endif
//root.document = OE_svgParser::fromFile("../motifs/open_embroider_em2.svg", "px", 96.0f);
//root.document = OE_svgParser::fromFile("../motifs/startrek_small.svg", "px", 96.0f);
if (root.document == NULL) {
printf("Could not open SVG image.\n");
glfwTerminate();
return -1;
}
root.interfaceDisplay = new OE_interfaceDisplay();
root.interfaceDisplay->setDocument(root.document);
root.display = root.interfaceDisplay;
root.controller = new OE_controller(root.display, root.document);
//root.controller->testOpenEmbroider();
//root.controller->testStarTrek();
if ((root.controller == NULL)||(root.display == NULL) ) {
glfwTerminate();
return -1;
}
root.display->setController(root.controller);
{
int width = 0, height = 0;
glfwGetFramebufferSize(window, &width, &height);
root.display->resize(width, height);
root.display->draw();
root.display->showAll();
while (!glfwWindowShouldClose(window))
{
drawframe(window);
glfwPollEvents();