public override void SetWidth(StringMeasure sm, float subPixel)
        {
            var widF = subPixel + WidthF;

            Width     = (int)widF;
            XsubPixel = widF - Width;
        }
Exemple #2
0
 public ConsoleDisplayLine[] Flush(StringMeasure stringMeasure, bool temporary)
 {
     fromCssToButton();
     ConsoleDisplayLine[] ret = PrintStringBuffer.ButtonsToDisplayLines(m_buttonList, stringMeasure, false, temporary);
     this.clearBuffer();
     return(ret);
 }
Exemple #3
0
        public override void SetWidth(StringMeasure sm, float subPixel)
        {
            float widF = (subPixel + WidthF);

            Width     = (int)(widF);
            XsubPixel = widF - Width;
        }
Exemple #4
0
        private static int getDivideIndex(ConsoleButtonString button, StringMeasure sm)
        {
            AConsoleDisplayPart divCss = null;
            int pointX    = button.PointX;
            int strLength = 0;
            int index     = 0;

            foreach (AConsoleDisplayPart css in button.StrArray)
            {
                if (pointX + css.Width > Config.DrawableWidth)
                {
                    if (index == 0 && !css.CanDivide)
                    {
                        continue;
                    }
                    divCss = css;
                    break;
                }
                index++;
                strLength += css.Str.Length;
                pointX    += css.Width;
            }
            if (divCss != null)
            {
                int cssDivIndex = getDivideIndex(divCss, sm);
                if (cssDivIndex > 0)
                {
                    strLength += cssDivIndex;
                }
            }
            return(strLength);
        }
 //indexの文字数の前方文字列とindex以降の後方文字列に分割
 public ConsoleStyledString DivideAt(int index, StringMeasure sm)
 {
     if ((index <= 0)||(index > Str.Length))
         return null;
     ConsoleStyledString ret = DivideAt(index);
     ret.SetWidth(sm);
     this.SetWidth(sm);
     return ret;
 }
 public override void SetWidth(StringMeasure sm, float subPixel)
 {
     if (Error)
     {
         Width = 0;
         return;
     }
     Width     = sm.GetDisplayLength(Str, Font);
     XsubPixel = subPixel;
 }
Exemple #7
0
        public ConsoleDisplayLine FlushSingleLine(StringMeasure stringMeasure, bool temporary)
        {
            fromCssToButton();
            setWidthToButtonList(m_buttonList, stringMeasure, true);
            ConsoleButtonString[] dispLineButtonArray = new ConsoleButtonString[m_buttonList.Count];
            m_buttonList.CopyTo(dispLineButtonArray);
            ConsoleDisplayLine line = new ConsoleDisplayLine(dispLineButtonArray, true, temporary);

            this.clearBuffer();
            return(line);
        }
Exemple #8
0
        public override void SetWidth(StringMeasure sm, float subPixel)
        {
            float widF = (subPixel + WidthF);

            Width      = (int)(widF);
            XsubPixel  = widF - Width;
            rect.X     = (int)(subPixel + originalRectF.X);
            rect.Width = Width - rect.X;
            rect.X    += Config.DrawingParam_ShapePositionShift;
            visible    = (rect.X >= 0 && rect.Width > 0);         // && rect.Y >= 0 && (rect.Y + rect.Height) <= Config.FontSize);
        }
Exemple #9
0
		public override void SetWidth(StringMeasure sm, float subPixel)
		{
			if (this.Error)
			{
				Width = 0;
				return;
			}
			if (cImage != null)
				return;
			Width = sm.GetDisplayLength(Str, Config.Font);
			XsubPixel = subPixel;
		}
Exemple #10
0
        private void calcPrintCWidth(StringMeasure stringMeasure)
        {
            string str  = new string(' ', Config.PrintCLength);
            Font   font = Config.Font;

            printCWidth = stringMeasure.GetDisplayLength(str, font);

            str         += " ";
            printCWidthL = stringMeasure.GetDisplayLength(str, font);

            str          += " ";
            printCWidthL2 = stringMeasure.GetDisplayLength(str, font);
        }
Exemple #11
0
 public ConsoleDisplayLine AppendAndFlushErrButton(string str, StringStyle style, string input,
                                                   ScriptPosition pos, StringMeasure sm)
 {
     fromCssToButton();
     m_stringList.Add(new ConsoleStyledString(str, style));
     if (m_stringList.Count == 0)
     {
         return(null);
     }
     m_buttonList.Add(createButton(m_stringList, input, pos));
     m_stringList.Clear();
     return(FlushSingleLine(sm, false));
 }
        //単一のボタンフラグ
        //public bool IsButton { get; set; }
        //indexの文字数の前方文字列とindex以降の後方文字列に分割
        public ConsoleStyledString DivideAt(int index, StringMeasure sm)
        {
            //if ((index <= 0)||(index > Str.Length)||this.Error)
            //	return null;
            var ret = DivideAt(index);

            if (ret == null)
            {
                return(null);
            }
            SetWidth(sm, XsubPixel);
            ret.SetWidth(sm, XsubPixel);
            return(ret);
        }
