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
int width = 400;
int 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);
for (OE2DAtomDisplay adisp : disp.GetAtomDisplays()) {
OEAtomBase atom = adisp.GetAtom();
String message = "atom idx=" + Integer.toString(atom.GetIdx());
oedepict.OEAddSVGClickEvent(disp, adisp, message);
}
oedepict.OERenderMolecule("AddAtomClickEvent.svg", disp);
Download code
Example for adding event for bond displays
int width = 400;
int 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);
for (OE2DBondDisplay bdisp : disp.GetBondDisplays()) {
OEBondBase bond = bdisp.GetBond();
String message = "bond idx=" + Integer.toString(bond.GetIdx());
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.getOERedBoxPen());
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.getOEBlueBoxPen());
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