Re: Clearing a CanvasGadget
Posted: Thu Sep 19, 2019 8:49 am
You have to comment out the FillMemory() part to make the Box() part visible.
http://www.purebasic.com
https://www.purebasic.fr/english/
But the FillMemory part doesn't change the canvas to red.#NULL wrote:You have to comment out the FillMemory() part to make the Box() part visible.
Code: Select all
OpenWindow(0,0,0,600,600,"Test")
CanvasGadget(1,0,0,500,500)
StartDrawing(CanvasOutput(1))
time1_start=ElapsedMilliseconds()
For f=1 To 1000
Box(1,0,500,500, $ff0000ff)
Next f
time1_end=ElapsedMilliseconds()
While WindowEvent() : Wend
Delay(2000) ; To see the red
time2_start=ElapsedMilliseconds()
For f=1 To 1000
For y=0 To OutputHeight()-1
FillMemory(DrawingBuffer(), DrawingBufferPitch(), #Red)
Next
Next f
time2_end=ElapsedMilliseconds()
StopDrawing()
MessageRequester("",
"time1: "+Str(time1_end-time1_start) + #CRLF$ +
"time2: "+Str(time2_end-time2_start) )
quit=0
Repeat
event=WaitWindowEvent()
; User has pressed the close window gadget
If event=#PB_Event_CloseWindow
quit=1
EndIf
Until quit=1
End
The output is only done with StopDrawing()marcoagpinto wrote:What is wrong in my test code?
Code: Select all
OpenWindow(0,0,0,600,600,"Test")
CanvasGadget(1,0,0,500,500)
StartDrawing(CanvasOutput(1))
time1_start=ElapsedMilliseconds()
For f=1 To 1000
Box(1,0,500,500,#Red)
Next f
time1_end=ElapsedMilliseconds()
StopDrawing()
Delay(2000) ; To see the red
StartDrawing(CanvasOutput(1))
time2_start=ElapsedMilliseconds()
For f=1 To 1000
FillMemory(DrawingBuffer(), DrawingBufferPitch() * OutputHeight(), #Red)
Next f
time2_end=ElapsedMilliseconds()
StopDrawing()
Debug "time1: "+Str(time1_end-time1_start)
Debug "time2: "+Str(time2_end-time2_start)
quit=0
Repeat
event=WaitWindowEvent()
; User has pressed the close window gadget
If event=#PB_Event_CloseWindow
quit=1
EndIf
Until quit=1
End
This is already implemented and is called SetGadgetColor()marcoagpinto wrote:@Fred:
Could you implement a function in PB to clear a canvas?
ClearCanvasGadget(gadget, colour)
I don't know about Windows but on macOS SetGadgetColor is rather slow for clearing the canvas.Josh wrote:his is already implemented and is called SetGadgetColor()![]()
Look at my posting from 17.01.2019 20:47 in this thread.
Code: Select all
SetGadgetAttribute(CanvasGadget, #PB_Canvas_Image, ImageID(MyBackgroundImage))
Well,Josh wrote:This is already implemented and is called SetGadgetColor()marcoagpinto wrote:@Fred:
Could you implement a function in PB to clear a canvas?
ClearCanvasGadget(gadget, colour)![]()
Look at my posting from 17.01.2019 20:47 in this thread.
Code: Select all
StartDrawing(CanvasOutput(1))
time2_start=ElapsedMilliseconds()
For f=1 To 1000
DrawText(10,10,"TESTING",#Yellow,#White)
SetGadgetColor(1,#PB_Gadget_BackColor,#Blue)
SetGadgetColor(1,#PB_Gadget_FrontColor,#Blue)
ResizeGadget(1, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Next f
time2_end=ElapsedMilliseconds()
StopDrawing()
Don't use SetGadgetColor() inside StartDrawing/StopDrawingmarcoagpinto wrote:It doesn't work properly![]()
Code: Select all
OpenWindow(0,0,0,600,600,"Test")
CanvasGadget(1,0,0,500,500)
StartDrawing(CanvasOutput(1))
time1 = ElapsedMilliseconds()
For i = 1 To 1000
Box(1,0,500,500,#Red)
Next
time1 = ElapsedMilliseconds() - time1
StopDrawing()
MessageRequester ("", "")
StartDrawing(CanvasOutput(1))
time2 = ElapsedMilliseconds()
For i = 1 To 1000
FillMemory(DrawingBuffer(), DrawingBufferPitch() * OutputHeight(), #Red)
Next
time2 = ElapsedMilliseconds() - time2
StopDrawing()
MessageRequester ("", "")
SetGadgetColor (1, #PB_Gadget_BackColor, #Green)
time3 = ElapsedMilliseconds()
For i = 1 To 1000
ResizeGadget (1, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Next
time3 = ElapsedMilliseconds() - time3
MessageRequester ("", "")
SetGadgetColor (1, #PB_Gadget_BackColor, #Yellow)
StartDrawing(CanvasOutput(1))
time4 = ElapsedMilliseconds()
For i = 1 To 1000
Next
time4 = ElapsedMilliseconds() - time4
StopDrawing()
Debug "time1: " + time1
Debug "time2: " + time2
Debug "time3: " + time3
Debug "time4: " + time4
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Code: Select all
OpenWindow(0,0,0,600,600,"Test")
CanvasGadget(1,0,0,500,500)
time1 = ElapsedMilliseconds()
For i = 1 To 1000
StartDrawing(CanvasOutput(1))
DrawText(10,10,"TEST",#Yellow,#Blue)
Box(1,0,500,500,#Red)
StopDrawing()
Next
time1 = ElapsedMilliseconds() - time1
; MessageRequester ("", "")
time2 = ElapsedMilliseconds()
For i = 1 To 1000
StartDrawing(CanvasOutput(1))
DrawText(10,10,"TEST",#Yellow,#Blue)
FillMemory(DrawingBuffer(), DrawingBufferPitch() * OutputHeight(), #Red)
StopDrawing()
Next
time2 = ElapsedMilliseconds() - time2
; MessageRequester ("", "")
time3 = ElapsedMilliseconds()
For i = 1 To 1000
StartDrawing(CanvasOutput(1))
DrawText(10,10,"TEST",#Yellow,#Blue)
StopDrawing()
SetGadgetColor (1, #PB_Gadget_BackColor, #Green)
Next
time3 = ElapsedMilliseconds() - time3
Debug "time1: " + time1
Debug "time2: " + time2
Debug "time3: " + time3
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Can you explain why you are doing this?In my code I am drawing in the canvas and then want to clear it
Yes.#NULL wrote:Can you explain why you are doing this?In my code I am drawing in the canvas and then want to clear it