Exemple #13
0
        private static int getDivideIndex(AConsoleDisplayPart part, StringMeasure sm)
        {
            if (!part.CanDivide)
            {
                return(-1);
            }
            ConsoleStyledString css = part as ConsoleStyledString;

            if (part == null)
            {
                return(-1);
            }
            int    widthLimit = Config.DrawableWidth - css.PointX;
            string str        = css.Str;
            Font   font       = css.Font;
            int    point      = 0;
            int    highLength = str.Length; //widthLimitを超える最低の文字index(文字数-1)。
            int    lowLength  = 0;          //超えない最大の文字index。
            //int i = (int)(widthLimit / fontDisplaySize);//およその文字数を推定
            //if (i > str.Length - 1)//配列の外を参照しないように。
            //	i = str.Length - 1;
            int i = lowLength;            //およその文字数を推定←やめた

            string test = null;

            while ((highLength - lowLength) > 1)            //差が一文字以下になるまで繰り返す。
            {
                test  = str.Substring(0, i);
                point = sm.GetDisplayLength(test, font);
                if (point <= widthLimit)                //サイズ内ならlowLengthを更新。文字数を増やす。
                {
                    lowLength = i;
                    i++;
                }
                else                //サイズ外ならhighLengthを更新。文字数を減らす。
                {
                    highLength = i;
                    i--;
                }
            }
            return(lowLength);
        }
 public void CalcWidth(StringMeasure sm, float subpixel)
 {
     Width = -1;
     if ((strArray != null) && (strArray.Length > 0))
     {
         Width = 0;
         foreach (AConsoleDisplayPart css in strArray)
         {
             if (css.Width <= 0)
             {
                 css.SetWidth(sm, subpixel);
             }
             Width   += css.Width;
             subpixel = css.XsubPixel;
         }
         if (Width <= 0)
         {
             Width = -1;
         }
     }
     XsubPixel = subpixel;
 }
