Exemplo n.º 1
0
        /// <summary>Renders a single control</summary>
        /// <param name="controlToRender">Control that will be rendered</param>
        private void renderControl(Controls.Control controlToRender)
        {
            IControlRendererAdapter renderer = null;

            Type controlType = controlToRender.GetType();

            // If this is an actual instance of the 'Control' class, don't render it.
            // Such instances can be used to construct invisible containers, and are most
            // prominently embodied in the 'desktop' control that hosts the whole GUI.
            if (
                (controlType == typeof(Controls.Control)) ||
                (controlType == typeof(Controls.DesktopControl))
                )
            {
                return;
            }

            // Find a renderer for this control. If no renderer for the control itself can
            // be found, look for a renderer then can render its base class. This allows
            // controls to inherit from existing controls, remaining renderable (but also
            // gaining the ability to accept a specialized renderer for the new derived
            // control class!). Normally, this loop will finish without any repetitions.
            while (controlType != typeof(object))
            {
                bool found = this.employer.Renderers.TryGetValue(controlType, out renderer);
                if (found)
                {
                    break;
                }

                // Next, try the base class of this type
                controlType = controlType.BaseType;
            }

            // If we found a renderer, use it to render the control
            if (renderer != null)
            {
                renderer.Render(controlToRender, this.flatGuiGraphics);
            }
            else // No renderer found, output a warning
            {
#if WINDOWS
                Trace.WriteLine(
                    string.Format(
                        "Warning: No renderer found for control '{0}' or any of its base classes.\n" +
                        "         Control will not be rendered.",
                        controlToRender.GetType().FullName.ToString()
                        )
                    );
#endif
            }
        }
Exemplo n.º 2
0
        /// <summary>Renders a single control</summary>
        /// <param name="controlToRender">Control that will be rendered</param>
        private void renderControl(Controls.Control controlToRender)
        {
            IControlRendererAdapter renderer = null;

            Type controlType = controlToRender.GetType();

            // If this is an actual instance of the 'Control' class, don't render it.
            // Such instances can be used to construct invisible containers, and are most
            // prominently embodied in the 'desktop' control that hosts the whole GUI.
            if (
                (controlType == typeof(Controls.Control)) ||
                (controlType == typeof(Controls.DesktopControl))
                )
            {
                return;
            }

            // Find a renderer for this control. If no renderer for the control itself can
            // be found, look for a renderer then can render its base class. This allows
            // controls to inherit from existing controls, remaining renderable (but also
            // gaining the ability to accept a specialized renderer for the new derived
            // control class!). Normally, this loop will finish without any repetitions.
            while (controlType != typeof(object))
            {
                bool found = this.employer.Renderers.TryGetValue(controlType, out renderer);
                if (found)
                {
                    break;
                }

                // Next, try the base class of this type
                controlType = controlType.BaseType;
            }

            // If we found a renderer, use it to render the control
            if (renderer != null)
            {
                renderer.Render(controlToRender, this.flatGuiGraphics);
            }
            else
            { // No renderer found, output a warning
#if DEBUG
                if (controlToRender.IsVisible == true)
                {
                    logger.Warn("Impossible to find a control renderer for the component type : {0}, are you sure its assembly has been registered ??", controlToRender.GetType());
                }
#endif
            }
        }