Пример #1
0
        public override bool Accept()
        {
            try {
                ExtRect selectRegion = fView.ImageCtl.SelectionRegion;

                if (!selectRegion.IsEmpty())
                {
                    fMultimediaLink.IsPrimaryCutout      = true;
                    fMultimediaLink.CutoutPosition.Value = selectRegion;
                }
                else
                {
                    fMultimediaLink.IsPrimaryCutout      = false;
                    fMultimediaLink.CutoutPosition.Value = ExtRect.CreateEmpty();
                }

                var uid = fMultimediaLink.GetUID(fBase.Context.Tree);
                PortraitsCache.Instance.RemoveObsolete(uid);

                return(true);
            } catch (Exception ex) {
                Logger.WriteError("PortraitSelectDlgController.Accept()", ex);
                return(false);
            }
        }
Пример #2
0
        public IImage CreateImage(Stream stream, int thumbWidth, int thumbHeight, ExtRect cutoutArea)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (Bitmap bmp = new Bitmap(stream))
            {
                bool cutoutIsEmpty = cutoutArea.IsEmpty();
                int  imgWidth      = (cutoutIsEmpty) ? bmp.Width : cutoutArea.GetWidth();
                int  imgHeight     = (cutoutIsEmpty) ? bmp.Height : cutoutArea.GetHeight();

                if (thumbWidth > 0 && thumbHeight > 0)
                {
                    float ratio = SysUtils.ZoomToFit(imgWidth, imgHeight, thumbWidth, thumbHeight);
                    imgWidth  = (int)(imgWidth * ratio);
                    imgHeight = (int)(imgHeight * ratio);
                }

                Bitmap newImage = new Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb);
                using (Graphics graphic = Graphics.FromImage(newImage)) {
                    graphic.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    graphic.SmoothingMode      = SmoothingMode.HighQuality;
                    graphic.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    graphic.CompositingQuality = CompositingQuality.HighQuality;

                    if (cutoutIsEmpty)
                    {
                        graphic.DrawImage(bmp, 0, 0, imgWidth, imgHeight);
                    }
                    else
                    {
                        Rectangle destRect = new Rectangle(0, 0, imgWidth, imgHeight);
                        //Rectangle srcRect = cutoutArea.ToRectangle();
                        graphic.DrawImage(bmp, destRect,
                                          cutoutArea.Left, cutoutArea.Top,
                                          cutoutArea.GetWidth(), cutoutArea.GetHeight(),
                                          GraphicsUnit.Pixel);
                    }
                }

                return(new ImageHandler(newImage));
            }
        }
Пример #3
0
        public IImage CreateImage(Stream stream, int thumbWidth, int thumbHeight, ExtRect cutoutArea)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (Bitmap bmp = new Bitmap(stream))
            {
                bool cutoutIsEmpty = cutoutArea.IsEmpty();
                int  imgWidth      = (cutoutIsEmpty) ? bmp.Width : cutoutArea.GetWidth();
                int  imgHeight     = (cutoutIsEmpty) ? bmp.Height : cutoutArea.GetHeight();

                if (thumbWidth > 0 && thumbHeight > 0)
                {
                    float ratio = GfxHelper.ZoomToFit(imgWidth, imgHeight, thumbWidth, thumbHeight);
                    imgWidth  = (int)(imgWidth * ratio);
                    imgHeight = (int)(imgHeight * ratio);
                }

                Bitmap newImage = new Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb);
                using (Graphics graphic = new Graphics(newImage)) {
                    graphic.AntiAlias          = true;
                    graphic.ImageInterpolation = ImageInterpolation.High;
                    graphic.PixelOffsetMode    = PixelOffsetMode.Half;

                    if (cutoutIsEmpty)
                    {
                        graphic.DrawImage(bmp, 0, 0, imgWidth, imgHeight);
                    }
                    else
                    {
                        RectangleF sourRect = new RectangleF(cutoutArea.Left, cutoutArea.Top,
                                                             cutoutArea.GetWidth(), cutoutArea.GetHeight());
                        RectangleF destRect = new RectangleF(0, 0, imgWidth, imgHeight);

                        graphic.DrawImage(bmp, sourRect, destRect);
                    }
                }

                return(new ImageHandler(newImage));
            }
        }
