Example #1
0
 public TextElemet(OoShapeObserver shape)
 {
     Shape = shape;
     if (shape != null)
     {
         Text              = shape.Text;
         ScreenPosition    = shape.GetRelativeScreenBoundsByDom();
         ObjectBoundingBox = BrailleTextView.MakeZoomBoundingBox(ScreenPosition, WindowManager.GetPrintZoomLevel());
         Matrix            = BrailleTextView.BrailleRenderer.RenderMatrix(ObjectBoundingBox.Width, Text);
         Position          = new Point(ObjectBoundingBox.X, ObjectBoundingBox.Y);
         Center            = new Point(ObjectBoundingBox.X + (ObjectBoundingBox.Width / 2), ObjectBoundingBox.Y + (ObjectBoundingBox.Height / 2));
     }
     else
     {
         Center            = Position = new Point();
         Matrix            = new bool[0, 0];
         ObjectBoundingBox = ScreenPosition = new Rectangle();
         Text = String.Empty;
     }
 }
        /// <summary>
        /// Sets the shape or point to blink and starts the blinking frame around the last selected shape.
        /// </summary>
        internal void InitBrailleDomFocusHighlightMode(OoShapeObserver _shape = null, bool visualize = true)
        {
            if (shapeManipulatorFunctionProxy != null)
            {
                if (_shape == null)
                {
                    _shape = shapeManipulatorFunctionProxy.LastSelectedShape;
                }

                if (_shape != null && _shape.IsValid(false))
                {
                    StartFocusHighlightModes();

                    // inform sighted user
                    if (visualize)
                    {
                        byte[] pngData;
                        if (_shape.GetShapeAsPng(out pngData) > 0)
                        {
                            DesktopOverlayWindow.Instance.initBlinking(
                                ref pngData,                           // png as byte array
                                _shape.GetAbsoluteScreenBoundsByDom(), // bounding box
                                0.75,                                  // opacity (0.0 (transparent) .. 1.0)
                                1500,                                  // The total blinking time in ms until blinking stops and the window is hidden again
                                //The pattern of milliseconds to be on|off|...,
                                // e.g. [250,150,250,150,250,150,800,1000] for three short flashes (on for 250ms)
                                // with gaps (of 150ms) and one long on time (800ms) followed by a pause(1s).
                                // The pattern is repeated until the total blinking time is over.
                                // If less than 2 values are given, the default of [500, 500] is used!
                                new int[8] {
                                250, 150, 250, 150, 250, 150, 500, 150
                            }
                                );
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Sets the shape for modification to the given observer.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="observed">The observed.</param>
        /// <returns>the currently selected Shape observer</returns>
        public bool SetPolypointForModification(OoPolygonPointsObserver points, OoShapeObserver shape)
        {
            if (shape != null && points != null && points.Shape == shape)
            {
                if (shapeManipulatorFunctionProxy != null && !ImageData.Instance.Active)
                {
                    // OoElementSpeaker.PlayElementImmediately(shape, LL.GetTrans("tangram.lector.oo_observer.selected", String.Empty));
                    if (shapeManipulatorFunctionProxy.LastSelectedShape != shape)
                    {
                        shapeManipulatorFunctionProxy.LastSelectedShape = shape;
                    }
                    shapeManipulatorFunctionProxy.LastSelectedShapePolygonPoints = points;
                    // shapeManipulatorFunctionProxy.SelectLastPolygonPoint();
                    shapeManipulatorFunctionProxy.SelectPolygonPoint();
                }
                else // title+desc dialog handling
                {
                    ImageData.Instance.NewSelectionHandling(shape);
                }
            }

            return(false);
        }
        /// <summary>
        /// Gets the shape observer for modification.
        /// </summary>
        /// <param name="c">The component to get the corresponding observer to.</param>
        /// <param name="observed">The observed window / draw document.</param>
        /// <param name="silent">if set to <c>true</c> no audio feedback about the selection is given.</param>
        /// <param name="immediatly">if set to <c>true</c> the audio feedback is immediately given and all other audio feedback is aborted.</param>
        /// <returns>The corresponding observer to the shape in the given Draw document.</returns>
        public OoShapeObserver GetShapeForModification(OoAccComponent c, OoAccessibleDocWnd observed, bool silent = true, bool immediately = true)
        {
            if (observed != null && c.Role != AccessibleRole.INVALID)
            {
                //TODO: prepare name:

                OoShapeObserver shape = observed.GetRegisteredShapeObserver(c);
                if (shape != null)
                {
                    return(GetShapeForModification(shape, observed, silent, immediately));

                    //if (shapeManipulatorFunctionProxy != null && !ImageData.Instance.Active)
                    //{
                    //    OoElementSpeaker.PlayElementImmediately(shape, LL.GetTrans("tangram.lector.oo_observer.selected", String.Empty));
                    //    //audioRenderer.PlaySound("Form kann manipuliert werden");
                    //    shapeManipulatorFunctionProxy.LastSelectedShape = shape;
                    //    return shape;
                    //}
                    //else // title+desc dialog handling
                    //{
                    //    ImageData.Instance.NewSelectionHandling(shape);
                    //}
                }
                else
                {
                    // disable the pageShapes
                    if (c.Name.StartsWith("PageShape:"))
                    {
                        return(null);
                    }

                    OoElementSpeaker.PlayElementImmediately(c, LL.GetTrans("tangram.lector.oo_observer.selected"));
                    audioRenderer.PlaySound(LL.GetTrans("tangram.lector.oo_observer.selected_element.locked"));
                }
            }
            return(null);
        }
        /// <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))
                            );
                    }
                }


                double zoomDivRatio = newZoom / oldZoom;

                if (newZoom > 0 && (vr.ContentBox.Height <= vr.ContentHeight * zoomDivRatio || vr.ContentBox.Width <= vr.ContentWidth * zoomDivRatio))
                {
                    Point newCenter = new Point(
                        (int)Math.Round(oldCenter.X * zoomDivRatio),
                        (int)Math.Round(oldCenter.Y * zoomDivRatio)
                        );

                    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>
 /// Sets the shape for modification to the given observer.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="observed">The observed.</param>
 /// <param name="silent">if set to <c>true</c> no audio feedback about the selection is given.</param>
 /// <param name="immediatly">if set to <c>true</c> the audio feedback is immediately given and all other audio feedback is aborted.</param>
 /// <returns>the currently selected Shape observer</returns>
 public OoShapeObserver GetShapeForModification(OoShapeObserver shape, OoAccessibleDocWnd observed = null, bool silent = true, bool immediately = true)
 {
     return(SetShapeForModification(shape, silent, immediately) ? shape : null);
 }
Example #7
0
        /// <summary>
        /// Builds an Observer class for the specific shape type.
        /// </summary>
        /// <param name="s">The shape to observe.</param>
        /// <param name="page">The page the shape is placed on.</param>
        /// <param name="parent">The parent shape if the shape is part of a group.</param>
        /// <returns>
        /// An shape observer class for the specific shape type.
        /// </returns>
        internal static OoShapeObserver BuildShapeObserver(XShape s, OoDrawPageObserver page, OoShapeObserver parent)
        {
            if (s != null && page != null)
            {
                if (OoUtils.ElementSupportsService(s, OO.Services.DRAW_SHAPE_CUSTOM))
                {
                    return(new OoCustomShapeObserver(s, page, parent));
                }

                // normal shape
                return(new OoShapeObserver(s, page, parent));
            }
            return(null);
        }
Example #8
0
 /// <summary>
 /// Builds an Observer class for the specific shape type.
 /// </summary>
 /// <param name="s">The shape to observe.</param>
 /// <param name="page">The page the shape is placed on.</param>
 /// <param name="parent">The parent shape if the shape is part of a group.</param>
 /// <returns>
 /// An shape observer class for the specific shape type.
 /// </returns>
 public static OoShapeObserver BuildShapeObserver(Object s, OoDrawPageObserver page, OoShapeObserver parent)
 {
     return(BuildShapeObserver(s as XShape, page, parent));
 }
        /// <summary>
        /// Gets the audio text for the given element.
        /// </summary>
        /// <param name="element">The element to get the text of.</param>
        /// <param name="additionalText">An additional text, that is put behind the element properties and befor the label (if available).</param>
        /// <returns>A string that should describe the element in the following form: [ROLE] [NAME] [TITLE] (addintionalText) [TEXT]</returns>
        public static String GetElementAudioText(OoShapeObserver element, string additionalText = "")
        {
            String result = String.Empty;

            if (element != null && element.IsValid(false))
            {
                try
                {
                    bool isText = element.IsText;

                    #region default element handling

                    if (isText)
                    {
                        result = LL.GetTrans("tangram.oomanipulation.element_speaker.text_element", element.Text, element.Title);
                    }
                    else
                    {
                        //result += element.AccComponent.Role + " " + element.Name;
                        result += element.Name;

                        if (!String.IsNullOrWhiteSpace(element.Title))
                        {
                            result += (result.EndsWith(" ") ? "" : " ") + element.Title;
                        }
                    }

                    if (!String.IsNullOrEmpty(additionalText))
                    {
                        result += (result.EndsWith(" ") ? "" : " ") + additionalText;
                    }
                    else
                    {
                        result = result.Trim();
                    }

                    #endregion

                    #region object text

                    if (!isText && !String.IsNullOrWhiteSpace(element.Text))
                    {
                        result += " - " + LL.GetTrans("tangram.oomanipulation.element_speaker.text_value", element.Text);
                    }

                    #endregion

                    #region Group

                    if (element.IsGroup || element.HasChildren)
                    {
                        int cCount = element.ChildCount;
                        result += (result.EndsWith(" ") ? "" : " ") + "- "
                                  + LL.GetTrans("tangram.oomanipulation.element_speaker.has_" + (cCount == 1 ? "one_child" : "children"), cCount.ToString());
                    }

                    #endregion

                    #region Group Member

                    if (element.IsGroupMember && element.Parent != null)
                    {
                        result += " - " + LL.GetTrans("tangram.oomanipulation.element_speaker.child_of", element.Parent.Name);
                    }

                    #endregion
                }
                catch (System.Exception ex)
                {
                    Logger.Instance.Log(LogPriority.DEBUG, "OoElementSpeaker", "[ERROR] Can't play element: " + ex);
                }
            }

            return(String.IsNullOrWhiteSpace(result) ? LL.GetTrans("tangram.oomanipulation.element_speaker.default") : result);
        }
Example #10
0
 /// <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);
 }