Skip to content

Commit

Permalink
Added the feature to add multiple people in the photo viewing window (f…
Browse files Browse the repository at this point in the history
…ix #517)
  • Loading branch information
Serg-Norseman committed Dec 14, 2023
1 parent e90b7ac commit 4c53d2f
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 30 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Added the feature to add multiple people in the photo viewing window.
<li>Restored the possibility of empty value of residence facts.
<li>Added localization to Japanese [Takashi Namba (難波鷹史)].
<li>Fixed encoding detection when reading CSV files [Alex Zaytsev].
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Добавлена возможность присоединять ряд персон в окне просмотра фотографий.
<li>Восстановлена возможность пустого значения фактов местожительства.
<li>Добавлена локализация на японский язык [Takashi Namba (難波鷹史)].
<li>Исправлено определение кодировки при чтении CSV-файлов [Alexander Zaytsev].
Expand Down
1 change: 1 addition & 0 deletions projects/GKCore/GKCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<EmbeddedResource Include="Resources\btn_info.gif" />
<EmbeddedResource Include="Resources\tg_bookmark.png" />
<EmbeddedResource Include="Resources\btn_circle.png" />
<EmbeddedResource Include="Resources\btn_portrait.png" />
</ItemGroup>


Expand Down
25 changes: 25 additions & 0 deletions projects/GKCore/GKCore/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

using System.Threading.Tasks;
using BSLib;
using GDModel;
using GDModel.Providers.GEDCOM;
using GKCore.Charts;
Expand Down Expand Up @@ -1044,6 +1045,30 @@ public static async Task<bool> DeleteFamilyWife(IBaseWindow baseWin, ChangeTrack
return result;
}

public static async Task<bool> SelectPhotoRegion(IView owner, IBaseWindow baseWin, GDMMultimediaRecord mediaRecord, ExtRect region)
{
var indiRec = await baseWin.Context.SelectPerson(owner, null, TargetMode.tmNone, GDMSex.svUnknown);
if (indiRec == null) return false;

GDMMultimediaLink mmLink = indiRec.GetPrimaryMultimediaLink();
if (mmLink == null) {
mmLink = indiRec.SetPrimaryMultimediaLink(mediaRecord);
} else {
mmLink = indiRec.AddMultimedia(mediaRecord);
}
SetMultimediaLinkRegion(mmLink, region, false);

return true;
}

public static void SetMultimediaLinkRegion(GDMMultimediaLink mmLink, ExtRect selectionRegion, bool isPrimary)
{
if (mmLink != null) {
mmLink.CutoutPosition.Value = selectionRegion;
mmLink.IsPrimaryCutout = isPrimary;
}
}

public static async Task<bool> SelectPortraitRegion(IView owner, IBaseWindow baseWin, GDMMultimediaLink mmLink)
{
bool result;
Expand Down
12 changes: 2 additions & 10 deletions projects/GKCore/GKCore/Controllers/PortraitSelectDlgController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ public PortraitSelectDlgController(IPortraitSelectDlg view) : base(view)
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();
}
BaseController.SetMultimediaLinkRegion(fMultimediaLink, fView.ImageCtl.SelectionRegion, true);

var uid = fMultimediaLink.GetUID(fBase.Context.Tree);
PortraitsCache.Instance.RemoveObsolete(uid);
Expand All @@ -82,7 +74,7 @@ public override void UpdateView()
IImage img = fBase.Context.LoadMediaImage(mmRec, -1, -1, ExtRect.Empty, false);
if (img == null) return;

fView.ImageCtl.OpenImage(img);
fView.ImageCtl.OpenImage(mmRec, img);

if (fMultimediaLink.IsPrimaryCutout) {
fView.ImageCtl.SelectionRegion = fMultimediaLink.CutoutPosition.Value;
Expand Down
6 changes: 3 additions & 3 deletions projects/GKCore/GKCore/Design/Controls/IImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
*/

using BSLib;
using GDModel;
using GKCore.Design.Graphics;
using GKCore.Design.Controls;

namespace GKCore.Design.Controls
{
/// <summary>
///
/// This control is used only in MediaViewerWin and PortraitSelectDlg.
/// </summary>
public interface IImageView : IBaseControl
{
ExtRect SelectionRegion { get; set; }
bool ShowNamedRegionTips { get; set; }

void AddNamedRegion(string name, ExtRect region);
void OpenImage(IImage image);
void OpenImage(GDMMultimediaRecord mediaRecord, IImage image);
}
}
Binary file added projects/GKCore/Resources/btn_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion projects/GKv2/GEDKeeper2/GKUI/Forms/MediaViewerWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void SetViewMedia(string mediaFile)
public void SetViewImage(IImage img)
{
var imageCtl = new GKUI.Components.ImageView();
imageCtl.OpenImage(img);
imageCtl.OpenImage(fController.MultimediaRecord, img);

fController.ProcessPortraits(imageCtl);

Expand Down
13 changes: 13 additions & 0 deletions projects/GKv2/GKComponents/GKUI/Components/ImageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public sealed class ImageBox : ScrollablePanel
/// </summary>
public event EventHandler ImageChanged;

/// <summary>
/// Occurs when the SelectionRegion property is changed.
/// </summary>
public event EventHandler SelectionRegionChanged;

/// <summary>
/// Occurs when the Zoom property is changed.
/// </summary>
Expand Down Expand Up @@ -139,6 +144,7 @@ public RectangleF SelectionRegion
if (fSelectionRegion != value) {
fSelectionRegion = value;
Invalidate();
OnSelectionRegionChanged(EventArgs.Empty);
}
}
}
Expand Down Expand Up @@ -681,6 +687,13 @@ private void OnImageChanged(EventArgs e)
handler(this, e);
}

