Gui

Blitz3D Forums/Blitz3D Programming/Gui

Hi, i'm trying to make a gui system but have a question, how do i add an id to a window because when you use a function to create a window you tend to use something like
W.Win = New Win
then you have the code for creating it but if i then tested it to create more that one window and make a function to add say a button to one window how would i add referance to the window i want to add it to?

Add a reference number field in the Win type.

ok but what then, if i want to call it up i need to use something like if
W\Ref = Reference then
*what ever is wanted*
endif
but how does that add a direct link to a window, like say i wanted to code the window to be able to be moved around with the mouse, i would need to be able to get the window that the mouse is over to be identified seperate from the others and then changed the properties inside the functions that created that window without affecting the others.

Goober,

I use one Type for all gizmos. As Shifty Geezer has suggested you can add a ID field to the Type. I would go a step further by adding a Array of Types to store a pointer to the gizmos by ID. This will allow you to access properties of individual gizmos by ID.

Heres an excerpt of code from MAUI. For example purposes only:)

Type MAUI_Gizmo
	Field id%
	Field typeid%
	Field format% ;1:2D, 2:3D
	Field templateid%
	Field parentid%
	Field relativeid% ;first child, sibling
	Field x#
	Field y#
	Field z#
	Field width#
	Field height#
	Field depth#
	Field order%
	Field pointer[5]
	Field entity%[5]
	Field texture%[5]
	Field sound%[5]
	Field propertyname$[4]
	Field propertyvalue$[4]
	Field propertydatatype%[4]
	Field event%
	Field behavior%[5]
	Field action%[5]
	Field state%
End Type

Const MAUI_GIZMO_MAX=100 ;max number of gizmos

Dim MAUI_GizmoID.MAUI_Gizmo(MAUI_GIZMO_MAX) ;<--- Array of Types

Global MAUI_Gizmos ;current number of gizmos

Function MAUI_GizmoNew.MAUI_Gizmo()
	this.MAUI_Gizmo = New MAUI_Gizmo
	MAUI_Gizmos=MAUI_Gizmos+1 ; Simple ID management
	this\id=MAUI_Gizmos
	;default values
	this\format=1
	this\width=32
	this\height=32
	this\state=1
	MAUI_GizmoID(this\id)=this ;<--- Record ID: Stores pointer to record in Array of Types 
	Return this
End Function

Function MAUI_GizmoCreate%(parentid%,typeid%,x#,y#,width#,height#)
	this.MAUI_Gizmo = MAUI_GizmoNew()
	this\parentid%=parentid%
	this\typeid%=typeid%
	this\x#=x#
	this\y#=y#
	this\width#=width#
	this\height#=height#
	Return this
End Function


Now you can create and access gizmos individually by ID. Whats really cool about this method is that there are variety of ways you can manage ID assignment. For example you can use a stack to push and pop IDs to recycle IDs. Very good for gizmos that are constant created and deleted. Anyhows...

;Create a gizmo; returns the Id of the Gizmo
MyGizmo=MAUI_GizmoCreate(MAUI_GIZMO_CANVAS,MAUI_GIZMO_WINDOW,0,0,256,256)

;Access gizmo properties
MAUI_GizmoID(MyGizmo)\x#=16
;-OR-
MyGizmo1.MAUI_Gizmo=MAUI_GizmoID(MyGizmo)
MyGizmo1\x#=16


This method sort of makes sense but it's a bit blurry to understand, can you please explain it in a simpler way if possible, mean while i will try and addapt your idea to my coding.
thanks

Can you explain your question/problem in simpler terms? I don't understand.

I see what he means... for each instance of GUI control or objects you create a new TYPE. I suggest a read through on TYPEs here: http://www.blitzbasic.com/Community/posts.php?topic=34757

And a general rummage through the TUTORIALS section would not be too out of hand as a reccomend as well.

RZ