Exemple #15
0
 public void CalcWidth(StringMeasure sm, float subpixel)
 {
     Width = -1;
     if (StrArray != null && StrArray.Length > 0)
     {
         Width = 0;
         foreach (var css in StrArray)
         {
             if (css.Width <= 0)
             {
                 css.SetWidth(sm, subpixel);
             }
             Width   += css.Width;
             subpixel = css.XsubPixel;
         }
         if (Width <= 0)
         {
             Width = -1;
         }
     }
     XsubPixel = subpixel;
 }
 public ConsoleDisplayLine FlushSingleLine(StringMeasure stringMeasure, bool temporary)
 {
     fromCssToButton();
     setLengthToButtonList(stringMeasure);
     ConsoleButtonString[] dispLineButtonArray = new ConsoleButtonString[buttonList.Count];
     buttonList.CopyTo(dispLineButtonArray);
     ConsoleDisplayLine line = new ConsoleDisplayLine(parent, dispLineButtonArray, true, temporary);
     this.Clear();
     return line;
 }
 private int getDivideIndex(ConsoleButtonString button, StringMeasure sm)
 {
     ConsoleStyledString divCss = null;
     int pointX = button.PointX;
     int strLength = 0;
     foreach (ConsoleStyledString css in button.StrArray)
     {
         if (pointX + css.Width > Config.WindowX)
         {
             divCss = css;
             break;
         }
         strLength += css.Str.Length;
         pointX += css.Width;
     }
     if (divCss != null)
         strLength += getDivideIndex(divCss, sm);
     return strLength;
 }
        //{ PrintFlush(force, false); }
        //public void PrintFlush(bool force, bool temporary)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="force">バッファーが空のとき改行する</param>
        public void PrintFlush(bool force)
        {
            if (!this.Enabled)
                return;
            if (!force && printBuffer.IsEmpty)
                return;
            if (force && printBuffer.IsEmpty)
                printBuffer.Append(" ", Style);

            StringMeasure stringMeasure = new StringMeasure(getGraphics(), this.bgColor, Config.TextDrawingMode);
            ConsoleDisplayLine[] dispList = printBuffer.Flush(stringMeasure, force_temporary);
            //ConsoleDisplayLine[] dispList = printBuffer.Flush(stringMeasure, temporary | force_temporary);
            stringMeasure.Dispose();
            addRangeDisplayLine(dispList);
            RefreshStrings(false);
        }
        //indexの文字数の前方文字列とindex以降の後方文字列に分割
        public ConsoleButtonString DivideAt(int divIndex, StringMeasure sm)
        {
            if (divIndex <= 0)
            {
                return(null);
            }
            List <AConsoleDisplayPart> cssListA = new List <AConsoleDisplayPart>();
            List <AConsoleDisplayPart> cssListB = new List <AConsoleDisplayPart>();
            int  index    = 0;
            int  cssIndex = 0;
            bool b        = false;

            for (cssIndex = 0; cssIndex < strArray.Length; cssIndex++)
            {
                if (b)
                {
                    cssListB.Add(strArray[cssIndex]);
                    continue;
                }
                int length = strArray[cssIndex].Str.Length;
                if (divIndex < index + length)
                {
                    ConsoleStyledString oldcss = strArray[cssIndex] as ConsoleStyledString;
                    if (oldcss == null || !oldcss.CanDivide)
                    {
                        throw new ExeEE("文字列分割異常");
                    }
                    ConsoleStyledString newCss = oldcss.DivideAt(divIndex - index, sm);
                    cssListA.Add(oldcss);
                    if (newCss != null)
                    {
                        cssListB.Add(newCss);
                    }
                    b = true;
                    continue;
                }
                else if (divIndex == index + length)
                {
                    cssListA.Add(strArray[cssIndex]);
                    b = true;
                    continue;
                }
                index += length;
                cssListA.Add(strArray[cssIndex]);
            }
            if ((cssIndex >= strArray.Length) && (cssListB.Count == 0))
            {
                return(null);
            }
            AConsoleDisplayPart[] cssArrayA = new AConsoleDisplayPart[cssListA.Count];
            AConsoleDisplayPart[] cssArrayB = new AConsoleDisplayPart[cssListB.Count];
            cssListA.CopyTo(cssArrayA);
            cssListB.CopyTo(cssArrayB);
            this.strArray = cssArrayA;
            ConsoleButtonString ret = new ConsoleButtonString(null, cssArrayB);

            this.CalcWidth(sm, XsubPixel);
            ret.CalcWidth(sm, 0);
            this.CalcPointX(this.PointX);
            ret.CalcPointX(this.PointX + this.Width);
            ret.parent     = this.parent;
            ret.ParentLine = this.ParentLine;
            ret.IsButton   = this.IsButton;
            ret.IsInteger  = this.IsInteger;
            ret.Input      = this.Input;
            ret.Inputs     = this.Inputs;
            ret.Generation = this.Generation;
            ret.ErrPos     = this.ErrPos;
            ret.Title      = this.Title;
            return(ret);
        }
 //indexの文字数の前方文字列とindex以降の後方文字列に分割
 public ConsoleButtonString DivideAt(int divIndex, StringMeasure sm)
 {
     if (divIndex <= 0)
         return null;
     List<ConsoleStyledString> cssListA = new List<ConsoleStyledString>();
     List<ConsoleStyledString> cssListB = new List<ConsoleStyledString>();
     int index = 0;
     int cssIndex = 0;
     bool b = false;
     for (cssIndex = 0; cssIndex < strArray.Length; cssIndex++)
     {
         if (b)
         {
             cssListB.Add(strArray[cssIndex]);
             continue;
         }
         int length = strArray[cssIndex].Str.Length;
         if (divIndex < index + length)
         {
             ConsoleStyledString newCss = strArray[cssIndex].DivideAt(divIndex - index, sm);
             cssListA.Add(strArray[cssIndex]);
             if (newCss != null)
                 cssListB.Add(newCss);
             b = true;
             continue;
         }
         else if (divIndex == index + length)
         {
             cssListA.Add(strArray[cssIndex]);
             b = true;
             continue;
         }
         index += length;
         cssListA.Add(strArray[cssIndex]);
     }
     if((cssIndex >= strArray.Length) && (cssListB.Count == 0))
         return null;
     ConsoleStyledString[] cssArrayA = new ConsoleStyledString[cssListA.Count];
     ConsoleStyledString[] cssArrayB = new ConsoleStyledString[cssListB.Count];
     cssListA.CopyTo(cssArrayA);
     cssListB.CopyTo(cssArrayB);
     this.strArray = cssArrayA;
     ConsoleButtonString ret = null;
     if (this.IsButton)
         ret = new ConsoleButtonString(this.parent, cssArrayB, this.Input);
     else
         ret = new ConsoleButtonString(this.parent, cssArrayB);
     this.SetWidth(sm);
     ret.SetWidth(sm);
     return ret;
 }
Exemple #21
0
 /// <summary>
 /// 1810beta003新規 マークアップ用 Append とFlushを同時にやる
 /// </summary>
 /// <param name="str"></param>
 /// <param name="stringMeasure"></param>
 /// <returns></returns>
 public ConsoleDisplayLine[] PrintHtml(string str, StringMeasure stringMeasure)
 {
     throw new NotImplementedException();
 }
 public void SetWidth(StringMeasure sm)
 {
     Width = -1;
     if ((strArray != null) && (strArray.Length > 0))
     {
         Width = 0;
         foreach (ConsoleStyledString css in strArray)
         {
             css.SetWidth(sm);
             Width += css.Width;
         }
         if (Width <= 0)
             Width = -1;
     }
 }
 internal ConsoleDisplayLine PrintPlainwithSingleLine(string str)
 {
     if (!this.Enabled)
         return null;
     if (string.IsNullOrEmpty(str))
         return null;
     printBuffer.AppendPlainText(str, Style);
     StringMeasure stringMeasure = new StringMeasure(getGraphics(), this.bgColor, Config.TextDrawingMode);
     ConsoleDisplayLine dispLine = printBuffer.FlushSingleLine(stringMeasure, false);
     stringMeasure.Dispose();
     return dispLine;
 }
