Using COLOR() function

New to FreeBASIC? Post your questions here.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Using COLOR() function

Post by BasicCoder2 »

In a routine I want to save the current foreground and background color but can't seem to get the background color?
In the code below I can see the &H88 but not the &H99 in the returned value.
Also the Help example uses uinteger instead of ulong

Code: Select all

screenres 640,480,32
color rgb(&H88,0,0),rgb(0,&H99,0)
dim as ulong c
c = color()
print hex(c,16)
sleep
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Using COLOR() function

Post by fxm »

See documentation:
Return Value
Returns a 32-bit value containing the current foreground color in the Low Word and the current background color in the High Word. (In hi/truecolor modes, only the foreground color is returned, taking up the whole 32 bits.)
The old color values can be retrieved at the same time as setting new ones.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using COLOR() function

Post by dodicat »

for 32 bits

Code: Select all

screenres 640,480,32
color rgb(&H88,0,0),rgb(0,&H99,0)
dim as integer f,b  'fore,back
screencontrol 13,f,b


print f,b

circle(200,200),50,f,,,,f
circle(500,200),50,b,,,,f

sleep  
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Using COLOR() function

Post by fxm »

Code: Select all

Print Hex(f, 6), Hex(b, 6)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Using COLOR() function

Post by BasicCoder2 »

fxm wrote: (In hi/truecolor modes, only the foreground color is returned, taking up the whole 32 bits.]

So is there any way to get the background color in 32 bit mode?

Code: Select all

screenres 640,480,32
color rgb(0,0,0),rgb(255,255,255):cls
sub colorPrint(text as string,fg as ulong,bg as ulong)
    dim as ulong oldColor
    oldColor = color(fg,bg)
    print text
    color oldColor
end sub
colorPrint("hello world",rgb(255,0,0),rgb(0,255,0))
print "hello world"
sleep
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Using COLOR() function

Post by fxm »

See dodicat's post.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using COLOR() function

Post by MrSwiss »

BasicCoder2 wrote:Also the Help example uses uinteger instead of ulong
Replace 'Integer' with 'ULong' updated example code
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Using COLOR() function

Post by BasicCoder2 »

Thank you for your patience and tolerance.
The FBIDE help I used is out of date and I also forgot about FBWiki which didn't show up when I did a google search for "freebasic color command".
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Using COLOR() function

Post by fxm »

MrSwiss wrote:
BasicCoder2 wrote:Also the Help example uses uinteger instead of ulong
Replace 'Integer' with 'ULong' updated example code
Thank you for updating the documentation.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using COLOR() function

Post by MrSwiss »

No problem, if the problem is 'spelled out' like it was here ...
Post Reply