Skip to content
OE_interfaceDisplay.cpp 26 KiB
Newer Older
/*
 * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr
 *
 * 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 "OE_interfaceDisplay.h"
#include "OE_utils.h"

#include "OE_controller.h"

#include <iostream>

#include <GL/gl.h>
#include <cstdlib>
#include <math.h>
#include <cstdio>
#include <cstring>
#include <algorithm> 

#include "actions/OE_actionsCurves.h"
#include "actions/OE_actionsStitchs.h"
#include "actions/OE_actionsLineStitchs.h"
#include "actions/OE_actionsBirailStitchs.h"
3dsman's avatar
3dsman committed
#include "actions/OE_actionsFillStitchs.h"
#include "actions/OE_actionsSelection.h"
#include "actions/OE_actionsThreads.h"

raoul's avatar
raoul committed
static const GLuint TOOLSSELID = 0;
static const GLuint STITCHSSELID  = 1;
static const GLuint CURVESSELID = 2;
raoul's avatar
raoul committed
static const GLuint ZEROID  = 0;
static const GLuint TRANSTOOLID = 1;
static const GLuint MOVETOOLID = 0;
static const GLuint SCALETOOLID = 1;
raoul's avatar
raoul committed
OE_interfaceDisplay::OE_interfaceDisplay(OE_document* document)
	editStyle = new OE_display::OE_displayStyle();
	commandStyle = new OE_display::OE_displayStyle();
	commandStyle->drawGrid = false;
	commandStyle->drawCurves = false;
	commandStyle->drawStitches = false;
	commandStyle->drawCommands = true;
raoul's avatar
raoul committed
	setDocument(document);
}

OE_interfaceDisplay::~OE_interfaceDisplay()
{
raoul's avatar
raoul committed
bool OE_interfaceDisplay::setDocument(OE_document* document)
raoul's avatar
raoul committed
	return true;
}


bool OE_interfaceDisplay::setController(OE_controller* controller)
{
raoul's avatar
raoul committed
	return true;
}

void OE_interfaceDisplay::mouse_Pos(double x, double y)
{
raoul's avatar
raoul committed
	OE_display::mouse_Pos(x, y);
	vector_2dt oldClosestPoint = editClosestPoint;
raoul's avatar
raoul committed
	vector_2d absMove = vector_2d((mouse.x - clicOldMouse.x)*zoom*2, (mouse.y - clicOldMouse.y)*zoom*2);
raoul's avatar
raoul committed
	if (editionState == MoveSelection) //if the move action is enabled
raoul's avatar
raoul committed
		controller->editActionMoveSelection(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
		                                              (mouse.y - clicOldMouse.y)*zoom*2));
		return;
raoul's avatar
raoul committed
	if (editionState == ScaleSelection) //if the scale action is enabled
	{
		vector_2d bbCenter = controller->getSelectionBoundingBox().getCenter();
		float scale = (absMouse-bbCenter).len()/(screenToDocument(clicOldMouse)-bbCenter).len();
raoul's avatar
raoul committed
		controller->editActionScaleSelection(vector_2d(scale,scale));
		return;
	if (editionState == NewSubcurve) //if we must find the closest subcurve (get the closest point on it too)
	{
		closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
	}else if (editSubcurve) //if we are working on a defined subcurve get the closest point on it
raoul's avatar
raoul committed
	{
		editClosestPoint = controller->getClosestPoint(editSubcurve->getCurve(), absMouse);
	}
	if (editionState == MovePointcurve && selControlCurve && selControlType==0) //if we're moving a curve control point
raoul's avatar
raoul committed
		controller->editActionMovePointCurve(vector_2d((mouse.x - clicOldMouse.x)*zoom*2,
		                                               (mouse.y - clicOldMouse.y)*zoom*2));
	if (editionState == MovePointstitch) //if we're moving a linkstitch control point
	{
		controller->editActionMovePointLinkStitch(absMove);
		controller->editActionMoveGridPointFillStitch(absMove);
	if (selControlStitch) //if we're working on a stitch
raoul's avatar
raoul committed
	{
		OE_linestitch* tmpLineStitch = dynamic_cast<OE_linestitch*>(selControlStitch);
		OE_birailstitch* tmpBirailStitch = dynamic_cast<OE_birailstitch*>(selControlStitch);
3dsman's avatar
3dsman committed
		OE_fillstitch* tmpFillStitch = dynamic_cast<OE_fillstitch*>(selControlStitch);
raoul's avatar
raoul committed
		if (tmpLineStitch && editionState == OffsetWidthLinestitch) //if this is a linestitch and we're picking the scaleWidth controler
raoul's avatar
raoul committed
			controller->editActionSetLinestitchWidth((mouse.x - clicOldMouse.x)/100.0f, true);
			return;
		//if we're define control curves for linestitch or birailstitch
		if (((tmpLineStitch || tmpFillStitch ||tmpBirailStitch) && selControlType == 0)||((tmpLineStitch ||tmpBirailStitch) && selControlType == 1)||
			(tmpBirailStitch && selControlType == 2))
raoul's avatar
raoul committed
		{
			if (editionState == NewSubcurve)
			{
				editionState = TraceSubcurve;
				if (oldClosestPoint.t>editClosestPoint.t) controller->editActionAddSubcurvePosSwitchDir();
			}
raoul's avatar
raoul committed
			if (editionState == TraceSubcurve)
			{
				controller->editActionAddSubcurvePosEnd(editClosestPoint.t);
			}
			else if (editionState == MoveSubcurve)
raoul's avatar
raoul committed
			{
				controller->editActionSetSubcurvePos(editClosestPoint.t);
			}
		}
	}
}

void OE_interfaceDisplay::mouse_Button(int button, int action, int mods)
{
raoul's avatar
raoul committed
	modState = mods;
	OE_display::mouse_Button(button, action, mods);
raoul's avatar
raoul committed
	if (curScreen == edit && button == GLFW_MOUSE_BUTTON_LEFT && action==GLFW_PRESS)
raoul's avatar
raoul committed
		if (editionState == NewSubcurve)
		{
			if (!closestCurve)
raoul's avatar
raoul committed
			else
			{
				controller->addAction(new OE_actionJoincurveAddSubCurve(curJoincurve, subcurve_id, closestCurve,
raoul's avatar
raoul committed
				                                                        editClosestPoint.t, editClosestPoint.t,
				                                                        false));
				//subcurve_id = -1;
raoul's avatar
raoul committed
				selControlStitch = controller->getStitch(-1);
				selControlType = 0;
				//editSubcurve = curJoincurve->getCurve(-1);
				editSubcurve = curJoincurve->getCurve(subcurve_id);
raoul's avatar
raoul committed
			}
		}
		else
		{
			clicOldMouse = mouse;
raoul's avatar
raoul committed
			if (editionState == None)
			{
raoul's avatar
raoul committed
			}
			if (editionState == None)
			{
raoul's avatar
raoul committed
			}
Loading full blame...