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
uint width = 400;
uint height = 200;
OEImage image = new OEImage(width, height);
OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEDepict.OEPrepareDepiction(mol);
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
foreach (OE2DAtomDisplay adisp in disp.GetAtomDisplays())
{
OEAtomBase atom = adisp.GetAtom();
String message = "atom idx=" + atom.GetIdx().ToString();
OEDepict.OEAddSVGClickEvent(disp, adisp, message);
}
OEDepict.OERenderMolecule("AddAtomClickEvent.svg", disp);
Download code
Example for adding event for bond displays
uint width = 400;
uint height = 200;
OEImage image = new OEImage(width, height);
OEGraphMol mol = new OEGraphMol();
OEChem.OESmilesToMol(mol, "Cc1cccnc1/C=C/[C@H](C(=O)O)O");
OEDepict.OEPrepareDepiction(mol);
OE2DMolDisplayOptions opts = new OE2DMolDisplayOptions(width, height, OEScale.AutoScale);
OE2DMolDisplay disp = new OE2DMolDisplay(mol, opts);
foreach (OE2DBondDisplay bdisp in disp.GetBondDisplays())
{
OEBondBase bond = bdisp.GetBond();
String message = "bond idx=" + bond.GetIdx().ToString();
OEDepict.OEAddSVGClickEvent(disp, bdisp, message);
}
OEDepict.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");
OEDepict.OEAddSVGClickEvent(group_rectangle, "clicked on rectangle");
image.PushGroup(group_rectangle);
image.DrawRectangle(new OE2DPoint(30, 30), new OE2DPoint(70, 70), OEDepict.OERedBoxPen);
image.PopGroup(group_rectangle);
OESVGGroup group_circle = image.NewSVGGroup("circle");
OEDepict.OEAddSVGClickEvent(group_circle, "clicked on circle");
image.PushGroup(group_circle);
image.DrawCircle(new OE2DPoint(150, 50), 30, OEDepict.OEBlueBoxPen);
image.PopGroup(group_circle);
OEDepict.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