Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Creating custom buttons  (Read 2816 times)

0 Members and 1 Guest are viewing this topic.

Favor98

  • Newbie
  • *
  • Posts: 4
    • View Profile
Creating custom buttons
« on: May 22, 2014, 02:05:10 pm »
I'm completely new to sfml and I'd like to know how you guys manage to create and display custom made images for buttons/menus and such.

I've seen this thread: http://en.sfml-dev.org/forums/index.php?topic=3265.0
and I'd like to know how to create, save and load the custom made texture.

I created a simple texture for test in PS, without background, only text and if I save it as .bmp it doesn't display anything when I load it but if I flatten layers then it displays the text with white background. How can I make it to display the text alone.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Creating custom buttons
« Reply #1 on: May 22, 2014, 02:10:20 pm »
Export in a format that supports transparency, for example PNG.
Laurent Gomila - SFML developer

Favor98

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating custom buttons
« Reply #2 on: May 22, 2014, 02:25:41 pm »
Ok I managed to save it but now my program exits when I try to load it from file.

Texture NewGame;
      if (!NewGame.loadFromFile("Images/NewGame2.png"))
         return -1;
      S_newgame.setTexture(NewGame);
      window.draw(S_newgame);

Favor98

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating custom buttons
« Reply #3 on: May 22, 2014, 02:31:51 pm »
Nvm I fixed it, seems like sfml only supports 8bit PNGs....only 1 thing I'd like to know....if I want to create an effect that when I mouse over text, should I make it in a way that if the event when mouse is over it to change the image, ofc then I need to create another image just with aditional effects.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Creating custom buttons
« Reply #4 on: May 22, 2014, 02:39:41 pm »
Quote
Nvm I fixed it, seems like sfml only supports 8bit PNGs
SFML does not support 8-bit PNG.

Quote
only 1 thing I'd like to know....if I want to create an effect that when I mouse over text, should I make it in a way that if the event when mouse is over it to change the image, ofc then I need to create another image just with aditional effects.
Yes. Or put both in the same texture, and just change the sprite's textureRect.
Laurent Gomila - SFML developer

Favor98

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating custom buttons
« Reply #5 on: May 22, 2014, 07:06:21 pm »
Right so I created 1 texture with 2 images, I managed to use SetTextureRect but I got little issues with mouse settings now. I used

if (event.type == Event::MouseMoved)
         {
            mouse_poz = Mouse::getPosition();

mouse_poz is of Vector2i type. Now how do I get bounds of the texture, I know I got 2 functions for it but what's this FloatRect I just don't know how to store the values in a variable :(

if I set position like if(mouse_poz.x > 0 && mouse_poz.x < 100 && mouse_poz.y > 0 && mouse_poz.y < 100) then it works but only if my window is maximized/positioned in upper left corner....how can I set it up so it works relatively to the window position
« Last Edit: May 22, 2014, 07:16:06 pm by Favor98 »

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Creating custom buttons
« Reply #6 on: May 22, 2014, 07:48:37 pm »
Now how do I get bounds of the texture
How about texture.getSize()?
You can also grab it from your sprite (if you set the texture) with getLocalBounds().

how can I set it up so it works relatively to the window position
If you read the tutorials, you would know it.
Failing to succeed does not mean failing to progress!