Ejemplo n.º 1
0
        private void DrawRenderingAction(RenderingAction action, Control component, Dictionary <string, object> variables)
        {
            if (variables == null)
            {
                variables = new Dictionary <string, object>();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> kvp in variables)
            {
                dict.Add(kvp.Key, kvp.Value);
            }

            Rectangle bounds = component.Parent.Layout.GetControlBounds(component);

            dict.Add("Component.Width", bounds.Width);
            dict.Add("Component.Height", bounds.Height);

            /*
             * if (component is System.Windows.Forms.ToolStripDropDownMenu)
             * {
             *      System.Windows.Forms.ToolStripDropDownMenu tsddm = (component as System.Windows.Forms.ToolStripDropDownMenu);
             *      if (tsddm.OwnerItem != null)
             *      {
             *              dict.Add("Component.Parent.Width", tsddm.OwnerItem.Width);
             *              dict.Add("Component.Parent.Height", tsddm.OwnerItem.Height);
             *      }
             * }
             * if (component is System.Windows.Forms.ToolStripSplitButton)
             * {
             *      dict.Add("Component.ButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).ButtonBounds.Width);
             *      dict.Add("Component.DropDownButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).DropDownButtonBounds.Width);
             * }
             */

            if (action is RectangleRenderingAction)
            {
                RectangleRenderingAction act = (action as RectangleRenderingAction);

                double x = act.X.Evaluate(dict) + bounds.X;
                double y = act.Y.Evaluate(dict) + bounds.Y;
                double w = act.Width.Evaluate(dict);
                double h = act.Height.Evaluate(dict);

                if (act.Fill != null)
                {
                    FillRectangle(BrushFromFill(act.Fill, new Rectangle(x, y, w, h)), x, y, w, h);
                }
                if (act.Outline != null)
                {
                    if (act.Outline is SolidOutline)
                    {
                        DrawRectangle(PenFromOutline(act.Outline), x, y, w - 1, h - 1);
                    }
                    else if (act.Outline is ThreeDOutline)
                    {
                        ThreeDOutline threed = (act.Outline as ThreeDOutline);

                        Color lightColor = Color.Empty;
                        Color darkColor  = Color.Empty;

                        switch (threed.Type)
                        {
                        case ThreeDOutlineType.Inset:
                        {
                            lightColor = Color.FromString(threed.DarkColor);
                            darkColor  = Color.FromString(threed.LightColor);
                            break;
                        }

                        case ThreeDOutlineType.Outset:
                        {
                            lightColor = Color.FromString(threed.LightColor);
                            darkColor  = Color.FromString(threed.DarkColor);
                            break;
                        }
                        }

                        Pen lightPen = new Pen(lightColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));
                        Pen darkPen  = new Pen(darkColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));

                        DrawLine(lightPen, x, y, x + w, y);
                        DrawLine(lightPen, x, y, x, y + h);
                        DrawLine(darkPen, x + w - 1, y, x + w - 1, y + h - 1);
                        DrawLine(darkPen, x, y + h - 1, x + w - 1, y + h - 1);
                    }
                }
            }
            else if (action is LineRenderingAction)
            {
                LineRenderingAction act = (action as LineRenderingAction);

                double x1 = act.X1.Evaluate(dict) + bounds.X;
                double y1 = act.Y1.Evaluate(dict) + bounds.Y;
                double x2 = act.X2.Evaluate(dict);
                double y2 = act.Y2.Evaluate(dict);

                if (act.Outline != null)
                {
                    DrawLine(PenFromOutline(act.Outline), x1, y1, x2, y2);
                }
            }
            else if (action is TextRenderingAction)
            {
                TextRenderingAction act = (action as TextRenderingAction);

                int    x      = (int)Math.Round(act.X.Evaluate(dict) + bounds.X);
                int    y      = (int)Math.Round(act.Y.Evaluate(dict) + bounds.Y);
                int    width  = (int)Math.Round(act.Width.Evaluate(dict));
                int    height = (int)Math.Round(act.Height.Evaluate(dict));
                Color  color  = Color.FromString(act.Color);
                string value  = act.Value.ReplaceVariables(dict);

                // graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                Font font = SystemFonts.MenuFont;

                /*
                 * if (act.Font != null)
                 * {
                 *      font = Font.FromFamily(act.Font, 8);
                 * }
                 */
                DrawText(value, font, new Rectangle(x, y, width, height), color, act.HorizontalAlignment, act.VerticalAlignment);
            }
        }
