/// <summary> /// If Braille text is at the requested position in the given view range that this function tries to get the corresponding text. /// </summary> /// <param name="vr">The viewrange to check.</param> /// <param name="e">the gesture event</param> private String checkForTouchedBrailleText(BrailleIOViewRange vr, GestureEventArgs e) { if (vr.ContentRender is ITouchableRenderer && e != null && e.Gesture != null) { var touchRendeer = (ITouchableRenderer)vr.ContentRender; // calculate the position in the content int x = (int)e.Gesture.NodeParameters[0].X; int y = (int)e.Gesture.NodeParameters[0].Y; x = x - vr.ViewBox.X - vr.ContentBox.X - vr.GetXOffset(); y = y - vr.ViewBox.Y - vr.ContentBox.Y - vr.GetYOffset(); var touchedElement = touchRendeer.GetContentAtPosition(x, y); if (touchedElement != null && touchedElement is RenderElement) { var touchedValue = ((RenderElement)touchedElement).GetValue(); if (((RenderElement)touchedElement).HasSubParts()) { List <RenderElement> touchedSubparts = ((RenderElement)touchedElement).GetSubPartsAtPoint(x, y); if (touchedSubparts != null && touchedSubparts.Count > 0) { touchedValue = touchedSubparts[0].GetValue(); } } System.Diagnostics.Debug.WriteLine("----- [BRAILLE TEXT TOUCHED] : '" + touchedValue.ToString() + "'"); return(touchedValue.ToString()); } } return(String.Empty); }
/// <summary> /// Zooms the specified view to the given zoom level. /// </summary> /// <param name="viewName">Name of the view.</param> /// <param name="viewRangeName">Name of the view range.</param> /// <param name="zoomLevel">The zoom level.</param> public bool ZoomTo(string viewName, string viewRangeName, double zoomLevel) { if (io == null || io.GetView(viewName) as BrailleIOScreen == null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); bool success = false; if (vr != null) { var oldZoom = vr.GetZoom(); var newZoom = zoomLevel; success = zoom(vr, oldZoom, newZoom); } else { return(false); } io.RefreshDisplay(); return(success); }
/// <summary> /// get all the visible viewRanges in the currently visible screen containing text. /// </summary> /// <returns>list of ViewRanges containing text</returns> List<BrailleIOViewRange> getAllViews() { List<BrailleIOViewRange> vrs = new List<BrailleIOViewRange>(); var screens = io.GetActiveViews(); foreach (var item in screens) { if (item is BrailleIOScreen) { foreach (var vrPair in ((BrailleIOScreen)item).GetOrderedViewRanges()) { if (vrPair.Value != null) { BrailleIOViewRange vr = vrPair.Value; if (vr.IsVisible() && (vr.IsText() || vr.IsOther())) { vrs.Add(vr); } } } } else if (item is BrailleIOViewRange) { BrailleIOViewRange vr = item as BrailleIOViewRange; if (vr.IsVisible() && (vr.IsText() || vr.IsOther())) { vrs.Add(vr); } } } return vrs; }
/// <summary> /// Sets the content of the region. /// </summary> /// <param name="screen">The screen.</param> /// <param name="vrName">Name of the region (viewRange).</param> /// <param name="content">The content.</param> /// <returns>true if the content could be set, otherwise false</returns> private bool setRegionContent(BrailleIOScreen screen, String vrName, Object content) { if (screen != null) { BrailleIOViewRange vr = screen.GetViewRange(vrName); if (vr != null) { if (content != null) { if (content is bool[, ]) { vr.SetMatrix(content as bool[, ]); } else if (content is Bitmap) { vr.SetBitmap(content as Bitmap); } else if (content is String) { vr.SetText(content.ToString()); } else { return(false); } return(true); } else { vr.SetMatrix(null); } //TODO: check if this works } } return(false); }
bool updateFullScreen(int width, int height) { if (io != null) { // main screen BrailleIOScreen fullScreen = io.GetView(BS_FULLSCREEN_NAME) as BrailleIOScreen; if (fullScreen != null) { fullScreen.SetHeight(height); fullScreen.SetWidth(width); // center BrailleIOViewRange center = fullScreen.GetViewRange(VR_CENTER_NAME); if (center != null) { center.SetHeight(height); center.SetWidth(width); } io.RefreshDisplay(true); return(true); } } return(false); }
/// <summary> /// Get the touched view range. /// </summary> /// <param name="x">x value of the tap (on pin device)</param> /// <param name="y">y value of the tap (on pin device)</param> /// <param name="s">visible screen</param> /// <returns>touched view range</returns> public BrailleIOViewRange GetTouchedViewRange(double x, double y, BrailleIOScreen s) { if (s != null) { OrderedDictionary viewRanges = s.GetViewRanges(); if (viewRanges.Count > 0) { object[] keys = new object[viewRanges.Keys.Count]; viewRanges.Keys.CopyTo(keys, 0); for (int i = keys.Length - 1; i >= 0; i--) { BrailleIOViewRange vr = viewRanges[keys[i]] as BrailleIOViewRange; if (vr != null && vr.IsVisible()) { if (x >= vr.GetLeft() && x <= (vr.GetLeft() + vr.GetWidth())) { if (y >= vr.GetTop() && y <= (vr.GetTop() + vr.GetHeight())) { return(vr); } } } } } } return(null); }
/// <summary> /// Fills the center region of the main screen with the content depending on the currentView. /// </summary> private void fillMainCenterContent(BrailleIOScreen screen) { if (screen != null) { BrailleIOViewRange center = screen.GetViewRange(VR_CENTER_NAME); BrailleIOViewRange center2 = screen.GetViewRange(VR_CENTER_2_NAME); if (center != null) { switch (currentView) { case LectorView.Drawing: setCaptureArea(); if (center2 != null) { center2.SetVisibility(false); } break; case LectorView.Braille: String content = "Hallo Welt"; // TODO: set real content setRegionContent(screen, VR_CENTER_2_NAME, content); break; default: setCaptureArea(); break; } } } }
/// <summary> /// Move current view range to the given object. /// For example, this should be used for following the focused object on the pin device. /// </summary> /// <param name="objectBounds">object that should be shown centered on pin device</param> public void MoveToObject(Rectangle boundingBox) { if (boundingBox == null || IsInMinimapMode()) { return; } BrailleIOScreen vs = GetVisibleScreen(); BrailleIOViewRange center = GetActiveCenterView(vs); if (center != null) { // use not whole screen, but open office document position as screen position, because contentWidth and contentHeight of view range is related to this instead of to the whole screen //Rectangle boundingBox = new Rectangle(objectBounds.X, objectBounds.Y, objectBounds.Width, objectBounds.Height); Point centeredScreenPosition = new Point((int)Math.Round(boundingBox.X + boundingBox.Width * 0.5), (int)Math.Round(boundingBox.Y + boundingBox.Height * 0.5)); //Point centeredScreenPosition = new Point(boundingBox.X, boundingBox.Y); Point pinDevicePosition = new Point(0, 0); double zoom = center.GetZoom(); if (zoom != 0) { pinDevicePosition = new Point((int)(Math.Round(centeredScreenPosition.X * -zoom) + ((int)Math.Round(center.ContentBox.Width * 0.5))), (int)(Math.Round(centeredScreenPosition.Y * -zoom) + ((int)Math.Round(center.ContentBox.Height * 0.5)))); //pinDevicePosition = new Point((int)(Math.Round(centeredScreenPosition.X * -zoom)), (int)(Math.Round(centeredScreenPosition.Y * -zoom))); } MoveToPosition(vs.Name, center.Name, pinDevicePosition); } }
/// <summary> /// Zooms the specified view with the given factor. /// </summary> /// <param name="viewName">Name of the view.</param> /// <param name="viewRangeName">Name of the view range.</param> /// <param name="factor">The zoom factor.</param> protected bool zoomWithFactor(string viewName, string viewRangeName, double factor) { if (io == null || io.GetView(viewName) as BrailleIOScreen == null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); bool success = false; if (vr != null) { double oldZoom = vr.GetZoom(); if (oldZoom > 0) { double newZoom = oldZoom * factor; success = zoom(vr, oldZoom, newZoom); } else { return(false); } } else { return(false); } this.io.RefreshDisplay(); return(success); }
/// <summary> /// Switch between fullscreen and main screen. /// </summary> private void toggleFullscreen() { if (io.GetView(BS_FULLSCREEN_NAME) != null) { var view = io.GetView(BS_FULLSCREEN_NAME) as BrailleIO.Interface.IViewable; BrailleIOScreen ms = io.GetView(BS_MAIN_NAME) as BrailleIOScreen; if (view != null && ms != null) { BrailleIOViewRange mainscreenCenterVR = ms.GetViewRange(VR_CENTER_NAME); BrailleIOViewRange fullscreenCenterVR = (view as BrailleIOScreen).GetViewRange(VR_CENTER_NAME); if (view.IsVisible()) { if (mainscreenCenterVR != null && fullscreenCenterVR != null) { syncViewRangeWithVisibleCenterViewRange(mainscreenCenterVR); syncContrastSettings(fullscreenCenterVR, mainscreenCenterVR); } io.HideView(BS_FULLSCREEN_NAME); io.ShowView(BS_MAIN_NAME); } else { if (mainscreenCenterVR != null && fullscreenCenterVR != null) { syncViewRangeWithVisibleCenterViewRange(fullscreenCenterVR); syncContrastSettings(mainscreenCenterVR, fullscreenCenterVR); } io.HideView(BS_MAIN_NAME); io.ShowView(BS_FULLSCREEN_NAME); } } } }
/// <summary> /// Reduce or increase contrast of the image with the given value. /// </summary> /// <param name="viewName">name of the view</param> /// <param name="viewRangeName">name of the view range</param> /// <param name="factor">factor that should be added to current contrast</param> /// <returns>true if threshold could be set to new value, false if it is already max or min value</returns> private bool updateContrast(string viewName, string viewRangeName, int factor) { if (io == null || io.GetView(viewName) as BrailleIOScreen == null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); int oldThreshold = 0; int newThreshold = 0; if (vr != null) { oldThreshold = vr.GetContrastThreshold(); newThreshold = vr.SetContrastThreshold(oldThreshold + factor); } io.RefreshDisplay(); if ((oldThreshold >= 255 || oldThreshold <= 0) && (newThreshold >= 255 || newThreshold <= 0)) { return(false); } else { return(true); } }
/// <summary> /// Synchronize the contrastThreshold and InvertImage value. /// </summary> /// <param name="oldvr">ViewRange whose values should be used in the new ViewRange.</param> /// <param name="newvr">ViewRange that should get the values of the old ViewRange.</param> private void syncContrastSettings(BrailleIOViewRange oldvr, BrailleIOViewRange newvr) { if (oldvr != null && newvr != null) { newvr.InvertImage = oldvr.InvertImage; newvr.SetContrastThreshold(oldvr.GetContrastThreshold()); } }
//BrailleIOScreen GetVisibleScreen() //{ // if (monitor != null && io != null) // { // var views = io.GetViews(); // if (views != null && views.Count > 0) // { // try // { // //var vs = views.First(x => (x is BrailleIO.Interface.IViewable && ((BrailleIO.Interface.IViewable)x).IsVisible())); // object vs = null; // for (int i = views.Count - 1; i >= 0; i--) // { // object x = views[i]; // if ((x is BrailleIO.Interface.IViewable && ((BrailleIO.Interface.IViewable)x).IsVisible())) // { // vs = x; // break; // } // } // if (vs != null && vs is BrailleIOScreen) // { // return vs as BrailleIOScreen; // } // } // catch (InvalidOperationException) { } //Happens if no view could been found in the listing // } // } // return null; //} static IList getRenderingElementsFromViewRange(BrailleIOViewRange vr, int left, int right, int top, int bottom) { if (vr != null && vr.ContentRender is ITouchableRenderer) { return ((ITouchableRenderer)vr.ContentRender).GetAllContentInArea(left, right, top, bottom); } return null; }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="screenPos">The screen pos.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, Rectangle screenPos) { if (view != null && !screenPos.IsEmpty) { return(IsElementsBoundingBoxVisibleInView(GetViewPort(view), screenPos, Math.Max(0.0000001, view.GetZoom()))); } return(false); }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="shape">The shape.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, OoShapeObserver shape) { if (view != null && shape != null) { return(IsElementsBoundingBoxVisibleInView(GetViewPort(view), shape, Math.Max(0.0000001, view.GetZoom()))); } return(false); }
BrailleIOViewRange getMainDetailRegion(int left, int top, int width, int height) { BrailleIOViewRange bottom = new BrailleIOViewRange(left, top, width, height); bottom.SetBorder(1, 0, 0); bottom.SetMargin(1, 0, 0); bottom.SetPadding(1, 0, 0); return(bottom); }
BrailleIOViewRange getMainStatusRegion(int left, int top, int width, int height) { BrailleIOViewRange _status = new BrailleIOViewRange(left, top, width, height); _status.SetBorder(0, 0, 0, 1); _status.SetMargin(0, 0, 0, 2); _status.SetPadding(0, 0, 0, 1); return(_status); }
public StartScreen(LL ll, int width, int height) : base("StartScreen") { this.ll = ll; title = new BrailleIOViewRange(2, 2, width - 4, height - 4); title.SetText(ll.GetTrans("game.title") + "\n" + ll.GetTrans("game.keybindings1") + "\n" + ll.GetTrans("game.keybindings2") + "\n" + ll.GetTrans("game.keybindings3") + "\n" + ll.GetTrans("game.keybindings4")); AddViewRange(title); }
/// <summary> /// Initializes a new instance of the <see cref="OoObserver"/> class. /// Listen to an OoDrawAccessibilityObserver and handles the events. /// Basic interpreter for events from an OpenOffice Draw application. /// </summary> public OoObserver() : base(20) { shapeManipulatorFunctionProxy = new OpenOfficeDrawShapeManipulator(this, WindowManager.Instance as IZoomProvider, WindowManager.Instance as IFeedbackReceiver); WindowManager.blinkTimer.ThreeQuarterTick += new EventHandler <EventArgs>(blinkTimer_Tick); OnShapeBoundRectChange = new OoShapeObserver.BoundRectChangeEventHandler(ShapeBoundRectChangeHandler); OnViewOrZoomChange = new OoDrawPagesObserver.ViewOrZoomChangeEventHandler(ShapeBoundRectChangeHandler); initFunctionProxy(); registerAsSpecializedFunctionProxy(); //OoSelectionObserver.Instance.SelectionChanged += new EventHandler<OoSelectionChandedEventArgs>(OoDrawAccessibilityObserver_SelectionChanged); OoDrawAccessibilityObserver.Instance.DrawWindowOpend += new EventHandler <OoWindowEventArgs>(OoDrawAccessibilityObserver_DrawWindowOpend); OoDrawAccessibilityObserver.Instance.DrawWindowPropertyChange += new EventHandler <OoWindowEventArgs>(OoDrawAccessibilityObserver_DrawWindowPropertyChange); OoDrawAccessibilityObserver.Instance.DrawWindowMinimized += new EventHandler <OoWindowEventArgs>(OoDrawAccessibilityObserver_DrawWindowMinimized); OoDrawAccessibilityObserver.Instance.DrawWindowClosed += new EventHandler <OoWindowEventArgs>(OoDrawAccessibilityObserver_DrawWindowClosed); OoDrawAccessibilityObserver.Instance.DrawWindowActivated += new EventHandler <OoWindowEventArgs>(OoDrawAccessibilityObserver_DrawWindowActivated); OoDrawAccessibilityObserver.Instance.DrawSelectionChanged += new EventHandler <OoAccessibilitySelectionChangedEventArgs>(Instance_DrawSelectionChanged); shapeManipulatorFunctionProxy.SelectedShapeChanged += new EventHandler <SelectedShapeChangedEventArgs>(shapeManipulatorFunctionProxy_SelectedShapeChanged); shapeManipulatorFunctionProxy.PolygonPointSelected += shapeManipulatorFunctionProxy_PolygonPointSelected; // make the observes aware of the currently open DRAW docs (still opened before started this instance) List <OoAccessibleDocWnd> docList = OoDrawAccessibilityObserver.Instance.GetDrawDocs(); foreach (var doc in docList) { OoDrawAccessibilityObserver_DrawWindowActivated(null, new OoWindowEventArgs(doc)); } #region Renderer Hook BrailleIOViewRange vr = getDisplayViewRange(WindowManager.BS_MAIN_NAME); if (vr != null) { vr.RendererChanged += new EventHandler <EventArgs>(vr_RendererChanged); vr_RendererChanged(vr, null); } BrailleIOViewRange vr_minimap = getDisplayViewRange(WindowManager.BS_MINIMAP_NAME); if (vr_minimap != null) { vr_minimap.RendererChanged += new EventHandler <EventArgs>(vr_RendererChanged); vr_RendererChanged(vr_minimap, null); } BrailleIOViewRange vr_fullscreen = getDisplayViewRange(WindowManager.BS_FULLSCREEN_NAME); if (vr_fullscreen != null) { vr_fullscreen.RendererChanged += new EventHandler <EventArgs>(vr_RendererChanged); vr_RendererChanged(vr_fullscreen, null); } #endregion }
// deselect everything on the HyperBraille Device public void DeselectAll() { selectedText.Clear(); // clear any text in the text box on display pageNumDisplay.Clear(); // clear any page number in the text box on display if (selectionTimer.Enabled == true) { StopBlink(); // stop the blinking of any previously selected section } viewRangeCurrentlySelected = null; // update the view range currently selected }
BrailleIOViewRange getMainScreenCenter2Region(int left, int top, int width, int height) { BrailleIOViewRange center2 = new BrailleIOViewRange(left, top, width, height); center2.SetZoom(-1); center2.SetBorder(0); center2.SetContrastThreshold(STANDARD_CONTRAST_THRESHOLD); center2.SetMargin(7, 0); return(center2); }
BrailleIOViewRange getMainTopRegion(int left, int top, int width, int height) { BrailleIOViewRange _top = new BrailleIOViewRange(left, top, width, height); _top.SetBorder(0, 0, 1); _top.SetMargin(0, 0, 1); _top.SetPadding(0, 11, 1, 0); _top.SetWidth((int)(width * 1.4)); // only that region content is not doing line breaks return(_top); }
private void jumpToTopBorder(BrailleIOViewRange center) { if (center != null) { center.SetYOffset(0); io.RefreshDisplay(); audioRenderer.PlaySoundImmediately(LL.GetTrans("tangram.lector.wm.panning.jump.up")); Logger.Instance.Log(LogPriority.MIDDLE, this, "[INTERACTION] jump to top"); } }
bool updateMainScreen(int width, int height) { if (io != null) { // main screen BrailleIOScreen mainScreen = io.GetView(BS_MAIN_NAME) as BrailleIOScreen; if (mainScreen != null) { mainScreen.SetHeight(height); mainScreen.SetWidth(width); // center BrailleIOViewRange center = mainScreen.GetViewRange(VR_CENTER_NAME); if (center != null) { center.SetHeight(height); center.SetWidth(width); } // center 2 BrailleIOViewRange center2 = mainScreen.GetViewRange(VR_CENTER_2_NAME); if (center2 != null) { center2.SetHeight(height); center2.SetWidth(width); } //top BrailleIOViewRange top = mainScreen.GetViewRange(VR_TOP_NAME); if (top != null) { top.SetWidth((int)(width * 1.4)); // only that region content is not doing line breaks } // status BrailleIOViewRange status = mainScreen.GetViewRange(VR_STATUS_NAME); if (status != null) { status.SetLeft(width - 12); } // center 2 BrailleIOViewRange detail = mainScreen.GetViewRange(VR_DETAIL_NAME); if (detail != null) { detail.SetTop(height - 7); detail.SetWidth(width); } io.RefreshDisplay(true); return(true); } } return(false); }
/// <summary> /// Builds a dummy view range with the same size as the image. /// </summary> /// <param name="img">The image.</param> /// <returns>A dummy view range with the size of the image.</returns> private static IViewBoxModel buildImageDummyViewRange(Image img) { BrailleIOViewRange view = new BrailleIOViewRange(0, 0, 0, 0); if (img != null) { view.SetWidth(img.Width); view.SetHeight(img.Height); } return(view); }
private void jumpToRightBorder(BrailleIOViewRange center) { if (center != null) { int offset = center.ContentWidth - center.ContentBox.Width; center.SetXOffset(-offset); io.RefreshDisplay(); audioRenderer.PlaySoundImmediately(LL.GetTrans("tangram.lector.wm.panning.jump.right")); Logger.Instance.Log(LogPriority.MIDDLE, this, "[INTERACTION] jump to right"); } }
// given a View Range, select it public void SelectViewRange(BrailleIOViewRange viewRange) { selectedText.Clear(); // clear any text in the text box on display if (selectionTimer.Enabled == true) { StopBlink(); // stop the blinking of any previously selected section } viewRangeCurrentlySelected = viewRange; // update the view range currently selected selectionTimer.Start(); // start the blinking cycle on this new selected section selectedText.Text = paperOnDisplay.GetContent(viewRangeCurrentlySelected.Name); // set the text in the text box to be the text just selected by the user }
/// <summary> /// Add the given scroll step to the current offset position of view range to realize a scrolling. /// </summary> /// <param name="vr">View range to scroll.</param> /// <param name="scrollStep">Steps to scroll the view range.</param> private void scrollViewRange(BrailleIOViewRange vr, int scrollStep) { if (vr != null) { int newPos = vr.OffsetPosition.Y + scrollStep; if (newPos <= 0 && newPos >= (vr.ContentBox.Height - vr.ContentHeight)) { vr.SetYOffset(newPos); } } }
// TODO: correct toggle function for active detail area view range private void toggleFullDetailScreen() { BrailleIOScreen vs = GetVisibleScreen(); BrailleIOViewRange detailVR = vs.GetViewRange(VR_DETAIL_NAME); // TODO: ImageData class creates own detail area --> do not use global detailarea BrailleIOViewRange topVR = vs.GetViewRange(VR_TOP_NAME); detailVR.SetHeight(deviceSize.Height - topVR.GetHeight()); detailVR.SetTop(topVR.GetHeight() - 3); io.RefreshDisplay(); audioRenderer.PlaySoundImmediately(LL.GetTrans("tangram.lector.wm.views.detail_maximize")); }
/// <summary> /// Zooms the specified view by the given factor. /// </summary> /// <param name="screen">The screen containing the view.</param> /// <param name="viewRangeName">Name of the view range inside the screen.</param> /// <param name="changeFactor">The change factor for zoom.</param> /// <param name="render">if set to <c>true</c> a new rendering is forced.</param> /// <returns> /// <c>true</c> if the zoom factor of the view was changed successfully. /// </returns> /// <remarks> /// Views will change their presentation only after calling <see cref="BrailleIOMediator.Instance.RenderDisplay()" />. /// Call the <c>RenderDisplay()</c> function after you have done all your changes to see the results. /// </remarks> private static bool Zoom(BrailleIOScreen screen, string viewRangeName, double changeFactor, bool render = false) { if (screen != null) { BrailleIOViewRange vr = screen.GetViewRange(viewRangeName); if (vr != null) { return(Zoom(vr, changeFactor, render)); } } return(false); }
void IBailleIORendererHook.PostRenderHook(IViewBoxModel view, object content, ref bool[,] result, params object[] additionalParams) { _lastView = view as BrailleIOViewRange; if (Active && CanBeActivated() ) { List<TextElemet> visibleTexts = getVisibleTextElements(view); foreach (var visibleText in visibleTexts) { renderTextFieldInMatrix(ref result, visibleText, ((BrailleIOViewRange)view).GetXOffset(), ((BrailleIOViewRange)view).GetYOffset(), ((BrailleIOViewRange)view).GetZoom()); } visibleTexts = null; } }
/// <summary> /// Get position of tap on the screen /// </summary> /// <param name="x">x value of tap (on pin device)</param> /// <param name="y">y value of tap (on pin device)</param> /// <param name="vr">touched view range</param> /// <returns>position on the screen</returns> public Point GetTapPositionOnScreen(double x, double y, BrailleIOViewRange vr) { Point p = GetTapPositionInContent(x, y, vr); if (vr != null && p != null) { double zoom = vr.GetZoom(); if (zoom != 0) { int x_old = p.X; int y_old = p.Y; p = new Point((int)Math.Round(x_old / zoom), (int)Math.Round(y_old / zoom)); if (ScreenObserver != null && ScreenObserver.ScreenPos is Rectangle) { Rectangle sp = (Rectangle)ScreenObserver.ScreenPos; p.X += sp.X; p.Y += sp.Y; } System.Diagnostics.Debug.WriteLine("tap screen position: " + p.ToString()); } } return p; }
/// <summary> /// Get position of tap within the content /// </summary> /// <param name="x">x value of tap (on pin device)</param> /// <param name="y">y value of tap (on pin device)</param> /// <param name="vr">touched view range</param> /// <returns>position within content</returns> public Point GetTapPositionInContent(double x, double y, BrailleIOViewRange vr) { Point p = new Point(); if (vr != null) { double contentX = x - vr.OffsetPosition.X - vr.Padding.Left - vr.Margin.Left - vr.Border.Left; double contentY = y - vr.OffsetPosition.Y - vr.Padding.Top - vr.Margin.Top - vr.Border.Top; p = new Point((int)Math.Round(contentX), (int)Math.Round(contentY)); System.Diagnostics.Debug.WriteLine("tap content position: " + p.ToString()); } return p; }
/// <summary> /// Synchronize the zoom and x/y offset of the given view range with that of the center view range of the visible screen. /// </summary> /// <param name="vr">view range that should be syncronized with visible center</param> private void syncViewRangeWithVisibleCenterViewRange(BrailleIOViewRange vr) { BrailleIOScreen vs = GetVisibleScreen(); if (!vs.Name.Equals(BS_MINIMAP_NAME)) { BrailleIOViewRange visibleCenterVR = vs.GetViewRange(VR_CENTER_NAME); double zoom = visibleCenterVR.GetZoom(); int x = visibleCenterVR.GetXOffset(); int y = visibleCenterVR.GetYOffset(); if (visibleCenterVR.ContentHeight <= vr.ContentBox.Height && visibleCenterVR.ContentWidth <= vr.ContentBox.Width) { vr.SetZoom(-1); // für Anpassung bei kleinster Zoomstufe } else vr.SetZoom(zoom); vr.SetXOffset(x); vr.SetYOffset(y); } }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="shape">The shape.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, OoShapeObserver shape) { if (view != null && shape != null) { return IsElementsBoundingBoxVisibleInView(GetViewPort(view), shape, Math.Max(0.0000001, view.GetZoom())); } return false; }
private void setTangramScreen() { try { if (io != null) { string name = "TangramSceen"; BrailleIOScreen ts = new BrailleIOScreen(name); BrailleIOViewRange tv = new BrailleIOViewRange(0, 0, io.GetDeviceSizeX(), io.GetDeviceSizeY()); tv.SetBitmap(Bitmap.FromFile(@"config/pics/tactile_logo.bmp")); ts.AddViewRange(name + "View", tv); io.AddView(name, ts); io.ShowView(name); io.RefreshDisplay(); io.RefreshDisplay(); System.Threading.Thread.Sleep(10); } } catch { } }
/// <summary> /// Add the given scroll step to the current offset position of view range to realize a scrolling. /// </summary> /// <param name="vr">View range to scroll.</param> /// <param name="scrollStep">Steps to scroll the view range.</param> private void scrollViewRange(BrailleIOViewRange vr, int scrollStep) { if (vr != null) { int newPos = vr.OffsetPosition.Y + scrollStep; if (newPos <= 0 && newPos >= (vr.ContentBox.Height - vr.ContentHeight)) vr.SetYOffset(newPos); } }
/// <summary> /// Shows the center region in full screen (other regions are set invisible). /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <returns></returns> BrailleIOScreen buildFullScreen(int width, int height) { BrailleIOScreen fullScreen = new BrailleIOScreen(BS_FULLSCREEN_NAME); BrailleIOViewRange center = new BrailleIOViewRange(0, 0, width, height); center.SetZoom(-1); center.SetBorder(0); center.SetContrastThreshold(STANDARD_CONTRAST_THRESHOLD); center.ShowScrollbars = true; fullScreen.AddViewRange(VR_CENTER_NAME, center); if (io != null) io.AddView(BS_FULLSCREEN_NAME, fullScreen); fullScreen.SetVisibility(false); return fullScreen; }
/// <summary> /// Gets the view port of a given view. The viewPort is the /// presented part of the content. /// /// ┌────────────────────┐ -- content /// │ │ /// │ ╔════════╗╌╌ viewPort /// │ ║ ║ │ /// │ ╚════════╝ │ /// │ │ /// └────────────────────┘ /// </summary> /// <param name="view">The view.</param> /// <returns></returns> static Rectangle GetViewPort(BrailleIOViewRange view) { Rectangle viewPort = new Rectangle(); if (view != null) { viewPort.Width = view.ContentBox.Width; viewPort.Height = view.ContentBox.Height; viewPort.X = -view.GetXOffset(); viewPort.Y = -view.GetYOffset(); } return viewPort; }
/// <summary> /// Zooms the given view range to the new zoom level and calculates the new offset out of the old center position. /// </summary> /// <param name="vr">view range that should be zoomed</param> /// <param name="oldZoom">old zoom of the view range</param> /// <param name="newZoom">new zoom</param> /// <returns>true, if zoom was successful</returns> private bool zoom(BrailleIOViewRange vr, double oldZoom, double newZoom) { if (vr != null) { Point oldCenter = new Point(); var oldvrdin = vr.ContentBox; bool zoomToShape = false; Point oldOffset = new Point(vr.GetXOffset(), vr.GetYOffset()); // Prüfung auf größte Zoomstufe if (newZoom > vr.MAX_ZOOM_LEVEL) { if (oldZoom == vr.MAX_ZOOM_LEVEL) return false; newZoom = vr.MAX_ZOOM_LEVEL; } // Prüfung auf kleinste Zoomstufe if (vr.ContentBox.Height >= vr.ContentHeight && vr.ContentBox.Width >= vr.ContentWidth) { if (oldZoom >= newZoom) return false; oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) zoomToShape = true; else { oldCenter = new Point( (int)Math.Round(((double)vr.ContentWidth / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)vr.ContentHeight / 2) + (vr.GetYOffset() * -1)) ); } } else { oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) zoomToShape = true; else { // central point of center region as center for zooming oldCenter = new Point( (int)Math.Round(((double)oldvrdin.Width / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)oldvrdin.Height / 2) + (vr.GetYOffset() * -1)) ); } } if (newZoom > 0) { double zoomRatio = newZoom / oldZoom; Point newCenter = new Point( (int)Math.Round(oldCenter.X * zoomRatio), (int)Math.Round(oldCenter.Y * zoomRatio) ); Point newOffset = new Point(); if (zoomToShape) { newOffset = new Point(oldOffset.X + (oldCenter.X - newCenter.X), oldOffset.Y + (oldCenter.Y - newCenter.Y)); } else { newOffset = new Point( (int)Math.Round((newCenter.X - ((double)oldvrdin.Width / 2)) * -1), (int)Math.Round((newCenter.Y - ((double)oldvrdin.Height / 2)) * -1) ); } vr.SetZoom(newZoom); vr.MoveTo(new Point(Math.Min(newOffset.X, 0), Math.Min(newOffset.Y, 0))); } else // set to smallest zoom level { vr.SetZoom(-1); vr.SetXOffset(0); vr.SetYOffset(0); } // check for correct panning if (vr.GetXOffset() > 0) { vr.SetXOffset(0); } if (vr.GetYOffset() > 0) { vr.SetYOffset(0); } if ((vr.ContentWidth + vr.GetXOffset()) < vr.ContentBox.Width) { int maxOffset = Math.Min(0, vr.ContentBox.Width - vr.ContentWidth); vr.SetXOffset(maxOffset); } if ((vr.ContentHeight + vr.GetYOffset()) < vr.ContentBox.Height) { int maxOffset = Math.Min(0, vr.ContentBox.Height - vr.ContentHeight); vr.SetYOffset(maxOffset); } return true; } return false; }
/// <summary> /// If Braille text is at the requested position in the given view range that this function tries to get the corresponding text. /// </summary> /// <param name="vr">The viewrange to check.</param> /// <param name="e">the gestrure evnet</param> private String CheckForTouchedBrailleText(BrailleIOViewRange vr, GestureEventArgs e) { if (vr.ContentRender is ITouchableRenderer) { var touchRendeer = (ITouchableRenderer)vr.ContentRender; // calculate the position in the content int x = (int)e.Gesture.NodeParameters[0].X; int y = (int)e.Gesture.NodeParameters[0].Y; x = x - vr.ViewBox.X - vr.ContentBox.X - vr.GetXOffset(); y = y - vr.ViewBox.Y - vr.ContentBox.Y - vr.GetYOffset(); var touchedElement = touchRendeer.GetContentAtPosition(x, y); if (touchedElement != null && touchedElement is RenderElement) { var touchedValue = ((RenderElement)touchedElement).GetValue(); if (((RenderElement)touchedElement).HasSubParts()) { List<RenderElement> touchedSubparts = ((RenderElement)touchedElement).GetSubPartsAtPoint(x, y); if (touchedSubparts != null && touchedSubparts.Count > 0) { touchedValue = touchedSubparts[0].GetValue(); } } System.Diagnostics.Debug.WriteLine("----- [BRAILLE TEXT TOUCHED] : '" + touchedValue.ToString() + "'"); return touchedValue.ToString(); } } return String.Empty; }
/// <summary> /// Set offset position of view range to given position. /// </summary> /// <param name="vr">View range to set new offset.</param> /// <param name="y_pos">new offset position.</param> private void scrollViewRangeTo(BrailleIOViewRange vr, int y_pos) { if (vr != null && y_pos <= 0) { if (y_pos >= (vr.ContentBox.Height - vr.ContentHeight)) vr.SetYOffset(y_pos); else vr.SetYOffset(0); } }
/// <summary> /// Add the given scroll step to the current offset position of view range to realize a scrolling. /// </summary> /// <param name="vr">View range to scroll.</param> /// <param name="scrollStep">Steps to scroll the view range.</param> private bool scrollViewRange(BrailleIOViewRange vr, int scrollStep) { if (vr != null) { int newPos = vr.OffsetPosition.Y + scrollStep; if (newPos <= 0 && newPos >= (vr.ContentBox.Height - vr.ContentHeight)) { vr.SetYOffset(newPos); return true; } } return false; }
/// <summary> /// Set text value of a view range and scrolls to the bottom if necessary. /// </summary> /// <param name="vr">View range to fill with content.</param> /// <param name="text">Text content.</param> private void setScrollableViewRangeTextContent(BrailleIOViewRange vr, string text) { if (vr != null) { vr.SetText(text); if (text.Length <= 40) return; // TODO: only hack because at this point contentHeight is that of last shown content --> if the new content is very short, than the scrolling would show it out of view range int contentHeight = vr.ContentHeight - 1; // TODO: ignore last line in content renderer instead of "-1" if (vr.ShowScrollbars && (contentHeight > vr.ContentBox.Height)) // TODO: adaption also necessary if content is smaller than offset position { int diff = vr.ContentBox.Height - contentHeight; scrollViewRangeTo(vr, diff); } } }
BrailleIOViewRange getMainStatusRegion(int left, int top, int width, int height) { BrailleIOViewRange _status = new BrailleIOViewRange(left, top, width, height); _status.SetBorder(0, 0, 0, 1); _status.SetMargin(0, 0, 0, 2); _status.SetPadding(0, 0, 0, 1); return _status; }
/// <summary> /// Set the content in minimap mode. Thereby the screen capturing bitmap is shown with blinking frame. /// </summary> /// <param name="vr">ViewRange in which minimap content should be shown.</param> /// <param name="e">EventArgs of the screen capturing event.</param> void setMinimapContent(BrailleIOViewRange vr, CaptureChangedEventArgs e) { int width = vr.ContentBox.Width; int height = vr.ContentBox.Height; Bitmap bmp = new Bitmap(width, height); Graphics graph = Graphics.FromImage(bmp); if (screenBeforeMinimap != null) { BrailleIOViewRange imgvr = screenBeforeMinimap.GetViewRange(VR_CENTER_NAME); if (imgvr == null) return; int xoffset = imgvr.GetXOffset(); int yoffset = imgvr.GetYOffset(); int imgWidth = imgvr.ContentWidth; int imgHeight = imgvr.ContentHeight; if (imgWidth > 0 && imgHeight > 0) { // calculate image size for minimap (complete image has to fit into view range) int imgScaledWidth = imgWidth; int imgScaledHeight = imgHeight; double scaleFactorX = 1; double scaleFactorY = 1; if (width != 0 && imgScaledWidth > width) { scaleFactorX = (double)imgWidth / (double)width; if (scaleFactorX != 0) { imgScaledWidth = width; imgScaledHeight = (int)(imgHeight / scaleFactorX); } } if (height != 0 && imgScaledHeight > height) { scaleFactorY = (double)imgScaledHeight / (double)height; if (scaleFactorY != 0) { imgScaledHeight = height; imgScaledWidth = (int)(imgScaledWidth / scaleFactorY); } } // calculate scaling factor from original image to minimap image size MinimapScalingFactor = 1 / (scaleFactorX * scaleFactorY); double zoom = imgvr.GetZoom(); if (zoom > 0) MinimapScalingFactor = MinimapScalingFactor * zoom; // calculate position and size of the blinking frame int x = Math.Abs(xoffset) * imgScaledWidth / imgWidth; int y = Math.Abs(yoffset) * imgScaledHeight / imgHeight; int frameWidth = width * imgScaledWidth / imgWidth; int frameHeigth = height * imgScaledHeight / imgHeight; // draw scaled image and blinking frame graph.DrawImage(e.Img, 0, 0, imgScaledWidth, imgScaledHeight); Color frameColor = Color.Black; if (!blinkPinsUp) frameColor = Color.White; graph.DrawRectangle(new Pen(frameColor, 2), x, y, frameWidth, frameHeigth); vr.SetBitmap(bmp); } } }
BrailleIOViewRange getMainScreenCenter2Region(int left, int top, int width, int height) { BrailleIOViewRange center2 = new BrailleIOViewRange(left, top, width, height); center2.SetZoom(-1); center2.SetBorder(0); center2.SetContrastThreshold(STANDARD_CONTRAST_THRESHOLD); center2.SetMargin(7, 0); return center2; }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="screenPos">The screen pos.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, Rectangle screenPos) { if (view != null && !screenPos.IsEmpty) { return IsElementsBoundingBoxVisibleInView(GetViewPort(view), screenPos, Math.Max(0.0000001, view.GetZoom())); } return false; }
BrailleIOViewRange getMainTopRegion(int left, int top, int width, int height) { BrailleIOViewRange _top = new BrailleIOViewRange(left, top, width, height); _top.SetBorder(0, 0, 1); _top.SetMargin(0, 0, 1); _top.SetPadding(0, 11, 1, 0); _top.SetWidth((int)(width * 1.4)); // only that region content is not doing line breaks return _top; }
private void createDetailView(string detailViewName, int left, int top, int width, int height, bool scrollable) { try { if (!detailViewDic.ContainsKey(detailViewName)) { detailViewDic.Add(detailViewName, null); } brailleIoScreen = wManager.GetVisibleScreen(); detailViewDic[detailViewName] = new BrailleIOViewRange(left, top, width, height); brailleIoScreen.AddViewRange(viewRangename, detailViewDic[detailViewName]); viewRangename = detailViewDic[detailViewName].Name; detailViewDic[detailViewName].SetVisibility(true); detailViewDic[detailViewName].SetZIndex(99); detailViewDic[detailViewName].SetBorder(1, 0, 0); detailViewDic[detailViewName].SetMargin(1, 0, 0); detailViewDic[detailViewName].SetPadding(1, 0, 0); detailViewDic[detailViewName].HasBorder = true; detailViewDic[detailViewName].ShowScrollbars = scrollable; detailViewDic[detailViewName].SetText(""); var render = detailViewDic[detailViewName].ContentRender; if (render != null && render is IBrailleIOHookableRenderer) { if (detailViewName == TITLE_DESC_VIEW_NAME) { ((IBrailleIOHookableRenderer)render).RegisterHook(CaretHook); } else if (detailViewName == TITLE_DESC_SAVE_VIEW_NAME) { ((IBrailleIOHookableRenderer)render).RegisterHook(UnderLiningHook); } } } catch (Exception ex) { Logger.Instance.Log(LogPriority.DEBUG, this, "[ERROR] while changing the height of the detail region", ex); } }
BrailleIOViewRange getMainDetailRegion(int left, int top, int width, int height) { BrailleIOViewRange bottom = new BrailleIOViewRange(left, top, width, height); bottom.SetBorder(1, 0, 0); bottom.SetMargin(1, 0, 0); bottom.SetPadding(1, 0, 0); return bottom; }