/// <summary>
        /// append the text string \a text to the RenderedString \a rs.
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="text"></param>
        private void AppendRenderedText(RenderedString rs, string text)
        {
            var cpos = 0;

            // split the given string into lines based upon the newline character
            while (text.Length > cpos)
            {
                // find next newline
                var nlpos = text.IndexOf("\n", cpos);
                // calculate length of this substring
                var len = ((nlpos != -1) ? nlpos : text.Length) - cpos;

                // construct new text component and append it.
                var rtc = new RenderedStringTextComponent(text.Substring(cpos, len), d_fontName);
                rtc.SetPadding(d_padding);
                rtc.SetColours(new ColourRect(d_colours));
                rtc.SetVerticalFormatting(d_vertAlignment);
                rtc.SetAspectLock(d_aspectLock);
                rs.AppendComponent(rtc);

                // break line if needed
                if (nlpos != -1)
                {
                    rs.AppendLineBreak();
                }

                // advance current position.  +1 to skip the \n char
                cpos += len + 1;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public RenderedString Clone()
        {
            var rs = new RenderedString();

            rs.CloneComponentList(d_components);
            rs.CloneTrackInfoList(d_lines);
            return(rs);
        }
        private void HandleWindow(RenderedString rs, string value)
        {
            var rwc = new RenderedStringWidgetComponent(value);

            rwc.SetPadding(d_padding);
            rwc.SetVerticalFormatting(d_vertAlignment);
            rwc.SetAspectLock(d_aspectLock);
            rs.AppendComponent(rwc);
        }
Esempio n. 4
0
        /// <summary>
        /// helper to set up an appropriate FormattedRenderedString
        /// </summary>
        /// <param name="window"></param>
        /// <param name="renderedString"></param>
        protected void SetupStringFormatter(Window window, RenderedString renderedString)
        {
            var horzFormatting = _horzFormatting.Get(window);

            // no formatting change
            if (horzFormatting == _lastHorizontalFormatting)
            {
                _formattedRenderedString.SetRenderedString(renderedString);
                return;
            }

            _lastHorizontalFormatting = horzFormatting;

            switch (horzFormatting)
            {
            case HorizontalTextFormatting.LeftAligned:
                _formattedRenderedString = new LeftAlignedRenderedString(renderedString);
                break;

            case HorizontalTextFormatting.CentreAligned:
                _formattedRenderedString = new CentredRenderedString(renderedString);
                break;

            case HorizontalTextFormatting.RightAligned:
                _formattedRenderedString = new RightAlignedRenderedString(renderedString);
                break;

            case HorizontalTextFormatting.Justified:
                _formattedRenderedString = new JustifiedRenderedString(renderedString);
                break;

            case HorizontalTextFormatting.WordWrapLeftAligned:
                _formattedRenderedString =
                    new RenderedStringWordWrapper <LeftAlignedRenderedString>(renderedString);
                //new RenderedStringWordWrapper<LeftAlignedRenderedString>(rendered_string, rs => new LeftAlignedRenderedString(rs));
                break;

            case HorizontalTextFormatting.WordWrapCentreAligned:
                _formattedRenderedString =
                    new RenderedStringWordWrapper <CentredRenderedString>(renderedString);
                //new RenderedStringWordWrapper<CentredRenderedString>(rendered_string, rs => new CentredRenderedString(rs));
                break;

            case HorizontalTextFormatting.WordWrapRightAligned:
                _formattedRenderedString =
                    new RenderedStringWordWrapper <RightAlignedRenderedString>(renderedString);
                //new RenderedStringWordWrapper<RightAlignedRenderedString>(rendered_string, rs => new RightAlignedRenderedString(rs));
                break;

            case HorizontalTextFormatting.WordWrapJustified:
                _formattedRenderedString =
                    new RenderedStringWordWrapper <JustifiedRenderedString>(renderedString);
                //new RenderedStringWordWrapper<JustifiedRenderedString>(rendered_string, rs => new JustifiedRenderedString(rs));
                break;
            }
        }
        private void HandleImage(RenderedString rs, string value)
        {
            var ric = new RenderedStringImageComponent(PropertyHelper.FromString <Image>(value));

            ric.SetPadding(d_padding);
            ric.SetColours(d_colours);
            ric.SetVerticalFormatting(d_vertAlignment);
            ric.SetSize(d_imageSize);
            ric.SetAspectLock(d_aspectLock);
            rs.AppendComponent(ric);
        }
Esempio n. 6
0
        // TODO: Destructor.
        // TODO: ~RenderedStringWordWrapper(){DeleteFormatters();}

        // implementation of base interface

        // TODO: specialised version of format used with Justified text
        public override void Format(Window refWnd, Sizef areaSize)
        {
            DeleteFormatters();

            var lstring = new RenderedString();
            var rstring = new RenderedString(d_renderedString);

            T frs;

            for (var line = 0; line < rstring.GetLineCount(); ++line)
            {
                float rsWidth;
                while ((rsWidth = rstring.GetPixelSize(refWnd, line).Width) > 0)
                {
                    // skip line if no wrapping occurs
                    if (rsWidth <= areaSize.Width)
                    {
                        break;
                    }

                    // split rstring at width into lstring and remaining rstring
                    rstring.Split(refWnd, line, areaSize.Width, lstring);
                    //frs = _constructor(new RenderedString(lstring));
                    frs = new T();
                    frs.SetRenderedString(new RenderedString(lstring));
                    frs.Format(refWnd, areaSize);
                    Lines.Add(frs);
                    line = 0;
                }
            }

            // last line.
            //frs = _constructor(new RenderedString(rstring));
            frs = new T();
            frs.SetRenderedString(new RenderedString(rstring));
            frs.Format(refWnd, areaSize);
            Lines.Add(frs);
        }
 private void HandleVertAlignment(RenderedString rs, string value)
 {
     if (value == TopAlignedValueName)
     {
         d_vertAlignment = VerticalFormatting.TopAligned;
     }
     else if (value == BottomAlignedValueName)
     {
         d_vertAlignment = VerticalFormatting.BottomAligned;
     }
     else if (value == CentreAlignedValueName)
     {
         d_vertAlignment = VerticalFormatting.CentreAligned;
     }
     else if (value == StretchAlignedValueName)
     {
         d_vertAlignment = VerticalFormatting.Stretched;
     }
     else
     {
         System.GetSingleton().Logger.LogEvent("BasicRenderedStringParser::handleVertAlignment: unknown " +
                                               "vertical alignment '" + value + "'.  Ignoring!");
     }
 }
        /// <summary>
        /// Process the control string \a ctrl_str.
        /// </summary>
        /// <param name="rs"></param>
        /// <param name="ctrlStr"></param>
        private void ProcessControlString(RenderedString rs, string ctrlStr)
        {
            // all our default strings are of the form <var> = <val>
            // so do a quick check for the = char and abort if it's not there.
            if (-1 == ctrlStr.IndexOf("="))
            {
                System.GetSingleton().Logger.LogEvent(
                    "BasicRenderedStringParser.ProcessControlString: unable to make " +
                    "sense of control string '" + ctrlStr + "'.  Ignoring!");

                return;
            }

            //char var_buf[128];
            //char val_buf[128];
            //sscanf(ctrl_str.c_str(), " %127[^ =] = '%127[^']", var_buf, val_buf);

            //const String var_str(var_buf);
            //const String val_str(val_buf);

            var values = ctrlStr.Split('=');
            var varStr = values[0];
            var valStr = values[1].Trim('\'');

            // look up handler function and
            // despatch handler, or log error
            if (_tagHandlers.ContainsKey(varStr))
            {
                _tagHandlers[varStr](rs, valStr);
            }
            else
            {
                System.GetSingleton().Logger.LogEvent("BasicRenderedStringParser::processControlString: unknown " +
                                                      "control variable '" + varStr + "'.  Ignoring!");
            }
        }
 private void HandleImageHeight(RenderedString rs, string value)
 {
     d_imageSize.Height = Single.Parse(value);
 }
Esempio n. 10
0
        /// <summary>
        /// split the string in line \a line as close to \a split_point as possible.
        /// <para>
        /// The RenderedString \a left will receive the left portion of the split,
        /// while the right portion of the split will remain in this RenderedString.
        /// </para>
        /// </summary>
        /// <param name="refWnd"></param>
        /// <param name="line">
        /// The line number on which the split is to occur.
        /// </param>
        /// <param name="splitPoint">
        /// float value specifying the pixel location where the split should occur.
        /// The actual split will occur as close to this point as possible, though
        /// preferring a shorter 'left' portion when the split can not be made
        /// exactly at the requested point.
        /// </param>
        /// <param name="left">
        /// RenderedString object that will receieve the left portion of the split.
        /// Any existing content in the RenderedString is replaced.
        /// </param>
        /// <exception cref="InvalidRequestException">
        /// thrown if \a line is out of range.
        /// </exception>
        public void Split(Window refWnd, int line, float splitPoint, RenderedString left)
        {
            // FIXME: This function is big and nasty; it breaks all the rules for a
            // 'good' function and desperately needs some refactoring work done to it.
            // On the plus side, it does seem to work though ;)

            if (line >= GetLineCount())
            {
                throw new InvalidRequestException("line number specified is invalid.");
            }

            left.ClearComponents();

            if (d_components.Count == 0)
            {
                return;
            }

            // move all components in lines prior to the line being split to the left
            if (line > 0)
            {
                // calculate size of range
                var sz = d_lines[line - 1].First + d_lines[line - 1].Second;

                //// range start
                //ComponentList::iterator cb = d_components.begin();
                //// range end (exclusive)
                //ComponentList::iterator ce = cb + sz;
                //// copy components to left side
                //left.d_components.assign(cb, ce);
                //// erase components from this side.
                //d_components.erase(cb, ce);
                for (int i = 0; i < sz; i++)
                {
                    left.d_components.Add(d_components[0]);
                    d_components.RemoveAt(0);
                }

                //LineList::iterator lb = d_lines.begin();
                //LineList::iterator le = lb + line;
                //// copy lines to left side
                //left.d_lines.assign(lb, le);
                //// erase lines from this side
                //d_lines.erase(lb, le);
                for (int i = 0; i < line; i++)
                {
                    left.d_lines.Add(d_lines[0]);
                    d_lines.RemoveAt(0);
                }
            }

            // find the component where the requested split point lies.
            var partialExtent = 0f;

            var idx           = 0;
            var lastComponent = d_lines[0].Second;

            for (; idx < lastComponent; ++idx)
            {
                partialExtent += d_components[idx].GetPixelSize(refWnd).Width;

                if (splitPoint <= partialExtent)
                {
                    break;
                }
            }

            // case where split point is past the end
            if (idx >= lastComponent)
            {
                // transfer this line's components to the 'left' string.
                //
                // calculate size of range
                var sz = d_lines[0].Second;
                //// range start
                //ComponentList::iterator cb = d_components.begin();
                //// range end (exclusive)
                //ComponentList::iterator ce = cb + sz;
                //// copy components to left side
                //left.d_components.insert(left.d_components.end(), cb, ce);
                //// erase components from this side.
                //d_components.erase(cb, ce);
                for (int i = 0; i < sz; i++)
                {
                    left.d_components.Add(d_components[0]);
                    d_components.RemoveAt(0);
                }

                // copy line info to left side
                left.d_lines.Add(d_lines[0]);
                // erase line from this side
                d_lines.RemoveAt(0);

                // fix up lines in this object
                for (int comp = 0, i = 0; i < d_lines.Count; ++i)
                {
                    d_lines[i].First = comp;
                    comp            += d_lines[i].Second;
                }

                return;
            }

            left.AppendLineBreak();
            var leftLine = left.GetLineCount() - 1;

            // Everything up to 'idx' is xfered to 'left'
            for (var i = 0; i < idx; ++i)
            {
                left.d_components.Add(d_components[0]);
                d_components.RemoveAt(0);
                ++left.d_lines[leftLine].Second;
                --d_lines[0].Second;
            }

            // now to split item 'idx' putting half in left and leaving half in this.
            RenderedStringComponent c = d_components[0];

            if (c.CanSplit())
            {
                var lc = c.Split(refWnd, splitPoint - (partialExtent - c.GetPixelSize(refWnd).Width), idx == 0);

                if (lc != null)
                {
                    left.d_components.Add(lc);
                    ++left.d_lines[leftLine].Second;
                }
            }
            // can't split, if component width is >= split_point xfer the whole
            // component to it's own line in the left part (FIX #306)
            else if (c.GetPixelSize(refWnd).Width >= splitPoint)
            {
                left.AppendLineBreak();
                left.d_components.Add(d_components[0]);
                d_components.RemoveAt(0);
                ++left.d_lines[leftLine + 1].Second;
                --d_lines[0].Second;
            }

            // fix up lines in this object
            for (int comp = 0, i = 0; i < d_lines.Count; ++i)
            {
                d_lines[i].First = comp;
                comp            += d_lines[i].Second;
            }
        }
 public RightAlignedRenderedString(RenderedString @string)
     : base(@string)
 {
 }
Esempio n. 12
0
 protected FormattedRenderedString(RenderedString @string)
 {
     d_renderedString = @string;
 }
 private void HandlePadding(RenderedString rs, string value)
 {
     d_padding = PropertyHelper.FromString <Rectf>(value);
 }
 private void HandleFont(RenderedString rs, string value)
 {
     d_fontName = value;
 }
 private void HandleColour(RenderedString rs, string value)
 {
     d_colours.SetColours(PropertyHelper.FromString <Colour>(value));
 }
Esempio n. 16
0
 public LeftAlignedRenderedString(RenderedString @string)
     : base(@string)
 {
 }
Esempio n. 17
0
 /// <summary>
 /// set the RenderedString.
 /// </summary>
 /// <param name="string"></param>
 public void SetRenderedString(RenderedString @string)
 {
     d_renderedString = @string;
 }
 private void HandleBottomPadding(RenderedString rs, string value)
 {
     d_padding.d_max.Y = Single.Parse(value);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="string"></param>
 public CentredRenderedString(RenderedString @string)
     : base(@string)
 {
 }
 private void HandleLeftPadding(RenderedString rs, string value)
 {
     d_padding.d_min.X = Single.Parse(value);
 }
Esempio n. 21
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="string"></param>
 /// <param name="constructor"></param>
 public RenderedStringWordWrapper(RenderedString @string /*, Func<RenderedString, T> constructor*/)
     : base(@string)
 {
     //_constructor = constructor;
 }
 private void HandleRightPadding(RenderedString rs, string value)
 {
     d_padding.d_max.X = Single.Parse(value);
 }
 private void HandleAspectLock(RenderedString rs, string value)
 {
     d_aspectLock = Boolean.Parse(value);
 }
 private void HandleImageSize(RenderedString rs, string value)
 {
     d_imageSize = PropertyHelper.FromString <Sizef>(value);
 }
Esempio n. 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="other"></param>
 public RenderedString(RenderedString other)
 {
     CloneComponentList(other.d_components);
     CloneTrackInfoList(other.d_lines);
 }
 private void HandleImageWidth(RenderedString rs, string value)
 {
     d_imageSize.Width = Single.Parse(value);
 }
Esempio n. 27
0
 public JustifiedRenderedString(RenderedString @string)
     : base(@string)
 {
 }
        public RenderedString Parse(string inputString, Font initialFont, ColourRect initialColours)
        {
            if (inputString == null)
            {
                inputString = String.Empty;
            }

            // first-time initialisation (due to issues with static creation order)
            if (!d_initialised)
            {
                InitialiseTagHandlers();
            }

            InitialiseDefaultState();

            // maybe override initial font.
            if (initialFont != null)
            {
                d_fontName = initialFont.GetName();
            }

            // maybe override initial colours.
            if (initialColours != null)
            {
                d_colours = new ColourRect(initialColours);
            }

            var rs          = new RenderedString();
            var currSection = new StringBuilder();
            var tagString   = new StringBuilder();

            for (int inputIter = 0; inputIter < inputString.Length;)
            {
                var foundTag = ParseSection(inputString, ref inputIter, inputString.Length, '[', currSection);
                AppendRenderedText(rs, currSection.ToString());

                if (!foundTag)
                {
                    return(rs);
                }

                if (!ParseSection(inputString, ref inputIter, inputString.Length, ']', tagString))
                {
                    System.GetSingleton().Logger.LogEvent(
                        "BasicRenderedStringParser.Parse: Ignoring unterminated tag : [" + tagString);

                    return(rs);
                }

                ProcessControlString(rs, tagString.ToString());
            }

            //for (String::const_iterator input_iter(input_string.begin());
            //     input_iter != input_string.end();
            //     /* no-op*/)
            //{
            //    const bool found_tag = parse_section(input_iter, input_string.end(), '[', curr_section);
            //    appendRenderedText(rs, curr_section);

            //    if (!found_tag)
            //        return rs;

            //    if (!parse_section(input_iter, input_string.end(), ']', tag_string))
            //    {
            //        Logger::getSingleton().logEvent(
            //            "BasicRenderedStringParser::parse: Ignoring unterminated tag : [" +
            //            tag_string);

            //        return rs;
            //    }

            //    processControlString(rs, tag_string);
            //}

            return(rs);
        }