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

Author Topic: how to subtract colors?  (Read 4321 times)

0 Members and 1 Guest are viewing this topic.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
how to subtract colors?
« on: September 15, 2013, 02:04:11 am »
hello everybody
i have an opaque object, and now i want to lessen it's alpha value.
there is no overload to the '-' operator, and trying something like
text_box.setFillColor(text_box.getFillColor() + sf::Color(0, 0, 0, -15));
doesn't work.

so, how can i subtract 15 from the alpha value? this is in a loop, to be subtracted by this amount many times.
thanks in advance!
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: how to subtract colors?
« Reply #1 on: September 15, 2013, 02:51:07 am »
What exactly do you mean by "doesn't work"?  What's the error message?
« Last Edit: September 15, 2013, 02:54:38 am by Ixrec »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: how to subtract colors?
« Reply #2 on: September 15, 2013, 02:58:25 am »
Quote
What exactly do you mean by "doesn't work"?
-15 silently wraps around to be 241 because it's unsigned char and that's what all unsigned types are supposed to do(wrap around)
Just overload global operator- yourself(not too good) or write own subtraction function(much better). :-\
Back to C++ gamedev with SFML in May 2023

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: how to subtract colors?
« Reply #3 on: September 15, 2013, 03:37:36 am »
What exactly do you mean by "doesn't work"?  What's the error message?
there's no error message. it adds 15, instead of subtracting it.

-15 silently wraps around to be 241 because it's unsigned char and that's what all unsigned types are supposed to do(wrap around)
ok, not a bad idea. but how am i going to acess the alpha value from a color, since getFillColor() will obviously not work?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: how to subtract colors?
« Reply #4 on: September 15, 2013, 04:06:03 am »
The docs say r, g, b and a are public attributes of an sf::Color, so you should just be able to use ".a" to get at it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: how to subtract colors?
« Reply #5 on: September 15, 2013, 09:17:38 am »
There's an operator - for sf::Color in the current development version.
Laurent Gomila - SFML developer

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: how to subtract colors?
« Reply #6 on: September 15, 2013, 09:38:59 pm »
The docs say r, g, b and a are public attributes of an sf::Color, so you should just be able to use ".a" to get at it.

yeah, but the color isn't a public attribute from the Shape class, and the only setter method I found is "setFillColor", which sets all colors at once.
maybe something like
text_box.setFillColor(sf::Color(text_box.getFillColor().r, text_box.getFillColor().g,  text_box.getFillColor().b,  text_box.getFillColor().a - 15));
would work, but i did something simpler:

sf::Color color(text_box.getFillColor());
color.a-=15;
text_box.setFillColor(color);

There's an operator - for sf::Color in the current development version.
ok, thanks for the info :)


and thanks everybody for the help :)
« Last Edit: September 15, 2013, 10:45:48 pm by Stauricus »
Visit my game site (and hopefully help funding it? )
Website | IndieDB

 

anything