Permalink
Browse files

Add retina display support.

  • Loading branch information...
1 parent 6a728c7 commit de24bb40507e3993b874167f5b0c1ac4a09f66cc @a-fung committed Oct 12, 2012
@@ -1,4 +1,5 @@
using System;
+using System.Html;
namespace afung.MangaWeb3.Client
{
@@ -22,6 +23,19 @@ public class Environment
public static int MangaPagesToPreload = 1;
public static int MangaPagesUnloadDistance = 3;
+
+ public static double PixelRatio
+ {
+ get
+ {
+ if (Number.IsFinite(ExtendedWindow.DevicePixelRatio))
+ {
+ return ExtendedWindow.DevicePixelRatio;
+ }
+
+ return 1.0;
+ }
+ }
}
/// <summary>
@@ -0,0 +1,18 @@
+// ExtendedWindow.cs
+//
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.CompilerServices;
+
+namespace System.Html
+{
+ [Imported]
+ [IgnoreNamespace]
+ [ScriptName("window")]
+ public class ExtendedWindow
+ {
+ [ScriptName("devicePixelRatio")]
+ public static readonly double DevicePixelRatio;
+ }
+}
@@ -64,12 +64,20 @@ public int Page
}
}
+ private ImageElement imageElement
+ {
+ get
+ {
+ return imageObject == null || !imageObject.Is("img") ? null : (ImageElement)imageObject.GetElement(0);
+ }
+ }
+
public MangaPage(int mangaId, int page, int width, int height)
{
this.mangaId = mangaId;
this.page = page;
- this.width = Settings.DisplayType == 0 ? 0 : width; // Fit Height?
- this.height = Settings.DisplayType == 2 ? 0 : height; // Fit Width?
+ this.width = width - 2;
+ this.height = height;
unloaded = loading = loaded = false;
}
@@ -88,8 +96,8 @@ public void Load(Action onload)
pageRequest = new MangaPageRequest();
pageRequest.id = mangaId;
pageRequest.page = page;
- pageRequest.width = width;
- pageRequest.height = height;
+ pageRequest.width = Settings.DisplayType == 0 ? 0 : (int)Math.Round(width * Environment.PixelRatio); // Fit Height?
+ pageRequest.height = Settings.DisplayType == 2 ? 0 : (int)Math.Round(height * Environment.PixelRatio); // Fit Width?
Request.Send(pageRequest, MangaPageRequestSucess);
}
@@ -109,6 +117,24 @@ private void MangaPageRequestSucess(MangaImageResponse response)
"load",
delegate(jQueryEvent e)
{
+ if (Settings.DisplayType == 0)
+ {
+ imageObject.Height(height);
+ }
+ else if (Settings.DisplayType == 2)
+ {
+ imageObject.Width(width);
+ }
+ else
+ {
+ double widthFactor = width / imageElement.Width;
+ double heightFactor = height / imageElement.Height;
+ double factor = widthFactor < heightFactor ? widthFactor : heightFactor;
+ imageObject
+ .Width(Math.Round(imageElement.Width * factor))
+ .Height(Math.Round(imageElement.Height * factor));
+ }
+
loading = false;
loaded = true;
onload();
@@ -50,6 +50,7 @@
<ItemGroup>
<Compile Include="Import\Bootstrap.cs" />
<Compile Include="Import\CKFinder.cs" />
+ <Compile Include="Import\ExtendedWindow.cs" />
<Compile Include="Import\jQueryTouch.cs" />
<Compile Include="Import\MouseWheelEvent.cs" />
<Compile Include="Modal\ChangePasswordModal.cs" />

0 comments on commit de24bb4

Please sign in to comment.