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;
//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_display::OE_display(OE_document* document,OE_controller* controller)
}
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;
if(document)
{
3dsman
committed
std::list<OE_pointcurve*>::iterator curve = document->curves.begin();
while (curve != document->curves.end())
(*curve)->refresh(zoom/2);
curve++;
}
}
return true;
}
bool OE_display::setController(OE_controller* controller)
this->controller = controller;
return true;
}
/** \brief move and zoom to see the entire document
*/
void OE_display::showAll()
{
if (document)
BoundingBox bound = document->getBound();
viewPos.x = (bound.getMax().x + bound.getMin().x)/2;
viewPos.y = (bound.getMax().y + bound.getMin().y)/2;
zoom = maxf((bound.getMax().x - bound.getMin().x )/width/1.5,(bound.getMax().y - bound.getMin().y)/height/1.5);
3dsman
committed
void OE_display::showSelection()
{
if (document&&controller)
{
float xMin,yMin,xMax,yMax;
BoundingBox bound = controller->getSelectionBoundingBox();
viewPos.x = (bound.getMax().x + bound.getMin().x)/2;
viewPos.y = (bound.getMax().y + bound.getMin().y)/2;
zoom = maxf((bound.getMax().x - bound.getMin().x )/width/1.5,(bound.getMax().y - bound.getMin().y)/height/1.5);
}
}
void OE_display::mouse_Pos(double x, double y)
{
if (pan)
viewPos = viewPos + (mouse-vector_2d(x,y))*zoom;
mouse.x = x;
mouse.y = y;
absMouse = viewPos+(mouse-vector_2d(width,height)/2)*zoom*2;
}
void OE_display::mouse_Button(int button, int action, int mods)
{
if (button == GLFW_MOUSE_BUTTON_MIDDLE)
{
if (action == GLFW_PRESS)
pan = true;
else
pan = false;
}
}
void OE_display::scroll(double xoffset, double yoffset)
{
if(!pan){
if (yoffset>0)
zoom = zoom/1.1;
else
zoom = zoom*1.1;
}
}
void OE_display::resize(int width, int height)
{
this->width = width;
this->height = height;
}
void OE_display::key(int key, int scancode, int action, int mods){};