Пример #4
0
        public static void RestoreFormRect(Form form, ExtRect rt, Eto.Forms.WindowState winState)
        {
            // check for new and empty struct
            if (form == null || rt.IsEmpty())
            {
                return;
            }

            if (winState != Eto.Forms.WindowState.Minimized)
            {
                form.Location = new Point(rt.Left, rt.Top);
                form.Width    = rt.GetWidth();
                form.Height   = rt.GetHeight();

                form.WindowState = winState;
            }
            else
            {
                form.WindowState = Eto.Forms.WindowState.Maximized;
            }
        }
Пример #5
0
        public void Test_ExtRect()
        {
            ExtRect rt = ExtRect.Create(0, 0, 9, 9);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            rt = ExtRect.CreateBounds(0, 0, 10, 10);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            Assert.AreEqual("{X=0,Y=0,Width=10,Height=10}", rt.ToString());

            Assert.IsTrue(rt.Contains(5, 5));

            rt.Inflate(3, -2);
            Assert.AreEqual("{X=3,Y=-2,Width=4,Height=14}", rt.ToString());

            rt.Offset(2, 5);
            Assert.AreEqual("{X=5,Y=3,Width=4,Height=14}", rt.ToString());

            rt = rt.GetOffset(10, 10);
            Assert.AreEqual("{X=15,Y=13,Width=4,Height=14}", rt.ToString());

            Assert.IsTrue(rt.IntersectsWith(ExtRect.Create(16, 14, 20, 20)));

            rt = ExtRect.CreateEmpty();
            Assert.IsTrue(rt.IsEmpty());

            Assert.IsFalse(rt.Contains(5, 5));
        }
Пример #6
0
        public static void RestoreFormRect(Form form, ExtRect rt, FormWindowState winState)
        {
            // check for new and empty struct
            if (form == null || rt.IsEmpty())
            {
                return;
            }

            if (winState != FormWindowState.Minimized)
            {
                form.Left   = rt.Left;
                form.Top    = rt.Top;
                form.Width  = rt.GetWidth();
                form.Height = rt.GetHeight();

                form.WindowState = winState;
            }
            else
            {
                form.WindowState = FormWindowState.Maximized;
            }
        }
        public override bool Accept()
        {
            try {
                ExtRect selectRegion = fView.ImageCtl.SelectionRegion;

                if (!selectRegion.IsEmpty())
                {
                    fMultimediaLink.IsPrimaryCutout      = true;
                    fMultimediaLink.CutoutPosition.Value = selectRegion;
                }
                else
                {
                    fMultimediaLink.IsPrimaryCutout      = false;
                    fMultimediaLink.CutoutPosition.Value = ExtRect.CreateEmpty();
                }

                PortraitsCache.Instance.RemoveObsolete(fMultimediaLink);

                return(true);
            } catch (Exception ex) {
                Logger.LogWrite("PortraitSelectDlgController.Accept(): " + ex.Message);
                return(false);
            }
        }
