sojamo / controlp5

A gui library for processing.org
GNU Lesser General Public License v2.1
490 stars 142 forks source link

controlP5 and opengl incompatibility. how to solve? #104

Closed jcgcunha closed 6 years ago

jcgcunha commented 7 years ago

Hello. Basically I figured out what was making the backspace not work properly on a textfield on my code. If i use opengl which I need, I'm not able to keep pressing backspace to delete the text all at once. Instead I need to press and release, press and release etc... Is there any workaround? Everything else works fine (on my main code) like getting the strings from the textfields by pressing buttons etc.

Not functional with opengl

import controlP5.*;
import processing.opengl.*;
ControlP5 caixas;
Textfield selected;

void setup() {
   size(600, 400,OPENGL);
  caixas = new ControlP5(this);

  selected = caixas.addTextfield("Name").setPosition(20, 200).setSize(200, 40)
  .setAutoClear(false)
  .setFont(createFont("Calibri", 17))
  .setColorActive(color(255));
}
void draw() {
      background(0);
}

Fully functional without opengl:

import controlP5.*; 
ControlP5 caixas;
Textfield selected;

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

  caixas = new ControlP5(this);

  selected = caixas.addTextfield("Name").setPosition(20, 200).setSize(200, 40)
  .setAutoClear(false)
  .setFont(createFont("Calibri", 17))
  .setColorActive(color(255));
}
void draw() {
      background(0);
}
sojamo commented 7 years ago

Hi, the title of this issue is misleading, the issue refers to key handling. Since ControlP5 receives key events from Processing's PApplet (keyEvents are registered with PApplet using registerMethod inside the ControlWindow class), this might be a Processing issue. See test below which demonstrates the same issue (using Processing 3.2.1 on mac) without using ControlP5.

int cnt = 0;
void setup() {
  size(400,400); // keyPressed works as expected
  // size(400,400,P3D); // keyPressed does not work as expected
}

void draw() {

}

void keyPressed() {
  println("pressed", frameCount, cnt++);
}

void keyReleased() {
  println("released");
  cnt = 0;
}
jcgcunha commented 7 years ago

Ok, I'm sorry about the misleading issue. It only happened with controlp5 (due to all the circumstances together) so I though it had something to do with the textfields. But yes, I tried your sketch and it's precisely the same. It just gets me crazy not being able to clear the text properly. Thank you for your time.