guiDefaultControlRender.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gui/core/guiDefaultControlRender.h"
  24. #include "gui/core/guiTypes.h"
  25. #include "core/color.h"
  26. #include "math/mRect.h"
  27. #include "gfx/gfxDevice.h"
  28. #include "gfx/gfxDrawUtil.h"
  29. static ColorI colorLightGray(192, 192, 192);
  30. static ColorI colorGray(128, 128, 128);
  31. static ColorI colorDarkGray(64, 64, 64);
  32. static ColorI colorWhite(255,255,255);
  33. static ColorI colorBlack(0,0,0);
  34. void renderRaisedBox( const RectI &bounds, GuiControlProfile *profile )
  35. {
  36. S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x - 1;
  37. S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y - 1;
  38. GFXDrawUtil* drawUtil = GFX->getDrawUtil();
  39. drawUtil->drawRectFill( bounds, profile->mFillColor);
  40. drawUtil->drawLine(l, t, l, b - 1, colorWhite);
  41. drawUtil->drawLine(l, t, r - 1, t, colorWhite);
  42. drawUtil->drawLine(l, b, r, b, colorBlack);
  43. drawUtil->drawLine(r, b - 1, r, t, colorBlack);
  44. drawUtil->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColor);
  45. drawUtil->drawLine(r - 1, b - 2, r - 1, t + 1, profile->mBorderColor);
  46. }
  47. void renderSlightlyRaisedBox( const RectI &bounds, GuiControlProfile *profile )
  48. {
  49. S32 l = bounds.point.x + 1, r = bounds.point.x + bounds.extent.x - 1;
  50. S32 t = bounds.point.y + 1, b = bounds.point.y + bounds.extent.y - 1;
  51. GFXDrawUtil *drawer = GFX->getDrawUtil();
  52. drawer->drawRectFill( bounds, profile->mFillColor);
  53. drawer->drawLine(l, t, l, b, profile->mBorderColor);
  54. drawer->drawLine(l, t, r, t, profile->mBorderColor);
  55. drawer->drawLine(l + 1, b, r, b, profile->mBorderColor);
  56. drawer->drawLine(r, t + 1, r, b - 1, profile->mBorderColor);
  57. }
  58. void renderLoweredBox( const RectI &bounds, GuiControlProfile *profile )
  59. {
  60. S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x - 1;
  61. S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y - 1;
  62. GFXDrawUtil* drawUtil = GFX->getDrawUtil();
  63. drawUtil->drawRectFill( bounds, profile->mFillColor);
  64. drawUtil->drawLine(l, b, r, b, colorWhite);
  65. drawUtil->drawLine(r, b - 1, r, t, colorWhite);
  66. drawUtil->drawLine(l, t, r - 1, t, colorBlack);
  67. drawUtil->drawLine(l, t + 1, l, b - 1, colorBlack);
  68. drawUtil->drawLine(l + 1, t + 1, r - 2, t + 1, profile->mBorderColor);
  69. drawUtil->drawLine(l + 1, t + 2, l + 1, b - 2, profile->mBorderColor);
  70. }
  71. void renderSlightlyLoweredBox( const RectI &bounds, GuiControlProfile *profile )
  72. {
  73. S32 l = bounds.point.x + 1, r = bounds.point.x + bounds.extent.x - 1;
  74. S32 t = bounds.point.y + 1, b = bounds.point.y + bounds.extent.y - 1;
  75. GFXDrawUtil* drawUtil = GFX->getDrawUtil();
  76. drawUtil->drawRectFill( bounds, profile->mFillColor);
  77. drawUtil->drawLine(l, b, r, b, profile->mBorderColor);
  78. drawUtil->drawLine(r, t, r, b - 1, profile->mBorderColor);
  79. drawUtil->drawLine(l, t, l, b - 1, profile->mBorderColor);
  80. drawUtil->drawLine(l + 1, t, r - 1, t, profile->mBorderColor);
  81. }
  82. void renderBorder( const RectI &bounds, GuiControlProfile *profile )
  83. {
  84. S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x - 1;
  85. S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y - 1;
  86. GFXDrawUtil *drawer = GFX->getDrawUtil();
  87. switch(profile->mBorder)
  88. {
  89. case 1:
  90. drawer->drawRect(bounds, profile->mBorderColor);
  91. break;
  92. case 2:
  93. drawer->drawLine(l + 1, t + 1, l + 1, b - 2, profile->mBevelColorHL);
  94. drawer->drawLine(l + 2, t + 1, r - 2, t + 1, profile->mBevelColorHL);
  95. drawer->drawLine(r, t, r, b, profile->mBevelColorHL);
  96. drawer->drawLine(l, b, r - 1, b, profile->mBevelColorHL);
  97. drawer->drawLine(l, t, r - 1, t, profile->mBorderColorNA);
  98. drawer->drawLine(l, t + 1, l, b - 1, profile->mBorderColorNA);
  99. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColorNA);
  100. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mBorderColorNA);
  101. break;
  102. case 3:
  103. drawer->drawLine(l, b, r, b, profile->mBevelColorHL);
  104. drawer->drawLine(r, t, r, b - 1, profile->mBevelColorHL);
  105. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mFillColor);
  106. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mFillColor);
  107. drawer->drawLine(l, t, l, b - 1, profile->mBorderColorNA);
  108. drawer->drawLine(l + 1, t, r - 1, t, profile->mBorderColorNA);
  109. drawer->drawLine(l + 1, t + 1, l + 1, b - 2, profile->mBevelColorLL);
  110. drawer->drawLine(l + 2, t + 1, r - 2, t + 1, profile->mBevelColorLL);
  111. break;
  112. case 4:
  113. drawer->drawLine(l, t, l, b - 1, profile->mBevelColorHL);
  114. drawer->drawLine(l + 1, t, r, t, profile->mBevelColorHL);
  115. drawer->drawLine(l, b, r, b, profile->mBevelColorLL);
  116. drawer->drawLine(r, t + 1, r, b - 1, profile->mBevelColorLL);
  117. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColor);
  118. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mBorderColor);
  119. break;
  120. case 5:
  121. renderFilledBorder( bounds, profile );
  122. break;
  123. //
  124. case -1:
  125. // Draw a simple sizable border with corners
  126. // Taken from the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  127. if(profile->mBitmapArrayRects.size() >= 8)
  128. {
  129. drawer->clearBitmapModulation();
  130. RectI destRect;
  131. RectI stretchRect;
  132. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  133. // Indices into the bitmap array
  134. enum
  135. {
  136. BorderTopLeft = 0,
  137. BorderTop,
  138. BorderTopRight,
  139. BorderLeft,
  140. //Fill,
  141. BorderRight,
  142. BorderBottomLeft,
  143. BorderBottom,
  144. BorderBottomRight,
  145. NumBitmaps
  146. };
  147. // Draw all corners first.
  148. //top left border
  149. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[BorderTopLeft]);
  150. //top right border
  151. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x,bounds.point.y),mBitmapBounds[BorderTopRight]);
  152. //bottom left border
  153. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomLeft].extent.y),mBitmapBounds[BorderBottomLeft]);
  154. //bottom right border
  155. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
  156. bounds.point.x + bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x,
  157. bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomRight].extent.y),
  158. mBitmapBounds[BorderBottomRight]);
  159. // End drawing corners
  160. // Begin drawing sides and top stretched borders
  161. //start with top line stretch
  162. destRect.point.x = bounds.point.x + mBitmapBounds[BorderTopLeft].extent.x;
  163. destRect.extent.x = bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x - mBitmapBounds[BorderTopLeft].extent.x;
  164. destRect.extent.y = mBitmapBounds[BorderTop].extent.y;
  165. destRect.point.y = bounds.point.y;
  166. //stretch it
  167. stretchRect = mBitmapBounds[BorderTop];
  168. stretchRect.inset(1,0);
  169. //draw it
  170. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  171. //bottom line stretch
  172. destRect.point.x = bounds.point.x + mBitmapBounds[BorderBottomLeft].extent.x;
  173. destRect.extent.x = bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x - mBitmapBounds[BorderBottomLeft].extent.x;
  174. destRect.extent.y = mBitmapBounds[BorderBottom].extent.y;
  175. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottom].extent.y;
  176. //stretch it
  177. stretchRect = mBitmapBounds[BorderBottom];
  178. stretchRect.inset(1,0);
  179. //draw it
  180. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  181. //left line stretch
  182. destRect.point.x = bounds.point.x;
  183. destRect.extent.x = mBitmapBounds[BorderLeft].extent.x;
  184. destRect.extent.y = bounds.extent.y - mBitmapBounds[BorderTopLeft].extent.y - mBitmapBounds[BorderBottomLeft].extent.y;
  185. destRect.point.y = bounds.point.y + mBitmapBounds[BorderTopLeft].extent.y;
  186. //stretch it
  187. stretchRect = mBitmapBounds[BorderLeft];
  188. stretchRect.inset(0,1);
  189. //draw it
  190. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  191. //right line stretch
  192. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[BorderRight].extent.x;
  193. destRect.extent.x = mBitmapBounds[BorderRight].extent.x;
  194. destRect.extent.y = bounds.extent.y - mBitmapBounds[BorderTopRight].extent.y - mBitmapBounds[BorderBottomRight].extent.y;
  195. destRect.point.y = bounds.point.y + mBitmapBounds[BorderTopRight].extent.y;
  196. //stretch it
  197. stretchRect = mBitmapBounds[BorderRight];
  198. stretchRect.inset(0,1);
  199. //draw it
  200. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  201. // End drawing sides and top stretched borders
  202. break;
  203. }
  204. case -2:
  205. // Draw a simple sizable border with corners that is filled in
  206. renderSizableBitmapBordersFilled(bounds, 1, profile);
  207. break;
  208. case -3:
  209. // Draw a simple fixed height border with center fill horizontally.
  210. renderFixedBitmapBordersFilled( bounds, 1, profile );
  211. break;
  212. }
  213. }
  214. void renderFilledBorder( const RectI &bounds, GuiControlProfile *profile )
  215. {
  216. renderFilledBorder( bounds, profile->mBorderColor, profile->mFillColor, profile->mBorderThickness );
  217. }
  218. void renderFilledBorder( const RectI &bounds, const ColorI &borderColor, const ColorI &fillColor, U32 thickness )
  219. {
  220. RectI fillBounds = bounds;
  221. fillBounds.inset( thickness, thickness );
  222. GFX->getDrawUtil()->drawRectFill( bounds, borderColor );
  223. GFX->getDrawUtil()->drawRectFill( fillBounds, fillColor );
  224. }
  225. // Render out the sizable bitmap borders based on a multiplier into the bitmap array
  226. // Based on the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  227. void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, GuiControlProfile *profile)
  228. {
  229. // Indices into the bitmap array
  230. S32 numBitmaps = 9;
  231. S32 borderTopLeft = numBitmaps * baseMultiplier - numBitmaps;
  232. S32 borderTop = 1 + borderTopLeft;
  233. S32 borderTopRight = 2 + borderTopLeft;
  234. S32 borderLeft = 3 + borderTopLeft;
  235. S32 fill = 4 + borderTopLeft;
  236. S32 borderRight = 5 + borderTopLeft;
  237. S32 borderBottomLeft = 6 + borderTopLeft;
  238. S32 borderBottom = 7 + borderTopLeft;
  239. S32 borderBottomRight = 8 + borderTopLeft;
  240. GFXDrawUtil *drawer = GFX->getDrawUtil();
  241. drawer->clearBitmapModulation();
  242. if(profile->mBitmapArrayRects.size() >= (numBitmaps * baseMultiplier))
  243. {
  244. RectI destRect;
  245. RectI stretchRect;
  246. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  247. // Draw all corners first.
  248. //top left border
  249. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
  250. //top right border
  251. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
  252. //bottom left border
  253. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
  254. //bottom right border
  255. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
  256. bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
  257. bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
  258. mBitmapBounds[borderBottomRight]);
  259. // End drawing corners
  260. // Begin drawing sides and top stretched borders
  261. //start with top line stretch
  262. destRect.point.x = bounds.point.x + mBitmapBounds[borderTopLeft].extent.x;
  263. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderTopRight].extent.x - mBitmapBounds[borderTopLeft].extent.x;
  264. destRect.extent.y = mBitmapBounds[borderTop].extent.y;
  265. destRect.point.y = bounds.point.y;
  266. //stretch it
  267. stretchRect = mBitmapBounds[borderTop];
  268. stretchRect.inset(1,0);
  269. //draw it
  270. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  271. //bottom line stretch
  272. destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
  273. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
  274. destRect.extent.y = mBitmapBounds[borderBottom].extent.y;
  275. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottom].extent.y;
  276. //stretch it
  277. stretchRect = mBitmapBounds[borderBottom];
  278. stretchRect.inset(1,0);
  279. //draw it
  280. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  281. //left line stretch
  282. destRect.point.x = bounds.point.x;
  283. destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
  284. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopLeft].extent.y - mBitmapBounds[borderBottomLeft].extent.y;
  285. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopLeft].extent.y;
  286. //stretch it
  287. stretchRect = mBitmapBounds[borderLeft];
  288. stretchRect.inset(0,1);
  289. //draw it
  290. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  291. //right line stretch
  292. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
  293. destRect.extent.x = mBitmapBounds[borderRight].extent.x;
  294. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopRight].extent.y - mBitmapBounds[borderBottomRight].extent.y;
  295. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopRight].extent.y;
  296. //stretch it
  297. stretchRect = mBitmapBounds[borderRight];
  298. stretchRect.inset(0,1);
  299. //draw it
  300. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  301. //fill stretch
  302. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  303. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  304. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTop].extent.y - mBitmapBounds[borderBottom].extent.y;
  305. destRect.point.y = bounds.point.y + mBitmapBounds[borderTop].extent.y;
  306. //stretch it
  307. stretchRect = mBitmapBounds[fill];
  308. stretchRect.inset(1,1);
  309. //draw it
  310. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  311. // End drawing sides and top stretched borders
  312. }
  313. }
  314. // Render out the sizable bitmap borders based on a multiplier into the bitmap array
  315. // Based on the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  316. void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, GuiControlProfile *profile )
  317. {
  318. // Indices into the bitmap array
  319. S32 numBitmaps = 9;
  320. S32 borderTopLeft = startIndex;
  321. S32 borderTop = 1 + borderTopLeft;
  322. S32 borderTopRight = 2 + borderTopLeft;
  323. S32 borderLeft = 3 + borderTopLeft;
  324. S32 fill = 4 + borderTopLeft;
  325. S32 borderRight = 5 + borderTopLeft;
  326. S32 borderBottomLeft = 6 + borderTopLeft;
  327. S32 borderBottom = 7 + borderTopLeft;
  328. S32 borderBottomRight = 8 + borderTopLeft;
  329. GFXDrawUtil *drawer = GFX->getDrawUtil();
  330. drawer->clearBitmapModulation();
  331. if(profile->mBitmapArrayRects.size() >= (startIndex + numBitmaps))
  332. {
  333. RectI destRect;
  334. RectI stretchRect;
  335. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  336. // Draw all corners first.
  337. //top left border
  338. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
  339. //top right border
  340. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
  341. //bottom left border
  342. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
  343. //bottom right border
  344. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(
  345. bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
  346. bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
  347. mBitmapBounds[borderBottomRight]);
  348. // End drawing corners
  349. // Begin drawing sides and top stretched borders
  350. //start with top line stretch
  351. destRect.point.x = bounds.point.x + mBitmapBounds[borderTopLeft].extent.x;
  352. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderTopRight].extent.x - mBitmapBounds[borderTopLeft].extent.x;
  353. destRect.extent.y = mBitmapBounds[borderTop].extent.y;
  354. destRect.point.y = bounds.point.y;
  355. //stretch it
  356. stretchRect = mBitmapBounds[borderTop];
  357. stretchRect.inset(1,0);
  358. //draw it
  359. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  360. //bottom line stretch
  361. destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
  362. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
  363. destRect.extent.y = mBitmapBounds[borderBottom].extent.y;
  364. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottom].extent.y;
  365. //stretch it
  366. stretchRect = mBitmapBounds[borderBottom];
  367. stretchRect.inset(1,0);
  368. //draw it
  369. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  370. //left line stretch
  371. destRect.point.x = bounds.point.x;
  372. destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
  373. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopLeft].extent.y - mBitmapBounds[borderBottomLeft].extent.y;
  374. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopLeft].extent.y;
  375. //stretch it
  376. stretchRect = mBitmapBounds[borderLeft];
  377. stretchRect.inset(0,1);
  378. //draw it
  379. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  380. //left line stretch
  381. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
  382. destRect.extent.x = mBitmapBounds[borderRight].extent.x;
  383. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopRight].extent.y - mBitmapBounds[borderBottomRight].extent.y;
  384. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopRight].extent.y;
  385. //stretch it
  386. stretchRect = mBitmapBounds[borderRight];
  387. stretchRect.inset(0,1);
  388. //draw it
  389. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  390. //fill stretch
  391. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  392. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  393. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTop].extent.y - mBitmapBounds[borderBottom].extent.y;
  394. destRect.point.y = bounds.point.y + mBitmapBounds[borderTop].extent.y;
  395. //stretch it
  396. stretchRect = mBitmapBounds[fill];
  397. stretchRect.inset(1,1);
  398. //draw it
  399. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  400. // End drawing sides and top stretched borders
  401. }
  402. }
  403. // Render out the fixed bitmap borders based on a multiplier into the bitmap array
  404. // It renders left and right caps, with a sizable fill area in the middle to reach
  405. // the x extent. It does not stretch in the y direction.
  406. void renderFixedBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, GuiControlProfile *profile )
  407. {
  408. // Indices into the bitmap array
  409. S32 numBitmaps = 3;
  410. S32 borderLeft = numBitmaps * baseMultiplier - numBitmaps;
  411. S32 fill = 1 + borderLeft;
  412. S32 borderRight = 2 + borderLeft;
  413. GFXDrawUtil *drawer = GFX->getDrawUtil();
  414. drawer->clearBitmapModulation();
  415. if(profile->mBitmapArrayRects.size() >= (numBitmaps * baseMultiplier))
  416. {
  417. RectI destRect;
  418. RectI stretchRect;
  419. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  420. // Draw all corners first.
  421. //left border
  422. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
  423. //right border
  424. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
  425. // End drawing corners
  426. // Begin drawing fill
  427. //fill stretch
  428. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  429. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  430. destRect.extent.y = mBitmapBounds[fill].extent.y;
  431. destRect.point.y = bounds.point.y;
  432. //stretch it
  433. stretchRect = mBitmapBounds[fill];
  434. stretchRect.inset(1,0);
  435. //draw it
  436. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  437. // End drawing fill
  438. }
  439. }
  440. // Render out the fixed bitmap borders based on a multiplier into the bitmap array
  441. // It renders left and right caps, with a sizable fill area in the middle to reach
  442. // the x extent. It does not stretch in the y direction.
  443. void renderFixedBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, GuiControlProfile *profile )
  444. {
  445. // Indices into the bitmap array
  446. S32 numBitmaps = 3;
  447. S32 borderLeft = startIndex;
  448. S32 fill = 1 + startIndex;
  449. S32 borderRight = 2 + startIndex;
  450. GFXDrawUtil *drawer = GFX->getDrawUtil();
  451. drawer->clearBitmapModulation();
  452. if(profile->mBitmapArrayRects.size() >= (startIndex + numBitmaps))
  453. {
  454. RectI destRect;
  455. RectI stretchRect;
  456. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  457. // Draw all corners first.
  458. //left border
  459. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
  460. //right border
  461. drawer->drawBitmapSR(profile->getBitmapResource(),Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
  462. // End drawing corners
  463. // Begin drawing fill
  464. //fill stretch
  465. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  466. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  467. destRect.extent.y = mBitmapBounds[fill].extent.y;
  468. destRect.point.y = bounds.point.y;
  469. //stretch it
  470. stretchRect = mBitmapBounds[fill];
  471. stretchRect.inset(1,0);
  472. //draw it
  473. drawer->drawBitmapStretchSR(profile->getBitmapResource(),destRect,stretchRect);
  474. // End drawing fill
  475. }
  476. }