(GUI): added scale large image option.

This commit is contained in:
morkt 2018-03-11 20:50:33 +04:00
parent c5113b08ba
commit ce2e256dc2
13 changed files with 175 additions and 13 deletions

View File

@ -91,6 +91,9 @@
<setting name="appLastDestination" serializeAs="String">
<value />
</setting>
<setting name="winDownScaleImage" serializeAs="String">
<value>False</value>
</setting>
</GARbro.GUI.Properties.Settings>
</userSettings>
</configuration>

View File

@ -2,7 +2,7 @@
//! \date Sun Jul 06 06:34:56 2014
//! \brief preview images.
//
// Copyright (C) 2014-2015 by morkt
// Copyright (C) 2014-2018 by morkt
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
@ -259,6 +259,7 @@ namespace GARbro.GUI
{
ActiveViewer = ImageView;
ImageCanvas.Source = bitmap;
ApplyDownScaleSetting();
SetStatusText (string.Format (guiStrings.MsgImageSize, bitmap.PixelWidth,
bitmap.PixelHeight, bitmap.Format.BitsPerPixel));
}
@ -289,5 +290,42 @@ namespace GARbro.GUI
}, DispatcherPriority.ContextIdle);
}
}
private void SetImageScaleMode (bool scale)
{
if (scale)
{
ImageCanvas.Stretch = Stretch.Uniform;
RenderOptions.SetBitmapScalingMode (ImageCanvas, BitmapScalingMode.HighQuality);
ImageView.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
ImageView.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
}
else
{
ImageCanvas.Stretch = Stretch.None;
RenderOptions.SetBitmapScalingMode (ImageCanvas, BitmapScalingMode.NearestNeighbor);
ImageView.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
ImageView.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
}
}
private void ApplyDownScaleSetting ()
{
bool image_need_scale = DownScaleImage.Get<bool>();
if (image_need_scale && ImageCanvas.Source != null)
{
var image = ImageCanvas.Source;
image_need_scale = image.Width > ImageView.ActualWidth || image.Height > ImageView.ActualHeight;
}
SetImageScaleMode (image_need_scale);
}
private void PreviewSizeChanged (object sender, SizeChangedEventArgs e)
{
var image = ImageCanvas.Source;
if (null == image || !DownScaleImage.Get<bool>())
return;
SetImageScaleMode (image.Width > e.NewSize.Width || image.Height > e.NewSize.Height);
}
}
}

View File

@ -360,7 +360,8 @@
</ListView.View>
</local:ListViewEx>
<Grid Grid.Column="2" Name="PreviewPane" SnapsToDevicePixels="True">
<ScrollViewer Name="ImageView" Background="LightGray" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ScrollViewer Name="ImageView" Background="LightGray" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
SizeChanged="PreviewSizeChanged">
<Image Name="ImageCanvas" Stretch="None" UseLayoutRounding="True" SnapsToDevicePixels="True"
local:TouchScrolling.IsEnabled="True" RenderOptions.BitmapScalingMode="NearestNeighbor"
Cursor="Images/Cursors/grab.cur" local:TouchScrolling.DraggingCursor="Images/Cursors/grabbing.cur" />

View File

@ -56,6 +56,8 @@ namespace GARbro.GUI
public App App { get { return m_app; } }
internal static readonly GuiResourceSetting DownScaleImage = new GuiResourceSetting ("winDownScaleImage");
const StringComparison StringIgnoreCase = StringComparison.CurrentCultureIgnoreCase;
public MainWindow()
@ -82,6 +84,7 @@ namespace GARbro.GUI
this.MinWidth = e.NewSize.Width+79;
}
};
DownScaleImage.PropertyChanged += (s, e) => ApplyDownScaleSetting();
pathLine.EnterKeyDown += acb_OnKeyDown;
}

View File

@ -357,5 +357,17 @@ namespace GARbro.GUI.Properties {
this["appLastDestination"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool winDownScaleImage {
get {
return ((bool)(this["winDownScaleImage"]));
}
set {
this["winDownScaleImage"] = value;
}
}
}
}

View File

