Recent

Author Topic: Get Element ID from Click  (Read 4572 times)

yodamiit

  • Newbie
  • Posts: 1
Get Element ID from Click
« on: November 08, 2023, 01:56:33 pm »
Hi all!
I'm using TBCSVGViewer to show SVG image.
Maybe there is some way to Get SVG Element ID which was clicked?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8579
Re: Get Element ID from Click
« Reply #1 on: November 08, 2023, 09:13:18 pm »
Noting that you're a new member of the forum and welcome :-)

I suspect that the lack of response is not because people aren't interested, but because you're the local expert in this field.

From experience with things like Inkscape (and predecessor software over many years), I'd suggest that the obvious problem with SVG is that once you've got a fully-rendered image it can be very difficult to detect what's actually been clicked. A useful approach might be to first find a way to present the elements in sequence: either in the order presented in the file or by trying to work out which elements occlude others.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Get Element ID from Click
« Reply #2 on: November 09, 2023, 11:08:42 pm »
Hello yodamiit,

Your question is clear. What would be convenient for you is a function in TBCSVGViewer component to detect which SVG element is at a certain position. This component relies on TBGRASVG class of BGRABitmap, which does not have this feature yet.

One way to implement such feature would be to implement something similar as the recursive Draw functions, except that instead of rendering the elements, it would check if a point is in the current shape. This is not trivial to implement, in particular when it comes to checking for each individual SVG shape. One way to avoid having to rewrite the InternalDraw methods would be to mock the TBGRACanvas2D objet to replace the drawing functions by the checking functions and pass this mock object as a parameter of the InternalDraw methods of the SVG shapes.

Regards
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018