Exemple #24
0
 public abstract void SetWidth(StringMeasure sm, float subPixel);
 private int getDivideIndex(ConsoleStyledString css, StringMeasure sm)
 {
     int widthLimit = Config.WindowX - css.PointX;
     string str = css.Str;
     Font font = css.Font;
     int point = 0;
     int highLength = str.Length - 1;//widthLimitを超える最低の文字index(文字数-1)。
     int lowLength = 0;//超えない最大の文字index。
     //int i = (int)(widthLimit / fontDisplaySize);//およその文字数を推定
     int i = 0;//およその文字数を推定
     if (i > str.Length - 1)//配列の外を参照しないように。
         i = str.Length - 1;
     string test = null;
     while ((highLength - lowLength) > 1)//差が一文字以下になるまで繰り返す。
     {
         test = str.Substring(0, i);
         point = sm.GetDisplayLength(test, font);
         if (point <= widthLimit)//サイズ内ならlowLengthを更新。文字数を増やす。
         {
             lowLength = i;
             i++;
         }
         else//サイズ外ならhighLengthを更新。文字数を減らす。
         {
             highLength = i;
             i--;
         }
     }
     return lowLength;
 }
 //stringListにPointX、Widthを追加
 private void setLengthToButtonList(StringMeasure stringMeasure)
 {
     int pointX = 0;
     int count = buttonList.Count;
     for (int i = 0; i < buttonList.Count; i++)
     {
         ConsoleButtonString button = buttonList[i];
         button.SetWidth(stringMeasure);
         button.SetPointX(pointX);
         pointX += button.Width;
         //if (!devide)//分割を行わないならどんどん追加していく
         //    continue;
         //while (pointX > StaticConfig.WindowX)
         //{//はみ出た
         //    int divideIndex = getDivideIndex(css, stringMeasure);
         //    if (divideIndex <= 0)
         //    {//分割不要。全部次の行に移動。
         //        css.PointX = 0;
         //        pointX = css.Width;
         //    }
         //    else if (divideIndex >= css.Str.Length)
         //    {//分割不要。全部その行に収まる
         //        pointX = 0;
         //        break;
         //    }
         //    else
         //    {//分割必要。divideIndex以降を次の行に移動。
         //        ConsoleStyledString newCss = css.DivideAt(divideIndex, stringMeasure);
         //        newCss.PointX = 0;
         //        pointX = newCss.Width;
         //        stringList.Insert(i + dividedCount + 1, newCss);
         //        dividedCount++;
         //    }
         //    css = stringList[i + dividedCount];
         //}
     }
 }
Exemple #27
0
        /// <summary>
        /// htmlから表示行の作成
        /// </summary>
        /// <param name="str">htmlテキスト</param>
        /// <param name="sm"></param>
        /// <param name="console">実際の表示に使わないならnullにする</param>
        /// <returns></returns>
        public static ConsoleDisplayLine[] Html2DisplayLine(string str, StringMeasure sm, EmueraConsole console)
        {
            List <AConsoleDisplayPart> cssList    = new List <AConsoleDisplayPart>();
            List <ConsoleButtonString> buttonList = new List <ConsoleButtonString>();
            StringStream    st = new StringStream(str);
            int             found;
            bool            hasComment = str.IndexOf("<!--") >= 0;
            bool            hasReturn  = str.IndexOf('\n') >= 0;
            HtmlAnalzeState state      = new HtmlAnalzeState();

            while (!st.EOS)
            {
                found = st.Find('<');
                if (hasReturn)
                {
                    int rFound = st.Find('\n');
                    if (rFound >= 0 && (found > rFound || found < 0))
                    {
                        found = rFound;
                    }
                }
                if (found < 0)
                {
                    string txt = Unescape(st.Substring());
                    cssList.Add(new ConsoleStyledString(txt, state.GetSS()));
                    if (state.FlagPClosed)
                    {
                        throw new CodeEE("</p>の後にテキストがあります");
                    }
                    if (state.FlagNobrClosed)
                    {
                        throw new CodeEE("</nobr>の後にテキストがあります");
                    }
                    break;
                }
                else if (found > 0)
                {
                    string txt = Unescape(st.Substring(st.CurrentPosition, found));
                    cssList.Add(new ConsoleStyledString(txt, state.GetSS()));
                    state.LineHead      = false;
                    st.CurrentPosition += found;
                }
                //コメントタグのみ特別扱い
                if (hasComment && st.CurrentEqualTo("<!--"))
                {
                    st.CurrentPosition += 4;
                    found = st.Find("-->");
                    if (found < 0)
                    {
                        throw new CodeEE("コメンdト終了タグ\"-->\"がみつかりません");
                    }
                    st.CurrentPosition += found + 3;
                    continue;
                }
                if (hasReturn && st.Current == '\n')                //テキスト中の\nは<br>として扱う
                {
                    state.FlagBr = true;
                    st.ShiftNext();
                }
                else                //タグ解析
                {
                    st.ShiftNext();
                    AConsoleDisplayPart part = tagAnalyze(state, st);
                    if (st.Current != '>')
                    {
                        throw new CodeEE("タグ終端'>'が見つかりません");
                    }
                    if (part != null)
                    {
                        cssList.Add(part);
                    }
                    st.ShiftNext();
                }

                if (state.FlagBr)
                {
                    state.LastButtonTag = state.CurrentButtonTag;
                    if (cssList.Count > 0)
                    {
                        buttonList.Add(cssToButton(cssList, state, console));
                    }
                    buttonList.Add(null);
                }
                if (state.FlagButton && cssList.Count > 0)
                {
                    buttonList.Add(cssToButton(cssList, state, console));
                }
                state.FlagBr        = false;
                state.FlagButton    = false;
                state.LastButtonTag = state.CurrentButtonTag;
            }
            //</nobr></p>は省略許可
            if (state.CurrentButtonTag != null || state.FontStyle != FontStyle.Regular || state.FonttagList.Count > 0)
            {
                throw new CodeEE("閉じられていないタグがあります");
            }
            if (cssList.Count > 0)
            {
                buttonList.Add(cssToButton(cssList, state, console));
            }

            foreach (ConsoleButtonString button in buttonList)
            {
                if (button != null && button.PointXisLocked)
                {
                    if (!state.FlagNobr)
                    {
                        throw new CodeEE("<nobr>が設定されていない行ではpos属性は使用できません");
                    }
                    if (state.Alignment != DisplayLineAlignment.LEFT)
                    {
                        throw new CodeEE("alignがleftでない行ではpos属性は使用できません");
                    }
                    break;
                }
            }
            ConsoleDisplayLine[] ret = PrintStringBuffer.ButtonsToDisplayLines(buttonList, sm, state.FlagNobr, false);

            foreach (ConsoleDisplayLine dl in ret)
            {
                dl.SetAlignment(state.Alignment);
            }
            return(ret);
        }
