Exemple #1
0
 bool TryReduceBlockWidth(BlockElement root, int blockEndIndex, int blockWidth, out int restartAtIndex, out int restartBlockWidth)
 {
     restartAtIndex    = 0;
     restartBlockWidth = 0;
     for (int i = blockEndIndex; i >= 0; i--)
     {
         AElement e = root.Children[i];
         if (e.IsThisAtomABreakingSpace)
         {
             return(false);
         }
         blockWidth -= e.Width;
         if (blockWidth <= root.Width)
         {
             // if this is text, hyphenate, otherwise just insert a line break.
             if (e is CharacterElement)
             {
                 AElement hyphen = new InternalHyphenBreakElement(e.Style);
                 if (blockWidth + hyphen.Width <= root.Width)
                 {
                     root.Children.Insert(i, hyphen);
                     restartBlockWidth = blockWidth;
                     restartAtIndex    = i;
                     return(true);
                 }
                 continue;
             }
             root.Children.Insert(i, new InternalLineBreakElement(e.Style));
             restartBlockWidth = blockWidth;
             restartAtIndex    = i;
             return(true);
         }
     }
     return(false);
 }
 public void ParseTag(HTMLchunk chunk, AElement atom)
 {
     if (!chunk.bClosure || chunk.bEndClosure)
     {
         // create the tag and add it to the list of open tags.
         OpenTag tag = new OpenTag(chunk);
         m_OpenTags.Add(tag);
         // parse the tag (which will update the StyleParser's current style
         ParseTag(tag, atom);
         // if the style has changed and atom is not null, set the atom's style to the current style.
         if (atom != null)
         {
             atom.Style = Style;
         }
         // if this is a self-closing tag (<br/>) close it!
         if (chunk.bEndClosure)
         {
             CloseOneTag(chunk);
         }
     }
     else
     {
         CloseOneTag(chunk);
     }
 }
Exemple #3
0
 public ButtonAsIcon(AElement parent, int page, string icon_normal = null, string icon_down = null, string icon_hover = null)
     : base(parent, page)
 {
     m_IconNormal = icon_normal;
     m_IconDown = icon_down;
     m_IconHover = icon_hover;
 }
Exemple #4
0
        // ============================================================================================================
        // Get Carat Position, given an input index into the text or a clicked position
        // ============================================================================================================

        public Point GetCaratPositionByIndex(int textIndex)
        {
            Point carat = Point.Zero;

            if (m_Root == null)
            {
                return(carat);
            }
            int index = 0;

            for (int i = 0; i < m_Root.Children.Count; i++)
            {
                AElement e = m_Root.Children[i];
                if (index == textIndex && !e.IsThisAtomInternalOnly)
                {
                    return(carat);
                }
                if (e.IsThisAtomALineBreak)
                {
                    carat.X  = 0;
                    carat.Y += e.Height;
                }
                carat.X += e.Width;
                if (e.IsThisAtomInternalOnly)
                {
                    if (index == textIndex)
                    {
                        return(carat);
                    }
                    index--;
                }
                index++;
            }
            return(carat);
        }
Exemple #5
0
        public static Elements.Div Generate(AElement element, string id, string cssClass)
        {
            var newDivInstance = new Elements.Div(child: element, id: id, cssClass: cssClass);

            newDivInstance.Rendered = GenerateDivBody(id: id, cssClass: cssClass, content: element?.Rendered);

            return(newDivInstance);
        }
Exemple #6
0
 public MenuBar(List<MenuElement> children, AElement parent, int page)
     : base(parent, page)
 {
     if (children == null)
         m_Elements = new List<MenuElement>();
     else
         m_Elements = children;
     HandlesMouseInput = true;
 }
Exemple #7
0
        public TabBar(AElement parent, int page, string[] items = null)
            : base(parent, page)
        {
            HandlesMouseInput = true;

            if (items != null)
                foreach (string item in items)
                    AddTab(item);
        }
Exemple #8
0
 public ACompiledScript(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
     lock (_rand)
     {
         _className    = _NextName();
         _functionName = _NextName();
     }
 }
Exemple #9
0
        public Property(string propertyValue, AElement element, PropertyInfo propertyInfo)
        {
            PropertyName = element.Name;

            PropertyValue = propertyValue;

            Element = element;

            PropertyInfo = propertyInfo;
        }
