Page 1 of 1

Testing window & gadgets colors

Posted: Thu May 03, 2012 9:27 am
by graves
Hi,
if you need to know how shows your program colors, try this:

Code: Select all

Global my_COLORS.s = "250,255,220|255,225,255|225,250,225|64,255,64|200,200,200|0,32,64|225,250,225|255,200,80|210,190,140"
Global d2h.s = "0123456789ABCDEF"

macro Dec2Hex(n)
  mid(d2h,(n/16)+1,1)+mid(d2h,(n%16)+1,1)
endmacro
macro divide_cols(col)
  val(StringField(col,1,",")), val(StringField(col,2,",")), val(StringField(col,3,","))
endmacro

Procedure SetTracks(rd,gr,bl)
  co = RGB(rd,gr,bl)
  hcolor.s = "$"+Dec2Hex(bl)+Dec2Hex(gr)+Dec2Hex(rd)
  SetGadgetState(1,rd)
  SetGadgetState(2,gr)
  SetGadgetState(3,bl)
  SetGadgetText (11,Rset(str(rd),3,"0"))
  SetGadgetText (12,Rset(str(gr),3,"0"))
  SetGadgetText (13,Rset(str(bl),3,"0"))
  SetGadgetText (14,hcolor)
  SetGadgetText (15,str(co))
  SetGadgetColor(21,#PB_Gadget_FrontColor,0)
  SetGadgetColor(21,#PB_Gadget_BackColor,co)
  SetGadgetColor(22,#PB_Gadget_FrontColor,$FFFFFF)
  SetGadgetColor(22,#PB_Gadget_BackColor,co)
  SetGadgetColor(23,#PB_Gadget_FrontColor,co)
  SetGadgetColor(23,#PB_Gadget_BackColor,0)
  SetGadgetColor(24,#PB_Gadget_FrontColor,co)
  SetGadgetColor(24,#PB_Gadget_BackColor,$FFFFFF)
  SetGadgetColor(25,#PB_Gadget_FrontColor,co)
EndProcedure

Openwindow(0, 0, 0, 320,160, "Testing Colors",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
 TrackbarGadget( 1, 55, 10,256, 25, 0, 255)
 TrackbarGadget( 2, 55, 45,256, 25, 0, 255)
 TrackbarGadget( 3, 55, 80,256, 25, 0, 255)
 TextGadget    ( 4,  2, 13, 30, 15, "Red")
 TextGadget    ( 5,  2, 48, 30, 15, "Green")
 TextGadget    ( 6,  2, 83, 30, 15, "Blue")
 TextGadget    (11, 32, 13, 20, 15, "000")
 TextGadget    (12, 32, 48, 20, 15, "000")
 TextGadget    (13, 32, 83, 20, 15, "000")
 SetGadgetColor(11, #PB_Gadget_FrontColor, RGB(200,0,0))
 SetGadgetColor(12, #PB_Gadget_FrontColor, RGB(0,128,0))
 SetGadgetColor(13, #PB_Gadget_FrontColor, RGB(0,0,200))
 TextGadget    (14,  2,118, 50, 20, "$000000")
 TextGadget    (15, 55,118, 50, 20, "0",#PB_Text_Right)
 ButtonGadget  (19,  5,142, 55, 15, "ClipBoard")
 for n=1 to 5
   TextGadget  (20+n,110+((n-1)*40),115, 40, 20, "TEST",#PB_Text_Border|#PB_Text_Center)
 next
 for n=1 to 9
   StringGadget(30+n,110+((n-1)*20),142, 15, 15, " "+str(n),#PB_String_ReadOnly)
   color.s = StringField(my_COLORS,n,"|")
   SetGadgetColor(30+n, #PB_Gadget_BackColor, RGB(divide_cols(color)))
 next
 SetGadgetColor(36, #PB_Gadget_FrontColor, #White)
 hcolor.s = ""

Repeat
  select Waitwindowevent()
    case #PB_Event_CloseWindow: break
    case #PB_Event_Gadget
         nGad = EventGadget()
         if nGad = 19
            if len(hcolor): SetClipboardText(hcolor): endif
         elseif nGad > 30 AND nGad < 40
            if EventType() = #PB_EventType_Focus
              ncol  = nGad - 30
              color = StringField(my_COLORS,ncol,"|")
              rd    = val(StringField(color,1,","))
              gr    = val(StringField(color,2,","))
              bl    = val(StringField(color,3,","))
              SetTracks(rd,gr,bl)
            endif
         else
            rd = GetGadgetState(1)
            gr = GetGadgetState(2)
            bl = GetGadgetState(3)
            SetTracks(rd,gr,bl)
         endif
  endselect
Forever

END

Re: Testing window & gadgets colors

Posted: Thu May 03, 2012 10:39 am
by electrochrisso
Interesting,
Added: Global hcolor.s = "$000000"
Comment Out: ;hcolor.s = ""
To get paste to clipboard to work properly.

Re: Testing window & gadgets colors

Posted: Thu May 03, 2012 4:54 pm
by yrreti
Nice code graves
I made something similar about 6 years ago, in which you could with sliders like
you use, select a color. It also allowed you to select an objects color from your
desktop and paste it into the program. You could also paste the resultant color
code into your PB IDE editor if you wanted to. It was just a solid color though.
I like what you did by showing the effects of color in the text boxes below.
That gives you a nice view of the final results you want to achieve, because
sometimes a color you may think looks okay, really isn't when combined with the
text.
Nice job.
Thanks for sharing.

Re: Testing window & gadgets colors

Posted: Thu May 03, 2012 5:26 pm
by graves
Hi again,
It also allowed you to select an objects color from your
desktop and paste it into the program
Select a color from any desktop object is a good idea. I will work to include it.

Regards

Re: Testing window & gadgets colors

Posted: Fri May 04, 2012 2:08 am
by ozzie
A useful tool - thanks.

Re: Testing window & gadgets colors

Posted: Fri May 04, 2012 1:07 pm
by Kwai chang caine
Thanks for sharing 8)