Using COLOR() function

New to FreeBASIC? Post your questions here.
BasicCoder2
Posts: 3338
Joined: Jan 01, 2009 7:03

Using COLOR() function

Postby BasicCoder2 » Nov 23, 2018 19:40

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
Posts: 8687
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Using COLOR() function

Postby fxm » Nov 23, 2018 19:59

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: 5546
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using COLOR() function

Postby dodicat » Nov 23, 2018 20:23

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
Posts: 8687
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Using COLOR() function

Postby fxm » Nov 23, 2018 20:42

Code: Select all

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

Re: Using COLOR() function

Postby BasicCoder2 » Nov 23, 2018 20:48

fxm wrote: [color=#FF0000](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
Posts: 8687
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Using COLOR() function

Postby fxm » Nov 23, 2018 20:52

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

Re: Using COLOR() function

Postby MrSwiss » Nov 23, 2018 20:54

BasicCoder2 wrote:Also the Help example uses uinteger instead of ulong

Replace 'Integer' with 'ULong' updated example code
BasicCoder2
Posts: 3338
Joined: Jan 01, 2009 7:03

Re: Using COLOR() function

Postby BasicCoder2 » Nov 23, 2018 21:38

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
Posts: 8687
Joined: Apr 22, 2009 12:46
Location: Paris (suburbs), FRANCE

Re: Using COLOR() function

Postby fxm » Nov 24, 2018 14:11

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: 2926
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Using COLOR() function

Postby MrSwiss » Nov 24, 2018 20:17

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

Return to “Beginners”

Who is online

Users browsing this forum: dodicat and 2 guests