Exemple #28
0
        //indexの文字数の前方文字列とindex以降の後方文字列に分割
        public ConsoleButtonString DivideAt(int divIndex, StringMeasure sm)
        {
            if (divIndex <= 0)
            {
                return(null);
            }
            var cssListA = new List <AConsoleDisplayPart>();
            var cssListB = new List <AConsoleDisplayPart>();
            var index    = 0;
            var cssIndex = 0;
            var b        = false;

            for (cssIndex = 0; cssIndex < StrArray.Length; cssIndex++)
            {
                if (b)
                {
                    cssListB.Add(StrArray[cssIndex]);
                    continue;
                }
                var length = StrArray[cssIndex].Str.Length;
                if (divIndex < index + length)
                {
                    var oldcss = StrArray[cssIndex] as ConsoleStyledString;
                    if (oldcss == null || !oldcss.CanDivide)
                    {
                        throw new ExeEE("文字列分割異常");
                    }
                    var newCss = oldcss.DivideAt(divIndex - index, sm);
                    cssListA.Add(oldcss);
                    if (newCss != null)
                    {
                        cssListB.Add(newCss);
                    }
                    b = true;
                    continue;
                }
                if (divIndex == index + length)
                {
                    cssListA.Add(StrArray[cssIndex]);
                    b = true;
                    continue;
                }
                index += length;
                cssListA.Add(StrArray[cssIndex]);
            }
            if (cssIndex >= StrArray.Length && cssListB.Count == 0)
            {
                return(null);
            }
            var cssArrayA = new AConsoleDisplayPart[cssListA.Count];
            var cssArrayB = new AConsoleDisplayPart[cssListB.Count];

            cssListA.CopyTo(cssArrayA);
            cssListB.CopyTo(cssArrayB);
            StrArray = cssArrayA;
            var ret = new ConsoleButtonString(null, cssArrayB);

            CalcWidth(sm, XsubPixel);
            ret.CalcWidth(sm, 0);
            CalcPointX(PointX);
            ret.CalcPointX(PointX + Width);
            ret.parent     = parent;
            ret.ParentLine = ParentLine;
            ret.IsButton   = IsButton;
            ret.IsInteger  = IsInteger;
            ret.Input      = Input;
            ret.Inputs     = Inputs;
            ret.Generation = Generation;
            ret.ErrPos     = ErrPos;
            ret.Title      = Title;
            return(ret);
        }
        public ConsoleDisplayLine[] Flush(StringMeasure stringMeasure, bool temporary)
        {
            fromCssToButton();
            setLengthToButtonList(stringMeasure);
            if (buttonList.Count == 0)
                return new ConsoleDisplayLine[0];
            List<ConsoleDisplayLine> lineList = new List<ConsoleDisplayLine>();
            List<ConsoleButtonString> lineButtonList = new List<ConsoleButtonString>();
            ConsoleButtonString[] dispLineButtonArray = null;
            int shiftX = 0;
            int windowWidth = Config.WindowX;
            bool firstLine = true;
            bool newLine = false;
            for (int i = 0; i < buttonList.Count; i++)
            {
                if (newLine)
                {
                    shiftX = buttonList[i].PointX;
                    for (int j = i; j < buttonList.Count; j++)
                        buttonList[j].ShiftPositionX(-shiftX);
                    newLine = false;
                }
                if (buttonList[i].PointX + buttonList[i].Width > windowWidth)
                {//ここから新しい表示行
                    if ((!makeButtonWrap) || (lineButtonList.Count == 0) || (!buttonList[i].IsButton && !Config.CompatiLinefeedAs1739))
                    {//ボタン分割
                        int divIndex =getDivideIndex(buttonList[i], stringMeasure);
                        if (divIndex > 0)
                        {
                            ConsoleButtonString newButton = buttonList[i].DivideAt(divIndex, stringMeasure);
                            newButton.SetPointX(buttonList[i].PointX + buttonList[i].Width);
                            buttonList.Insert(i + 1, newButton);
                            lineButtonList.Add(buttonList[i]);
                            i++;
                        }
                    }
                    dispLineButtonArray = new ConsoleButtonString[lineButtonList.Count];
                    lineButtonList.CopyTo(dispLineButtonArray);
                    lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
                    firstLine = false;
                    lineButtonList.Clear();
                    newLine = true;
                    i--;
                    continue;
                }
                lineButtonList.Add(buttonList[i]);
                continue;
            }
            if (lineButtonList.Count > 0)
            {
                dispLineButtonArray = new ConsoleButtonString[lineButtonList.Count];
                lineButtonList.CopyTo(dispLineButtonArray);
                lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
            }

            //if (StaticConfig.ButtonWrap)
            //{//ボタン処理優先
            //    setLengthToButtonList(stringMeasure, false);
            //    ConsoleButtonString[] buttons = createButtons(stringMeasure, stringList);
            //    List<ConsoleButtonString> buttonList = new List<ConsoleButtonString>();
            //    int shiftX = 0;
            //    int windowWidth = StaticConfig.WindowX;
            //    bool firstLine = true;
            //    bool newLine = false;
            //    for (int i = 0; i < buttons.Length; i++)
            //    {
            //        if (newLine)
            //        {
            //            shiftX = buttons[i].PointX;
            //            for (int j = i; j < buttons.Length; j++)
            //                buttons[j].ShiftPositionX(-shiftX);
            //            newLine = false;
            //        }
            //        if ((buttons[i].PointX + buttons[i].Width > windowWidth) && (buttonList.Count > 0))
            //        {//ここから新しい表示行
            //            dispLineButtonArray = new ConsoleButtonString[buttonList.Count];
            //            buttonList.CopyTo(dispLineButtonArray);
            //            lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
            //            firstLine = false;
            //            buttonList.Clear();
            //            newLine = true;
            //            i--;
            //            continue;
            //            //buttonList.Add(buttons[i]);
            //            //continue;
            //        }
            //        buttonList.Add(buttons[i]);
            //        continue;
            //    }
            //    if (buttonList.Count > 0)
            //    {
            //        dispLineButtonArray = new ConsoleButtonString[buttonList.Count];
            //        buttonList.CopyTo(dispLineButtonArray);
            //        lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
            //    }
            //}
            //else
            //{//折り返し処理優先
            //    setLengthToButtonList(stringMeasure, true);
            //    List<ConsoleStyledString> buttonCssList = new List<ConsoleStyledString>();
            //    int pointX = -1;
            //    bool firstLine = true;
            //    for (int i = 0; i < stringList.Count; i++)
            //    {
            //        if ((buttonCssList.Count > 0) && (stringList[i].PointX == 0))
            //        {//ここから新しい表示行
            //            dispLineButtonArray = createButtons(stringMeasure, buttonCssList);
            //            lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
            //            firstLine = false;
            //            buttonCssList.Clear();
            //            buttonCssList.Add(stringList[i]);
            //            pointX = stringList[i].PointX;
            //            continue;
            //        }
            //        buttonCssList.Add(stringList[i]);
            //        pointX = stringList[i].PointX;
            //        continue;
            //    }
            //    if (buttonCssList.Count > 0)
            //    {
            //        dispLineButtonArray = createButtons(stringMeasure, buttonCssList);
            //        lineList.Add(new ConsoleDisplayLine(parent, dispLineButtonArray, firstLine, temporary));
            //        firstLine = false;
            //    }
            //}
            ConsoleDisplayLine[] ret = new ConsoleDisplayLine[lineList.Count];
            lineList.CopyTo(ret);
            this.Clear();
            return ret;
        }
 public ConsoleDisplayLine AppendErrButton(string str, StringStyle style, string input, ScriptPosition pos, StringMeasure sm)
 {
     fromCssToButton();
     stringList.Add(new ConsoleStyledString(str, style));
     if (stringList.Count == 0)
         return null;
     buttonList.Add(createButton(stringList, input, pos));
     stringList.Clear();
     setLengthToButtonList(sm);
     ConsoleButtonString[] dispLineButtonArray = new ConsoleButtonString[buttonList.Count];
     buttonList.CopyTo(dispLineButtonArray);
     ConsoleDisplayLine line = new ConsoleDisplayLine(parent, dispLineButtonArray, true, false);
     this.Clear();
     return line;
 }
        private void calcPrintCWidth(StringMeasure stringMeasure)
        {
            string str = new string(' ', Config.PrintCLength);
            printCWidth = stringMeasure.GetDisplayLength(str, Config.Font);

            str += " ";
            printCWidthL = stringMeasure.GetDisplayLength(str, Config.Font);

            str += " ";
            printCWidthL2 = stringMeasure.GetDisplayLength(str, Config.Font);
        }
