Skip to content

Commit

Permalink
Disentangle Brush/Face code from UI code, use a public signal instead
Browse files Browse the repository at this point in the history
Instead of calling SurfaceInspector::update from low-level functions, we
offer a public signal for the Inspectors to subscribe when they're
opened in the first place.
  • Loading branch information
codereader committed Apr 1, 2017
1 parent 57e4a2b commit e0d901e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
11 changes: 8 additions & 3 deletions radiant/brush/Brush.cpp
Expand Up @@ -11,7 +11,6 @@
#include "Face.h"
#include "FixedWinding.h"
#include "math/Ray.h"
#include "ui/surfaceinspector/SurfaceInspector.h"

#include <functional>

Expand Down Expand Up @@ -460,8 +459,8 @@ void Brush::onFaceShaderChanged()
{
onFacePlaneChanged();

// Queue an UI update of the texture tools
ui::SurfaceInspector::update();
// Queue an UI update of the texture tools if any of them is listening
signal_faceShaderChanged().emit();
}

void Brush::onFaceConnectivityChanged()
Expand Down Expand Up @@ -914,6 +913,12 @@ bool Brush::getIntersection(const Ray& ray, Vector3& intersection)
return true;
}

sigc::signal<void>& Brush::signal_faceShaderChanged()
{
static sigc::signal<void> _sigFaceShaderChanged;
return _sigFaceShaderChanged;
}

void Brush::edge_push_back(FaceVertexId faceVertex) {
m_select_edges.push_back(SelectableEdge(m_faces, faceVertex));
for (Observers::iterator i = m_observers.begin(); i != m_observers.end(); ++i) {
Expand Down
6 changes: 5 additions & 1 deletion radiant/brush/Brush.h
Expand Up @@ -8,6 +8,7 @@
#include "RenderableWireFrame.h"
#include "Translatable.h"

#include <sigc++/signal.h>
#include <boost/noncopyable.hpp>

class RenderableCollector;
Expand Down Expand Up @@ -129,7 +130,7 @@ class Brush :
// ----

DetailFlag _detailFlag;

public:
// Public constants
static const std::size_t PRISM_MIN_SIDES;
Expand Down Expand Up @@ -303,6 +304,9 @@ class Brush :
// Calculate the intersection of the given ray with this brush, returns true on intersection and fills in the out variable
bool getIntersection(const Ray& ray, Vector3& intersection);

// Signal for external code to get notified each time any face of any brush changes
static sigc::signal<void>& signal_faceShaderChanged();

private:
void edge_push_back(FaceVertexId faceVertex);

Expand Down
11 changes: 8 additions & 3 deletions radiant/brush/Face.cpp
Expand Up @@ -11,7 +11,6 @@
#include "Brush.h"
#include "BrushNode.h"
#include "BrushModule.h"
#include "ui/surfaceinspector/SurfaceInspector.h"

// The structure that is saved in the undostack
class Face::SavedState :
Expand Down Expand Up @@ -377,8 +376,8 @@ void Face::texdefChanged()
revertTexdef();
EmitTextureCoordinates();

// Update the Texture Tools
ui::SurfaceInspector::update();
// Fire the signal to update the Texture Tools
signal_texdefChanged().emit();
}

const TextureProjection& Face::getProjection() const
Expand Down Expand Up @@ -607,3 +606,9 @@ void Face::updateFaceVisibility()
{
_faceIsVisible = contributes() && getFaceShader().getGLShader()->getMaterial()->isVisible();
}

sigc::signal<void>& Face::signal_texdefChanged()
{
static sigc::signal<void> _sigTexdefChanged;
return _sigTexdefChanged;
}
4 changes: 4 additions & 0 deletions radiant/brush/Face.h
Expand Up @@ -13,6 +13,7 @@
#include "FacePlane.h"
#include <memory>
#include <boost/noncopyable.hpp>
#include <sigc++/signal.h>
#include "selection/algorithm/Shader.h"

const double GRID_MIN = 0.125;
Expand Down Expand Up @@ -207,4 +208,7 @@ class Face :

void updateFaceVisibility();

// Signal for external code to get notified each time the texdef of any face changes
static sigc::signal<void>& signal_texdefChanged();

}; // class Face
11 changes: 11 additions & 0 deletions radiant/ui/surfaceinspector/SurfaceInspector.cpp
Expand Up @@ -30,6 +30,7 @@
#include "selection/algorithm/Primitives.h"
#include "selection/algorithm/Shader.h"
#include "brush/Face.h"
#include "brush/Brush.h"

namespace ui
{
Expand Down Expand Up @@ -705,6 +706,13 @@ void SurfaceInspector::_preShow()
GlobalSelectionSystem().addObserver(this);
GlobalUndoSystem().addObserver(this);

// Get notified about face shader changes
_brushFaceShaderChanged = Brush::signal_faceShaderChanged().connect(
[this] { _updateNeeded = true; });

_faceTexDefChanged = Face::signal_texdefChanged().connect(
[this] { _updateNeeded = true; });

// Re-scan the selection
doUpdate();
}
Expand All @@ -720,6 +728,9 @@ void SurfaceInspector::_preHide()
{
TransientWindow::_preHide();

_faceTexDefChanged.disconnect();
_brushFaceShaderChanged.disconnect();

GlobalUndoSystem().removeObserver(this);
GlobalSelectionSystem().removeObserver(this);
}
Expand Down
12 changes: 8 additions & 4 deletions radiant/ui/surfaceinspector/SurfaceInspector.h
Expand Up @@ -9,6 +9,7 @@
#include "wxutil/window/TransientWindow.h"
#include "ui/common/ShaderChooser.h"

#include <sigc++/connection.h>
#include <memory>

namespace wxutil { class ControlButton; }
Expand All @@ -29,10 +30,10 @@ class SurfaceInspector;
typedef std::shared_ptr<SurfaceInspector> SurfaceInspectorPtr;

/// Inspector for properties of a surface and its applied texture
class SurfaceInspector
: public wxutil::TransientWindow,
public SelectionSystem::Observer,
public UndoSystem::Observer
class SurfaceInspector :
public wxutil::TransientWindow,
public SelectionSystem::Observer,
public UndoSystem::Observer
{
struct ManipulatorRow
{
Expand Down Expand Up @@ -90,6 +91,9 @@ class SurfaceInspector

bool _updateNeeded;

sigc::connection _brushFaceShaderChanged;
sigc::connection _faceTexDefChanged;

public:

// Constructor
Expand Down

0 comments on commit e0d901e

Please sign in to comment.