Exemple #1
0
        /// <summary>
        /// Returns the brush used to draw the Axis dot
        /// </summary>
        /// <param name="style">The Axis style.</param>
        /// <param name="x">The Axis x coordinate.</param>
        /// <param name="y">The Axis y coordinate.</param>
        /// <returns></returns>
        public Brush GetAxisBrush(DirectInputAxisStyle style, Rectangle boundingBox, int x, int y)
        {
            if (style != null)
            {
                string imageFileName = style.BackgroundNeutralImageFileName;
                double relativeX     = (double)x / (double)AxisOneMax;
                double relativeY     = (double)y / (double)AxisTwoMax;

                if (relativeX < 0.4 && relativeY > 0.4 && relativeY < 0.6)
                {
                    imageFileName = style.BackgroundLeftImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeX > 0.6 && relativeY > 0.4 && relativeY < 0.6)
                {
                    imageFileName = style.BackgroundRightImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeY < 0.4 && relativeX > 0.4 && relativeX < 0.6)
                {
                    imageFileName = style.BackgroundTopImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeY > 0.6 && relativeX > 0.4 && relativeX < 0.6)
                {
                    imageFileName = style.BackgroundBottomImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeX < 0.4 && relativeY < 0.4)
                {
                    imageFileName = style.BackgroundTopLeftImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeX > 0.6 && relativeY < 0.4)
                {
                    imageFileName = style.BackgroundTopRightImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeX < 0.4 && relativeY > 0.6)
                {
                    imageFileName = style.BackgroundBottomLeftImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                if (relativeX > 0.6 && relativeY > 0.6)
                {
                    imageFileName = style.BackgroundBottomRightImageFileName ?? style.BackgroundNeutralImageFileName;
                }

                return(imageFileName == null || !FileHelper.StyleImageExists(imageFileName)
                    ? string.IsNullOrEmpty(style.BackgroundNeutralImageFileName) || !FileHelper.StyleImageExists(style.BackgroundNeutralImageFileName) ?
                       new SolidBrush(style.ForegroundColor) : this.BrushFromImage(boundingBox, style.BackgroundNeutralImageFileName)
                    : this.BrushFromImage(boundingBox, imageFileName));
            }
            else
            {
                return(new SolidBrush(GlobalSettings.CurrentStyle.DefaultDirectInputAxisStyle.ForegroundColor));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyStyleForm" /> class.
        /// </summary>
        /// <param name="initialStyle">The initial style.</param>
        /// <param name="defaultStyle">The default style to revert to when the override checkbox is unchecked.</param>
        public DirectInputAxisStyleForm(DirectInputAxisStyle initialStyle, DirectInputAxisStyle defaultStyle)
        {
            if (defaultStyle == null)
            {
                throw new ArgumentNullException(nameof(defaultStyle));
            }
            if (defaultStyle.SubStyle == null)
            {
                throw new ArgumentNullException(nameof(defaultStyle));
            }

            this.initialStyle = ((DirectInputAxisStyle)initialStyle?.Clone()) ?? new DirectInputAxisStyle {
                SubStyle = null
            };
            this.defaultStyle = (DirectInputAxisStyle)defaultStyle?.Clone();
            this.currentStyle = (DirectInputAxisStyle)this.initialStyle.Clone();
            this.currentStyle.DrawAxisBackground = true;

            this.InitializeComponent();
        }