LCDDrawing.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "StdAfx.h"
  13. #include "LCDDrawing.h"
  14. static CTextureObject _toPointer;
  15. static CTextureObject _toBcgClouds;
  16. static CTextureObject _toBcgGrid;
  17. CDrawPort *_pdp = NULL;
  18. static PIX _pixSizeI;
  19. static PIX _pixSizeJ;
  20. static PIXaabbox2D _boxScreen;
  21. static FLOAT _tmNow;
  22. static ULONG _ulA;
  23. extern void LCDInit(void)
  24. {
  25. try {
  26. _toBcgClouds.SetData_t(CTFILENAME("Textures\\General\\Background6.tex"));
  27. _toBcgGrid.SetData_t(CTFILENAME("Textures\\General\\Grid16x16-dot.tex"));
  28. _toPointer.SetData_t(CTFILENAME("Textures\\General\\Pointer.tex"));
  29. } catch (char *strError) {
  30. FatalError("%s\n", strError);
  31. }
  32. }
  33. extern void LCDEnd(void)
  34. {
  35. _toBcgClouds.SetData(NULL);
  36. _toBcgGrid.SetData(NULL);
  37. _toPointer.SetData(NULL);
  38. }
  39. extern void LCDPrepare(FLOAT fFade)
  40. {
  41. // get current time and alpha value
  42. _tmNow = (FLOAT)_pTimer->GetHighPrecisionTimer().GetSeconds();
  43. _ulA = NormFloatToByte(fFade);
  44. }
  45. extern void LCDSetDrawport(CDrawPort *pdp)
  46. {
  47. _pdp = pdp;
  48. _pixSizeI = _pdp->GetWidth();
  49. _pixSizeJ = _pdp->GetHeight();
  50. _boxScreen = PIXaabbox2D ( PIX2D(0,0), PIX2D(_pixSizeI, _pixSizeJ));
  51. }
  52. void TiledTexture( PIXaabbox2D &_boxScreen, FLOAT fStretch, MEX2D &vScreen, MEXaabbox2D &boxTexture)
  53. {
  54. PIX pixW = _boxScreen.Size()(1);
  55. PIX pixH = _boxScreen.Size()(2);
  56. boxTexture = MEXaabbox2D(MEX2D(0, 0), MEX2D(pixW/fStretch, pixH/fStretch));
  57. boxTexture+=vScreen;
  58. }
  59. extern void LCDDrawBox(PIX pixUL, PIX pixDR, PIXaabbox2D &box, COLOR col)
  60. {
  61. // up
  62. _pdp->DrawLine(
  63. box.Min()(1)-pixUL, box.Min()(2)-pixUL,
  64. box.Max()(1)+pixDR, box.Min()(2)-pixUL, col);
  65. // down
  66. _pdp->DrawLine(
  67. box.Min()(1)-pixUL, box.Max()(2)+pixDR,
  68. box.Max()(1)+pixDR, box.Max()(2)+pixDR, col);
  69. // left
  70. _pdp->DrawLine(
  71. box.Min()(1)-pixUL, box.Min()(2)-pixUL,
  72. box.Min()(1)-pixUL, box.Max()(2)+pixDR, col);
  73. // right
  74. _pdp->DrawLine(
  75. box.Max()(1)+pixDR, box.Min()(2)-pixUL,
  76. box.Max()(1)+pixDR, box.Max()(2)+pixDR+1, col);
  77. }
  78. extern void LCDScreenBoxOpenLeft(COLOR col)
  79. {
  80. // up
  81. _pdp->DrawLine(
  82. _boxScreen.Min()(1)-1, _boxScreen.Min()(2),
  83. _boxScreen.Max()(1)-1, _boxScreen.Min()(2), col);
  84. // down
  85. _pdp->DrawLine(
  86. _boxScreen.Min()(1)-1, _boxScreen.Max()(2)-1,
  87. _boxScreen.Max()(1)-1, _boxScreen.Max()(2)-1, col);
  88. // right
  89. _pdp->DrawLine(
  90. _boxScreen.Max()(1)-1, _boxScreen.Min()(2),
  91. _boxScreen.Max()(1)-1, _boxScreen.Max()(2)-1+1, col);
  92. }
  93. extern void LCDScreenBoxOpenRight(COLOR col)
  94. {
  95. // up
  96. _pdp->DrawLine(
  97. _boxScreen.Min()(1)-1, _boxScreen.Min()(2),
  98. _boxScreen.Max()(1)-1, _boxScreen.Min()(2), col);
  99. // down
  100. _pdp->DrawLine(
  101. _boxScreen.Min()(1)-1, _boxScreen.Max()(2)-1,
  102. _boxScreen.Max()(1)-1, _boxScreen.Max()(2)-1, col);
  103. // left
  104. _pdp->DrawLine(
  105. _boxScreen.Min()(1), _boxScreen.Min()(2),
  106. _boxScreen.Min()(1), _boxScreen.Max()(2)-1+1, col);
  107. }
  108. extern void LCDScreenBox(COLOR col)
  109. {
  110. LCDDrawBox(0,-1, _boxScreen, col);
  111. }
  112. extern void LCDRenderClouds1(void)
  113. {
  114. MEXaabbox2D boxBcgClouds1;
  115. TiledTexture(_boxScreen, 1.3f*_pdp->GetWidth()/640.0f,
  116. MEX2D(sin(_tmNow*0.75f)*50,sin(_tmNow*0.9f)*40), boxBcgClouds1);
  117. _pdp->PutTexture(&_toBcgClouds, _boxScreen, boxBcgClouds1, C_dGREEN|_ulA>>1);
  118. TiledTexture(_boxScreen, 0.8f*_pdp->GetWidth()/640.0f,
  119. MEX2D(sin(_tmNow*0.95f)*50,sin(_tmNow*0.8f)*40), boxBcgClouds1);
  120. _pdp->PutTexture(&_toBcgClouds, _boxScreen, boxBcgClouds1, C_dGREEN|_ulA>>1);
  121. }
  122. extern void LCDRenderClouds2(void)
  123. {
  124. MEXaabbox2D boxBcgClouds2;
  125. TiledTexture(_boxScreen, 0.5f*_pdp->GetWidth()/640.0f,
  126. MEX2D(2,10), boxBcgClouds2);
  127. _pdp->PutTexture(&_toBcgClouds, _boxScreen, boxBcgClouds2, C_BLACK|(_ulA>>1));
  128. }
  129. extern void LCDRenderClouds2Light(void)
  130. {
  131. MEXaabbox2D boxBcgClouds2;
  132. TiledTexture(_boxScreen, 1.7f*_pdp->GetWidth()/640.0f,
  133. MEX2D(2,10), boxBcgClouds2);
  134. _pdp->PutTexture(&_toBcgClouds, _boxScreen, boxBcgClouds2, C_BLACK|(_ulA>>1));
  135. }
  136. extern void LCDRenderGrid(void)
  137. {
  138. MEXaabbox2D boxBcgGrid;
  139. TiledTexture(_boxScreen, 1.0f, MEX2D(0,0), boxBcgGrid);
  140. _pdp->PutTexture(&_toBcgGrid, _boxScreen, boxBcgGrid, C_dGREEN|_ulA);
  141. }
  142. /*
  143. extern void LCDRenderClouds1(void)
  144. {
  145. MEXaabbox2D boxBcgClouds1 = MEXaabbox2D(MEX2D(0,0), MEX2D(256,512));
  146. MEXaabbox2D boxBcgClouds2 = MEXaabbox2D(MEX2D(0,0), MEX2D(512,256));
  147. boxBcgClouds1 += MEX2D( sin(_tmNow*0.45f)*50, sin(_tmNow*0.65f)*40);
  148. boxBcgClouds2 += MEX2D( sin(_tmNow*0.55f)*50, sin(_tmNow*0.35f)*40);
  149. _pdp->PutTexture( &_toBcgClouds, _boxScreen, boxBcgClouds1, C_dGREEN|(_ulA>>1));
  150. _pdp->PutTexture( &_toBcgClouds, _boxScreen, boxBcgClouds2, C_dGREEN|(_ulA>>1));
  151. }
  152. extern void LCDRenderClouds2(void)
  153. {
  154. MEXaabbox2D boxBcgClouds = MEXaabbox2D(MEX2D(0,0), MEX2D(512,512));
  155. boxBcgClouds += MEX2D(2,10);
  156. _pdp->PutTexture( &_toBcgClouds, _boxScreen, boxBcgClouds, C_BLACK|(_ulA>>1));
  157. }
  158. extern void LCDRenderClouds2Light(void)
  159. {
  160. MEXaabbox2D boxBcgClouds2;
  161. TiledTexture( _boxScreen, 1.3f, MEX2D(2,10), boxBcgClouds2);
  162. _pdp->PutTexture( &_toBcgClouds, _boxScreen, boxBcgClouds2, C_BLACK|(_ulA>>1));
  163. }
  164. extern void LCDRenderGrid(void)
  165. {
  166. MEXaabbox2D boxBcgGrid;
  167. TiledTexture( _boxScreen, 1.0f, MEX2D(8,8), boxBcgGrid);
  168. _pdp->PutTexture( &_toBcgGrid, _boxScreen, boxBcgGrid, C_dGREEN|_ulA);
  169. }
  170. */
  171. extern COLOR LCDGetColor(COLOR colDefault, const char *strName)
  172. {
  173. return colDefault;//||((colDefault&0xFF0000)<<8);
  174. }
  175. extern COLOR LCDFadedColor(COLOR col)
  176. {
  177. return MulColors(C_WHITE|_ulA, col);
  178. }
  179. extern COLOR LCDBlinkingColor(COLOR col0, COLOR col1)
  180. {
  181. return LerpColor( col0, col1, sin(_tmNow*10.0f)*0.5f+0.5f);
  182. }
  183. extern void LCDDrawPointer(PIX pixI, PIX pixJ)
  184. {
  185. CDisplayMode dmCurrent;
  186. _pGfx->GetCurrentDisplayMode(dmCurrent);
  187. if (dmCurrent.IsFullScreen()) {
  188. while (ShowCursor(FALSE) >= 0);
  189. } else {
  190. if (!_pInput->IsInputEnabled()) {
  191. while (ShowCursor(TRUE) < 0);
  192. }
  193. return;
  194. }
  195. PIX pixSizeI = _toPointer.GetWidth();
  196. PIX pixSizeJ = _toPointer.GetHeight();
  197. pixI-=1;
  198. pixJ-=1;
  199. _pdp->PutTexture( &_toPointer, PIXaabbox2D( PIX2D(pixI, pixJ), PIX2D(pixI+pixSizeI, pixJ+pixSizeJ)),
  200. LCDFadedColor(C_WHITE|255));
  201. }