Attaching objects to tabbers and updating.

BlitzMax Forums/BlitzMax GUI Programming/Attaching objects to tabbers and updating.

Recently I have needed to create a small pop up with tabbers. My problem is attaching individual gadgets to each tabber page and then updating them.

I've read the maxGUI tutorials on Tabbers and the author does not offer a way to create each tabber with their own attached Tgadgets.

Here is my current code, I need a special canvas for each tabber page or perhaps one canvas object that works between the three pages. How do I check which tab is down and update accordingly?

' GUI application to adjust RGB levels of a photograph
Strict

Global start_x:Float = 320
Global start_y:Float = 240

' a simple spline type

Function spline_f:Float(p:Float, p1:Float, p2:Float, t:Float) 
	Local a:Float = (1 - t) 
	Return (a ^ 2.0 * p) + (2.0 * t * a * p1) + (t ^ 2 * p2) 
End Function

Function draw_spline(x:Float, y:Float, x2:Float, y2:Float, x3:Float, y3:Float, divisions:Float) 
	
End Function

' create the window and tabbers
Local MyWindow:TGadget = CreateWindow("Color Curves", 320, 320, 312, 324, Null, 1) 
Local Tabber:TGadget = CreateTabber(0, 0, 312, 300, MyWindow) 
' make some canvases (canvi?) to house the Red,Green, and Blue curve drawings respectivly
Local red_canvas:TGadget = CreateCanvas(12, 12, 255, 255, tabber) 
red_canvas.SetColor(0, 0, 0) 

Local green_canvas:TGadget = CreateCanvas(12, 12, 255, 255, tabber) 
green_canvas.SetColor(0, 0, 0) 

Local blue_canvas:TGadget = CreateCanvas(12, 12, 255, 255, tabber) 
blue_canvas.SetColor(255, 255, 255) 

' create tabs
AddGadgetItem(Tabber, "Red Curve", 0, 0, "Adjust red levels.") 
AddGadgetItem (Tabber, "Green Curve", 0, 0, "Adjust green levels.") 
AddGadgetItem (Tabber, "Blue Curve", 0, 0, "Adjust blue levels.") 


Repeat
	WaitEvent() 
	Select EventID() 
		Case EVENT_WINDOWCLOSE
     	End
	
		Case EVENT_GADGETPAINT
		
    			SetGraphics CanvasGraphics (red_canvas) 
			SetColor(255, 0, 0) 
    			DrawText("Red Canvas", 0, 0) 
			Flip
			
			SetGraphics CanvasGraphics (green_canvas) 
			SetColor(0, 255, 0) 
    			DrawText("Green Canvas", 0, 0) 
			Flip
			
			SetGraphics CanvasGraphics (blue_canvas) 
			SetColor(0, 0, 255) 
    			DrawText("Blue Canvas", 0, 0) 
			Flip
	
   End Select
Forever


you only really need one canvas. I hope this helps you understand it better:
' GUI application to adjust RGB levels of a photograph
Strict

Global start_x:Float = 320
Global start_y:Float = 240

' a simple spline type
Function spline_f:Float(p:Float, p1:Float, p2:Float, t:Float) 
	Local a:Float = (1 - t) 
	Return (a ^ 2.0 * p) + (2.0 * t * a * p1) + (t ^ 2 * p2) 
End Function

Function draw_spline(x:Float, y:Float, x2:Float, y2:Float, x3:Float, y3:Float, divisions:Float) 
	
End Function

' create the window and tabbers
Local MyWindow:TGadget = CreateWindow("Color Curves", 320, 320, 312, 324, Null, 1) 
Local Tabber:TGadget = CreateTabber(0, 0, 312, 300, MyWindow)
' make some canvases (canvi?) to house the Red,Green, and Blue curve drawings respectivly
Local canvas:TGadget = CreateCanvas(12, 12, 255, 255, tabber) 
' create tabs
AddGadgetItem(Tabber, "Red Curve", 0, 0, "Adjust red levels.") 
AddGadgetItem (Tabber, "Green Curve", 0, 0, "Adjust green levels.") 
AddGadgetItem (Tabber, "Blue Curve", 0, 0, "Adjust blue levels.")
SelectGadgetItem tabber,0 
Global grfx:tgraphics = CanvasGraphics(canvas)
SetGraphics grfx 
Global text$ = "Red Canvas"
Global r% = 255,g%=0,b%=0
CreateTimer 60
Global index% = 0

Repeat
	WaitEvent() 

	Select EventID() 
		Case EVENT_WINDOWCLOSE
     	End
	
		Case EVENT_TIMERTICK
			RedrawGadget canvas
		Case EVENT_GADGETPAINT
			Cls
			SetColor r,g,b
			DrawText text,0,0
			Flip()
		Case EVENT_GADGETACTION
			Select EventData()
    			Case 0
					r = 255
					g = 0
					b = 0 
    				text = "Red Canvas" 
				Case 1
					r = 0
					g = 255
					b = 0 
    				text = "Green Canvas"
				Case 2
					r = 0
					g = 0
					b = 255 
    				text = "Blue Canvas"
			End Select
   End Select
Forever

having more than one canvas is a waste of resources. Or maybe it's cause I don't know how to do it that way :-).

You can have different canvas for each tabs...
I used the basic example that comes with MaxGUI
' createtabber.bmx
Import MaxGui.Drivers
Strict 
Local window:TGadget
Local tabber:TGadget
Local document:TGadget[3],pa:tgadget[3]
Local currentdocument:TGadget

