> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.0fZRCuC9XCq/rev.3
 * 
 * authors: 
 *   GoToLoop

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/**
 * Mouse Button Check (v1.0)
 * GoToLoop (2016-Mar-17)
 *
 * forum.Processing.org/two/discussion/15531/
 * how-to-detect-right-mouse-button-press-release-
 * while-left-mouse-button-is-plessed-in-p3d-mode
 *
 * studio.ProcessingTogether.com/sp/pad/export/ro.9$uOULvJSGGfw
 */

static final String RENDERER = P3D;
//static final String RENDERER = P2D;
//static final String RENDERER = FX2D;
//static final String RENDERER = JAVA2D;

boolean leftBtn, rightBtn, centerBtn;

void setup() {
  size(400, 300, RENDERER);
  smooth(8);
  noLoop();
  frameRate(20);

  fill(-1);
  stroke(0);
  strokeWeight(2.5);
  rectMode(CENTER);
}

void draw() {
  final String btnStats = "L: " + leftBtn +
    "    R: " + rightBtn + "    C: " + centerBtn;

  if (1/2 != 1/2.)  frame.setTitle(btnStats);
  else              println(btnStats);

  background(leftBtn? 0 : -1);
  if (leftBtn & rightBtn)
    rect(width>>1, height>>1, width>>1, height>>1);
}

void mousePressed() {
  updateButtons(mouseButton, true);
  redraw();
}

void mouseReleased() {
  updateButtons(mouseButton, false);
  redraw();
}

void updateButtons(int btn, boolean bool) {
  if      (btn == LEFT)   leftBtn   = bool;
  else if (btn == RIGHT)  rightBtn  = bool;
  else                    centerBtn = bool;
}