Why doesn't $FF0000 show as Red ?

Just starting out? Need help? Post your questions and find answers here.
millie78526
User
User
Posts: 23
Joined: Thu Apr 18, 2024 9:12 pm

Why doesn't $FF0000 show as Red ?

Post by millie78526 »

TIA :
Why doesn't $FF0000 show as Red ?

Code: Select all

                SetGadgetColor(3, #PB_Gadget_FrontColor, $FF0000)
Pls , see code below :

Code: Select all


; purebasic
If OpenWindow(0, 0, 0, 200, 500, "SetStringColor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ; Create the font objects
  Define VerdanaFont = LoadFont(#PB_Any, "Arial Black", 10)
  Define TahomaFont  = LoadFont(#PB_Any, "Arial Black", 14)
  
  StringGadget(1, 10, 10, 180, 36, "1st String", #PB_String_ReadOnly)
  SetGadgetFont(1, FontID(VerdanaFont))  ; Set font to Verdana for StringGadget(1)

  StringGadget(3, 10, 100, 180, 36, "START", #PB_String_ReadOnly)
  SetGadgetFont(3, FontID(TahomaFont))  ; Set font to Tahoma for StringGadget(3)

                SetGadgetColor(3, #PB_Gadget_BackColor, $467061) ; String
                SetGadgetColor(3, #PB_Gadget_FrontColor, $00FF00)

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            Select EventType()
              Case #PB_EventType_Focus
                Debug "Case 1 String Focus"
              Case #PB_EventType_Change
                Debug "Case 1 String Change"
              Case #PB_EventType_LostFocus
                Debug "Case 1 String Lost Focus"
            EndSelect  
          Case 3
            Select EventType()
              Case #PB_EventType_Focus
                Debug "Case 3 String Focus"
                SetGadgetColor(3, #PB_Gadget_BackColor, $467061) ; $DFDFDF) ; String 
                SetGadgetColor(3, #PB_Gadget_FrontColor, $FF0000)
                SetGadgetText(3, "WORKING...")
              Case #PB_EventType_Change
                Debug "Case 3 String Change"
              Case #PB_EventType_LostFocus
                Debug "Case 3 String Lost Focus"
                SetGadgetColor(3, #PB_Gadget_BackColor, $467061) ; String
                SetGadgetColor(3, #PB_Gadget_FrontColor, $00FF00)
                SetGadgetText(3, "START")
            EndSelect  
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
  Until Quit = 1
EndIf
End

PBJim
Enthusiast
Enthusiast
Posts: 294
Joined: Fri Jan 19, 2024 11:56 pm

Re: Why doesn't $FF0000 show as Red ?

Post by PBJim »

Hello Millie

It's because you have the bits the wrong way around...

Code: Select all

SetGadgetColor(3, #PB_Gadget_FrontColor, $0000FF)
or you can just use RGB(255, 0, 0)

Code: Select all

SetGadgetColor(3, #PB_Gadget_FrontColor, RGB(255, 0, 0))
The help for SetGadgetColor shows an example with $0000FF.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 316
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Why doesn't $FF0000 show as Red ?

Post by Derren »

In PB it's not RRGGBB but BBGGRR
Red is $0000FF

There is some technical explanation, I'm sure it's even mentioned in the documentation somewhere.
But it's easier to just accept that it's different than any other software and move on, if you're not familiar with how Computers store numbers.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Why doesn't $FF0000 show as Red ?

Post by infratec »

Or simply use:

Code: Select all

#Red
It is a defined constant.

Code: Select all

SetGadgetColor(3, #PB_Gadget_FrontColor, #Red)
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why doesn't $FF0000 show as Red ?

Post by mk-soft »

Derren wrote: Mon May 27, 2024 5:14 pm In PB it's not RRGGBB but BBGGRR
Red is $0000FF

There is some technical explanation, I'm sure it's even mentioned in the documentation somewhere.
But it's easier to just accept that it's different than any other software and move on, if you're not familiar with how Computers store numbers.
It indicates how the colours are located in the memory. So for PB as RRGGBBAA. Sometimes, however, you have to query the graphic to see what the sequence is.
As a long value, however, this is reversed because of the little endian notation of the representation of values in memory.

Code: Select all

Structure _Color
  Red.a
  Green.a
  Blue.a
  Alpha.a
EndStructure

Structure sColor
  StructureUnion
    Component._Color
    Color.l
    Byte.a[4]
  EndStructureUnion
EndStructure

Define Color1.sColor

Color1\Color = RGBA($10,$20,$30,$FF)
Debug "hex = " + Hex(Color1\Color, #PB_Long)
Debug "r = " + Hex(Color1\Component\Red)
Debug "g = " + Hex(Color1\Component\Green)
Debug "b = " + Hex(Color1\Component\Blue)
Debug "a = " + Hex(Color1\Component\Alpha)

Debug "by0 = " + Hex(Color1\Byte[0])
Debug "by1 = " + Hex(Color1\Byte[1])
Debug "by2 = " + Hex(Color1\Byte[2])
Debug "by3 = " + Hex(Color1\Byte[3])
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
millie78526
User
User
Posts: 23
Joined: Thu Apr 18, 2024 9:12 pm

Re: Why doesn't $FF0000 show as Red ? [Solved]

Post by millie78526 »

Aha....
Thank you very much Guys !
Post Reply