Example #1
0
        //////////////////////////////////////////////////////////////////////////
        private void FixHotspot(DefinitionFileItem node, int modX, int modY)
        {
            bool found = false;

            foreach (DefinitionFileItem subNode in node.Children)
            {
                if (subNode.Name.ToUpper() == "HOTSPOT")
                {
                    found = true;
                    int[] values = subNode.GetIntArray();
                    if (values.Length > 1)
                    {
                        values[0] += modX;
                        values[1] += modY;

                        subNode.Value = string.Format("{0},{1}", values[0], values[1]);
                    }
                    break;
                }
            }

            if (!found)
            {
                DefinitionFileItem subNode = new DefinitionFileItem();
                subNode.Name  = "HOTSPOT";
                subNode.Value = string.Format("{0},{1}", modX, modY);

                node.Children.Add(subNode);
            }
            IsChanged = true;
        }
Example #2
0
        //////////////////////////////////////////////////////////////////////////
        private void NodeToString(DefinitionFileItem node, ref string str, string indent)
        {
            if (node.Name != null)
            {
                str += indent + node.Name;
            }

            if (node.Children.Count > 0)
            {
                if (node.Name != null)
                {
                    str += "\n" + indent + "{\n";
                }

                foreach (DefinitionFileItem subNode in node.Children)
                {
                    string newIndent = indent;
                    if (node.Name != null)
                    {
                        newIndent += "  ";
                    }
                    NodeToString(subNode, ref str, newIndent);
                }

                if (node.Name != null)
                {
                    str += indent + "}\n";
                }
            }
            else
            {
                if (IsNumberList(node.Value))
                {
                    str += " { " + node.Value.Replace(",", ", ") + " } ";
                }
                else
                {
                    bool needsQuotes = node.Value.Contains(" ") || node.Value.Contains("\\") || node.Value == "";

                    str += " = ";
                    if (needsQuotes)
                    {
                        str += "\"";
                    }
                    str += node.Value;
                    if (needsQuotes)
                    {
                        str += "\"";
                    }
                }
                str += "\n";
            }
        }
 //////////////////////////////////////////////////////////////////////////
 private void ScanDefinition(string DefFilename, DefinitionFileItem DefFileItem)
 {
     if (DefFileItem.Children.Count > 0)
     {
         for (int i = 0; i < DefFileItem.Children.Count; i++)
         {
             ScanDefinition(DefFilename, DefFileItem.Children[i]);
         }
     }
     else if (DefFileItem.Value != string.Empty)
     {
         string[] ItemsToScan = new string[] { "CAPTION", "TITLE", "TEXT" };
         foreach (string Item in ItemsToScan)
         {
             if (DefFileItem.Name.ToUpper() == Item)
             {
                 Strings.Add(new StringLocation(DefFileItem.Value, DefFilename, DefFileItem.LineNum, StringLocation.StringType.DefinitionFile));
             }
         }
     }
 }
Example #4
0
        //////////////////////////////////////////////////////////////////////////
        private void ProcessNode(DefinitionFileItem node)
        {
            if (node.Name != null && node.Name.ToUpper() == "IMAGE")
            {
                int modX, modY;
                Optimizer.CropImage(node.Value, out modX, out modY);

                if (modX != 0 || modY != 0)
                {
                    FixHotspot(node.Parent, modX, modY);
                }
            }

            // the collection can grow by adding a missing hotspot, hence no foreach
            int numNodes = node.Children.Count;

            for (int i = 0; i < numNodes; i++)
            {
                DefinitionFileItem subNode = node.Children[i];
                ProcessNode(subNode);
            }
        }