Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Incognito-old
Path: blob/main/static/src/gs/public/radius-raid/js/text.js
1324 views
1
$.textLine = function( opt ) {
2
var textLength = opt.text.length,
3
size = 5;
4
for( var i = 0; i < textLength; i++ ) {
5
var letter = $.definitions.letters[ ( opt.text.charAt( i ) ) ] || $.definitions.letters[ 'unknown' ];
6
for( var y = 0; y < size; y++ ) {
7
for( var x = 0; x < size; x++ ) {
8
if( letter[ y ][ x ] === 1 ) {
9
opt.ctx.rect( opt.x + ( x * opt.scale ) + ( ( size * opt.scale ) + opt.hspacing ) * i, opt.y + y * opt.scale, opt.scale, opt.scale );
10
}
11
}
12
}
13
}
14
};
15
16
$.text = function( opt ) {
17
var size = 5,
18
letterSize = size * opt.scale,
19
lines = opt.text.split('\n'),
20
linesCopy = lines.slice( 0 ),
21
lineCount = lines.length,
22
longestLine = linesCopy.sort( function ( a, b ) { return b.length - a.length; } )[ 0 ],
23
textWidth = ( longestLine.length * letterSize ) + ( ( longestLine.length - 1 ) * opt.hspacing ),
24
textHeight = ( lineCount * letterSize ) + ( ( lineCount - 1 ) * opt.vspacing );
25
26
var sx = opt.x,
27
sy = opt.y,
28
ex = opt.x + textWidth,
29
ey = opt.y + textHeight;
30
31
if( opt.halign == 'center' ) {
32
sx = opt.x - textWidth / 2;
33
ex = opt.x + textWidth / 2;
34
} else if( opt.halign == 'right' ) {
35
sx = opt.x - textWidth;
36
ex = opt.x;
37
}
38
39
if( opt.valign == 'center' ) {
40
sy = opt.y - textHeight / 2;
41
ey = opt.y + textHeight / 2;
42
} else if( opt.valign == 'bottom' ) {
43
sy = opt.y - textHeight;
44
ey = opt.y;
45
}
46
47
var cx = sx + textWidth / 2,
48
cy = sy + textHeight / 2;
49
50
if( opt.render ) {
51
for( var i = 0; i < lineCount; i++ ) {
52
var line = lines[ i ],
53
lineWidth = ( line.length * letterSize ) + ( ( line.length - 1 ) * opt.hspacing ),
54
x = opt.x,
55
y = opt.y + ( letterSize + opt.vspacing ) * i;
56
57
if( opt.halign == 'center' ) {
58
x = opt.x - lineWidth / 2;
59
} else if( opt.halign == 'right' ) {
60
x = opt.x - lineWidth;
61
}
62
63
if( opt.valign == 'center' ) {
64
y = y - textHeight / 2;
65
} else if( opt.valign == 'bottom' ) {
66
y = y - textHeight;
67
}
68
69
if( opt.snap ) {
70
x = Math.floor( x );
71
y = Math.floor( y );
72
}
73
74
$.textLine( {
75
ctx: opt.ctx,
76
x: x,
77
y: y,
78
text: line,
79
hspacing: opt.hspacing,
80
scale: opt.scale
81
} );
82
}
83
}
84
85
return {
86
sx: sx,
87
sy: sy,
88
cx: cx,
89
cy: cy,
90
ex: ex,
91
ey: ey,
92
width: textWidth,
93
height: textHeight
94
}
95
};
96