Page 1 of 1

Why doesn't $FF0000 show as Red ?

Posted: Mon May 27, 2024 4:10 pm
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


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

Posted: Mon May 27, 2024 5:12 pm
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.

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

Posted: Mon May 27, 2024 5:14 pm
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.

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

Posted: Mon May 27, 2024 5:51 pm
by infratec
Or simply use:

Code: Select all

#Red
It is a defined constant.

Code: Select all

SetGadgetColor(3, #PB_Gadget_FrontColor, #Red)

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

Posted: Mon May 27, 2024 6:38 pm
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])

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

Posted: Mon May 27, 2024 9:28 pm
by millie78526
Aha....
Thank you very much Guys !