Ejemplo n.º 2
0
        private void DrawRenderingAction(RenderingAction action, Control component, Dictionary<string, object> variables)
        {
            if (variables == null) variables = new Dictionary<string, object>();
            Dictionary<string, object> dict = new Dictionary<string, object>();

            foreach (KeyValuePair<string, object> kvp in variables)
            {
                dict.Add(kvp.Key, kvp.Value);
            }

            Rectangle bounds = component.Parent.Layout.GetControlBounds(component);

            dict.Add("Component.Width", bounds.Width);
            dict.Add("Component.Height", bounds.Height);

            /*
            if (component is System.Windows.Forms.ToolStripDropDownMenu)
            {
                System.Windows.Forms.ToolStripDropDownMenu tsddm = (component as System.Windows.Forms.ToolStripDropDownMenu);
                if (tsddm.OwnerItem != null)
                {
                    dict.Add("Component.Parent.Width", tsddm.OwnerItem.Width);
                    dict.Add("Component.Parent.Height", tsddm.OwnerItem.Height);
                }
            }
            if (component is System.Windows.Forms.ToolStripSplitButton)
            {
                dict.Add("Component.ButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).ButtonBounds.Width);
                dict.Add("Component.DropDownButtonWidth", (component as System.Windows.Forms.ToolStripSplitButton).DropDownButtonBounds.Width);
            }
            */

            if (action is RectangleRenderingAction)
            {
                RectangleRenderingAction act = (action as RectangleRenderingAction);

                double x = act.X.Evaluate(dict) + bounds.X;
                double y = act.Y.Evaluate(dict) + bounds.Y;
                double w = act.Width.Evaluate(dict);
                double h = act.Height.Evaluate(dict);

                if (act.Fill != null)
                {
                    FillRectangle(BrushFromFill(act.Fill, new Rectangle(x, y, w, h)), x, y, w, h);
                }
                if (act.Outline != null)
                {
                    if (act.Outline is SolidOutline)
                    {
                        DrawRectangle(PenFromOutline(act.Outline), x, y, w - 1, h - 1);
                    }
                    else if (act.Outline is ThreeDOutline)
                    {
                        ThreeDOutline threed = (act.Outline as ThreeDOutline);

                        Color lightColor = Color.Empty;
                        Color darkColor = Color.Empty;

                        switch (threed.Type)
                        {
                            case ThreeDOutlineType.Inset:
                            {
                                lightColor = Color.FromString(threed.DarkColor);
                                darkColor = Color.FromString(threed.LightColor);
                                break;
                            }
                            case ThreeDOutlineType.Outset:
                            {
                                lightColor = Color.FromString(threed.LightColor);
                                darkColor = Color.FromString(threed.DarkColor);
                                break;
                            }
                        }

                        Pen lightPen = new Pen(lightColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));
                        Pen darkPen = new Pen(darkColor, new Measurement(act.Outline.Width, MeasurementUnit.Pixel));

                        DrawLine(lightPen, x, y, x + w, y);
                        DrawLine(lightPen, x, y, x, y + h);
                        DrawLine(darkPen, x + w - 1, y, x + w - 1, y + h - 1);
                        DrawLine(darkPen, x, y + h - 1, x + w - 1, y + h - 1);
                    }
                }
            }
            else if (action is LineRenderingAction)
            {
                LineRenderingAction act = (action as LineRenderingAction);

                double x1 = act.X1.Evaluate(dict) + bounds.X;
                double y1 = act.Y1.Evaluate(dict) + bounds.Y;
                double x2 = act.X2.Evaluate(dict);
                double y2 = act.Y2.Evaluate(dict);

                if (act.Outline != null)
                {
                    DrawLine(PenFromOutline(act.Outline), x1, y1, x2, y2);
                }
            }
            else if (action is TextRenderingAction)
            {
                TextRenderingAction act = (action as TextRenderingAction);

                int x = (int)Math.Round(act.X.Evaluate(dict) + bounds.X);
                int y = (int)Math.Round(act.Y.Evaluate(dict) + bounds.Y);
                int width = (int)Math.Round(act.Width.Evaluate(dict));
                int height = (int)Math.Round(act.Height.Evaluate(dict));
                Color color = Color.FromString(act.Color);
                string value = act.Value.ReplaceVariables(dict);

                // graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                Font font = SystemFonts.MenuFont;
                /*
                if (act.Font != null)
                {
                    font = Font.FromFamily(act.Font, 8);
                }
                */
                DrawText(value, font, new Rectangle(x, y, width, height), color, act.HorizontalAlignment, act.VerticalAlignment);
            }
        }