OEAddSVGClickEvent¶
Link |
Description |
---|---|
adding click event to OE2DAtomDisplay |
|
adding click event to OE2DBondDisplay |
|
adding click event to OESVGGroup (low-level function) |
bool OEAddSVGClickEvent(OE2DMolDisplay& disp, OE2DAtomDisplay* adisp,
const std::string& message);
bool OEAddSVGClickEvent(OE2DMolDisplay& disp, OE2DBondDisplay* bdisp,
const std::string& message);
Adds a click event to an atom or bond in an .svg
image.
When clicking at the position defined by the given atom or bond
display, an event is triggered with the given message.
Note
This functionality is only available for .svg
image format.
See also
Generating Interactive SVG Images chapter including the How to Catch SVG Events section
- disp
The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.
- adisp
The OE2DAtomDisplay object that defines the mouse click position.
- bdisp
The OE2DBondDisplay object that defines the mouse click position
- message
The text that will be emitted when an event is triggered on mouse click.
Example for adding event for atom displays
const auto width = 400u;
const auto height = 200u;
OEImage image(width, height);
OEGraphMol mol;
OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEPrepareDepiction(mol);
OE2DMolDisplayOptions opts(width, height, OEScale::AutoScale);
OE2DMolDisplay disp(mol, opts);
for (OEIter<OE2DAtomDisplay> ai = disp.GetAtomDisplays(); ai; ++ai)
{
OE2DAtomDisplay* adisp = ai;
const OEAtomBase* atom = adisp->GetAtom();
const string message = "atom idx=" + OENumberToString(atom->GetIdx());
OEAddSVGClickEvent(disp, adisp, message);
}
OERenderMolecule("AddAtomClickEvent.svg", disp);
Download code
Example for adding event for bond displays
const auto width = 400u;
const auto height = 200u;
OEImage image(width, height);
OEGraphMol mol;
OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEPrepareDepiction(mol);
OE2DMolDisplayOptions opts(width, height, OEScale::AutoScale);
OE2DMolDisplay disp(mol, opts);
for (OEIter<OE2DBondDisplay> bi = disp.GetBondDisplays(); bi; ++bi)
{
OE2DBondDisplay* bdisp = bi;
const OEBondBase* bond = bdisp->GetBond();
const string message = "bond idx=" + OENumberToString(bond->GetIdx());
OEAddSVGClickEvent(disp, bdisp, message);
}
OERenderMolecule("AddBondClickEvent.svg", disp);
Download code
See also
OE2DMolDisplay class
OE2DAtomDisplay and OE2DBondDisplay classes
bool OEAddSVGClickEvent(OESVGGroup* svggroup, const std::string& message);
Adds a click event to a specific SVG group in .svg
image.
When clicking at the elements drawn inside the given
OESVGGroup object, an event is triggered
with the given message
Note
This functionality is only available for .svg
image format.
Hint
The OEAddSVGClickEvent
function should always be called
prior to pushing / popping the OESVGGroup object.
Example:
The following example creates an .svg
image with a red rectangle and
a blue circle.
Both drawing elements are rendered inside OESVGGroup objects
that are associated with messages clicked on rectangle
and clicked on circle
,
respectively.
When the generated .svg
image is displayed in a HTTP server, clicking
on the rectangle and the circle triggers events with the corresponding messages.
OESVGGroup* group_rectangle = image.NewSVGGroup("rectangle");
OEAddSVGClickEvent(group_rectangle, "clicked on rectangle");
image.PushGroup(group_rectangle);
image.DrawRectangle(OE2DPoint(30, 30), OE2DPoint(70, 70), OERedBoxPen);
image.PopGroup(group_rectangle);
OESVGGroup* group_circle = image.NewSVGGroup("circle");
OEAddSVGClickEvent(group_circle, "clicked on circle");
image.PushGroup(group_circle);
image.DrawCircle(OE2DPoint(150, 50), 30, OEBlueBoxPen);
image.PopGroup(group_circle);
OEWriteImage("AddSVGClickEvent.svg", image);
Download code
See also
Generating Interactive SVG Images chapter including the How to Catch SVG Events section that shows how to test the
.svg
image file generated by this example.OEAddSVGHover
functionOEAddSVGToggle
function