private void OnSelectionRegionChanged(EventArgs e)
{
EventHandler handler = SelectionRegionChanged;
if (handler != null)
handler(this, e);
}

private void OnZoomChanged(EventArgs e)
{
EventHandler handler = ZoomChanged;
Expand Down
42 changes: 39 additions & 3 deletions projects/GKv2/GKComponents/GKUI/Components/ImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
using System.Drawing;
using System.Windows.Forms;
using BSLib;
using GDModel;
using GKCore;
using GKCore.Controllers;
using GKCore.Design.Controls;
using GKCore.Design.Graphics;
using GKCore.Design.Views;
using GKCore.Interfaces;
using GKCore.Types;
using GKUI.Platform.Handlers;
Expand All @@ -34,12 +37,15 @@ namespace GKUI.Components
{
public class ImageView : UserControl, ILocalizable, IImageView
{
private GDMMultimediaRecord fMediaRecord;

private ImageBox imageBox;
private ToolStrip toolStrip;
private ToolStripComboBox cbZoomLevels;
private ToolStripButton btnSizeToFit;
private ToolStripButton btnZoomIn;
private ToolStripButton btnZoomOut;
private ToolStripButton btnPortrait;


public List<NamedRegion> NamedRegions
Expand Down Expand Up @@ -123,6 +129,14 @@ private void InitializeComponent()
btnZoomOut.Name = "btnZoomOut";
btnZoomOut.Click += btnZoomOut_Click;

btnPortrait = new ToolStripButton();
btnPortrait.DisplayStyle = ToolStripItemDisplayStyle.Image;
btnPortrait.Image = UIHelper.LoadResourceImage("Resources.btn_portrait.png");
btnPortrait.ImageTransparentColor = Color.Magenta;
btnPortrait.Name = "btnPortrait";
btnPortrait.Click += btnPortrait_Click;
btnPortrait.Visible = false;

cbZoomLevels = new ToolStripComboBox();
cbZoomLevels.DropDownStyle = ComboBoxStyle.DropDownList;
cbZoomLevels.Name = "zoomLevelsToolStripComboBox";
Expand All @@ -136,11 +150,14 @@ private void InitializeComponent()
btnZoomOut,
new ToolStripSeparator(),
cbZoomLevels,
new ToolStripSeparator(),
btnPortrait,
new ToolStripSeparator()});

imageBox = new ImageBox();
imageBox.SelectionMode = ImageBoxSelectionMode.Zoom;
imageBox.SelectionMode = ImageBoxSelectionMode.Rectangle;
imageBox.ZoomChanged += imageBox_ZoomChanged;
imageBox.SelectionRegionChanged += imageBox_SelectionRegionChanged;
imageBox.Dock = DockStyle.Fill;

Controls.Add(imageBox);
Expand All @@ -156,14 +173,15 @@ public void AddNamedRegion(string name, ExtRect region)
imageBox.NamedRegions.Add(new NamedRegion(name, region));
}

public void OpenImage(IImage image)
public void OpenImage(GDMMultimediaRecord mediaRecord, IImage image)
{
if (image != null) {
fMediaRecord = mediaRecord;
OpenImage(((ImageHandler)image).Handle);
}
}

