update according to review
This commit is contained in:
parent
664c217180
commit
2cfbc143c3
5 changed files with 107 additions and 97 deletions
|
@ -1,80 +1,84 @@
|
|||
#include "sceneview.h"
|
||||
#include "editor/editor_client.h"
|
||||
#include "editor/editor_server.h"
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include "core/crc32.h"
|
||||
#include "graphics/pipeline.h"
|
||||
|
||||
SceneView::SceneView(QWidget* parent) :
|
||||
QDockWidget(parent)
|
||||
{
|
||||
m_pipeline = NULL;
|
||||
setWidget(new QWidget());
|
||||
setWindowTitle("Scene");
|
||||
setObjectName("sceneView");
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
|
||||
void SceneView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QList<QUrl>& list = event->mimeData()->urls();
|
||||
if(!list.empty())
|
||||
{
|
||||
QString file = list[0].toLocalFile();
|
||||
if(file.endsWith(".msh"))
|
||||
{
|
||||
m_client->addEntity();
|
||||
m_client->addComponent(crc32("renderable"));
|
||||
QString base_path = m_client->getBasePath();
|
||||
if(file.startsWith(base_path))
|
||||
{
|
||||
file.remove(0, base_path.length());
|
||||
}
|
||||
m_client->setComponentProperty("renderable", "source", file.toLatin1().data(), file.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
m_client->mouseDown(event->x(), event->y(), event->button() == Qt::LeftButton ? 0 : 2);
|
||||
m_last_x = event->x();
|
||||
m_last_y = event->y();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void SceneView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
m_client->mouseMove(event->x(), event->y(), event->x() - m_last_x, event->y() - m_last_y);
|
||||
m_last_x = event->x();
|
||||
m_last_y = event->y();
|
||||
}
|
||||
|
||||
void SceneView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
m_client->mouseUp(event->x(), event->y(), event->button() == Qt::LeftButton ? 0 : 2);
|
||||
}
|
||||
|
||||
|
||||
void SceneView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
int w = event->size().width();
|
||||
int h = event->size().height();
|
||||
if (m_pipeline)
|
||||
{
|
||||
m_pipeline->resize(w, h);
|
||||
}
|
||||
#include "sceneview.h"
|
||||
#include "editor/editor_client.h"
|
||||
#include "editor/editor_server.h"
|
||||
#include <qapplication.h>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include "core/crc32.h"
|
||||
#include "graphics/pipeline.h"
|
||||
|
||||
SceneView::SceneView(QWidget* parent) :
|
||||
QDockWidget(parent)
|
||||
{
|
||||
m_pipeline = NULL;
|
||||
setWidget(new QWidget());
|
||||
setWindowTitle("Scene");
|
||||
setObjectName("sceneView");
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
|
||||
void SceneView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasUrls())
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const QList<QUrl>& list = event->mimeData()->urls();
|
||||
if(!list.empty())
|
||||
{
|
||||
QString file = list[0].toLocalFile();
|
||||
if(file.endsWith(".msh"))
|
||||
{
|
||||
m_client->addEntity();
|
||||
m_client->addComponent(crc32("renderable"));
|
||||
QString base_path = m_client->getBasePath();
|
||||
if(file.startsWith(base_path))
|
||||
{
|
||||
file.remove(0, base_path.length());
|
||||
}
|
||||
m_client->setComponentProperty("renderable", "source", file.toLatin1().data(), file.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
m_client->mouseDown(event->x(), event->y(), event->button() == Qt::LeftButton ? 0 : 2);
|
||||
m_last_x = event->x();
|
||||
m_last_y = event->y();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void SceneView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
int flags = 0;
|
||||
flags |= Qt::ControlModifier & QApplication::keyboardModifiers() ? (int)Lumix::EditorServer::MouseFlags::CONTROL : 0;
|
||||
flags |= Qt::AltModifier & QApplication::keyboardModifiers() ? (int)Lumix::EditorServer::MouseFlags::ALT : 0;
|
||||
m_client->mouseMove(event->x(), event->y(), event->x() - m_last_x, event->y() - m_last_y, flags);
|
||||
m_last_x = event->x();
|
||||
m_last_y = event->y();
|
||||
}
|
||||
|
||||
void SceneView::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
m_client->mouseUp(event->x(), event->y(), event->button() == Qt::LeftButton ? 0 : 2);
|
||||
}
|
||||
|
||||
|
||||
void SceneView::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
int w = event->size().width();
|
||||
int h = event->size().height();
|
||||
if (m_pipeline)
|
||||
{
|
||||
m_pipeline->resize(w, h);
|
||||
}
|
||||
}
|
|
@ -102,13 +102,13 @@ namespace Lumix
|
|||
}
|
||||
|
||||
|
||||
DelegateList<void(PropertyListEvent&)>& EditorClient::propertyListReceived()
|
||||
EditorClient::PropertyListCallback& EditorClient::propertyListReceived()
|
||||
{
|
||||
return m_impl->m_property_list_received;
|
||||
}
|
||||
|
||||
|
||||
DelegateList<void(EntitySelectedEvent&)>& EditorClient::entitySelected()
|
||||
EditorClient::EntitySelectedCallback& EditorClient::entitySelected()
|
||||
{
|
||||
return m_impl->m_entity_selected;
|
||||
}
|
||||
|
@ -162,10 +162,10 @@ namespace Lumix
|
|||
}
|
||||
|
||||
|
||||
void EditorClient::mouseMove(int x, int y, int dx, int dy)
|
||||
void EditorClient::mouseMove(int x, int y, int dx, int dy, int flags)
|
||||
{
|
||||
int data[4] = {x, y, dx, dy};
|
||||
m_impl->sendMessage(ClientMessageType::POINTER_MOVE, data, 16);
|
||||
int data[] = {x, y, dx, dy, flags};
|
||||
m_impl->sendMessage(ClientMessageType::POINTER_MOVE, data, 20);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace Lumix
|
|||
|
||||
class LUMIX_ENGINE_API EditorClient
|
||||
{
|
||||
public:
|
||||
typedef DelegateList<void(PropertyListEvent&)> PropertyListCallback;
|
||||
typedef DelegateList<void(EntitySelectedEvent&)> EntitySelectedCallback;
|
||||
|
||||
public:
|
||||
EditorClient() { m_impl = NULL; }
|
||||
|
||||
|
@ -28,7 +32,7 @@ namespace Lumix
|
|||
void addComponent(uint32_t type);
|
||||
void mouseDown(int x, int y, int button);
|
||||
void mouseUp(int x, int y, int button);
|
||||
void mouseMove(int x, int y, int dx, int dy);
|
||||
void mouseMove(int x, int y, int dx, int dy, int flags);
|
||||
void requestProperties(uint32_t type_crc);
|
||||
void setComponentProperty(const char* component, const char* property, const void* value, int32_t length);
|
||||
void navigate(float forward, float right, int32_t fast);
|
||||
|
@ -37,8 +41,8 @@ namespace Lumix
|
|||
void setEntityPosition(int32_t entity, const Vec3& position);
|
||||
const char* getBasePath() const;
|
||||
EventManager& getEventManager();
|
||||
DelegateList<void (PropertyListEvent&)>& propertyListReceived();
|
||||
DelegateList<void (EntitySelectedEvent&)>& entitySelected();
|
||||
PropertyListCallback& propertyListReceived();
|
||||
EntitySelectedCallback& entitySelected();
|
||||
|
||||
private:
|
||||
struct EditorClientImpl* m_impl;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#include "editor_server.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <gl/GL.h>
|
||||
|
||||
#include "core/array.h"
|
||||
#include "core/blob.h"
|
||||
#include "core/crc32.h"
|
||||
|
@ -121,7 +117,7 @@ struct EditorServerImpl
|
|||
bool create(const char* base_path);
|
||||
void destroy();
|
||||
void onPointerDown(int x, int y, MouseButton::Value button);
|
||||
void onPointerMove(int x, int y, int relx, int rely);
|
||||
void onPointerMove(int x, int y, int relx, int rely, int mouse_flags);
|
||||
void onPointerUp(int x, int y, MouseButton::Value button);
|
||||
void selectEntity(Entity e);
|
||||
void navigate(float forward, float right, int fast);
|
||||
|
@ -384,7 +380,7 @@ void EditorServerImpl::onPointerDown(int x, int y, MouseButton::Value button)
|
|||
}
|
||||
|
||||
|
||||
void EditorServerImpl::onPointerMove(int x, int y, int relx, int rely)
|
||||
void EditorServerImpl::onPointerMove(int x, int y, int relx, int rely, int mouse_flags)
|
||||
{
|
||||
switch(m_mouse_mode)
|
||||
{
|
||||
|
@ -395,9 +391,8 @@ void EditorServerImpl::onPointerMove(int x, int y, int relx, int rely)
|
|||
break;
|
||||
case EditorServerImpl::MouseMode::TRANSFORM:
|
||||
{
|
||||
|
||||
Gizmo::TransformOperation tmode = GetKeyState(VK_MENU) & 0x8000 ? Gizmo::TransformOperation::ROTATE : Gizmo::TransformOperation::TRANSLATE;
|
||||
int flags = GetKeyState(VK_LCONTROL) & 0x8000 ? Gizmo::Flags::FIXED_STEP : 0;
|
||||
Gizmo::TransformOperation tmode = mouse_flags & (int)EditorServer::MouseFlags::ALT/*GetKeyState(VK_MENU) & 0x8000*/ ? Gizmo::TransformOperation::ROTATE : Gizmo::TransformOperation::TRANSLATE;
|
||||
int flags = mouse_flags & (int)EditorServer::MouseFlags::CONTROL/*GetKeyState(VK_LCONTROL) & 0x8000*/ ? Gizmo::Flags::FIXED_STEP : 0;
|
||||
m_gizmo.transform(m_camera.getComponent(CAMERA_HASH), tmode, x, y, relx, rely, flags);
|
||||
}
|
||||
break;
|
||||
|
@ -1087,7 +1082,7 @@ void EditorServerImpl::onMessage(const uint8_t* data, int32_t size)
|
|||
onPointerDown(msg[1], msg[2], (MouseButton::Value)msg[3]);
|
||||
break;
|
||||
case ClientMessageType::POINTER_MOVE:
|
||||
onPointerMove(msg[1], msg[2], msg[3], msg[4]);
|
||||
onPointerMove(msg[1], msg[2], msg[3], msg[4], msg[5]);
|
||||
break;
|
||||
case ClientMessageType::POINTER_UP:
|
||||
onPointerUp(msg[1], msg[2], (MouseButton::Value)msg[3]);
|
||||
|
|
|
@ -20,6 +20,13 @@ namespace Lumix
|
|||
|
||||
class LUMIX_ENGINE_API EditorServer
|
||||
{
|
||||
public:
|
||||
enum class MouseFlags : int
|
||||
{
|
||||
ALT = 1,
|
||||
CONTROL = 2
|
||||
};
|
||||
|
||||
public:
|
||||
EditorServer() { m_impl = 0; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue