示例#1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Share the image with another sprite
        /// </summary>
        ///
        /// <param name="spriteToCopy">The original sprite</param>
        /// <param name="newSprite">The sprite that will get the same image as the sprite that is being copied</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool CopyTexture(Impl.Sprite spriteToCopy, Impl.Sprite newSprite)
        {
            // Ignore null pointers
            if (spriteToCopy.texture == null)
            {
                newSprite.texture = null;
                return(true);
            }

            // Loop all our textures to check if we already have this one
            foreach (var pair in m_ImageMap)
            {
                ImageMapData data = pair.Value;

                foreach (Impl.Texture texture in data.data)
                {
                    // Check if the pointer points to our texture
                    if (texture == spriteToCopy.texture)
                    {
                        // The texture is now used at multiple places
                        ++(texture.users);
                        newSprite.texture = spriteToCopy.texture;
                        newSprite.sprite  = new Sprite(spriteToCopy.sprite);
                        return(true);
                    }
                }
            }

            Internal.Output("TGUI warning: Can't copy texture that wasn't loaded by TextureManager.");
            return(false);
        }
示例#2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a MessageBox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public MessageBox(string configFileFilename)
        {
            Add(m_Label, "MessageBoxText");
            m_Label.TextSize = m_TextSize;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "MessageBox");

            // Find the folder that contains the config file
            string configFileFolder = configFileFilename.Substring(0, configFileFilename.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            bool childWindowPropertyFound = false;
            bool buttonPropertyFound      = false;

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "textcolor")
                {
                    m_Label.TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "childwindow")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for ChildWindow in section MessageBox in " + m_LoadedConfigFile + ".");
                    }

                    InternalLoad(configFileFolder + configFile.Values [i].Substring(1, configFile.Values [i].Length - 2));
                    childWindowPropertyFound = true;
                }
                else if (configFile.Properties[i] == "button")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for Button in section MessageBox in " + m_LoadedConfigFile + ".");
                    }

                    m_ButtonConfigFileFilename = configFileFolder + configFile.Values [i].Substring(1, configFile.Values [i].Length - 2);
                    buttonPropertyFound        = true;
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section MessageBox in " + m_LoadedConfigFile + ".");
                }
            }

            if (!childWindowPropertyFound)
            {
                throw new Exception("TGUI error: Missing a ChildWindow property in section MessageBox in " + m_LoadedConfigFile + ".");
            }

            if (!buttonPropertyFound)
            {
                throw new Exception("TGUI error: Missing a Button property in section MessageBox in " + m_LoadedConfigFile + ".");
            }
        }
示例#3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Removes a tab with a given name
        /// </summary>
        ///
        /// <param name="name">The name of the tab to remove</param>
        ///
        /// When multiple tabs have the same name, only the first will be removed.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Remove(string name)
        {
            // Remove the tab
            int index = m_TabNames.IndexOf(name);

            if (index != -1)
            {
                m_TabNames.RemoveAt(index);
                m_NameWidth.RemoveAt(index);

                // Check if the selected tab should change
                if (m_SelectedTab == index)
                {
                    m_SelectedTab = -1;
                }
                else if (m_SelectedTab > index)
                {
                    --m_SelectedTab;
                }

                return;
            }

            Internal.Output("TGUI warning: Failed to remove the tab. The name didn't match any tab.");
        }
示例#4
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Slider2d section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Slider2d(string configFileFilename)
        {
            m_DraggableWidget  = true;
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Slider2d");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separatehoverimage")
                {
                    m_SeparateHoverImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "tracknormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureTrackNormal);
                }
                else if (configFile.Properties[i] == "trackhoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureTrackHover);
                }
                else if (configFile.Properties[i] == "thumbnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureThumbNormal);
                }
                else if (configFile.Properties[i] == "thumbhoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureThumbHover);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Slider2d in " + m_LoadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_TextureTrackNormal.texture != null) && (m_TextureThumbNormal.texture != null))
            {
                // Set the size of the slider
                m_Size = new Vector2f(m_TextureTrackNormal.Size.X, m_TextureTrackNormal.Size.Y);
            }
            else
            {
                throw new Exception("Not all needed images were loaded for the slider. Is the Slider2d section in " + m_LoadedConfigFile + " complete?");
            }

            // Check if optional textures were loaded
            if ((m_TextureTrackHover.texture != null) && (m_TextureThumbHover.texture != null))
            {
                m_WidgetPhase |= (byte)WidgetPhase.Hover;
            }
        }
示例#5
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a SpinButton section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public SpinButton(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "SpinButton");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separatehoverimage")
                {
                    m_SeparateHoverImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "arrowupnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpNormal);
                }
                else if (configFile.Properties[i] == "arrowuphoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpHover);
                }
                else if (configFile.Properties[i] == "arrowdownnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownNormal);
                }
                else if (configFile.Properties[i] == "arrowdownhoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownHover);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section SpinButton in " + m_LoadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_TextureArrowUpNormal.texture != null) && (m_TextureArrowDownNormal.texture != null))
            {
                m_Size = new Vector2f(m_TextureArrowUpNormal.Size.X, m_TextureArrowUpNormal.Size.Y + m_TextureArrowDownNormal.Size.Y);
            }
            else
            {
                throw new Exception("Not all needed images were loaded for the spin button. Is the SpinButton section in " + m_LoadedConfigFile + " complete?");
            }

            // Check if optional textures were loaded
            if ((m_TextureArrowUpHover.texture != null) && (m_TextureArrowDownHover.texture != null))
            {
                m_WidgetPhase |= (byte)WidgetPhase.Hover;
            }
        }
示例#6
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Selects the tab with a given index
        /// </summary>
        ///
        /// <param name="index">The index of the tab to select</param>
        ///
        /// When the index is too high then nothing will happen.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Select(uint index)
        {
            // If the index is too big then do nothing
            if (index > m_TabNames.Count - 1)
            {
                Internal.Output("TGUI warning: Failed to select the tab. The index was too high.");
                return;
            }

            // Select the tab
            m_SelectedTab = (int)index;
        }
示例#7
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Convert the value to a color
        /// </summary>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Color ReadColor(int i)
        {
            Color color;

            if (!Internal.ExtractColor(Values[i], out color))
            {
                Internal.Output("TGUI warning: Property " + Properties[i] + " in section " + m_Section
                                + " has a bad value: '" + Values[i] + "'. Using the default white color.");
            }

            return(color);
        }
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Returns the duration of the currently displayed frame
 /// </summary>
 ///
 /// <returns>Duration of the frame that is currently displayed</returns>
 ///
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public int GetCurrentFrameDuration()
 {
     if (m_CurrentFrame >= 0)
     {
         return(m_FrameDuration[m_CurrentFrame]);
     }
     else
     {
         Internal.Output("TGUI warning: Can't get duration of current frame: no frames available.");
         return(0);
     }
 }
示例#9
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a ChatBox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public ChatBox(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "ChatBox");

            // Find the folder that contains the config file
            string configFileFolder = configFileFilename.Substring(0, configFileFilename.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backgroundcolor")
                {
                    BackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "bordercolor")
                {
                    BorderColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "borders")
                {
                    Borders borders;
                    if (Internal.ExtractBorders(configFile.Values [i], out borders))
                    {
                        Borders = borders;
                    }
                }
                else if (configFile.Properties[i] == "scrollbar")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for Scrollbar in section ChatBox in " + m_LoadedConfigFile + ".");
                    }

                    // load the scrollbar
                    m_Scroll = new Scrollbar(configFileFolder + (configFile.Values[i]).Substring(1, configFile.Values[i].Length - 2));
                    m_Scroll.VerticalScroll = true;
                    m_Scroll.Size           = new Vector2f(m_Scroll.Size.X, m_Panel.Size.Y);
                    m_Scroll.LowValue       = (int)(m_Panel.Size.Y);
                    m_Scroll.Maximum        = (int)m_FullTextHeight;
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section ChatBox in " + m_LoadedConfigFile + ".");
                }
            }
        }
示例#10
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Selects the tab with a given name
        /// </summary>
        ///
        /// <param name="name">The name of the tab to select</param>
        ///
        /// When the name doen't match any tab then nothing will be changed.
        /// If there are multiple tabs with the same name then the first one will be selected.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Select(string name)
        {
            // Select the tab
            int index = m_TabNames.IndexOf(name);

            if (index != -1)
            {
                m_SelectedTab = index;
                return;
            }

            Internal.Output("TGUI warning: Failed to select the tab. The name didn't match any tab.");
        }
