Window output canvas

Just starting out? Need help? Post your questions and find answers here.
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 180
Joined: Thu Dec 28, 2023 9:04 pm

Window output canvas

Post by rndrei »

How to display canvas in a specific window?
WindowsOutput(#win) do not offer. It is canvas to be displayed in a certain window!

Code: Select all

   If StartDrawing(CanvasOutput(canvas))
      Box(10,10,200,200,#Black) 
      DrawText(25,  20, "Test canvas", #white, #black)
   StopDrawing()
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Window output canvas

Post by RASHAD »

You have to create first the Canvas Gadget

Code: Select all

	OpenWindow(?,?,?,?,?,"",flags)
	Canvas = CanvasGadget(#PB_Any,0,0,220,220)
	 If StartDrawing(CanvasOutput(canvas))
	 	DrawingMode(#PB_2DDrawing_Transparent)
      		Box(10,10,200,200,#Black) 
      		DrawText(25,  20, "Test canvas", #white, #black)
   	  	StopDrawing()
   	  endif
Egypt my love
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 180
Joined: Thu Dec 28, 2023 9:04 pm

Re: Window output canvas

Post by rndrei »

I have 2 windows, I have a canvas, how can I bring the canvas to a certain window?

Code: Select all

#window_1=10
#window_2=11
#canvas_1=12
OpenWindow(#WINDOW_1,0,0,250,250, "window 1", #PB_Window_WindowCentered)
OpenWindow(#WINDOW_2,300,300,250,250, "window 2", #PB_Window_WindowCentered)
CanvasGadget(#canvas_1, 0, 50,50 , 24)  
Repeat
Event_CS = WaitWindowEvent()
  If StartDrawing(CanvasOutput(#canvas_1))
     Box(50,50,100,200,#Black) 
     DrawText(35, 30, "Test canvas", #Red, #Yellow)
    StopDrawing()
  EndIf     
Until Event_CS = #PB_Event_CloseWindow
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 486
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Window output canvas

Post by Mindphazer »

Your Canvas is drawn on the last window created
UseGadgetList(WindowID) to select the window on which your canvas will be drawn
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
rndrei
Enthusiast
Enthusiast
Posts: 180
Joined: Thu Dec 28, 2023 9:04 pm

Re: Window output canvas

Post by rndrei »

work it! thank`s!
Post Reply