private void DeterminePopupPosition(Collection<WordInfo> c, RenderedTextInfo r, int maxWidth) { popUpInfo.visible = true; popUpInfo.words = c; WordInfo last = c[c.Count - 1]; // h: height int h1; int up; int down; if (r.Line1 == -1) up = 0; else up = r.Line1; if (r.Line2 == -1) down = 0; else down = LastFullScreenLine - r.Line2; if (r.Line1 == -1 || r.Line2 == -1) h1 = LastFullScreenLine + 1; else h1 = r.Line2 - r.Line1 + 1; int h2 = last.Line + 1; // s: single bool s1 = (h1 == 1); bool s2 = (h2 == 1); int length2 = last.X2; popUpInfo.Y = -1; if (s1 && s2) { if (down > 0) { if (r.X1 + length2 <= maxWidth) SetPopUpCoordinates(r.Line2 + 1, r.X1, 1, 0); else SetPopUpCoordinates(r.Line2 + 1, maxWidth - length2, 1, 0); } else if (up > 0) { if (r.X1 + length2 <= maxWidth) SetPopUpCoordinates(r.Line1 - 1, r.X1, -1, 0); else SetPopUpCoordinates(r.Line1 - 1, maxWidth - length2, -1, 0); } else if (popUpOffsetX + r.X2 + length2 <= maxWidth) SetPopUpCoordinates(r.Line1, r.X2, 0, 1); else if (r.X1 >= popUpOffsetX + length2) SetPopUpCoordinates(r.Line1, r.X1 - length2, 0, -1); } else { if (h2 <= down) SetPopUpCoordinates(r.Line2 + 1, 0, 1, 0); else if (s2 && r.Line2 != -1 && r.Line2 <= LastFullScreenLine && r.X2 + popUpOffsetX + length2 <= maxWidth) SetPopUpCoordinates(r.Line2, r.X2, 0, 1); else if (h2 <= up) if (h2 == 1) SetPopUpCoordinates(r.Line1 - 1, maxWidth - length2, -1, 0); else if (r.Line1 != -1 && r.X1 >= length2 + popUpOffsetX) SetPopUpCoordinates(r.Line1 - h2 + 1, 0, -1, 0); else SetPopUpCoordinates(r.Line1 - h2, 0, -1, 0); else if (s2 && r.Line1 != -1 && r.X1 >= length2 + popUpOffsetX) SetPopUpCoordinates(r.Line1, r.X1 - length2, 0, -1); } if (popUpInfo.Y == -1) // The worst case: draw over SetPopUpCoordinates((NumberOfScreenLines - h2 + 1) / 2, 0, 0, 0); popUpInfo.Y2 = popUpInfo.Y + h2 - 1; popUpInfo.X2 = popUpInfo.X + last.X2; //DebugString = "[" + h1.ToString() + ']' // + r.Line1.ToString() + ':' + r.X1.ToString() + '—' // + r.Line2.ToString() + ':' + r.X2.ToString() // + " -- > [" + h2.ToString() + ']' + popUpInfo.Y.ToString() + ':' + popUpInfo.X.ToString(); }
public TextPair() { Height = -1; CurrentPos1 = 0; CurrentPos2 = 0; AllLinesComputed1 = false; AllLinesComputed2 = false; RenderedInfo1 = new RenderedTextInfo(); RenderedInfo2 = new RenderedTextInfo(); }