ColorUtils.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //////////////////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Utils.cpp
  21. //
  22. //
  23. #include "StdAfx.H"
  24. #include "ColorUtils.H"
  25. /////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Draw_Sunken_Rect
  28. //
  29. void
  30. Draw_Sunken_Rect
  31. (
  32. UCHAR *pbits,
  33. const RECT &rect,
  34. int scanline_size
  35. )
  36. {
  37. int width = rect.right - rect.left;
  38. int height = rect.bottom - rect.top;
  39. // Draw the 4 lines that compose the rectangle
  40. ::Draw_Vert_Line (pbits, rect.left, rect.top, height, ::GetSysColor (COLOR_3DSHADOW), scanline_size);
  41. ::Draw_Vert_Line (pbits, rect.right-1, rect.top, height, ::GetSysColor (COLOR_3DHIGHLIGHT), scanline_size);
  42. ::Draw_Horz_Line (pbits, rect.left, rect.top, width, ::GetSysColor (COLOR_3DSHADOW), scanline_size);
  43. ::Draw_Horz_Line (pbits, rect.left, rect.bottom-1, width, ::GetSysColor (COLOR_3DHIGHLIGHT), scanline_size);
  44. return ;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. //
  48. // Draw_Raised_Rect
  49. //
  50. void
  51. Draw_Raised_Rect
  52. (
  53. UCHAR *pbits,
  54. const RECT &rect,
  55. int scanline_size
  56. )
  57. {
  58. int width = rect.right - rect.left;
  59. int height = rect.bottom - rect.top;
  60. // Draw the 4 lines that compose the rectangle
  61. ::Draw_Vert_Line (pbits, rect.left, rect.top, height, ::GetSysColor (COLOR_3DHIGHLIGHT), scanline_size);
  62. ::Draw_Vert_Line (pbits, rect.right-1, rect.top, height, ::GetSysColor (COLOR_3DSHADOW), scanline_size);
  63. ::Draw_Horz_Line (pbits, rect.left, rect.top, width, ::GetSysColor (COLOR_3DHIGHLIGHT), scanline_size);
  64. ::Draw_Horz_Line (pbits, rect.left, rect.bottom-1, width, ::GetSysColor (COLOR_3DSHADOW), scanline_size);
  65. return ;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. //
  69. // Frame_Rect
  70. //
  71. void
  72. Frame_Rect
  73. (
  74. UCHAR *pbits,
  75. const RECT &rect,
  76. COLORREF color,
  77. int scanline_size
  78. )
  79. {
  80. UCHAR red = GetRValue (color);
  81. UCHAR green = GetRValue (color);
  82. UCHAR blue = GetRValue (color);
  83. int index = (rect.top * scanline_size) + (rect.left * 3);
  84. for (int col = rect.left; col < rect.right; col ++) {
  85. pbits[index++] = blue;
  86. pbits[index++] = green;
  87. pbits[index++] = red;
  88. }
  89. index = ((rect.bottom-1) * scanline_size) + (rect.left * 3);
  90. for (col = rect.left; col < rect.right; col ++) {
  91. pbits[index++] = blue;
  92. pbits[index++] = green;
  93. pbits[index++] = red;
  94. }
  95. index = (rect.top * scanline_size) + (rect.left * 3);
  96. for (int row = rect.top; row < rect.bottom; row ++) {
  97. pbits[index] = blue;
  98. pbits[index + 1] = green;
  99. pbits[index + 2] = red;
  100. index += scanline_size;
  101. }
  102. index = (rect.top * scanline_size) + ((rect.right-1) * 3);
  103. for (row = rect.top; row < rect.bottom; row ++) {
  104. pbits[index] = blue;
  105. pbits[index + 1] = green;
  106. pbits[index + 2] = red;
  107. index += scanline_size;
  108. }
  109. return ;
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. //
  113. // Draw_Vert_Line
  114. //
  115. void
  116. Draw_Vert_Line
  117. (
  118. UCHAR *pbits,
  119. int x,
  120. int y,
  121. int len,
  122. COLORREF color,
  123. int scanline_size
  124. )
  125. {
  126. UCHAR red = GetRValue (color);
  127. UCHAR green = GetRValue (color);
  128. UCHAR blue = GetRValue (color);
  129. int index = (y * scanline_size) + (x * 3);
  130. for (int row = y; row < len; row ++) {
  131. pbits[index] = blue;
  132. pbits[index + 1] = green;
  133. pbits[index + 2] = red;
  134. index += scanline_size;
  135. }
  136. return ;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. //
  140. // Draw_Horz_Line
  141. //
  142. void
  143. Draw_Horz_Line
  144. (
  145. UCHAR *pbits,
  146. int x,
  147. int y,
  148. int len,
  149. COLORREF color,
  150. int scanline_size
  151. )
  152. {
  153. UCHAR red = GetRValue (color);
  154. UCHAR green = GetRValue (color);
  155. UCHAR blue = GetRValue (color);
  156. int index = (y * scanline_size) + (x * 3);
  157. for (int col = x; col < len; col ++) {
  158. pbits[index++] = blue;
  159. pbits[index++] = green;
  160. pbits[index++] = red;
  161. }
  162. return ;
  163. }