Guest User

Untitled

a guest
May 20th, 2025
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.95 KB | None | 0 0
  1. require "ISUI/ISPanel"
  2.  
  3. ISRichTextPanel = ISPanel:derive("ISRichTextPanel");
  4. local IMAGE_PAD = 5
  5.  
  6. ISRichTextPanel.drawMargins = false
  7.  
  8. --************************************************************************--
  9. --** ISRichTextPanel:initialise
  10. --**
  11. --************************************************************************--
  12.  
  13. function ISRichTextPanel:initialise()
  14. ISPanel.initialise(self);
  15. end
  16.  
  17. function ISRichTextPanel:setText(text)
  18. self.text = text or ""
  19. end
  20.  
  21. function ISRichTextPanel:processCommand(command, x, y, lineImageHeight, lineHeight)
  22. if command == "LINE" then
  23. x = 0;
  24. lineImageHeight = 0;
  25. y = y + lineHeight;
  26.  
  27. end
  28. if command == "BR" then
  29. x = 0;
  30. lineImageHeight = 0;
  31. y = y + lineHeight + lineHeight;
  32.  
  33. end
  34. if command == "H1" then
  35. self.orient[self.currentLine] = "centre";
  36. self.rgb[self.currentLine] = {};
  37. self.rgb[self.currentLine].r = 1;
  38. self.rgb[self.currentLine].g = 1;
  39. self.rgb[self.currentLine].b = 1;
  40. self.font = UIFont.Large;
  41. self.fonts[self.currentLine] = self.font;
  42. end
  43. if command == "H2" then
  44. self.orient[self.currentLine] = "left";
  45. self.rgb[self.currentLine] = {};
  46. self.rgb[self.currentLine].r = 0.8;
  47. self.rgb[self.currentLine].g = 0.8;
  48. self.rgb[self.currentLine].b = 0.8;
  49. self.font = UIFont.Medium;
  50. self.fonts[self.currentLine] = self.font;
  51. end
  52. if command == "TEXT" then
  53. self.orient[self.currentLine] = "left";
  54. self.rgb[self.currentLine] = {};
  55. self.rgb[self.currentLine].r = 0.7;
  56. self.rgb[self.currentLine].g = 0.7;
  57. self.rgb[self.currentLine].b = 0.7;
  58. self.rgbCurrent = self.rgb[self.currentLine]
  59. self.font = self.defaultFont;
  60. self.fonts[self.currentLine] = self.font;
  61. end
  62. if command == "CENTRE" then
  63. self.orient[self.currentLine] = "centre";
  64. end
  65.  
  66. if command == "LEFT" then
  67. self.orient[self.currentLine] = "left";
  68. end
  69.  
  70. if command == "RIGHT" then
  71. self.orient[self.currentLine] = "right";
  72. end
  73. if string.find(command, "PUSHRGB:") then
  74. table.insert(self.rgbStack, self.rgbCurrent)
  75. local rgb = string.split(string.sub(command, 9, string.len(command)), ",")
  76. self.rgb[self.currentLine] = {}
  77. self.rgb[self.currentLine].r = tonumber(rgb[1])
  78. self.rgb[self.currentLine].g = tonumber(rgb[2])
  79. self.rgb[self.currentLine].b = tonumber(rgb[3])
  80. self.rgbCurrent = self.rgb[self.currentLine]
  81. elseif string.find(command, "POPRGB") then
  82. if #self.rgbStack > 0 then
  83. self.rgbCurrent = table.remove(self.rgbStack, #self.rgbStack)
  84. self.rgb[self.currentLine] = self.rgbCurrent
  85. end
  86. elseif string.find(command, "RGB:") then
  87. local rgb = string.split(string.sub(command, 5, string.len(command)), ",");
  88. self.rgb[self.currentLine] = {};
  89. self.rgb[self.currentLine].r = tonumber(rgb[1]);
  90. self.rgb[self.currentLine].g = tonumber(rgb[2]);
  91. self.rgb[self.currentLine].b = tonumber(rgb[3]);
  92. self.rgbCurrent = self.rgb[self.currentLine]
  93. elseif string.find(command, "GHC") then
  94. self.rgb[self.currentLine] = {};
  95. self.rgb[self.currentLine].r = getCore():getGoodHighlitedColor():getR();
  96. self.rgb[self.currentLine].g = getCore():getGoodHighlitedColor():getG();
  97. self.rgb[self.currentLine].b = getCore():getGoodHighlitedColor():getB();
  98. self.rgbCurrent = self.rgb[self.currentLine]
  99. elseif string.find(command, "BHC") then
  100. self.rgb[self.currentLine] = {};
  101. self.rgb[self.currentLine].r = getCore():getBadHighlitedColor():getR();
  102. self.rgb[self.currentLine].g = getCore():getBadHighlitedColor():getG();
  103. self.rgb[self.currentLine].b = getCore():getBadHighlitedColor():getB();
  104. self.rgbCurrent = self.rgb[self.currentLine]
  105. end
  106. if string.find(command, "RED") then
  107. self.rgb[self.currentLine] = {};
  108. self.rgb[self.currentLine].r = 1;
  109. self.rgb[self.currentLine].g = 0;
  110. self.rgb[self.currentLine].b = 0;
  111. self.rgbCurrent = self.rgb[self.currentLine]
  112. end
  113. if string.find(command, "ORANGE") then
  114. self.rgb[self.currentLine] = {};
  115. self.rgb[self.currentLine].r = 0.9;
  116. self.rgb[self.currentLine].g = 0.3;
  117. self.rgb[self.currentLine].b = 0;
  118. self.rgbCurrent = self.rgb[self.currentLine]
  119. end
  120. if string.find(command, "GREEN") then
  121. self.rgb[self.currentLine] = {};
  122. self.rgb[self.currentLine].r = 0;
  123. self.rgb[self.currentLine].g = 1;
  124. self.rgb[self.currentLine].b = 0;
  125. self.rgbCurrent = self.rgb[self.currentLine]
  126. end
  127. if string.find(command, "SIZE:") then
  128.  
  129. local size = string.sub(command, 6);
  130. --~ print(size);
  131. if(size == "small") then
  132. self.font = UIFont.NewSmall;
  133. end
  134. if(size == "medium") then
  135. self.font = UIFont.Medium;
  136. end
  137. if(size == "large") then
  138. self.font = UIFont.Large;
  139. end
  140. self.fonts[self.currentLine] = self.font;
  141. end
  142.  
  143. if string.find(command, "IMAGE:") ~= nil then
  144. local w = 0;
  145. local h = 0;
  146. if string.find(command, ",") ~= nil then
  147. local vs = string.split(command, ",");
  148.  
  149. command = string.trim(vs[1]);
  150. w = tonumber(string.trim(vs[2]));
  151. h = tonumber(string.trim(vs[3]));
  152.  
  153. end
  154. self.images[self.imageCount] = getTexture(string.sub(command, 7));
  155. if(w==0) then
  156. w = self.images[self.imageCount]:getWidth();
  157. h = self.images[self.imageCount]:getHeight();
  158. end
  159. if(x + w >= self.width - (self.marginLeft + self.marginRight)) then
  160. x = 0;
  161. y = y + lineHeight;
  162. end
  163.  
  164. if(lineImageHeight < h + 0) then
  165. lineImageHeight = h + 0;
  166. end
  167.  
  168. if self.images[self.imageCount] == nil then
  169. --print("Could not find texture");
  170. end
  171. self.imageX[self.imageCount] = x+IMAGE_PAD;
  172. self.imageY[self.imageCount] = y+(lineHeight-lineImageHeight)/2;
  173. self.imageW[self.imageCount] = w;
  174. self.imageH[self.imageCount] = h;
  175. self.imageCount = self.imageCount + 1;
  176. x = x + w + IMAGE_PAD*2;
  177. --[[
  178. local newY = math.max(y + (h / 2) - 7, y)
  179.  
  180. for c,v in ipairs(self.lines) do
  181. if self.lineY[c] == y then
  182. self.lineY[c] = newY;
  183. end
  184. end
  185. for c,v in ipairs(self.imageY) do
  186. if self.imageY[c] == y then
  187. self.imageY[c] = newY;
  188. end
  189. end
  190. y = newY;
  191. --]]
  192. end
  193.  
  194.  
  195. if string.find(command, "IMAGECENTRE:") ~= nil then
  196. local w = 0;
  197. local h = 0;
  198. if string.find(command, ",") ~= nil then
  199. local vs = string.split(command, ",");
  200.  
  201. command = string.trim(vs[1]);
  202. w = tonumber(string.trim(vs[2]));
  203. h = tonumber(string.trim(vs[3]));
  204.  
  205. end
  206. self.images[self.imageCount] = getTexture(string.sub(command, 13));
  207. if(w==0) then
  208. w = self.images[self.imageCount]:getWidth();
  209. h = self.images[self.imageCount]:getHeight();
  210. end
  211. if(x + w >= self.width - (self.marginLeft + self.marginRight)) then
  212. x = 0;
  213. y = y + lineHeight;
  214. end
  215.  
  216. if(lineImageHeight < (h / 2) + 8) then
  217. lineImageHeight = (h / 2) + 16;
  218. end
  219.  
  220. if self.images[self.imageCount] == nil then
  221. --print("Could not find texture");
  222. end
  223. local mx = (self.width - self.marginLeft - self.marginRight) / 2;
  224. self.imageX[self.imageCount] = mx - (w/2);
  225. self.imageY[self.imageCount] = y;
  226. self.imageW[self.imageCount] = w;
  227. self.imageH[self.imageCount] = h;
  228. self.imageCount = self.imageCount + 1;
  229. x = x + w + 7;
  230.  
  231. for c,v in ipairs(self.lines) do
  232. if self.lineY[c] == y then
  233. self.lineY[c] = self.lineY[c] + (h / 2);
  234. end
  235. end
  236.  
  237. y = y + (h / 2);
  238. end
  239.  
  240. if string.find(command, "VIDEOCENTRE:") ~= nil then
  241. local w = 0;
  242. local h = 0;
  243. local w2 = 384
  244. local h2 = 216
  245. local image = "";
  246. if string.find(command, ",") ~= nil then
  247. local vs = string.split(command, ",");
  248.  
  249. command = string.trim(vs[1]);
  250. w = tonumber(string.trim(vs[2])); --video width
  251. h = tonumber(string.trim(vs[3])); --video height
  252. if vs[5] then --test to see if the display height has been defined
  253. w2 = tonumber(string.trim(vs[4])) --display width
  254. h2 = tonumber(string.trim(vs[5])) --display height
  255. end
  256. image = "media/videos/" .. string.trim(string.split(command, ":")[2]) .. ".png"
  257. end
  258.  
  259. if Core.getInstance() then
  260. -- Play the video
  261. self.videos[self.videoCount] = getVideo(string.sub(command, 13), w, h);
  262.  
  263. w = w2
  264. h = h2
  265. if(x + w >= self.width - (self.marginLeft + self.marginRight)) then
  266. x = 0;
  267. y = y + lineHeight;
  268. end
  269.  
  270. if(lineImageHeight < (h / 2) + 8) then
  271. lineImageHeight = (h / 2) + 16;
  272. end
  273.  
  274. if self.videos[self.videoCount] == nil then
  275. print("Could not find video");
  276. end
  277. local mx = (self.width - self.marginLeft - self.marginRight) / 2;
  278. self.videoX[self.videoCount] = mx - (w/2);
  279. self.videoY[self.videoCount] = y;
  280. self.videoW[self.videoCount] = w;
  281. self.videoH[self.videoCount] = h;
  282. self.videoCount = self.videoCount + 1;
  283. x = x + w + 7;
  284.  
  285. for c,v in ipairs(self.lines) do
  286. if self.lineY[c] == y then
  287. self.lineY[c] = self.lineY[c] + (h / 2);
  288. end
  289. end
  290.  
  291. y = y + (h / 2);
  292. else
  293. -- Video Effects off, show the backup image
  294. -- self.images[self.imageCount] = getTexture(image);
  295.  
  296. -- w = self.images[self.imageCount]:getWidth();
  297. -- h = self.images[self.imageCount]:getHeight();
  298.  
  299. -- if(x + w >= self.width - (self.marginLeft + self.marginRight)) then
  300. -- x = 0;
  301. -- y = y + lineHeight;
  302. -- end
  303.  
  304. -- if(lineImageHeight < (h / 2) + 8) then
  305. -- lineImageHeight = (h / 2) + 16;
  306. -- end
  307.  
  308. -- if self.images[self.imageCount] == nil then
  309. -- --print("Could not find texture");
  310. -- end
  311. -- local mx = (self.width - self.marginLeft - self.marginRight) / 2;
  312. -- self.imageX[self.imageCount] = mx - (w/2);
  313. -- self.imageY[self.imageCount] = y;
  314. -- self.imageW[self.imageCount] = w;
  315. -- self.imageH[self.imageCount] = h;
  316. -- self.imageCount = self.imageCount + 1;
  317. -- x = x + w + 7;
  318.  
  319. -- for c,v in ipairs(self.lines) do
  320. -- if self.lineY[c] == y then
  321. -- self.lineY[c] = self.lineY[c] + (h / 2);
  322. -- end
  323. -- end
  324.  
  325. -- y = y + (h / 2);
  326. end
  327. end
  328.  
  329. if string.find(command, "INDENT:") then
  330. self.indent = tonumber(string.sub(command, 8))
  331. end
  332.  
  333. if string.find(command, "JOYPAD:") ~= nil then
  334. local w = 0
  335. local h = 0
  336. if string.find(command, ",") ~= nil then
  337. local vs = string.split(command, ",")
  338. command = string.trim(vs[1])
  339. w = tonumber(string.trim(vs[2]))
  340. h = tonumber(string.trim(vs[3]))
  341. end
  342. self.images[self.imageCount] = Joypad.Texture[string.sub(command, 8)]
  343. if w == 0 then
  344. w = self.images[self.imageCount]:getWidth()
  345. h = self.images[self.imageCount]:getHeight()
  346. end
  347. if(x + w >= self.width - (self.marginLeft + self.marginRight)) then
  348. x = 0
  349. y = y + lineHeight
  350. end
  351. if lineImageHeight < h + 0 then
  352. lineImageHeight = h + 0;
  353. end
  354. self.imageX[self.imageCount] = x+IMAGE_PAD
  355. self.imageY[self.imageCount] = y+(lineHeight-lineImageHeight)/2
  356. self.imageW[self.imageCount] = w
  357. self.imageH[self.imageCount] = h
  358. self.imageCount = self.imageCount + 1
  359. x = x + w + IMAGE_PAD*2
  360. end
  361.  
  362. if string.find(command, "SETX:") then
  363. x = tonumber(string.sub(command, 6))
  364. end
  365.  
  366. if string.find(command, "SPACE") then
  367. if x > 0 then
  368. x = x + getTextManager():MeasureStringX(self.font, " ") + 2
  369. end
  370. end
  371.  
  372. return x, y, lineImageHeight
  373.  
  374. end
  375.  
  376. function ISRichTextPanel:replaceKeyName(text, offset)
  377. local p1,p2 = string.find(text, "<KEY:", offset)
  378. if not p1 then return text, nil end
  379. local p3,p4 = string.find(text, ">", p2 + 1)
  380. if not p3 then return text, nil end
  381. local binding = string.sub(text, p2 + 1, p3 - 1):gsub("&nbsp;", " ")
  382. local textBefore = string.sub(text, 1, p1 - 1)
  383. local textAfter = string.sub(text, p4 + 1)
  384. local newText = " <PUSHRGB:0,0.635,0.91> " .. getKeyName(getCore():getKey(binding)) .. " <POPRGB> "
  385. return textBefore .. newText .. textAfter, p1 + #newText
  386. end
  387.  
  388. function ISRichTextPanel:replaceKeyNames(text)
  389. local offset = 1
  390. while true do
  391. text, offset = self:replaceKeyName(text, offset)
  392. if not offset then break end
  393. end
  394. return text
  395. end
  396.  
  397. function ISRichTextPanel:onMouseWheel(del)
  398. self:setYScroll(self:getYScroll() - (del*18));
  399. return true;
  400. end
  401. --************************************************************************--
  402. --** ISRichTextPanel:paginate
  403. --**
  404. --** Splits multiline text up into seperate lines, and positions images to be
  405. --** rendered
  406. --************************************************************************--
  407. function ISRichTextPanel:paginate()
  408. local lines = 1;
  409. self.textDirty = false;
  410. self.imageCount = 1;
  411. self.font = self.defaultFont;
  412. self.fonts = {};
  413. self.images = {}
  414. self.imageX = {}
  415. self.imageY = {}
  416. self.rgb = {};
  417. self.rgbCurrent = { r = 1, g = 1, b = 1 }
  418. self.rgbStack = {}
  419. self.orient = {}
  420. self.indent = 0
  421.  
  422. self.imageW = {}
  423. self.imageH = {}
  424.  
  425. self.lineY = {}
  426. self.lineX = {}
  427. self.lines = {}
  428.  
  429. self.keybinds = {}
  430.  
  431. self.videoCount = 1;
  432. self.videos = {}
  433. self.videoX = {}
  434. self.videoY = {}
  435. self.videoW = {}
  436. self.videoH = {}
  437.  
  438. local bDone = false;
  439. local leftText = self:replaceKeyNames(self.text) .. ' ';
  440. local cur = 0;
  441. local y = 0;
  442. local x = 0;
  443. local lineImageHeight = 0;
  444. leftText = leftText:gsub("\n", " <LINE> ")
  445. if self.maxLines > 0 then
  446. local lines = leftText:split("<LINE>")
  447. for i=1,(#lines - self.maxLines) do
  448. table.remove(lines,1)
  449. end
  450. leftText = ' '
  451. for k,v in ipairs(lines) do
  452. leftText = leftText..v.." <LINE> "
  453. end
  454. end
  455. local maxLineWidth = self.maxLineWidth or (self.width - self.marginRight - self.marginLeft)
  456. -- Always go through at least once.
  457. while not bDone do
  458. cur = string.find(leftText, " ", cur+1);
  459. if cur ~= nil then
  460. -- while string.sub(leftText, cur, cur)== " " do
  461. -- cur = cur + 1
  462. -- end
  463. -- cur = cur - 1
  464. local token = string.sub(leftText, 0, cur);
  465. if string.find(token, "<") and string.find(token, ">") then -- handle missing ' ' after '>'
  466. cur = string.find(token, ">") + 1;
  467. token = string.sub(leftText, 0, cur - 1);
  468. end
  469. leftText = string.sub(leftText, cur);
  470. cur = 1
  471. if string.find(token, "<") and string.find(token, ">") then
  472. if not self.lines[lines] then
  473. self.lines[lines] = ''
  474. self.lineX[lines] = x
  475. self.lineY[lines] = y
  476. end
  477. lines = lines + 1
  478. local st = string.find(token, "<");
  479. local en = string.find(token, ">");
  480. local escSeq = string.sub(token, st+1, en-1);
  481. local lineHeight = getTextManager():getFontFromEnum(self.font):getLineHeight();
  482. if lineHeight < 10 then
  483. lineHeight = 10;
  484. end
  485. if lineHeight < lineImageHeight then
  486. lineHeight = lineImageHeight;
  487. end
  488. self.currentLine = lines;
  489. x, y, lineImageHeight = self:processCommand(escSeq, x, y, lineImageHeight, lineHeight);
  490. else
  491. if token:contains("&lt;") then
  492. token = token:gsub("&lt;", "<")
  493. end
  494. if token:contains("&gt;") then
  495. token = token:gsub("&gt;", ">")
  496. end
  497. local chunkText = self.lines[lines] or ''
  498. local chunkX = self.lineX[lines] or x
  499. if chunkText == '' then
  500. chunkText = string.trim(token)
  501. elseif string.trim(token) ~= '' then
  502. chunkText = chunkText..' '..string.trim(token)
  503. end
  504. local pixLen = getTextManager():MeasureStringX(self.font, chunkText);
  505. if chunkX + pixLen > maxLineWidth then
  506. if self.lines[lines] and self.lines[lines] ~= '' then
  507. lines = lines + 1;
  508. end
  509. local lineHeight = getTextManager():getFontFromEnum(self.font):getLineHeight();
  510. if lineHeight < lineImageHeight then
  511. lineHeight = lineImageHeight;
  512. end
  513. lineImageHeight = 0;
  514. y = y + lineHeight;
  515. x = 0;
  516. self.lines[lines] = string.trim(token)
  517. if self.lines[lines] ~= "" then
  518. x = self.indent
  519. end
  520. self.lineX[lines] = x
  521. self.lineY[lines] = y
  522. x = x + getTextManager():MeasureStringX(self.font, self.lines[lines])
  523. else
  524. if not self.lines[lines] then
  525. self.lines[lines] = ''
  526. self.lineX[lines] = x
  527. self.lineY[lines] = y
  528. end
  529. self.lines[lines] = chunkText
  530. if self.lineX[lines] == 0 and self.lines[lines] ~= "" then
  531. self.lineX[lines] = self.indent
  532. end
  533. x = self.lineX[lines] + pixLen
  534. end
  535. end
  536. else
  537. if string.trim(leftText) ~= '' then
  538. local str = leftText
  539. if str:contains("&lt;") then
  540. str = str:gsub("&lt;", "<")
  541. end
  542. if str:contains("&gt;") then
  543. str = str:gsub("&gt;", ">")
  544. end
  545. self.lines[lines] = string.trim(str);
  546. if x == 0 and self.lines[lines] ~= "" then
  547. x = self.indent
  548. end
  549. self.lineX[lines] = x;
  550. self.lineY[lines] = y;
  551. local lineHeight = getTextManager():getFontFromEnum(self.font):getLineHeight();
  552. y = y + lineHeight
  553. elseif self.lines[lines] and self.lines[lines] ~= '' then
  554. local lineHeight = getTextManager():getFontFromEnum(self.font):getLineHeight();
  555. if lineHeight < lineImageHeight then
  556. lineHeight = lineImageHeight;
  557. end
  558. y = y + lineHeight
  559. end
  560. bDone = true;
  561. end
  562. end
  563.  
  564. if self.autosetheight then
  565. self:setHeight(self.marginTop + y + self.marginBottom);
  566. end
  567.  
  568. self:setScrollHeight(self.marginTop + y + self.marginBottom);
  569. end
  570.  
  571. function ISRichTextPanel:setContentTransparency(alpha)
  572. self.contentTransparency = alpha;
  573. end
  574.  
  575. --************************************************************************--
  576. --** ISRichTextPanel:render
  577. --**
  578. --************************************************************************--
  579. function ISRichTextPanel:render()
  580.  
  581. self.r = 1;
  582. self.g = 1;
  583. self.b = 1;
  584.  
  585. if self.lines == nil then
  586. return;
  587. end
  588.  
  589. if self.keybinds then
  590. for binding,text in pairs(self.keybinds) do
  591. if getKeyName(getCore():getKey(binding)) ~= text then
  592. self.textDirty = true
  593. break
  594. end
  595. end
  596. end
  597.  
  598. if self.clip then self:setStencilRect(0, 0, self.width, self.height) end
  599. if self.textDirty then
  600. self:paginate();
  601. end
  602. --ISPanel.render(self);
  603. for c,v in ipairs(self.images) do
  604. self:drawTextureScaled(v, self.imageX[c] + self.marginLeft, self.imageY[c] + self.marginTop, self.imageW[c], self.imageH[c], self.contentTransparency, 1, 1, 1);
  605. end
  606.  
  607. for c,v in ipairs(self.videos) do
  608. v:RenderFrame()
  609. self:drawTextureScaled(v, self.videoX[c] + self.marginLeft, self.videoY[c] + self.marginTop, self.videoW[c], self.videoH[c], self.contentTransparency, 1, 1, 1);
  610. end
  611.  
  612. self.font = self.defaultFont
  613. local orient = "left";
  614. local c = 1
  615. while c <= #self.lines do
  616. local v = self.lines[c]
  617.  
  618. if self.lineY[c] + self.marginTop + self:getYScroll() >= self:getHeight() then
  619. break
  620. end
  621.  
  622. if self.rgb[c] then
  623. self.r = self.rgb[c].r;
  624. self.g = self.rgb[c].g;
  625. self.b = self.rgb[c].b;
  626. end
  627.  
  628. if self.orient[c] then
  629. orient = self.orient[c];
  630. end
  631.  
  632. if self.fonts[c] then
  633. self.font = self.fonts[c];
  634. end
  635.  
  636. if self.marginTop + self:getYScroll() + self.lineY[c] + getTextManager():getFontHeight(self.font) > 0 then
  637.  
  638. local r = self.r;
  639. local b = self.b;
  640. local g = self.g;
  641.  
  642. if v:contains("&lt;") then
  643. v = v:gsub("&lt;", "<")
  644. end
  645. if v:contains("&gt;") then
  646. v = v:gsub("&gt;", ">")
  647. end
  648.  
  649. if string.trim(v) ~= "" then
  650. if orient == "centre" then
  651. local lineY = self.lineY[c]
  652. local lineLength = 0
  653. local c2 = c
  654. while (c2 <= #self.lines) and (self.lineY[c2] == lineY) do
  655. local font = self.fonts[c2] or self.font
  656. lineLength = lineLength + getTextManager():MeasureStringX(font, string.trim(self.lines[c2]))
  657. c2 = c2 + 1
  658. end
  659. local lineX = self.marginLeft + (self.width - self.marginLeft - self.marginRight - lineLength) / 2
  660. while (c <= #self.lines) and (self.lineY[c] == lineY) do
  661. if self.rgb[c] then
  662. self.r = self.rgb[c].r;
  663. self.g = self.rgb[c].g;
  664. self.b = self.rgb[c].b;
  665. end
  666. local r = self.r;
  667. local b = self.b;
  668. local g = self.g;
  669. if self.orient[c] then
  670. orient = self.orient[c];
  671. end
  672. if self.fonts[c] then
  673. self.font = self.fonts[c];
  674. end
  675. self:drawText(string.trim(self.lines[c]), lineX + self.lineX[c], self.lineY[c] + self.marginTop, r, g, b, self.contentTransparency, self.font)
  676. -- lineX = lineX + getTextManager():MeasureStringX(self.font, self.lines[c])
  677. c = c + 1
  678. end
  679. c = c - 1
  680. elseif orient == "right" then
  681. self:drawTextRight( string.trim(v), self.lineX[c] + self.marginLeft, self.lineY[c] + self.marginTop, r, g, b,self.contentTransparency, self.font);
  682. else
  683. self:drawText( string.trim(v), self.lineX[c] + self.marginLeft, self.lineY[c] + self.marginTop, r, g, b,self.contentTransparency, self.font);
  684. end
  685.  
  686. -- self:drawRect(self.lineX[c] + self.marginLeft, self.lineY[c] + self.marginTop, self.width, 1, 1.0, 0.5, 0.5, 0.5)
  687. end
  688. end
  689. c = c + 1
  690. end
  691.  
  692. if ISRichTextPanel.drawMargins then
  693. self:drawRectBorder(0, 0, self.width, self:getScrollHeight(), 0.5,1,1,1)
  694. self:drawRect(self.marginLeft, 0, 1, self:getScrollHeight(), 1,1,1,1)
  695. local maxLineWidth = self.maxLineWidth or (self.width - self.marginRight - self.marginLeft)
  696. -- self:drawRect(self.marginLeft + maxLineWidth, 0, 1, self:getScrollHeight(), 1,1,1,1)
  697. self:drawRect(self.width - self.marginRight, 0, 1, self:getScrollHeight(), 1,1,1,1)
  698. self:drawRect(0, self.marginTop, self.width, 1, 1,1,1,1)
  699. self:drawRect(0, self:getScrollHeight() - self.marginBottom, self.width, 1, 1,1,1,1)
  700. end
  701.  
  702. if self.clip then self:clearStencilRect() end
  703. --self:setScrollHeight(y);
  704. end
  705.  
  706. function ISRichTextPanel:onResize()
  707. -- ISUIElement.onResize(self);
  708. self.width = self:getWidth();
  709. self.height = self:getHeight();
  710. self.textDirty = true;
  711. self:updateScrollbars()
  712. end
  713.  
  714. function ISRichTextPanel:setMargins(left, top, right, bottom)
  715. self.marginLeft = left
  716. self.marginTop = top
  717. self.marginRight = right
  718. self.marginBottom = bottom
  719. end
  720.  
  721. function ISRichTextPanel:doRightJoystickScrolling(joypadData, dx, dy)
  722. dx = dx or 20
  723. dy = dy or 20
  724. local axisY = getJoypadAimingAxisY(joypadData.id)
  725. if axisY > 0.75 then
  726. self:setYScroll(self:getYScroll() - dy * UIManager.getMillisSinceLastRender() / 33.3)
  727. end
  728. if axisY < -0.75 then
  729. self:setYScroll(self:getYScroll() + dy * UIManager.getMillisSinceLastRender() / 33.3)
  730. end
  731. local axisX = getJoypadAimingAxisX(joypadData.id)
  732. if axisX > 0.75 then
  733. self:setXScroll(self:getXScroll() - dx * UIManager.getMillisSinceLastRender() / 33.3)
  734. end
  735. if axisX < -0.75 then
  736. self:setXScroll(self:getXScroll() + dx * UIManager.getMillisSinceLastRender() / 33.3)
  737. end
  738. end
  739.  
  740. --************************************************************************--
  741. --** ISRichTextPanel:new
  742. --**
  743. --************************************************************************--
  744. function ISRichTextPanel:new (x, y, width, height)
  745. local o = {}
  746. --o.data = {}
  747. o = ISPanel:new(x, y, width, height);
  748. setmetatable(o, self);
  749. self.__index = self;
  750. o.x = x;
  751. o.y = y;
  752. o.contentTransparency = 1.0;
  753. o.backgroundColor = {r=0, g=0, b=0, a=0.5};
  754. o.borderColor = {r=0, g=0, b=0, a=0.0};
  755. o.width = width;
  756. o.height = height;
  757. o.anchorLeft = true;
  758. o.anchorRight = false;
  759. o.anchorTop = true;
  760. o.anchorBottom = false;
  761. o.marginLeft = 20;
  762. o.marginTop = 10;
  763. o.marginRight = 10;
  764. o.marginBottom = 10;
  765. o.autosetheight = true;
  766. o.text = ""
  767. o.textDirty = false;
  768. o.textR = 1;
  769. o.textG = 1;
  770. o.textB = 1;
  771. o.clip = false
  772. o.maxLines = 0
  773. o.defaultFont = UIFont.NewSmall
  774. return o;
  775. end
Advertisement
Add Comment
Please, Sign In to add comment