How to draw a canvas on all tabs of a tabber?

BlitzMax Forums/MaxGUI Module/How to draw a canvas on all tabs of a tabber?

jondecker76(Posted 2010) [#1]
I'm currently developing a multi-platform applictaion (a skin editor to make skin files for another application I'm working on)
The editor has many tabs for different types of options, and I want to show a preview of the skin on a canvas that is displayed in the same place on all tabs (there are 13 tabs in all, so creating a separate canvas for each tab seems overkill to me)

I initially started development in Linux only and created canvase after the tabber , and set the window as the parent. This worked fine, but when I got the chance to test it on Windows, the canvas is hidden behind the tabber. I've also tried making the tabber the parent of the canvas, but that doesn't work in either Windows or Linux.

I'd like to find a sane way to show the preview window on all tabs without having to create 13 canvases and deal with the logic to determine which one to draw to. Any suggestions?

Here is a short sample code. I have commented out some alternate ways to create the canvas, but they all have one problem or another that makes it not work. Any help would be appreciated!

SuperStrict

Import MaxGui.Drivers

'Create Window
Global win:TGadget=CreateWindow("Skin Editor",0,0,640,480,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_STATUS|WINDOW_CENTER|WINDOW_ACCEPTFILES)

'Create Tabber and tabs
Global tabber:TGadget=CreateTabber(0,0,ClientWidth(win),ClientHeight(win),win)
SetGadgetLayout(tabber,1,1,1,1)
AddGadgetItem(tabber,"General",	False,-1,"General properties")
AddGadgetItem(tabber,"Appearance",	False,-1,"Appearance related items")
AddGadgetItem(tabber,"Options",	False,-1,"Misc. Options")

'Create a panel for each tab
Global GENERAL:Int		=0
Global APPEARANCE:Int	=1
Global OPTIONS:Int		=2
Global NUMTABS:Int		=3

Global TabPanel:TGadget[NUMTABS]
Global CurrentTabPanel:TGadget
TabPanel[GENERAL]=CreateTabPanel(tabber)
TabPanel[APPEARANCE]=CreateTabPanel(tabber)
TabPanel[OPTIONS]=CreateTabPanel(tabber)

'Create the canvas
'Global canPreview:TGadget=CreateCanvas(10,25,320,240,TabPanel[GENERAL]) 'Works, but only on 1 tab!
Global canPreview:TGadget=CreateCanvas(10,25,320,240,win) 'works in linux, but not visible in windows!
'Global canPreview:TGadget=CreateCanvas(10,25,320,240,tabber) 'doesn't work in either linux or windows!

'Create a timer to refresh the canvas
CreateTimer(30)

'Do some simple setup
init()

While WaitEvent()
	Select EventID()
	Case EVENT_GADGETACTION
		Select EventSource()
		Case tabber
			HideGadget currentTabPanel
			currentTabPanel=TabPanel[EventData()]
			ShowGadget currentTabPanel
		End Select
	Case EVENT_TIMERTICK
		RedrawGadget canPreview
	Case EVENT_GADGETPAINT
		SetGraphics(CanvasGraphics(canPreview))
		Render()
				
	Case EVENT_WINDOWCLOSE
		End
	End Select
Wend



Function Init()
	currentTabPanel=TabPanel[GENERAL]
	ShowGadget(TabPanel[GENERAL])
End Function

Function Render()	
	Cls
	SetColor(255,255,255)
	DrawOval(160+(Sin(MilliSecs()/10))*160,120,20,20)
	Flip
End Function


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




Zeke(Posted 2010) [#2]
reduce tab panels size:



jondecker76(Posted 2010) [#3]
yes, but then all of the other gadgets that need to go both under and to the right of the preview can't all go into the panel for that tab. Perhaps the only way is going to be making 2 panels per tab, one for below the preview, and one for the area to the right of the preview?


jsp(Posted 2010) [#4]
Yes, either 2 panels or may an array of gadgets which needs to be switched on/off. Unfortunately we don't have an re-parent command which is cross-platform.


jondecker76(Posted 2010) [#5]
Just posing a follow-up on this. Unfortunately, Zeeke's example above only works on Windows. Its a bit ugly, but to get things working cross-platform, I ended up resorting to:

'==============
'PREVIEW CANVAS
'==============
?win32
Global canPreview:TGadget=CreateCanvas(0,0,600,400,tabber)
?
?linux
Global canPreview:TGadget=CreateCanvas(0,25,600,400,win)
?