@ -86,5 +86,8 @@
<Setting Name="appLastDestination" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="winDownScaleImage" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -33,6 +33,7 @@ using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using GameRes;
using GARbro.GUI.Properties;
using GARbro.GUI.Strings;
namespace GARbro.GUI
@ -54,6 +55,10 @@ namespace GARbro.GUI
};
}
static readonly IEnumerable<IResourceSetting> ViewerSettings = new [] {
MainWindow.DownScaleImage,
};
SettingsViewModel ViewModel;
static string LastSelectedSection = null;
@ -82,17 +87,20 @@ namespace GARbro.GUI
if (!ViewModel.HasChanges)
return;
if (OnApplyChanges != null)
OnApplyChanges (this, new EventArgs());
OnApplyChanges (this, EventArgs.Empty);
ViewModel.HasChanges = false;
}
private SettingsViewModel CreateSettingsTree ()
{
SettingsSectionView[] list = {
new SettingsSectionView {
Label = guiStrings.TextViewer,
Panel = CreateSectionPanel (ViewerSettings)
},
new SettingsSectionView {
Label = guiStrings.TextFormats,
Children = EnumerateFormatsSettings(),
Panel = (UIElement)this.Resources["FormatsPanel"]
},
};
SettingsSectionView selected_section = null;
@ -110,13 +118,7 @@ namespace GARbro.GUI
var formats = FormatCatalog.Instance.Formats.Where (f => f.Settings != null && f.Settings.Any());
foreach (var format in formats.OrderBy (f => f.Tag))
{
var pane = new WrapPanel();
foreach (var setting in format.Settings)
{
var widget = CreateSettingWidget (setting, setting.Value as dynamic);
if (widget != null)
pane.Children.Add (widget);
}
var pane = CreateSectionPanel (format.Settings);
if (pane.Children.Count > 0)
{
var section = new SettingsSectionView {
@ -130,7 +132,19 @@ namespace GARbro.GUI
return list;
}
UIElement CreateSettingWidget (IResourceSetting setting, bool value)
Panel CreateSectionPanel (IEnumerable<IResourceSetting> settings)
{
var pane = new WrapPanel();
foreach (var setting in settings)
{
var widget = CreateSettingWidget (setting, setting.Value);
if (widget != null)
pane.Children.Add (widget);
}
return pane;
}
UIElement CreateCheckBoxWidget (IResourceSetting setting)
{
return new CheckBox {
Template = (ControlTemplate)this.Resources["BoundCheckBox"],
@ -138,7 +152,7 @@ namespace GARbro.GUI
};
}
UIElement CreateSettingWidget (IResourceSetting setting, Encoding value)
UIElement CreateEncodingWidget (IResourceSetting setting)
{
var view = CreateSettingView<Encoding> (setting);
// XXX make a control template in XAML instead
@ -169,6 +183,10 @@ namespace GARbro.GUI
UIElement CreateSettingWidget<TUnknown> (IResourceSetting setting, TUnknown value)
{
if (value is bool)
return CreateCheckBoxWidget (setting);
if (value is Encoding)
return CreateEncodingWidget (setting);
Trace.WriteLine (string.Format ("Unknown setting type {0}", value.GetType()), "[GUI]");
return null;
}
@ -348,4 +366,36 @@ namespace GARbro.GUI
throw new System.NotImplementedException();
}
}
internal class GuiResourceSetting : ResourceSettingBase, INotifyPropertyChanged
{
public override object Value {
get { return Settings.Default[Name]; }
set {
if (!Settings.Default[Name].Equals (value))
{
Settings.Default[Name] = value;
OnPropertyChanged();
}
}
}
public GuiResourceSetting () { }
public GuiResourceSetting (string name)
{
Name = name;
Text = guiStrings.ResourceManager.GetString (name, guiStrings.Culture) ?? name;
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged ([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
}
}
}
}

View File

@ -1273,6 +1273,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Image viewer.
/// </summary>
public static string TextViewer {
get {
return ResourceManager.GetString("TextViewer", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Visit download page.
/// </summary>
@ -1326,5 +1335,14 @@ namespace GARbro.GUI.Strings {
return ResourceManager.GetString("Type_NONE", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Scale large images to fit window.
/// </summary>
public static string winDownScaleImage {
get {
return ResourceManager.GetString("winDownScaleImage", resourceCulture);
}
}
}
}

View File

@ -691,4 +691,10 @@ Overwrite?</comment>
<value>環境設定</value>
<comment>Preferences</comment>
</data>
<data name="TextViewer" xml:space="preserve">
<value>Image viewer</value>
</data>
<data name="winDownScaleImage" xml:space="preserve">
<value>Scale large images to fit window</value>
</data>
</root>

View File

@ -561,4 +561,12 @@
<value>script</value>
<comment>translation pending</comment>
</data>
<data name="TextViewer" xml:space="preserve">
<value>Image viewer</value>
<comment>translation pending</comment>
</data>
<data name="winDownScaleImage" xml:space="preserve">
<value>Scale large images to fit window</value>
<comment>translation pending</comment>
</data>
</root>

View File

@ -545,4 +545,10 @@ Overwrite?</value>
<data name="TextPreferences" xml:space="preserve">
<value>Preferences</value>
</data>
<data name="TextViewer" xml:space="preserve">
<value>Image viewer</value>
</data>
<data name="winDownScaleImage" xml:space="preserve">
<value>Scale large images to fit window</value>
</data>
</root>

View File

@ -566,4 +566,10 @@
<data name="TextPreferences" xml:space="preserve">
<value>Настройки</value>
</data>
<data name="TextViewer" xml:space="preserve">
<value>Просмотр</value>
</data>
<data name="winDownScaleImage" xml:space="preserve">
<value>Масштабировать большие изображения</value>
</data>
</root>

View File

@ -562,4 +562,12 @@
<value>script</value>
<comment>translation pending</comment>
</data>
<data name="TextViewer" xml:space="preserve">
<value>Image viewer</value>
<comment>translation pending</comment>
</data>
<data name="winDownScaleImage" xml:space="preserve">
<value>Scale large images to fit window</value>
<comment>translation pending</comment>
</data>
</root>