Skip to content

Commit

Permalink
Traktor: Improved terrain editor brushes a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed Jun 7, 2024
1 parent a6f6424 commit 41a33d6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
2 changes: 1 addition & 1 deletion code/Terrain/Editor/ElevateBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ uint32_t ElevateBrush::begin(float x, float y, const State& state)
{
m_radius = state.radius;
m_fallOff = state.falloff;
m_strength = state.strength * 0.0256 / m_heightfield->getWorldExtent().y();
m_strength = state.strength * 0.0256f / m_heightfield->getWorldExtent().y();
m_attribute = state.attribute;
return MdHeight;
}
Expand Down
9 changes: 3 additions & 6 deletions code/Terrain/Editor/FlattenBrush.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 @@ -12,10 +12,8 @@
#include "Terrain/Editor/FlattenBrush.h"
#include "Terrain/Editor/IFallOff.h"

namespace traktor
namespace traktor::terrain
{
namespace terrain
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.terrain.FlattenBrush", FlattenBrush, IBrush)

Expand All @@ -33,7 +31,7 @@ uint32_t FlattenBrush::begin(float x, float y, const State& state)
{
m_radius = state.radius;
m_fallOff = state.falloff;
m_strength = abs(state.strength) * 0.5f;
m_strength = abs(state.strength) * 0.05f;

if (!m_explicit)
m_height = m_heightfield->getGridHeightNearest(x, y);
Expand Down Expand Up @@ -73,5 +71,4 @@ void FlattenBrush::setHeight(float height)
m_height = m_heightfield->worldToUnit(height);
}

}
}
26 changes: 8 additions & 18 deletions code/Terrain/Editor/TerrainEditorPlugin.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 Down Expand Up @@ -39,10 +39,8 @@
#include "Ui/ToolBar/ToolBarItemGroup.h"
#include "Ui/ToolBar/ToolBarSeparator.h"

namespace traktor
namespace traktor::terrain
{
namespace terrain
{

T_IMPLEMENT_RTTI_CLASS(L"traktor.terrain.TerrainEditorPlugin", TerrainEditorPlugin, scene::ISceneEditorPlugin)

Expand Down Expand Up @@ -73,19 +71,13 @@ bool TerrainEditorPlugin::create(ui::Widget* parent, ui::ToolBar* toolBar)
m_toolToggleFallOffSharp = new ui::ToolBarButton(i18n::Text(L"TERRAIN_EDITOR_SHARP_FALLOFF"), image + 5, ui::Command(L"Terrain.Editor.SharpFallOff"), ui::ToolBarButton::BsDefaultToggle);
m_toolToggleFallOffImage = new ui::ToolBarButton(i18n::Text(L"TERRAIN_EDITOR_SHARP_IMAGE"), image + 15, ui::Command(L"Terrain.Editor.ImageFallOff"), ui::ToolBarButton::BsDefaultToggle);

Ref< ui::Container > containerStrength = new ui::Container();
containerStrength->create(toolBar, ui::WsNone, new ui::TableLayout(L"100,35", L"24", 2_ut, 2_ut));

m_sliderStrength = new ui::Slider();
m_sliderStrength->create(containerStrength);
m_sliderStrength->setRange(1, 10);
m_sliderStrength->create(toolBar);
m_sliderStrength->setRange(0, 10);
m_sliderStrength->setValue(5);
m_sliderStrength->addEventHandler< ui::ContentChangeEvent >(this, &TerrainEditorPlugin::eventSliderStrengthChange);

m_staticStrength = new ui::Static();
m_staticStrength->create(containerStrength, L"50%");

m_toolStrength = new ui::ToolBarEmbed(containerStrength, 135_ut);
m_toolStrength = new ui::ToolBarEmbed(m_sliderStrength, 100_ut);

m_colorControl = new ui::ColorControl();
m_colorControl->create(toolBar, ui::WsBorder);
Expand Down Expand Up @@ -301,15 +293,15 @@ void TerrainEditorPlugin::updateModifierState()
else if (m_toolToggleFallOffImage->isToggled())
m_terrainEditModifier->setFallOff(L"Terrain.Editor.ImageFallOff");

int32_t material = m_toolMaterial->getSelected();
const int32_t material = m_toolMaterial->getSelected();
if (material >= 0)
m_terrainEditModifier->setMaterial(material);

int32_t attribute = m_toolAttribute->getSelected();
const int32_t attribute = m_toolAttribute->getSelected();
if (attribute >= 0)
m_terrainEditModifier->setAttribute(attribute);

int32_t visualize = m_toolVisualize->getSelected();
const int32_t visualize = m_toolVisualize->getSelected();
if (visualize >= 0)
m_terrainEditModifier->setVisualizeMode((TerrainComponent::VisualizeMode)visualize);

Expand All @@ -319,7 +311,6 @@ void TerrainEditorPlugin::updateModifierState()
void TerrainEditorPlugin::eventSliderStrengthChange(ui::ContentChangeEvent* event)
{
m_terrainEditModifier->setStrength(m_sliderStrength->getValue() / 10.0f);
m_staticStrength->setText(toString(int32_t(m_sliderStrength->getValue() * 10)) + L"%");
}

void TerrainEditorPlugin::eventColorClick(ui::MouseButtonUpEvent* event)
Expand Down Expand Up @@ -351,5 +342,4 @@ void TerrainEditorPlugin::eventModifierChanged(scene::ModifierChangedEvent* even
m_toolGroup->setEnable(m_context->getModifier() == m_terrainEditModifier);
}

}
}
21 changes: 8 additions & 13 deletions code/Terrain/Editor/TerrainEditorPlugin.h
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 @@ -11,17 +11,15 @@
#include "Scene/Editor/ISceneEditorPlugin.h"
#include "Ui/Events/AllEvents.h"

namespace traktor
namespace traktor::scene
{
namespace scene
{

class ModifierChangedEvent;

}
}

namespace ui
{
namespace traktor::ui
{

class ColorControl;
class Slider;
Expand All @@ -31,10 +29,10 @@ class ToolBarDropDown;
class ToolBarEmbed;
class ToolBarItemGroup;

}
}

namespace terrain
{
namespace traktor::terrain
{

class TerrainEditModifier;

Expand Down Expand Up @@ -66,7 +64,6 @@ class TerrainEditorPlugin : public scene::ISceneEditorPlugin
Ref< ui::ToolBarButton > m_toolToggleFallOffSharp;
Ref< ui::ToolBarButton > m_toolToggleFallOffImage;
Ref< ui::Slider > m_sliderStrength;
Ref< ui::Static > m_staticStrength;
Ref< ui::ToolBarEmbed > m_toolStrength;
Ref< ui::ColorControl > m_colorControl;
Ref< ui::ToolBarEmbed > m_toolColor;
Expand All @@ -86,6 +83,4 @@ class TerrainEditorPlugin : public scene::ISceneEditorPlugin
void eventModifierChanged(scene::ModifierChangedEvent* event);
};

}
}

0 comments on commit 41a33d6

Please sign in to comment.