Page 1 of 1

#PB_Event_Repaint and CanvasGadget[Resolved]

Posted: Tue Dec 20, 2016 8:34 am
by collectordave
Noticed in the Help file that #PB_Event_Repaint is shown with Canvasgadget as well as windows.

How do i use this get this event for the canvas gadget?

Regards

cd

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 8:40 am
by Fred
In the doc:

Code: Select all

There is no need to redraw the content every time a #PB_Event_Repaint event is receive
Is the sentence not explicit ? We could remove it anyway, as the repaint event (which is only applicate on a window) is almost never useful.

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 8:54 am
by netmaestro
It's a child window that maintains its own drawing without further intervention from the programmer. #PB_Event_Repaint is redundant here, could be removed without anyone noticing. You can ignore it in the secure knowledge that using it wouldn't gain you anything useful.

Re: #PB_Event_Repaint and CanvasGadget[Resolved]

Posted: Tue Dec 20, 2016 9:12 am
by collectordave
Hi
In the doc:

Code:
There is no need to redraw the content every time a #PB_Event_Repaint event is receive


Is the sentence not explicit ? We could remove it anyway, as the repaint event (which is only applicate on a window) is almost never useful.
The sentence is quite explicit and I do realise there is no need to redraw the contents of a canvas gadegt everytime. However there are times when it is desirable to repaint a canvas gadget.

In the following example all I want is for a circle to be drawn in the middle of the canvas gadget even after a resize event nothing more.

Code: Select all

;PB 5.6 Beta Only!

#PB_EventType_Resize = 6

Procedure DoDrawing()
  
  ;Clear Grid Canvas gadget
  Define ClearImg.i
  ClearImg = CreateImage(#PB_Any,700,400,32,RGB(255,255,255))
  SetGadgetAttribute(10,#PB_Canvas_Image,ImageID(ClearImg))    
  FreeImage(ClearImg)
    
  If StartVectorDrawing(CanvasVectorOutput(10))

    AddPathCircle(GadgetWidth(10)/2,GadgetHeight(10)/2, 75)
     
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(10)
   
    StopVectorDrawing()
    
  EndIf
 
 EndProcedure

If OpenWindow(0, 0, 0, 600, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(10, 0, 0, 400, 200)
    ButtonGadget(11, 220, 270, 90, 50, "")
    DoDrawing()
   
    Repeat
      Event = WaitWindowEvent()
        Select event
           
          Case #PB_Event_Gadget
            Select EventGadget()
              Case 11
                ResizeGadget(10,0,0,450,250)
                
              Case 10
                If EventType() = #PB_EventType_Resize
                  DoDrawing()
                EndIf
                
            EndSelect
           
     EndSelect
     
    Until Event = #PB_Event_CloseWindow
  EndIf
However when the button is clicked the canvas gadget changes but no resize event for the canvas gadget so the circle is then off centre.

So the question is still there how do i use the repaint event on a canvas gadget?

Update for PB 5.6

Resize added and code updated so all works fine now.
cd




Regards

cd

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 9:14 am
by netmaestro
Do you get repaint events while the size is happening? If so, you just found a use for it.

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 9:21 am
by collectordave
Hi

Running my example above you get repaint events while moving the mouse over the button but no over the Canvas it would appear.

There is also no repaint event for the window when the canvas is resized.

cd

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 9:46 am
by collectordave
The main use for this would be for Custom Gadgets based around the canvas gadget where resizing the canvas gadget makes the display of the custom gadget change. One example would be a custom grid gadget where the grid is drawn at programme start to the original size and then the user resizes the window and the programme resizes the canvas gadget\custom gadget to fit. The repaint event for the gadget would then be under the control of the programmer who can choose to redraw the content or not depending on the programme and time taken to redraw.

cd

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 9:50 am
by Fred
there is no repaint event on the canvas, what you miss is a resizeevent, then you can redraw the canvas (will be added in next version).

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 10:04 am
by collectordave
Brilliant.

A resize event would be great!


Should the link between repaint and canvas be removed from the docs?

Regards

cd

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 10:16 am
by Fred
Yes it will, no gadget needs to bother about repaint event

Re: #PB_Event_Repaint and CanvasGadget

Posted: Tue Dec 20, 2016 10:55 am
by collectordave
This is probably just a bit cheeky so apologies.

I have noticed that some custom gadgets use normal gadgets in their construction. All works fine Bindevent() etc do their job very well. It is just that the position of these controls depends on the position of the underlying canvas gadget so could the event be fired for move as well as resize? Or is that just a waste of time?

Regards

cd