Unable to draw using line() after initializing ControlP5 library. How do I make them work together?
in
Contributed Library Questions
•
1 year ago
Hi,
I have a sketch that does 2 things:
1. Getting some hand drawn shape using line() function.
2. Show onscreen keyboard using ControlP5 library.
But when I initialize the ControlP5 library, the line drawing doesn't work any longer. Commenting out the ControlP5 part of the code does make the line drawing on again. I've tried setting the setAutoDraw() to false under ControlP5 and draw the button when necessary but no luck.
Here's the code:
- import controlP5.*; //for GUI
- PImage bg;
- ControlP5 controlP5;
- controlP5.Button btnContinue;
- void setup() {
- size(1366, 768);
- frameRate(120);
- smooth();
- controlP5 = new ControlP5(this);
- controlP5.setAutoDraw(false);
- btnContinue = controlP5.addButton("btnContinue", 0, 34, 638, 60, 30);
- btnContinue.setImages(loadImage("touch_to_continue.png"), loadImage("touch_to_continue.png"), loadImage("touch_to_continue.png"));
- btnContinue.updateSize();
- bg = loadImage("data/bg.png");
- drawBound();
- }
- void draw() {
- if (mousePressed) {
- strokeWeight(5);
- if (mouseX > 40 && mouseY > 99 && mouseX < 1326 && mouseY < 635) {
- line(pmouseX, pmouseY, mouseX, mouseY);
- }
- }
- else {
- //controlP5.draw();
- }
- }
- void keyPressed() {
- if (key == 's' || key == 'S') {
- PImage temp = get(40, 99, 1286, 539); //get(x, y, width, height)
- String filename = "user-" + year() + month() + day() + "-" + hour() + minute() + second() + ".png";
- temp.save(savePath("feedbacks/" + filename));
- drawBound();
- }
- }
- void drawBound() {
- background(bg);
- strokeWeight(1);
- line(40, 99, 1366, 99);
- line(1326, 99, 1326, 635);
- line(1326, 635, 40, 635);
- line(40, 635, 40, 99);
- }
1