예제 #1
0
        internal void SwapOrientation(IList <WordAndCanvas> wordAndCanvasList, bool memorizeForUndo)
        {
            Debug.Assert(wordAndCanvasList != null && wordAndCanvasList.Count == 1);
            WordAndCanvas wac = wordAndCanvasList.First();

            if (memorizeForUndo)
            {
                viewModel.UndoStack.MemorizeSwapOrientation(wordAndCanvasList);
                viewModel.RemoveWordPosition(wac.WordPosition);

                wac.WordPosition.SetNewPositionOrientation(new PositionOrientation(wac.WordPosition.StartRow, wac.WordPosition.StartColumn, !wac.WordPosition.IsVertical));

                // Do not accept Illegal placements, adjust to only valid placements
                WordPositionLayout         layout      = viewModel.GetLayoutExcludingWordPosition(wac.WordPosition);
                List <PositionOrientation> topLeftList = new List <PositionOrientation>
                {
                    new PositionOrientation(wac.WordPosition.PositionOrientation)
                };
                AdjustToSuitableLocationInLayout(layout, wordAndCanvasList, topLeftList, true);
                wac.WordPosition.SetNewPositionOrientation(topLeftList[0]);
                viewModel.AddWordPosition(wac.WordPosition);
            }
            wac.RebuildCanvasAfterOrientationSwap();    // Only relocate visually letters of the word
            MoveWordAndCanvasList(wordAndCanvasList);   // Visual animation

            FinalRefreshAfterUpdate();
        }
예제 #2
0
        // Initial drawing of for current model layout
        internal IList <WordAndCanvas> AddCanvasForWordPositionList(IEnumerable <WordPosition> wordPositionList)
        {
            List <WordAndCanvas> wordAndCanvasList = new List <WordAndCanvas>();

            // Draw letters
            foreach (WordPosition wp in wordPositionList)
            {
                WordCanvas    wc  = new WordCanvas(wp);
                WordAndCanvas wac = new WordAndCanvas(wp, wc);
                DrawingCanvas.Children.Add(wc);
                m_WordAndCanvasList.Add(wac);
                wordAndCanvasList.Add(wac);
            }

            return(wordAndCanvasList);
        }
예제 #3
0
        // Helper, this was originally in MainGrid_MouseDown handler, but when a right-click occurs,
        // it is assumed than it will select automatically a non-selected word, so code got promoted to its own function...
        private void UpdateSelectionAfterClick(MouseButtonEventArgs e)
        {
            if (DrawingCanvas.InputHitTest(e.GetPosition(DrawingCanvas)) is TextBlock hitTextBlock)
            {
                WordCanvas    hitC = hitTextBlock.Parent as WordCanvas;
                WordAndCanvas hit  = m_WordAndCanvasList.FirstOrDefault(wac => ReferenceEquals(wac.WordCanvas, hitC));
                Debug.Assert(hit != null);

                //Debug.WriteLine("Hit " + hit.WordPosition.ToString());

                // If Ctrl key is NOT pressed, clear previous selection
                // But if we click again in something already selected, do not clear selection!
                if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    if (m_Sel.WordAndCanvasList != null && !m_Sel.WordAndCanvasList.Contains(hit))
                    {
                        m_Sel.Clear();
                    }
                }


                // Add current word to selection
                m_Sel.Add(hit);

                // If Shift key is pressed, selection is extended to connected words
                if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    //viewModel.Layout.GetConnectedWordPositions(hitWP).ForEach(connected => AddWordPositionToSelection(connected));
                    foreach (WordPosition connected in viewModel.Layout.GetConnectedWordPositions(hit.WordPosition))
                    {
                        m_Sel.Add(m_WordAndCanvasList.FirstOrDefault(wac => wac.WordPosition == connected));
                    }
                }

                // Remove and add again elements to move so they're displayed above non-moved elements
                //foreach (WordCanvas wc in m_Sel.WordPositionList.Select(wp => Map.GetWordCanvasFromWordPosition(wp)))
                foreach (WordCanvas wc in m_Sel.WordAndCanvasList.Select(wac => wac.WordCanvas))
                {
                    DrawingCanvas.Children.Remove(wc);
                    DrawingCanvas.Children.Add(wc);
                    wc.SetColor(Brushes.White, Brushes.DarkBlue);
                }
            }
        }
예제 #4
0
        private void RecolorizeWord(WordAndCanvas wac, PlaceWordStatus status)
        {
            bool isInSelection = m_Sel.WordAndCanvasList?.Contains(wac) ?? false;

            switch (status)
            {
            case PlaceWordStatus.Valid:
                if (isInSelection)
                {
                    wac.WordCanvas.SetColor(SelectedValidForeground, SelectedValidBackground);
                }
                else
                {
                    wac.WordCanvas.SetColor(NormalValidForeground, NormalValidBackground);
                }
                break;

            case PlaceWordStatus.TooClose:
                if (isInSelection)
                {
                    wac.WordCanvas.SetColor(SelectedTooCloseForeground, SelectedTooCloseBackground);
                }
                else
                {
                    wac.WordCanvas.SetColor(NormalTooCloseForeground, NormalTooCloseBackground);
                }
                break;

            case PlaceWordStatus.Invalid:
                if (isInSelection)
                {
                    wac.WordCanvas.SetColor(SelectedInvalidForeground, SelectedInvalidBackground);
                }
                else
                {
                    wac.WordCanvas.SetColor(NormalInvalidForeground, NormalInvalidBackground);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
예제 #5
0
 internal static PlaceWordStatus CanPlaceWordInLayout(WordPositionLayout layout, WordAndCanvas wac)
 {
     return(layout.CanPlaceWord(wac.WordPosition, true));
 }
예제 #6
0
 internal PlaceWordStatus CanPlaceWord(WordAndCanvas wac, bool withTooClose)
 {
     return(Layout.CanPlaceWord(wac.WordPosition, withTooClose));
 }