Пример #8
0
        public void Test_TreeChartPerson()
        {
            using (TreeChartPerson tcPerson = new TreeChartPerson(null)) {
                Assert.IsNotNull(tcPerson);

                tcPerson.BuildBy(null);

                Assert.AreEqual(null, tcPerson.Rec);

                Assert.AreEqual(null, tcPerson.Portrait);
                Assert.AreEqual(0, tcPerson.PortraitWidth);

                tcPerson.Divorced = false;
                Assert.AreEqual(false, tcPerson.Divorced);
                tcPerson.Divorced = true;
                Assert.AreEqual(true, tcPerson.Divorced);

                tcPerson.IsDup = false;
                Assert.AreEqual(false, tcPerson.IsDup);
                tcPerson.IsDup = true;
                Assert.AreEqual(true, tcPerson.IsDup);

                Assert.AreEqual(0, tcPerson.Height);
                Assert.AreEqual(0, tcPerson.Width);

                tcPerson.IsDead = false;
                Assert.AreEqual(false, tcPerson.IsDead);
                tcPerson.IsDead = true;
                Assert.AreEqual(true, tcPerson.IsDead);

                Assert.AreEqual(0, tcPerson.PtX);
                tcPerson.PtX = 11;
                Assert.AreEqual(11, tcPerson.PtX);

                Assert.AreEqual(0, tcPerson.PtY);
                tcPerson.PtY = 22;
                Assert.AreEqual(22, tcPerson.PtY);

                tcPerson.Selected = false;
                Assert.AreEqual(false, tcPerson.Selected);
                tcPerson.Selected = true;
                Assert.AreEqual(true, tcPerson.Selected);

                Assert.AreEqual(GDMSex.svUnknown, tcPerson.Sex);
                tcPerson.Sex = GDMSex.svMale;
                Assert.AreEqual(GDMSex.svMale, tcPerson.Sex);

                EnumSet <SpecialUserRef> enums = tcPerson.Signs;
                Assert.IsTrue(enums.IsEmpty());

                Assert.AreEqual(0, tcPerson.GetChildsCount());
                Assert.AreEqual(0, tcPerson.GetSpousesCount());

                TreeChartPerson child = new TreeChartPerson(null);
                tcPerson.AddChild(null);
                tcPerson.AddChild(child);
                Assert.AreEqual(1, tcPerson.GetChildsCount());
                Assert.AreEqual(child, tcPerson.GetChild(0));

                TreeChartPerson spouse = new TreeChartPerson(null);
                tcPerson.AddSpouse(null);
                tcPerson.AddSpouse(spouse);
                Assert.AreEqual(1, tcPerson.GetSpousesCount());
                Assert.AreEqual(spouse, tcPerson.GetSpouse(0));

                Assert.IsFalse(tcPerson.HasFlag(PersonFlag.pfDescWalk));
                tcPerson.SetFlag(PersonFlag.pfDescWalk);
                Assert.IsTrue(tcPerson.HasFlag(PersonFlag.pfDescWalk));

                tcPerson.BuildBy(null);

                ExtRect psnRt = tcPerson.Rect;
                Assert.IsTrue(psnRt.IsEmpty());

                tcPerson.Sex = GDMSex.svMale;
                var color = ((ColorHandler)tcPerson.GetSelectedColor()).Handle;
                Assert.AreEqual(Color.FromArgb(255, Color.Blue), color);

                tcPerson.Sex = GDMSex.svFemale;
                color        = ((ColorHandler)tcPerson.GetSelectedColor()).Handle;
                Assert.AreEqual(Color.FromArgb(255, Color.Red), color);

                tcPerson.Sex = GDMSex.svUnknown;
                color        = ((ColorHandler)tcPerson.GetSelectedColor()).Handle;
                Assert.AreEqual(Color.FromArgb(255, Color.Black), color);
            }
        }
Пример #9
0
        public void Test_TreeChartModel()
        {
            using (var model = new TreeChartModel())
            {
                Assert.IsNotNull(model);

                model.Base = fBase;
                Assert.AreEqual(fBase, model.Base);

                model.BranchDistance = TreeChartModel.DEF_BRANCH_DISTANCE;
                Assert.AreEqual(TreeChartModel.DEF_BRANCH_DISTANCE, model.BranchDistance);

                model.CertaintyIndex = true;
                Assert.AreEqual(true, model.CertaintyIndex);

                model.DepthLimit = 8;
                Assert.AreEqual(8, model.DepthLimit);

                model.DepthLimit = 8;
                Assert.AreEqual(8, model.DepthLimit);

                Assert.IsNotNull(model.Filter);

                model.HighlightedPerson = null;
                Assert.AreEqual(null, model.HighlightedPerson);

                Assert.AreEqual(0, model.ImageHeight);
                Assert.AreEqual(0, model.ImageWidth);

                model.KinRoot = null;
                Assert.AreEqual(null, model.KinRoot);

                model.Kind = TreeChartKind.ckAncestors;
                Assert.AreEqual(TreeChartKind.ckAncestors, model.Kind);

                model.Margins = 15;
                Assert.AreEqual(15, model.Margins);

                Assert.IsNull(model.Options);

                model.PathDebug = true;
                Assert.AreEqual(true, model.PathDebug);

                Assert.IsNotNull(model.Persons);

                Assert.IsNotNull(model.PreparedIndividuals);

                Assert.IsNull(model.Root);

                model.Scale = 1.3f;
                Assert.AreEqual(1.3f, model.Scale);

                model.Scale = 0.1f;
                Assert.AreEqual(0.5f, model.Scale);

                model.Scale = 1.7f;
                Assert.AreEqual(1.5f, model.Scale);

                Assert.Throws(typeof(ArgumentNullException), () => { model.DoFilter(null); });

                Assert.IsNull(model.FindPersonByCoords(0, 0));

                Assert.AreEqual(ExtRect.Create(0, -18, 15, -2), TreeChartModel.GetExpanderRect(ExtRect.Create(0, 0, 0, 0)));
                Assert.AreEqual(ExtRect.Create(-8, -18, 7, -2), TreeChartModel.GetPersonExpandRect(ExtRect.Create(0, 0, 0, 0)));

                ExtRect rt = model.VisibleArea;
                Assert.IsTrue(rt.IsEmpty());
            }
        }