本文整理汇总了C++中Composite::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Composite::add方法的具体用法?C++ Composite::add怎么用?C++ Composite::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composite
的用法示例。
在下文中一共展示了Composite::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_incomplete
void test_incomplete()
{
Composite c;
c.add( new ConcreteComposite1 );
c.add( new ConcreteComposite2 );
BOOST_CHECK_EQUAL( c.size(), 3u );
c.add( new_clone( c ) ); // add c to itself
BOOST_CHECK_EQUAL( c.size(), 6u );
c.add( c ); // add c to itself
BOOST_CHECK_EQUAL( c.size(), 12u );
c.foo();
}
示例2: init
bool PoissonBlendEx::init(Composite& rootNode) {
ImageRGBA srcImg, tarImg;
ReadImageFromFile(getFullPath("images/sfmarket.png"), srcImg);
ReadImageFromFile(getFullPath("images/sfsunset.png"), tarImg);
ConvertImage(srcImg, src);
ConvertImage(tarImg, tar);
ImageGlyphPtr srcGlyph = createImageGlyph(srcImg, false);
ImageGlyphPtr tarGlyph = createImageGlyph(tarImg, false);
ImageGlyphPtr resultGlyph = createImageGlyph(tarImg, false);
GlyphRegionPtr srcRegion = MakeGlyphRegion(srcGlyph,
CoordPercent(0.05f, 0.0f), CoordPercent(0.4f, 0.3f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
GlyphRegionPtr tarRegion = MakeGlyphRegion(tarGlyph,
CoordPercent(0.55f, 0.0f), CoordPercent(0.4f, 0.3f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
TextLabelPtr textLabel = TextLabelPtr(
new TextLabel("Solving Poisson Blend ...",
CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f)));
textLabel->fontSize = UnitPX(20.0f);
textLabel->fontType = FontType::Bold;
textLabel->fontStyle = FontStyle::Outline;
GlyphRegionPtr resultRegion = MakeGlyphRegion(resultGlyph,
CoordPercent(0.1f, 0.35f), CoordPercent(0.8f, 0.5f),
AspectRule::FixedWidth, COLOR_NONE, COLOR_NONE,
Color(200, 200, 200, 255), UnitPX(1.0f));
rootNode.add(srcRegion);
rootNode.add(tarRegion);
rootNode.add(resultRegion);
rootNode.add(textLabel);
workerTask = WorkerTaskPtr(new Worker([=] {
PoissonBlend(src, tar, 32, 6);
ImageRGBA out;
ConvertImage(tar,out);
getContext()->addDeferredTask([=]() {
resultGlyph->set(out,getContext().get());
textLabel->setLabel("Finished!");
});
}));
workerTask->execute(isForcedClose());
return true;
}
示例3: main
int main() {
Composite comp;
Leaf test("test");
test.show();
comp.add(&test);
Composite a;
a.add(new Leaf("aa"));
a.add(new Leaf("bb"));
a.show();
comp.add(&a);
comp.show();
return 0;
}
示例4: init
bool MeshWireframeEx::init(Composite& rootNode) {
box3f renderBBox = box3f(float3(-0.5f, -0.5f, -0.5f),
float3(1.0f, 1.0f, 1.0f));
mesh.load(getFullPath("models/monkey.obj"));
Subdivide(mesh,SubDivisionScheme::CatmullClark);
mesh.updateVertexNormals();
//Make region on screen to render 3d view
renderRegion = MakeRegion("Render View", CoordPerPX(0.5f, 0.5f, -256, -256),
CoordPX(512, 512), COLOR_NONE, COLOR_WHITE, UnitPX(1.0f));
//Initialize depth buffer to store the render
depthFrameBuffer.initialize(512, 512);
wireframeFrameBuffer.initialize(512, 512);
//Set up camera
camera.setNearFarPlanes(-2.0f, 2.0f);
camera.setZoom(0.75f);
camera.setCameraType(CameraType::Orthographic);
//Map object geometry into unit bounding box for draw.
camera.setPose(MakeTransform(mesh.getBoundingBox(), renderBBox));
//Add listener to respond to mouse manipulations
addListener(&camera);
//Add render component to root node so it is relatively positioned.
rootNode.add(renderRegion);
setOnResize([=](const int2& dims) {
camera.setDirty(true);
});
wireframeShader.setFaceColor(Color(0.1f,0.1f,1.0f,0.5f));
wireframeShader.setEdgeColor(Color(1.0f,0.8f,0.1f,1.0f));
wireframeShader.setLineWidth(1.5f);
return true;
}
示例5: init
bool MeshParticleEx::init(Composite& rootNode) {
box3f renderBBox = box3f(float3(-0.5f, -0.5f, -0.5f),float3(1.0f, 1.0f, 1.0f));
mesh.load(getFullPath("models/monkey.obj"));
mesh.updateVertexNormals();
int N = (int)mesh.vertexLocations.size();
mesh.vertexColors.resize(N);
box3f box = mesh.getBoundingBox();
for (int n = 0; n < N; n++) {
float3 pt = mesh.vertexLocations[n];
pt = (pt - box.position) / box.dimensions;
mesh.vertexColors[n] = HSVAtoRGBAf(HSVA(pt.x, 0.7f, 0.8f, 1.0f));
}
//Make region on screen to render 3d view
renderRegion=MakeRegion("Render View",CoordPerPX(0.5f,0.5f,-256,-256),CoordPX(512,512),COLOR_NONE,COLOR_WHITE,UnitPX(1.0f));
//Initialize depth buffer to store the render
depthFrameBuffer.initialize(512, 512);
//Set up camera
camera.setNearFarPlanes(0.1f, 3.0f);
camera.setZoom(1.0f);
camera.setCameraType(CameraType::Perspective);
camera.setDirty(true);
//Map object geometry into unit bounding box for draw.
camera.setPose(MakeTransform(mesh.getBoundingBox(), renderBBox));
//Add listener to respond to mouse manipulations
addListener(&camera);
//Add render component to root node so it is relatively positioned.
rootNode.add(renderRegion);
return true;
}
示例6: main
int main() {
Leaf* leaf1 = new Leaf();
Leaf* leaf2 = new Leaf();
Composite* composite = new Composite();
composite->add( leaf1 );
composite->add( leaf2 );
Composite* composite2 = new Composite();
composite2->add( new Leaf() );
composite2->add( new Leaf() );
composite2->add( new Leaf() );
composite2->add( new Leaf() );
composite->add( composite2 );
composite->operation();
}
示例7: init
bool TabPaneEx::init(Composite& rootNode) {
TabBarPtr tabBar=TabBarPtr(new TabBar("Tab Bar",CoordPX(10,10),CoordPerPX(1.0,1.0,-20.0f,-20.0f)));
tabBar->backgroundColor=MakeColor(64,64,64);
const int K = 15;
for (int k = 0;k < K;k++) {
CompositePtr tabPane = CompositePtr(new Composite(MakeString()<<"Tab "<<k, CoordPX(0, 0), CoordPercent(1.0f, 1.0f)));
tabPane->backgroundColor = MakeColor(HSVAtoColor(HSVA(k/(float)K, 0.7f, 1.0f, 1.0f)));
tabBar->addPane(MakeShared<TabPane>(tabPane,(k%2==0)));
}
rootNode.backgroundColor=MakeColor(0,0,0);
rootNode.add(tabBar);
return true;
}
示例8: init
bool DialogsEx::init(Composite& rootNode) {
FileButtonPtr saveButton=FileButtonPtr(new FileButton("Save File", CoordPerPX(0.2f, 0.0f, 0.0f, 5.0f),CoordPX(40, 40), FileDialogType::SaveFile));
FileButtonPtr openMultiButton = FileButtonPtr(new FileButton("Open Multi-File", CoordPerPX(0.2f, 0.0f, 45.0f, 5.0f), CoordPX(40, 40), FileDialogType::OpenMultiFile));
FileSelectorPtr fileSelector=FileSelectorPtr(new FileSelector("Selector", CoordPerPX(0.5f, 0.0f,0.0f,90.0f),CoordPX(300.0f, 30.0f)));
ColorSelectorPtr colorselect = ColorSelectorPtr(new ColorSelector("Color", CoordPerPX(0.2f, 0.0f, 90.0f, 5.0f), CoordPX(150, 40)));
ListBoxPtr listBox = ListBoxPtr(new ListBox("List Box", CoordPX( 5.0f, 90.0f),CoordPX(300,300)));
for (int i = 0;i < 30;i++) {
listBox->addEntry(ListEntryPtr(new ListEntry(listBox.get(),MakeString()<<"Multi-Selection Entry ("<<i<<")",30.0f)));
}
listBox->update();
listBox->setEnableMultiSelection(true);
rootNode.add(saveButton);
rootNode.add(openMultiButton);
rootNode.add(fileSelector);
rootNode.add(colorselect);
rootNode.add(listBox);
using extensions = std::initializer_list<std::string>;
std::string exampleFile = getContext()->getFullPath("images" + ALY_PATH_SEPARATOR + "sfsunset.png");
fileSelector->addFileExtensionRule("Portable Network Graphics", "png");
fileSelector->addFileExtensionRule("XML", extensions { "raw", "xml" });
fileSelector->addFileExtensionRule("Text", "txt");
fileSelector->setValue(exampleFile);
saveButton->addFileExtensionRule("Portable Network Graphics", "png");
saveButton->addFileExtensionRule("XML", extensions { "raw", "xml" });
saveButton->addFileExtensionRule("Text", "txt");
saveButton->setValue(exampleFile);
openMultiButton->addFileExtensionRule("Portable Network Graphics", "png");
openMultiButton->addFileExtensionRule("XML", extensions { "raw", "xml" });
openMultiButton->addFileExtensionRule("Text", "txt");
openMultiButton->setValue(exampleFile);
return true;
}
示例9: init
bool TweenEx::init(Composite& rootNode) {
TextLabelPtr label = MakeTextLabel("Hello There!", CoordPercent(0.5f, 0.9f), CoordPX(100, 30), FontType::Normal, UnitPT(16.0f),RGBA(255, 255, 255, 255), HorizontalAlignment::Center,VerticalAlignment::Bottom);
label->setOrigin(Origin::MiddleCenter);
std::shared_ptr<ImageGlyph> img = createImageGlyph(getFullPath("images/sfmarket.png"));
GlyphRegionPtr imgr = MakeGlyphRegion(img, CoordPercent(0.5f, 0.45f),CoordPX(100,300), AspectRule::FixedHeight, Color(32, 64, 128, 255),Color(128, 128, 128, 128), Color(200, 200, 200, 255), UnitPX(1.0f));
GlyphRegionPtr iconr = MakeGlyphRegion(createAwesomeGlyph(0xf1b3),CoordPX(20, 20), CoordPX(50, 50), Color(32, 64, 128, 255),Color(255, 255, 255, 255));
imgr->setOrigin(Origin::MiddleCenter);
addTween(imgr->foregroundColor, Color(128, 128, 128, 255),Color(128, 128, 128, 0), 3.0, SineOut());
addTween(imgr->dimensions, CoordPX(50, 50), CoordPX(300, 300), 1.0, SineOut());
addTween(iconr->backgroundColor, Color(255, 64, 32, 255),Color(32, 64, 255, 255), 3.0, SineIn());
addTween(iconr->foregroundColor, Color(0, 0, 0, 255),Color(255, 255, 255, 255), 3.0, SineIn());
addTween(iconr->position, CoordPX(100, 10), CoordPerPX(0.5f,0.0f,-25.0f, 10.0f), 3.0, ExponentialOut());
addTween(label->position, CoordPercent(0.5f, 0.7f), CoordPercent(0.5f, 0.9f), 1.0f, ExponentialOut())->addCompleteEvent([=](Tweenable* tween) {
addTween(label->fontSize, UnitPT(16.0f), UnitPT(36.0f), 1.0f, ExponentialIn())->addCompleteEvent(
[=](Tweenable* object) {
label->setLabel( "Did you like that tween?");
});
});
rootNode.add(label);
rootNode.add(iconr);
rootNode.add(imgr);
return true;
}
示例10: init
bool ExpandEx::init(Composite& rootNode) {
ExpandBarPtr expandBar = ExpandBarPtr(
new ExpandBar("exapander", CoordPercent(0.7f, 0.0f),
CoordPercent(0.3f, 1.0f)));
CompositePtr geomRegion = CompositePtr(
new aly::Composite("Geometry", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 400.0f)));
CompositePtr scrollRegion = CompositePtr(
new aly::Composite("Scroll", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 200.0f)));
scrollRegion->setScrollEnabled(true);
scrollRegion->setOrientation(Orientation::Vertical);
scrollRegion->add(
MakeRegion("Region 1", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 300.0f), Color(255, 0, 0)));
scrollRegion->add(
MakeRegion("Region 2", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 300.0f), Color(0, 255, 0)));
expandBar->add(geomRegion, 400, false);
std::string exampleFile = getContext()->getFullPath(
"models" + ALY_PATH_SEPARATOR+"monkey.ply");
geomRegion->setOrientation(Orientation::Vertical);
geomRegion->add(scrollRegion);
RegionPtr apprRegion = RegionPtr(
new aly::Region("Appearance", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 3000.0f)));
expandBar->add(apprRegion, 400, false);
apprRegion->backgroundColor = MakeColor(128, 64, 255);
CompositePtr lightRegion = CompositePtr(
new aly::Composite("Lighting", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 300.0f)));
expandBar->add(lightRegion, 300, false);
RegionPtr renderingRegion = RegionPtr(
new aly::Region("Rendering", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 300.0f)));
expandBar->add(renderingRegion, 300, true);
RegionPtr filterRegion = RegionPtr(
new aly::Region("Filtering", CoordPX(0, 0),
CoordPerPX(1.0f, 0.0f, 0.0f, 300.0f)));
expandBar->add(filterRegion, 300, false);
rootNode.backgroundColor = MakeColor(getContext()->theme.LIGHT);
rootNode.add(expandBar);
return true;
}
示例11: init
bool DragEx::init(Composite& rootNode) {
int N = 25;
srand(817213);
std::list<TextLabelPtr> labels;
for (int i = 0;i <N;i++) {
TextLabelPtr label = MakeTextLabel(MakeString() << "Drag (" << i<<")", CoordPX(rand()%700, rand()%500), CoordPX(100, 100), FontType::Bold, UnitPT(16.0f), COLOR_WHITE, HorizontalAlignment::Center, VerticalAlignment::Middle);
label->backgroundColor = MakeColor(HSVAtoColor(HSVA(i/(float)N,0.7f,0.5f,1.0f)));
label->borderColor = MakeColor(64,64,64);
label->borderWidth = UnitPX(1.0f);
label->onMouseDown = [=](AlloyContext* context, const InputEvent& e) {
if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
//Bring component to top by setting it to be drawn last.
dynamic_cast<Composite*>(label->parent)->putLast(label);
label->borderColor = MakeColor(200, 200, 200);
}
return false;
};
label->onMouseUp = [=](AlloyContext* context, const InputEvent& e) {
label->borderColor = MakeColor(64,64,64);
return false;
};
labels.push_back(label);
label->setDragEnabled(true);
rootNode.add(label);
}
//Force drag elements inside draw bounds.
setOnResize([=](const int2& dims) {
box2px bounds(pixel2(0, 0), pixel2((float)dims.x,(float)dims.y));
for (TextLabelPtr label : labels) {
//Get current location, including drag offset.
box2px box = label->getBounds();
box.position = aly::clamp(box.position, bounds.position,bounds.position + bounds.dimensions - box.dimensions);
label->position=CoordPX(box.position);
//Reset drag offset now that we changed position.
label->setDragOffset(pixel2(0, 0));
//Repack component.
label->pack();
}
});
//getContext()->setDebug(true);
return true;
}
示例12: init
bool ExpandTreeEx::init(Composite& rootNode) {
ExpandTreePtr tree = ExpandTreePtr(
new ExpandTree("Tree", CoordPercent(0.0f, 0.0f),
CoordPercent(0.35f, 1.0f)));
std::string homeDir = GetCurrentWorkingDirectory();
for (FileDescription fd : GetDirectoryDescriptionListing(homeDir)) {
std::string fileName = GetFileName(fd.fileLocation);
if (fileName.length() > 0 && fileName[0] == '.')
continue;
TreeItemPtr child;
if (fd.fileType == FileType::Directory) {
child = TreeItemPtr(new TreeItem(fileName, 0xf115, 22));
addDirectory(fd.fileLocation, child.get());
} else {
child = TreeItemPtr(new TreeItem(fileName, 0xf016, 18));
child->onExpand = [this,fd](TreeItem* current) {
addLeaf(current,fd);
};
}
tree->addItem(child);
}
rootNode.add(tree);
return true;
}
示例13: init
bool ColorSpaceEx::init(Composite& rootNode) {
//Set up camera
camera.setNearFarPlanes(-10.0f, 10.0f);
camera.setZoom(1.0f);
camera.setCameraType(CameraType::Orthographic);
camera.setPose(float4x4::identity());
//Map object geometry into unit bounding box for draw.
//Add listener to respond to mouse manipulations
addListener(&camera);
setOnResize([this](const int2& dims) {
camera.setDirty(true);
});
SelectionPtr selection = SelectionPtr(new Selection("Color Space", CoordPX(5, 5), CoordPX(200, 30), std::vector<std::string>{"RGB", "HSV", "XYZ", "CIELAB"}));
selection->onSelect = [this](int index) {
this->setColorSpace(index);
};
selection->setSelectionIndex(3);
rootNode.add(selection);
return true;
}
示例14: init
bool DataFlowEx::init(Composite& rootNode) {
graph = MakeDataFlow("Data Flow", CoordPX(10, 10),
CoordPerPX(1.0f, 1.0f, -20.0f, -20.0f));
ComputePtr computeNode1 = MakeComputeNode("Compute 1", pixel2(200, 600));
ComputePtr computeNode2 = MakeComputeNode("Compute 2", pixel2(600, 600));
ComputePtr computeNode3 = MakeComputeNode("Compute 3", pixel2(100, 700));
ComputePtr computeNode4 = MakeComputeNode("Compute 4", pixel2(300, 700));
ComputePtr computeNode5 = MakeComputeNode("Compute 5", pixel2(500, 700));
ComputePtr computeNode6 = MakeComputeNode("Compute 6", pixel2(700, 700));
ComputePtr computeNode7 = MakeComputeNode("Compute 7", pixel2(400, 800));
ViewPtr viewNode1 = MakeViewNode("View 1", pixel2(200, 800));
ViewPtr viewNode2 = MakeViewNode("View 2", pixel2(600, 800));
DataPtr dataNode1 = MakeDataNode("Data 1", pixel2(100, 300));
DataPtr dataNode2 = MakeDataNode("Data 2", pixel2(300, 300));
DataPtr dataNode3 = MakeDataNode("Data 3", pixel2(300, 500));
DataPtr dataNode4 = MakeDataNode("Data 4", pixel2(100, 500));
SourcePtr sourceNode1 = MakeSourceNode("Source 1", pixel2(100, 100));
SourcePtr sourceNode2 = MakeSourceNode("Source 2", pixel2(200, 200));
SourcePtr sourceNode3 = MakeSourceNode("Source 3", pixel2(300, 200));
GroupPtr groupNode1 = MakeGroupNode("Group 1", pixel2(600, 400));
GroupPtr groupNode2 = MakeGroupNode("Group 2", pixel2(800, 400));
DestinationPtr destNode1 = MakeDestinationNode("Destination 1",
pixel2(350, 900));
DestinationPtr destNode2 = MakeDestinationNode("Destination 2",
pixel2(450, 900));
for (int i = 0; i <2; i++) {
groupNode1->add(MakeInputPort(MakeString() << "Input " << i));
groupNode2->add(MakeInputPort(MakeString() << "Input " << i));
}
for (int i = 0; i <2; i++) {
groupNode1->add(MakeOutputPort(MakeString() << "Output " << i));
groupNode2->add(MakeOutputPort(MakeString() << "Output " << i));
}
for (int i = 0; i < 4; i++) {
dataNode1->add(MakeInputPort(MakeString() << "Input " << i));
dataNode2->add(MakeInputPort(MakeString() << "Input " << i));
dataNode3->add(MakeInputPort(MakeString() << "Input " << i));
dataNode4->add(MakeInputPort(MakeString() << "Input " << i));
}
for (int i = 0; i < 3; i++) {
dataNode1->add(MakeOutputPort(MakeString() << "Output " << i));
dataNode2->add(MakeOutputPort(MakeString() << "Output " << i));
dataNode3->add(MakeOutputPort(MakeString() << "Output " << i));
dataNode4->add(MakeOutputPort(MakeString() << "Output " << i));
}
for (int i = 0; i < 7; i++) {
computeNode1->add(MakeInputPort(MakeString() << "Input " << i));
computeNode2->add(MakeInputPort(MakeString() << "Input " << i));
computeNode3->add(MakeInputPort(MakeString() << "Input " << i));
computeNode4->add(MakeInputPort(MakeString() << "Input " << i));
computeNode5->add(MakeInputPort(MakeString() << "Input " << i));
computeNode6->add(MakeInputPort(MakeString() << "Input " << i));
computeNode7->add(MakeInputPort(MakeString() << "Input " << i));
}
for (int i = 0; i < 2; i++) {
computeNode1->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode2->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode3->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode4->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode5->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode6->add(MakeOutputPort(MakeString() << "Output " << i));
computeNode7->add(MakeOutputPort(MakeString() << "Output " << i));
}
for (int i = 0; i < 3; i++) {
viewNode1->add(MakeInputPort(MakeString() << "Input " << i));
viewNode2->add(MakeInputPort(MakeString() << "Input " << i));
}
graph->add(computeNode1);
graph->add(computeNode2);
graph->add(computeNode3);
graph->add(computeNode4);
graph->add(computeNode5);
graph->add(computeNode6);
graph->add(computeNode7);
graph->add(viewNode1);
graph->add(viewNode2);
graph->add(groupNode1);
graph->add(groupNode2);
graph->add(dataNode1);
graph->add(dataNode2);
graph->add(dataNode3);
graph->add(dataNode4);
graph->add(MakeConnection(groupNode1->getOutputPort(0), computeNode2->getInputPort(3)));
graph->add(MakeConnection(groupNode2->getOutputPort(1), computeNode2->getInputPort(4)));
graph->add(MakeConnection(computeNode1->getOutputPort(0), computeNode3->getInputPort(1)));
//.........这里部分代码省略.........
示例15: init
bool LocatorEx::init(Composite& rootNode) {
const int N = 300;
const int K = 5;
const float SEARCH_RADIUS = 0.2f;
drawRegion = DrawPtr(new Draw("Draw Region", CoordPerPX(0.5f, 0.5f, -400, -400), CoordPX(800, 800)));
rootNode.add(drawRegion);
samples.resize(N);
for (int n = 0; n < N; n++) {
samples[n] = float2(RandomUniform(0.0f, 1.0f),
RandomUniform(0.0f, 1.0f));
}
locator = std::unique_ptr<Locator2f>(new Locator2f(samples));
matcher = std::unique_ptr<Matcher2f>(new Matcher2f(samples));
MakeDelaunay(samples, delaunayTriangles);
drawRegion->onDraw = [this, SEARCH_RADIUS](const AlloyContext* context, const box2px& bounds) {
NVGcontext* nvg = context->nvgContext;
nvgStrokeColor(nvg, Color(64, 64, 64));
nvgStrokeWidth(nvg, 2.0f);
for (int n = 0; n < (int)delaunayTriangles.size(); n++) {
uint3 tri = delaunayTriangles[n];
float2 pt0 = samples[tri.x];
float2 pt1 = samples[tri.y];
float2 pt2 = samples[tri.z];
pt0 = pt0*bounds.dimensions + bounds.position;
pt1 = pt1*bounds.dimensions + bounds.position;
pt2 = pt2*bounds.dimensions + bounds.position;
nvgBeginPath(nvg);
nvgMoveTo(nvg, pt0.x, pt0.y);
nvgLineTo(nvg, pt1.x, pt1.y);
nvgLineTo(nvg, pt2.x, pt2.y);
nvgStroke(nvg);
}
if (cursor.x > 0 && cursor.y > 0) {
nvgStrokeColor(nvg, Color(255, 128, 64));
nvgStrokeWidth(nvg, 2.0f);
for (int n = 0; n < (int)kNN.size(); n++) {
float2 pt = samples[kNN[n].first];
nvgBeginPath(nvg);
pt = pt*bounds.dimensions + bounds.position;
nvgMoveTo(nvg, cursor.x, cursor.y);
nvgLineTo(nvg, pt.x, pt.y);
nvgStroke(nvg);
}
nvgBeginPath(nvg);
nvgFillColor(nvg, Color(255, 128, 64));
nvgCircle(nvg, cursor.x, cursor.y, 4.0f);
nvgFill(nvg);
}
nvgFillColor(nvg, Color(128, 128, 128));
for (float2 pt : samples.data) {
nvgBeginPath(nvg);
pt = pt*bounds.dimensions + bounds.position;
nvgCircle(nvg, pt.x, pt.y, 2.0f);
nvgFill(nvg);
}
for (float2i pt : nearest) {
nvgFillColor(nvg, Color(128, 128, 255, 255));
nvgBeginPath(nvg);
float2 qt = pt*bounds.dimensions + bounds.position;
nvgCircle(nvg, qt.x, qt.y, 4.0f);
nvgFill(nvg);
}
if (closest.index >= 0) {
nvgFillColor(nvg, Color(128, 255, 128));
nvgBeginPath(nvg);
float2 pt = closest*bounds.dimensions + bounds.position;
nvgCircle(nvg, pt.x, pt.y, 6.0f);
nvgFill(nvg);
}
if (cursor.x > 0 && cursor.y > 0) {
nvgStrokeColor(nvg, Color(128, 128, 255, 128));
nvgStrokeWidth(nvg, 2.0f);
nvgBeginPath(nvg);
nvgEllipse(nvg, cursor.x, cursor.y, SEARCH_RADIUS*bounds.dimensions.x, SEARCH_RADIUS*bounds.dimensions.y);
nvgStroke(nvg);
}
};
drawRegion->onMouseOver = [this, K, SEARCH_RADIUS](const AlloyContext* context, const InputEvent& event) {
box2px bounds = drawRegion->getBounds();
cursor = event.cursor;
float2 pt = (cursor - bounds.position) / bounds.dimensions;
closest = locator->closest(pt);
locator->closest(pt, SEARCH_RADIUS, nearest);
matcher->closest(pt, K, kNN);
return true;
};
return true;
}