I've now implemented the menu component.
You can download an example of it here
http://www.tyranntrpg.org/Runtime2.zip
An example of what it looks like is shown below:
The code to create the menu is:
Dim anEvent As New dgdkEvent
anEvent.ToID = STR_EventHandler
anEvent.Type = dgdkEvent.EventType.Create
anEvent.Catagory = dgdkEvent.EventCatagory.Menu
Dim menuItems() As String = {"New Character", "Edit Character", "Start Game", "Quit Game"}
Dim aMenu As New tyMenu("testMenu", "Main Menu", 100, 100, menuItems)
anEvent.EventObject = aMenu
SendEvent(anEvent, STR_CORE)
This then send the menu object to the dgdk thread which handles everything from there.
The code in the dgdk Thread just needs to do this:
Case dgdkEvent.EventType.Create
Dim aComponent As tyComponent = CType(anEvent.EventObject, tyComponent)
AddComponent(aComponent)
Public Sub AddComponent(ByVal component As tyComponent)
component.RefreshDisplay()
SyncLock _components
_components.Add(component.ID, component)
End SyncLock
End Sub
And it will initially draw the component on the screen as all components derive from a base class tyComponent which implements an interface which has RefreshDisplay.
The loop that controls the components is:
Private Sub EventHandler()
While LoopGDK() = True
ProcessEvents()
UpdateComponents()
Sync()
Thread.Sleep(10)
If _abort = True Then
Exit Sub
End If
End While
End Sub
Private Sub UpdateComponents()
For Each dictEntry As DictionaryEntry In _components
Dim acomponent As tyComponent = CType(dictEntry.Value, tyComponent)
Dim resultEvent As dgdkEvent = aComponent.MouseAction(MouseX, MouseY, MouseButton)
If resultEvent.Catagory <> dgdkEvent.EventCatagory.Empty Then
resultEvent.ToID = STR_CORE
SendEvent(resultEvent, _ProcessID)
End If
Next
End Sub
ProcessEvents will just check to see if there has been any new events sent to the thread
This works as another thing that the component interface honours is .MouseAction(MouseX, MouseY, MouseButton)
So it doesn't need to know what the type of component it is, it just knows that all components can do RefreshDisplay and MouseAction. This is making for much less code
Next it's onto a text box which is going to be slightly harder, but another thing the interface honours is KeyPress(ByVal key As Char).
Jas
----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"