Skip to content
OE_display.cpp 26.5 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_display.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>
        //float OE_display::cx, OE_display::cy = 0.0;
        vector_2d OE_display::viewPos;
 		float OE_display::zoom = 1.0;
        //int OE_display::mouseX, OE_display::mouseY, OE_display::mouseXInit, OE_display::mouseYInit = -1;
		bool OE_display::pan = false;
		int OE_display::width, OE_display::height = 0;
OE_display::OE_display(OE_document* document,OE_controller* controller, OE_displayStyle* style)
	this->document = document;
}

OE_display::~OE_display()
{
}

/** \brief draw the document on screen
 *
 * \return true if all is ok
 *
 */

bool OE_display::setDocument(OE_document * document)
{
	this->document = document;
        std::list<OE_pointcurve*>::iterator curve = document->curves.begin();
		
		while (curve != document->curves.end())
			(*curve)->refresh(zoom/2);
			curve++;
bool OE_display::setController(OE_controller* controller)
	this->controller = controller;
	return true;
}

bool OE_display::setDisplayStyle(OE_displayStyle* style)
{
	this->style = style;
	return true;
}

bool OE_display::refreshAll()
{
	if(document)
	{
		std::list<OE_pointcurve*>::iterator curve = document->curves.begin();

		while (curve != document->curves.end())
		{
			(*curve)->refresh(zoom/2, !changeDpi);
		std::list<OE_stitchs*>::iterator stitch = document->stitchs.begin();

		while (stitch != document->stitchs.end())
		{
			(*stitch)->refresh(zoom/2, !changeDpi);

		if (controller) controller->generateInstructions();

		changeDpi = false;
		return true;
	}
	return false;
}

/** \brief draw the move gizmo
 *
 * \return true if all is ok
 *
 */

bool OE_display::drawSelectionTools(bool select)
{
	vector_2d min = selectionBounds.getMin();
	vector_2d max = selectionBounds.getMax();


	float crossSize = zoom*style->moveCrossSize;
	float boxOffset = zoom*style->moveCrossSize;

	min.x -= boxOffset;
	min.y -= boxOffset;
	max.x += boxOffset;
	max.y += boxOffset;

	if (selectionBounds.init)
	{
		if (select)
		{

			glTranslatef(min.x,min.y,0);
			glPushName(0); //id of the move tool

			glBegin(GL_QUADS);
				style->selectionBoundColor.gl();
				//glColor4d(1,0,0,1);
				glVertex2f(crossSize*1.0f,0);
				glVertex2f(0,crossSize*1.0f);
				glVertex2f(-crossSize*1.0f,0);
				glVertex2f(0,-crossSize*1.0f);
			glEnd();

			glPopName();
			glPushName(1); //id of the scale tool

			glBegin(GL_QUADS);

			glVertex2f(-crossSize*0.5f,-crossSize*0.5f);
			glVertex2f(-crossSize*0.5f,-crossSize*1.5f);
			glVertex2f(-crossSize*1.5f,-crossSize*1.5f);
			glVertex2f(-crossSize*1.5f,-crossSize*0.5f);
			glEnd();

			glPopName();

			glTranslatef(-min.x,-min.y,0);

		}else
		{

			//draw selection bound
			glLineWidth(1.5);
			glBegin(GL_LINE_LOOP);
				style->selectionBoundColor.gl();
				glVertex2f(min.x,min.y);
				glVertex2f(min.x,max.y);
				glVertex2f(max.x,max.y);
				glVertex2f(max.x,min.y);
			glEnd();

			glTranslatef(min.x,min.y,0);

			//draw move cross
			glBegin(GL_TRIANGLES);
				style->transformGizmoColor.gl();
				glVertex2f(-crossSize*0.6f,-crossSize*0.1f);
				glVertex2f(-crossSize*0.6f,crossSize*0.1f);
				glVertex2f(crossSize*0.6f,crossSize*0.1f);

				glVertex2f(crossSize*0.6f,crossSize*0.1f);
				glVertex2f(-crossSize*0.6f,-crossSize*0.1f);
				glVertex2f(crossSize*0.6f,-crossSize*0.1f);

				glVertex2f(crossSize*0.6f,crossSize*0.3f);
				glVertex2f(crossSize*1.0f,0);
Loading full blame...