public TPTabletUIGroup CreateGroup()
    {
        int             identifier = m_allGroups.Count;
        TPTabletUIGroup grp        = new TPTabletUIGroup(identifier);

        m_allGroups.Add(grp);
        return(grp);
    }
    /** Finds the child group of the specified group and name. */
    public int FindChildGroupIdByName(TPTabletUIGroup grp, string name)
    {
        int numChildrGroups = grp.GetNumChildGroups();

        for (int i = 0; i < numChildrGroups; i++)
        {
            TPTabletUIGroup childGrp = grp.GetChildGroup(i);
            if (childGrp.GetName() == name)
            {
                return(i);
            }
        }
        return(-1);
    }
    /** Finds the group of the specified name. */
    public TPTabletUIGroup FindGroupByName(string name)
    {
        int i;

        for (i = 0; i < m_allGroups.Count; i++)
        {
            TPTabletUIGroup grp = m_allGroups[i] as TPTabletUIGroup;
            if (grp.GetName() == name)
            {
                return(grp);
            }
        }
        return(null);
    }
    public void CalculateRect(ref Stack positionStack, ref Vector2 maxCoords)
    {
        Vector2 p = (Vector2)positionStack.Peek() + m_position;

        positionStack.Push(p);
        int i;

        for (i = 0; i < m_groups.Count; i++)
        {
            TPTabletUIGroup grp = m_groups[i] as TPTabletUIGroup;
            grp.CalculateRect(ref positionStack, ref maxCoords);
        }
        positionStack.Pop();

        for (i = 0; i < m_buttons.Count; i++)
        {
            TPTabletUIButton btn = m_buttons[i] as TPTabletUIButton;
            btn.CalculateRect(p, ref maxCoords);
        }
        m_boundRect = Rect.MinMaxRect(p.x, p.y, maxCoords.x, maxCoords.y);
    }
    /** Updates the bounding rectangles of all the groups and buttons. */
    private void CalculateRect()
    {
        Stack positionStack = new Stack();

        positionStack.Push(new Vector2(0.0f, 0.0f));
        int i;

        for (i = 0; i < m_rootGroups.Count; i++)
        {
            TPTabletUIGroup grp       = m_rootGroups[i] as TPTabletUIGroup;
            Vector2         maxCoords = new Vector2(0.0f, 0.0f);
            grp.CalculateRect(ref positionStack, ref maxCoords);
            if (maxCoords.x > m_size.x)
            {
                m_size.x = maxCoords.x;
            }
            if (maxCoords.y > m_size.y)
            {
                m_size.y = maxCoords.y;
            }
        }
    }
    public bool Parse(byte[] bytes)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();

        ConfigFile cf = new ConfigFile();

        if (!cf.Parse(bytes))
        {
            return(false);
        }
        ConfigElement root = cf.GetRoot();

        if (root.GetName() != "TabletInterface")
        {
            mgr.PutErrorMessage("The configuration file is invalid.");
            return(false);
        }

        m_networkEvents = new ArrayList();
        m_rootGroups    = new ArrayList();

        int i;

        for (i = 0; i < root.GetNumChildren(); i++)
        {
            ConfigElement ce   = root.GetChild(i);
            string        name = ce.GetName();
            if (name == "NetworkEvent")
            {
                TPTabletUIEvent networkEvent = new TPTabletUIEvent();
                if (networkEvent.Parse(ce))
                {
                    m_networkEvents.Add(networkEvent);
                }
                else
                {
                    return(false);
                }
            }
            else if (name == "GUIDefinition")
            {
                ConfigElement guiDef = ce;
                string        attrib = ce.GetAttribute("orientation");
                if (!string.IsNullOrEmpty(attrib))
                {
                    if (attrib == "vertical")
                    {
                        m_orientation = ScreenOrientation.Portrait;
                    }
                    else if (attrib == "horizontal")
                    {
                        m_orientation = ScreenOrientation.LandscapeLeft;
                    }
                    else
                    {
                        mgr.PutErrorMessage("Found an invalid orientation attribute. (" + attrib + ")");
                        return(false);
                    }
                }
                int j;
                for (j = 0; j < guiDef.GetNumChildren(); j++)
                {
                    ce = guiDef.GetChild(j);
                    if (ce.GetName() == "Group")
                    {
                        TPTabletUIGroup rootGroup = CreateGroup();
                        if (rootGroup.Parse(ce))
                        {
                            m_rootGroups.Add(rootGroup);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
        }

        CalculateRect();

        return(true);
    }
    public bool Parse(ConfigElement ce)
    {
        TPTabletUIManager mgr = TPTabletUIManager.GetInstance();
        TPTabletUIConfig  cfg = mgr.GetConfig();

        m_name = ce.GetAttribute("name");

        string attrib = ce.GetAttribute("position");

        if (string.IsNullOrEmpty(attrib))
        {
            mgr.PutErrorMessage("Found a Group element ("
                                + GetName() + ") which doesn't have the position attribute.");
            return(false);
        }
        else
        {
            string[] vec = attrib.Split(' ');
            if (vec.Length != 2)
            {
                mgr.PutErrorMessage("Found an invalid position attribute (Group : "
                                    + GetName() + ").");
                return(false);
            }
            float.TryParse(vec[0], out m_position.x);
            float.TryParse(vec[1], out m_position.y);
        }

        attrib = ce.GetAttribute("mode");
        if (!string.IsNullOrEmpty(attrib))
        {
            if (attrib == "all")
            {
                m_mode = Mode.All;
            }
            else if (attrib == "selection")
            {
                m_mode = Mode.Selection;
            }
            else
            {
                mgr.PutErrorMessage("Found an invalid mode attribute (Group : "
                                    + GetName() + ") : " + attrib);
                return(false);
            }
        }

        int i;

        for (i = 0; i < ce.GetNumChildren(); i++)
        {
            ConfigElement child = ce.GetChild(i);
            string        name  = child.GetName();
            if (name == "Enable")
            {
                attrib = child.GetAttribute("value");
                if (!string.IsNullOrEmpty(attrib))
                {
                    if (attrib == "true")
                    {
                        m_enabled = true;
                    }
                    else if (attrib == "false")
                    {
                        m_enabled = false;
                    }
                    else
                    {
                        mgr.PutErrorMessage("Found an invalid value attribute (Group/Enable : "
                                            + GetName() + ") : " + attrib);
                        return(false);
                    }
                    m_orgEnabled = m_enabled;
                }
            }
            else if (name == "Selection")
            {
                attrib = child.GetAttribute("index");
                if (!string.IsNullOrEmpty(attrib))
                {
                    int.TryParse(attrib, out m_selection);
                    m_orgSelection = m_selection;
                }
            }
            else if (name == "Group")
            {
                TPTabletUIGroup grp = cfg.CreateGroup();
                if (grp.Parse(child))
                {
                    m_groups.Add(grp);
                }
                else
                {
                    return(false);
                }
            }
            else if (name == "Button")
            {
                TPTabletUIButton btn = cfg.CreateButton();
                if (btn.Parse(child))
                {
                    m_buttons.Add(btn);
                }
                else
                {
                    return(false);
                }
            }
        }

        return(true);
    }