Problem with a conditional in draw()
in
Programming Questions
•
1 years ago
I am getting the error message "cannot convert from void to boolean" when I try to run this conditional in draw():
RectSelectionTool selectRectangle;
EllipseSelectionTool selectEllipse;
void setup() {
size (screen.width, screen.height);
background (225, 225, 255);
selectRectangle = new RectSelectionTool (0, 0, 0, 0, 0, 0, 50, 50);
selectEllipse=new EllipseSelectionTool (0, 0, 0, 0, 0, 50, 50, 50);
}
void draw() {
background (225, 225, 255);
if (selectRectangle.rollOver(true)) {
selectRectangle.select();
selectRectangle.display();
}
else { // do nothing
}
if (selectEllipse.rollOver(true)) {
selectEllipse.select();
selectEllipse.display();
}
else { // do nothing
}
}
// mouse and keyboard events
void mousePressed () {
selectRectangle.click (mouseX, mouseY);
selectEllipse.click (mouseX, mouseY);
}
void mouseDragged() {
}
void mouseReleased () {
selectRectangle.release ();
selectEllipse.release();
}
void keyPressed () {
}
abstract class InteractiveBoxes {
int boxPosX, boxPosY, boxPosW, boxPosH;
int boxPosXOff, boxPosYOff;
boolean over = false;
boolean pressed = false;
InteractiveBoxes (int tempBoxPosX, int tempBoxPosY, int tempBoxWidth, int tempBoxHeight) {
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
boxPosW=tempBoxWidth;
boxPosH=tempBoxHeight;
}
// methods of the abstract InteractiveBoxes class
void rollOver () {
if ((mouseX>=boxPosX) && (mouseX <=boxPosX+boxPosW) && (mouseY>=boxPosY) && (mouseY<=boxPosY+boxPosH)) {
over=true;
}
else {
over=false;
}
} // end of the rollOver function
void click (int mX, int mY) {
boxPosX=mouseX;
boxPosY=mouseY;
boxPosW=mouseX-boxPosX;
boxPosH=mouseY-boxPosY;
} // end the click function
void press (int mX, int mY) {
if (over==true) {
pressed=true;
boxPosXOff=mX-boxPosX;
boxPosYOff=mY-boxPosY;
}
} // end of the press function
void drag (int mX, int mY) {
if (pressed==true) {
boxPosX=mX-boxPosXOff;
boxPosY=mY-boxPosYOff;
}
} // end of the drag function
void release () {
pressed=false;
} // end of release function
}
abstract class SelectionTool extends InteractiveBoxes {
PImage icon;
int iconXPos, iconYPos, iconW, iconH;
int SelectX, SelectY, SelectW, SelectH;
boolean activate = false;
// constructor of the abstract SelectionTool class
SelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int tempIconXPos, int tempIconYPos, int tempIconW, int tempIconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
iconXPos=tempIconXPos;
iconYPos=tempIconYPos;
iconW=tempIconW;
iconH=tempIconH;
} // end of the constructor
// methods of the abstract SelectionTool class
void rollOver (boolean over) {
if (mousePressed && (mouseX>=iconXPos) && (mouseX <=iconXPos+iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
over=true;
}
else {
over=false;
}
} // end of the rollOver function
void release () {
pressed=false;
SelectX=boxPosX;
SelectY=boxPosY;
SelectW=mouseX-boxPosX;
SelectH=mouseY-boxPosY;
} // end of release function
abstract void select ();
void display () {
image (icon, iconXPos, iconYPos);
} // end of the display function
} // end of the SelectionTool class
class RectSelectionTool extends SelectionTool {
// constructor of the RectSelectionTool class
RectSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int iconXPos, int iconYPos, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, iconXPos, iconYPos, iconW, iconH);
icon=loadImage("rectangularmarquee.jpg");
} // end of the constructor
// methods of the RectSelectionTool class
void select () {
strokeWeight(1);
stroke(0, 0, 255);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
if (mousePressed)
{
rect (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
}
else {
rect (SelectX, SelectY, SelectW, SelectH);
}
stroke(0);
}
} // end of the RectSelectionTool class
class EllipseSelectionTool extends SelectionTool {
// constructor of the EllipseSelectionTool class
EllipseSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int iconXPos, int iconYPos, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, iconXPos, iconYPos, iconW, iconH);
icon=loadImage ("ellipticalmarquee.jpg");
} // end of the constructor
// methods of the EllipseSelectionTool class
void select () {
strokeWeight(1);
stroke(0, 0, 255);
fill (0, 0, 0, 0);
if (mousePressed) {
ellipseMode(CORNER);
ellipse (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
}
else {
ellipseMode(CORNER);
ellipse (SelectX, SelectY, SelectW, SelectH);
}
stroke(0);
}
} // end of the EllipseSelectionTool class
RectSelectionTool selectRectangle;
EllipseSelectionTool selectEllipse;
void setup() {
size (screen.width, screen.height);
background (225, 225, 255);
selectRectangle = new RectSelectionTool (0, 0, 0, 0, 0, 0, 50, 50);
selectEllipse=new EllipseSelectionTool (0, 0, 0, 0, 0, 50, 50, 50);
}
void draw() {
background (225, 225, 255);
if (selectRectangle.rollOver(true)) {
selectRectangle.select();
selectRectangle.display();
}
else { // do nothing
}
if (selectEllipse.rollOver(true)) {
selectEllipse.select();
selectEllipse.display();
}
else { // do nothing
}
}
// mouse and keyboard events
void mousePressed () {
selectRectangle.click (mouseX, mouseY);
selectEllipse.click (mouseX, mouseY);
}
void mouseDragged() {
}
void mouseReleased () {
selectRectangle.release ();
selectEllipse.release();
}
void keyPressed () {
}
abstract class InteractiveBoxes {
int boxPosX, boxPosY, boxPosW, boxPosH;
int boxPosXOff, boxPosYOff;
boolean over = false;
boolean pressed = false;
InteractiveBoxes (int tempBoxPosX, int tempBoxPosY, int tempBoxWidth, int tempBoxHeight) {
boxPosX=tempBoxPosX;
boxPosY=tempBoxPosY;
boxPosW=tempBoxWidth;
boxPosH=tempBoxHeight;
}
// methods of the abstract InteractiveBoxes class
void rollOver () {
if ((mouseX>=boxPosX) && (mouseX <=boxPosX+boxPosW) && (mouseY>=boxPosY) && (mouseY<=boxPosY+boxPosH)) {
over=true;
}
else {
over=false;
}
} // end of the rollOver function
void click (int mX, int mY) {
boxPosX=mouseX;
boxPosY=mouseY;
boxPosW=mouseX-boxPosX;
boxPosH=mouseY-boxPosY;
} // end the click function
void press (int mX, int mY) {
if (over==true) {
pressed=true;
boxPosXOff=mX-boxPosX;
boxPosYOff=mY-boxPosY;
}
} // end of the press function
void drag (int mX, int mY) {
if (pressed==true) {
boxPosX=mX-boxPosXOff;
boxPosY=mY-boxPosYOff;
}
} // end of the drag function
void release () {
pressed=false;
} // end of release function
}
abstract class SelectionTool extends InteractiveBoxes {
PImage icon;
int iconXPos, iconYPos, iconW, iconH;
int SelectX, SelectY, SelectW, SelectH;
boolean activate = false;
// constructor of the abstract SelectionTool class
SelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int tempIconXPos, int tempIconYPos, int tempIconW, int tempIconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
iconXPos=tempIconXPos;
iconYPos=tempIconYPos;
iconW=tempIconW;
iconH=tempIconH;
} // end of the constructor
// methods of the abstract SelectionTool class
void rollOver (boolean over) {
if (mousePressed && (mouseX>=iconXPos) && (mouseX <=iconXPos+iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
over=true;
}
else {
over=false;
}
} // end of the rollOver function
void release () {
pressed=false;
SelectX=boxPosX;
SelectY=boxPosY;
SelectW=mouseX-boxPosX;
SelectH=mouseY-boxPosY;
} // end of release function
abstract void select ();
void display () {
image (icon, iconXPos, iconYPos);
} // end of the display function
} // end of the SelectionTool class
class RectSelectionTool extends SelectionTool {
// constructor of the RectSelectionTool class
RectSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int iconXPos, int iconYPos, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, iconXPos, iconYPos, iconW, iconH);
icon=loadImage("rectangularmarquee.jpg");
} // end of the constructor
// methods of the RectSelectionTool class
void select () {
strokeWeight(1);
stroke(0, 0, 255);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
if (mousePressed)
{
rect (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
}
else {
rect (SelectX, SelectY, SelectW, SelectH);
}
stroke(0);
}
} // end of the RectSelectionTool class
class EllipseSelectionTool extends SelectionTool {
// constructor of the EllipseSelectionTool class
EllipseSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, int iconXPos, int iconYPos, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, iconXPos, iconYPos, iconW, iconH);
icon=loadImage ("ellipticalmarquee.jpg");
} // end of the constructor
// methods of the EllipseSelectionTool class
void select () {
strokeWeight(1);
stroke(0, 0, 255);
fill (0, 0, 0, 0);
if (mousePressed) {
ellipseMode(CORNER);
ellipse (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
}
else {
ellipseMode(CORNER);
ellipse (SelectX, SelectY, SelectW, SelectH);
}
stroke(0);
}
} // end of the EllipseSelectionTool class
1