#PB_Event_Repaint and CanvasGadget[Resolved]

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

#PB_Event_Repaint and CanvasGadget[Resolved]

Post 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
Last edited by collectordave on Sat Jan 28, 2017 8:34 am, edited 1 time in total.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: #PB_Event_Repaint and CanvasGadget

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: #PB_Event_Repaint and CanvasGadget

Post 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.
BERESHEIT
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: #PB_Event_Repaint and CanvasGadget[Resolved]

Post 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
Last edited by collectordave on Sat Jan 28, 2017 8:34 am, edited 1 time in total.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: #PB_Event_Repaint and CanvasGadget

Post by netmaestro »

Do you get repaint events while the size is happening? If so, you just found a use for it.
BERESHEIT
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: #PB_Event_Repaint and CanvasGadget

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: #PB_Event_Repaint and CanvasGadget

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: #PB_Event_Repaint and CanvasGadget

Post 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).
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: #PB_Event_Repaint and CanvasGadget

Post by collectordave »

Brilliant.

A resize event would be great!


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

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: #PB_Event_Repaint and CanvasGadget

Post by Fred »

Yes it will, no gadget needs to bother about repaint event
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: #PB_Event_Repaint and CanvasGadget

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply