コード例 #1
0
        /// <summary>
        /// Calculates the line count.
        /// </summary>
        /// <param name="editFieldEntry">The edit field entry.</param>
        public void CalculateLineCount(EditField_DialogEntry editFieldEntry)
        {
            if (editFieldEntry != null && editFieldEntry.InputBox != null && CharsPerLine > 0)
            {
                switch (editFieldEntry.InputBox.BoxHeightType)
                {
                case BoxHeightTypes.TextLength:
                    if (editFieldEntry.Title != null)
                    {
                        //Only as big as needed to show current content
                        LineCount = (int)Math.Ceiling(editFieldEntry.Title.Length / (double)CharsPerLine);
                    }
                    break;

                case BoxHeightTypes.MaximumTextLength:

                    if (editFieldEntry.Validator != null && editFieldEntry.Validator.MaxTextLength > 0)
                    {
                        //maximum allowed space for content box
                        LineCount = (int)Math.Ceiling(editFieldEntry.Validator.MaxTextLength / (double)CharsPerLine);
                    }
                    break;

                case BoxHeightTypes.Unknown:
                case BoxHeightTypes.SingleLine:
                default:
                    LineCount = 1;
                    break;
                }
                if (LineCount <= 0)
                {
                    LineCount = 1;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Renders the label.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        public bool[,] RenderLabel(EditField_DialogEntry entry, IViewBoxModel view)
        {
            bool[,] labelMatrix = emptyMatrix;

            if (cachedLabelMatrix == null)
            {
                if (view != null && entry != null && entry.HasLabel)
                {
                    string titleBackup = entry.Title;

                    this.Entry.Title = entry.Label;

                    labelMatrix = renderDialogEntry(view);

                    cachedLabelMatrix = labelMatrix;

                    this.Entry.Title = titleBackup;

                    lastLabel = entry.Label;
                }
            }
            else
            {
                labelMatrix = (bool[, ])cachedLabelMatrix.Clone();
            }

            return(labelMatrix);
        }
コード例 #3
0
 /// <summary>
 /// Calculates the box properties.
 /// </summary>
 /// <param name="view">The view.</param>
 /// <param name="entry">The entry.</param>
 public void CalculateBoxProperties(IViewBoxModel view, EditField_DialogEntry entry)
 {
     if (view != null && entry != null)
     {
         calculateLineWidth(view);
         calculateLineContentWidth();
         calculateCharsPerLine();
         CalculateLineCount(entry);
         CalculateLineContentHeight(view);
         CalculateBoxDimensions(view, entry);
     }
 }
コード例 #4
0
        /// <summary>
        /// Calculates the box dimensions.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="editFieldEntry">The edit field entry.</param>
        /// <param name="lineContentWidth">Width of the line content.</param>
        /// <param name="lineWidth">Width of the line.</param>
        /// <param name="lineCount">The line count.</param>
        /// <returns></returns>
        public void CalculateBoxDimensions(IViewBoxModel view, EditField_DialogEntry editFieldEntry)
        {
            Point dimensions = new Point(0, 0);

            if (view != null)
            {
                if (editFieldEntry != null && editFieldEntry.InputBox != null && editFieldEntry.InputBox.IsMinimized && LineWidth != null)
                {
                    dimensions = new Point(LineWidth, CHAR_HEIGHT + (2 * BORDER_THICKNESS));
                }
                else if (LineWidth > 0 && LineContentHeight > 0)
                {
                    dimensions = new Point(LineWidth, LineContentHeight);
                }
            }

            BoxDimensions = dimensions;
        }
コード例 #5
0
 /*Checks if Cursor should be shown/hidden/updated.*/
 private void handleCursorBlinking(EditField_DialogEntry localEntry)
 {
     if (localEntry != null)
     {
         if (localEntry.Status.HasFlag(DialogEntryStatus.Editing))
         {
             if (cursorRenderer.ShouldCursorToggle(localEntry))
             {
                 cursorHasChanged = true;
             }
         }
         else if (!localEntry.Status.HasFlag(DialogEntryStatus.Editing) && cursorRenderer.ShowCursorForBlinking)
         {
             cursorRenderer.ShowCursorForBlinking = false;
             cursorHasChanged = true;
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Inserts the rendered dialog elements in the list of rendered elements.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="verticalOffset">The vertical offset where the elements starts.</param>
        /// <param name="width">The minimum width of this element.</param>
        protected virtual void insertIntoRenderedElements(RenderedDialogEntry entry, int verticalOffset, int horizontalOffset = 0, int minWidth = 0)
        {
            if (entry.M != null && (entry.M.GetLength(0) * entry.M.GetLength(1) > 0))
            {
                if (entry.Entry != null)
                {
                    RenderElement renderElement = new RenderElement(
                        horizontalOffset, verticalOffset,
                        Math.Max(minWidth, entry.M.GetLength(1)), entry.M.GetLength(0) + 1,     // add one pin space underneath for the selection marking
                        entry.Entry);

                    //DISPLAY NAME FOR SINGLE LINE ITEMS
                    if (entry.Entry.Type == DialogEntryType.EditField)
                    {
                        EditField_DialogEntry editField = (EditField_DialogEntry)entry.Entry;

                        if (editField != null && (editField.InputBox.IsMinimized || editField.InputBox.BoxHeightType == BoxHeightTypes.SingleLine || editField.InputBox.MinimizeType == MinimizeTypes.AlwaysMinimize))
                        {
                            renderElement.DisplayName = ((EditFieldRenderer)editField.Renderer).GetLastTitleSegment();
                        }
                        else
                        {
                            renderElement.DisplayName = editField.Title;
                        }


                        if (editField.HasLabel)
                        {
                            renderElement.DisplayName = editField.Label + " " + renderElement.DisplayName;
                        }
                    }
                    RenderedElements.Add(renderElement);
                }
                else if (entry.RenderedElements != null && entry.RenderedElements.Count > 0)
                {
                    foreach (var item in entry.RenderedElements)
                    {
                        RenderedElements.Add(item);
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Renders a content object into an boolean matrix;
        /// while <c>true</c> values indicating raised pins and <c>false</c> values indicating lowered pins
        /// Special Renderer for the EditField types.
        /// </summary>
        /// <param name="view">The frame to render in. This gives access to the space to render and other parameters. Normally this is a IBrailleIOViewRange.</param>
        /// <param name="content">The content to render.</param>
        /// <returns>
        /// A two dimensional boolean M x N matrix (bool[M,N]) where M is the count of rows (this is height)
        /// and N is the count of columns (which is the width).
        /// Positions in the Matrix are of type [i,j]
        /// while i is the index of the row (is the y position)
        /// and j is the index of the column (is the x position).
        /// In the matrix <c>true</c> values indicating raised pins and <c>false</c> values indicating lowered pins
        /// </returns>
        /// <remarks>
        /// Ignores the set content if this render has its own DialogEntry
        /// </remarks>
        public override bool[,] RenderMatrix(IViewBoxModel view, object content)
        {
            bool[,] m = emptyMatrix;

            if (view != null && content != null && content is EditField_DialogEntry)
            {
                Entry          = content as EditField_DialogEntry;
                editFieldEntry = (EditField_DialogEntry)Entry;

                /*EditField items with unknown Box types will be displayed as normal dialog entries.*/
                if (editFieldEntry != null && editFieldEntry.InputBox != null && editFieldEntry.InputBox.BoxHeightType != BoxHeightTypes.Unknown && editFieldEntry.InputBox.MinimizeType != MinimizeTypes.Unknown)
                {
                    HasChanged = changeOccured(view);
                    handleCursorBlinking(editFieldEntry);

                    /*If a cached version exists and nothing has changed, use already cached matrix. Else recalculate.*/
                    if (cachedFinalMatrix == null || HasChanged)
                    {
                        lock (SyncLock)
                        {
                            m = buildCachedFinalMatrix(view);

                            cachedFinalMatrix = (bool[, ])m.Clone();

                            titleHasChanged         = false;
                            borderOrEdgeHaveChanged = false;
                            cursorHasChanged        = false;
                        }
                    }
                    else
                    {
                        m = cachedFinalMatrix;
                    }
                }
                else
                {
                    m = renderDialogEntry(view);
                }
            }
            return(m);
        }
コード例 #8
0
        /// <summary>
        /// Renders  a single line type edit field.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        private bool[,] renderSingleLineTitle(IViewBoxModel view, EditField_DialogEntry entry, int LineContentWidth, int LineCount, int CharsPerLine, Boolean needsUpdate)
        {
            bool[,] renderedText = emptyMatrix;

            if (view != null && Entry != null && entry != null && entry.Title != null)
            {
                int width = LineContentWidth - (CHAR_WIDTH * DOTAMOUNT);

                string titleSegment = "";

                string titleBackup = Entry.Title;

                titleSegment = getTitleSegmentOfSingleLine(width, Entry.Title, entry.GetCursorPosition(), CharsPerLine, needsUpdate);

                Entry.Title  = titleSegment;
                renderedText = renderDialogEntry(view);
                Entry.Title  = titleBackup;

                LastTitleSegment = titleSegment;
            }

            return(renderedText);
        }
コード例 #9
0
        public Boolean ShouldCursorToggle(EditField_DialogEntry localEntry)
        {
            Boolean shouldCursorBeShown = false;

            if (localEntry != null && FrameCount != null)
            {
                FrameCount++;
                if (FrameCount >= FRAME_COUNT_LIMIT && ShowCursorForBlinking != null)
                {
                    if (ShowCursorForBlinking)
                    {
                        ShowCursorForBlinking = false;
                    }
                    else
                    {
                        ShowCursorForBlinking = true;
                    }
                    FrameCount          = 0;
                    shouldCursorBeShown = true;
                }
            }
            return(shouldCursorBeShown);
        }
コード例 #10
0
        /// <summary>
        /// Renders the cursor into the title matrix.
        /// </summary>
        /// <param name="renderedText">The rendered text.</param>
        /// <param name="position">The position.</param>
        /// <returns></returns>
        /// TODO Edit XML Comment Template for renderCursorIntoTitleMatrix
        public bool[,] renderCursorIntoTitleMatrix(bool[,] renderedText, EditField_DialogEntry entry, int position, Boolean needsUpdate)
        {
            if (renderedText != null && position != null && entry != null && ShowCursorForBlinking)
            {
                if (cachedCursorMatrix != null && !needsUpdate)
                {
                    renderedText = cachedCursorMatrix;
                }
                else
                {
                    if (INTER_CHAR_WIDTH > 0)
                    {
                        renderedText = renderCursorAsVerticalLine(renderedText, position, entry.Title);
                    }
                    else
                    {
                        renderedText = renderCursorAsDot(renderedText, position, entry.Title);
                    }

                    cachedCursorMatrix = (bool[, ])renderedText.Clone();
                }
            }
            return(renderedText);
        }
コード例 #11
0
        /// <summary>
        /// Renders the title matrix. Is the content of the edit field box.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        public bool[,] RenderTitleMatrix(IViewBoxModel view, EditField_DialogEntry entry, int LineContentWidth, int LineCount, int CharsPerLine, Boolean needsUpdate)
        {
            bool[,] renderedText = new bool[0, 0];

            if (view != null && entry != null)
            {
                if (!needsUpdate && cachedTitleMatrix != null)
                {
                    renderedText = (bool[, ])cachedTitleMatrix.Clone();
                }
                else
                {
                    Entry = entry;
                    /*Content of Box has smaller Space, so temporary view with smaller content box is needed.*/
                    IViewBoxModel smallerView = new DummyViewBox(view);
                    Rectangle     contentBox  = smallerView.ContentBox;
                    //+1 da sonst statt 105, 104 raus kommt. Benötigt wird %mod3
                    contentBox.Width       = LineContentWidth + 1;
                    smallerView.ContentBox = contentBox;

                    if (entry.Title.Length == 0)
                    {
                        //if content is empty
                        renderedText = new bool[CHAR_HEIGHT, LineContentWidth];
                    }
                    else if (entry.Title.Length * CHAR_WIDTH > LineContentWidth && (entry.InputBox.BoxHeightType == BoxHeightTypes.SingleLine || entry.InputBox.MinimizeType == MinimizeTypes.AlwaysMinimize))
                    {
                        //if editfield box is always minimized or single line type and bigger than a simple line
                        renderedText = renderSingleLineTitle(smallerView, entry, LineContentWidth, LineCount, CharsPerLine, needsUpdate);
                    }
                    else
                    {
                        //If through Minimization some text will not be shown until further action. show "TEXTPART...." instead
                        if (entry.InputBox.IsMinimized && (entry.InputBox.MinimizeType != MinimizeTypes.NeverMinimize) && entry.Title.Length > CharsPerLine)
                        {
                            //backup title, since entry is needed for rendering, but title will be displayed shortened
                            string titleBackup = entry.Title;

                            LastTitleSegment = entry.Title.Substring(0, (CharsPerLine - DOTAMOUNT)) + ALLDOTS;
                            entry.Title      = LastTitleSegment;
                            renderedText     = renderDialogEntry(smallerView);
                            entry.Title      = titleBackup;
                        }
                        //if edit field box will be a simple line: default rendering
                        else if (LineCount == 1)
                        {
                            renderedText = renderDialogEntry(smallerView);
                        }
                        //if edit field box will have more than one line
                        else
                        {
                            renderedText = renderMultiLineTitle(smallerView, entry, LineContentWidth, LineCount, CharsPerLine);
                        }
                    };

                    if (renderedText.GetLength(0) == 0 && renderedText.GetLength(1) == 0)
                    {
                        renderedText = new bool[4, LineContentWidth];
                    }

                    cachedTitleMatrix = (bool[, ])renderedText.Clone();
                }
                lastCursorPosition = entry.GetCursorPosition();
            }

            return(renderedText);
        }
コード例 #12
0
        /// <summary>
        /// Renders the titles that will result in more than one line.
        /// Workaround function. Breaks long strings into parts of length CharsPerLine.
        /// So the MatrixBrailleRenderer will not break strings unpredictable, resulting in
        /// spaces after or between broken parts. --> Causes CursorPosition to fail
        /// </summary>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        private bool[,] renderMultiLineTitle(IViewBoxModel view, EditField_DialogEntry entry, int LineContentWidth, int LineCount, int CharsPerLine)
        {
            if (brailleRenderer == null)
            {
                brailleRenderer = new Renderer.MatrixBrailleRenderer(Renderer.RenderingProperties.IGNORE_LAST_LINESPACE | Renderer.RenderingProperties.RETURN_REAL_WIDTH);
            }
            bool[,] completeMatrix = brailleRenderer.RenderMatrix(view.ContentBox.Width, entry.Title);


            //bool[,] completeMatrix = emptyMatrix;

            //if (view != null && entry != null && entry.Title != null)
            //{

            //    List<string> titleParts = new List<string>();

            //    /*Cut string into CharsPerLine-long bits*/
            //    for (int i = 0; i < LineCount; i++)
            //    {
            //        if (entry.Title.Length > i * CharsPerLine + CharsPerLine)
            //            titleParts.Add(entry.Title.Substring(i * CharsPerLine, CharsPerLine));
            //        else
            //        {
            //            if (entry.Title.Length >= i * CharsPerLine)
            //                titleParts.Add(entry.Title.Substring(i * CharsPerLine));
            //            else break;
            //        }
            //    }

            //    List<bool[,]> boolTitleParts = new List<bool[,]>();

            //    int dimensiony = CHAR_HEIGHT;
            //    int dimensionx = LineContentWidth;

            //    int index = 0;

            //    /*Backup because entry's own renderer will be used. Renderer uses title for rendering.*/
            //    string titleBackup = Entry.Title;

            //    /*Render all string parts seperately*/
            //    foreach (var item in titleParts)
            //    {
            //        if (index > 0) dimensiony = INTER_LINE_HEIGHT + CHAR_HEIGHT + dimensiony;

            //        Entry.Title = item;
            //        boolTitleParts.Add(renderDialogEntry(view));

            //        index++;
            //    }

            //    Entry.Title = titleBackup;

            //    completeMatrix = new bool[dimensiony, dimensionx];

            //    index = 0;
            //    /*Join all seperate rendered string parts into one Matrix*/
            //    foreach (var item in boolTitleParts)
            //    {
            //        for (int i = 0; i < item.GetLength(0); i++)
            //        {
            //            if(i < completeMatrix.GetLength(0))
            //            for (int j = 0; j < item.GetLength(1); j++)
            //            {
            //                try
            //                {
            //                    if (j < completeMatrix.GetLength(1))
            //                    {
            //                        if (index == 0)
            //                            completeMatrix[i, j] = item[i, j];
            //                        else
            //                        {
            //                            completeMatrix[i + (index * (INTER_CHAR_WIDTH + CHAR_HEIGHT)), j] = item[i, j];
            //                        }
            //                    }
            //                }
            //                catch (Exception e)
            //                {
            //                    System.Diagnostics.Debug.WriteLine(e.ToString());
            //                }
            //            }
            //        }
            //        index++;
            //    }

            //}
            return(completeMatrix);
        }