Page 1 of 1

Using HTML5 Color

Posted: Tue Mar 21, 2017 9:49 am
by falsam

Code: Select all

Enumeration
  #mf
  #color
EndEnumeration

Procedure GetColor()
  Protected selector = GadgetID(#color) 
  Protected htmlcolor.s, color
  
  ;Get HTML Color
  !v_htmlcolor = $(v_selector.div).find("input").val();
  
  ;HTMLColor -> RGBColor
  color = Val("$"+ReverseString(Mid(htmlcolor, 2, 6)))

  Debug "Red " + Red(Color)
  Debug "Green " + Green(Color)
  Debug "Blue " + Blue(Color)
EndProcedure

OpenWindow(#mf, 0, 0, 0, 0, "Color Picker", #PB_Window_Background)
StringGadget(#color, 10, 30, 80, 24, "")

;Change input type
Define  selector = GadgetID(#color)
! $(v_selector.div).find("input").attr('type', 'color');

BindGadgetEvent(#color, @GetColor(), #PB_EventType_Change)
Internet Explorer [ ] Edge [X] Chrome[X] FireFox[X] Opera[X] Safari[?] Android[X]

Re: Using HTML5 Color

Posted: Tue Mar 21, 2017 12:53 pm
by T4r4ntul4
Very nice snippet!
Needed to change something to get the real RGB numbers:

Code: Select all

Enumeration
  #mf
  #color
EndEnumeration

Procedure GetColor()
  Protected selector = GadgetID(#color)
  Protected htmlcolor.s, color, redc.s, greenc.s, bluec.s
 
  ;Get HTML Color
  !v_htmlcolor = $(v_selector.div).find("input").val();
  
  redc = Mid(htmlcolor, 2, 2)
  greenc = Mid(htmlcolor, 4, 2)
  bluec = Mid(htmlcolor, 6, 2)
  
  Debug "Red " + Val("$"+redc)
  Debug "Green " + Val("$"+greenc)
  Debug "Blue " + Val("$"+bluec)
EndProcedure

OpenWindow(#mf, 0, 0, 0, 0, "Color Picker", #PB_Window_Background)
StringGadget(#color, 10, 30, 80, 24, "")

;Change input type
Define  selector = GadgetID(#color)
! $(v_selector.div).find("input").attr('type', 'color');

BindGadgetEvent(#color, @GetColor(), #PB_EventType_Change)