Пример #1
0
        //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);
        }
Пример #2
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指定次第ではクリック不可能なボタンができてしまう。まあ仕方ない
            //}
        }
Пример #3
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);
        }