Scaling issue?

Just starting out? Need help? Post your questions and find answers here.
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

Scaling issue?

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: Scaling issue?

Post 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

Egypt my love
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Scaling issue?

Post by Andre »

Nice example, thank RASHAD :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: Scaling issue?

Post by RASHAD »

You are welcome Andre :)
Egypt my love
SMaag
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: Scaling issue?

Post 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)
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

Re: Scaling issue?

Post by tua »

Do you have your desktop scaled to 125% as I do (anything but 100%)?
tua
User
User
Posts: 68
Joined: Sun Jul 23, 2023 8:49 pm
Location: BC, Canada

Re: Scaling issue?

Post by tua »

Thanks, Rashad - perfect!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: Scaling issue?

Post by RASHAD »

You are welcome :D
Egypt my love
User avatar
minimy
Enthusiast
Enthusiast
Posts: 594
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Scaling issue?

Post by minimy »

Very nice example! Thanks for share! :D
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
Piero
Addict
Addict
Posts: 884
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Scaling issue?

Post by Piero »

#PB_Window_BorderLess seems to have issues on MacOS (PB 6.20)
Edit: Also 6.21
Post Reply