Exemple #10
0
        public static Property InitProperty(IAutoviewDto autoviewDto, AElement element, ModelStateDictionary modelstate)
        {
            PropertyInfo getPropertyInfo = GetPropertyInfoOfDtoByName(autoviewDto, propertyName: element.Name);

            string getPropertyValue = Extensions.GetPropertyValue(autoviewDto, propertyInfo: getPropertyInfo);

            var newProperty = new Property(propertyValue: getPropertyValue, element, propertyInfo: getPropertyInfo);

            InitPropertyErrors(property: ref newProperty, modelstate);

            newProperty.Element = newProperty.Element.InitialElement(property: newProperty);

            return(newProperty);
        }
    private void OnTriggerEnter(Collider collider)
    {
        // Check if other is AElement
        AElement other = collider.GetComponent <AElement>();

        if (other != null)
        {
            // React with other's element
            ElementalReaction(other.Element);

            // Destroy other if it's a Projectile
            //  if (other is ElementalProjectile && other.gameObject.layer != 17)
            //    Destroy(other.gameObject);
        }
    }
Exemple #12
0
    private void OnTriggerEnter(Collider collider)
    {
        AElement other = collider.GetComponent <AElement>();

        if (other != null)
        {
            ElementalReaction(other.Element);

            // Destroy other if it's a Projectile
            if (other is ElementalProjectile)
            {
                Destroy(other.gameObject);
            }
        }
    }
Exemple #13
0
 public void InterpretHREF(HTMLchunk chunk, AElement atom)
 {
     if (chunk.EndClosure)
     {
     }                         // solo anchor elements are meaningless.
     if (!chunk.Closure)
     {
         // opening a hyperlink!
         RecalculateStyle();
         var tag = new OpenTag(chunk);
         _openTags.Add(tag);
         ParseTag(tag, atom);
     }
     else
     {
         RecalculateStyle();  // closing a hyperlink.
     }
 }
Exemple #14
0
        public int GetCaratIndexByPosition(Point pointInText)
        {
            int index = 0;

            if (m_Root == null)
            {
                return(index);
            }
            Rectangle rect = new Rectangle(0, 0, 0, 0);

            for (int i = 0; i < m_Root.Children.Count; i++)
            {
                AElement e = m_Root.Children[i];
                rect.Width  = e.Width;
                rect.Height = e.Height;
                if (rect.Contains(pointInText))
                {
                    return(index);
                }
                if (e.IsThisAtomALineBreak)
                {
                    rect.Width = m_MaxWidth - rect.X;
                    if (rect.Contains(pointInText))
                    {
                        return(e.IsThisAtomInternalOnly ? index - 1 : index);
                    }
                    rect.X  = 0;
                    rect.Y += e.Height;
                }
                if (e.IsThisAtomInternalOnly)
                {
                    index--;
                }
                rect.X += e.Width;
                index++;
            }
            // check for click at bottom of page
            rect = new Rectangle(0, rect.Y, m_MaxWidth, 2000);
            if (rect.Contains(pointInText))
            {
                return(index); // end of the last line
            }
            return(-1);        // don't change
        }
    private void OnTriggerEnter(Collider collider)
    {
        // Check if other is AElement
        AElement other = collider.GetComponent <AElement>();

        if (other != null)
        {
            if (other is ElementalProjectile)
            {
                ElementalProjectile elemProj = other.GetComponent <ElementalProjectile>();
                if (elemProj.InstanceID != gameObject.GetInstanceID())
                {
                    // React with other's element
                    ElementalReaction(other.Element);
                }
            }
            else
            {
                // React with other's element
                ElementalReaction(other.Element);
            }
        }
    }
