Free Electron
BoxViewerSystem.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
8 
9 namespace fe
10 {
11 namespace ext
12 {
13 
14 /**
15  * Test-only.
16  *
17  * Simple Box Viewer System used for unit testing.
18  */
19 class BoxViewerSystem : virtual public ViewerSystem
20 {
21 public:
22  void updateBoxes(const t_note_id &note_id)
23  {
24  boxAccessorSet.bind(m_dataset->scope());
25 
26  // Find box records.
27  boxAccessorSet.filter(boxRecords, m_dataset);
28  };
29 
30  void draw(Record viewportRecord) override
31  {
32  const Color green(0.0,1.0,0.0,1.0);
33 
34  // Get the pointer to the draw interface.
35  sp<DrawI> draw = m_viewportAccessorSet.draw(viewportRecord);
36 
37  // Loop over each box.
38  for (Record boxRecord : boxRecords)
39  {
40  // DrawI->drawTransformedBoxes() draws boxes from the corners.
41  // We want to draw the box from the center so we just do a little
42  // translation.
43  SpatialTransform drawBoxCenter = boxAccessorSet.transform(boxRecord);
44  translate(drawBoxCenter, -boxAccessorSet.size(boxRecord)/2);
45 
46  draw->drawTransformedBoxes(
47  &drawBoxCenter,
48  &boxAccessorSet.size(boxRecord),
49  1,
50  false,
51  &green);
52  }
53  };
54 
55  void connectOrchestrator(sp<OrchestratorI> orchestrator) override
56  {
58 
59  orchestrator->connect(this, &BoxViewerSystem::updateBoxes, "boxes_added");
60  orchestrator->connect(this, &BoxViewerSystem::updateBoxes, FE_NOTE_COMPILE);
61  }
62 
63  AsBox boxAccessorSet;
64  std::vector<Record> boxRecords;
65 };
66 
67 } /* namespace ext */
68 } /* namespace fe */
Base class for Viewer Systems.
Definition: ViewerSystem.h:21
kernel
Definition: namespace.dox:3
Special vector for color (RGBA)
Definition: Color.h:21
Accessor< SpatialVector > size
Size of box.
Definition: AsBox.h:33
Test-only.
Definition: AsBox.h:19
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Test-only.
Definition: BoxViewerSystem.h:19
void connectOrchestrator(sp< OrchestratorI > orchestrator) override
Callback for the System to register itself to the orchestrator.
Definition: ViewerSystem.h:48
void draw(Record viewportRecord) override
Draw stuff into the viewport.
Definition: BoxViewerSystem.h:30
AsViewport m_viewportAccessorSet
Accessors for viewport data.
Definition: ViewerSystem.h:63
Accessor< SpatialTransform > transform
Transform of box.
Definition: AsBox.h:31
void connectOrchestrator(sp< OrchestratorI > orchestrator) override
Callback for the System to register itself to the orchestrator.
Definition: BoxViewerSystem.h:55
Accessor< hp< DrawI > > draw
Draw Interface for actually drawing stuff.
Definition: AsViewport.h:35