CardMaker.Card.CardRenderer.DrawCard C# (CSharp) Method

DrawCard() public method

public DrawCard ( int nX, int nY, Graphics zGraphics, CardMaker.Card.DeckLine zDeckLine, bool bExport, bool bDrawBackground ) : void
nX int
nY int
zGraphics System.Drawing.Graphics
zDeckLine CardMaker.Card.DeckLine
bExport bool
bDrawBackground bool
return void
        public void DrawCard(int nX, int nY, Graphics zGraphics, DeckLine zDeckLine, bool bExport, bool bDrawBackground)
        {
            List<string> listLine = zDeckLine.LineColumns;

            // Custom Graphics Setting
            zGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            zGraphics.SmoothingMode = SmoothingMode.AntiAlias;
            //zGraphics.SmoothingMode = SmoothingMode.HighQuality;

            var matrixOriginal = zGraphics.Transform;

            // Zoom does not apply to export
            if (!bExport)
            {
                zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                // Custom Graphics Setting

                zGraphics.InterpolationMode = 1.0f != ZoomLevel
                    ? InterpolationMode.NearestNeighbor
                    : InterpolationMode.Bilinear;
            }

            //Logger.Clear();
            ProjectLayoutElement zSelectedElement = null;

            if (!bExport)
            {
                zSelectedElement = ElementManager.Instance.GetSelectedElement();
            }

            // draw the background
            if (bDrawBackground)
            {
                zGraphics.FillRectangle(Brushes.White, nX, nY, CurrentDeck.CardLayout.width,
                    CurrentDeck.CardLayout.height);
            }

            // All drawing is handled in reverse element order

            if (null != CurrentDeck.CardLayout.Element)
            {
                for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                {
                    var zElement = CurrentDeck.CardLayout.Element[nIdx];
                    if (zElement.enabled) // only add enabled items to draw
                    {
                        IssueManager.Instance.FireChangeElementEvent(zElement.name);

                        // get override Element
                        ProjectLayoutElement zOverrideElement = CurrentDeck.GetOverrideElement(zElement, listLine, zDeckLine, bExport);
                        var zDrawElement = zOverrideElement;

                        // translate any index values in the csv
                        var zElementString = CurrentDeck.TranslateString(zDrawElement.variable, zDeckLine, zDrawElement, bExport);

                        // enabled is re-checked due to possible override of the enabled value
                        if (!zElementString.DrawElement || !zDrawElement.enabled)
                        {
                            continue;
                        }

                        var eType = DrawItem.GetElementType(zDrawElement.type);

                        //NOTE: removed transform backup (draw element resets it anyway...)
                        //if (!bExport) // backup is only necessary for zoomed canvas
                        //{
                            //matrixPrevious = zGraphics.Transform;
                        //}
                        DrawItem.DrawElement(zGraphics, CurrentDeck, zDrawElement, eType, nX, nY, zElementString.String, bExport);
                        if (!bExport)
                        {
                            //zGraphics.Transform = matrixPrevious;
                            zGraphics.ScaleTransform(ZoomLevel, ZoomLevel);
                        }
                    }
                }

                if (!bExport)
                {
                    // draw all selections and element borders after everything else
                    for (var nIdx = CurrentDeck.CardLayout.Element.Length - 1; nIdx > -1; nIdx--)
                    {
                        ProjectLayoutElement zElement = CurrentDeck.CardLayout.Element[nIdx];
                        if (zElement.enabled) // only add enabled items to draw
                        {
                            var bDrawSelection = zSelectedElement == zElement;

                            if (CardMakerInstance.DrawElementBorder)
                            {
                                var matrixPrevious = zGraphics.Transform;
                                DrawItem.DrawElementDebugBorder(zGraphics, zElement, nX, nY, bDrawSelection);
                                zGraphics.Transform = matrixPrevious;
                            }
                        }
                    }
                }
            }
            // draw the card border
            if ((bExport && CardMakerSettings.PrintLayoutBorder) || (!bExport && CurrentDeck.CardLayout.drawBorder))
            {
                // note that the border is inclusive in the width/height consuming 2 pixels (0 to total-1)
                zGraphics.DrawRectangle(Pens.Black, nX, nY, CurrentDeck.CardLayout.width - 1, CurrentDeck.CardLayout.height - 1);
            }

            zGraphics.Transform = matrixOriginal;
        }

Usage Example

Ejemplo n.º 1
0
 protected override void OnPaint(PaintEventArgs e)
 {
     if (ActiveDeck?.CardLayout == null)
     {
         e.Graphics.FillRectangle(Brushes.White, 0, 0, Size.Width, Size.Height);
         e.Graphics.DrawString("Select a Layout in the Project Window", new Font(DefaultFont.FontFamily, 20), Brushes.Red, new RectangleF(10, 10, Size.Width - 10, Size.Height - 10));
         return;
     }
     
     if (-1 != ActiveDeck.CardIndex && ActiveDeck.CardIndex < ActiveDeck.CardCount)
     {
         m_zCardRenderer.DrawCard(0, 0, e.Graphics, ActiveDeck.CurrentLine, false, true);
     }
 }