Exemple #16
0
        void CalculateLayoutWidthsRecursive(BlockElement root)
        {
            int  longestBlockWidth = 0, blockWidth = 0;
            int  longestLineWidth = 0, lineWidth = 0;
            int  styleWidth    = 0;
            bool isLastElement = false;

            for (int i = 0; i < root.Children.Count; i++)
            {
                AElement e = root.Children[i];
                isLastElement = i >= root.Children.Count - 1;
                if (e is BlockElement)
                {
                    e.Width = root.Width;
                    CalculateLayoutWidthsRecursive(e as BlockElement);
                    blockWidth += (e as BlockElement).Layout_MinWidth;
                    lineWidth  += (e as BlockElement).Layout_MaxWidth;
                }
                else
                {
                    if (!e.IsThisAtomABreakingSpace)
                    {
                        blockWidth += e.Width;
                    }
                    if (e.IsThisAtomABreakingSpace || isLastElement)
                    {
                        if (blockWidth > root.Width)
                        {
                            int restartAtIndex, restartBlockWidth;
                            if (TryReduceBlockWidth(root, i - 1, blockWidth + styleWidth, out restartAtIndex, out restartBlockWidth))
                            {
                                i          = restartAtIndex - 1;
                                blockWidth = restartBlockWidth;
                                lineWidth  = restartBlockWidth;
                                continue;
                            }
                        }
                        if (blockWidth + styleWidth > longestBlockWidth)
                        {
                            longestBlockWidth = blockWidth + styleWidth;
                        }
                        blockWidth = 0;
                    }
                    lineWidth += e.Width;
                    if (e.Style.ExtraWidth > styleWidth)
                    {
                        styleWidth = e.Style.ExtraWidth;
                    }
                }
                if (e.IsThisAtomALineBreak || isLastElement)
                {
                    if (blockWidth + styleWidth > longestBlockWidth)
                    {
                        longestBlockWidth = blockWidth + styleWidth;
                    }
                    if (lineWidth + styleWidth > longestLineWidth)
                    {
                        longestLineWidth = lineWidth + styleWidth;
                    }
                    blockWidth = 0;
                    lineWidth  = 0;
                    styleWidth = 0;
                }
            }
            root.Layout_MinWidth = longestBlockWidth;
            root.Layout_MaxWidth = longestLineWidth;
        }
Exemple #17
0
        // ============================================================================================================
        // Parse and create boxes
        // ============================================================================================================

        BlockElement ParseHtmlToBlocks(string html)
        {
            IResourceProvider provider = Service.Get <IResourceProvider>();
            StyleParser       styles = new StyleParser(provider);
            BlockElement      root, currentBlock;

            root = currentBlock = new BlockElement("root", styles.Style); // this is the root!
            // if this is not HTML, do not parse tags. Otherwise search out and interpret tags.
            bool parseHTML = true;

            if (!parseHTML)
            {
                for (int i = 0; i < html.Length; i++)
                {
                    currentBlock.AddAtom(new CharacterElement(styles.Style, html[i]));
                }
            }
            else
            {
                m_Parser.Init(html);
                HTMLchunk chunk;
                while ((chunk = ParseNext(m_Parser)) != null)
                {
                    if (!(chunk.oHTML == string.Empty))
                    {
                        // This is a span of text.
                        string text = chunk.oHTML;
                        // make sure to replace escape characters!
                        text = EscapeCharacters.ReplaceEscapeCharacters(text);
                        //Add the characters to the current box
                        for (int i = 0; i < text.Length; i++)
                        {
                            currentBlock.AddAtom(new CharacterElement(styles.Style, text[i]));
                        }
                    }
                    else
                    {
                        // This is a tag. interpret the tag and edit the openTags list.
                        // It may also be an atom, in which case we should add it to the list of atoms!
                        AElement atom = null;
                        if (chunk.bClosure && !chunk.bEndClosure)
                        {
                            styles.CloseOneTag(chunk);
                            if (currentBlock.Tag == chunk.sTag)
                            {
                                currentBlock = currentBlock.Parent;
                            }
                        }
                        else
                        {
                            bool isBlockTag = false;
                            switch (chunk.sTag)
                            {
                            // ====================================================================================
                            // Anchor elements are added to the open tag collection as HREFs.
                            case "a":
                                styles.InterpretHREF(chunk, null);
                                break;

                            // ====================================================================================
                            // These html elements are ignored.
                            case "body":
                                break;

                            // ====================================================================================
                            // These html elements are blocks but can also have styles
                            case "center":
                            case "left":
                            case "right":
                            case "div":
                                atom = new BlockElement(chunk.sTag, styles.Style);
                                styles.ParseTag(chunk, atom);
                                isBlockTag = true;
                                break;

                            // ====================================================================================
                            // These html elements are styles, and are added to the StyleParser.
                            case "span":
                            case "font":
                            case "b":
                            case "i":
                            case "u":
                            case "outline":
                            case "big":
                            case "basefont":
                            case "medium":
                            case "small":
                                styles.ParseTag(chunk, null);
                                break;

                            // ====================================================================================
                            // These html elements are added as atoms only. They cannot impart style
                            // onto other atoms.
                            case "br":
                                atom = new CharacterElement(styles.Style, '\n');
                                break;

                            case "gumpimg":
                                // draw a gump image
                                atom = new ImageElement(styles.Style, ImageElement.ImageTypes.UI);
                                styles.ParseTag(chunk, atom);
                                break;

                            case "itemimg":
                                // draw a static image
                                atom = new ImageElement(styles.Style, ImageElement.ImageTypes.Item);
                                styles.ParseTag(chunk, atom);
                                break;

                            // ====================================================================================
                            // Every other element is not interpreted, but rendered as text. Easy!
                            default:
                            {
                                string text = html.Substring(chunk.iChunkOffset, chunk.iChunkLength);
                                // make sure to replace escape characters!
                                text = EscapeCharacters.ReplaceEscapeCharacters(text);
                                //Add the characters to the current box
                                for (int i = 0; i < text.Length; i++)
                                {
                                    currentBlock.AddAtom(new CharacterElement(styles.Style, text[i]));
                                }
                            }
                            break;
                            }

                            if (atom != null)
                            {
                                currentBlock.AddAtom(atom);
                                if (isBlockTag && !chunk.bEndClosure)
                                {
                                    currentBlock = (BlockElement)atom;
                                }
                            }
                            styles.CloseAnySoloTags();
                        }
                    }
                }
            }

            return(root);
        }
