PB constants: #Gray, #Blue, etc... only for Windows...

Everything else that doesn't fall into one of the other PB categories.
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Trond wrote:If you try to use them on Linux (with GTK) you will in fact get wrong colours every time (except for shades of gray), as the red and blue component are inversed compared to Windows. That's why defining them on Linux makes no sense: they are indeed Windows specific.
Thats not true.
If you use the PB commands, you will get correct colors because they map the values to be compatible on every OS. If you use Gtk directly, you usually cannot use a rgb value directly anyway, as it uses the GdkColor structure in most places which uses 16bit per color, so you need a conversion anyway.

> Defining constants that has the same name but different values on different platforms is not an option in my opinion. They are called constants for a reason.

This is exactly what PB does to map event constants, keyboard codes etc between the different OS.

IceSoft:
> but I belive at least the nativ color constants should be usable on all supported OS.

And where does it stop ? Somebody else thinks some other value is "nativ" to him and he needs the value everywhere. We cannot just define a constant for every value somebody may ever need. PB only defines the constants needed for the PB commandset (#PB_...) + the constants for the OS API.

Defining a few constants for yourself is really no big deal. Calling PB not "crossplatform usable" because of it us just nonsense.
quidquid Latine dictum sit altum videtur
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Kaeru Gaman wrote:
Trond wrote:If you try to use them on Linux (with GTK) you will in fact get wrong colours every time (except for shades of gray), as the red and blue component are inversed compared to Windows. That's why defining them on Linux makes no sense: they are indeed Windows specific.
Aye caramba!
that means you need to run my colors.pbi thru some converter to change RGB to BGR to make it work...?
bones!
As you can see, Windows uses BGR for the colour constants. Gdk (and gtk) uses RGB.

Code: Select all

Debug Hex(#Blue)
Debug Hex(#Red)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Trond wrote:As you can see, Windows uses BGR for the colour constants. Gdk (and gtk) uses RGB.

Code: Select all

Debug Hex(#Blue)
Debug Hex(#Red)
since I have no Linux and no OSX, I can't test it.

> Windows uses BGR for the colour constants.
common mistake: just the other way round!

RGB means, the first byte in Memory is the Red-Value.
interpreted as a single Number, the LeastSignificantByte is first in Memory,
but when you write it as a Number, you start with the MostSignificant Digit.

so, as a Hex-Number you write $BBGGRR, but it is RGB,
BGR would be written $RRGGBB as a Hex number.
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Kaeru Gaman wrote:
Trond wrote:As you can see, Windows uses BGR for the colour constants. Gdk (and gtk) uses RGB.

Code: Select all

Debug Hex(#Blue)
Debug Hex(#Red)
since I have no Linux and no OSX, I can't test it.

> Windows uses BGR for the colour constants.
common mistake: just the other way round!
...
BGR would be written $RRGGBB as a Hex number.
Windows constants are written as $RRGGBB, thus, they are BGR as you say. I think we agree but have language problem here.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Windows constants are written as $RRGGBB, thus, they are BGR as you say. I think we agree but have language problem here.
when I write a 24bit color Value as a Hex number, I have to write the Blue value first.

Code: Select all

OpenWindow(0, #PB_Ignore,0, 200,100, "Color is Blue")
SetWindowColor(0, $FF0000 ) 
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
so, it's RGB, written $BBGGRR...
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I just got a bit confused due to this:

Code: Select all

OpenWindow(0, 100, 100, 512, 384, "asdf")

CreateGadgetList(WindowID(0))

#WindowsBlue = $FF0000
#GdkParseColorRed = "#FF0000"
#GdkParseColorBlue = "#0000FF"

TextGadget(0, 10, 10, 300, 30, "This is blue")
TextGadget(1, 10, 60, 300, 30, "This is red")
TextGadget(2, 10, 110, 300, 30, "This is blue")

SetGadgetColor(0, #PB_Gadget_FrontColor, #WindowsBlue)

color.GdkColor
gdk_color_parse_(#GdkParseColorRed, @color)
gtk_widget_modify_fg_(GadgetID(1), #GTK_STATE_NORMAL, @color)

gdk_color_parse_(#GdkParseColorBlue, @color)
gtk_widget_modify_fg_(GadgetID(2), #GTK_STATE_NORMAL, @color)

Repeat
  If WaitWindowEvent() = #PB_Event_CloseWindow
    Break
  EndIf
ForEver
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

the GdkParseColor string seems to be a Webcolor format.
if you write windows blue255 = $FF0000 in webformat it's #0000FF

... I can't test your example... is it Linux or does it use a lib?
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It's Linux, but you should be able to use a gtk lib for Windows as well.
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

gdk_color_parse() uses X color names, which are "#RRGGBB". There are even some weirder X formats like "#RGB" or "#RRRRGGGGBBBB"
( http://linux.die.net/man/3/xparsecolor )

With PB commands, you can use the same hex number and you will get the same color on every OS.
quidquid Latine dictum sit altum videtur
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

freak wrote:With PB commands, you can use the same hex number and you will get the same color on every OS.
good to know.
that means, my colors.pbi is cross-platform when used with PB color commands.
oh... and have a nice day.
Post Reply