Page 1 of 1

CanvasGadget Container in a splitter

Posted: Mon May 08, 2017 5:02 am
by DoubleDutch
There are two bugs that occur on OSX with a CanvasGadget that has the #PB_Canvas_Container flag when the Canvas is in a Splitter.

First, the offset of the gadgets added to the Canvas is incorrect.

Second, the gadgets are clipped to the original size of the canvas (after it has been automatically resized by the splitter)

Neither of these two bugs occurs in Windows.

Here is some source code to demonstrate:

Code: Select all

If OpenWindow(0, 0, 0, 520, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
    CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 10, 10, 80, 30, "Clean up")

    CloseGadgetList()
    
    ButtonGadget(2,0,0,0,0,"other gadget") ; *** these two lines have been added to the standard demo to put the canvas inside a splitter
    SplitterGadget(3,0,0,520,220,0,2,#PB_Splitter_Vertical)
  
    Repeat
      Event = WaitWindowEvent()
    
      If Event = #PB_Event_Gadget
        Select EventGadget() 
          Case 0
            If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
              If StartDrawing(CanvasOutput(0))
                x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
                y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
                
                ResizeGadget(1,x,y,#PB_Ignore,#PB_Ignore)   ; *** this line has been added to show that the offset of the gadget is incorrect if inside a splitter
                             
                Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
                StopDrawing()
              EndIf
            EndIf
          
          Case 1
            If StartDrawing(CanvasOutput(0))
              Box(0, 0, 200, 200, #White)
              StopDrawing()
            EndIf
        EndSelect
      EndIf
    
    Until Event = #PB_Event_CloseWindow
  EndIf
First click in the Canvas - you will see that although the button gadget has been programmed to be at the same position as the cursor, instead it's offset is wrong (slightly shifted down & right). When it's not in a splitter it is correct (at the same position as the cursor).

Now draw and you should see the button moves with the cursor, draw to the right and you should see that although the canvas is extended because of the splitter, the button image is clipped to the original 'creation' size of the canvas.

In fact the canvas gadgets are clipped to the original size even if you use ResizeGadget, see:

Code: Select all

If OpenWindow(0, 0, 0, 520, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
    CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 10, 10, 80, 30, "Clean up")

    CloseGadgetList()
    
    ResizeGadget(0,#PB_Ignore,#PB_Ignore,500,#PB_Ignore) ; the canvas' gadgets will be clipped on a resize
  
    Repeat
      Event = WaitWindowEvent()
    
      If Event = #PB_Event_Gadget
        Select EventGadget() 
          Case 0
            If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
              If StartDrawing(CanvasOutput(0))
                x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
                y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
                
                ResizeGadget(1,x,y,#PB_Ignore,#PB_Ignore)   ; *** this line has been added to show that the offset of the gadget is incorrect if inside a splitter
                             
                Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
                StopDrawing()
              EndIf
            EndIf
          
          Case 1
            If StartDrawing(CanvasOutput(0))
              Box(0, 0, 200, 200, #White)
              StopDrawing()
            EndIf
        EndSelect
      EndIf
    
    Until Event = #PB_Event_CloseWindow
  EndIf
As mentioned, everything works perfectly in Windows, this just seems to affect OSX (not tested on Linux).

Re: CanvasGadget Container in a splitter

Posted: Mon May 08, 2017 5:31 am
by DoubleDutch
If I surround the canvas with a container then the offset problem seems to go away, this might be a clue as to what is happening?If

Code: Select all

OpenWindow(0, 0, 0, 520, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	
	ContainerGadget(4,0,0,200,300) ; *** add this to fix the offset issue?
    CanvasGadget(0, 0, 0, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 0, 0, 80, 30, "Clean up")

    CloseGadgetList()
  CloseGadgetList()
    
    ButtonGadget(2,0,0,0,0,"other gadget") ; *** these two lines have been added to the standard demo to put the canvas inside a splitter
    SplitterGadget(3,0,0,520,220,4,2,#PB_Splitter_Vertical)
  
    Repeat
      Event = WaitWindowEvent()
    
      If Event = #PB_Event_Gadget
        Select EventGadget() 
          Case 0
            If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
              If StartDrawing(CanvasOutput(0))
                x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
                y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
                
                ResizeGadget(1,x,y,#PB_Ignore,#PB_Ignore)   ; *** this line has been added to show that the offset of the gadget is incorrect if inside a splitter
                             
                Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
                StopDrawing()
              EndIf
            EndIf
          
          Case 1
            If StartDrawing(CanvasOutput(0))
              Box(0, 0, 200, 200, #White)
              StopDrawing()
            EndIf

          Case 4
          	If EventType()=#PB_EventType_Resize
;          		ResizeGadget(0,#PB_Ignore,#PB_Ignore,GadgetWidth(4),GadgetHeight(4)) ; *** offset issue comes back if you resize the canvas!  Uncomment this to see...
          	EndIf
        EndSelect
      EndIf
    
    Until Event = #PB_Event_CloseWindow
  EndIf

Re: CanvasGadget Container in a splitter

Posted: Mon May 08, 2017 5:40 am
by DoubleDutch
In the last example, with the resize line uncommented (so it will do the resize), change these lines from: ContainerGadget(4,0,0,200,300)

Code: Select all

ContainerGadget(4,0,0,200,300)
    CanvasGadget(0, 0, 0, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 0, 0, 80, 30, "Clean up")

    CloseGadgetList()
CloseGadgetList()
to

Code: Select all

ContainerGadget(4,0,0,200,300)
    CanvasGadget(0, 0, 0, 200, 300, #PB_Canvas_Container)
    ButtonGadget(1, 0, 0, 80, 30, "Clean up")

    CloseGadgetList()
  CloseGadgetList()
For a negative offset on the gadgets!

Re: CanvasGadget Container in a splitter

Posted: Wed Aug 09, 2017 3:36 pm
by Fred
I don't see the issues here, can anybody else confirm ?

Re: CanvasGadget Container in a splitter

Posted: Wed Aug 09, 2017 6:44 pm
by DoubleDutch
Can you not see it?

Re: CanvasGadget Container in a splitter

Posted: Wed Aug 09, 2017 7:10 pm
by mk-soft
The mouse position from canvas gadget not right

Code: Select all

                x = GetGadgetAttribute(0, #PB_Canvas_MouseX) - 2 ; Offset correction
                y = GetGadgetAttribute(0, #PB_Canvas_MouseY) - 2 ; Offset correction
                Debug x
                

Re: CanvasGadget Container in a splitter

Posted: Thu Aug 10, 2017 4:27 am
by DoubleDutch
Is this my fault or pb ?

Re: CanvasGadget Container in a splitter

Posted: Thu Aug 10, 2017 9:25 am
by Fred
It seems right here (i can use the whole canvas)

Re: CanvasGadget Container in a splitter

Posted: Thu Aug 10, 2017 2:22 pm
by DoubleDutch
Maybe it depends on the OS version? I was using the latest OSX, also mk-soft appears to notice the problem too.

Re: CanvasGadget Container in a splitter

Posted: Thu Aug 10, 2017 5:20 pm
by mk-soft
I thing MacOS...

Same problem with DesktopMouseXY.

The actual mouse position is the blank mouse cursor without the white border.

Hardware: Mac-Mini Late 2012 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
Monitor: Benq GL2460
MacOS: 10.12.6

Re: CanvasGadget Container in a splitter

Posted: Thu Nov 02, 2023 10:16 am
by Fred
I don't want to offset the cursor as it's the black arrow which count, not the white border and i you set another cursor it will be wrong. The button is offseted becaus it gots transparent borders. Try with a ListViewGadget() and it will be right.