Page 1 of 1
Multiple StartDrawing()/StopDrawing
Posted: Fri Aug 17, 2018 6:40 pm
by DK_PETER
StartDrawing(TextureOutput(Texture))
StopDrawing(TextureOutPut(Texture))
StartDrawing(ImageOutput(Image))
StopDrawing(ImageOutput(Image))
StartDrawing(CanvasOutput(ID))
StopDrawing(CanvasOutput(ID))
etc...
Except from ScreenOutput(), it should be doable...I think.
Don't know how much work it would require, though.
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 12:35 am
by Michael Vogel
Do you mean, something like this...
Code: Select all
StartDrawing(TextureOutput(Texture))
StartDrawing(ImageOutput(Image))
dc=StartDrawing(CanvasOutput(ID))
StopDrawing(TextureOutPut(Texture))
StopDrawing(ImageOutput(Image))
StopDrawing(CanvasOutput(ID))
...should be allowed?
I would like it, but it would need to change all drawing commands adding a referer parameter, e.g. Box(dc,x,y,w,h)
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 6:58 am
by DK_PETER
Yes. Right now we have a single StopDrawing() for all outputs.
(Screen, Sprite, Texture, Image, Canvas, Printer and Window)
Being able to do multiple outputs at the same time would be
a big leap forward.
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 8:37 am
by STARGÅTE
DK_PETER wrote:Being able to do multiple outputs at the same time would bea big leap forward.
It is already implemented:
PureBasic Help wrote:If "Create thread-safe executable" is enabled in the compiler options then every thread has its own current drawing output, which means two threads can do drawing on separate outputs at the same time.
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 8:57 am
by DK_PETER
@StarGate
Here's an example of what I would like to be able to do.
Code: Select all
Declare.i InsertImage()
OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 100
For x = 0 To 4 Step 100
DrawImage(ImageID(InsertImage()), x * 100, y * 100)
Next x
Next y
StopDrawing()
Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow
Procedure.i InsertImage()
Protected im = CreateImage(#PB_Any, 100, 100)
StartDrawing(ImageOutput(im))
Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
StopDrawing()
ProcedureReturn im
EndProcedure
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 9:12 am
by #NULL
maybe something like this:
(tested on linux)
Code: Select all
; enable threadsafe!
Procedure getImage(*p.Integer)
Protected im = CreateImage(#PB_Any, 100, 100)
StartDrawing(ImageOutput(im))
Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
StopDrawing()
*p\i = im
EndProcedure
Procedure.i InsertImage()
Protected im, t
t = CreateThread(@ getImage(), @ im)
WaitThread(t)
ProcedureReturn im
EndProcedure
OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 100
For x = 0 To 4 Step 100
DrawImage(ImageID(InsertImage()), x * 100, y * 100)
Next x
Next y
StopDrawing()
Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 9:15 am
by STARGÅTE
@Null, I was to slow ^^, looks very similar
Code: Select all
CompilerIf Not #PB_Compiler_Thread
MessageRequester("", "Enable Create thread-safe executable")
End
CompilerEndIf
Declare.i InsertImage()
OpenWindow(0, 0, 0, 800, 800, "Test", #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 500, 500)
StartDrawing(CanvasOutput(0))
For y = 0 To 4 Step 1
For x = 0 To 4 Step 1
DrawImage(ImageID(InsertImage()), x * 100, y * 100)
Next x
Next y
StopDrawing()
Repeat : ev = WindowEvent() : Until ev = #PB_Event_CloseWindow
Procedure.i InsertImageThread(*Image.Integer)
Protected im = CreateImage(#PB_Any, 100, 100)
StartDrawing(ImageOutput(im))
Box(0,0, 100, 100, RGB(Random(255), Random(255), Random(255)))
StopDrawing()
*Image\i = im
EndProcedure
Procedure.i InsertImage()
Protected Image.i
WaitThread(CreateThread(@InsertImageThread(), @Image))
ProcedureReturn Image
EndProcedure
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 9:28 am
by Michael Vogel
Not sure if a something like PushDrawingState() and PopDrawingState() could be useful to allow something like the example above without using threads.
Code: Select all
Procedure ImageFx(image)
state=#False
PushDrawingState()
If StartDrawing(ImageOutput(image))
;...
StopDrawing()
state=#True
EndIf
PopDrawingState()
ProcedureReturn state
EndProcedure
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 9:30 am
by DK_PETER
@Null And @Stargate
I do think, that my idea would be the best way, if possible.
Anyway, thank you both for a nice alternative solution - I didn't think of that.
Re: Multiple StartDrawing()/StopDrawing
Posted: Sat Aug 18, 2018 9:31 am
by #NULL
STARGÅTE wrote:@Null, I was to slow ^^, looks very similar

At least you used a proper threadsafe check instead of my lazy comment
