-
Notifications
You must be signed in to change notification settings - Fork 2
/
TileView.cs
63 lines (54 loc) · 2.19 KB
/
TileView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using FFImageLoading.Forms;
using FFImageLoading.Transformations;
using FFImageLoading.Work;
namespace Tiled.Views
{
public class TileView : CachedImage
{
private int _maxPos;
public TileView(int xPos, int yPos, int maxPos, int tileSize)
{
_maxPos = maxPos;
this.DownsampleToViewSize = true;
this.Transformations = new List<ITransformation>();
this.WidthRequest = tileSize;
this.HeightRequest = tileSize;
if (xPos == 0 && yPos == 0)
{
this.Transformations.Add(new CornersTransformation(Constants.CORNER_RADIUS, CornerTransformType.TopLeftRounded));
}
else if (xPos == maxPos - 1 && yPos == 0)
{
this.Transformations.Add(new CornersTransformation(Constants.CORNER_RADIUS, CornerTransformType.TopRightRounded));
}
else if (xPos == 0 && yPos == maxPos - 1)
{
this.Transformations.Add(new CornersTransformation(Constants.CORNER_RADIUS, CornerTransformType.BottomLeftRounded));
}
else if (xPos == maxPos - 1 && yPos == maxPos - 1)
{
this.Transformations.Add(new CornersTransformation(Constants.CORNER_RADIUS, CornerTransformType.BottomRightRounded));
}
this.Transformations.Add(new CropTransformation(maxPos, CalculateOffset(xPos), CalculateOffset(yPos)));
}
private double CalculateOffset(int index)
{
double tileSize = 1 / (double)_maxPos;
double minimumValue = _maxPos % 2 == 0 ?
CalculateMinimumEvenGridOffset(tileSize) :
CalculateMinimumUnevenGridOffset();
return minimumValue + index * tileSize;
}
private double CalculateMinimumUnevenGridOffset()
{
return -((int)Math.Floor((double)_maxPos / 2) / (double)_maxPos);
}
private double CalculateMinimumEvenGridOffset(double tileSize)
{
double evenTileSizeCorrection = tileSize / 2;
return -((_maxPos - 1) * evenTileSizeCorrection);
}
}
}