Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Romans_I_XVI
Roku Guru

Please help me with hex colors.

So I'm just having a hard time with this and hoping others on the forums can help. If I currently hold a variable that is the decimal equivalent of &hffffffff (which is white) and that decimal is 4294967295 , how wold I go about using that value in an argument that would normally accept a color represented by a hex value? Also I am declaring doubles with # so that the math goes through properly, and I even tried using the decimal directly, such as ...


screen.DrawObject(x, y, bm, 4294967295#)


Am I missing something simple? How would I go about doing this?

Thank you.
0 Kudos
8 REPLIES 8
TheEndless
Channel Surfer

Re: Please help me with hex colors.

I'm sure I'm missing something here, but why do you need the decimal value? Are you converting it from something else?
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Romans_I_XVI
Roku Guru

Re: Please help me with hex colors.

I'm getting the decimal value from hue,saturation,value. viewtopic.php?f=34&t=85620
0 Kudos
Romans_I_XVI
Roku Guru

Re: Please help me with hex colors.

I actually just figured out a slightly ridiculous way to get the result I want lol, but if it works it works. Just tried using the decTohex function found here -> viewtopic.php?t=51127


function decToHex (dec as integer) as string
hexTab = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
hex = ""
while dec > 0
hex = hexTab [dec mod 16] + hex
dec = dec / 16
end while
if hex = "" return "0" else return hex
end function


Then I took that string and put it in a


screen.DrawObject(x,y,bm,val(str,16))


It worked, lol. If there is a better way I will certainly use it, but otherwise I guess this will work.

Edit: I can now change the hue and saturation of each of the 3 sections of my ship while in game... muahahaha

😄
0 Kudos
TheEndless
Channel Surfer

Re: Please help me with hex colors.

"Romans_I_XVI" wrote:
I'm getting the decimal value from hue,saturation,value. viewtopic.php?f=34&t=85620

Sounds like you're not getting a valid value back from that function. That function returns a double, not an integer, so it won't work with DrawObject (assuming you actually mean to be passing it to DrawObject... are you trying to add a tint to the bitmap?). Have you tried casting it to an integer before returning the value?
    color% =  rgb[0] + rgb[1] + rgb[2] + a
return color%
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Romans_I_XVI
Roku Guru

Re: Please help me with hex colors.

I tried what you said TheEndless, the result is the same. Plus doesn't it need to be a double? If I used integers the math didn't work right. Either way, the doubles do in fact work in the DrawObject(), but at a certain point they go out of range, I believe it is 7FFFFFFF or 2147483647 that the color stops changing.

But again, it is working now, although I have to jump through a few hoops, I will jump through those hoops before the gameplay is actually going, so it's no problem.
0 Kudos
TheEndless
Channel Surfer

Re: Please help me with hex colors.

"Romans_I_XVI" wrote:
Plus doesn't it need to be a double?

Nope...
BrightScript Debugger> ?type(&hffffffff)
Integer

You might need the doubles for precision during your math operations, but it should be an integer when passed to the 2D API functions. I suppose it's possible they work with either, but note that the version of Val() you used also returns an integer.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Romans_I_XVI
Roku Guru

Re: Please help me with hex colors.

Oh ok, I didn't know that. So I just need them to be doubles while I am doing the math, but afterwards I can store the value as an integer. I wasn't 100% sure how it worked, I just knew that before I added those #'s I was not getting the correct value back. Thank you for clarifying!
0 Kudos
dev42
Visitor

Re: Please help me with hex colors.

I'm confused. Don't worry! It's perfectly normal.

Why do you need a hex value anyway? It's just a nice way to "see" the individual components of the color when they are lined up together. IOW it's just a style convention for us humans. An Integer should work.

Now, I don't have access to the SDK at the moment (?) and I've never sent a color in to DrawObject as I've always used it as: DrawObject(x as Integer, y as Integer, src as Object) as Boolean, but I can use your ported routine ( TYVM btw ) without having to convert to hex and can feed it directly into DrawLine.

The only other "thought" is my takeaway from what TheEndless was saying ... GIGO. Are you sure you're sending in good values for HSVA?
0 Kudos