Skip to content

Commit

Permalink
#5231: Handle patch vertex colours the same ways as brushes and entit…
Browse files Browse the repository at this point in the history
…ies do
  • Loading branch information
codereader committed May 21, 2020
1 parent 4227575 commit d6c2136
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 45 deletions.
2 changes: 2 additions & 0 deletions include/ientity.h
Expand Up @@ -341,6 +341,8 @@ const char* const RKEY_SHOW_ENTITY_ANGLES = "user/ui/xyview/showEntityAngles";
class IEntitySettings
{
public:
virtual ~IEntitySettings() {}

virtual const Vector3& getLightVertexColour(LightEditVertexType type) const = 0;
virtual void setLightVertexColour(LightEditVertexType type, const Vector3& value) = 0;

Expand Down
57 changes: 29 additions & 28 deletions include/ipatch.h
@@ -1,26 +1,4 @@
/*
Copyright (C) 2001-2006, William Joseph.
All Rights Reserved.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if !defined(INCLUDED_IPATCH_H)
#define INCLUDED_IPATCH_H
#pragma once

#include "imodule.h"

Expand Down Expand Up @@ -168,6 +146,27 @@ class IPatch
virtual void setFixedSubdivisions(bool isFixed, const Subdivisions& divisions) = 0;
};

namespace patch
{

enum class PatchEditVertexType : std::size_t
{
Corners,
Inside,
NumberOfVertexTypes,
};

class IPatchSettings
{
public:
virtual ~IPatchSettings() {}

virtual const Vector3& getVertexColour(PatchEditVertexType type) const = 0;
virtual void setVertexColour(PatchEditVertexType type, const Vector3& value) = 0;

virtual sigc::signal<void>& signal_settingsChanged() = 0;
};

/* greebo: the abstract base class for a patch-creating class.
* At the moment, the CommonPatchCreator, Doom3PatchCreator and Doom3PatchDef2Creator derive from this base class.
*/
Expand All @@ -177,8 +176,12 @@ class PatchCreator :
public:
// Create a patch and return the sceneNode
virtual scene::INodePtr createPatch() = 0;

virtual IPatchSettings& getSettings() = 0;
};

}

class Patch;
class IPatchNode
{
Expand Down Expand Up @@ -236,10 +239,10 @@ enum class PatchDefType
};