' CreateDocument creates a hidden panel that fills entire tabber client area 

Function CreateDocument:TGadget(tabber:TGadget)
	Local	panel:TGadget
	panel=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
	SetGadgetLayout panel,1,1,1,1
	HideGadget panel
	Return panel
End Function

' create a default window with a tabber gadget that fills entire client area

window=CreateWindow("My Window",30,20,400,300)

tabber=CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1 

' add three items and corresponding document panels to the tabber

AddGadgetItem tabber,"Document 0",False,-1,""
AddGadgetItem tabber,"Document 1",False,-1,"Tabber Tip 1"
AddGadgetItem tabber,"Document 2",False,-1,"tips 4 2"

document[0]=CreateDocument(tabber)
document[1]=CreateDocument(tabber)
document[2]=CreateDocument(tabber)

SetPanelColor document[0],255,200,200
SetPanelColor document[1],200,255,200
SetPanelColor document[2] , 200 , 200 , 255

'to keep track of the canvases associated each to one tab (document[])


pa[0]=CreateCanvas(10 , 10 , 100 , 100 , document[0])
pa[1]=CreateCanvas(10 , 10 , 200 , 100 , document[1])
pa[2]=CreateCanvas(10 , 10 , 100 , 200 , document[2])


' our documents start off hidden so make first one current and show

currentdocument=document[0]
ShowGadget currentdocument


Global grfx:tgraphics = CanvasGraphics(pa[0])
SetGraphics grfx 

' standard message loop with special tabber GADGET_ACTION handling
Global text$ = "Red Canvas"
Global what_canvas:Int=0
While WaitEvent()
	Select EventID() 
	
		Case EVENT_TIMERTICK
			'redraw ONLY the current document-canvas
			RedrawGadget pa[what_canvas]
			
		Case EVENT_GADGETPAINT
			Cls
			DrawText text,0,0
			Flip()

	
		Case EVENT_GADGETACTION
			If EventSource()=tabber
				HideGadget currentdocument
				currentdocument = document[EventData()]
				'choose what canvas uses
				what_canvas = EventData()
				'setup graphics for that one
				grfx:tgraphics = CanvasGraphics(pa[what_canvas])
				SetGraphics grfx
				ShowGadget currentdocument
			EndIf
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend


using degac sample and an eventhook, I think this is more or less what you want.
SuperStrict' createtabber.bmx
'Import MaxGui.Drivers
 
Local window:TGadget
Global tabber:TGadget
Global document:TGadget[3],pa:tgadget[3]
Global currentdocument:TGadget

' CreateDocument creates a hidden panel that fills entire tabber client area 

Function CreateDocument:TGadget(tabber:TGadget)
	Local	panel:TGadget
	panel=CreatePanel(0,0,ClientWidth(tabber),ClientHeight(tabber),tabber)
	SetGadgetLayout panel,1,1,1,1
	HideGadget panel
	Return panel
End Function

' create a default window with a tabber gadget that fills entire client area

window=CreateWindow("My Window",30,20,400,300)

tabber=CreateTabber(0,0,ClientWidth(window),ClientHeight(window),window)
SetGadgetLayout tabber,1,1,1,1 

' add three items and corresponding document panels to the tabber

AddGadgetItem tabber,"Red Curve",False,-1,""
AddGadgetItem tabber,"Green Curve",False,-1,"Tabber Tip 1"
AddGadgetItem tabber,"Blue Curve",False,-1,"tips 4 2"

document[0]=CreateDocument(tabber)
document[1]=CreateDocument(tabber)
document[2]=CreateDocument(tabber)

SetPanelColor document[0],255,200,200
SetPanelColor document[1],200,255,200
SetPanelColor document[2],200,200,255

'to keep track of the canvases associated each to one tab (document[])


pa[0]=CreateCanvas(10 , 10 , 100 , 100 , document[0])
pa[1]=CreateCanvas(10 , 10 , 200 , 100 , document[1])
pa[2]=CreateCanvas(10 , 10 , 100 , 200 , document[2])

AddHook EmitEventHook, MyHook
' our documents start off hidden so make first one current and show

currentdocument=document[0]
ShowGadget currentdocument


Global grfx:tgraphics = CanvasGraphics(pa[0])
SetGraphics grfx 

' standard message loop with special tabber GADGET_ACTION handling
SetColor 255,0,0
Global text$ = "Red Canvas"
Global what_canvas:Int=0
'CreateTimer 60
Global index% = 0
While WaitEvent()
	Select EventID() 
	
			
		Case EVENT_GADGETPAINT
			updateCanvas()
			
			
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend

Function MyHook:Object(iId:Int,tData:Object,tContext:Object)
	Local Event:TEvent=TEvent(tData)
	
	If Event.source=tabber 
		index = event.data
		UpdateCanvas()
		Return Null
  	EndIf

	Return tData
End Function

Function UpdateCanvas:Int()
	Select  index
		Case 0
			SetColor 255,0,0
			text = "Red Canvas"
		Case 1
			SetColor 0,255,0
			text = "Green Canvas"
		Case 2
			text = "Blue Canvas"
			SetColor 0,0,255
	End Select
	grfx:tgraphics = CanvasGraphics(pa[index])
	SetGraphics grfx
	If currentdocument <> document[index]
		HideGadget currentdocument
		currentdocument = document[index]
	EndIf
	ShowGadget currentdocument 
    Cls
	DrawText text,0,0 
    Flip
End Function


Thanks gentlemen.