File: PatchControlInstance.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (53 lines) | stat: -rw-r--r-- 1,636 bytes parent folder | download | duplicates (3)
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);
	}
};