It is currently Mon Dec 10, 2018 12:50 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: [Done] Canvas gadget / #PB_EventType_Resize
PostPosted: Thu Aug 09, 2018 6:51 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10456
Location: Beyond the pale...
Purebasic 5.70 Beta 1x64. Ubuntu 18.04.

qt subsystem.

The following shows that when using a #PB_EventType_Resize bound event with a canvas gadget, the underlying bitmap has not been resized prior to the event procedure firing. GadgetWidth() and GadgetHeight() seem correct. We had a similar problem under Windows before PB 5.70 beta 1.

This problem can hide itself within the StartDrawing() bug reported previously since if we are drawing within the resize event procedure, the StartDrawing() can fail if the bitmap still has 0 width, for example, because of this resizing issue; and the StartDrawing() bug then kicks in. Two bugs for the price of one!

Run the code and resize the window.

Code:
Procedure winSize()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, 100, WindowHeight(0)-20)
EndProcedure

Procedure ResizeOne()
  If StartDrawing (CanvasOutput(0))
    Debug "Drawing output width = " + Str(OutputWidth()) + ", SHOULD BE 100!"
    Debug "Canvas gadget width = " + Str(GadgetWidth(0))
    Debug "Canvas gadget height = " + Str(GadgetHeight(0))
    StopDrawing()
    End 
  EndIf
 
EndProcedure


If OpenWindow(0, 0, 0, 220, 220, "Canvas example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  CanvasGadget(0, 10, 10, 50, 200)
 
  BindEvent(#PB_Event_SizeWindow, @winSize(), 0)
  BindGadgetEvent(0, @ResizeOne(), #PB_EventType_Resize)
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: Canvas gadget / #PB_EventType_Resize
PostPosted: Sun Sep 16, 2018 8:40 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13423
Location: France
Fixed.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Canvas gadget / #PB_EventType_Resize
PostPosted: Sun Nov 25, 2018 6:26 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10456
Location: Beyond the pale...
There is another problem with Canvas gadget and redrawing in response to event type resize (I think also reported by mk-soft).

The following should fill the canvas with red on resize.

Code:
Declare winSize()
Declare CanvasEventHandler()


If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 10, 220, 220)
  BindEvent(#PB_Event_SizeWindow, @winSize(), 0)
  BindGadgetEvent(0, @CanvasEventHandler(), #PB_EventType_Resize)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
 
 
Procedure winSize()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0))
EndProcedure

Procedure CanvasEventHandler()
  If StartDrawing(CanvasOutput(0))
    Box(0, 0, GadgetWidth(0), GadgetHeight(0), $FF)
    StopDrawing()
  EndIf
EndProcedure

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Done] Canvas gadget / #PB_EventType_Resize
PostPosted: Sun Nov 25, 2018 7:15 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1473
Location: Germany
Yes, is not Fixed

Link to Bugreport: viewtopic.php?f=23&t=71638


The problem is that the gadgets at the event resize are not yet valid data stored, and therefore the query of the sizes are not correct...
Only in the next event are the sizes valid.

Here's another code so you can see the error.
Code:
Declare winSize()
Declare CanvasEventHandler()


If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  CanvasGadget(0, 5, 5, 210, 210)
  BindEvent(#PB_Event_SizeWindow, @winSize(), 0)
  BindGadgetEvent(0, @CanvasEventHandler(), #PB_EventType_Resize)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

 
Procedure winSize()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0) - 10, WindowHeight(0) - 10)
  ;PostEvent(#PB_Event_Gadget, EventWindow(), 0, #PB_EventType_Resize, 2)
EndProcedure

Procedure CanvasEventHandler()
  Select EventType()
    Case #PB_EventType_Resize
      If EventData() = 2
        Debug "PostEvent Resize Data 2"
      Else
        Debug "PB Event Resize"
      EndIf
      If StartDrawing(CanvasOutput(0))
        Box(0, 0, GadgetWidth(0), GadgetHeight(0), $FF0000)
        StopDrawing()
      EndIf
   
  EndSelect
EndProcedure

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


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


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:  

 


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