MCPcopy Create free account
hub / github.com/TankOs/SFGUI / CreatePane

Method CreatePane

src/SFGUI/Renderer.cpp:235–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235Primitive::Ptr Renderer::CreatePane( const sf::Vector2f& position, const sf::Vector2f& size, float border_width,
236 const sf::Color& color, const sf::Color& border_color, int border_color_shift ) {
237 if( border_width <= 0.f ) {
238 return CreateRect( position, position + size, color );
239 }
240
241 auto primitive = std::make_shared<Primitive>( 20 );
242
243 sf::Color dark_border( border_color );
244 sf::Color light_border( border_color );
245
246 Context::Get().GetEngine().ShiftBorderColors( light_border, dark_border, border_color_shift );
247
248 auto left = position.x;
249 auto top = position.y;
250 auto right = left + size.x;
251 auto bottom = top + size.y;
252
253 auto add_quad = [&primitive]( const sf::Vector2f& top_left, const sf::Vector2f& bottom_left,
254 const sf::Vector2f& bottom_right, const sf::Vector2f& top_right,
255 const sf::Color& quad_color ) {
256 PrimitiveVertex vertex0;
257 PrimitiveVertex vertex1;
258 PrimitiveVertex vertex2;
259 PrimitiveVertex vertex3;
260
261 vertex0.position = sf::Vector2f( std::floor( top_left.x + .5f ), std::floor( top_left.y + .5f ) );
262 vertex1.position = sf::Vector2f( std::floor( bottom_left.x + .5f ), std::floor( bottom_left.y + .5f ) );
263 vertex2.position = sf::Vector2f( std::floor( top_right.x + .5f ), std::floor( top_right.y + .5f ) );
264 vertex3.position = sf::Vector2f( std::floor( bottom_right.x + .5f ), std::floor( bottom_right.y + .5f ) );
265
266 vertex0.color = quad_color;
267 vertex1.color = quad_color;
268 vertex2.color = quad_color;
269 vertex3.color = quad_color;
270
271 vertex0.texture_coordinate = sf::Vector2f( 0.f, 0.f );
272 vertex1.texture_coordinate = sf::Vector2f( 0.f, 1.f );
273 vertex2.texture_coordinate = sf::Vector2f( 1.f, 0.f );
274 vertex3.texture_coordinate = sf::Vector2f( 1.f, 1.f );
275
276 primitive->AddVertex( vertex0 );
277 primitive->AddVertex( vertex1 );
278 primitive->AddVertex( vertex2 );
279 primitive->AddVertex( vertex2 );
280 primitive->AddVertex( vertex1 );
281 primitive->AddVertex( vertex3 );
282 };
283
284 auto add_line = [&add_quad]( const sf::Vector2f& begin, const sf::Vector2f& end, const sf::Color& line_color, float thickness ) {
285 sf::Vector2f normal( end - begin );
286 sf::Vector2f unrotated_normal( normal );
287 std::swap( normal.x, normal.y );
288 auto length = std::sqrt( normal.x * normal.x + normal.y * normal.y );
289
290 if( !( length > 0.f ) ) {
291 return;
292 }

Callers 12

CreateSliderMethod · 0.80
CreateStepperMethod · 0.80
CreateButtonDrawableMethod · 0.80
CreateWindowDrawableMethod · 0.80
CreateEntryDrawableMethod · 0.80
InvalidateImplMethod · 0.80

Calls 2

ShiftBorderColorsMethod · 0.80
AddVertexMethod · 0.80

Tested by

no test coverage detected