Skip to content

Commit

Permalink
Traktor: Fixed the SplineComponent editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jan 21, 2024
1 parent 9aa2e84 commit ce2507f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 97 deletions.
4 changes: 2 additions & 2 deletions code/Shape/Editor/EditorProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "Shape/Editor/Solid/SolidEditorPlugin.h"
#include "Shape/Editor/Solid/SolidEntityEditorFactory.h"
#include "Shape/Editor/Spline/ControlPointComponentEditorFactory.h"
#include "Shape/Editor/Spline/SplineEntityEditorFactory.h"
#include "Shape/Editor/Spline/SplineComponentEditorFactory.h"

namespace traktor
{
Expand Down Expand Up @@ -96,7 +96,6 @@ void EditorProfile::createEntityEditorFactories(
) const
{
outEntityEditorFactories.push_back(new SolidEntityEditorFactory());
outEntityEditorFactories.push_back(new SplineEntityEditorFactory());
}

void EditorProfile::createComponentEditorFactories(
Expand All @@ -105,6 +104,7 @@ void EditorProfile::createComponentEditorFactories(
) const
{
outComponentEditorFactories.push_back(new ControlPointComponentEditorFactory());
outComponentEditorFactories.push_back(new SplineComponentEditorFactory());
}

Ref< world::EntityData > EditorProfile::createEntityData(
Expand Down
17 changes: 6 additions & 11 deletions code/Shape/Editor/Spline/ControlPointComponentEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@
#include "Scene/Editor/EntityAdapter.h"
#include "Shape/Editor/Spline/ControlPointComponentEditor.h"

namespace traktor
namespace traktor::shape
{
namespace shape
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.shape.ControlPointComponentEditor", ControlPointComponentEditor, scene::DefaultComponentEditor)

Expand All @@ -24,19 +22,16 @@ ControlPointComponentEditor::ControlPointComponentEditor(scene::SceneEditorConte

void ControlPointComponentEditor::drawGuide(render::PrimitiveRenderer* primitiveRenderer) const
{
primitiveRenderer->pushDepthState(false, false, false);

bool selected = m_entityAdapter->isSelected() || m_entityAdapter->getParent()->isSelected();

const bool selected = m_entityAdapter->isSelected() || m_entityAdapter->getParent()->isSelected();
const auto& T = m_entityAdapter->getTransform();

primitiveRenderer->pushDepthState(false, false, false);
primitiveRenderer->drawSolidPoint(
T.translation(),
4.0f,
8.0f,
selected ? Color4ub(100, 100, 255, 220) : Color4ub(255, 255, 255, 100)
);

primitiveRenderer->popDepthState();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@
#include "Render/PrimitiveRenderer.h"
#include "Scene/Editor/EntityAdapter.h"
#include "Shape/Editor/Spline/SplineComponent.h"
#include "Shape/Editor/Spline/SplineEntityEditor.h"
#include "Shape/Editor/Spline/SplineComponentEditor.h"

namespace traktor
namespace traktor::shape
{
namespace shape
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.shape.SplineEntityEditor", SplineEntityEditor, scene::DefaultEntityEditor)
T_IMPLEMENT_RTTI_CLASS(L"traktor.shape.SplineComponentEditor", SplineComponentEditor, scene::DefaultComponentEditor)

SplineEntityEditor::SplineEntityEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter)
: scene::DefaultEntityEditor(context, entityAdapter)
SplineComponentEditor::SplineComponentEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter, world::IEntityComponentData* componentData)
: scene::DefaultComponentEditor(context, entityAdapter, componentData)
{
}

void SplineEntityEditor::drawGuide(render::PrimitiveRenderer* primitiveRenderer) const
void SplineComponentEditor::drawGuide(render::PrimitiveRenderer* primitiveRenderer) const
{
auto splineComponent = getEntityAdapter()->getComponent< SplineComponent >();
auto splineComponent = m_entityAdapter->getComponent< SplineComponent >();
if (!splineComponent)
return;

primitiveRenderer->pushDepthState(false, false, false);

const auto& path = splineComponent->getPath();
const auto& keys = path.keys();
if (keys.empty())
Expand All @@ -39,6 +35,8 @@ void SplineEntityEditor::drawGuide(render::PrimitiveRenderer* primitiveRenderer)
const float st = path.getStartTime();
const float et = path.getEndTime();

primitiveRenderer->pushDepthState(false, false, false);

const uint32_t nsteps = (uint32_t)keys.size() * 10;
for (uint32_t i = 0; i < nsteps; ++i)
{
Expand All @@ -47,12 +45,11 @@ void SplineEntityEditor::drawGuide(render::PrimitiveRenderer* primitiveRenderer)
primitiveRenderer->drawLine(
path.evaluate(t1, true).position,
path.evaluate(t2, true).position,
getEntityAdapter()->isSelected() ? Color4ub(100, 100, 255, 220) : Color4ub(255, 255, 255, 80)
m_entityAdapter->isSelected() ? Color4ub(100, 100, 255, 220) : Color4ub(255, 255, 255, 80)
);
}

primitiveRenderer->popDepthState();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Scene/Editor/DefaultEntityEditor.h"
#include "Scene/Editor/DefaultComponentEditor.h"

namespace traktor
namespace traktor::shape
{
namespace shape
{

/*!
* \ingroup Shape
*/
class SplineEntityEditor : public scene::DefaultEntityEditor
class SplineComponentEditor : public scene::DefaultComponentEditor
{
T_RTTI_CLASS;

public:
SplineEntityEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter);
explicit SplineComponentEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter, world::IEntityComponentData* componentData);

virtual void drawGuide(render::PrimitiveRenderer* primitiveRenderer) const override final;
};

}
}
33 changes: 33 additions & 0 deletions code/Shape/Editor/Spline/SplineComponentEditorFactory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* TRAKTOR
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Shape/Editor/Spline/SplineComponentData.h"
#include "Shape/Editor/Spline/SplineComponentEditor.h"
#include "Shape/Editor/Spline/SplineComponentEditorFactory.h"

namespace traktor::shape
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.shape.SplineComponentEditorFactory", SplineComponentEditorFactory, scene::IComponentEditorFactory)

const TypeInfoSet SplineComponentEditorFactory::getComponentDataTypes() const
{
return makeTypeInfoSet< SplineComponentData >();
}

bool SplineComponentEditorFactory::alwaysRebuild(const world::IEntityComponentData* componentData) const
{
return false;
}

Ref< scene::IComponentEditor > SplineComponentEditorFactory::createComponentEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter, world::IEntityComponentData* componentData) const
{
return new SplineComponentEditor(context, entityAdapter, componentData);
}

}
31 changes: 31 additions & 0 deletions code/Shape/Editor/Spline/SplineComponentEditorFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* TRAKTOR
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once

#include "Scene/Editor/IComponentEditorFactory.h"

namespace traktor::shape
{

/*!
* \ingroup Shape
*/
class SplineComponentEditorFactory : public scene::IComponentEditorFactory
{
T_RTTI_CLASS;

public:
virtual const TypeInfoSet getComponentDataTypes() const override final;

virtual bool alwaysRebuild(const world::IEntityComponentData* componentData) const override final;

virtual Ref< scene::IComponentEditor > createComponentEditor(scene::SceneEditorContext* context, scene::EntityAdapter* entityAdapter, world::IEntityComponentData* componentData) const override final;
};

}
31 changes: 0 additions & 31 deletions code/Shape/Editor/Spline/SplineEntityEditorFactory.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions code/Shape/Editor/Spline/SplineEntityEditorFactory.h

This file was deleted.

0 comments on commit ce2507f

Please sign in to comment.