public void ChangeStr(ConsoleButtonString[] newButtons) { buttons = null; foreach (ConsoleButtonString button in newButtons) button.ParentLine = this; buttons = newButtons; }
private static ConsoleDisplayLine m_buttonsToDisplayLine(List <ConsoleButtonString> lineButtonList, bool firstLine, bool temporary) { ConsoleButtonString[] dispLineButtonArray = new ConsoleButtonString[lineButtonList.Count]; lineButtonList.CopyTo(dispLineButtonArray); lineButtonList.Clear(); return(new ConsoleDisplayLine(dispLineButtonArray, firstLine, temporary)); }
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); }
/// <summary> /// ここまでのcssをボタン化。発生原因はbrタグ、行末、ボタンタグ /// </summary> /// <param name="cssList"></param> /// <param name="isbutton"></param> /// <param name="state"></param> /// <param name="console"></param> /// <returns></returns> private static ConsoleButtonString cssToButton(List <AConsoleDisplayPart> cssList, HtmlAnalzeState state, EmueraConsole console) { AConsoleDisplayPart[] css = new AConsoleDisplayPart[cssList.Count]; cssList.CopyTo(css); cssList.Clear(); ConsoleButtonString ret = null; if (state.LastButtonTag != null && state.LastButtonTag.IsButton) { if (state.LastButtonTag.ButtonIsInteger) { ret = new ConsoleButtonString(console, css, state.LastButtonTag.ButtonValueInt, state.LastButtonTag.ButtonValueStr); } else { ret = new ConsoleButtonString(console, css, state.LastButtonTag.ButtonValueStr); } } else { ret = new ConsoleButtonString(console, css); ret.Title = null; } if (state.LastButtonTag != null) { ret.Title = state.LastButtonTag.ButtonTitle; if (state.LastButtonTag.PointXisLocked) { ret.LockPointX(state.LastButtonTag.PointX); } } return(ret); }
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); }
public ConsoleDisplayLine(EmueraConsole parentWindow, ConsoleButtonString[] buttons, bool isLogical, bool temporary) { parent = parentWindow; if (buttons == null) { buttons = new ConsoleButtonString[0]; return; } this.buttons = buttons; foreach (ConsoleButtonString button in buttons) button.ParentLine = this; IsLogicalLine = isLogical; IsTemporary = temporary; }
//public ConsoleDisplayLine(EmueraConsole parentWindow, ConsoleButtonString[] buttons, bool isLogical, bool temporary) public ConsoleDisplayLine(ConsoleButtonString[] buttons, bool isLogical, bool temporary) { //parent = parentWindow; if (buttons == null) { buttons = new ConsoleButtonString[0]; return; } this.buttons = buttons; foreach (ConsoleButtonString button in buttons) { button.ParentLine = this; } IsLogicalLine = isLogical; IsTemporary = temporary; }
//public ConsoleDisplayLine(EmueraConsole parentWindow, ConsoleButtonString[] buttons, bool isLogical, bool temporary) public ConsoleDisplayLine(ConsoleButtonString[] buttons, bool isLogical, bool temporary) { //parent = parentWindow; if (buttons == null) { buttons = new ConsoleButtonString[0]; return; } this.buttons = buttons; for (var i = 0; i < buttons.Length; ++i) { buttons[i].ParentLine = this; } IsLogicalLine = isLogical; IsTemporary = temporary; }
private void addDisplayLine(ConsoleDisplayLine line, bool force_LEFT) { if (LastLineIsTemporary) { deleteLine(1); } //不適正なFontのチェック AConsoleDisplayPart errorStr = null; AConsoleDisplayPart css = null; var button_count = line.Buttons.Length; var button_strcount = 0; for (var b = 0; b < button_count; ++b) { ConsoleButtonString button = line.Buttons[b]; button_strcount = button.StrArray.Length; for (var i = 0; i < button_strcount; ++i) { css = button.StrArray[i]; if (css.Error) { errorStr = css; break; } } } if (errorStr != null) { MessageBox.Show("Emueraの表示処理中に不適正なフォントを検出しました\n描画処理を続行できないため強制終了します", "フォント不適正"); this.Quit(); return; } if (force_LEFT) { line.SetAlignment(DisplayLineAlignment.LEFT); } else { line.SetAlignment(alignment); } line.LineNo = lineNo; displayLineList.Add(line); lineNo++; if (line.IsLogicalLine) { logicalLineCount++; } if (lineNo == int.MaxValue) { lastDrawnLineNo = -1; lineNo = 0; } if (logicalLineCount == long.MaxValue) { logicalLineCount = 0; } if (displayLineList.Count > Config.MaxLog) { displayLineList.RemoveAt(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 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; }
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); }
/// <summary> /// 物理行をボタン単位に分割。引数のcssListの内容は変更される場合がある。 /// </summary> /// <returns></returns> private ConsoleButtonString[] createButtons(List <AConsoleDisplayPart> cssList) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < cssList.Count; i++) { buf.Append(cssList[i].Str); } List <ButtonPrimitive> bpList = ButtonStringCreator.SplitButton(buf.ToString()); ConsoleButtonString[] ret = new ConsoleButtonString[bpList.Count]; AConsoleDisplayPart[] cssArray = null; if (ret.Length == 1) { cssArray = new AConsoleDisplayPart[cssList.Count]; cssList.CopyTo(cssArray); if (bpList[0].CanSelect) { ret[0] = new ConsoleButtonString(parent, cssArray, bpList[0].Input); } else { ret[0] = new ConsoleButtonString(parent, cssArray); } return(ret); } int cssStartCharIndex = 0; int buttonEndCharIndex = 0; int cssIndex = 0; List <AConsoleDisplayPart> buttonCssList = new List <AConsoleDisplayPart>(); for (int i = 0; i < ret.Length; i++) { ButtonPrimitive bp = bpList[i]; buttonEndCharIndex += bp.Str.Length; while (true) { if (cssIndex >= cssList.Count) { break; } AConsoleDisplayPart css = cssList[cssIndex]; if (cssStartCharIndex + css.Str.Length >= buttonEndCharIndex) { //ボタンの終端を発見 int used = buttonEndCharIndex - cssStartCharIndex; if (used > 0 && css.CanDivide) { //cssの区切りの途中でボタンの区切りがある。 ConsoleStyledString newCss = ((ConsoleStyledString)css).DivideAt(used); if (newCss != null) { cssList.Insert(cssIndex + 1, newCss); newCss.PointX = css.PointX + css.Width; } } buttonCssList.Add(css); cssStartCharIndex += css.Str.Length; cssIndex++; break; } //ボタンの終端はまだ先。 buttonCssList.Add(css); cssStartCharIndex += css.Str.Length; cssIndex++; } cssArray = new AConsoleDisplayPart[buttonCssList.Count]; buttonCssList.CopyTo(cssArray); if (bp.CanSelect) { ret[i] = new ConsoleButtonString(parent, cssArray, bp.Input); } else { ret[i] = new ConsoleButtonString(parent, cssArray); } buttonCssList.Clear(); } return(ret); }
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; }
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 void LeaveMouse() { if (selectingButton != null) { selectingButton = null; RefreshStrings(true); } }
public void MoveMouse(Point point) { ConsoleButtonString select = null; //数値か文字列の入力待ち状態でなければ無視 if ((state != ConsoleState.WaitInteger) && (state != ConsoleState.WaitString) && (state != ConsoleState.WaitSystemInteger) && (state != ConsoleState.WaitIntegerWithTimer) && (state != ConsoleState.WaitStringWithTimer) && (state != ConsoleState.Error) && (state != ConsoleState.WaitOneInteger) && (state != ConsoleState.WaitOneString) && (state != ConsoleState.WaitOneIntegerWithTimer) && (state != ConsoleState.WaitOneStringWithTimer)) goto end; //入力・マクロ処理中は無視 if (inProcess) goto end; //履歴表示中は無視 //if (window.ScrollBar.Value != window.ScrollBar.Maximum) // goto end; int pointX = point.X; int pointY = point.Y; //表示上は下から何行目? int displayLineNo = (window.MainPicBox.Height - pointY) / Config.LineHeight + 1; //実際は何行目? //int lineNo = displayLineList.Count - displayLineNo; int lineNo = displayLineList.Count - displayLineNo - (window.ScrollBar.Maximum - window.ScrollBar.Value); if ((lineNo < 0) || (lineNo >= displayLineList.Count)) goto end; select = displayLineList[lineNo].GetPointingButton(pointX); if ((select == null) || (select.Generation != lastButtonGeneration)) select = null; else if ((state == ConsoleState.WaitInteger || state == ConsoleState.WaitIntegerWithTimer || state == ConsoleState.WaitOneInteger || state == ConsoleState.WaitOneIntegerWithTimer) && (!select.IsInteger)) select = null; else if ((state == ConsoleState.WaitSystemInteger) && (!select.IsInteger)) select = null; end: if (select != selectingButton) { selectingButton = select; RefreshStrings(true); } return; }
public void RefreshStrings(bool force, Graphics graph) { //描画中にEmueraが閉じられると廃棄されたPictureBoxにアクセスしてしまったりするので if (!this.Enabled) return; bool isBackLog = window.ScrollBar.Value != window.ScrollBar.Maximum; //ログ表示はREDRAWの設定に関係なく行うようにする if ((redraw == ConsoleRedraw.None) && (!force) && (!isBackLog)) return; if (selectingButton != null) { //履歴表示中は選択肢無効 //if (isBackLog) // selectingButton = null; //数値か文字列の入力待ち状態でなければ無効 if ((state != ConsoleState.WaitInteger) && (state != ConsoleState.WaitString) && (state != ConsoleState.WaitSystemInteger) && (state != ConsoleState.WaitIntegerWithTimer) && (state != ConsoleState.WaitStringWithTimer) && (state != ConsoleState.Error) && (state != ConsoleState.WaitOneInteger) && (state != ConsoleState.WaitOneString) && (state != ConsoleState.WaitOneIntegerWithTimer) && (state != ConsoleState.WaitOneStringWithTimer)) selectingButton = null; //選択肢が最新でないなら無効 else if (selectingButton.Generation != lastButtonGeneration) selectingButton = null; } if (!force) {//forceならば確実に再描画。 if ((!isBackLog) && (lastDrawnLineNo == lineNo) && (lastSelectingButton == selectingButton)) return; //Environment.TickCountは分解能が悪すぎるのでwinmmのタイマーを呼んで来る uint sec = WinmmTimer.TickCount - lastUpdate; //まだ書き換えるタイミングでないなら次の更新を待ってみる //ただし、入力待ちなど、しばらく更新のタイミングがない場合には強制的に書き換えてみる if (sec < msPerFrame && (state == ConsoleState.Running || state == ConsoleState.Initializing)) return; } if (forceTextBoxColor) { uint sec = WinmmTimer.TickCount - lastBgColorChange; //色変化が速くなりすぎないように一定時間以内の再呼び出しは強制待ちにする while (sec < 200) { Application.DoEvents(); sec = WinmmTimer.TickCount - lastBgColorChange; } window.TextBox.BackColor = this.bgColor; lastBgColorChange = WinmmTimer.TickCount; } lastUpdate = WinmmTimer.TickCount; barUpdate(); window.SuspendLayout(); this.m_RefreshStrings(graph); window.ResumeLayout(); if (Config.UseImageBuffer) window.Refresh(); if (isBackLog) lastDrawnLineNo = -1; else lastDrawnLineNo = lineNo; lastSelectingButton = selectingButton; /*デバッグ用。描画が超重い環境を想定 System.Threading.Thread.Sleep(50); */ //Initializing中はさらに頻度を下げる:読み込みを早くするため。 if (state == ConsoleState.Initializing) lastUpdate = WinmmTimer.TickCount; if (forceTextBoxColor) { forceTextBoxColor = false; } }
public bool ButtonIsSelected(ConsoleButtonString button) { return selectingButton == button; }
//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; }
/// <summary> /// 物理行をボタン単位に分割。引数のcssListの内容は変更される場合がある。 /// </summary> /// <returns></returns> private ConsoleButtonString[] createButtons(List<ConsoleStyledString> cssList) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < cssList.Count; i++) { buf.Append(cssList[i].Str); } List<ButtonPrimitive> bpList = ButtonStringCreator.SplitButton(buf.ToString()); ConsoleButtonString[] ret = new ConsoleButtonString[bpList.Count]; ConsoleStyledString[] cssArray = null; if (ret.Length == 1) { cssArray = new ConsoleStyledString[cssList.Count]; cssList.CopyTo(cssArray); if (bpList[0].CanSelect) ret[0] = new ConsoleButtonString(parent, cssArray, bpList[0].Input); else ret[0] = new ConsoleButtonString(parent, cssArray); return ret; } int cssStartCharIndex = 0; int buttonEndCharIndex = 0; int cssIndex = 0; List<ConsoleStyledString> buttonCssList = new List<ConsoleStyledString>(); for (int i = 0; i < ret.Length; i++) { ButtonPrimitive bp = bpList[i]; buttonEndCharIndex += bp.Str.Length; while (true) { if (cssIndex >= cssList.Count) break; ConsoleStyledString css = cssList[cssIndex]; if (cssStartCharIndex + css.Str.Length >= buttonEndCharIndex) {//ボタンの終端を発見 int used = buttonEndCharIndex - cssStartCharIndex; if (used > 0) {//cssの区切りの途中でボタンの区切りがある。 ConsoleStyledString newCss = css.DivideAt(used); if (newCss != null) { cssList.Insert(cssIndex + 1, newCss); newCss.PointX = css.PointX + css.Width; } } buttonCssList.Add(css); cssStartCharIndex += css.Str.Length; cssIndex++; break; } //ボタンの終端はまだ先。 buttonCssList.Add(css); cssStartCharIndex += css.Str.Length; cssIndex++; } cssArray = new ConsoleStyledString[buttonCssList.Count]; buttonCssList.CopyTo(cssArray); if (bp.CanSelect) ret[i] = new ConsoleButtonString(parent, cssArray, bp.Input); else ret[i] = new ConsoleButtonString(parent, cssArray); buttonCssList.Clear(); } return ret; }
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; }
//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); }
//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); }