Graphics-ColorPicker

 view release on metacpan or  search on metacpan

ColorPicker.pm  view on Meta::CPAN

  var me = parent._sample.document;
  var t = '<font color=';
  var whitefont = t + 'white>';
  var hexfont = t + '"#' + hex + '">';
  var blackfont = t + 'black>';
  t = '<td width=|. ($colwidth-15) . q| id="';
  var td_bgblack = t + 'dark">';
  var td_bghex = t + 'clrd">';
  var td_bgwhite = t + 'lite">';
  var end = '</font></td>';
  me.write('<html><head>'+"\n");
  me.writeln('<style type="text/css">')
  me.writeln('  #dark{background-color: black;font-family: VERDANA,ARIAL,HELVETICA,SAN-SERIF;font-size: 16px !important;font-weight: bold;}');
  me.writeln('  #lite{background-color: white;font-family: VERDANA,ARIAL,HELVETICA,SAN-SERIF;font-size: 16px !important;font-weight: bold;}');
  me.writeln('  #clrd{background-color: #' + hex + ';font-family: VERDANA,ARIAL,HELVETICA,SAN-SERIF;font-size: 16px !important;font-weight: bold;}');
  me.writeln('</style>');
  me.writeln('</head>');
  me.writeln('<body bgcolor="#ffffff"><table cellspacing=5 cellpadding=5 border=0>');
  me.writeln('<tr align=center valign=middle>');
    me.writeln(td_bgwhite + hexfont + hex + end);
    me.writeln(td_bghex + whitefont + hex + end + '</tr>');
  me.writeln('<tr align=center valign=middle>');
    me.writeln(td_bgblack + hexfont + hex + end);
    me.writeln(td_bghex + blackfont + hex + end + '</tr>');
  me.writeln('</table></body></html>');
  me.close();
  if (typeof top.update_hook == 'function')
    top.update_hook(self);
  return true;
}
ishex = new RegExp("^([a-zA-Z0-9]{2})([a-zA-Z0-9]{2})([a-zA-Z0-9]{2})$");
function ckhex(s) {
  if ( s.match(ishex) ) {
    rgb[0] = parseInt(s.slice(0,2), 16); // r
    rgb[1] = parseInt(s.slice(2,4), 16); // g
    rgb[2] = parseInt(s.slice(4,6), 16); // b
    return true;
  } else {
    alert(s + "\nmust be 6 RGB elements\nhexadecimal a-zA-Z0-9" );
    document.forms.rgb.hex.value = "";
    return false;
  }
}
function setrgb() {
  document.forms.rgb.r.value = rgb[0]; // r
  document.forms.rgb.g.value = rgb[1]; // g
  document.forms.rgb.b.value = rgb[2]; // b
}
function hexclk() {
  var s = document.forms.rgb.hex.value;
  if ( ckhex(s) ) { 
    hex = s;
    setrgb();
    update();
  }
}
function newco(i,c) {
  var newcolor = document.forms.rgb[clr[c]];
  var n = newcolor.value;
  if (n == '') return false;
  if (isNaN(n)) {
    alert(color[c] + ' is not a number');
    newcolor.value = "";
    return false;
  }
  if ( n < 0 | . '||' . q| n > 255 ) {
    alert(color[c] + " out of range\nmust be 0-255");
    newcolor.value = "";
    return false;
  }
  n = Number(n) + Number(i);
  if ( n < 0 ) n = 0;
  if ( n > 255 ) n = 255;
  if ( rgb[c] != n ) {
    rgb[c] = n;
    newcolor.value = n;
    sethex();
  }
  return false; // always!
}
function sethex() {
  if (isNaN(rgb[0]) | .'||'. q| isNaN(rgb[1]) | .'||'. q|isNaN(rgb[2])) return false;
  hex = "" + tohex(rgb[0]) + tohex(rgb[1]) + tohex(rgb[2]);
  document.forms.rgb.hex.value = hex;
  update();
}
function tohex(n) {
  var h = "" + hexd[n>>4] + hexd[n%16];
  return h;
}
function clrupd() {
  document.forms.rgb.r.blur();
  document.forms.rgb.g.blur();
  document.forms.rgb.b.blur();
  document.forms.rgb.hex.blur();
  return true;
}
function clk216(r,g,b) {
  hex = "" + r + g + b;
  document.forms.rgb.hex.value = "" + hex;
  rgb[0] = eval('0x' + r);
  rgb[1] = eval('0x' + g);
  rgb[2] = eval('0x' + b);
  setrgb();
  update();
  return false;
}
function populate(n) {
  for (var i=0; i < n; i++) {
    var I = 'X' + i;
    document[I].src = icache.src;
  }
  return true;
}
</script>
<style>
A.NU { 
  color: #ffffcc;
  background: transparent;
  font-family: VERDANA,ARIAL,HELVETICA,SAN-SERIF;
  font-size: 12px !important;
  font-weight: bold;
  text-decoration: none;
}
#txt {
  font-family: VERDANA,ARIAL,HELVETICA,SAN-SERIF;
  font-size: 10px !important;  
}
</style>
</head>
|;