// Acquires the PatchCreator of the given type ("Def2", "Def3")
inline PatchCreator& GlobalPatchCreator(PatchDefType type)
inline patch::PatchCreator& GlobalPatchCreator(PatchDefType type)
{
std::shared_ptr<PatchCreator> _patchCreator(
std::static_pointer_cast<PatchCreator>(
std::shared_ptr<patch::PatchCreator> _patchCreator(
std::static_pointer_cast<patch::PatchCreator>(
module::GlobalModuleRegistry().getModule(
type == PatchDefType::Def2 ? MODULE_PATCHDEF2 : MODULE_PATCHDEF3
)
Expand All @@ -248,5 +251,3 @@ inline PatchCreator& GlobalPatchCreator(PatchDefType type)

return *_patchCreator;
}

#endif
3 changes: 0 additions & 3 deletions radiant/brush/csg/CSG.cpp
Expand Up @@ -6,10 +6,7 @@
#include "itextstream.h"
#include "iundo.h"
#include "igrid.h"
#include "iradiant.h"
#include "imainframe.h"
#include "iselection.h"
#include "ieventmanager.h"

#include "scenelib.h"
#include "shaderlib.h"
Expand Down
19 changes: 10 additions & 9 deletions radiant/patch/Patch.cpp
@@ -1,7 +1,7 @@
#include "Patch.h"

#include "i18n.h"
#include "iuimanager.h"
#include "ipatch.h"
#include "imainframe.h"
#include "shaderlib.h"
#include "irenderable.h"
Expand All @@ -27,15 +27,16 @@ inline VertexPointer vertexpointer_arbitrarymeshvertex(const ArbitraryMeshVertex
return VertexPointer(&array->vertex, sizeof(ArbitraryMeshVertex));
}

inline const Colour4b colour_for_index(std::size_t i, std::size_t width) {
static const Vector3 cornerColourVec = ColourSchemes().getColour("patch_vertex_corner");
static const Vector3 insideColourVec = ColourSchemes().getColour("patch_vertex_inside");
const Colour4b colour_corner(int(cornerColourVec[0]*255), int(cornerColourVec[1]*255),
int(cornerColourVec[2]*255), 255);
const Colour4b colour_inside(int(insideColourVec[0]*255), int(insideColourVec[1]*255),
int(insideColourVec[2]*255), 255);
inline const Colour4b colour_for_index(std::size_t i, std::size_t width)
{
static const Vector3& cornerColourVec = GlobalPatchCreator(PatchDefType::Def3).getSettings().getVertexColour(patch::PatchEditVertexType::Corners);
static const Vector3& insideColourVec = GlobalPatchCreator(PatchDefType::Def3).getSettings().getVertexColour(patch::PatchEditVertexType::Inside);
const Colour4b colour_corner(int(cornerColourVec[0]*255), int(cornerColourVec[1]*255),
int(cornerColourVec[2]*255), 255);
const Colour4b colour_inside(int(insideColourVec[0]*255), int(insideColourVec[1]*255),
int(insideColourVec[2]*255), 255);

return (i%2 || (i/width)%2) ? colour_inside : colour_corner;
return (i%2 || (i/width)%2) ? colour_inside : colour_corner;
}

inline bool double_valid(double f) {
Expand Down
16 changes: 14 additions & 2 deletions radiant/patch/PatchCreators.cpp
Expand Up @@ -14,6 +14,9 @@
#include "patch/algorithm/General.h"
#include "selection/algorithm/Patch.h"

namespace patch
{

namespace
{
const char* const RKEY_PATCH_SUBDIVIDE_THRESHOLD = "user/ui/patch/subdivideThreshold";
Expand All @@ -30,10 +33,15 @@ scene::INodePtr Doom3PatchCreator::createPatch()
// All patches are created in the active layer by default
node->moveToLayer(GlobalMapModule().getRoot()->getLayerManager().getActiveLayer());
}

return node;
}

IPatchSettings& Doom3PatchCreator::getSettings()
{
return *_settings;
}

// RegisterableModule implementation
const std::string& Doom3PatchCreator::getName() const
{
Expand All @@ -57,6 +65,8 @@ void Doom3PatchCreator::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;

_settings.reset(new PatchSettings);

registerPatchCommands();

// Construct and Register the patch-related preferences
Expand Down Expand Up @@ -110,7 +120,7 @@ scene::INodePtr Doom3PatchDef2Creator::createPatch()
// All patches are created in the active layer by default
node->moveToLayer(GlobalMapModule().getRoot()->getLayerManager().getActiveLayer());
}

return node;
}

Expand Down Expand Up @@ -138,3 +148,5 @@ void Doom3PatchDef2Creator::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
}

}
18 changes: 17 additions & 1 deletion radiant/patch/PatchCreators.h
@@ -1,6 +1,10 @@
#pragma once

#include "ipatch.h"
#include "PatchSettings.h"

namespace patch
{

/**
* greebo: The Doom3PatchCreator implements the method createPatch(),
Expand All @@ -9,9 +13,14 @@
class Doom3PatchCreator :
public PatchCreator
{
private:
std::unique_ptr<PatchSettings> _settings;

public:
// PatchCreator implementation
scene::INodePtr createPatch();
scene::INodePtr createPatch() override;

IPatchSettings& getSettings() override;

// RegisterableModule implementation
virtual const std::string& getName() const;
Expand All @@ -31,8 +40,15 @@ class Doom3PatchDef2Creator :
// PatchCreator implementation
scene::INodePtr createPatch();

IPatchSettings& getSettings() override
{
throw std::runtime_error("Not applicable for this type, use DEF3");
}

// RegisterableModule implementation
virtual const std::string& getName() const;
virtual const StringSet& getDependencies() const;
virtual void initialiseModule(const ApplicationContext& ctx);
};

}
4 changes: 2 additions & 2 deletions radiant/patch/PatchModule.cpp
Expand Up @@ -2,5 +2,5 @@
#include "module/StaticModule.h"

// Define the static patchcreator modules
module::StaticModule<Doom3PatchCreator> doom3PatchDef3Creator;
module::StaticModule<Doom3PatchDef2Creator> doom3PatchDef2Creator;
module::StaticModule<patch::Doom3PatchCreator> doom3PatchDef3Creator;
module::StaticModule<patch::Doom3PatchDef2Creator> doom3PatchDef2Creator;
47 changes: 47 additions & 0 deletions radiant/patch/PatchSettings.h
@@ -0,0 +1,47 @@
#pragma once

#include "ipatch.h"
#include "math/Vector3.h"

namespace patch
{

class PatchSettings :
public IPatchSettings
{
private:
Vector3 _vertexColourCorner;
Vector3 _vertexColourInside;

sigc::signal<void> _signalSettingsChanged;

std::vector<Vector3> _vertexColours;
public:
PatchSettings() :
_vertexColours(static_cast<std::size_t>(PatchEditVertexType::NumberOfVertexTypes))
{
_vertexColours[static_cast<std::size_t>(PatchEditVertexType::Corners)] = Vector3(1, 0, 1);
_vertexColours[static_cast<std::size_t>(PatchEditVertexType::Inside)] = Vector3(0, 1, 0);
}

const Vector3& getVertexColour(PatchEditVertexType type) const override
{
assert(type != PatchEditVertexType::NumberOfVertexTypes);
return _vertexColours[static_cast<std::size_t>(type)];
}

void setVertexColour(PatchEditVertexType type, const Vector3& value) override
{
assert(type != PatchEditVertexType::NumberOfVertexTypes);
_vertexColours[static_cast<std::size_t>(type)] = value;

_signalSettingsChanged.emit();
}

sigc::signal<void>& signal_settingsChanged() override
{
return _signalSettingsChanged;
}
};

}
12 changes: 12 additions & 0 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -5,6 +5,7 @@
#include "ifilter.h"
#include "ientity.h"
#include "ibrush.h"
#include "ipatch.h"
#include "iorthocontextmenu.h"
#include "ieventmanager.h"
#include "imainframe.h"
Expand Down Expand Up @@ -156,11 +157,14 @@ void UserInterfaceModule::initialiseEntitySettings()
);

applyEntityVertexColours();
applyBrushVertexColours();
applyPatchVertexColours();

_coloursUpdatedConn = ColourSchemeEditor::signal_ColoursChanged().connect(
[this]() {
applyEntityVertexColours();
applyBrushVertexColours();
applyPatchVertexColours();
}
);

Expand All @@ -176,6 +180,14 @@ void UserInterfaceModule::applyBrushVertexColours()
settings.setVertexColour(ColourSchemes().getColour("brush_vertices"));
}

void UserInterfaceModule::applyPatchVertexColours()
{
auto& settings = GlobalPatchCreator(PatchDefType::Def3).getSettings();

settings.setVertexColour(patch::PatchEditVertexType::Corners, ColourSchemes().getColour("patch_vertex_corner"));
settings.setVertexColour(patch::PatchEditVertexType::Inside, ColourSchemes().getColour("patch_vertex_inside"));
}

void UserInterfaceModule::applyEntityVertexColours()
{
auto& settings = GlobalEntityModule().getSettings();
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/UserInterfaceModule.h
Expand Up @@ -41,6 +41,7 @@ class UserInterfaceModule :
void initialiseEntitySettings();
void applyEntityVertexColours();
void applyBrushVertexColours();
void applyPatchVertexColours();
void refreshShadersCmd(const cmd::ArgumentList& args);
};

Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -992,6 +992,7 @@
<ClInclude Include="..\..\radiant\model\ScaledModelExporter.h" />
<ClInclude Include="..\..\radiant\patch\algorithm\General.h" />
<ClInclude Include="..\..\radiant\patch\algorithm\Prefab.h" />
<ClInclude Include="..\..\radiant\patch\PatchSettings.h" />
<ClInclude Include="..\..\radiant\precompiled.h" />
<ClInclude Include="..\..\radiant\RadiantApp.h" />
<ClInclude Include="..\..\radiant\RadiantModule.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -2256,6 +2256,9 @@
<ClInclude Include="..\..\radiant\brush\BrushSettings.h">
<Filter>src\brush</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\patch\PatchSettings.h">
<Filter>src\patch</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit d6c2136

Please sign in to comment.