예제 #1
0
    void GenerateStageDisplay(SelectorGenerator gen, Stage stage)
    {
        var obj = PrefabUtility.InstantiatePrefab(gen.stageDisplayPrefab, gen.transform) as GameObject;

        var pos   = gen.transform.position;
        var count = gen.stages.Count;

        pos.y   -= count * gen.span;
        obj.name = $"Stage {stage.stageName} ({count + 1})";
        obj.transform.position = pos;

        var ctrl = obj.GetComponent <StageDisplay>();

        ctrl.stage = stage;
        ctrl.stageTitle.GetComponent <TMP_Text>().text = stage.stageName;
        var g        = ctrl.stageDisplay.GetComponent <Renderer>();
        var material = new Material(g.sharedMaterial);

        if (stage.thumbnail != null)
        {
            material.SetTexture("_MainTex", stage.thumbnail);
            material.SetTexture("_EmissionMap", stage.thumbnail);
        }
        g.material = material;

        gen.stages.Add(stage);
    }
예제 #2
0
 /// <summary>
 /// Retrieves all controls from descendants of the starting control 
 /// that match any selector within the supplied selector strings. 
 /// </summary>
 public static IEnumerable<Control> QuerySelectorAll(this Control control, string selector)
 {
     var generator = new SelectorGenerator<Control>(new ControlOps());
     Parser.Parse(selector, generator);
     return generator.Selector(Enumerable.Repeat(control, 1));
 }
예제 #3
0
파일: CssQuery.cs 프로젝트: nhajidin/SVG
 public static IEnumerable<SvgElement> QuerySelectorAll(this SvgElement elem, string selector)
 {
     var generator = new SelectorGenerator<SvgElement>(new SvgElementOps());
     Fizzler.Parser.Parse(selector, generator);
     return generator.Selector(Enumerable.Repeat(elem, 1));
 }
예제 #4
0
 /// <summary>
 /// Retrieves all element nodes from descendants of the starting 
 /// element node that match any selector within the supplied 
 /// selector strings. 
 /// </summary>
 public static IEnumerable<XmlNode> QuerySelectorAll(this XmlNode node, string selector)
 {
     var generator = new SelectorGenerator<XmlNode>(new XmlNodeOps());
     Parser.Parse(selector, generator);
     return generator.Selector(Enumerable.Repeat(node, 1));
 }
예제 #5
0
        private static Match[] Evaluate(HtmlDocument document, Control tb, ListBox lb, Control hb, ToolStripItem status, IEnumerable<Match> oldMatches, RichTextBox rtb)
        {
            var input = tb.Text.Trim();
            tb.ForeColor = SystemColors.WindowText;
            
            var elements = new HtmlNode[0];
            
            if (string.IsNullOrEmpty(input))
            {
                status.Text = "Ready";
                hb.Text = null;
            }
            else
            {
                try
                {
                    //
                    // Simple way to query for elements:
                    //
                    // nodes = document.DocumentNode.QuerySelectorAll(input).ToArray();
                    //
                    // However, we want to generate the human readable text and
                    // the element selector in a single pass so go the bare metal way 
                    // here to make all the parties to talk to each other.
                    //
                    
                    var generator = new SelectorGenerator<HtmlNode>(new HtmlNodeOps());
                    var helper = new HumanReadableSelectorGenerator();
                    Parser.Parse(input, new SelectorGeneratorTee(generator, helper));
                    if (document != null)
                        elements = generator.Selector(Enumerable.Repeat(document.DocumentNode, 1)).ToArray();
                    hb.Text = helper.Text;

                    status.Text = "Matches: " + elements.Length.ToString("N0");
                }
                catch (FormatException e)
                {
                    tb.ForeColor = Color.FromKnownColor(KnownColor.Red);
                    status.Text = "Error: " + e.Message;
                    hb.Text = "Oops! " + e.Message;
                }
            }
            
            if (oldMatches != null)
                Highlight(rtb, oldMatches, null, SystemColors.Info, null);
        
            lb.BeginUpdate();
            try
            {
                lb.Items.Clear();
                if (!elements.Any())
                    return new Match[0];

                var html = rtb.Text;
                var matches  = new List<Match>(elements.Length);
                foreach (var element in elements)
                {
                    var index = rtb.GetFirstCharIndexFromLine(element.Line - 1) + element.LinePosition - 1;
                    var match = _tagExpression.Match(html, index);
                    if (match.Success)
                        matches.Add(match);
                }
                
                Highlight(rtb, matches, null, Color.Yellow, null);
                
                lb.Items.AddRange(elements.Select(n => n.GetBeginTagString()).ToArray());
                
                return matches.ToArray();
            }
            finally
            {
                lb.EndUpdate();
            }
        }