Page 1 of 1
coordinates of text
Posted: Sun Mar 23, 2025 10:52 pm
by k3pto
Is there a way to get the x and y coordinates of individual lines of text within a gadget?
Just 2D in Windows. I want to determine on which entry within a list box the user did a right-click without having to select it first with a left-click.
Re: coordinates of text
Posted: Fri Mar 28, 2025 4:08 pm
by Piero
I wonder if you mean in 3D…
Re: coordinates of text
Posted: Sat Mar 29, 2025 7:41 am
by DarkDragon
k3pto wrote: Sun Mar 23, 2025 10:52 pm
Is there a way to get the x and y coordinates of individual lines of text within a gadget?
Which OS? This will be highly OS specific.
Re: coordinates of text
Posted: Fri Apr 04, 2025 9:19 pm
by Nituvious
I'm not sure how you could get text width in purebasic but y is pretty simple. It's just font size. If you want to get the height of multiple lines then it's just font size multiplied by the number of new lines in your string
Re: coordinates of text
Posted: Sat Apr 05, 2025 8:16 am
by firace
Try this out:
(heavily based on old code by Rashad!)
Code: Select all
Procedure WndProc(hWnd, uMsg, wParam, lParam)
itemh = SendMessage_(GadgetID(6), #LB_GETITEMHEIGHT, 0, 0)
Select uMsg
Case #WM_CONTEXTMENU
Select wParam
Case GadgetID(6)
GetCursorPos_(p.POINT)
ScreenToClient_ (GadgetID(6), @p)
Debug "x: " + p\x
Debug "y: " + p\y
index = Int(p\y/itemh)
Debug "Gadget 6 Item "+Str(index)
EndSelect
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow( 0, 0, 0, 620, 510, "TEST", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
ListViewGadget( 6, 20, 90, 280, 260, #PB_ListView_MultiSelect )
For x = 0 To 4
AddGadgetItem(6, -1, "TEST")
Next
SetWindowCallback(@WndProc())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
SetWindowCallback(0)