OEDrawSVGHoverText¶
bool OEDrawSVGHoverText(OE2DMolDisplay &disp, OE2DAtomDisplay *adisp,
const std::string &text, const OEFont &font)
bool OEDrawSVGHoverText(OE2DMolDisplay &disp, OE2DBondDisplay *bdisp,
const std::string &text, const OEFont &font)
Creates and interactive effect in .svg
images.
The given text will appear when the mouse is hovering
over the position defined by the given atom / bond display.
Note
This functionality is only available for .svg
image format. In other image formats it has no effect.
The generated svg
image should be included into and
HTML page with the SVG MIME type.
<object data="<imagename>.svg" type="image/svg+xml"></object>
See also
- disp
The OE2DMolDisplay object that holds the data necessary to depict the molecule with which it is initialized.
- adisp
The OE2DAtomDisplay object that defines where the text will appear.
- bdisp
The OE2DBondDisplay object that defines where the text will appear.
- text
The text that appears when the cursor is hovered over the given position.
- font
The graphical properties of the font used to draw the text.
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);
opts.SetMargins(10);
OE2DMolDisplay disp(mol, opts);
OEFont font(OEFontFamily::Default, OEFontStyle::Default, 12u, OEAlignment::Center, OEDarkRed);
for (OEIter<OE2DAtomDisplay> ai = disp.GetAtomDisplays(); ai; ++ai)
{
OE2DAtomDisplay* adisp = ai;
const OEAtomBase* atom = adisp->GetAtom();
const string hovertext = "atom idx=" + OENumberToString(atom->GetIdx());
OEDrawSVGHoverText(disp, adisp, hovertext, font);
}
OERenderMolecule("HoverAtomText.svg", disp);
Download code
hover mouse over any atoms
Example of using the OEDrawSVGHoverText function for atom positions
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);
opts.SetMargins(10);
OE2DMolDisplay disp(mol, opts);
OEFont font(OEFontFamily::Default, OEFontStyle::Default, 12u, OEAlignment::Center, OEDarkRed);
for (OEIter<OE2DBondDisplay> bi = disp.GetBondDisplays(); bi; ++bi)
{
OE2DBondDisplay* bdisp = bi;
const OEBondBase* bond = bdisp->GetBond();
const string hovertext = "bond idx=" + OENumberToString(bond->GetIdx());
OEDrawSVGHoverText(disp, bdisp, hovertext, font);
}
OERenderMolecule("HoverBondText.svg", disp);
Download code
hover mouse over the middle of any bonds
Example of using the OEDrawSVGHoverText function for bond positions
See also
OE2DMolDisplay class
OE2DAtomDisplay and OE2DBondDisplay classes
OEFont class
OEDrawSVGToggleText
function