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"
|
|
|
|
|
|
|
|
View::View(Project *pProject, GLWindow *share)
|
|
|
|
: GLWindow(share)
|
|
|
|
{
|
|
|
|
m_Project = pProject;
|
2012-08-20 06:05:56 +02:00
|
|
|
mCamera = NULL;
|
2012-02-05 03:50:57 +01:00
|
|
|
m_OverlayScale = 1.0f;
|
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);
|
|
|
|
|
|
|
|
mCamera->SetViewpoint(LC_VIEWPOINT_HOME, 1, false, false);
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
case LC_ACTION_SELECT:
|
|
|
|
if (Sys_KeyDown(KEY_CONTROL))
|
|
|
|
return LC_CURSOR_SELECT_GROUP;
|
|
|
|
else
|
|
|
|
return LC_CURSOR_SELECT;
|
|
|
|
|
|
|
|
case LC_ACTION_INSERT:
|
|
|
|
return LC_CURSOR_BRICK;
|
|
|
|
|
|
|
|
case LC_ACTION_LIGHT:
|
|
|
|
return LC_CURSOR_LIGHT;
|
|
|
|
|
|
|
|
case LC_ACTION_SPOTLIGHT:
|
|
|
|
return LC_CURSOR_SPOTLIGHT;
|
|
|
|
|
|
|
|
case LC_ACTION_CAMERA:
|
|
|
|
return LC_CURSOR_CAMERA;
|
|
|
|
|
|
|
|
case LC_ACTION_MOVE:
|
|
|
|
return LC_CURSOR_MOVE;
|
|
|
|
|
|
|
|
case LC_ACTION_ROTATE:
|
|
|
|
return LC_CURSOR_ROTATE;
|
|
|
|
|
|
|
|
case LC_ACTION_ERASER:
|
|
|
|
return LC_CURSOR_DELETE;
|
|
|
|
|
|
|
|
case LC_ACTION_PAINT:
|
|
|
|
return LC_CURSOR_PAINT;
|
|
|
|
|
|
|
|
case LC_ACTION_ZOOM:
|
|
|
|
return LC_CURSOR_ZOOM;
|
|
|
|
|
|
|
|
case LC_ACTION_ZOOM_REGION:
|
|
|
|
return LC_CURSOR_ZOOM_REGION;
|
|
|
|
|
|
|
|
case LC_ACTION_PAN:
|
|
|
|
return LC_CURSOR_PAN;
|
|
|
|
|
|
|
|
case LC_ACTION_ROTATE_VIEW:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
case LC_ACTION_ROLL:
|
|
|
|
return LC_CURSOR_ROLL;
|
|
|
|
|
|
|
|
case LC_ACTION_CURVE:
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnDraw()
|
|
|
|
{
|
|
|
|
MakeCurrent();
|
|
|
|
|
2011-09-20 03:26:31 +02:00
|
|
|
m_Project->Render(this, false);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnInitialUpdate()
|
|
|
|
{
|
|
|
|
GLWindow::OnInitialUpdate();
|
|
|
|
m_Project->AddView(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnLeftButtonDown(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnLeftButtonUp(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnLeftButtonUp(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnLeftButtonDoubleClick(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-01-28 03:10:19 +01:00
|
|
|
void View::OnMiddleButtonDown(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
|
|
|
m_Project->OnMiddleButtonDown(this, x, y, bControl, bShift);
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnMiddleButtonUp(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
|
|
|
m_Project->OnMiddleButtonUp(this, x, y, bControl, bShift);
|
|
|
|
}
|
|
|
|
|
2011-09-07 23:06:51 +02:00
|
|
|
void View::OnRightButtonDown(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnRightButtonDown(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnRightButtonUp(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnRightButtonUp(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void View::OnMouseMove(int x, int y, bool bControl, bool bShift)
|
|
|
|
{
|
2011-09-20 01:03:28 +02:00
|
|
|
m_Project->OnMouseMove(this, x, y, bControl, bShift);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|