Exemple #1
0
        private void DrawIndex(Graphics g, FaceBase face, Size size)
        {
            GraphicsState gstate = g.Save();

            SizeF tSize        = new SizeF(size.Width, size.Height / 3f);
            Color emotionColor = Describer.EmotionColor(face);

            Font  font;
            SizeF fsize;
            // header
            string header = $"{DateTime.Now.ToString("MM月dd日")}心情指数:";

            MatchFontSize(g, tSize.Width, tSize.Height, header, out font, out fsize);
            g.DrawOutlineString(header, font, emotionColor, Color.Black, PointF.Empty);
#if DEBUG
            g.DrawRectangles(Pens.Red, new RectangleF[] { new RectangleF(PointF.Empty, fsize) });
#endif
            // detail
            string etext = Describer.DescribeIndexDetail(face);
            MatchFontSize(g, tSize.Width, tSize.Height, etext, out font, out fsize);
            PointF loc = new PointF(size.Width - fsize.Width, tSize.Height * 2);
            g.DrawOutlineString(etext, font, emotionColor, Color.Black, loc, 0.125f, true);
#if DEBUG
            g.DrawRectangles(Pens.Red, new RectangleF[] { new RectangleF(loc, fsize) });
#endif
            // emoji
            float left = (size.Width - fsize.Width) / 2;
            using (Image emoji = Image.FromFile(Describer.DescribEmoji(face)))
            {
                g.DrawImage(emoji,
                            new RectangleF(left, tSize.Height, tSize.Height, tSize.Height),
                            new RectangleF(0, 0, emoji.Width, emoji.Height),
                            GraphicsUnit.Pixel);
            }

            int pid = DirectoryHelper.RandomFile(Path.Combine(Global.PluginRoot, @"Content\progress"));
            using (Image progess = Image.FromFile(Path.Combine(Global.PluginRoot, $@"Content\progress\{pid}.png")))
                using (Image progessx = Image.FromFile(Path.Combine(Global.PluginRoot, $@"Content\progressx\{pid}.png")))
                {
                    float ratio = tSize.Height / progess.Height;
                    DrawImageMappingColor(g, progess, Color.FromArgb(192, 192, 192),
                                          new RectangleF(left + tSize.Height, tSize.Height, progess.Width * ratio, tSize.Height),
                                          new RectangleF(0, 0, progess.Width, progess.Height));

                    float cw = progess.Width * (float)Math.Pow(face.DominantEmotion / 100, 1 / 3.0);
                    if (face.DominantEmotionIndex < 0)
                    {
                        cw = progess.Width;
                    }
                    DrawImageMappingColor(g, progess, emotionColor,
                                          new RectangleF(left + tSize.Height, tSize.Height, cw * ratio, tSize.Height),
                                          new RectangleF(0, 0, cw, progess.Height));

                    DrawImageMappingColor(g, progessx, Color.Black,
                                          new RectangleF(left + tSize.Height, tSize.Height, progessx.Width * ratio, tSize.Height),
                                          new RectangleF(0, 0, progessx.Width, progessx.Height));
                }

            g.Restore(gstate);
        }