void SkillListView_OnFormatRow(object sender, FormatRowEventArgs e) { const float fLightValue = 1.5f; Skill sk = (Skill)e.Model; // get the real class color Color clrClass = UITools.GetClassColor(sk.Class); // lighten it up (god damn it looks bad otherwise) int nR = Math.Min(255, (int)(clrClass.R * fLightValue)); int nG = Math.Min(255, (int)(clrClass.G * fLightValue)); int nB = Math.Min(255, (int)(clrClass.B * fLightValue)); e.Item.BackColor = Color.FromArgb(nR, nG, nB); // check availability of this skill if (IsSkillGood(sk)) { e.Item.Decoration = null; e.Item.ForeColor = Color.Black; } else { e.Item.Decoration = m_decorRowRed; e.Item.ForeColor = Color.FromArgb(128, UITools.Red); } }
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"); }
void RenderInvestmentGraph(ToolStripStatusLabel lbl) { Image imgOld = lbl.BackgroundImage; List <string> vFinalTag = new List <string>(); // get all investments from data Dictionary <string, Data.Investment> investments = Data.Investments; // determine total variable by sender (ae/te/both) int nTotal; if (lbl.Name.Contains("AE")) { nTotal = Data.GetTotalInvestments(Data.INVESTMENT.AE); } else if (lbl.Name.Contains("TE")) { nTotal = Data.GetTotalInvestments(Data.INVESTMENT.TE); } else { nTotal = Data.GetTotalInvestments(Data.INVESTMENT.AE) + Data.GetTotalInvestments(Data.INVESTMENT.TE); } Rectangle rectCurrent = new Rectangle(0, 0, lbl.Width, lbl.Height); Bitmap bmpFinal = new Bitmap(lbl.Width, lbl.Height); Graphics gfx = Graphics.FromImage(bmpFinal); SolidBrush brClasstagColor = new SolidBrush(Color.White); if (nTotal > 0) { foreach (KeyValuePair <string, Data.Investment> entry in investments) { int nClasstagValue; if (lbl.Name.Contains("AE")) { nClasstagValue = entry.Value.AE; } else if (lbl.Name.Contains("TE")) { nClasstagValue = entry.Value.TE; } else { nClasstagValue = entry.Value.AE + entry.Value.TE; } if (nClasstagValue == 0) { continue; // dont change the color } brClasstagColor.Color = UITools.GetClassColor(entry.Key.Split("_".ToCharArray())[0]); // get color of this classtag // find the % of this investment float fPercent = nClasstagValue / (float)nTotal; // adjust the draw rect by that % rectCurrent.Width = (int)(lbl.Width * fPercent); // draw it gfx.FillRectangle(brClasstagColor, rectCurrent); // now move over that much rectCurrent.X += rectCurrent.Width; // adjust tooltip based on this classtag's info // string.Format("{0,-8} {1,-20} {2}", stuff) //szFinalTag += UITools.FixClasstag(entry.Key) + ": \t" + ((int)(fPercent * 100)) + "%\n"; string szTabAmount = "\t"; if (entry.Key.Contains("General")) { szTabAmount += "\t"; } string szPercent = string.Format("{0:#.0}", fPercent * 100) + "%"; vFinalTag.Add(string.Format("{0,-25}{1}{2,-6}\n", UITools.FixClasstag(entry.Key), szTabAmount, szPercent)); } if (rectCurrent.X < lbl.Width) // if theres a gap left on the end, fill it { rectCurrent.Width = lbl.Width; gfx.FillRectangle(brClasstagColor, rectCurrent); // color will be the last successful classtag } } // render border gfx.DrawRectangle(Pens.Black, new Rectangle(0, 0, lbl.Width - 1, lbl.Height - 1)); // -1 cuz we wanna see it, not be ON the control border // gdi cleanup brClasstagColor.Dispose(); gfx.Dispose(); // set bg image lbl.BackgroundImage = bmpFinal; // get rid of old image if (imgOld != null) { imgOld.Dispose(); } // save the "tooltip" data // sort the text by % first (beginning of string X.X%) string szFinalTag = ""; //customerList = customerList.OrderBy(c => int.Parse(c.Code)).ToList(); vFinalTag.Sort(new InvestmentGraphSorter()); foreach (var szLine in vFinalTag) { szFinalTag += szLine; } lbl.Tag = szFinalTag; }