Example #1
0
        public override bool Render(ProjectLayoutElement zElement, Graphics zGraphics)
        {
            if (zElement.height < (TargetRect.Y + TargetRect.Height))
            {
                // too tall, completely end the draw
                return(false);
            }

            // draw border (debugging)
            if (CardMakerInstance.DrawFormattedTextBorder)
            {
                zGraphics.DrawRectangle(Pens.Green, TargetRect.X + m_fXOffset, TargetRect.Y + m_fYOffset, TargetRect.Width, TargetRect.Height);
            }

            // already null checked in the ProcessMarkup
            var zBmp = DrawItem.LoadImageFromCache(m_sImageFile);

            zGraphics.DrawImage(zBmp, TargetRect.X + m_fXOffset, TargetRect.Y + m_fYOffset, TargetRect.Width, TargetRect.Height);

            if (CardMakerInstance.DrawFormattedTextBorder)
            {
                zGraphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 255, 0, 0)), TargetRect.X, TargetRect.Y, TargetRect.Width, TargetRect.Height);
            }

            return(true);
        }
Example #2
0
        public override bool Render(ProjectLayoutElement zElement, Graphics zGraphics)
        {
            // already null checked in the ProcessMarkup
            var zBmp = DrawItem.LoadImageFromCache(m_sImageFile);

            zGraphics.DrawImage(zBmp, TargetRect.X + m_fXOffset, TargetRect.Y + m_fYOffset, m_nWidth, m_nHeight);

            if (CardMakerInstance.DrawFormattedTextBorder)
            {
                zGraphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 255, 0)), TargetRect.X, TargetRect.Y, m_nWidth, m_nHeight);
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// Processes the image markup and if the image is valid associates it with the current process data.
        /// </summary>
        /// <param name="zElement"></param>
        /// <param name="zData"></param>
        /// <param name="zProcessData"></param>
        /// <param name="zGraphics"></param>
        /// <returns>false -  The BackgroundImageMarkup.Render is called as part of a TextMarkup</returns>
        public override bool ProcessMarkup(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
        {
            var arrayComponents = m_sVariable.Split(new char[] { ';' });

            if (1 > arrayComponents.Length)
            {
                return(false);
            }

            StringAlignment = zProcessData.CurrentStringAlignment;
            LineNumber      = zProcessData.CurrentLine;

            m_sImageFile = arrayComponents[0];

            var zBmp = DrawItem.LoadImageFromCache(m_sImageFile);

            m_fXOffset = zProcessData.CurrentXOffset;
            m_fYOffset = zProcessData.CurrentYOffset;

            if (null != zBmp)
            {
                switch (arrayComponents.Length)
                {
                case 1:
                    m_nWidth   = zBmp.Width;
                    m_nHeight  = zBmp.Height;
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, 0, 0);
                    return(true);

                case 5:
                {
                    if (ParseUtil.ParseFloat(arrayComponents[1], out m_fXOffset) &&
                        ParseUtil.ParseFloat(arrayComponents[2], out m_fYOffset) &&
                        int.TryParse(arrayComponents[3], out m_nWidth) &&
                        int.TryParse(arrayComponents[4], out m_nHeight))
                    {
                        TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, 0, 0);
                        return(true);
                    }
                }
                break;
                }
            }

            return(false);
        }
Example #4
0
 private void btnSetSizeToImage_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtElementVariable.Text))
     {
         var zBmp = DrawItem.LoadImageFromCache(txtElementVariable.Text);
         if (null == zBmp)
         {
             var zElement = ElementManager.Instance.GetSelectedElement();
             if (null != zElement)
             {
                 var zElementString = LayoutManager.Instance.ActiveDeck.GetStringFromTranslationCache(zElement.name);
                 if (null != zElementString.String)
                 {
                     zBmp = DrawItem.LoadImageFromCache(zElementString.String);
                 }
             }
         }
         if (null != zBmp)
         {
             numericElementW.Value = zBmp.Width;
             numericElementH.Value = zBmp.Height;
         }
     }
 }
Example #5
0
        public override bool ProcessMarkup(ProjectLayoutElement zElement, FormattedTextData zData, FormattedTextProcessData zProcessData, Graphics zGraphics)
        {
            var arrayComponents = m_sVariable.Split(new char[] { ';' });

            if (1 > arrayComponents.Length)
            {
                return(false);
            }
            LineNumber = zProcessData.CurrentLine;

            m_sImageFile = arrayComponents[0];

            var zBmp = DrawItem.LoadImageFromCache(m_sImageFile);

            if (null == zBmp)
            {
                return(false);
            }

            var fLineHeightPercent = -1f;

            // SOOOOO much duplication
            switch (arrayComponents.Length)
            {
            case 1:
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                break;

            case 2:
                float.TryParse(arrayComponents[1], out fLineHeightPercent);
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                break;

            case 3:
                if (float.TryParse(arrayComponents[1], out m_fXOffset) &&
                    float.TryParse(arrayComponents[2], out m_fYOffset))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                }
                break;

            case 4:
                float.TryParse(arrayComponents[1], out fLineHeightPercent);
                if (float.TryParse(arrayComponents[2], out m_fXOffset) &&
                    float.TryParse(arrayComponents[3], out m_fYOffset))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, zBmp.Width, zBmp.Height);
                }
                break;

            case 5:     // width and height are absolute (even overlapping drawing)
            {
                int nWidth;
                int nHeight;
                if (float.TryParse(arrayComponents[1], out m_fXOffset) &&
                    float.TryParse(arrayComponents[2], out m_fYOffset) &&
                    int.TryParse(arrayComponents[3], out nWidth) &&
                    int.TryParse(arrayComponents[4], out nHeight))
                {
                    TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, nWidth, nHeight);
                }
            }
            break;
            }

            if (TargetRect == RectangleF.Empty)
            {
                return(false);
            }

            m_fXOffset += zProcessData.CurrentXOffset;
            m_fYOffset += zProcessData.CurrentYOffset;

            if (-1f != fLineHeightPercent)
            {
                var aspectRatio = TargetRect.Width / TargetRect.Height;
                var fNewHeight  = fLineHeightPercent * (zProcessData.FontHeight == 0f ? 1f : (float)zProcessData.FontHeight);
                var fNewWidth   = fNewHeight * aspectRatio;
                TargetRect = new RectangleF(zProcessData.CurrentX, zProcessData.CurrentY, fNewWidth, fNewHeight);
            }

            // newline eval
            if (TargetRect.Width + TargetRect.X > zElement.width)
            {
                zProcessData.MoveToNextLine(zElement);
                TargetRect = new RectangleF(0, zProcessData.CurrentY, TargetRect.Width, TargetRect.Height);
            }

            // cap off excessively wide images
            if (TargetRect.Width + TargetRect.X > zElement.width)
            {
                TargetRect = new RectangleF(TargetRect.X, TargetRect.Y, zElement.width, TargetRect.Height);
            }

            // Center the image on the line based on font height or line height (todo figure out which...)
            TargetRect = new RectangleF(TargetRect.X,
                                        TargetRect.Y + (((float)zProcessData.FontHeight - (float)TargetRect.Height) / 2f), TargetRect.Width, TargetRect.Height);

            zProcessData.CurrentX += TargetRect.Width;

            return(true);
        }