Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void UpdateAndDraw(ControlBase control, TimeSpan time)
        {
            if (!(control is Controls.CharacterPicker picker))
            {
                return;
            }

            if (!control.IsDirty)
            {
                return;
            }

            RefreshTheme(control.FindThemeColors(), control);

            SadFont font = (control.AlternateFont ?? control.Parent.Host.ParentConsole.Font) as SadFont ?? throw new NotSupportedException("The character picker control only supports SadFont fonts.");

            // Sync font with control surface
            if (control.Surface.Width != font.Columns || control.Surface.Height != font.Rows)
            {
                control.Resize(font.Columns, font.Rows);
            }

            if (picker.NewCharacterLocation != new Point(-1, -1))
            {
                control.Surface.SetEffect(picker.OldCharacterLocation.X, picker.OldCharacterLocation.Y, null);
            }

            control.Surface.Fill(picker.GlyphForeground, picker.GlyphBackground, 0, null);

            int i = 0;

            for (int y = 0; y < font.Rows; y++)
            {
                for (int x = 0; x < font.Columns; x++)
                {
                    control.Surface.SetGlyph(x, y, i);
                    control.Surface.SetMirror(x, y, picker.MirrorSetting);
                    i++;
                }
            }

            control.Surface.SetForeground(picker.NewCharacterLocation.X, picker.NewCharacterLocation.Y, picker.SelectedGlyphForeground);
            control.Surface.SetEffect(picker.NewCharacterLocation.X, picker.NewCharacterLocation.Y, picker.SelectedGlyphEffect);

            control.IsDirty = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the cell coordinates of the <paramref name="targetFont"/> based on a cell in the <paramref name="sourceFont"/>.
        /// </summary>
        /// <param name="point">The position of the cell in the <paramref name="sourceFont"/>.</param>
        /// <param name="sourceFont">The source font translating from.</param>
        /// <param name="targetFont">The target font translating to.</param>
        /// <returns>The position of the cell in the <paramref name="targetFont"/>.</returns>
        public static Point TranslateFont(this Point point, SadFont sourceFont, SadFont targetFont)
        {
            var world = point.ConsoleLocationToWorld(sourceFont.Size.X, sourceFont.Size.Y);

            return(world.WorldLocationToConsole(targetFont.Size.X, targetFont.Size.Y));
        }