Exemple #32
0
        public static ConsoleDisplayLine[] ButtonsToDisplayLines(List <ConsoleButtonString> buttonList, StringMeasure stringMeasure, bool nobr, bool temporary)
        {
            if (buttonList.Count == 0)
            {
                return(new ConsoleDisplayLine[0]);
            }
            setWidthToButtonList(buttonList, stringMeasure, nobr);
            List <ConsoleDisplayLine>  lineList       = new List <ConsoleDisplayLine>();
            List <ConsoleButtonString> lineButtonList = new List <ConsoleButtonString>();
            int  windowWidth = Config.DrawableWidth;
            bool firstLine   = true;

            for (int i = 0; i < buttonList.Count; i++)
            {
                if (buttonList[i] == null)
                {                //強制改行フラグ
                    lineList.Add(m_buttonsToDisplayLine(lineButtonList, firstLine, temporary));
                    firstLine = false;
                    buttonList.RemoveAt(i);
                    i--;
                    continue;
                }
                if (nobr || ((buttonList[i].PointX + buttonList[i].Width <= windowWidth)))
                {                //改行不要モードであるか表示可能領域に収まるならそのままでよい
                    lineButtonList.Add(buttonList[i]);
                    continue;
                }
                //新しい表示行を作る

                //ボタンを分割するか?
                //「ボタンの途中で行を折りかえさない」がfalseなら分割する
                //このボタンが単体で表示可能領域を上回るなら分割必須
                //クリック可能なボタンでないなら分割する。ただし「ver1739以前の非ボタン折り返しを再現する」ならクリックの可否を区別しない
                if ((!Config.ButtonWrap) || (lineButtonList.Count == 0) || (!buttonList[i].IsButton && !Config.CompatiLinefeedAs1739))
                {                //ボタン分割する
                    int divIndex = getDivideIndex(buttonList[i], stringMeasure);
                    if (divIndex > 0)
                    {
                        ConsoleButtonString newButton = buttonList[i].DivideAt(divIndex, stringMeasure);
                        //newButton.CalcPointX(buttonList[i].PointX + buttonList[i].Width);
                        buttonList.Insert(i + 1, newButton);
                        lineButtonList.Add(buttonList[i]);
                        i++;
                    }
                    else if (divIndex == 0 && (lineButtonList.Count > 0))
                    {                    //まるごと次の行に送る
                    }
                    else                 //分割できない要素のみで構成されたボタンは分割できない
                    {
                        lineButtonList.Add(buttonList[i]);
                        continue;
                    }
                }
                lineList.Add(m_buttonsToDisplayLine(lineButtonList, firstLine, temporary));
                firstLine = false;
                //位置調整
//				shiftX = buttonList[i].PointX;
                int pointX = 0;
                for (int j = i; j < buttonList.Count; j++)
                {
                    if (buttonList[j] == null)                    //強制改行を挟んだ後は調整無用
                    {
                        break;
                    }
                    buttonList[j].CalcPointX(pointX);
                    pointX += buttonList[j].Width;
                }
                i--;                //buttonList[i]は新しい行に含めないので次の行のために再検討する必要がある(直後のi++と相殺)
            }
            if (lineButtonList.Count > 0)
            {
                lineList.Add(m_buttonsToDisplayLine(lineButtonList, firstLine, temporary));
            }
            ConsoleDisplayLine[] ret = new ConsoleDisplayLine[lineList.Count];
            lineList.CopyTo(ret);
            return(ret);
        }
        private string CreateTypeCString(string str, bool alignmentRight)
        {
            StringMeasure stringMeasure = new StringMeasure(getGraphics(), this.bgColor, Config.TextDrawingMode);
            if (printCWidth == -1)
                calcPrintCWidth(stringMeasure);
            int length = 0;
            int width = 0;
            if (str != null)
                length = Config.Encode.GetByteCount(str);
            int printcLength = Config.PrintCLength;
            Font font = new Font(Style.Fontname, Config.Font.Size, Style.FontStyle, GraphicsUnit.Pixel);

            if ((alignmentRight) && (length < printcLength))
            {
                str = new string(' ', printcLength - length) + str;
                width = stringMeasure.GetDisplayLength(str, font);
                while (width > printCWidth)
                {
                    if (str[0] != ' ')
                        break;
                    str = str.Remove(0, 1);
                    width = stringMeasure.GetDisplayLength(str, font);
                }
            }
            else if ((!alignmentRight) && (length < printcLength + 1))
            {
                str += new string(' ', printcLength + 1 - length);
                width = stringMeasure.GetDisplayLength(str, font);
                while (width > printCWidthL)
                {
                    if (str[str.Length - 1] != ' ')
                        break;
                    str = str.Remove(str.Length - 1, 1);
                    width = stringMeasure.GetDisplayLength(str, font);
                }
            }
            stringMeasure.Dispose();
            return str;
        }
