guiDefaultControlRender.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. GFX->getDrawUtil()->drawRectFill( bounds, profile->mFillColor);
  39. GFX->getDrawUtil()->drawLine(l, t, l, b - 1, colorWhite);
  40. GFX->getDrawUtil()->drawLine(l, t, r - 1, t, colorWhite);
  41. GFX->getDrawUtil()->drawLine(l, b, r, b, colorBlack);
  42. GFX->getDrawUtil()->drawLine(r, b - 1, r, t, colorBlack);
  43. GFX->getDrawUtil()->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColor);
  44. GFX->getDrawUtil()->drawLine(r - 1, b - 2, r - 1, t + 1, profile->mBorderColor);
  45. }
  46. void renderSlightlyRaisedBox( const RectI &bounds, GuiControlProfile *profile )
  47. {
  48. S32 l = bounds.point.x + 1, r = bounds.point.x + bounds.extent.x - 1;
  49. S32 t = bounds.point.y + 1, b = bounds.point.y + bounds.extent.y - 1;
  50. GFXDrawUtil *drawer = GFX->getDrawUtil();
  51. drawer->drawRectFill( bounds, profile->mFillColor);
  52. drawer->drawLine(l, t, l, b, profile->mBorderColor);
  53. drawer->drawLine(l, t, r, t, profile->mBorderColor);
  54. drawer->drawLine(l + 1, b, r, b, profile->mBorderColor);
  55. drawer->drawLine(r, t + 1, r, b - 1, profile->mBorderColor);
  56. }
  57. void renderLoweredBox( const RectI &bounds, GuiControlProfile *profile )
  58. {
  59. S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x - 1;
  60. S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y - 1;
  61. GFX->getDrawUtil()->drawRectFill( bounds, profile->mFillColor);
  62. GFX->getDrawUtil()->drawLine(l, b, r, b, colorWhite);
  63. GFX->getDrawUtil()->drawLine(r, b - 1, r, t, colorWhite);
  64. GFX->getDrawUtil()->drawLine(l, t, r - 1, t, colorBlack);
  65. GFX->getDrawUtil()->drawLine(l, t + 1, l, b - 1, colorBlack);
  66. GFX->getDrawUtil()->drawLine(l + 1, t + 1, r - 2, t + 1, profile->mBorderColor);
  67. GFX->getDrawUtil()->drawLine(l + 1, t + 2, l + 1, b - 2, profile->mBorderColor);
  68. }
  69. void renderSlightlyLoweredBox( const RectI &bounds, GuiControlProfile *profile )
  70. {
  71. S32 l = bounds.point.x + 1, r = bounds.point.x + bounds.extent.x - 1;
  72. S32 t = bounds.point.y + 1, b = bounds.point.y + bounds.extent.y - 1;
  73. GFX->getDrawUtil()->drawRectFill( bounds, profile->mFillColor);
  74. GFX->getDrawUtil()->drawLine(l, b, r, b, profile->mBorderColor);
  75. GFX->getDrawUtil()->drawLine(r, t, r, b - 1, profile->mBorderColor);
  76. GFX->getDrawUtil()->drawLine(l, t, l, b - 1, profile->mBorderColor);
  77. GFX->getDrawUtil()->drawLine(l + 1, t, r - 1, t, profile->mBorderColor);
  78. }
  79. void renderBorder( const RectI &bounds, GuiControlProfile *profile )
  80. {
  81. S32 l = bounds.point.x, r = bounds.point.x + bounds.extent.x - 1;
  82. S32 t = bounds.point.y, b = bounds.point.y + bounds.extent.y - 1;
  83. GFXDrawUtil *drawer = GFX->getDrawUtil();
  84. switch(profile->mBorder)
  85. {
  86. case 1:
  87. drawer->drawRect(bounds, profile->mBorderColor);
  88. break;
  89. case 2:
  90. drawer->drawLine(l + 1, t + 1, l + 1, b - 2, profile->mBevelColorHL);
  91. drawer->drawLine(l + 2, t + 1, r - 2, t + 1, profile->mBevelColorHL);
  92. drawer->drawLine(r, t, r, b, profile->mBevelColorHL);
  93. drawer->drawLine(l, b, r - 1, b, profile->mBevelColorHL);
  94. drawer->drawLine(l, t, r - 1, t, profile->mBorderColorNA);
  95. drawer->drawLine(l, t + 1, l, b - 1, profile->mBorderColorNA);
  96. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColorNA);
  97. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mBorderColorNA);
  98. break;
  99. case 3:
  100. drawer->drawLine(l, b, r, b, profile->mBevelColorHL);
  101. drawer->drawLine(r, t, r, b - 1, profile->mBevelColorHL);
  102. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mFillColor);
  103. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mFillColor);
  104. drawer->drawLine(l, t, l, b - 1, profile->mBorderColorNA);
  105. drawer->drawLine(l + 1, t, r - 1, t, profile->mBorderColorNA);
  106. drawer->drawLine(l + 1, t + 1, l + 1, b - 2, profile->mBevelColorLL);
  107. drawer->drawLine(l + 2, t + 1, r - 2, t + 1, profile->mBevelColorLL);
  108. break;
  109. case 4:
  110. drawer->drawLine(l, t, l, b - 1, profile->mBevelColorHL);
  111. drawer->drawLine(l + 1, t, r, t, profile->mBevelColorHL);
  112. drawer->drawLine(l, b, r, b, profile->mBevelColorLL);
  113. drawer->drawLine(r, t + 1, r, b - 1, profile->mBevelColorLL);
  114. drawer->drawLine(l + 1, b - 1, r - 1, b - 1, profile->mBorderColor);
  115. drawer->drawLine(r - 1, t + 1, r - 1, b - 2, profile->mBorderColor);
  116. break;
  117. case 5:
  118. renderFilledBorder( bounds, profile );
  119. break;
  120. //
  121. case -1:
  122. // Draw a simple sizable border with corners
  123. // Taken from the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  124. if(profile->mBitmapArrayRects.size() >= 8)
  125. {
  126. drawer->clearBitmapModulation();
  127. RectI destRect;
  128. RectI stretchRect;
  129. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  130. // Indices into the bitmap array
  131. enum
  132. {
  133. BorderTopLeft = 0,
  134. BorderTop,
  135. BorderTopRight,
  136. BorderLeft,
  137. //Fill,
  138. BorderRight,
  139. BorderBottomLeft,
  140. BorderBottom,
  141. BorderBottomRight,
  142. NumBitmaps
  143. };
  144. // Draw all corners first.
  145. //top left border
  146. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[BorderTopLeft]);
  147. //top right border
  148. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x,bounds.point.y),mBitmapBounds[BorderTopRight]);
  149. //bottom left border
  150. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomLeft].extent.y),mBitmapBounds[BorderBottomLeft]);
  151. //bottom right border
  152. drawer->drawBitmapSR(profile->mTextureObject,Point2I(
  153. bounds.point.x + bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x,
  154. bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottomRight].extent.y),
  155. mBitmapBounds[BorderBottomRight]);
  156. // End drawing corners
  157. // Begin drawing sides and top stretched borders
  158. //start with top line stretch
  159. destRect.point.x = bounds.point.x + mBitmapBounds[BorderTopLeft].extent.x;
  160. destRect.extent.x = bounds.extent.x - mBitmapBounds[BorderTopRight].extent.x - mBitmapBounds[BorderTopLeft].extent.x;
  161. destRect.extent.y = mBitmapBounds[BorderTop].extent.y;
  162. destRect.point.y = bounds.point.y;
  163. //stretch it
  164. stretchRect = mBitmapBounds[BorderTop];
  165. stretchRect.inset(1,0);
  166. //draw it
  167. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  168. //bottom line stretch
  169. destRect.point.x = bounds.point.x + mBitmapBounds[BorderBottomLeft].extent.x;
  170. destRect.extent.x = bounds.extent.x - mBitmapBounds[BorderBottomRight].extent.x - mBitmapBounds[BorderBottomLeft].extent.x;
  171. destRect.extent.y = mBitmapBounds[BorderBottom].extent.y;
  172. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[BorderBottom].extent.y;
  173. //stretch it
  174. stretchRect = mBitmapBounds[BorderBottom];
  175. stretchRect.inset(1,0);
  176. //draw it
  177. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  178. //left line stretch
  179. destRect.point.x = bounds.point.x;
  180. destRect.extent.x = mBitmapBounds[BorderLeft].extent.x;
  181. destRect.extent.y = bounds.extent.y - mBitmapBounds[BorderTopLeft].extent.y - mBitmapBounds[BorderBottomLeft].extent.y;
  182. destRect.point.y = bounds.point.y + mBitmapBounds[BorderTopLeft].extent.y;
  183. //stretch it
  184. stretchRect = mBitmapBounds[BorderLeft];
  185. stretchRect.inset(0,1);
  186. //draw it
  187. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  188. //right line stretch
  189. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[BorderRight].extent.x;
  190. destRect.extent.x = mBitmapBounds[BorderRight].extent.x;
  191. destRect.extent.y = bounds.extent.y - mBitmapBounds[BorderTopRight].extent.y - mBitmapBounds[BorderBottomRight].extent.y;
  192. destRect.point.y = bounds.point.y + mBitmapBounds[BorderTopRight].extent.y;
  193. //stretch it
  194. stretchRect = mBitmapBounds[BorderRight];
  195. stretchRect.inset(0,1);
  196. //draw it
  197. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  198. // End drawing sides and top stretched borders
  199. break;
  200. }
  201. case -2:
  202. // Draw a simple sizable border with corners that is filled in
  203. renderSizableBitmapBordersFilled(bounds, 1, profile);
  204. break;
  205. case -3:
  206. // Draw a simple fixed height border with center fill horizontally.
  207. renderFixedBitmapBordersFilled( bounds, 1, profile );
  208. break;
  209. }
  210. }
  211. void renderFilledBorder( const RectI &bounds, GuiControlProfile *profile )
  212. {
  213. renderFilledBorder( bounds, profile->mBorderColor, profile->mFillColor, profile->mBorderThickness );
  214. }
  215. void renderFilledBorder( const RectI &bounds, const ColorI &borderColor, const ColorI &fillColor, U32 thickness )
  216. {
  217. RectI fillBounds = bounds;
  218. fillBounds.inset( thickness, thickness );
  219. GFX->getDrawUtil()->drawRectFill( bounds, borderColor );
  220. GFX->getDrawUtil()->drawRectFill( fillBounds, fillColor );
  221. }
  222. // Render out the sizable bitmap borders based on a multiplier into the bitmap array
  223. // Based on the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  224. void renderSizableBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, GuiControlProfile *profile)
  225. {
  226. // Indices into the bitmap array
  227. S32 numBitmaps = 9;
  228. S32 borderTopLeft = numBitmaps * baseMultiplier - numBitmaps;
  229. S32 borderTop = 1 + borderTopLeft;
  230. S32 borderTopRight = 2 + borderTopLeft;
  231. S32 borderLeft = 3 + borderTopLeft;
  232. S32 fill = 4 + borderTopLeft;
  233. S32 borderRight = 5 + borderTopLeft;
  234. S32 borderBottomLeft = 6 + borderTopLeft;
  235. S32 borderBottom = 7 + borderTopLeft;
  236. S32 borderBottomRight = 8 + borderTopLeft;
  237. GFXDrawUtil *drawer = GFX->getDrawUtil();
  238. drawer->clearBitmapModulation();
  239. if(profile->mBitmapArrayRects.size() >= (numBitmaps * baseMultiplier))
  240. {
  241. RectI destRect;
  242. RectI stretchRect;
  243. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  244. // Draw all corners first.
  245. //top left border
  246. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
  247. //top right border
  248. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
  249. //bottom left border
  250. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
  251. //bottom right border
  252. drawer->drawBitmapSR(profile->mTextureObject,Point2I(
  253. bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
  254. bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
  255. mBitmapBounds[borderBottomRight]);
  256. // End drawing corners
  257. // Begin drawing sides and top stretched borders
  258. //start with top line stretch
  259. destRect.point.x = bounds.point.x + mBitmapBounds[borderTopLeft].extent.x;
  260. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderTopRight].extent.x - mBitmapBounds[borderTopLeft].extent.x;
  261. destRect.extent.y = mBitmapBounds[borderTop].extent.y;
  262. destRect.point.y = bounds.point.y;
  263. //stretch it
  264. stretchRect = mBitmapBounds[borderTop];
  265. stretchRect.inset(1,0);
  266. //draw it
  267. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  268. //bottom line stretch
  269. destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
  270. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
  271. destRect.extent.y = mBitmapBounds[borderBottom].extent.y;
  272. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottom].extent.y;
  273. //stretch it
  274. stretchRect = mBitmapBounds[borderBottom];
  275. stretchRect.inset(1,0);
  276. //draw it
  277. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  278. //left line stretch
  279. destRect.point.x = bounds.point.x;
  280. destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
  281. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopLeft].extent.y - mBitmapBounds[borderBottomLeft].extent.y;
  282. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopLeft].extent.y;
  283. //stretch it
  284. stretchRect = mBitmapBounds[borderLeft];
  285. stretchRect.inset(0,1);
  286. //draw it
  287. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  288. //right line stretch
  289. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
  290. destRect.extent.x = mBitmapBounds[borderRight].extent.x;
  291. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopRight].extent.y - mBitmapBounds[borderBottomRight].extent.y;
  292. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopRight].extent.y;
  293. //stretch it
  294. stretchRect = mBitmapBounds[borderRight];
  295. stretchRect.inset(0,1);
  296. //draw it
  297. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  298. //fill stretch
  299. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  300. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  301. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTop].extent.y - mBitmapBounds[borderBottom].extent.y;
  302. destRect.point.y = bounds.point.y + mBitmapBounds[borderTop].extent.y;
  303. //stretch it
  304. stretchRect = mBitmapBounds[fill];
  305. stretchRect.inset(1,1);
  306. //draw it
  307. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  308. // End drawing sides and top stretched borders
  309. }
  310. }
  311. // Render out the sizable bitmap borders based on a multiplier into the bitmap array
  312. // Based on the 'Skinnable GUI Controls in TGE' resource by Justin DuJardin
  313. void renderSizableBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, GuiControlProfile *profile )
  314. {
  315. // Indices into the bitmap array
  316. S32 numBitmaps = 9;
  317. S32 borderTopLeft = startIndex;
  318. S32 borderTop = 1 + borderTopLeft;
  319. S32 borderTopRight = 2 + borderTopLeft;
  320. S32 borderLeft = 3 + borderTopLeft;
  321. S32 fill = 4 + borderTopLeft;
  322. S32 borderRight = 5 + borderTopLeft;
  323. S32 borderBottomLeft = 6 + borderTopLeft;
  324. S32 borderBottom = 7 + borderTopLeft;
  325. S32 borderBottomRight = 8 + borderTopLeft;
  326. GFXDrawUtil *drawer = GFX->getDrawUtil();
  327. drawer->clearBitmapModulation();
  328. if(profile->mBitmapArrayRects.size() >= (startIndex + numBitmaps))
  329. {
  330. RectI destRect;
  331. RectI stretchRect;
  332. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  333. // Draw all corners first.
  334. //top left border
  335. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderTopLeft]);
  336. //top right border
  337. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderTopRight].extent.x,bounds.point.y),mBitmapBounds[borderTopRight]);
  338. //bottom left border
  339. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomLeft].extent.y),mBitmapBounds[borderBottomLeft]);
  340. //bottom right border
  341. drawer->drawBitmapSR(profile->mTextureObject,Point2I(
  342. bounds.point.x + bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x,
  343. bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottomRight].extent.y),
  344. mBitmapBounds[borderBottomRight]);
  345. // End drawing corners
  346. // Begin drawing sides and top stretched borders
  347. //start with top line stretch
  348. destRect.point.x = bounds.point.x + mBitmapBounds[borderTopLeft].extent.x;
  349. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderTopRight].extent.x - mBitmapBounds[borderTopLeft].extent.x;
  350. destRect.extent.y = mBitmapBounds[borderTop].extent.y;
  351. destRect.point.y = bounds.point.y;
  352. //stretch it
  353. stretchRect = mBitmapBounds[borderTop];
  354. stretchRect.inset(1,0);
  355. //draw it
  356. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  357. //bottom line stretch
  358. destRect.point.x = bounds.point.x + mBitmapBounds[borderBottomLeft].extent.x;
  359. destRect.extent.x = bounds.extent.x - mBitmapBounds[borderBottomRight].extent.x - mBitmapBounds[borderBottomLeft].extent.x;
  360. destRect.extent.y = mBitmapBounds[borderBottom].extent.y;
  361. destRect.point.y = bounds.point.y + bounds.extent.y - mBitmapBounds[borderBottom].extent.y;
  362. //stretch it
  363. stretchRect = mBitmapBounds[borderBottom];
  364. stretchRect.inset(1,0);
  365. //draw it
  366. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  367. //left line stretch
  368. destRect.point.x = bounds.point.x;
  369. destRect.extent.x = mBitmapBounds[borderLeft].extent.x;
  370. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopLeft].extent.y - mBitmapBounds[borderBottomLeft].extent.y;
  371. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopLeft].extent.y;
  372. //stretch it
  373. stretchRect = mBitmapBounds[borderLeft];
  374. stretchRect.inset(0,1);
  375. //draw it
  376. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  377. //left line stretch
  378. destRect.point.x = bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x;
  379. destRect.extent.x = mBitmapBounds[borderRight].extent.x;
  380. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTopRight].extent.y - mBitmapBounds[borderBottomRight].extent.y;
  381. destRect.point.y = bounds.point.y + mBitmapBounds[borderTopRight].extent.y;
  382. //stretch it
  383. stretchRect = mBitmapBounds[borderRight];
  384. stretchRect.inset(0,1);
  385. //draw it
  386. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  387. //fill stretch
  388. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  389. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  390. destRect.extent.y = bounds.extent.y - mBitmapBounds[borderTop].extent.y - mBitmapBounds[borderBottom].extent.y;
  391. destRect.point.y = bounds.point.y + mBitmapBounds[borderTop].extent.y;
  392. //stretch it
  393. stretchRect = mBitmapBounds[fill];
  394. stretchRect.inset(1,1);
  395. //draw it
  396. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  397. // End drawing sides and top stretched borders
  398. }
  399. }
  400. // Render out the fixed bitmap borders based on a multiplier into the bitmap array
  401. // It renders left and right caps, with a sizable fill area in the middle to reach
  402. // the x extent. It does not stretch in the y direction.
  403. void renderFixedBitmapBordersFilled( const RectI &bounds, S32 baseMultiplier, GuiControlProfile *profile )
  404. {
  405. // Indices into the bitmap array
  406. S32 numBitmaps = 3;
  407. S32 borderLeft = numBitmaps * baseMultiplier - numBitmaps;
  408. S32 fill = 1 + borderLeft;
  409. S32 borderRight = 2 + borderLeft;
  410. GFXDrawUtil *drawer = GFX->getDrawUtil();
  411. drawer->clearBitmapModulation();
  412. if(profile->mBitmapArrayRects.size() >= (numBitmaps * baseMultiplier))
  413. {
  414. RectI destRect;
  415. RectI stretchRect;
  416. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  417. // Draw all corners first.
  418. //left border
  419. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
  420. //right border
  421. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
  422. // End drawing corners
  423. // Begin drawing fill
  424. //fill stretch
  425. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  426. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  427. destRect.extent.y = mBitmapBounds[fill].extent.y;
  428. destRect.point.y = bounds.point.y;
  429. //stretch it
  430. stretchRect = mBitmapBounds[fill];
  431. stretchRect.inset(1,0);
  432. //draw it
  433. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  434. // End drawing fill
  435. }
  436. }
  437. // Render out the fixed bitmap borders based on a multiplier into the bitmap array
  438. // It renders left and right caps, with a sizable fill area in the middle to reach
  439. // the x extent. It does not stretch in the y direction.
  440. void renderFixedBitmapBordersFilledIndex( const RectI &bounds, S32 startIndex, GuiControlProfile *profile )
  441. {
  442. // Indices into the bitmap array
  443. S32 numBitmaps = 3;
  444. S32 borderLeft = startIndex;
  445. S32 fill = 1 + startIndex;
  446. S32 borderRight = 2 + startIndex;
  447. GFXDrawUtil *drawer = GFX->getDrawUtil();
  448. drawer->clearBitmapModulation();
  449. if(profile->mBitmapArrayRects.size() >= (startIndex + numBitmaps))
  450. {
  451. RectI destRect;
  452. RectI stretchRect;
  453. RectI* mBitmapBounds = profile->mBitmapArrayRects.address();
  454. // Draw all corners first.
  455. //left border
  456. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x,bounds.point.y),mBitmapBounds[borderLeft]);
  457. //right border
  458. drawer->drawBitmapSR(profile->mTextureObject,Point2I(bounds.point.x + bounds.extent.x - mBitmapBounds[borderRight].extent.x,bounds.point.y),mBitmapBounds[borderRight]);
  459. // End drawing corners
  460. // Begin drawing fill
  461. //fill stretch
  462. destRect.point.x = bounds.point.x + mBitmapBounds[borderLeft].extent.x;
  463. destRect.extent.x = (bounds.extent.x) - mBitmapBounds[borderLeft].extent.x - mBitmapBounds[borderRight].extent.x;
  464. destRect.extent.y = mBitmapBounds[fill].extent.y;
  465. destRect.point.y = bounds.point.y;
  466. //stretch it
  467. stretchRect = mBitmapBounds[fill];
  468. stretchRect.inset(1,0);
  469. //draw it
  470. drawer->drawBitmapStretchSR(profile->mTextureObject,destRect,stretchRect);
  471. // End drawing fill
  472. }
  473. }