Ejemplo n.º 1
0
        /// <summary>
        /// Combines the layers using their views onto its own TextGrid.
        /// </summary>
        private void CombineLayers()
        {
            var sortedLayers = _layers.OrderBy(layer => layer.zIndex).ToList();

            _textGrid.Reset();
            foreach (Layer layer in sortedLayers)
            {
                View view = layer.RenderView();

                for (var row = 0; row < view.size.rows; row++)
                {
                    for (var column = 0; column < view.size.columns; column++)
                    {
                        int monitorPositionRow    = view.externalPosition.row + row;
                        int monitorPositionColumn = view.externalPosition.column + column;

                        if (monitorPositionRow >= _textGrid.GetSize().rows)
                        {
                            continue;
                        }
                        if (monitorPositionColumn >= _textGrid.GetSize().columns)
                        {
                            continue;
                        }

                        _textGrid[monitorPositionRow, monitorPositionColumn] = view.textGrid[row, column];
                    }
                }

                layer.Change(false);
                layer.view.Change(false);
            }
        }
Ejemplo n.º 2
0
        // Rendering
        /// <summary>
        /// Make a 2d slice of the text grid using the internal position of the view to this grid, and the size of the view.
        /// </summary>
        /// <param name="externalTextGrid">The external grid to take a slice out of.</param>
        public void SetText(TextGrid externalTextGrid)
        {
            var externalSize = externalTextGrid.GetSize();

            textGrid = new TextGrid(size);

            int endRow    = internalPosition.row + size.rows - 1;
            int endColumn = internalPosition.column + size.columns - 1;

            int maxRow = Math.Min(endRow + 1, externalSize.rows);
            int maxCol = Math.Min(endColumn + 1, externalSize.columns);

            for (int row = internalPosition.row; row < maxRow; row++)
            {
                for (int column = internalPosition.column; column < maxCol; column++)
                {
                    char character = externalTextGrid[row, column];

                    int textRow    = row - internalPosition.row;
                    int textColumn = column - internalPosition.column;

                    textGrid[textRow, textColumn] = character;
                }
            }

            Change();
        }