Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[SFML 3.0] Ramka z podpisem

Ostatnio zmodyfikowano 2026-06-02 18:03
Autor Wiadomość
tBane
Temat założony przez niniejszego użytkownika
[SFML 3.0] Ramka z podpisem
» 2026-06-02 14:31:18
Cześć.
Nie żebym nie potrafił, ale szukam optymalnego sposobu na wyświetlenie w SFMLu ramki takiej jak na poniższej grafice.
Chodzi o to, żeby tło było przezroczyste.
ma ktoś jakiś pomysł jak to wygodnie napisać?

P-184161
tBane
Temat założony przez niniejszego użytkownika
» 2026-06-02 15:32:33
C/C++
void drawFrame() {
   
   
int x, y, w, h;
   
   
x = 128;
   
y = 128;
   
w = 256;
   
h = 256;
   
   
float thickness = 4.f;
   
float paddingLeft = 14.f;
   
float textPadding = 6.f;
   
   
sf::Color color = sf::Color( 255, 30, 45 );
   
   
sf::Text text( basicFont, _prefab->getName(), 14 );
   
text.setFillColor( color );
   
text.setStyle( sf::Text::Bold );
   
text.setPosition( sf::Vector2f( x + paddingLeft, y - 10 ) );
   
   
auto bounds = text.getLocalBounds();
   
   
float gapStart = paddingLeft - textPadding;
   
float gapEnd = paddingLeft + bounds.size.x + textPadding;
   
   
sf::RectangleShape topLeft( sf::Vector2f( gapStart, thickness ) );
   
topLeft.setPosition( sf::Vector2f( x, y ) );
   
topLeft.setFillColor( color );
   
   
sf::RectangleShape topRight( sf::Vector2f( w - gapEnd, thickness ) );
   
topRight.setPosition( sf::Vector2f( x + gapEnd, y ) );
   
topRight.setFillColor( color );
   
   
sf::RectangleShape left( sf::Vector2f( thickness, h ) );
   
left.setPosition( sf::Vector2f( x, y ) );
   
left.setFillColor( color );
   
   
sf::RectangleShape right( sf::Vector2f( thickness, h ) );
   
right.setPosition( sf::Vector2f( x + w - thickness, y ) );
   
right.setFillColor( color );
   
   
sf::RectangleShape bottom( sf::Vector2f( w, thickness ) );
   
bottom.setPosition( sf::Vector2f( x, y + h - thickness ) );
   
bottom.setFillColor( color );
   
   
window->draw( topLeft );
   
window->draw( topRight );
   
window->draw( left );
   
window->draw( right );
   
window->draw( bottom );
   
window->draw( text );
}
}
P-184162
« 1 »
  Strona 1 z 1