-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextContent.cs
67 lines (62 loc) · 1.71 KB
/
TextContent.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
64
65
66
67
using Android.App;
using Android.Graphics;
namespace Segmentus
{
class TextContent : DrawablePart
{
string text;
public string Text
{
get { return text; }
set
{
text = value;
RecountOrigin();
OnAppearanceChanged();
}
}
int colorID;
public int ColorID
{
get { return colorID; }
set
{
colorID = value;
OnAppearanceChanged();
}
}
float size;
int originX, originY;
static protected Paint paint;
static TextContent()
{
Typeface tf = Typeface.CreateFromAsset(Application.Context.Assets,
"fonts/manteka.ttf");
paint = new Paint();
paint.SetTypeface(tf);
paint.TextAlign = Paint.Align.Left;
}
public TextContent(string text, int colorID, float size,
Pivot parentPivot, float x = 0, float y = 0): base(parentPivot, x, y)
{
this.text = text;
this.colorID = colorID;
this.size = size;
RecountOrigin();
}
void RecountOrigin()
{
Rect r = new Rect();
paint.TextSize = size;
paint.GetTextBounds(text, 0, text.Length, r);
originX = -r.Width() / 2 - r.Left / 2;
originY = r.Height() / 2 - r.Bottom / 2;
}
protected override void Draw(Canvas canvas)
{
paint.Color = ColorBank.GetColor(colorID);
paint.TextSize = size;
canvas.DrawText(text, originX, originY, paint);
}
}
}