1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#pragma once
#include "ObservedSelectable.h"
#include "iselectiontest.h"
#include "PatchControl.h"
/* greebo: a PatchControlInstance basically consists of two parts: an ObservedSelectable and a PatchControl itself
*
* The PatchControl is a struct defined in ipatch.h and consists of a vertex and texture coordinates.
*
* The ObservedSelectable is inherited to inform the SelectionSystem about the selection changes. Everytime the
* selection state is altered, it calls the <observer> it has been passed in its constructor.
*/
class PatchControlInstance :
public selection::ObservedSelectable
{
public:
// The pointer to the actual PatchControl structure
PatchControl& control;
// Constructor
// It takes a reference to a PatchControl and the SelectionChanged callback as argument
// The observer/callback usually points back to the PatchNode::selectedChangeComponent member method
PatchControlInstance(PatchControl& ctrl, const SelectionChangedSlot& observer) :
selection::ObservedSelectable(observer),
control(ctrl)
{}
PatchControlInstance& operator=(const PatchControlInstance& other)
{
control = other.control;
return *this;
}
// Check if the control is selected by using the given SelectionTest
void testSelect(Selector& selector, SelectionTest& test)
{
SelectionIntersection best;
test.TestPoint(control.vertex, best);
// If there is a control point that can be selected, add the Selectable to the selector
if (best.isValid())
{
selector.addWithIntersection(*this, best);
}
}
// Snaps the control vertex to the grid
void snapto(float snap)
{
control.vertex.snap(snap);
}
};
|