/// <summary> /// Determines whether the entry is visible or not. /// </summary> /// <param name="renderedEntry">The rendered entry.</param> /// <param name="view">The view to check for (BrailleIoViewRange).</param> /// <returns> /// -1 if not visible; 0 if party visible, and 1 if fully visible. /// </returns> public virtual int IsEntryVisible(RenderElement renderedEntry, IViewBoxModel view = null) { if (!renderedEntry.IsEmpty()) { if (view == null) { view = _lastView; } if (view != null && view.ContentBox.Width * view.ContentBox.Height > 0) { int left, top, right, bottom; left = top = 0; if (view is IPannable) { left = ((IPannable)view).GetXOffset(); top = ((IPannable)view).GetYOffset(); } right = view.ContentBox.Width + left; bottom = view.ContentBox.Height + top; if (renderedEntry.IsInArea(left, left + right, top, top + bottom)) { if (renderedEntry.IsCompletelyInArea(left, right, top, bottom)) { return(1); } return(0); } } } return(-1); }
/// <summary> /// Makes the entry visible in the given view. /// If an entry is outside the visible area and the view is <see cref="BrailleIO.Interface.IPannable" />, /// the offsets are adapted to make the entry visible. /// </summary> /// <param name="renderedEntry">The rendered entry.</param> /// <param name="view">The view.</param> /// <param name="vertical">if set to <c>true</c> adapt view in vertical direction.</param> /// <param name="horizontal">if set to <c>true</c> adapt view in horizontal direction.</param> /// <returns> /// <c>true</c> if the entry would be visible; otherwise, <c>false</c>. /// </returns> /// <remarks> /// After a returning <c>true</c> you have to force an rerendering. /// </remarks> public virtual bool MakeEntryVisible(RenderElement renderedEntry, IViewBoxModel view = null, bool vertical = true, bool horizontal = false) { bool success = false; if (!renderedEntry.IsEmpty() && (vertical || horizontal)) { if (view == null) { view = _lastView; } if (view != null && view.ContentBox.Width * view.ContentBox.Height > 0) { int visibility = IsEntryVisible(renderedEntry, view); if (visibility > 0) { return(true); } else { if (view is IPannable) { // entry position Rectangle bbox = new Rectangle( renderedEntry.X, renderedEntry.Y, renderedEntry.Width, renderedEntry.Height); // visible view port Rectangle viewPort = new Rectangle( -((IPannable)view).GetXOffset(), -((IPannable)view).GetYOffset(), view.ContentBox.Width, view.ContentBox.Height); // check if item is selected --> add one more line for marking var entry = renderedEntry.GetValue() as DialogEntry; if (entry != null && entry.Status.HasFlag(DialogEntryStatus.Selected)) { bbox.Height += 1; } // check for scrolling directions /************** vertical ***********/ if (vertical) { if (bbox.Top < viewPort.Top) //entry starts over the view port // move upwards { viewPort.Y = bbox.Y; } else if (bbox.Bottom > viewPort.Bottom) // entry ends after the view port // move downwards? { int newY = viewPort.Top + (bbox.Bottom - viewPort.Bottom); viewPort.Y = Math.Min(bbox.Top, newY); } ((IPannable)view).SetYOffset(-viewPort.Y); success = ((IPannable)view).GetYOffset() == -viewPort.Y; } /************ horizontal ***********/ if (horizontal) { if (bbox.Left < viewPort.Left) // move right { viewPort.X = bbox.X; } else if (bbox.Right > viewPort.Right) // move left? { int newX = viewPort.Left + (bbox.Right - viewPort.Right); viewPort.X = Math.Min(bbox.Left, newX); } ((IPannable)view).SetXOffset(-viewPort.X); success = true; } } } } } return(success); }