示例#11
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Knob section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Knob(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_loadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_loadedConfigFile, "Knob");

            // Find the folder that contains the config file
            string configFileFolder = m_loadedConfigFile.Substring(0, m_loadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backgroundimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_backgroundTexture);
                }
                else if (configFile.Properties[i] == "foregroundimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_foregroundTexture);
                }
                else if (configFile.Properties[i] == "imagerotation")
                {
                    m_imageRotation = (float)Convert.ToDouble(configFile.Values[i]);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Knob in " + m_loadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_backgroundTexture.texture != null) && (m_foregroundTexture.texture != null))
            {
                // Rotate the image
                m_foregroundTexture.sprite.Origin   = new Vector2f(m_foregroundTexture.Size.X / 2.0f, m_foregroundTexture.Size.Y / 2.0f);
                m_foregroundTexture.sprite.Rotation = m_startRotation - m_imageRotation;

                m_foregroundTexture.sprite.Position = new Vector2f(m_backgroundTexture.Size.X / 2.0f, m_backgroundTexture.Size.Y / 2.0f);

                Size = new Vector2f(m_backgroundTexture.Size.X, m_backgroundTexture.Size.Y);
            }
            else
            {
                throw new Exception("Not all needed images were loaded for the knob. Is the Knob section in " + m_loadedConfigFile + " complete?");
            }
        }
示例#12
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Label section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Label(string configFileFilename)
        {
            m_Background.FillColor = new Color(0, 0, 0, 0);

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Label");

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "textcolor")
                {
                    m_Text.Color = configFile.ReadColor(i);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Label in " + m_LoadedConfigFile + ".");
                }
            }
        }
示例#13
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Removes a tab with a given index
        /// </summary>
        ///
        /// <param name="index">The index of the tab to remove</param>
        ///
        /// When the index is too high then nothing will happen.
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Remove(uint index)
        {
            // The index can't be too high
            if (index > m_TabNames.Count - 1)
            {
                Internal.Output("TGUI warning: Failed to remove the tab. The index was too high.");
                return;
            }

            // Remove the tab
            m_TabNames.RemoveAt((int)index);
            m_NameWidth.RemoveAt((int)index);

            // Check if the selected tab should change
            if (m_SelectedTab == (int)(index))
            {
                m_SelectedTab = -1;
            }
            else if (m_SelectedTab > (int)(index))
            {
                --m_SelectedTab;
            }
        }
示例#14
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a MenuBar section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public MenuBar(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "MenuBar");

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backgroundcolor")
                {
                    BackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "textcolor")
                {
                    TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedbackgroundcolor")
                {
                    SelectedBackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedtextcolor")
                {
                    SelectedTextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "distancetoside")
                {
                    DistanceToSide = Convert.ToUInt32(configFile.Values [i]);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section MenuBar in " + m_LoadedConfigFile + ".");
                }
            }
        }
