coordinates of text

Everything else that doesn't fall into one of the other PB categories.
k3pto
User
User
Posts: 87
Joined: Sat Jan 17, 2015 5:24 pm

coordinates of text

Post 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.
Last edited by k3pto on Sun Mar 30, 2025 9:18 pm, edited 1 time in total.
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: coordinates of text

Post by Piero »

I wonder if you mean in 3D…
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: coordinates of text

Post 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.
bye,
Daniel
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: coordinates of text

Post 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
▓▓▓▓▓▒▒▒▒▒░░░░░
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: coordinates of text

Post 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)
Post Reply