Exemple #34
0
        //stringListにPointX、Widthを追加
        private static void setWidthToButtonList(List <ConsoleButtonString> buttonList, StringMeasure stringMeasure, bool nobr)
        {
            int   pointX   = 0;
            int   count    = buttonList.Count;
            float subPixel = 0;

            for (int i = 0; i < buttonList.Count; i++)
            {
                ConsoleButtonString button = buttonList[i];
                if (button == null)
                {                //改行フラグ
                    pointX = 0;
                    continue;
                }
                button.CalcWidth(stringMeasure, subPixel);
                button.CalcPointX(pointX);
                pointX = button.PointX + button.Width;
                if (button.PointXisLocked)
                {
                    subPixel = 0;
                }
                //pointX += button.Width;
                subPixel = button.XsubPixel;
            }
            return;

            //1815 バグバグなのでコメントアウト Width測定の省略はいずれやりたい
            ////1815 alignLeft, nobrを前提にした新方式
            ////PointXの直接指定を可能にし、Width測定を一部省略
            //ConsoleStyledString lastCss = null;
            //for (int i = 0; i < buttonList.Count; i++)
            //{
            //    ConsoleButtonString button = buttonList[i];
            //    if (button == null)
            //    {//改行フラグ
            //        pointX = 0;
            //        lastCss = null;
            //        continue;
            //    }
            //    for (int j = 0; j < button.StrArray.Length; j++)
            //    {
            //        ConsoleStyledString css = button.StrArray[j];
            //        if (css.PointXisLocked)//位置固定フラグ
            //        {//位置固定なら前のcssのWidth測定を省略
            //            pointX = css.PointX;
            //            if (lastCss != null)
            //            {
            //                lastCss.Width = css.PointX - lastCss.PointX;
            //                if (lastCss.Width < 0)
            //                    lastCss.Width = 0;
            //            }
            //        }
            //        else
            //        {
            //            if (lastCss != null)
            //            {
            //                lastCss.SetWidth(stringMeasure);
            //                pointX += lastCss.Width;
            //            }
            //            css.PointX = pointX;
            //        }
            //    }
            //}
            ////ConsoleButtonStringの位置・幅を決定(クリック可能域の決定のために必要)
            //for (int i = 0; i < buttonList.Count; i++)
            //{
            //    ConsoleButtonString button = buttonList[i];
            //    if (button == null || button.StrArray.Length == 0)
            //        continue;
            //    button.PointX = button.StrArray[0].PointX;
            //    lastCss = button.StrArray[button.StrArray.Length - 1];
            //    if (lastCss.Width >= 0)
            //        button.Width = lastCss.PointX - button.PointX + lastCss.Width;
            //    else if (i >= buttonList.Count - 1 || buttonList[i+1] == null || buttonList[i+1].StrArray.Length == 0)//行末
            //        button.Width = Config.WindowX;//右端のボタンについては右側全部をボタン領域にしてしまう
            //    else
            //        button.Width = buttonList[i+1].StrArray[0].PointX - button.PointX;
            //    if (button.Width < 0)
            //        button.Width = 0;//pos指定次第ではクリック不可能なボタンができてしまう。まあ仕方ない
            //}
        }
 public ConsoleDisplayLine BufferToSingleLine(bool force, bool temporary)
 {
     if (!this.Enabled)
         return null;
     if (!force && printBuffer.IsEmpty)
         return null;
     if (force && printBuffer.IsEmpty)
         printBuffer.Append(" ", Style);
     StringMeasure stringMeasure = new StringMeasure(getGraphics(), this.bgColor, Config.TextDrawingMode);
     ConsoleDisplayLine dispLine = printBuffer.FlushSingleLine(stringMeasure, temporary | force_temporary);
     stringMeasure.Dispose();
     return dispLine;
 }
 public void SetWidth(StringMeasure sm)
 {
     Width = sm.GetDisplayLength(Str, Font);
 }
 public string getStBar(string barStr)
 {
     StringMeasure stringMeasure = new StringMeasure(getGraphics(), this.bgColor, Config.TextDrawingMode);
     StringBuilder bar = new StringBuilder();
     bar.Append(barStr);
     int width = 0;
     while (width < window.MainPicBox.Width)
     {//境界を越えるまで一文字ずつ増やす
         bar.Append(barStr);
         width = stringMeasure.GetDisplayLength(bar.ToString(), Config.Font);
     }
     while (width > window.MainPicBox.Width)
     {//境界を越えたら、今度は超えなくなるまで一文字ずつ減らす(barStrに複数字の文字列がきた場合に対応するため)
         bar.Remove(bar.Length - 1, 1);
         width = stringMeasure.GetDisplayLength(bar.ToString(), Config.Font);
     }
     stringMeasure.Dispose();
     return bar.ToString();
 }