示例#15
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a LoadingBar section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public LoadingBar(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "LoadingBar");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "backimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_M);
                    m_SplitImage = false;
                }
                else if (configFile.Properties[i] == "frontimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_M);
                }
                else if (configFile.Properties[i] == "backimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_L);
                }
                else if (configFile.Properties[i] == "backimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_M);
                    m_SplitImage = true;
                }
                else if (configFile.Properties[i] == "backimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureBack_R);
                }
                else if (configFile.Properties[i] == "frontimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_L);
                }
                else if (configFile.Properties[i] == "frontimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_M);
                }
                else if (configFile.Properties[i] == "frontimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFront_R);
                }
                else if (configFile.Properties [i] == "textcolor")
                {
                    TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties [i] == "textsize")
                {
                    TextSize = Convert.ToUInt32(configFile.Values [i]);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section LoadingBar in " + m_LoadedConfigFile + ".");
                }
            }

            // Check if the image is split
            if (m_SplitImage)
            {
                // Make sure the required textures were loaded
                if ((m_TextureBack_L.texture != null) && (m_TextureBack_M.texture != null) && (m_TextureBack_R.texture != null) &&
                    (m_TextureFront_L.texture != null) && (m_TextureFront_M.texture != null) && (m_TextureFront_R.texture != null))
                {
                    m_Size.X = (float)(m_TextureBack_L.Size.X + m_TextureBack_M.Size.X + m_TextureBack_R.Size.X);
                    m_Size.Y = (float)(m_TextureBack_M.Size.Y);

                    m_TextureBack_M.texture.texture.Repeated  = true;
                    m_TextureFront_M.texture.texture.Repeated = true;
                }
                else
                {
                    throw new Exception("Not all needed images were loaded for the loading bar. Is the LoadingBar section in " + m_LoadedConfigFile + " complete?");
                }
            }
            else // The image isn't split
            {
                // Make sure the required textures were loaded
                if ((m_TextureBack_M.texture != null) && (m_TextureFront_M.texture != null))
                {
                    m_Size = new Vector2f(m_TextureBack_M.Size.X, m_TextureBack_M.Size.Y);
                }
                else
                {
                    throw new Exception("TGUI error: Not all needed images were loaded for the loading bar. Is the LoadingBar section in " + m_LoadedConfigFile + " complete?");
                }
            }

            // Calculate the size of the front image (the size of the part that will be drawn)
            RecalculateSize();
        }
示例#16
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Button section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Button(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Button");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separatehoverimage")
                {
                    m_SeparateHoverImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "textcolor")
                {
                    m_Text.Color = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "normalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M);
                    m_SplitImage = false;
                }
                else if (configFile.Properties[i] == "hoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureHover_M);
                }
                else if (configFile.Properties[i] == "downimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureDown_M);
                }
                else if (configFile.Properties[i] == "focusedimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFocused_M);
                }
                else if (configFile.Properties[i] == "normalimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_L);
                }
                else if (configFile.Properties[i] == "normalimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M);
                    m_SplitImage = true;
                }
                else if (configFile.Properties[i] == "normalimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_R);
                }
                else if (configFile.Properties[i] == "hoverimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureHover_L);
                }
                else if (configFile.Properties[i] == "hoverimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureHover_M);
                }
                else if (configFile.Properties[i] == "hoverimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureHover_R);
                }
                else if (configFile.Properties[i] == "downimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureDown_L);
                }
                else if (configFile.Properties[i] == "downimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureDown_M);
                }
                else if (configFile.Properties[i] == "downimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureDown_R);
                }
                else if (configFile.Properties[i] == "focusedimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFocused_L);
                }
                else if (configFile.Properties[i] == "focusedimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFocused_M);
                }
                else if (configFile.Properties[i] == "focusedimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFocused_R);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Button in " + m_LoadedConfigFile + ".");
                }
            }

            // Check if the image is split
            if (m_SplitImage)
            {
                // Make sure the required textures were loaded
                if ((m_TextureNormal_L.texture != null) && (m_TextureNormal_M.texture != null) && (m_TextureNormal_R.texture != null))
                {
                    Size = new Vector2f(m_TextureNormal_L.Size.X + m_TextureNormal_M.Size.X + m_TextureNormal_R.Size.X,
                                        m_TextureNormal_M.Size.Y);

                    m_TextureNormal_M.texture.texture.Repeated = true;
                }
                else
                {
                    throw new Exception("Not all needed images were loaded for the button. Is the Button section in "
                                        + m_LoadedConfigFile + " complete?");
                }

                // Check if optional textures were loaded
                if ((m_TextureFocused_L.texture != null) && (m_TextureFocused_M.texture != null) && (m_TextureFocused_R.texture != null))
                {
                    m_AllowFocus   = true;
                    m_WidgetPhase |= (byte)WidgetPhase.Focused;

                    m_TextureFocused_M.texture.texture.Repeated = true;
                }
                if ((m_TextureHover_L.texture != null) && (m_TextureHover_M.texture != null) && (m_TextureHover_R.texture != null))
                {
                    m_WidgetPhase |= (byte)WidgetPhase.Hover;

                    m_TextureHover_M.texture.texture.Repeated = true;
                }
                if ((m_TextureDown_L.texture != null) && (m_TextureDown_M.texture != null) && (m_TextureDown_R.texture != null))
                {
                    m_WidgetPhase |= (byte)WidgetPhase.MouseDown;

                    m_TextureDown_M.texture.texture.Repeated = true;
                }
            }
            else // The image isn't split
            {
                // Make sure the required texture was loaded
                if (m_TextureNormal_M.texture != null)
                {
                    Size = new Vector2f(m_TextureNormal_M.Size.X, m_TextureNormal_M.Size.Y);
                }
                else
                {
                    throw new Exception("NormalImage property wasn't loaded. Is the Button section in " + m_LoadedConfigFile + " complete?");
                }

                // Check if optional textures were loaded
                if (m_TextureFocused_M.texture != null)
                {
                    m_AllowFocus   = true;
                    m_WidgetPhase |= (byte)WidgetPhase.Focused;
                }
                if (m_TextureHover_M.texture != null)
                {
                    m_WidgetPhase |= (byte)WidgetPhase.Hover;
                }
                if (m_TextureDown_M.texture != null)
                {
                    m_WidgetPhase |= (byte)WidgetPhase.MouseDown;
                }
            }
        }
