12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964 |
- using System;
- using System.Diagnostics;
- using System.Text;
- using UnityEngine;
- public static class NGUIText
- {
- public static void Update()
- {
- NGUIText.Update(true);
- }
- public static void Update(bool request)
- {
- NGUIText.finalSize = Mathf.RoundToInt((float)NGUIText.fontSize / NGUIText.pixelDensity);
- NGUIText.finalSpacingX = NGUIText.spacingX * NGUIText.fontScale;
- NGUIText.finalLineHeight = ((float)NGUIText.fontSize + NGUIText.spacingY) * NGUIText.fontScale;
- NGUIText.useSymbols = (NGUIText.bitmapFont != null && NGUIText.bitmapFont.hasSymbols && NGUIText.encoding && NGUIText.symbolStyle != NGUIText.SymbolStyle.None);
- if (NGUIText.dynamicFont != null && request)
- {
- NGUIText.dynamicFont.RequestCharactersInTexture(")_-", NGUIText.finalSize, NGUIText.fontStyle);
- if (!NGUIText.dynamicFont.GetCharacterInfo(')', out NGUIText.mTempChar, NGUIText.finalSize, NGUIText.fontStyle) || NGUIText.mTempChar.vert.height == 0f)
- {
- NGUIText.dynamicFont.RequestCharactersInTexture("A", NGUIText.finalSize, NGUIText.fontStyle);
- if (!NGUIText.dynamicFont.GetCharacterInfo('A', out NGUIText.mTempChar, NGUIText.finalSize, NGUIText.fontStyle))
- {
- NGUIText.baseline = 0f;
- return;
- }
- }
- float yMax = NGUIText.mTempChar.vert.yMax;
- float yMin = NGUIText.mTempChar.vert.yMin;
- NGUIText.baseline = Mathf.Round(yMax + ((float)NGUIText.finalSize - yMax + yMin) * 0.5f);
- }
- }
- public static void Prepare(string text)
- {
- if (NGUIText.dynamicFont != null)
- {
- NGUIText.dynamicFont.RequestCharactersInTexture(text, NGUIText.finalSize, NGUIText.fontStyle);
- }
- }
- public static BMSymbol GetSymbol(string text, int index, int textLength)
- {
- return (!(NGUIText.bitmapFont != null)) ? null : NGUIText.bitmapFont.MatchSymbol(text, index, textLength);
- }
- public static float GetGlyphWidth(int ch, int prev)
- {
- if (NGUIText.bitmapFont != null)
- {
- bool flag = false;
- if (ch == 8201)
- {
- flag = true;
- ch = 32;
- }
- BMGlyph bmglyph = NGUIText.bitmapFont.bmFont.GetGlyph(ch);
- if (bmglyph != null)
- {
- int num = bmglyph.advance;
- if (flag)
- {
- num >>= 1;
- }
- return NGUIText.fontScale * (float)((prev == 0) ? bmglyph.advance : (num + bmglyph.GetKerning(prev)));
- }
- }
- else if (NGUIText.dynamicFont != null && NGUIText.dynamicFont.GetCharacterInfo((char)ch, out NGUIText.mTempChar, NGUIText.finalSize, NGUIText.fontStyle))
- {
- return NGUIText.mTempChar.width * NGUIText.fontScale * NGUIText.pixelDensity;
- }
- return 0f;
- }
- public static NGUIText.GlyphInfo GetGlyph(int ch, int prev)
- {
- if (NGUIText.bitmapFont != null)
- {
- bool flag = false;
- if (ch == 8201)
- {
- flag = true;
- ch = 32;
- }
- BMGlyph bmglyph = NGUIText.bitmapFont.bmFont.GetGlyph(ch);
- if (bmglyph != null)
- {
- int num = (prev == 0) ? 0 : bmglyph.GetKerning(prev);
- NGUIText.glyph.v0.x = (float)((prev == 0) ? bmglyph.offsetX : (bmglyph.offsetX + num));
- NGUIText.glyph.v1.y = (float)(-(float)bmglyph.offsetY);
- NGUIText.glyph.v1.x = NGUIText.glyph.v0.x + (float)bmglyph.width;
- NGUIText.glyph.v0.y = NGUIText.glyph.v1.y - (float)bmglyph.height;
- NGUIText.glyph.u0.x = (float)bmglyph.x;
- NGUIText.glyph.u0.y = (float)(bmglyph.y + bmglyph.height);
- NGUIText.glyph.u2.x = (float)(bmglyph.x + bmglyph.width);
- NGUIText.glyph.u2.y = (float)bmglyph.y;
- NGUIText.glyph.u1.x = NGUIText.glyph.u0.x;
- NGUIText.glyph.u1.y = NGUIText.glyph.u2.y;
- NGUIText.glyph.u3.x = NGUIText.glyph.u2.x;
- NGUIText.glyph.u3.y = NGUIText.glyph.u0.y;
- int num2 = bmglyph.advance;
- if (flag)
- {
- num2 >>= 1;
- }
- NGUIText.glyph.advance = (float)(num2 + num);
- NGUIText.glyph.channel = bmglyph.channel;
- if (NGUIText.fontScale != 1f)
- {
- NGUIText.glyph.v0 *= NGUIText.fontScale;
- NGUIText.glyph.v1 *= NGUIText.fontScale;
- NGUIText.glyph.advance *= NGUIText.fontScale;
- }
- return NGUIText.glyph;
- }
- }
- else if (NGUIText.dynamicFont != null && NGUIText.dynamicFont.GetCharacterInfo((char)ch, out NGUIText.mTempChar, NGUIText.finalSize, NGUIText.fontStyle))
- {
- NGUIText.glyph.v0.x = NGUIText.mTempChar.vert.xMin;
- NGUIText.glyph.v1.x = NGUIText.glyph.v0.x + NGUIText.mTempChar.vert.width;
- NGUIText.glyph.v0.y = NGUIText.mTempChar.vert.yMax - NGUIText.baseline;
- NGUIText.glyph.v1.y = NGUIText.glyph.v0.y - NGUIText.mTempChar.vert.height;
- NGUIText.glyph.u0.x = NGUIText.mTempChar.uv.xMin;
- NGUIText.glyph.u0.y = NGUIText.mTempChar.uv.yMin;
- NGUIText.glyph.u2.x = NGUIText.mTempChar.uv.xMax;
- NGUIText.glyph.u2.y = NGUIText.mTempChar.uv.yMax;
- if (NGUIText.mTempChar.flipped)
- {
- NGUIText.glyph.u1 = new Vector2(NGUIText.glyph.u2.x, NGUIText.glyph.u0.y);
- NGUIText.glyph.u3 = new Vector2(NGUIText.glyph.u0.x, NGUIText.glyph.u2.y);
- }
- else
- {
- NGUIText.glyph.u1 = new Vector2(NGUIText.glyph.u0.x, NGUIText.glyph.u2.y);
- NGUIText.glyph.u3 = new Vector2(NGUIText.glyph.u2.x, NGUIText.glyph.u0.y);
- }
- NGUIText.glyph.advance = NGUIText.mTempChar.width;
- NGUIText.glyph.channel = 0;
- NGUIText.glyph.v0.x = Mathf.Round(NGUIText.glyph.v0.x);
- NGUIText.glyph.v0.y = Mathf.Round(NGUIText.glyph.v0.y);
- NGUIText.glyph.v1.x = Mathf.Round(NGUIText.glyph.v1.x);
- NGUIText.glyph.v1.y = Mathf.Round(NGUIText.glyph.v1.y);
- float num3 = NGUIText.fontScale * NGUIText.pixelDensity;
- if (num3 != 1f)
- {
- NGUIText.glyph.v0 *= num3;
- NGUIText.glyph.v1 *= num3;
- NGUIText.glyph.advance *= num3;
- }
- return NGUIText.glyph;
- }
- return null;
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static float ParseAlpha(string text, int index)
- {
- int num = NGUIMath.HexToDecimal(text[index + 1]) << 4 | NGUIMath.HexToDecimal(text[index + 2]);
- return Mathf.Clamp01((float)num / 255f);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static Color ParseColor(string text, int offset)
- {
- return NGUIText.ParseColor24(text, offset);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static Color ParseColor24(string text, int offset)
- {
- int num = NGUIMath.HexToDecimal(text[offset]) << 4 | NGUIMath.HexToDecimal(text[offset + 1]);
- int num2 = NGUIMath.HexToDecimal(text[offset + 2]) << 4 | NGUIMath.HexToDecimal(text[offset + 3]);
- int num3 = NGUIMath.HexToDecimal(text[offset + 4]) << 4 | NGUIMath.HexToDecimal(text[offset + 5]);
- float num4 = 0.003921569f;
- return new Color(num4 * (float)num, num4 * (float)num2, num4 * (float)num3);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static Color ParseColor32(string text, int offset)
- {
- int num = NGUIMath.HexToDecimal(text[offset]) << 4 | NGUIMath.HexToDecimal(text[offset + 1]);
- int num2 = NGUIMath.HexToDecimal(text[offset + 2]) << 4 | NGUIMath.HexToDecimal(text[offset + 3]);
- int num3 = NGUIMath.HexToDecimal(text[offset + 4]) << 4 | NGUIMath.HexToDecimal(text[offset + 5]);
- int num4 = NGUIMath.HexToDecimal(text[offset + 6]) << 4 | NGUIMath.HexToDecimal(text[offset + 7]);
- float num5 = 0.003921569f;
- return new Color(num5 * (float)num, num5 * (float)num2, num5 * (float)num3, num5 * (float)num4);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static string EncodeColor(Color c)
- {
- return NGUIText.EncodeColor24(c);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static string EncodeAlpha(float a)
- {
- int num = Mathf.Clamp(Mathf.RoundToInt(a * 255f), 0, 255);
- return NGUIMath.DecimalToHex8(num);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static string EncodeColor24(Color c)
- {
- int num = 16777215 & NGUIMath.ColorToInt(c) >> 8;
- return NGUIMath.DecimalToHex24(num);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static string EncodeColor32(Color c)
- {
- int num = NGUIMath.ColorToInt(c);
- return NGUIMath.DecimalToHex32(num);
- }
- public static bool ParseSymbol(string text, ref int index)
- {
- int num = 1;
- bool flag = false;
- bool flag2 = false;
- bool flag3 = false;
- bool flag4 = false;
- bool flag5 = false;
- return NGUIText.ParseSymbol(text, ref index, null, false, ref num, ref flag, ref flag2, ref flag3, ref flag4, ref flag5);
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static bool IsHex(char ch)
- {
- return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F');
- }
- public static bool ParseSymbol(string text, ref int index, BetterList<Color> colors, bool premultiply, ref int sub, ref bool bold, ref bool italic, ref bool underline, ref bool strike, ref bool ignoreColor)
- {
- int length = text.Length;
- if (index + 3 > length || text[index] != '[')
- {
- return false;
- }
- if (text[index + 2] == ']')
- {
- if (text[index + 1] == '-')
- {
- if (colors != null && colors.size > 1)
- {
- colors.RemoveAt(colors.size - 1);
- }
- index += 3;
- return true;
- }
- string text2 = text.Substring(index, 3);
- if (text2 != null)
- {
- if (text2 == "[b]")
- {
- bold = true;
- index += 3;
- return true;
- }
- if (text2 == "[i]")
- {
- italic = true;
- index += 3;
- return true;
- }
- if (text2 == "[u]")
- {
- underline = true;
- index += 3;
- return true;
- }
- if (text2 == "[s]")
- {
- strike = true;
- index += 3;
- return true;
- }
- if (text2 == "[c]")
- {
- ignoreColor = true;
- index += 3;
- return true;
- }
- }
- }
- if (index + 4 > length)
- {
- return false;
- }
- if (text[index + 3] == ']')
- {
- string text3 = text.Substring(index, 4);
- if (text3 != null)
- {
- if (text3 == "[/b]")
- {
- bold = false;
- index += 4;
- return true;
- }
- if (text3 == "[/i]")
- {
- italic = false;
- index += 4;
- return true;
- }
- if (text3 == "[/u]")
- {
- underline = false;
- index += 4;
- return true;
- }
- if (text3 == "[/s]")
- {
- strike = false;
- index += 4;
- return true;
- }
- if (text3 == "[/c]")
- {
- ignoreColor = false;
- index += 4;
- return true;
- }
- }
- char ch = text[index + 1];
- char ch2 = text[index + 2];
- if (NGUIText.IsHex(ch) && NGUIText.IsHex(ch2))
- {
- int num = NGUIMath.HexToDecimal(ch) << 4 | NGUIMath.HexToDecimal(ch2);
- NGUIText.mAlpha = (float)num / 255f;
- index += 4;
- return true;
- }
- }
- if (index + 5 > length)
- {
- return false;
- }
- if (text[index + 4] == ']')
- {
- string text4 = text.Substring(index, 5);
- if (text4 != null)
- {
- if (text4 == "[sub]")
- {
- sub = 1;
- index += 5;
- return true;
- }
- if (text4 == "[sup]")
- {
- sub = 2;
- index += 5;
- return true;
- }
- }
- }
- if (index + 6 > length)
- {
- return false;
- }
- if (text[index + 5] == ']')
- {
- string text5 = text.Substring(index, 6);
- if (text5 != null)
- {
- if (text5 == "[/sub]")
- {
- sub = 0;
- index += 6;
- return true;
- }
- if (text5 == "[/sup]")
- {
- sub = 0;
- index += 6;
- return true;
- }
- if (text5 == "[/url]")
- {
- index += 6;
- return true;
- }
- }
- }
- if (text[index + 1] == 'u' && text[index + 2] == 'r' && text[index + 3] == 'l' && text[index + 4] == '=')
- {
- int num2 = text.IndexOf(']', index + 4);
- if (num2 != -1)
- {
- index = num2 + 1;
- return true;
- }
- index = text.Length;
- return true;
- }
- else
- {
- if (index + 8 > length)
- {
- return false;
- }
- if (text[index + 7] == ']')
- {
- Color color = NGUIText.ParseColor24(text, index + 1);
- if (NGUIText.EncodeColor24(color) != text.Substring(index + 1, 6).ToUpper())
- {
- return false;
- }
- if (colors != null)
- {
- color.a = colors[colors.size - 1].a;
- if (premultiply && color.a != 1f)
- {
- color = Color.Lerp(NGUIText.mInvisible, color, color.a);
- }
- colors.Add(color);
- }
- index += 8;
- return true;
- }
- else
- {
- if (index + 10 > length)
- {
- return false;
- }
- if (text[index + 9] != ']')
- {
- return false;
- }
- Color color2 = NGUIText.ParseColor32(text, index + 1);
- if (NGUIText.EncodeColor32(color2) != text.Substring(index + 1, 8).ToUpper())
- {
- return false;
- }
- if (colors != null)
- {
- if (premultiply && color2.a != 1f)
- {
- color2 = Color.Lerp(NGUIText.mInvisible, color2, color2.a);
- }
- colors.Add(color2);
- }
- index += 10;
- return true;
- }
- }
- }
- public static string StripSymbols(string text)
- {
- if (text != null)
- {
- int i = 0;
- int length = text.Length;
- while (i < length)
- {
- char c = text[i];
- if (c == '[')
- {
- int num = 0;
- bool flag = false;
- bool flag2 = false;
- bool flag3 = false;
- bool flag4 = false;
- bool flag5 = false;
- int num2 = i;
- if (NGUIText.ParseSymbol(text, ref num2, null, false, ref num, ref flag, ref flag2, ref flag3, ref flag4, ref flag5))
- {
- text = text.Remove(i, num2 - i);
- length = text.Length;
- continue;
- }
- }
- i++;
- }
- }
- return text;
- }
- public static void Align(BetterList<Vector3> verts, int indexOffset, float printedWidth)
- {
- NGUIText.Alignment alignment = NGUIText.alignment;
- if (alignment != NGUIText.Alignment.Right)
- {
- if (alignment != NGUIText.Alignment.Center)
- {
- if (alignment == NGUIText.Alignment.Justified)
- {
- if (printedWidth < (float)NGUIText.rectWidth * 0.65f)
- {
- return;
- }
- float num = ((float)NGUIText.rectWidth - printedWidth) * 0.5f;
- if (num < 1f)
- {
- return;
- }
- int num2 = (verts.size - indexOffset) / 4;
- if (num2 < 1)
- {
- return;
- }
- float num3 = 1f / (float)(num2 - 1);
- float num4 = (float)NGUIText.rectWidth / printedWidth;
- int i = indexOffset + 4;
- int num5 = 1;
- while (i < verts.size)
- {
- float num6 = verts.buffer[i].x;
- float num7 = verts.buffer[i + 2].x;
- float num8 = num7 - num6;
- float num9 = num6 * num4;
- float a = num9 + num8;
- float num10 = num7 * num4;
- float b = num10 - num8;
- float t = (float)num5 * num3;
- num6 = Mathf.Lerp(num9, b, t);
- num7 = Mathf.Lerp(a, num10, t);
- num6 = Mathf.Round(num6);
- num7 = Mathf.Round(num7);
- verts.buffer[i++].x = num6;
- verts.buffer[i++].x = num6;
- verts.buffer[i++].x = num7;
- verts.buffer[i++].x = num7;
- num5++;
- }
- }
- }
- else
- {
- float num11 = ((float)NGUIText.rectWidth - printedWidth) * 0.5f;
- if (num11 < 0f)
- {
- return;
- }
- int num12 = Mathf.RoundToInt((float)NGUIText.rectWidth - printedWidth);
- int num13 = Mathf.RoundToInt((float)NGUIText.rectWidth);
- bool flag = (num12 & 1) == 1;
- bool flag2 = (num13 & 1) == 1;
- if ((flag && !flag2) || (!flag && flag2))
- {
- num11 += 0.5f * NGUIText.fontScale;
- }
- for (int j = indexOffset; j < verts.size; j++)
- {
- Vector3[] buffer = verts.buffer;
- int num14 = j;
- buffer[num14].x = buffer[num14].x + num11;
- }
- }
- }
- else
- {
- float num15 = (float)NGUIText.rectWidth - printedWidth;
- if (num15 < 0f)
- {
- return;
- }
- for (int k = indexOffset; k < verts.size; k++)
- {
- Vector3[] buffer2 = verts.buffer;
- int num16 = k;
- buffer2[num16].x = buffer2[num16].x + num15;
- }
- }
- }
- public static int GetExactCharacterIndex(BetterList<Vector3> verts, BetterList<int> indices, Vector2 pos)
- {
- for (int i = 0; i < indices.size; i++)
- {
- int num = i << 1;
- int i2 = num + 1;
- float x = verts[num].x;
- if (pos.x >= x)
- {
- float x2 = verts[i2].x;
- if (pos.x <= x2)
- {
- float y = verts[num].y;
- if (pos.y >= y)
- {
- float y2 = verts[i2].y;
- if (pos.y <= y2)
- {
- return indices[i];
- }
- }
- }
- }
- }
- return 0;
- }
- public static int GetApproximateCharacterIndex(BetterList<Vector3> verts, BetterList<int> indices, Vector2 pos)
- {
- float num = float.MaxValue;
- float num2 = float.MaxValue;
- int i = 0;
- for (int j = 0; j < verts.size; j++)
- {
- float num3 = Mathf.Abs(pos.y - verts[j].y);
- if (num3 <= num2)
- {
- float num4 = Mathf.Abs(pos.x - verts[j].x);
- if (num3 < num2)
- {
- num2 = num3;
- num = num4;
- i = j;
- }
- else if (num4 < num)
- {
- num = num4;
- i = j;
- }
- }
- }
- return indices[i];
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- private static bool IsSpace(int ch)
- {
- return ch == 32 || ch == 8202 || ch == 8203 || ch == 8201;
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void EndLine(ref StringBuilder s)
- {
- int num = s.Length - 1;
- if (num > 0 && NGUIText.IsSpace((int)s[num]))
- {
- s[num] = '\n';
- }
- else
- {
- s.Append('\n');
- }
- }
- [DebuggerHidden]
- [DebuggerStepThrough]
- private static void ReplaceSpaceWithNewline(ref StringBuilder s)
- {
- int num = s.Length - 1;
- if (num > 0 && NGUIText.IsSpace((int)s[num]))
- {
- s[num] = '\n';
- }
- }
- public static Vector2 CalculatePrintedSize(string text)
- {
- Vector2 zero = Vector2.zero;
- if (!string.IsNullOrEmpty(text))
- {
- if (NGUIText.encoding)
- {
- text = NGUIText.StripSymbols(text);
- }
- NGUIText.Prepare(text);
- float num = 0f;
- float num2 = 0f;
- float num3 = 0f;
- int length = text.Length;
- int prev = 0;
- for (int i = 0; i < length; i++)
- {
- int num4 = (int)text[i];
- if (num4 == 10)
- {
- if (num > num3)
- {
- num3 = num;
- }
- num = 0f;
- num2 += NGUIText.finalLineHeight;
- }
- else if (num4 >= 32)
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- if (bmsymbol == null)
- {
- float num5 = NGUIText.GetGlyphWidth(num4, prev);
- if (num5 != 0f)
- {
- num5 += NGUIText.finalSpacingX;
- if (Mathf.RoundToInt(num + num5) > NGUIText.regionWidth)
- {
- if (num > num3)
- {
- num3 = num - NGUIText.finalSpacingX;
- }
- num = num5;
- num2 += NGUIText.finalLineHeight;
- }
- else
- {
- num += num5;
- }
- prev = num4;
- }
- }
- else
- {
- float num6 = NGUIText.finalSpacingX + (float)bmsymbol.advance * NGUIText.fontScale;
- if (Mathf.RoundToInt(num + num6) > NGUIText.regionWidth)
- {
- if (num > num3)
- {
- num3 = num - NGUIText.finalSpacingX;
- }
- num = num6;
- num2 += NGUIText.finalLineHeight;
- }
- else
- {
- num += num6;
- }
- i += bmsymbol.sequence.Length - 1;
- prev = 0;
- }
- }
- }
- zero.x = ((num <= num3) ? num3 : (num - NGUIText.finalSpacingX));
- zero.y = num2 + NGUIText.finalLineHeight;
- }
- return zero;
- }
- public static int CalculateOffsetToFit(string text)
- {
- if (string.IsNullOrEmpty(text) || NGUIText.regionWidth < 1)
- {
- return 0;
- }
- NGUIText.Prepare(text);
- int length = text.Length;
- int prev = 0;
- int i = 0;
- int length2 = text.Length;
- while (i < length2)
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- if (bmsymbol == null)
- {
- int num = (int)text[i];
- float glyphWidth = NGUIText.GetGlyphWidth(num, prev);
- if (glyphWidth != 0f)
- {
- NGUIText.mSizes.Add(NGUIText.finalSpacingX + glyphWidth);
- }
- prev = num;
- }
- else
- {
- NGUIText.mSizes.Add(NGUIText.finalSpacingX + (float)bmsymbol.advance * NGUIText.fontScale);
- int j = 0;
- int num2 = bmsymbol.sequence.Length - 1;
- while (j < num2)
- {
- NGUIText.mSizes.Add(0f);
- j++;
- }
- i += bmsymbol.sequence.Length - 1;
- prev = 0;
- }
- i++;
- }
- float num3 = (float)NGUIText.regionWidth;
- int num4 = NGUIText.mSizes.size;
- while (num4 > 0 && num3 > 0f)
- {
- num3 -= NGUIText.mSizes[--num4];
- }
- NGUIText.mSizes.Clear();
- if (num3 < 0f)
- {
- num4++;
- }
- return num4;
- }
- public static string GetEndOfLineThatFits(string text)
- {
- int length = text.Length;
- int num = NGUIText.CalculateOffsetToFit(text);
- return text.Substring(num, length - num);
- }
- public static bool WrapText(string text, out string finalText)
- {
- return NGUIText.WrapText(text, out finalText, false);
- }
- public static bool WrapText(string text, out string finalText, bool keepCharCount)
- {
- if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 1 || NGUIText.finalLineHeight < 1f)
- {
- finalText = string.Empty;
- return false;
- }
- float num = (NGUIText.maxLines <= 0) ? ((float)NGUIText.regionHeight) : Mathf.Min((float)NGUIText.regionHeight, NGUIText.finalLineHeight * (float)NGUIText.maxLines);
- int num2 = (NGUIText.maxLines <= 0) ? 1000000 : NGUIText.maxLines;
- num2 = Mathf.FloorToInt(Mathf.Min((float)num2, num / NGUIText.finalLineHeight) + 0.01f);
- if (num2 == 0)
- {
- finalText = string.Empty;
- return false;
- }
- if (string.IsNullOrEmpty(text))
- {
- text = " ";
- }
- NGUIText.Prepare(text);
- StringBuilder stringBuilder = new StringBuilder();
- int length = text.Length;
- float num3 = (float)NGUIText.regionWidth;
- int num4 = 0;
- int i = 0;
- int num5 = 1;
- int prev = 0;
- bool flag = true;
- bool flag2 = true;
- bool flag3 = false;
- while (i < length)
- {
- char c = text[i];
- if (c > '')
- {
- flag3 = true;
- }
- if (c == '\n')
- {
- if (num5 == num2)
- {
- break;
- }
- num3 = (float)NGUIText.regionWidth;
- if (num4 < i)
- {
- stringBuilder.Append(text.Substring(num4, i - num4 + 1));
- }
- else
- {
- stringBuilder.Append(c);
- }
- flag = true;
- num5++;
- num4 = i + 1;
- prev = 0;
- }
- else if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i))
- {
- i--;
- }
- else
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- float num6;
- if (bmsymbol == null)
- {
- float glyphWidth = NGUIText.GetGlyphWidth((int)c, prev);
- if (glyphWidth == 0f)
- {
- goto IL_38A;
- }
- num6 = NGUIText.finalSpacingX + glyphWidth;
- }
- else
- {
- num6 = NGUIText.finalSpacingX + (float)bmsymbol.advance * NGUIText.fontScale;
- }
- num3 -= num6;
- if (NGUIText.IsSpace((int)c) && !flag3 && num4 < i)
- {
- int num7 = i - num4 + 1;
- if (num5 == num2 && num3 <= 0f && i < length)
- {
- char c2 = text[i];
- if (c2 < ' ' || NGUIText.IsSpace((int)c2))
- {
- num7--;
- }
- }
- stringBuilder.Append(text.Substring(num4, num7));
- flag = false;
- num4 = i + 1;
- }
- if (Mathf.RoundToInt(num3) < 0)
- {
- if (flag || num5 == num2)
- {
- stringBuilder.Append(text.Substring(num4, Mathf.Max(0, i - num4)));
- bool flag4 = NGUIText.IsSpace((int)c);
- if (!flag4 && !flag3)
- {
- flag2 = false;
- }
- if (num5++ == num2)
- {
- num4 = i;
- break;
- }
- if (keepCharCount)
- {
- NGUIText.ReplaceSpaceWithNewline(ref stringBuilder);
- }
- else
- {
- NGUIText.EndLine(ref stringBuilder);
- }
- flag = true;
- if (flag4)
- {
- num4 = i + 1;
- num3 = (float)NGUIText.regionWidth;
- }
- else
- {
- num4 = i;
- num3 = (float)NGUIText.regionWidth - num6;
- }
- prev = 0;
- }
- else
- {
- flag = true;
- num3 = (float)NGUIText.regionWidth;
- i = num4 - 1;
- prev = 0;
- if (num5++ == num2)
- {
- break;
- }
- if (keepCharCount)
- {
- NGUIText.ReplaceSpaceWithNewline(ref stringBuilder);
- }
- else
- {
- NGUIText.EndLine(ref stringBuilder);
- }
- goto IL_38A;
- }
- }
- else
- {
- prev = (int)c;
- }
- if (bmsymbol != null)
- {
- i += bmsymbol.length - 1;
- prev = 0;
- }
- }
- IL_38A:
- i++;
- }
- if (num4 < i)
- {
- stringBuilder.Append(text.Substring(num4, i - num4));
- }
- finalText = stringBuilder.ToString();
- return flag2 && (i == length || num5 <= Mathf.Min(NGUIText.maxLines, num2));
- }
- public static void Print(string text, BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- if (string.IsNullOrEmpty(text))
- {
- return;
- }
- int size = verts.size;
- NGUIText.Prepare(text);
- NGUIText.mColors.Add(Color.white);
- NGUIText.mAlpha = 1f;
- int prev = 0;
- float num = 0f;
- float num2 = 0f;
- float num3 = 0f;
- float num4 = (float)NGUIText.finalSize;
- Color a = NGUIText.tint * NGUIText.gradientBottom;
- Color b = NGUIText.tint * NGUIText.gradientTop;
- Color32 color = NGUIText.tint;
- int length = text.Length;
- Rect rect = default(Rect);
- float num5 = 0f;
- float num6 = 0f;
- float num7 = num4 * NGUIText.pixelDensity;
- bool flag = false;
- int num8 = 0;
- bool flag2 = false;
- bool flag3 = false;
- bool flag4 = false;
- bool flag5 = false;
- bool flag6 = false;
- if (NGUIText.bitmapFont != null)
- {
- rect = NGUIText.bitmapFont.uvRect;
- num5 = rect.width / (float)NGUIText.bitmapFont.texWidth;
- num6 = rect.height / (float)NGUIText.bitmapFont.texHeight;
- }
- for (int i = 0; i < length; i++)
- {
- int num9 = (int)text[i];
- float num10 = num;
- if (num9 == 10)
- {
- if (num > num3)
- {
- num3 = num;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num = 0f;
- num2 += NGUIText.finalLineHeight;
- prev = 0;
- }
- else if (num9 < 32)
- {
- prev = num9;
- }
- else if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i, NGUIText.mColors, NGUIText.premultiply, ref num8, ref flag2, ref flag3, ref flag4, ref flag5, ref flag6))
- {
- Color color2;
- if (flag6)
- {
- color2 = NGUIText.mColors[NGUIText.mColors.size - 1];
- color2.a *= NGUIText.mAlpha * NGUIText.tint.a;
- }
- else
- {
- color2 = NGUIText.tint * NGUIText.mColors[NGUIText.mColors.size - 1];
- color2.a *= NGUIText.mAlpha;
- }
- color = color2;
- int j = 0;
- int num11 = NGUIText.mColors.size - 2;
- while (j < num11)
- {
- color2.a *= NGUIText.mColors[j].a;
- j++;
- }
- if (NGUIText.gradient)
- {
- a = NGUIText.gradientBottom * color2;
- b = NGUIText.gradientTop * color2;
- }
- i--;
- }
- else
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- if (bmsymbol != null)
- {
- float num12 = num + (float)bmsymbol.offsetX * NGUIText.fontScale;
- float num13 = num12 + (float)bmsymbol.width * NGUIText.fontScale;
- float num14 = -(num2 + (float)bmsymbol.offsetY * NGUIText.fontScale);
- float num15 = num14 - (float)bmsymbol.height * NGUIText.fontScale;
- if (Mathf.RoundToInt(num + (float)bmsymbol.advance * NGUIText.fontScale) > NGUIText.regionWidth)
- {
- if (num == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num12 -= num;
- num13 -= num;
- num15 -= NGUIText.finalLineHeight;
- num14 -= NGUIText.finalLineHeight;
- num = 0f;
- num2 += NGUIText.finalLineHeight;
- }
- verts.Add(new Vector3(num12, num15));
- verts.Add(new Vector3(num12, num14));
- verts.Add(new Vector3(num13, num14));
- verts.Add(new Vector3(num13, num15));
- num += NGUIText.finalSpacingX + (float)bmsymbol.advance * NGUIText.fontScale;
- i += bmsymbol.length - 1;
- prev = 0;
- if (uvs != null)
- {
- Rect uvRect = bmsymbol.uvRect;
- float xMin = uvRect.xMin;
- float yMin = uvRect.yMin;
- float xMax = uvRect.xMax;
- float yMax = uvRect.yMax;
- uvs.Add(new Vector2(xMin, yMin));
- uvs.Add(new Vector2(xMin, yMax));
- uvs.Add(new Vector2(xMax, yMax));
- uvs.Add(new Vector2(xMax, yMin));
- }
- if (cols != null)
- {
- if (NGUIText.symbolStyle == NGUIText.SymbolStyle.Colored)
- {
- for (int k = 0; k < 4; k++)
- {
- cols.Add(color);
- }
- }
- else
- {
- Color32 item = Color.white;
- item.a = color.a;
- for (int l = 0; l < 4; l++)
- {
- cols.Add(item);
- }
- }
- }
- }
- else
- {
- NGUIText.GlyphInfo glyphInfo = NGUIText.GetGlyph(num9, prev);
- if (glyphInfo != null)
- {
- prev = num9;
- if (num8 != 0)
- {
- NGUIText.GlyphInfo glyphInfo2 = glyphInfo;
- glyphInfo2.v0.x = glyphInfo2.v0.x * 0.75f;
- NGUIText.GlyphInfo glyphInfo3 = glyphInfo;
- glyphInfo3.v0.y = glyphInfo3.v0.y * 0.75f;
- NGUIText.GlyphInfo glyphInfo4 = glyphInfo;
- glyphInfo4.v1.x = glyphInfo4.v1.x * 0.75f;
- NGUIText.GlyphInfo glyphInfo5 = glyphInfo;
- glyphInfo5.v1.y = glyphInfo5.v1.y * 0.75f;
- if (num8 == 1)
- {
- NGUIText.GlyphInfo glyphInfo6 = glyphInfo;
- glyphInfo6.v0.y = glyphInfo6.v0.y - NGUIText.fontScale * (float)NGUIText.fontSize * 0.4f;
- NGUIText.GlyphInfo glyphInfo7 = glyphInfo;
- glyphInfo7.v1.y = glyphInfo7.v1.y - NGUIText.fontScale * (float)NGUIText.fontSize * 0.4f;
- }
- else
- {
- NGUIText.GlyphInfo glyphInfo8 = glyphInfo;
- glyphInfo8.v0.y = glyphInfo8.v0.y + NGUIText.fontScale * (float)NGUIText.fontSize * 0.05f;
- NGUIText.GlyphInfo glyphInfo9 = glyphInfo;
- glyphInfo9.v1.y = glyphInfo9.v1.y + NGUIText.fontScale * (float)NGUIText.fontSize * 0.05f;
- }
- }
- float num12 = glyphInfo.v0.x + num;
- float num15 = glyphInfo.v0.y - num2;
- float num13 = glyphInfo.v1.x + num;
- float num14 = glyphInfo.v1.y - num2;
- float num16 = glyphInfo.advance;
- if (NGUIText.finalSpacingX < 0f)
- {
- num16 += NGUIText.finalSpacingX;
- }
- if (Mathf.RoundToInt(num + num16) > NGUIText.regionWidth)
- {
- if (num == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num12 -= num;
- num13 -= num;
- num15 -= NGUIText.finalLineHeight;
- num14 -= NGUIText.finalLineHeight;
- num = 0f;
- num2 += NGUIText.finalLineHeight;
- num10 = 0f;
- }
- if (NGUIText.IsSpace(num9))
- {
- if (flag4)
- {
- num9 = 95;
- }
- else if (flag5)
- {
- num9 = 45;
- }
- }
- num += ((num8 != 0) ? ((NGUIText.finalSpacingX + glyphInfo.advance) * 0.75f) : (NGUIText.finalSpacingX + glyphInfo.advance));
- if (!NGUIText.IsSpace(num9))
- {
- if (uvs != null)
- {
- if (NGUIText.bitmapFont != null)
- {
- glyphInfo.u0.x = rect.xMin + num5 * glyphInfo.u0.x;
- glyphInfo.u2.x = rect.xMin + num5 * glyphInfo.u2.x;
- glyphInfo.u0.y = rect.yMax - num6 * glyphInfo.u0.y;
- glyphInfo.u2.y = rect.yMax - num6 * glyphInfo.u2.y;
- glyphInfo.u1.x = glyphInfo.u0.x;
- glyphInfo.u1.y = glyphInfo.u2.y;
- glyphInfo.u3.x = glyphInfo.u2.x;
- glyphInfo.u3.y = glyphInfo.u0.y;
- }
- int m = 0;
- int num17 = (!flag2) ? 1 : 4;
- while (m < num17)
- {
- uvs.Add(glyphInfo.u0);
- uvs.Add(glyphInfo.u1);
- uvs.Add(glyphInfo.u2);
- uvs.Add(glyphInfo.u3);
- m++;
- }
- }
- if (cols != null)
- {
- if (glyphInfo.channel == 0 || glyphInfo.channel == 15)
- {
- if (NGUIText.gradient)
- {
- float num18 = num7 + glyphInfo.v0.y / NGUIText.fontScale;
- float num19 = num7 + glyphInfo.v1.y / NGUIText.fontScale;
- num18 /= num7;
- num19 /= num7;
- NGUIText.s_c0 = Color.Lerp(a, b, num18);
- NGUIText.s_c1 = Color.Lerp(a, b, num19);
- int n = 0;
- int num20 = (!flag2) ? 1 : 4;
- while (n < num20)
- {
- cols.Add(NGUIText.s_c0);
- cols.Add(NGUIText.s_c1);
- cols.Add(NGUIText.s_c1);
- cols.Add(NGUIText.s_c0);
- n++;
- }
- }
- else
- {
- int num21 = 0;
- int num22 = (!flag2) ? 4 : 16;
- while (num21 < num22)
- {
- cols.Add(color);
- num21++;
- }
- }
- }
- else
- {
- Color color3 = color;
- color3 *= 0.49f;
- switch (glyphInfo.channel)
- {
- case 1:
- color3.b += 0.51f;
- break;
- case 2:
- color3.g += 0.51f;
- break;
- case 4:
- color3.r += 0.51f;
- break;
- case 8:
- color3.a += 0.51f;
- break;
- }
- Color32 item2 = color3;
- int num23 = 0;
- int num24 = (!flag2) ? 4 : 16;
- while (num23 < num24)
- {
- cols.Add(item2);
- num23++;
- }
- }
- }
- if (!flag2)
- {
- if (!flag3)
- {
- verts.Add(new Vector3(num12, num15));
- verts.Add(new Vector3(num12, num14));
- verts.Add(new Vector3(num13, num14));
- verts.Add(new Vector3(num13, num15));
- }
- else
- {
- float num25 = (float)NGUIText.fontSize * 0.1f * ((num14 - num15) / (float)NGUIText.fontSize);
- verts.Add(new Vector3(num12 - num25, num15));
- verts.Add(new Vector3(num12 + num25, num14));
- verts.Add(new Vector3(num13 + num25, num14));
- verts.Add(new Vector3(num13 - num25, num15));
- }
- }
- else
- {
- for (int num26 = 0; num26 < 4; num26++)
- {
- float num27 = NGUIText.mBoldOffset[num26 * 2];
- float num28 = NGUIText.mBoldOffset[num26 * 2 + 1];
- float num29 = (!flag3) ? 0f : ((float)NGUIText.fontSize * 0.1f * ((num14 - num15) / (float)NGUIText.fontSize));
- verts.Add(new Vector3(num12 + num27 - num29, num15 + num28));
- verts.Add(new Vector3(num12 + num27 + num29, num14 + num28));
- verts.Add(new Vector3(num13 + num27 + num29, num14 + num28));
- verts.Add(new Vector3(num13 + num27 - num29, num15 + num28));
- }
- }
- if (flag4 || flag5)
- {
- NGUIText.GlyphInfo glyphInfo10 = NGUIText.GetGlyph((!flag5) ? 95 : 45, prev);
- if (glyphInfo10 != null)
- {
- if (uvs != null)
- {
- if (NGUIText.bitmapFont != null)
- {
- glyphInfo10.u0.x = rect.xMin + num5 * glyphInfo10.u0.x;
- glyphInfo10.u2.x = rect.xMin + num5 * glyphInfo10.u2.x;
- glyphInfo10.u0.y = rect.yMax - num6 * glyphInfo10.u0.y;
- glyphInfo10.u2.y = rect.yMax - num6 * glyphInfo10.u2.y;
- }
- float x = (glyphInfo10.u0.x + glyphInfo10.u2.x) * 0.5f;
- int num30 = 0;
- int num31 = (!flag2) ? 1 : 4;
- while (num30 < num31)
- {
- uvs.Add(new Vector2(x, glyphInfo10.u0.y));
- uvs.Add(new Vector2(x, glyphInfo10.u2.y));
- uvs.Add(new Vector2(x, glyphInfo10.u2.y));
- uvs.Add(new Vector2(x, glyphInfo10.u0.y));
- num30++;
- }
- }
- if (flag && flag5)
- {
- num15 = (-num2 + glyphInfo10.v0.y) * 0.75f;
- num14 = (-num2 + glyphInfo10.v1.y) * 0.75f;
- }
- else
- {
- num15 = -num2 + glyphInfo10.v0.y;
- num14 = -num2 + glyphInfo10.v1.y;
- }
- if (flag2)
- {
- for (int num32 = 0; num32 < 4; num32++)
- {
- float num33 = NGUIText.mBoldOffset[num32 * 2];
- float num34 = NGUIText.mBoldOffset[num32 * 2 + 1];
- verts.Add(new Vector3(num10 + num33, num15 + num34));
- verts.Add(new Vector3(num10 + num33, num14 + num34));
- verts.Add(new Vector3(num + num33, num14 + num34));
- verts.Add(new Vector3(num + num33, num15 + num34));
- }
- }
- else
- {
- verts.Add(new Vector3(num10, num15));
- verts.Add(new Vector3(num10, num14));
- verts.Add(new Vector3(num, num14));
- verts.Add(new Vector3(num, num15));
- }
- if (NGUIText.gradient)
- {
- float num35 = num7 + glyphInfo10.v0.y / NGUIText.fontScale;
- float num36 = num7 + glyphInfo10.v1.y / NGUIText.fontScale;
- num35 /= num7;
- num36 /= num7;
- NGUIText.s_c0 = Color.Lerp(a, b, num35);
- NGUIText.s_c1 = Color.Lerp(a, b, num36);
- int num37 = 0;
- int num38 = (!flag2) ? 1 : 4;
- while (num37 < num38)
- {
- cols.Add(NGUIText.s_c0);
- cols.Add(NGUIText.s_c1);
- cols.Add(NGUIText.s_c1);
- cols.Add(NGUIText.s_c0);
- num37++;
- }
- }
- else
- {
- int num39 = 0;
- int num40 = (!flag2) ? 4 : 16;
- while (num39 < num40)
- {
- cols.Add(color);
- num39++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- NGUIText.mColors.Clear();
- }
- public static void PrintApproximateCharacterPositions(string text, BetterList<Vector3> verts, BetterList<int> indices)
- {
- if (string.IsNullOrEmpty(text))
- {
- text = " ";
- }
- NGUIText.Prepare(text);
- float num = 0f;
- float num2 = 0f;
- float num3 = 0f;
- float num4 = (float)NGUIText.fontSize * NGUIText.fontScale * 0.5f;
- int length = text.Length;
- int size = verts.size;
- int prev = 0;
- for (int i = 0; i < length; i++)
- {
- int num5 = (int)text[i];
- verts.Add(new Vector3(num, -num2 - num4));
- indices.Add(i);
- if (num5 == 10)
- {
- if (num > num3)
- {
- num3 = num;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num = 0f;
- num2 += NGUIText.finalLineHeight;
- prev = 0;
- }
- else if (num5 < 32)
- {
- prev = 0;
- }
- else if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i))
- {
- i--;
- }
- else
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- if (bmsymbol == null)
- {
- float num6 = NGUIText.GetGlyphWidth(num5, prev);
- if (num6 != 0f)
- {
- num6 += NGUIText.finalSpacingX;
- if (Mathf.RoundToInt(num + num6) > NGUIText.regionWidth)
- {
- if (num == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num = num6;
- num2 += NGUIText.finalLineHeight;
- }
- else
- {
- num += num6;
- }
- verts.Add(new Vector3(num, -num2 - num4));
- indices.Add(i + 1);
- prev = num5;
- }
- }
- else
- {
- float num7 = (float)bmsymbol.advance * NGUIText.fontScale + NGUIText.finalSpacingX;
- if (Mathf.RoundToInt(num + num7) > NGUIText.regionWidth)
- {
- if (num == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num = num7;
- num2 += NGUIText.finalLineHeight;
- }
- else
- {
- num += num7;
- }
- verts.Add(new Vector3(num, -num2 - num4));
- indices.Add(i + 1);
- i += bmsymbol.sequence.Length - 1;
- prev = 0;
- }
- }
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num - NGUIText.finalSpacingX);
- }
- }
- public static void PrintExactCharacterPositions(string text, BetterList<Vector3> verts, BetterList<int> indices)
- {
- if (string.IsNullOrEmpty(text))
- {
- text = " ";
- }
- NGUIText.Prepare(text);
- float num = (float)NGUIText.fontSize * NGUIText.fontScale;
- float num2 = 0f;
- float num3 = 0f;
- float num4 = 0f;
- int length = text.Length;
- int size = verts.size;
- int prev = 0;
- for (int i = 0; i < length; i++)
- {
- int num5 = (int)text[i];
- if (num5 == 10)
- {
- if (num2 > num4)
- {
- num4 = num2;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(verts, size, num2 - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num2 = 0f;
- num3 += NGUIText.finalLineHeight;
- prev = 0;
- }
- else if (num5 < 32)
- {
- prev = 0;
- }
- else if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i))
- {
- i--;
- }
- else
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- if (bmsymbol == null)
- {
- float glyphWidth = NGUIText.GetGlyphWidth(num5, prev);
- if (glyphWidth != 0f)
- {
- float num6 = glyphWidth + NGUIText.finalSpacingX;
- if (Mathf.RoundToInt(num2 + num6) > NGUIText.regionWidth)
- {
- if (num2 == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num2 - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num2 = 0f;
- num3 += NGUIText.finalLineHeight;
- prev = 0;
- i--;
- }
- else
- {
- indices.Add(i);
- verts.Add(new Vector3(num2, -num3 - num));
- verts.Add(new Vector3(num2 + num6, -num3));
- prev = num5;
- num2 += num6;
- }
- }
- }
- else
- {
- float num7 = (float)bmsymbol.advance * NGUIText.fontScale + NGUIText.finalSpacingX;
- if (Mathf.RoundToInt(num2 + num7) > NGUIText.regionWidth)
- {
- if (num2 == 0f)
- {
- return;
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num2 - NGUIText.finalSpacingX);
- size = verts.size;
- }
- num2 = 0f;
- num3 += NGUIText.finalLineHeight;
- prev = 0;
- i--;
- }
- else
- {
- indices.Add(i);
- verts.Add(new Vector3(num2, -num3 - num));
- verts.Add(new Vector3(num2 + num7, -num3));
- i += bmsymbol.sequence.Length - 1;
- num2 += num7;
- prev = 0;
- }
- }
- }
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && size < verts.size)
- {
- NGUIText.Align(verts, size, num2 - NGUIText.finalSpacingX);
- }
- }
- public static void PrintCaretAndSelection(string text, int start, int end, BetterList<Vector3> caret, BetterList<Vector3> highlight)
- {
- if (string.IsNullOrEmpty(text))
- {
- text = " ";
- }
- NGUIText.Prepare(text);
- int num = end;
- if (start > end)
- {
- end = start;
- start = num;
- }
- float num2 = 0f;
- float num3 = 0f;
- float num4 = 0f;
- float num5 = (float)NGUIText.fontSize * NGUIText.fontScale;
- int indexOffset = (caret == null) ? 0 : caret.size;
- int num6 = (highlight == null) ? 0 : highlight.size;
- int length = text.Length;
- int i = 0;
- int prev = 0;
- bool flag = false;
- bool flag2 = false;
- Vector2 zero = Vector2.zero;
- Vector2 zero2 = Vector2.zero;
- while (i < length)
- {
- if (caret != null && !flag2 && num <= i)
- {
- flag2 = true;
- caret.Add(new Vector3(num2 - 1f, -num3 - num5));
- caret.Add(new Vector3(num2 - 1f, -num3));
- caret.Add(new Vector3(num2 + 1f, -num3));
- caret.Add(new Vector3(num2 + 1f, -num3 - num5));
- }
- int num7 = (int)text[i];
- if (num7 == 10)
- {
- if (num2 > num4)
- {
- num4 = num2;
- }
- if (caret != null && flag2)
- {
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(caret, indexOffset, num2 - NGUIText.finalSpacingX);
- }
- caret = null;
- }
- if (highlight != null)
- {
- if (flag)
- {
- flag = false;
- highlight.Add(zero2);
- highlight.Add(zero);
- }
- else if (start <= i && end > i)
- {
- highlight.Add(new Vector3(num2, -num3 - num5));
- highlight.Add(new Vector3(num2, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3 - num5));
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && num6 < highlight.size)
- {
- NGUIText.Align(highlight, num6, num2 - NGUIText.finalSpacingX);
- num6 = highlight.size;
- }
- }
- num2 = 0f;
- num3 += NGUIText.finalLineHeight;
- prev = 0;
- }
- else if (num7 < 32)
- {
- prev = 0;
- }
- else if (NGUIText.encoding && NGUIText.ParseSymbol(text, ref i))
- {
- i--;
- }
- else
- {
- BMSymbol bmsymbol = (!NGUIText.useSymbols) ? null : NGUIText.GetSymbol(text, i, length);
- float num8 = (bmsymbol == null) ? NGUIText.GetGlyphWidth(num7, prev) : ((float)bmsymbol.advance * NGUIText.fontScale);
- if (num8 != 0f)
- {
- float num9 = num2;
- float num10 = num2 + num8;
- float num11 = -num3 - num5;
- float num12 = -num3;
- if (Mathf.RoundToInt(num10 + NGUIText.finalSpacingX) > NGUIText.regionWidth)
- {
- if (num2 == 0f)
- {
- return;
- }
- if (num2 > num4)
- {
- num4 = num2;
- }
- if (caret != null && flag2)
- {
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(caret, indexOffset, num2 - NGUIText.finalSpacingX);
- }
- caret = null;
- }
- if (highlight != null)
- {
- if (flag)
- {
- flag = false;
- highlight.Add(zero2);
- highlight.Add(zero);
- }
- else if (start <= i && end > i)
- {
- highlight.Add(new Vector3(num2, -num3 - num5));
- highlight.Add(new Vector3(num2, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3 - num5));
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && num6 < highlight.size)
- {
- NGUIText.Align(highlight, num6, num2 - NGUIText.finalSpacingX);
- num6 = highlight.size;
- }
- }
- num9 -= num2;
- num10 -= num2;
- num11 -= NGUIText.finalLineHeight;
- num12 -= NGUIText.finalLineHeight;
- num2 = 0f;
- num3 += NGUIText.finalLineHeight;
- }
- num2 += num8 + NGUIText.finalSpacingX;
- if (highlight != null)
- {
- if (start > i || end <= i)
- {
- if (flag)
- {
- flag = false;
- highlight.Add(zero2);
- highlight.Add(zero);
- }
- }
- else if (!flag)
- {
- flag = true;
- highlight.Add(new Vector3(num9, num11));
- highlight.Add(new Vector3(num9, num12));
- }
- }
- zero = new Vector2(num10, num11);
- zero2 = new Vector2(num10, num12);
- prev = num7;
- }
- }
- i++;
- }
- if (caret != null)
- {
- if (!flag2)
- {
- caret.Add(new Vector3(num2 - 1f, -num3 - num5));
- caret.Add(new Vector3(num2 - 1f, -num3));
- caret.Add(new Vector3(num2 + 1f, -num3));
- caret.Add(new Vector3(num2 + 1f, -num3 - num5));
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left)
- {
- NGUIText.Align(caret, indexOffset, num2 - NGUIText.finalSpacingX);
- }
- }
- if (highlight != null)
- {
- if (flag)
- {
- highlight.Add(zero2);
- highlight.Add(zero);
- }
- else if (start < i && end == i)
- {
- highlight.Add(new Vector3(num2, -num3 - num5));
- highlight.Add(new Vector3(num2, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3));
- highlight.Add(new Vector3(num2 + 2f, -num3 - num5));
- }
- if (NGUIText.alignment != NGUIText.Alignment.Left && num6 < highlight.size)
- {
- NGUIText.Align(highlight, num6, num2 - NGUIText.finalSpacingX);
- }
- }
- }
- public static UIFont bitmapFont;
- public static Font dynamicFont;
- public static NGUIText.GlyphInfo glyph = new NGUIText.GlyphInfo();
- public static int fontSize = 16;
- public static float fontScale = 1f;
- public static float pixelDensity = 1f;
- public static FontStyle fontStyle = FontStyle.Normal;
- public static NGUIText.Alignment alignment = NGUIText.Alignment.Left;
- public static Color tint = Color.white;
- public static int rectWidth = 1000000;
- public static int rectHeight = 1000000;
- public static int regionWidth = 1000000;
- public static int regionHeight = 1000000;
- public static int maxLines = 0;
- public static bool gradient = false;
- public static Color gradientBottom = Color.white;
- public static Color gradientTop = Color.white;
- public static bool encoding = false;
- public static float spacingX = 0f;
- public static float spacingY = 0f;
- public static bool premultiply = false;
- public static NGUIText.SymbolStyle symbolStyle;
- public static int finalSize = 0;
- public static float finalSpacingX = 0f;
- public static float finalLineHeight = 0f;
- public static float baseline = 0f;
- public static bool useSymbols = false;
- private static Color mInvisible = new Color(0f, 0f, 0f, 0f);
- private static BetterList<Color> mColors = new BetterList<Color>();
- private static float mAlpha = 1f;
- private static CharacterInfo mTempChar;
- private static BetterList<float> mSizes = new BetterList<float>();
- private static Color32 s_c0;
- private static Color32 s_c1;
- private static float[] mBoldOffset = new float[]
- {
- -0.25f,
- 0f,
- 0.25f,
- 0f,
- 0f,
- -0.25f,
- 0f,
- 0.25f
- };
- public enum Alignment
- {
- Automatic,
- Left,
- Center,
- Right,
- Justified
- }
- public enum SymbolStyle
- {
- None,
- Normal,
- Colored
- }
- public class GlyphInfo
- {
- public Vector2 v0;
- public Vector2 v1;
- public Vector2 u0;
- public Vector2 u1;
- public Vector2 u2;
- public Vector2 u3;
- public float advance;
- public int channel;
- }
- }
|