forked from KevinCrossDCL/OryUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOryUIText.agc
154 lines (138 loc) · 7.42 KB
/
OryUIText.agc
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
foldstart // OryUIText (Updated 12/09/2019)
function OryUICreateText(oryUIComponentParameters$ as string)
local oryUITextID
oryUITextID = CreateText("")
if (oryUIComponentParameters$ <> "") then OryUIUpdateText(oryUITextID, oryUIComponentParameters$)
endfunction oryUITextID
function OryUIPinTextToBottomCentreOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + (GetSpriteWidth(oryUISpriteB) / 2.0) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + GetSpriteHeight(oryUISpriteB)) - GetTextTotalHeight(oryUITextA)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 1)
endif
endfunction
function OryUIPinTextToBottomLeftOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + GetSpriteHeight(oryUISpriteB)) - GetTextTotalHeight(oryUITextA)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 0)
endif
endfunction
function OryUIPinTextToBottomRightOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + GetSpriteWidth(oryUISpriteB) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + GetSpriteHeight(oryUISpriteB)) - GetTextTotalHeight(oryUITextA)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 2)
endif
endfunction
function OryUIPinTextToCentreLeftOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + (GetSpriteHeight(oryUISpriteB) / 2.0)) - (GetTextTotalHeight(oryUITextA) / 2.0)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 0)
endif
endfunction
function OryUIPinTextToCentreOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + (GetSpriteWidth(oryUISpriteB) / 2.0) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + (GetSpriteHeight(oryUISpriteB) / 2.0)) - (GetTextTotalHeight(oryUITextA) / 2.0)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 1)
endif
endfunction
function OryUIPinTextToCentreRightOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + GetSpriteWidth(oryUISpriteB) + oryUIOffsetX#, ((GetSpriteY(oryUISpriteB) + (GetSpriteHeight(oryUISpriteB) / 2.0)) - (GetTextTotalHeight(oryUITextA) / 2.0)) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 2)
endif
endfunction
function OryUIPinTextToTopCentreOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + (GetSpriteWidth(oryUISpriteB) / 2.0) + oryUIOffsetX#, GetSpriteY(oryUISpriteB) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 1)
endif
endfunction
function OryUIPinTextToTopLeftOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + oryUIOffsetX#, GetSpriteY(oryUISpriteB) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 0)
endif
endfunction
function OryUIPinTextToTopRightOfSprite(oryUITextA as integer, oryUISpriteB as integer, oryUIOffsetX# as float, oryUIOffsetY# as float)
if (GetTextExists(oryUITextA) and GetSpriteExists(oryUISpriteB))
SetTextPosition(oryUITextA, GetSpriteX(oryUISpriteB) + GetSpriteWidth(oryUISpriteB) + oryUIOffsetX#, GetSpriteY(oryUISpriteB) + oryUIOffsetY#)
SetTextAlignment(oryUITextA, 2)
endif
endfunction
function OryUIUpdateText(oryUITextID as integer, oryUIComponentParameters$ as string)
OryUISetParametersType(oryUIComponentParameters$)
if (GetTextExists(oryUITextID))
if (oryUIParameters.alignment > -999999)
SetTextAlignment(oryUITextID, oryUIParameters.alignment)
endif
if (oryUIParameters.angle# > -999999)
SetTextAngle(oryUITextID, oryUIParameters.angle#)
endif
if (oryUIParameters.bold > -999999)
SetTextBold(oryUITextID, oryUIParameters.bold)
endif
if (oryUIParameters.color#[1] > -999999 or oryUIParameters.color#[2] > -999999 or oryUIParameters.color#[3] > -999999)
SetTextColor(oryUITextID, oryUIParameters.color#[1], oryUIParameters.color#[2], oryUIParameters.color#[3], GetTextColorAlpha(oryUITextID))
endif
if (oryUIParameters.color#[4] > -999999)
SetTextColorAlpha(oryUITextID, oryUIParameters.color#[4])
endif
if (oryUIParameters.depth > -999999)
SetTextDepth(oryUITextID, oryUIParameters.depth)
endif
if (oryUIParameters.fixToScreen = 1)
FixTextToScreen(oryUITextID, 1)
endif
if (oryUIParameters.position#[1] > -999999 and oryUIParameters.position#[2] > -999999)
SetTextPosition(oryUITextID, oryUIParameters.position#[1], oryUIParameters.position#[2])
elseif (oryUIParameters.position#[1] > -999999 and oryUIParameters.position#[2] = -999999)
SetTextPosition(oryUITextID, oryUIParameters.position#[1], GetTextY(oryUITextID))
elseif (oryUIParameters.position#[1] = -999999 and oryUIParameters.position#[2] > -999999)
SetTextPosition(oryUITextID, GetTextX(oryUITextID), oryUIParameters.position#[2])
endif
if (oryUIParameters.size#[1] > -999999)
SetTextSize(oryUITextID, oryUIParameters.size#[1])
endif
if (oryUIParameters.text$ <> "")
SetTextString(oryUITextID, oryUIParameters.text$)
endif
endif
endfunction
function OryUIWrapText(oryUIText$ as string, oryUISize# as float, oryUIMaxWidth# as float)
local oryUIFinalText$ as string
local oryUILength as integer
local oryUISpace as integer
local oryUITmpText as integer
local oryUITmpText2 as integer
oryUITmpText = CreateText(oryUIText$)
SetTextSize(oryUITmpText, oryUISize#)
SetTextPosition(oryUITmpText, -10000, -10000)
if (GetTextTotalWidth(oryUITmpText) >= oryUIMaxWidth#)
while (GetTextTotalWidth(oryUITmpText) >= oryUIMaxWidth#)
oryUILength = len(oryUIText$)
oryUISpace = 0
for oryUIForI = 1 to oryUILength
if (mid(oryUIText$, oryUIForI, 1) = " ") then oryUISpace = oryUIForI
oryUITmpText2 = CreateText(left(oryUIText$, oryUIForI))
SetTextSize(oryUITmpText2, oryUISize#)
SetTextPosition(oryUITmpText2, -10000, -10000)
if (GetTextTotalWidth(oryUITmpText2) > oryUIMaxWidth#)
DeleteText(oryUITmpText2)
exit
endif
DeleteText(oryUITmpText2)
next
oryUIFinalText$ = oryUIFinalText$ + left(oryUIText$, (oryUISpace - 1)) + chr(10)
oryUIText$ = right(oryUIText$, (len(oryUIText$) - oryUISpace))
DeleteText(oryUITmpText)
oryUITmpText = CreateText(oryUIText$)
SetTextSize(oryUITmpText, oryUISize#)
SetTextPosition(oryUITmpText, -10000, -10000)
if (oryUISpace = 0) then exit
endwhile
if (len(oryUIText$) > 0) then oryUIFinalText$ = oryUIFinalText$ + oryUIText$
else
oryUIFinalText$ = oryUIText$
endif
DeleteText(oryUITmpText)
endfunction oryUIFinalText$
foldend