Buttons on Canvas don't work

Archives Forums/MacOS X Discussion/Buttons on Canvas don't work

Nigel Brown(Posted 2006) [#1]
My application attaches a canvas to the main window and then adds buttons, listbox... to the canvas. On the PC all works well the buttons appear ontop of the canvas and I get an image the background of my window.

When I rune the same program under MacOS I get the nice image on my window but no buttons or listbox? If I don't create the canvas and attach the buttons to the window itself all is well. But the look and feel is not how I want it!

Is this a BUG under MacOS? Or can you just not attach buttons and other widgets to canvas's under OSX?


SebHoll(Posted 2006) [#2]
This is probably more of a bug on Windows part, as you shouldn't be able to parent gadgets to a graphics canvas.

It seems Mac checks to make sure this doesn't happen but the Windows API doesn't and lets you parent almost any GUI control to anything else.


kfprimm(Posted 2006) [#3]
A canvas is just a panel which gives it's handle to DirectX/OpenGL to get the hDC, hRC, and all that good stuff. It's not a Windows bug.


Nigel Brown(Posted 2006) [#4]
Does this mean it's an OSX bug? Seb, When you say Mac checks to make sure this doesn't happen have you looked at the source?

I will leave this until Monday and then report it as a bug for not being cross platform!


Brucey(Posted 2006) [#5]
I would guess that a panel is a parent for containing child gadgets and a canvas is a 2d/3d context for drawing stuff.

If you just want an image (as a background, for example) you can do that with SetPanelPixmap().


Nigel Brown(Posted 2006) [#6]
Brucey, great tip I have been working with this today and managed to get buttons ontop of a panel with a background that I can render to. Only a couple of problems one seems to be with the GLMax2DDriver() the other I'm not sure about? Both problems have been commented out so should work on both PC and Mac as is. Mac cannot render to a canvas that is attached to a hidden window with the GLMax2DDriver either on PC or Mac.


SuperStrict

Local mywindow:Tgadget=CreateWindow("example",400,200,320,240)
Local mypanel:Tgadget=CreatePanel(0,0,320,240,mywindow) ; SetGadgetLayout(mypanel, 1, 0, 1, 0 )
Local mycanvas_window:TGadget = CreateWindow( "",0,0,320,240,Null,WINDOW_CLIENTCOORDS )'| WINDOW_HIDDEN )
Local mycanvas:TGadget=CreateCanvas(0,0,320,240,mycanvas_window) ; SetGadgetLayout(mycanvas, 1, 0, 1, 0 )
Local background:TImage=LoadImage(AppDir + "/resources/background1.jpg")
Local imagebuffer:TImage=CreateImage(320,240,1,DYNAMICIMAGE|MASKEDIMAGE)

Local button:TGadget=CreateButton("HELP",110,30,64,24,mypanel,BUTTON_CANCEL)

?Win32	SetGraphicsDriver BufferedD3D7Max2DDriver()
'?Win32	SetGraphicsDriver D3D7Max2DDriver()
?MacOs	SetGraphicsDriver GLMax2DDriver()
?
SetGraphics( CanvasGraphics(mycanvas) )
SetBlend(ALPHABLEND)
SetAlpha(1.0)

Local verdana:TImageFont = LoadImageFont( AppDir + "/resources/vera.ttf", 24, SMOOTHFONT )
SetImageFont verdana

CreateTimer(20)

Repeat 

	Select WaitEvent()

		Case EVENT_WINDOWCLOSE
			End
			
		Case EVENT_TIMERTICK

			SetGraphics( CanvasGraphics(mycanvas) )
			DrawImage(background,0,0)
'			SetColor(0,0,0)
			DrawText("HELP ME",0,0 )
			
			GrabImage(imagebuffer,0,0)
			SetPanelPixmap(mypanel, LockImage(imagebuffer))
			UnlockImage(imagebuffer)
	End Select

Forever



Rook Zimbabwe(Posted 2006) [#7]
This is probably more of a bug on Windows part, as you shouldn't be able to parent gadgets to a graphics canvas.



It's not a bug... it is a feature!!!

:)

Seriously are you strict or superstrict?


Rook Zimbabwe(Posted 2006) [#8]
This is probably more of a bug on Windows part, as you shouldn't be able to parent gadgets to a graphics canvas.



It's not a bug... it is a feature!!!

:)

Seriously are you strict or superstrict?