It is currently Thu Dec 12, 2019 5:06 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Done] Canvas Container and ResizeGadget (Workaround)
PostPosted: Wed Aug 22, 2018 12:48 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2059
Location: Germany
The position Y of gadgets in the canvas gadget container are not calculated correctly.

PB Version >= v5.60
MacOS 10.13.6
Code:
;-TOP

Procedure SizeWindow()
  Debug "1. PosY: " + GadgetY(1)
  ResizeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
  Debug "2. PosY: " + GadgetY(1)
EndProcedure

If OpenWindow(0, 0, 0, 220, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
 
  CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container)
  ButtonGadget(1, 10, 10, 80, 30, "Button")
  CloseGadgetList()
 
  BindEvent(#PB_Event_SizeWindow, @SizeWindow(), 0)
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
 
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Wed Aug 22, 2018 11:18 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget
PostPosted: Wed Aug 22, 2018 5:13 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2059
Location: Germany
Problem found!
Is forget resize gadget container (subview) from canvas gadget...

Workaround Update v0.6
Code:
;-TOP

; Workaround MacOS PB v5.60 - v5.62. Canvas Gadget Container Bugfix

; Link https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269

; -----------------------------------------------------------------------------

DeclareModule __Workaround
  Declare FixResizeGadget(Gadget, x, y, width, height)
EndDeclareModule

Module __Workaround
  Procedure FixResizeGadget(Gadget, x, y, width, height)
    ResizeGadget(Gadget, x, y, width, height)
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      ; Bugfix gadget container from canvasgadget
      Protected rect.NSRect, sv, container
      If GadgetType(Gadget) <> #PB_GadgetType_Canvas
        ProcedureReturn 1
      EndIf
      sv = CocoaMessage(0, GadgetID(Gadget), "subviews")
      If CocoaMessage(0, sv, "count")
        container = CocoaMessage(0, sv, "objectAtIndex:", 0)
        If container
          CocoaMessage(@rect, GadgetID(Gadget), "frame")
          rect\origin\x = 0
          rect\origin\y = 0
          CocoaMessage(0, container, "setFrame:@", @rect)
        EndIf
      EndIf
    CompilerEndIf
  EndProcedure
EndModule

DeclareModule Workaround
  CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
    Macro ResizeGadget(Gadget, x, y, width, height)
      __Workaround::FixResizeGadget(Gadget, x, y, width, height)
    EndMacro
  CompilerEndIf
EndDeclareModule

Module Workaround
EndModule

; -----------------------------------------------------------------------------

CompilerIf #PB_Compiler_IsMainFile
 
  UseModule Workaround
 
  Procedure SizeWindow()
    ResizeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
    StartDrawing(CanvasOutput(0))
    Box(2, 2, GadgetWidth(0) - 4, GadgetHeight(0) - 4, $B48246)
    StopDrawing()
  EndProcedure
 
  Define Event
 
  If OpenWindow(0, 0, 0, 220, 220, "Canvas Container Workaround", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
   
    CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container)
    ButtonGadget(1, 10, 10, 80, 30, "Button")
    CloseGadgetList()
   
    StartDrawing(CanvasOutput(0))
    Box(2, 2, GadgetWidth(0) - 4, GadgetHeight(0) - 4, $B48246)
    StopDrawing()
 
    BindEvent(#PB_Event_SizeWindow, @SizeWindow(), 0)
   
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
   
  EndIf
 
CompilerEndIf


How to get subViews from CanvasGadget

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Thu Aug 23, 2018 1:42 pm, edited 7 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget
PostPosted: Wed Aug 22, 2018 7:17 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3545
Location: Netherlands
mk-soft wrote:
How to get subViews from CanvasGadget

Off course there's no guarantee PB internals will stay the same but at the moment

PB_CanvasView contains
PB_NSFlippedView contains
PBButtonGadgetView

So it's the subviews of the subview you are looking for.

Code:
Procedure.i GetSubviews(View, Array Subviews.i(1))
  Protected sv = CocoaMessage(0, View, "subviews")
  Protected r.NSRange\length = CocoaMessage(0, sv, "count")
  If r\length
    ReDim Subviews(r\length - 1)
    CocoaMessage(0, sv, "getObjects:", @Subviews(0), "range:@", @r)
  EndIf
  ProcedureReturn r\length
EndProcedure




If OpenWindow(0, 0, 0, 220, 220, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
 
  CanvasGadget(0, 10, 10, 200, 200, #PB_Canvas_Container)
  ButtonGadget(1, 10, 10, 80, 30, "Button 1")
  ButtonGadget(2, 10, 40, 80, 30, "Button 2")
  CloseGadgetList()
 
  Dim Subviews.i(0)
 
  Count = GetSubviews(GadgetID(0), Subviews()); Count = 1
  Count = GetSubviews(Subviews(0), Subviews()); Count = 2 (Button 1 & 2)
 
  For i = 0 To Count - 1
    Debug Subviews(i); Output equal to GadgetID(1) and GadgetID(2)
  Next 
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
 
EndIf

_________________
macOS 10.15 Catalina, PB 5.71 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget
PostPosted: Wed Aug 22, 2018 8:36 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2059
Location: Germany
Thanks you, wilbert

I have optimize the workaround.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget (Workaround)
PostPosted: Thu Aug 23, 2018 11:20 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2059
Location: Germany
Workaround Update v0.4

Now as module for use inside modules...

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget (Workaround)
PostPosted: Tue Sep 25, 2018 6:19 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2059
Location: Germany
Remember

There's still time, but please don't forget :wink:

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas Container and ResizeGadget (Workaround)
PostPosted: Fri Apr 12, 2019 4:31 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13659
Location: France
Fixed. Thanks for the fix !


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye