MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / DrawMenuBackground

Method DrawMenuBackground

PanzerChasm/menu_drawer_soft.cpp:138–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138void MenuDrawerSoft::DrawMenuBackground(
139 const int start_x, const int start_y,
140 const unsigned int width, const unsigned int height )
141{
142 const PaletteTransformed& palette= *rendering_context_.palette_transformed;
143 uint32_t* const dst_pixels= rendering_context_.window_surface_data;
144 const int dst_row_pixels= rendering_context_.row_pixels;
145
146 // TODO - rewrite this method.
147 // Use more fast tiles texturing. Accept tiles texture with any size, not only 64x64.
148 // Draw cool framing, like in MenuDrawerGL.
149
150 const Picture& pic= tiles_picture_;
151 PC_ASSERT( pic.size[0] == 64u && pic.size[1] == 64u );
152
153 const int start_x_corrected= start_x - int( MenuParams::menu_border ) * int(menu_scale_);
154 const int end_x= start_x_corrected + int(width ) + int( MenuParams::menu_border * 2u ) * int(menu_scale_);
155 const int start_y_corrected= start_y - int( MenuParams::menu_border + MenuParams::menu_caption ) * int(menu_scale_);
156 const int end_y= start_y_corrected + int(height) + int( MenuParams::menu_border * 2u + MenuParams::menu_caption ) * int(menu_scale_);
157
158 // Tone borders
159 const unsigned char c_low= 128u;
160 const unsigned char c_middle= 192u;
161 const unsigned char c_height= 255u;
162
163 for( int y= start_y_corrected; y < end_y; y++ )
164 {
165 PC_ASSERT( y >= 0 && y < int(rendering_context_.viewport_size.Height()) );
166
167 const int tc_y= y / int(menu_scale_);
168 const int tc_y_warped= tc_y & 63;
169
170 for( int x= start_x_corrected; x < end_x; x++ )
171 {
172 PC_ASSERT( x >= 0 && x < int(rendering_context_.viewport_size.Width()) );
173
174 const int tc_x= x / int(menu_scale_);
175 const int tc_x_warped= tc_x & 63;
176
177 unsigned char components[4];
178 std::memcpy( components, &palette[ pic.data[ tc_y_warped * 64 + tc_x_warped ] ], sizeof(uint32_t) );
179 for( unsigned int j= 0u; j < 3u; j++ )
180 components[j]= ( components[j] * c_middle ) >> 8u;
181 std::memcpy( &dst_pixels[ x + y * dst_row_pixels ], components, sizeof(uint32_t) );
182 }
183 }
184
185 const auto toned_texel_fetch=
186 [&]( const int x, const int y, const unsigned char tone ) -> uint32_t
187 {
188 PC_ASSERT( x >= 0 && y < int(rendering_context_.viewport_size.Width()) );
189 PC_ASSERT( y >= 0 && y < int(rendering_context_.viewport_size.Height()) );
190 const int tc_y= y / int(menu_scale_);
191 const int tc_y_warped= tc_y & 63;
192 const int tc_x= x / int(menu_scale_);
193 const int tc_x_warped= tc_x & 63;
194
195 unsigned char components[4];

Callers

nothing calls this directly

Calls 2

HeightMethod · 0.80
WidthMethod · 0.80

Tested by

no test coverage detected