Search This Blog

Tuesday, January 31, 2012

Game Studio design, and code

Since the game studio is the primary interface for game development for the engine, a lot of thought and planning is required to make it as useful as possible.

First, a screen shot:


Now, the nuts and bolts.

The main form has a menu, tab control, and frame.  The frame (on the right side) will hold the project files in a tree view.  All script files will be listed there.  The tab pages will be where project files are edited.  The File menu allows projects to be opened, saved, closed, and printed.  The Edit menu contains standard cut, copy, paste, and select all commands.  There will be more menu items added for different file types.  I'm going to add in code compiling and testing functions soon.

There are different types of tab pages.  The one that is visible is a code editor tab.  All of the UI controls are UI members of one custom UI object, CodeControl.  The HScroll bar, VScroll bar, and Combo box are just regular controls as members of the custom control.  The text and line numbers are being drawn onto a customized group box object.  The custom group box object code is not very complicated, it just modifies some of the functionality of the default group box UI object to make it behave differently. 
The code for the custom group box:

Public Class EnhancedTextBox
    Inherits GroupBox

    Public Event DrawMe(ByRef e As System.Windows.Forms.PaintEventArgs)

    Public Sub New()
        MyBase.New()
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)
        Me.UpdateStyles()
        Me.Cursor = Cursors.IBeam
    End Sub

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.Up Or keyData = Keys.Down Or keyData = Keys.Left Or keyData = Keys.Right Then
            OnKeyDown(New KeyEventArgs(keyData))
            ProcessCmdKey = True
        ElseIf keyData = Keys.Tab Then
            OnKeyPress(New KeyPressEventArgs(Chr(9)))
            ProcessCmdKey = True
        ElseIf keyData = Keys.Delete Then
            OnKeyPress(New KeyPressEventArgs(Chr(127)))
            ProcessCmdKey = True
        Else
            Return MyBase.ProcessCmdKey(msg, keyData)
        End If
    End Function

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        e.Graphics.FillRectangle(Brushes.White, Me.ClientRectangle)        'clear client area
        e.Graphics.DrawRectangle(Pens.DarkGray, Me.ClientRectangle)        'draw boarder
        RaiseEvent DrawMe(e)        'call the draw event
    End Sub

End Class

The code for the custom rendering is a part of the CodeControl custom UI object.  I wish I could list all of that code here, but it is about 950 lines of code long.  Also, the code is not complete yet; there is a lot of functionality that I need to write.  When I get more of it done, I want to make a post devoted to covering the ins and out of how it works.
The brief version is the CodeControl uses the KeyPress, KeyDown, MouseDown, MouseMove, and MouseUp events from the EnhancedTextBox object to capture user input, and manipulate text that it stores in an array.  The DrawMe event triggers rendering code on the screen, using values from the HScroll and VScroll to determine what text to draw.  A syntax processor sets the color on recognized keywords, double quote delimited text, and numbers, that the DrawMe event uses to render colorized code.  I created overrides for the Text and Font properties of the EnhancedTextBox to handle getting and setting text from the control, and setting the font to be used for rendering.

More to come later...

No comments:

Post a Comment