Make text that is drawn, editable

please repair all your code posting
use:

</> button from forum editor

looks like
```
type or paste code here
```


why you make the
cp5 declaration inside draw? instead setup?

for what still have a text(); inside draw?

where is your event code??

not sure you wanted to do this?

/* ControlP5 by Andreas Schlegel, 2012 www.sojamo.de/libraries/controlp5 */

import controlP5.*;
ControlP5 cp5;
Textfield tf;
ColorWheel cw;

String textValue = "#123456";
String hexc = "";
color c_cw; //____________________________________________ from color wheel
int r_cw, g_cw, b_cw;
int r_tf, g_tf, b_tf; //__________________________________ from textfield FFFFFF

boolean diagp = true;

void setup() {
  size(400, 400);

  cp5 = new ControlP5(this);

  tf = cp5.addTextfield("input")
    .setPosition(20, 100)
    .setSize(100, 20)
    .setValue(textValue)
    .setFocus(true)
    .setAutoClear(false)
    .setColor(color(255))
    ;

  cw = cp5.addColorWheel("cw", 20, 80, 220 )
    .setRGB(color(128, 0, 255))
    .setPosition(150, 100)
    ;

}

void draw() {
  background(200, 200, 0);
}

public void cw(color c) { //_______________________________________ event code cw
  if ( diagp ) print("event cw color "+c+"  "); //_________________________________ set some globals
  r_cw = (int)red(c);
  g_cw = (int)green(c);
  b_cw = (int)blue(c);
  if ( diagp ) println(r_cw,g_cw,b_cw);
  c_cw = c;
  hexc = hex(c, 6);
  tf.setValue(hexc); //____________________________________________ set textfield
}

public void input(String theText) { // event__ automatically receives at ENTER results from controller input
  if ( diagp ) print("event input text : "+theText+"  ");
  String rs = theText.substring(0,2);
  r_tf = hex2decimal(rs);
  String gs = theText.substring(2,4);
  g_tf = hex2decimal(gs);
  String bs = theText.substring(4,6);
  b_tf = hex2decimal(bs);
  if ( diagp ) println(r_tf,g_tf,b_tf);
  cw.setRGB(color(r_tf,g_tf,b_tf));
}

public int hex2decimal(String s) {
  String digits = "0123456789ABCDEF";
  s = s.toUpperCase();
  int val = 0;
  for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    int d = digits.indexOf(c);
    val = 16*val + d;
  }
  return val;
}


2 Likes