public void OpenImage(Image image)
private void OpenImage(Image image)
{
if (image != null) {
imageBox.BeginUpdate();
Expand Down Expand Up @@ -209,6 +227,24 @@ private void btnZoomOut_Click(object sender, EventArgs e)
imageBox.ZoomOut();
}

private async void btnPortrait_Click(object sender, EventArgs e)
{
var mediaWin = ParentForm as IMediaViewerWin;
if (mediaWin == null) return;

var baseWin = mediaWin.OwnerWindow as IBaseWindow;
if (baseWin == null) return;

if (await BaseController.SelectPhotoRegion(mediaWin, baseWin, fMediaRecord, UIHelper.Rt2Rt(imageBox.SelectionRegion))) {
imageBox.SelectionRegion = RectangleF.Empty;
}
}

private void imageBox_SelectionRegionChanged(object sender, EventArgs e)
{
btnPortrait.Visible = (ParentForm is IMediaViewerWin && !imageBox.SelectionRegion.IsEmpty);
}

private void imageBox_ZoomChanged(object sender, EventArgs e)
{
UpdateZoomLevels();
Expand Down
11 changes: 4 additions & 7 deletions projects/GKv2/GKTestsUI2/GKComponents/ImageViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using BSLib;
using GKCore.Design.Graphics;
using GKTests;
using GKUI.Platform.Handlers;
using NUnit.Extensions.Forms;
using NUnit.Framework;

Expand Down Expand Up @@ -61,14 +62,10 @@ public void Dispose()
public void TestMethod()
{
IImage image1 = null;
fImageView.OpenImage(image1); // return without exceptions
fImageView.OpenImage(null, image1); // return without exceptions

Image image2 = null;
fImageView.OpenImage(image2); // return without exceptions

Bitmap img = new Bitmap(TestUtils.LoadResourceStream("shaytan_plant.jpg"));

fImageView.OpenImage(img);
image1 = new ImageHandler(new Bitmap(TestUtils.LoadResourceStream("shaytan_plant.jpg")));
fImageView.OpenImage(null, image1);

fForm.Show();

Expand Down
2 changes: 1 addition & 1 deletion projects/GKv3/GEDKeeper3/GKUI/Forms/MediaViewerWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void SetViewMedia(string mediaFile)
public void SetViewImage(IImage img)
{
var imageCtl = new GKUI.Components.ImageView();
imageCtl.OpenImage(img);
imageCtl.OpenImage(fController.MultimediaRecord, img);

fController.ProcessPortraits(imageCtl);

Expand Down
2 changes: 2 additions & 0 deletions projects/GKv3/GEDKeeper3/GKUI/Forms/SlideshowWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public SlideshowWin(IBaseWindow baseWin)
// while using GKButtonToolItem
tbStart.Image = UIHelper.LoadResourceImage("Resources.btn_start.gif");

fImageCtl.SelectionMode = ImageBoxSelectionMode.Zoom;

fController = new SlideshowController(this);
fController.Init(baseWin);
fController.LoadList();
Expand Down
2 changes: 1 addition & 1 deletion projects/GKv3/GEDKeeper3/GKUI/Forms/SlideshowWin.xeto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</ToolBar>
</Form.ToolBar>

<components:ImageBox x:Name="fImageCtl" SelectionMode="Zoom" Size="780, 560" />
<components:ImageBox x:Name="fImageCtl" Size="780, 560" />

</Form>
13 changes: 13 additions & 0 deletions projects/GKv3/GKComponents/GKUI/Components/ImageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public sealed class ImageBox : ScrollablePanel
/// </summary>
public event EventHandler ImageChanged;

/// <summary>
/// Occurs when the SelectionRegion property is changed.
/// </summary>
public event EventHandler SelectionRegionChanged;

/// <summary>
/// Occurs when the Zoom property is changed.
/// </summary>
Expand Down Expand Up @@ -136,6 +141,7 @@ public RectangleF SelectionRegion
if (fSelectionRegion != value) {
fSelectionRegion = value;
InvalidateContent();
OnSelectionRegionChanged(EventArgs.Empty);
}
}
}
Expand Down Expand Up @@ -656,6 +662,13 @@ private void OnImageChanged(EventArgs e)
handler(this, e);
}

private void OnSelectionRegionChanged(EventArgs e)
{
EventHandler handler = SelectionRegionChanged;
if (handler != null)
handler(this, e);
}

private void OnZoomChanged(EventArgs e)
{
EventHandler handler = ZoomChanged;
Expand Down
Loading

0 comments on commit 4c53d2f

Please sign in to comment.