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
// TODO: list les features présentes et à venir, disons jusqu'à la v1.0 alpha pour commencer
// TODO MF: déplacement de groupes
// TODO MF: resize de groupes
// TODO MF: intégration/merge avec autre doc, gaffe aux scaling, normalisation générale des coords pour nos fichiers ?
3dsman
committed
// liste des bugs identifiés a corriger
// TODO bug dans OE_interfaceDisplay::selectApply la selection ne clear qu'un seul type (curve ou stitch) quand on selection uniquement des objets de l'autre type
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_Drop_callback(GLFWwindow* window, int nbFiles, const char ** files)
{
OE_root* root = (OE_root*)glfwGetWindowUserPointer(window);
if ((root->document)&&(nbFiles>0))
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
std::string path(*files);
size_t dot = path.find_last_of(".");
if (dot != std::string::npos)
{
std::string ext = path.substr(dot, path.size() - dot);
std::cout<<ext<<std::endl;
if (ext == ".oe")
{
OE_document* tmp_doc = new OE_document;
delete root->document;
root->document = tmp_doc;
root->document->loadFromFile(path);
}
if (ext == ".svg")
{
OE_document* tmp_doc = OE_svgParser::fromFile(path, "px", 96.0f);
if (tmp_doc != NULL) {
delete root->document;
root->document = tmp_doc;
}else{
printf("Could not open SVG image.\n");
}
}
if (root->display)
{
root->display->setDocument(root->document);
root->display->showAll();
}
if (root->controller)
{
root->controller->setDocument(root->document);
root->controller->testLogo2();
}
}
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);
glfwSetDropCallback(window, OE_Drop_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();
root.document = new OE_document();
/*
#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);
if ((root.controller == NULL)||(root.display == NULL) ) {
glfwTerminate();
return -1;
}
//root.controller->testLogo2();
//root.controller->testOpenEmbroider();
//root.controller->testStarTrek();
root.controller->initNewDocument();
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();