Page 1 of 1

Scaling issue?

Posted: Tue Jun 10, 2025 7:44 pm
by tua
My goal is to have a custom window pop up over (in this case) a listicon upon right-click like a popup menu would - ideally with the same positioning.
The code below gets pretty close once I click in the top, left corner, but there's increasing drift when I move right and/or down over the listicon, suggesting I am having a scaling issue??

Can't figure it out. Any suggestion on how to achieve this are greatly appreciated!

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
  #Popup_Window
  #ListIcon
  #Popup_Text
EndEnumeration

Global Popup_Active.i = #False;, i

If OpenWindow(#MainWindow, 0, 0, 400, 300, "Right-click on listicon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ListIconGadget(#ListIcon, 10, 10, 380, 280, "Column 1", 100)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = #ListIcon And EventType() = #PB_EventType_RightClick

          ; Close previous popup if it's open
          If Popup_Active
            CloseWindow(#Popup_Window)
            Popup_Active = #False
          EndIf
          ; Calculate screen position based on mouse location in the window
          Define finalX.i = WindowX(#MainWindow) + WindowMouseX(#MainWindow)
          Define finalY.i = WindowY(#MainWindow) + WindowMouseY(#MainWindow)
          ; Create popup window at calculated position
          If OpenWindow(#Popup_Window, finalX, finalY, 150, 70, "", #PB_Window_BorderLess | #PB_Window_Tool)
            SetWindowColor(#Popup_Window, RGB(240, 240, 240))
            TextGadget(#Popup_Text, 10, 10, 130, 50, "Custom popup window")
            Popup_Active = #True
          EndIf
        EndIf
      Case #PB_Event_DeactivateWindow
        ; Close popup if it loses focus
        If Popup_Active And EventWindow() = #Popup_Window
          CloseWindow(#Popup_Window)
          Popup_Active = #False
        EndIf
      Case #PB_Event_CloseWindow
        If EventWindow() = #MainWindow
          Break
        EndIf
    EndSelect
  ForEver
EndIf

Re: Scaling issue?

Posted: Tue Jun 10, 2025 8:01 pm
by RASHAD
Hi

Code: Select all

EnableExplicit

Enumeration
  #MainWindow
  #Popup_Window
  #ListIcon
  #Popup_Text
EndEnumeration

Global Popup_Active.i = #False;, i
Global dpix.d,dpiy.d
dpix = DesktopResolutionX()
dpiy = DesktopResolutionY()


If OpenWindow(#MainWindow, 0, 0, 400, 300, "Right-click on listicon", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ListIconGadget(#ListIcon, 10, 10, 380, 280, "Column 1", 100)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = #ListIcon And EventType() = #PB_EventType_RightClick
          
          ; Close previous popup if it's open
          If Popup_Active
            CloseWindow(#Popup_Window)
            Popup_Active = #False
          EndIf
          ; Calculate screen position based on mouse location in the window
          Define finalX.i = DesktopMouseX()/dpix
          Define finalY.i = DesktopMouseY()/dpiy
          ; Create popup window at calculated position
          If OpenWindow(#Popup_Window, finalX, finalY, 150, 70, "", #PB_Window_BorderLess | #PB_Window_Tool)
            SetWindowColor(#Popup_Window, RGB(240, 240, 240))
            TextGadget(#Popup_Text, 10, 10, 130, 50, "Custom popup window")
            Popup_Active = #True
          EndIf
        EndIf
      Case #PB_Event_DeactivateWindow
        ; Close popup if it loses focus
        If Popup_Active And EventWindow() = #Popup_Window
          CloseWindow(#Popup_Window)
          Popup_Active = #False
        EndIf
      Case #PB_Event_CloseWindow
        If EventWindow() = #MainWindow
          Break
        EndIf
    EndSelect
  ForEver
EndIf


Re: Scaling issue?

Posted: Tue Jun 10, 2025 8:08 pm
by Andre
Nice example, thank RASHAD :D

Re: Scaling issue?

Posted: Tue Jun 10, 2025 8:10 pm
by RASHAD
You are welcome Andre :)

Re: Scaling issue?

Posted: Tue Jun 10, 2025 8:11 pm
by SMaag
I tested it. I do not see an increasing drift.

But to get the inner coordinates try the following

Code: Select all

Define finalX.i = WindowX(#MainWindow, #PB_Window_InnerCoordinate) + WindowMouseX(#MainWindow)
 Define finalY.i = WindowY(#MainWindow, #PB_Window_InnerCoordinate) + WindowMouseY(#MainWindow)

Re: Scaling issue?

Posted: Tue Jun 10, 2025 9:55 pm
by tua
Do you have your desktop scaled to 125% as I do (anything but 100%)?

Re: Scaling issue?

Posted: Tue Jun 10, 2025 9:57 pm
by tua
Thanks, Rashad - perfect!

Re: Scaling issue?

Posted: Tue Jun 10, 2025 10:06 pm
by RASHAD
You are welcome :D

Re: Scaling issue?

Posted: Wed Jun 11, 2025 10:30 pm
by minimy
Very nice example! Thanks for share! :D

Re: Scaling issue?

Posted: Thu Jun 12, 2025 4:16 pm
by Piero
#PB_Window_BorderLess seems to have issues on MacOS (PB 6.20)
Edit: Also 6.21