示例#17
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Checkbox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Checkbox(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Checkbox");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "textcolor")
                {
                    m_Text.Color = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "checkedimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureChecked);
                }
                else if (configFile.Properties[i] == "uncheckedimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureUnchecked);
                }
                else if (configFile.Properties[i] == "hoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureHover);
                }
                else if (configFile.Properties[i] == "focusedimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureFocused);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Checkbox in " + m_LoadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_TextureChecked.texture != null) && (m_TextureUnchecked.texture != null))
            {
                Size = new Vector2f(m_TextureUnchecked.Size.X, m_TextureChecked.Size.Y);
            }
            else
            {
                throw new Exception("Not all needed images were loaded for the checkbox. Is the Checkbox section in " + m_LoadedConfigFile + " complete?");
            }

            // Check if optional textures were loaded
            if (m_TextureFocused.texture != null)
            {
                m_AllowFocus   = true;
                m_WidgetPhase |= (byte)WidgetPhase.Focused;
            }
            if (m_TextureHover.texture != null)
            {
                m_WidgetPhase |= (byte)WidgetPhase.Hover;
            }
        }
示例#18
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a ComboBox section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public ComboBox(string configFileFilename)
        {
            m_DraggableWidget = true;

            m_ListBox.Visible               = false;
            m_ListBox.Size                  = new Vector2f(50, 24);
            m_ListBox.ItemHeight            = 24;
            m_ListBox.ItemSelectedCallback += NewItemSelectedCallbackFunction;
            m_ListBox.UnfocusedCallback    += ListBoxUnfocusedCallbackFunction;

            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "ComboBox");

            // Find the folder that contains the config file
            string configFileFolder = configFileFilename.Substring(0, configFileFilename.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separatehoverimage")
                {
                    m_SeparateHoverImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "backgroundcolor")
                {
                    BackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "textcolor")
                {
                    TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedbackgroundcolor")
                {
                    SelectedBackgroundColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedtextcolor")
                {
                    SelectedTextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "bordercolor")
                {
                    BorderColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "arrowupnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpNormal);
                }
                else if (configFile.Properties[i] == "arrowuphoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowUpHover);
                }
                else if (configFile.Properties[i] == "arrowdownnormalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownNormal);
                }
                else if (configFile.Properties[i] == "arrowdownhoverimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureArrowDownHover);
                }
                else if (configFile.Properties[i] == "borders")
                {
                    Borders borders;
                    if (Internal.ExtractBorders(configFile.Values [i], out borders))
                    {
                        Borders = borders;
                    }
                }
                else if (configFile.Properties[i] == "scrollbar")
                {
                    if ((configFile.Values[i].Length < 3) || (configFile.Values[i][0] != '"') || (configFile.Values[i][configFile.Values[i].Length - 1] != '"'))
                    {
                        throw new Exception("Failed to parse value for Scrollbar in section ChatBox in " + m_LoadedConfigFile + ".");
                    }

                    // load the scrollbar
                    m_ListBox.SetScrollbar(configFileFolder + (configFile.Values[i]).Substring(1, configFile.Values[i].Length - 2));
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section ComboBox in " + m_LoadedConfigFile + ".");
                }
            }

            // Make sure the required textures were loaded
            if ((m_TextureArrowUpNormal.texture == null) || (m_TextureArrowDownNormal.texture == null))
            {
                throw new Exception("Not all needed images were loaded for the combo box. Is the ComboBox section in " + m_LoadedConfigFile + " complete?");
            }

            // Check if optional textures were loaded
            if ((m_TextureArrowUpHover.texture != null) && (m_TextureArrowDownHover.texture != null))
            {
                m_WidgetPhase |= (byte)WidgetPhase.Hover;
            }
        }
示例#19
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Loads the widget
        /// </summary>
        ///
        /// <param name="configFileFilename">Filename of the config file.
        /// The config file must contain a Tab section with the needed information.</param>
        ///
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public Tab(string configFileFilename)
        {
            m_LoadedConfigFile = Global.ResourcePath + configFileFilename;

            // Parse the config file
            ConfigFile configFile = new ConfigFile(m_LoadedConfigFile, "Tab");

            // Find the folder that contains the config file
            string configFileFolder = m_LoadedConfigFile.Substring(0, m_LoadedConfigFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1);

            // Loop over all properties
            for (int i = 0; i < configFile.Properties.Count; ++i)
            {
                if (configFile.Properties[i] == "separateselectedimage")
                {
                    m_SeparateSelectedImage = configFile.ReadBool(i);
                }
                else if (configFile.Properties[i] == "textcolor")
                {
                    m_TextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "selectedtextcolor")
                {
                    m_SelectedTextColor = configFile.ReadColor(i);
                }
                else if (configFile.Properties[i] == "distancetoside")
                {
                    DistanceToSide = Convert.ToUInt32(configFile.Values [i]);
                }
                else if (configFile.Properties[i] == "normalimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M);
                    m_SplitImage = false;
                }
                else if (configFile.Properties[i] == "selectedimage")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureSelected_M);
                }
                else if (configFile.Properties[i] == "normalimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_L);
                }
                else if (configFile.Properties[i] == "normalimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_M);
                    m_SplitImage = true;
                }
                else if (configFile.Properties[i] == "normalimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureNormal_R);
                }
                else if (configFile.Properties[i] == "selectedimage_l")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureSelected_L);
                }
                else if (configFile.Properties[i] == "selectedimage_m")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureSelected_M);
                }
                else if (configFile.Properties[i] == "selectedimage_r")
                {
                    configFile.ReadTexture(i, configFileFolder, m_TextureSelected_R);
                }
                else
                {
                    Internal.Output("TGUI warning: Unrecognized property '" + configFile.Properties[i]
                                    + "' in section Tab in " + m_LoadedConfigFile + ".");
                }
            }

            // Check if the image is split
            if (m_SplitImage)
            {
                // Make sure the required textures were loaded
                if ((m_TextureNormal_L.texture != null) && (m_TextureNormal_M.texture != null) && (m_TextureNormal_R.texture != null))
                {
                    m_TabHeight = (uint)m_TextureNormal_M.Size.Y;

                    m_TextureNormal_M.texture.texture.Repeated = true;
                }
                else
                {
                    throw new Exception("Not all needed images were loaded for the tab. Is the Tab section in " + m_LoadedConfigFile + " complete?");
                }

                // Check if optional textures were loaded
                if ((m_TextureSelected_L.texture != null) && (m_TextureSelected_M.texture != null) && (m_TextureSelected_R.texture != null))
                {
                    m_WidgetPhase |= (byte)WidgetPhase.Selected;

                    m_TextureSelected_M.texture.texture.Repeated = true;
                }
            }
            else // The image isn't split
            {
                // Make sure the required texture was loaded
                if (m_TextureNormal_M.texture != null)
                {
                    m_TabHeight = (uint)m_TextureNormal_M.Size.Y;
                }
                else
                {
                    throw new Exception("NormalImage wasn't loaded. Is the Tab section in " + m_LoadedConfigFile + " complete?");
                }

                // Check if optional textures were loaded
                if (m_TextureSelected_M.texture != null)
                {
                    m_WidgetPhase |= (byte)WidgetPhase.Selected;
                }
            }

            // Recalculate the text size when auto sizing
            if (m_TextSize == 0)
            {
                TextSize = 0;
            }
        }