Exemple #18
0
 public VBScript(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
 public ButtonController(AElement model, GUIManager manager)
     : base(model, manager)
 {
 }
Exemple #20
0
 public Panel(AElement parent, int page)
     : base(parent, page)
 {
 }
Exemple #21
0
        internal static IElement ConstructElementType(XmlElement element, XmlPrefixMap map, AElement parent)
        {
            Type t = null;

            if (BusinessProcess.ElementMapCache != null)
            {
                if (BusinessProcess.ElementMapCache.IsCached(element.Name))
                {
                    t = BusinessProcess.ElementMapCache[element.Name];
                }
                else
                {
                    t = Utility.LocateElementType((parent == null ? null : parent.GetType()), element.Name, map);
                    BusinessProcess.ElementMapCache[element.Name] = t;
                }
            }
            else
            {
                t = Utility.LocateElementType((parent == null ? null : parent.GetType()), element.Name, map);
            }
            if (t != null)
            {
                return((IElement)_xmlConstructors[t].Invoke(new object[] { element, map, parent }));
            }
            return(null);
        }
Exemple #22
0
 public Button(AElement parent, int page)
     : base(parent, page)
 {
     HandlesMouseInput = true;
 }
Exemple #23
0
 public MessageFlow(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
 public TextBoxController(AElement model, GUIManager manager)
     : base(model, manager)
 {
 }
Exemple #25
0
 public CheckBox(AElement parent, int page)
     : base(parent, page)
 {
     HandlesMouseInput = true;
     FontSize = 14f;
 }
Exemple #26
0
 public EscalationEventDefinition(XmlElement elem, XmlPrefixMap map, AElement parent) : base(elem, map, parent)
 {
 }
Exemple #27
0
 public AGateway(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #28
0
 public Bounds(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #29
0
 public TextBox(AElement parent, int page)
     : base(parent, page)
 {
     HandlesMouseInput = true;
     HandlesKeyboardInput = true;
 }
Exemple #30
0
 public Association(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #31
0
        void LayoutElementsHorizontal(BlockElement root, int x, int y, out int ascenderDelta)
        {
            int x0 = x;
            int x1 = x + root.Width;
            int height = 0, lineHeight = 0;

            ascenderDelta = 0;
            int lineBeganAtElementIndex = 0;
            int lineCount = 0;

            for (int i = 0; i < root.Children.Count; i++)
            {
                AElement e0 = root.Children[i];
                if (e0.IsThisAtomALineBreak)
                {
                    // root alignment styles align a root's children elements within the root width.
                    if (root.Alignment == Alignments.Center)
                    {
                        int centerX = x + (x1 - x0) / 2;
                        for (int j = lineBeganAtElementIndex; j < i; j++)
                        {
                            AElement e1 = root.Children[j];
                            e1.Layout_X = centerX;
                            centerX    += e1.Width;
                        }
                    }
                    else if (root.Alignment == Alignments.Right)
                    {
                        int rightX = x1 - x0;
                        for (int j = lineBeganAtElementIndex; j < i; j++)
                        {
                            AElement e1 = root.Children[j];
                            e1.Layout_X = rightX;
                            rightX     += e1.Width;
                        }
                    }
                    e0.Layout_X = x0;
                    e0.Layout_Y = y;
                    if (lineHeight < e0.Height)
                    {
                        lineHeight = e0.Height;
                    }
                    y         += lineHeight;
                    x0         = x;
                    x1         = x + root.Width;
                    height    += lineHeight;
                    lineHeight = 0;
                    lineBeganAtElementIndex = i + 1;
                    lineCount++;
                    if (MaxLineCount > 0 && lineCount >= MaxLineCount)
                    {
                        int index = 0;
                        for (int j = 0; j < i; j++)
                        {
                            index += root.Children[j].IsThisAtomInternalOnly ? 0 : 1;
                        }
                        root.Children.RemoveRange(i, root.Children.Count - i);
                        m_OnPageOverflow?.Invoke(index);
                        break;
                    }
                }
                else
                {
                    int             wordWidth, styleWidth, wordHeight, ascender;
                    List <AElement> word = LayoutElementsGetWord(root.Children, i, out wordWidth, out styleWidth, out wordHeight, out ascender);
                    if (wordWidth + styleWidth > root.Width)
                    {
                        // Can't fit this word on even a full line. Must break it somewhere.
                        // might as well break it as close to the line end as possible.
                        // TODO: For words VERY near the end of the line, we should not break it, but flow to the next line.
                        LayoutElements_BreakWordAtLineEnd(root.Children, i, x1 - x0, word, wordWidth, styleWidth);
                        i--;
                    }
                    else if (x0 + wordWidth + styleWidth > x1)
                    {
                        // This word is too long for this line. Flow it to the next line without breaking, unless it's a space character,
                        // in which case we insert it before the linebreak.
                        // TODO: we should introduce some heuristic that that super long words aren't flowed. Perhaps words
                        // longer than 8 chars, where the break would be after character 3 and before 3 characters from the end?
                        if (word.Count == 1 && word[0].IsThisAtomABreakingSpace)
                        {
                            root.Children.Insert(i + 1, new InternalLineBreakElement(e0.Style));
                        }
                        else
                        {
                            root.Children.Insert(i, new InternalLineBreakElement(e0.Style));
                            i--;
                        }
                    }
                    else
                    {
                        // This word can fit on the current line without breaking. Lay it out!
                        foreach (AElement e1 in word)
                        {
                            if (e1 is BlockElement)
                            {
                                Alignments alignment = (e1 as BlockElement).Alignment;
                                switch (alignment)
                                {
                                case Alignments.Left:
                                    e1.Layout_X = x0;
                                    e1.Layout_Y = y;
                                    x0         += e1.Width;
                                    break;

                                case Alignments.Center:     // centered in the root element, not in the remaining space.
                                    e1.Layout_X = (x + root.Width - e1.Width) / 2;
                                    e1.Layout_Y = y;
                                    break;

                                case Alignments.Right:
                                    e1.Layout_X = x1 - e1.Width;
                                    e1.Layout_Y = y;
                                    x1         -= e1.Width;
                                    break;
                                }
                                LayoutElements((e1 as BlockElement));
                            }
                            else
                            {
                                e1.Layout_X = x0;
                                e1.Layout_Y = y; // -ascender;
                                x0         += e1.Width;
                            }
                        }
                        if (y + ascender < ascenderDelta)
                        {
                            ascenderDelta = y + ascender;
                        }
                        if (wordHeight > lineHeight)
                        {
                            lineHeight = wordHeight;
                        }
                        i += word.Count - 1;
                    }
                }
                if (e0.Height > lineHeight)
                {
                    lineHeight = e0.Height;
                }
            }
            root.Height = height + lineHeight;
        }
 public MenuBarController(AElement model, GUIManager manager)
     : base(model, manager)
 {
 }
Exemple #33
0
 public ATask(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #34
0
 public RadioButton(AElement parent, int page, RadioButtonGroup group)
     : base(parent, page)
 {
     IsDown = false;
     Group = group;
 }
Exemple #35
0
 public ANegatableCondition(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #36
0
 public GreaterThanOrEqualCondition(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #37
0
 public Participant(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #38
0
 public AScript(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
     _map = map;
 }
Exemple #39
0
 public EndEvent(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #40
0
 public static void InitalElement(this IAutoviewDto autoviewDto, AElement element)
 {
     Mainboard.Elements.Add(item: element);
 }
Exemple #41
0
 public Plane(XmlElement elem, XmlPrefixMap map, AElement parent)
     : base(elem, map, parent)
 {
 }
Exemple #42
0
 public Label(AElement parent, int page, string caption)
     : base(parent, page)
 {
     Caption = caption;
 }