示例#1
0
        static void ExportAsImage()
        {
            // build the display string list
            List <Data.ExportDataEntry> vExportData = Data.ExportData;

            // build the shared line height between calculation (here) and drawing (below)
            const int EXPORTPADDING = 5;
            int       nTextHeight   = 0;

            using (Bitmap bmpTemp = new Bitmap(1, 1))
            {
                using (Graphics gfxTemp = Graphics.FromImage(bmpTemp))
                    nTextHeight = (int)gfxTemp.MeasureString("OK", m_ftExportFont).Height; // just get a line height with this font
            }
            Dictionary <Data.ExportDataEntry.LINETYPE, int> vHeights = new Dictionary <Data.ExportDataEntry.LINETYPE, int>();

            vHeights.Add(Data.ExportDataEntry.LINETYPE.NONE, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.ABILITY, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.AE, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.LEVEL, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.TALENT, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.TE, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.TITLE, nTextHeight);
            vHeights.Add(Data.ExportDataEntry.LINETYPE.CLASSTAG, Properties.Resources.classtag_Druid_Balance.Height + EXPORTPADDING);

            // calculate total height based on the heights list and the data
            int nTotalHeight = 0;

            foreach (var entry in vExportData)
            {
                if (entry == null) // default line height on a fake newline
                {
                    nTotalHeight += vHeights[Data.ExportDataEntry.LINETYPE.NONE];
                    continue;
                }

                // real height for this line
                nTotalHeight += vHeights[entry.Type];
            }

            // create bitmap storage
            // dont use line height, just size of the classtag height
            Bitmap bmpFinal = new Bitmap(355, nTotalHeight, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            // create a gfx from the bitmap for rendering
            Graphics gfx = Graphics.FromImage(bmpFinal);

            // graphics settings
            gfx.SmoothingMode     = SmoothingMode.AntiAlias;
            gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
            gfx.PixelOffsetMode   = PixelOffsetMode.HighQuality;

            // render
            // background
            GraphicsUnit unit        = GraphicsUnit.Pixel;
            RectangleF   rectfBounds = bmpFinal.GetBounds(ref unit);

            Brush brBackground;

            // background gradient?
            if (Options.ExportBackground == "")
            {
                brBackground = new LinearGradientBrush(rectfBounds, Options.ExportGradientLeft, Options.ExportGradientRight, LinearGradientMode.Horizontal);
            }
            else // background image
            {
                brBackground = new TextureBrush(Ascension_Calculator.Properties.Resources.ResourceManager.GetObject("tiled_" + Options.ExportBackground) as Bitmap, WrapMode.Tile);
            }
            gfx.FillRectangle(brBackground, rectfBounds);
            brBackground.Dispose(); // done with background

            using (Pen p = new Pen(Color.Black, 3.0f))
                gfx.DrawRectangle(p, 0, 0, rectfBounds.Width, rectfBounds.Height);

            // string lines
            PointF ptLocation = new PointF(EXPORTPADDING, EXPORTPADDING);

            foreach (var data in vExportData)
            {
                if (data == null)
                {
                    ptLocation.Y += vHeights[Data.ExportDataEntry.LINETYPE.NONE];
                    continue; // dont handle this line, only "newline" it
                }

                Bitmap bmpShared   = null; // should get set
                PointF ptTemp      = new PointF(ptLocation.X, ptLocation.Y);
                string szText      = data.Text;
                Brush  brForeColor = Brushes.White;
                switch (data.Type)
                {
                case Data.ExportDataEntry.LINETYPE.CLASSTAG:
                    // draw classtag image
                    object[] arr         = (object[])data.Data;
                    Bitmap   bmpClasstag = UITools.GetClasstagImage((string)arr[0]) as Bitmap;
                    gfx.DrawImage(bmpClasstag, ptTemp);
                    ptTemp.X += bmpClasstag.Width + EXPORTPADDING;     // move over for next element
                    // draw ae investment
                    Bitmap bmpAE = UITools.GetInvestmentImage(Data.INVESTMENT.AE) as Bitmap;
                    ptTemp.Y += (bmpClasstag.Height >> 1) - (bmpAE.Height >> 1);
                    gfx.DrawImage(bmpAE, ptTemp);
                    ptTemp.X += bmpAE.Width + EXPORTPADDING;
                    string szAEInvestment = ((int)arr[1]).ToString();
                    UITools.DrawShadowString(gfx, m_ftExportFont, Brushes.DeepSkyBlue, szAEInvestment, (int)ptTemp.X, (int)ptTemp.Y);
                    ptTemp.X += gfx.MeasureString(szAEInvestment, m_ftExportFont).Width + EXPORTPADDING;
                    // draw te investment
                    Bitmap bmpTE = UITools.GetInvestmentImage(Data.INVESTMENT.TE) as Bitmap;
                    gfx.DrawImage(bmpTE, ptTemp);
                    ptTemp.X += bmpTE.Width + EXPORTPADDING;
                    string szTEInvestment = ((int)arr[2]).ToString();
                    UITools.DrawShadowString(gfx, m_ftExportFont, Brushes.Violet, szTEInvestment, (int)ptTemp.X, (int)ptTemp.Y);
                    // go down
                    ptLocation.Y += vHeights[Data.ExportDataEntry.LINETYPE.CLASSTAG];
                    break;

                case Data.ExportDataEntry.LINETYPE.ABILITY:
                    Skill sk = data.Data as Skill;
                    // indent without \t
                    ptTemp.X += 20;
                    // store icon to draw
                    bmpShared = UITools.SmallIconImageList.Images[sk.IconAsString] as Bitmap;
                    // cut off tabs
                    szText = szText.Replace("\t", "");
                    // change to class color
                    brForeColor = new SolidBrush(UITools.GetClassColor(sk.Class));
                    goto case Data.ExportDataEntry.LINETYPE.NONE;     // noice

                case Data.ExportDataEntry.LINETYPE.TALENT:
                    // nothing to do lul, switch gotos too goog
                    goto case Data.ExportDataEntry.LINETYPE.ABILITY;

                case Data.ExportDataEntry.LINETYPE.AE:
                    bmpShared = UITools.GetInvestmentImage(Data.INVESTMENT.AE) as Bitmap;
                    // change color
                    brForeColor = Brushes.DeepSkyBlue;
                    goto case Data.ExportDataEntry.LINETYPE.NONE;     // noice

                case Data.ExportDataEntry.LINETYPE.TE:
                    bmpShared = UITools.GetInvestmentImage(Data.INVESTMENT.TE) as Bitmap;
                    // change color
                    brForeColor = Brushes.Violet;
                    goto case Data.ExportDataEntry.LINETYPE.NONE;     // noice

                case Data.ExportDataEntry.LINETYPE.LEVEL:
                    bmpShared = UITools.SmallIconImageList.Images["level"] as Bitmap;
                    // change color
                    brForeColor = Brushes.Gold;
                    goto case Data.ExportDataEntry.LINETYPE.NONE;     // noice

                case Data.ExportDataEntry.LINETYPE.TITLE:
                    goto case Data.ExportDataEntry.LINETYPE.NONE;     // noice

                case Data.ExportDataEntry.LINETYPE.NONE:
                    // draw icon
                    if (bmpShared != null)
                    {
                        gfx.DrawImage(bmpShared, ptTemp);
                        // go over
                        ptTemp.X += bmpShared.Width + EXPORTPADDING;
                    }
                    // draw remainder string
                    UITools.DrawShadowString(gfx, m_ftExportFont, brForeColor, szText, (int)ptTemp.X, (int)ptTemp.Y);
                    // go down
                    ptLocation.Y += vHeights[Data.ExportDataEntry.LINETYPE.NONE];
                    break;
                }

                // reset point x
                ptLocation.X = EXPORTPADDING;
            }

            // done
            gfx.Flush();
            gfx.Dispose();

            try
            {
                // done, copy to clipboard lul
                //Clipboard.SetText(szFinal, TextDataFormat.Text);
                Clipboard.SetImage(bmpFinal);
            }
            catch (Exception) { }

            MessageBox.Show("Copied build to clipboard as image!", "Share Build");
        }
        override protected bool My_OnPaint(Graphics gfx)
        {
            // do default
            if (!base.My_OnPaint(gfx)) // checks for classtag validity for us
            {
                return(false);         // halt
            }
            // prepare to draw, sir
            Point ptLoc = new Point();

            string[] szLines = new string[3];

            // draw all our abilites for this classpec
            List <SkillUI> vGridData = GetGridData(Data.SelectedClasstag);

            int nIconSize = IconSize;

            foreach (var sUI in vGridData)
            {
                Point ptIcon = GetScrolledGridLocation(sUI.XGrid, sUI.YGrid);

                // prepare the text(s) to be shown
                string szSkillName = sUI.Skill.Name;

                // truncate too long names
                if (szSkillName.Length > NAME_TRUNC_LIMIT + 3)
                {
                    szSkillName  = szSkillName.Remove(NAME_TRUNC_LIMIT);
                    szSkillName += "...";
                }

                szLines[0] = szSkillName;
                szLines[1] = "Level " + sUI.Skill.RequiredLevel;
                szLines[2] = sUI.Skill.AECost + " AE";

                ptLoc.Y = ptIcon.Y + nIconSize - 8;
                // position each line (by row)
                foreach (var szLine in szLines)
                {
                    SizeF sizeString = gfx.MeasureString(szLine, m_ftText);
                    ptLoc.X  = ptIcon.X + (nIconSize >> 1) - ((int)(sizeString.Width) >> 1);
                    ptLoc.Y += (int)sizeString.Height - 1;

                    // draw text (WITH SHADOW!) (based on learned color)
                    Brush brush = Brushes.White;
                    if (Data.IsSkillLearned(sUI.Skill))
                    {
                        brush = UITools.Brush_Green;
                    }
                    else if (!Data.CanSkillBeLearned(sUI.Skill))
                    {
                        brush = UITools.Brush_Red;
                    }

                    UITools.DrawShadowString(gfx, m_ftText, brush, szLine, ptLoc.X, ptLoc.Y);
                }
            }

            // done
            return(true);
        }