Example #1
0
        /// <summary>
        /// Calculate the requested display size for the radio button.
        /// </summary>
        /// <param name="context">Render context.</param>
        /// <param name="palette">Palette for sourcing display values.</param>
        /// <param name="enabled">Should check box be displayed as enabled.</param>
        /// <param name="checkState">Checked state of the radio button.</param>
        /// <param name="tracking">Should check box be displayed as hot tracking.</param>
        /// <param name="pressed">Should check box be displayed as pressed.</param>
        public override Size GetRadioButtonPreferredSize(ViewLayoutContext context,
                                                         IPalette palette,
                                                         bool enabled,
                                                         bool checkState,
                                                         bool tracking,
                                                         bool pressed)
        {
            // Grab an image appropriate to the state
            Image drawImage = palette.GetRadioButtonImage(enabled, checkState, tracking, pressed);

            if (drawImage == null)
            {
                // Convert incoming parameters to radio button state
                RadioButtonState state = DiscoverRadioButtonState(enabled, checkState, tracking, pressed);

                // Request the drawing size of the radio button glyph
                return RadioButtonRenderer.GetGlyphSize(context.Graphics, state);
            }
            else
                return drawImage.Size;
        }
Example #2
0
        /// <summary>
        /// Perform drawing of a radio button.
        /// </summary>
        /// <param name="context">Render context.</param>
        /// <param name="displayRect">Display area available for drawing.</param>
        /// <param name="palette">Palette for sourcing display values.</param>
        /// <param name="enabled">Should radio button be displayed as enabled.</param>
        /// <param name="checkState">Checked state of the radio button.</param>
        /// <param name="tracking">Should radio button be displayed as hot tracking.</param>
        /// <param name="pressed">Should radio button be displayed as pressed.</param>
        public override void DrawRadioButton(RenderContext context,
                                             Rectangle displayRect,
                                             IPalette palette,
                                             bool enabled,
                                             bool checkState,
                                             bool tracking,
                                             bool pressed)
        {
            Debug.Assert(context != null);
            Debug.Assert(palette != null);

            // Validate parameter references
            if (context == null) throw new ArgumentNullException("context");
            if (palette == null) throw new ArgumentNullException("palette");

            // Grab an image appropriate to the state
            Image drawImage = palette.GetRadioButtonImage(enabled, checkState, tracking, pressed);

            // If no image from the palette then get a system radio button
            if (drawImage == null)
            {
                // Convert incoming parameters to radio button state
                RadioButtonState state = DiscoverRadioButtonState(enabled, checkState, tracking, pressed);

                // Request the glyph be drawn at the top left of the display rectangle
                RadioButtonRenderer.DrawRadioButton(context.Graphics, displayRect.Location, state);
            }
            else
            {
                // Find the offset to center the image
                int xOffset = (displayRect.Width - drawImage.Width) / 2;
                int yOffset = (displayRect.Height - drawImage.Height) / 2;

                // Draw the image centered
                context.Graphics.DrawImage(drawImage,
                                           displayRect.X + xOffset, displayRect.Y + yOffset,
                                           drawImage.Width, drawImage.Height);
            }
        }