#####################################

  my $num = 0;

  my $digitbox = q|
<MAP name="RED">
<AREA OnClick="return(newco(1,0));"
shape=rect
coords=0,0,16,7
href="+1"

ColorPicker.pm  view on Meta::CPAN

  py = mv - py;
  r = color_R(px,py);
  if (r > 255) return true; // have to return something
  if (color_GB(px,py)) return true; // ditto
  if (window._picker.c24flip != 0) {
    r = 255 - r;
    g = 255 - g;
    b = 255 - b;
  }
  setcolor(r,g,b);
  return true;
}
var con = 2.236067977;
color_R = function(x,y) {
  if (x < 0) x = -x;
   r = y + (x/2);
  if (r < 0) return 0;
  r = (con * r * sf) + 1;
  r >>= 1;
  if (r == 256) return 255;
  return r;
}
color_GB = function(x,y) {
  y = -y * sf;
  x *= sf;
  b = y + x/2;
  g = y - x/2;
  if (b < 0) b = 0;
  if (g < 0) g = 0;
  if (x < 0) {
    g = b - x;
  } else {
    b = g + x;
  }
  b = (con*b + 1) >>1;
  g = (con*g + 1) >>1;
  if (g > 256) return g;
  if (b > 256) return b;
  if (g > 255) g = 255;
  if (b > 255) b = 255;
  return 0;
}
greypluck = function() {
  pluckXY(arguments[0]);
  if (py > 255) py = 255;
  py = 255 - py;
  setcolor(py,py,py);
  return true;
}
pluckXY = function(skip) {
  if ( ! skip ) {
    var xy = window._data.document.location.search;
    var qloc = xy.lastIndexOf('?') + 1;
    var cloc = xy.lastIndexOf(',');
    px = bound(xy.substring(qloc,cloc));
    py = bound(xy.substring(cloc+1,xy.length));
  }
}
bound = function(n) {
  n = 0 + n;
  if (isNaN(n)) return 0;
  if (n < 0) n = 0;
  return n;
}
setcolor = function(r,g,b) {
  with (window._digits) {
  rgb[0] = r;
  rgb[1] = g;
  rgb[2] = b;
  setrgb();  
  sethex();
  }
  return true;
}
|;
}

#########################################
# replace problematic characters in js lib
#
sub j2s {
  my ($tp) = @_;
#  sub operation
  $$tp =~  s/%/%j/g;
  $$tp =~ s/\\/%a/g;
  $$tp =~  s/'/%v/g;
  $$tp =~ s/\$/%s/g;
  $$tp =~  s/"/%c/g;
  $$tp =~ s/\@/%r/g;
#  $$tp =~  s//%i/g;
  $$tp =~ s/\r/%p/g;
  $$tp =~ s/\n/%t/g;
  1;
}

=item $html=make_buttons(\%look_n_feel,$url,$active,\@buttons,$xtra);

  Called internally

  Return the html text for a button bar

  input:  button_color, width, \@buttons

  @buttons is a list of the form = (
        # text        command 
        'BUTT1' => 'command1',
        'BUTT2' => 'command2',
        ''      => '',		# empty
  );
        If the button text is false,
        a spacer is inserted in the button bar

  returns:      html for button bar


  NOTE:         class NU must be defined
  example:
                <style>
                A.NU { 
                  color: red; // #ff0000
                  background: transparent;



( run in 2.181 seconds using v1.01-cache-2.11-cpan-df04353d9ac )