2012-03-20 01:57:42 +01:00
|
|
|
#include "lc_global.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "project.h"
|
2012-08-20 06:05:56 +02:00
|
|
|
#include "camera.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "view.h"
|
|
|
|
#include "system.h"
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
View::View(Project *project)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project = project;
|
2012-08-20 06:05:56 +02:00
|
|
|
mCamera = NULL;
|
2012-02-05 03:50:57 +01:00
|
|
|
m_OverlayScale = 1.0f;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
if (project->GetActiveView())
|
|
|
|
SetCamera(project->GetActiveView()->mCamera, false);
|
|
|
|
else
|
|
|
|
SetDefaultCamera();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
View::~View()
|
|
|
|
{
|
|
|
|
if (m_Project != NULL)
|
|
|
|
m_Project->RemoveView(this);
|
2012-08-22 03:13:32 +02:00
|
|
|
|
|
|
|
if (mCamera && mCamera->IsSimple())
|
|
|
|
delete mCamera;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:14:35 +01:00
|
|
|
void View::SetCamera(Camera* camera, bool ForceCopy)
|
2012-08-20 06:05:56 +02:00
|
|
|
{
|
2012-11-15 02:14:35 +01:00
|
|
|
if (camera->IsSimple() || ForceCopy)
|
2012-08-20 06:05:56 +02:00
|
|
|
{
|
|
|
|
if (!mCamera || !mCamera->IsSimple())
|
|
|
|
mCamera = new Camera(true);
|
|
|
|
|
|
|
|
mCamera->CopyPosition(camera);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mCamera && mCamera->IsSimple())
|
|
|
|
delete mCamera;
|
|
|
|
|
|
|
|
mCamera = camera;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::SetDefaultCamera()
|
|
|
|
{
|
|
|
|
if (!mCamera || !mCamera->IsSimple())
|
|
|
|
mCamera = new Camera(true);
|
|
|
|
|
2014-01-30 04:13:34 +01:00
|
|
|
mCamera->SetViewpoint(LC_VIEWPOINT_HOME, 1, false);
|
2012-08-20 06:05:56 +02:00
|
|
|
}
|
|
|
|
|
2012-07-31 07:27:40 +02:00
|
|
|
LC_CURSOR_TYPE View::GetCursor() const
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
// TODO: check if we're the focused window and return just the default arrow if we aren't.
|
|
|
|
|
|
|
|
switch (m_Project->GetAction())
|
|
|
|
{
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_SELECT:
|
2013-08-09 06:57:18 +02:00
|
|
|
if (mInputState.Control)
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_SELECT_GROUP;
|
|
|
|
else
|
|
|
|
return LC_CURSOR_SELECT;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_INSERT:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_BRICK;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_LIGHT:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_LIGHT;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_SPOTLIGHT:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_SPOTLIGHT;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_CAMERA:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_CAMERA;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_MOVE:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_MOVE;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ROTATE:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_ROTATE;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ERASER:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_DELETE;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_PAINT:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_PAINT;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ZOOM:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_ZOOM;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ZOOM_REGION:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_ZOOM_REGION;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_PAN:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_PAN;
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ROTATE_VIEW:
|
2011-09-07 23:06:51 +02:00
|
|
|
switch (m_Project->GetOverlayMode())
|
|
|
|
{
|
2012-11-01 01:34:09 +01:00
|
|
|
case LC_OVERLAY_ROTATE_VIEW_X:
|
2012-03-03 02:16:02 +01:00
|
|
|
return LC_CURSOR_ROTATEX;
|
2012-11-01 01:34:09 +01:00
|
|
|
case LC_OVERLAY_ROTATE_VIEW_Y:
|
2012-03-03 02:16:02 +01:00
|
|
|
return LC_CURSOR_ROTATEY;
|
2012-11-01 01:34:09 +01:00
|
|
|
case LC_OVERLAY_ROTATE_VIEW_Z:
|
2012-03-03 02:16:02 +01:00
|
|
|
return LC_CURSOR_ROLL;
|
2012-11-01 01:34:09 +01:00
|
|
|
case LC_OVERLAY_ROTATE_VIEW_XYZ:
|
2011-09-07 23:06:51 +02:00
|
|
|
default:
|
2012-03-03 02:16:02 +01:00
|
|
|
return LC_CURSOR_ROTATE_VIEW;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 16:55:12 +02:00
|
|
|
case LC_TOOL_ROLL:
|
2011-09-07 23:06:51 +02:00
|
|
|
return LC_CURSOR_ROLL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LC_ASSERT_FALSE("Unknown cursor type.");
|
2012-06-23 02:14:09 +02:00
|
|
|
return LC_CURSOR_DEFAULT;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 03:43:16 +01:00
|
|
|
// Call this once before using a view during a callback in order
|
|
|
|
// to pick up any changes to the view or its camera.
|
|
|
|
const lcProjection& View::UpdateProjection()
|
|
|
|
{
|
|
|
|
mProjection.SetView(mCamera, mWidth, mHeight);
|
|
|
|
mCamera->LoadProjection(mProjection);
|
|
|
|
return mProjection;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::SetProjectionType(lcProjection::Type type)
|
|
|
|
{
|
|
|
|
mProjection.SetType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcProjection::Type View::GetProjectionType() const
|
|
|
|
{
|
|
|
|
return mProjection.GetType();
|
|
|
|
}
|
|
|
|
|
2011-09-07 23:06:51 +02:00
|
|
|
void View::OnDraw()
|
|
|
|
{
|
2011-09-20 03:26:31 +02:00
|
|
|
m_Project->Render(this, false);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnInitialUpdate()
|
|
|
|
{
|
|
|
|
m_Project->AddView(this);
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnUpdateCursor()
|
|
|
|
{
|
|
|
|
SetCursor(GetCursor());
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnLeftButtonDown()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnLeftButtonDown(this);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnLeftButtonUp()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnLeftButtonUp(this);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnLeftButtonDoubleClick()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnLeftButtonDoubleClick(this);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnMiddleButtonDown()
|
2012-01-28 03:10:19 +01:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnMiddleButtonDown(this);
|
2012-01-28 03:10:19 +01:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnMiddleButtonUp()
|
2012-01-28 03:10:19 +01:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnMiddleButtonUp(this);
|
2012-01-28 03:10:19 +01:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnRightButtonDown()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnRightButtonDown(this);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnRightButtonUp()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnRightButtonUp(this);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnMouseMove()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnMouseMove(this);
|
2013-01-28 20:57:33 +01:00
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void View::OnMouseWheel(float Direction)
|
2013-01-28 20:57:33 +01:00
|
|
|
{
|
2013-08-09 06:57:18 +02:00
|
|
|
m_Project->OnMouseWheel(this, Direction);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|