Trying to find the proper gadget for the job.

BlitzMax Forums/BlitzMax GUI Programming/Trying to find the proper gadget for the job.

Hello again.

Recdntly I've begun work on a drawing program tailored to my needs for sprite creation.

My question is what do I need to use for a drawing canvas? Naturally the canvas appeared to be the correct choice but everytime something gets on top of it it takes the image and ruins the drawing. What would you chaps do in this situation?

What are you putting on top of it? Do you mean you are drawing other gadget's on top of it? You shouldn't need to be doing this if you design the UI properly.

Please elaborate on exactly what you need the gadget to do...

' rendering a canvas using an EventHook based Applet Type

Strict

Type TApplet
	
	Field	window:TGadget
	Field	canvas:TGadget
	Field	timer:TTimer
	
	Method Render()
		Local x,y,width,height,t,i
		width=GraphicsWidth()
		height=GraphicsHeight()
		t=MilliSecs()
		SetBlend ALPHABLEND
		SetViewport 0,0,width,height
		SetClsColor 0,0,0
		SetOrigin width/2,height/2
		Cls
		For x=-width/2 To width/2 Step 2
			y=Sin(t*0.3+x)*height/2
			DrawLine 0,0,x,y
		Next
	End Method
	
	Method OnEvent(event:TEvent)
		Select event.id
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_TIMERTICK
			RedrawGadget canvas
		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			Render
			Flip
		End Select
	End Method

	Function eventhook:Object(id,data:Object,context:Object)
		Local	event:TEvent
		Local	app:TApplet
		event=TEvent(data)
		app=TApplet(context)
		app.OnEvent event	
	End Function
	
	Method Create:TApplet(name$)
		Local	a:TApplet
		Local	w,h
		window=CreateWindow(name,20,20,512,512)
		window.SetTarget Self
		w=ClientWidth(window)
		h=ClientHeight(window)
		canvas=CreateCanvas(0,0,w,h,window)
		canvas.SetLayout 1,1,1,1
		canvas.SetTarget Self		
		timer=CreateTimer(100)
		AddHook EmitEventHook,eventhook,Self
		Return Self		
	End Method
	
End Type

AutoMidHandle True

Local	applet:TApplet

applet=New TApplet.Create("Render Applet")

While True
	WaitEvent
Wend


Comes straight from the MaxGUI overview in tutorial section...really should read the docs...

Heh, that example doesn't even compile...

The trick is to parent the buttons to the canvas so windows knows you want them in front.

' rendering a canvas using an EventHook based Applet Type

Strict

Type TApplet
	
	Field	window:TGadget
	Field	canvas:TGadget
	Field button:TGadget
	Field	timer:TTimer
	
	Method Render()
		Local x,y,width,height,t,i
		width=GraphicsWidth()
		height=GraphicsHeight()
		t=MilliSecs()
		SetBlend ALPHABLEND
		SetViewport 0,0,width,height
		SetClsColor 0,0,0
		SetOrigin width/2,height/2
		Cls
		For x=-width/2 To width/2 Step 2
			y=Sin(t*0.3+x)*height/2
			DrawLine 0,0,x,y
		Next
	End Method
	
	Method OnEvent(event:TEvent)
		Select event.id
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_TIMERTICK
			RedrawGadget canvas
		Case EVENT_GADGETPAINT
			SetGraphics CanvasGraphics(canvas)
			Render
			Flip
		End Select
	End Method

	Function eventhook:Object(id,data:Object,context:Object)
		Local	event:TEvent
		Local	app:TApplet
		event=TEvent(data)
		app=TApplet(context)
		app.OnEvent event	
	End Function
	
	Method Create:TApplet(name$)
		Local	a:TApplet
		Local	w,h
		window=CreateWindow(name,20,20,512,512)
		button=CreateButton("Push Me",50,05,200,200,window)
		w=ClientWidth(window)
		h=ClientHeight(window)
		canvas=CreateCanvas(0,0,w,h,window)
		canvas.SetLayout 1,1,1,1
		timer=CreateTimer(100)
		AddHook EmitEventHook,eventhook,Self
		Return Self		
	End Method
	
End Type

AutoMidHandle True

Local	applet:TApplet

applet=New TApplet.Create("Render Applet")

While True
	WaitEvent
Wend



oops...my mistake :)