Selection tool picks up incorrect parameters
in
Programming Questions
•
1 years ago
Okay, here is some code. It's a freakin' mess, especially the last class called ImageCollage which is supposed to use parameters from the rectangular selection tool to copy part of a photograph that is in a movable box. Currently my main problem is that when the copySelection method of the ImageCollage class is working (and it works sometimes but not always), it copies a rectangular selection of the image but the x and y parameters are wrong. The width and height of the box seem to be the same though. It seems to be related to the values that I assign when I instantiate the object but I cannot figure out why.
I also left a bunch of code in the imageCollage class that is irrelevant right now but it is actually how I would prefer copying the selection: rather than use copy, I would like to use loadPixels() but I don't know how to make it work and it's just a bunch of code I copied from the Shiffman book which I can't get to work so I just left it there in the constructor for now...I am open to suggestions...
boolean selectToolStatus;
int toggle;
PictureGallery artWorks;
RectSelectionTool selectRectangle;
EllipseSelectionTool selectEllipse;
ImageCollage selectPartOfImage;
void setup() {
size (screen.width, screen.height);
background (225, 225, 255);
selectToolStatus=false;
toggle=0;
artWorks=new PictureGallery (50, 140, 330, 360, color (100));
selectRectangle = new RectSelectionTool (0, 0, width, height, color (0, 0, 255), 50, 50);
selectEllipse=new EllipseSelectionTool (0, 0, width, height, color (0, 0, 255), 50, 50);
selectPartOfImage=new ImageCollage (0, 0, 0, 0);
}
void draw() {
background (225, 225, 255);
artWorks.getImage();
artWorks.rollOver();
artWorks.display();
artWorks.getIconY();
artWorks.getArtworksX();
artWorks.getArtworksY();
artWorks.getArtworksW();
artWorks.getArtworksH();
selectEllipse.getSelectionX();
selectEllipse.getSelectionY();
selectEllipse.getSelectionW();
selectEllipse.getSelectionH();
selectRectangle.getSelectionX();
selectRectangle.getSelectionY();
selectRectangle.getSelectionW();
selectRectangle.getSelectionH();
if (keyPressed && key == CODED && keyCode == KeyEvent.VK_CONTROL) {
selectToolStatus=true; // when CONTROL key is pressed, status of the select tools is true
}
else {
selectToolStatus=false; // when CONTROL key is not pressed, status of the select tools is false
}
if (mousePressed && keyPressed && key == CODED && keyCode == KeyEvent.VK_CONTROL) {
if (toggle == 1) {
selectEllipse.select();
}
else if (toggle==2) {
selectRectangle.select();
}
}
if (toggle == 1) {
selectEllipse.drawSelection();
}
else if (toggle==2) {
selectRectangle.drawSelection();
}
selectRectangle.display();
selectEllipse.display();
selectPartOfImage.copySelection();
if (mousePressed && keyPressed && key == CODED && keyCode == KeyEvent.VK_ALT) {
selectPartOfImage.display(mouseX, mouseY);
}
} // end draw
// mouse and keyboard events
void mousePressed () {
artWorks.press(mouseX, mouseY);
selectEllipse.setToggle();
selectRectangle.setToggle();
if (toggle==1) {
selectEllipse.click (mouseX, mouseY);
}
else if (toggle==2) {
selectRectangle.click (mouseX, mouseY);
}
selectRectangle.rollOver();
selectEllipse.rollOver();
selectRectangle.insidePictureGallery();
selectEllipse.insidePictureGallery();
selectPartOfImage.click(mouseX, mouseY);
}
void keyPressed () {
artWorks.flipThrough();
}
void mouseDragged() {
if (selectToolStatus==false) {
artWorks.drag (mouseX, mouseY);
}
}
void mouseReleased () {
artWorks.release();
if (toggle==1) {
selectEllipse.release(); // calculate the ellipse shape if toggle is 1
}
else if (toggle==2) { // calculate the rectangle shape if toggle is 2
selectRectangle.release ();
}
}
abstract class InteractiveBoxes {
int boxPosX, boxPosY, boxPosW, boxPosH;
PFont fontA; // declare a variable that refers to the default font for all the subclasses
int fontHeight;
int marginSpacing;
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;
fontA = loadFont("ArialMT-48.vlw"); // Load the default font that the subclasses will be able to use
fontHeight=48; // set a default value for the font height (determined by the font size limit)
marginSpacing=5;
}
// 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 void display();
}
class PictureGallery extends InteractiveBoxes {
PImage[] images=new PImage[15];
int imageIndex;
color boxClr;
// constructor of the Picture Gallery class
PictureGallery (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color tempBoxClr) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
boxClr=tempBoxClr;
imageIndex=0;
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( "picture" + i + ".jpg" );
}
} // end of the constructor
// methods of the PictureGallery class
int getArtworksX () {
return (boxPosX);
}
int getArtworksY () {
return (boxPosY);
}
int getArtworksW () {
return (boxPosW);
}
int getArtworksH () {
return (boxPosH);
}
int getIconY () {
return (boxPosY+boxPosH);
}
PImage getImage () {
return images[imageIndex];
}
void flipThrough() {
if (key == CODED) {
if (keyCode == KeyEvent.VK_F1)
{
imageIndex++;
println("imageindeix is:" + imageIndex);
if (imageIndex>images.length-1)
{
imageIndex=0;
}
}
}
}
void display () {
try {
for (int i = 0; i < images.length; i ++ ) {
strokeWeight(4);
strokeJoin(ROUND);
fill (boxClr);
rect (boxPosX-2, boxPosY, boxPosW+4, boxPosH+100);
fill(240); // Set the fill for text instructions
fontHeight=16;
textFont(fontA, fontHeight); // Set the font type and size at Arial 16 for text instructions
text("Drag this box where you please. Press F1 key \nto flip through images in this picture gallery.", boxPosX+marginSpacing, ((boxPosY+boxPosH)+fontHeight+marginSpacing));
text("Click on selection tool then CTRL \nkey to select. Press ALT to paste", boxPosX+marginSpacing+97, ((boxPosY+boxPosH)+3*fontHeight+4*marginSpacing));
rect (boxPosX-2, boxPosY-2, boxPosW+4, boxPosH+4);
image (images[imageIndex], boxPosX, boxPosY, boxPosW, boxPosH);
}
}
catch (ArrayIndexOutOfBoundsException e) {
println ("Hey, that’s not a valid index!");
}
catch (NullPointerException e) {
println( "I can't find this array! ");
}
} // end of the display function
} // end of the Picture Gallery class
abstract class SelectionTool extends InteractiveBoxes {
PImage icon;
int iconXPos, iconYPos, iconW, iconH;
color boxClr;
int selectX, selectY, selectW, selectH;
boolean inside;
// constructor of the abstract SelectionTool class
SelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color tempBoxClr, int tempIconW, int tempIconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
boxClr=tempBoxClr;
iconW=tempIconW;
iconH=tempIconH;
inside=false;
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
} // end of the constructor
// methods of the abstract SelectionTool class
boolean insidePictureGallery () {
if (mousePressed && (mouseX>=artWorks.getArtworksX())&&(mouseX <=(artWorks.getArtworksX()+artWorks.getArtworksW()))&&(mouseY>=artWorks.getArtworksY())&& (mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH())))
{
inside=true;
}
else {
inside=false;
}
return inside;
} // end of the inside function
void click (int mX, int mY) {
if (over==true) {
}
else {
boxPosX=mouseX;
boxPosY=mouseY;
boxPosW=mouseX-boxPosX;
boxPosH=mouseY-boxPosY;
}
} // end the click function
int getSelectionX () {
return (selectX);
}
int getSelectionY () {
return (selectY);
}
int getSelectionW () {
return (selectW);
}
int getSelectionH () {
return (selectH);
}
void release () {
pressed=false;
selectX=boxPosX;
selectY=boxPosY;
selectW=mouseX-boxPosX;
selectH=mouseY-boxPosY;
} // end of release function
abstract void select ();
abstract void display ();
} // end of the SelectionTool class
class RectSelectionTool extends SelectionTool {
// constructor of the RectSelectionTool class
RectSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color boxClr, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, boxClr, iconW, iconH);
icon=loadImage("rectangularmarquee.jpg");
} // end of the constructor
// methods of the RectSelectionTool class
void select () {
if (inside==true && mouseX<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
if (mousePressed) {
rect (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
stroke(0);
}
}
}
void drawSelection () {
if (inside==true && selectX+selectW<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && selectY+selectH<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
rect (selectX, selectY, selectW, selectH);
stroke(0);
}
}
void setToggle () {
if (mousePressed && (mouseX>=iconXPos+iconW) && (mouseX <=iconXPos+2*iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
toggle=2;
println("toggle2");
}
}
void display () {
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
image (icon, iconXPos+iconW, iconYPos);
} // end of the display function
} // end of the RectSelectionTool class
class EllipseSelectionTool extends SelectionTool {
// constructor of the EllipseSelectionTool class
EllipseSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color boxClr, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, boxClr, iconW, iconH);
icon=loadImage ("ellipticalmarquee.jpg");
} // end of the constructor
// methods of the EllipseSelectionTool class
void select () {
if (inside==true && mouseX<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
if (mousePressed) {
ellipse (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
stroke(0);
}
}
}
void drawSelection () {
if (inside==true && selectX+selectW<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && selectY+selectH<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
ellipse (selectX, selectY, selectW, selectH);
stroke(0);
}
}
void setToggle () {
if (mousePressed && (mouseX>=iconXPos) && (mouseX <=iconXPos+iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
toggle=1;
println("toggle1");
}
}
void display () {
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
image (icon, iconXPos, iconYPos);
} // end of the display function
} // end of the EllipseSelectionTool class
class ImageCollage extends InteractiveBoxes {
PImage destination;
int collageX, collageY;
// constructor of the ImageCollage class
ImageCollage (int boxPosX, int boxPosY, int boxPosW, int boxPosH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
collageX=0;
collageY=0;
destination=createImage(selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), RGB);
artWorks.getImage().loadPixels();
for (int x = selectRectangle.getSelectionX(); x < selectRectangle.getSelectionX()+selectRectangle.getSelectionW(); x++ ) {
for (int y = selectRectangle.getSelectionY(); y < selectRectangle.getSelectionY()+selectRectangle.getSelectionH(); y++ ) {
int loc = x + y*artWorks.getImage().width;
float r = red(artWorks.getImage().pixels [loc]);
float g = green(artWorks.getImage().pixels[loc]);
float b = blue(artWorks.getImage().pixels[loc]);
// Set the display pixel to the image pixel
destination.pixels[loc] = color (r, g, b);
}
}
destination.updatePixels();
} // end of the constructor
void copySelection () {
copy (artWorks.getImage(), selectRectangle.getSelectionX(), selectRectangle.getSelectionY(), selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), mouseX, mouseY, selectRectangle.getSelectionW(), selectRectangle.getSelectionH());
}
void click (int mX, int mY) {
collageX=mouseX;
collageY=mouseY;
} // end the click function
void display () {
}
void display(int mX, int mY) {
copy (artWorks.getImage(), selectRectangle.getSelectionX(), selectRectangle.getSelectionY(), selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), collageX, collageY, selectRectangle.getSelectionW(), selectRectangle.getSelectionH());
}
}
I also left a bunch of code in the imageCollage class that is irrelevant right now but it is actually how I would prefer copying the selection: rather than use copy, I would like to use loadPixels() but I don't know how to make it work and it's just a bunch of code I copied from the Shiffman book which I can't get to work so I just left it there in the constructor for now...I am open to suggestions...
boolean selectToolStatus;
int toggle;
PictureGallery artWorks;
RectSelectionTool selectRectangle;
EllipseSelectionTool selectEllipse;
ImageCollage selectPartOfImage;
void setup() {
size (screen.width, screen.height);
background (225, 225, 255);
selectToolStatus=false;
toggle=0;
artWorks=new PictureGallery (50, 140, 330, 360, color (100));
selectRectangle = new RectSelectionTool (0, 0, width, height, color (0, 0, 255), 50, 50);
selectEllipse=new EllipseSelectionTool (0, 0, width, height, color (0, 0, 255), 50, 50);
selectPartOfImage=new ImageCollage (0, 0, 0, 0);
}
void draw() {
background (225, 225, 255);
artWorks.getImage();
artWorks.rollOver();
artWorks.display();
artWorks.getIconY();
artWorks.getArtworksX();
artWorks.getArtworksY();
artWorks.getArtworksW();
artWorks.getArtworksH();
selectEllipse.getSelectionX();
selectEllipse.getSelectionY();
selectEllipse.getSelectionW();
selectEllipse.getSelectionH();
selectRectangle.getSelectionX();
selectRectangle.getSelectionY();
selectRectangle.getSelectionW();
selectRectangle.getSelectionH();
if (keyPressed && key == CODED && keyCode == KeyEvent.VK_CONTROL) {
selectToolStatus=true; // when CONTROL key is pressed, status of the select tools is true
}
else {
selectToolStatus=false; // when CONTROL key is not pressed, status of the select tools is false
}
if (mousePressed && keyPressed && key == CODED && keyCode == KeyEvent.VK_CONTROL) {
if (toggle == 1) {
selectEllipse.select();
}
else if (toggle==2) {
selectRectangle.select();
}
}
if (toggle == 1) {
selectEllipse.drawSelection();
}
else if (toggle==2) {
selectRectangle.drawSelection();
}
selectRectangle.display();
selectEllipse.display();
selectPartOfImage.copySelection();
if (mousePressed && keyPressed && key == CODED && keyCode == KeyEvent.VK_ALT) {
selectPartOfImage.display(mouseX, mouseY);
}
} // end draw
// mouse and keyboard events
void mousePressed () {
artWorks.press(mouseX, mouseY);
selectEllipse.setToggle();
selectRectangle.setToggle();
if (toggle==1) {
selectEllipse.click (mouseX, mouseY);
}
else if (toggle==2) {
selectRectangle.click (mouseX, mouseY);
}
selectRectangle.rollOver();
selectEllipse.rollOver();
selectRectangle.insidePictureGallery();
selectEllipse.insidePictureGallery();
selectPartOfImage.click(mouseX, mouseY);
}
void keyPressed () {
artWorks.flipThrough();
}
void mouseDragged() {
if (selectToolStatus==false) {
artWorks.drag (mouseX, mouseY);
}
}
void mouseReleased () {
artWorks.release();
if (toggle==1) {
selectEllipse.release(); // calculate the ellipse shape if toggle is 1
}
else if (toggle==2) { // calculate the rectangle shape if toggle is 2
selectRectangle.release ();
}
}
abstract class InteractiveBoxes {
int boxPosX, boxPosY, boxPosW, boxPosH;
PFont fontA; // declare a variable that refers to the default font for all the subclasses
int fontHeight;
int marginSpacing;
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;
fontA = loadFont("ArialMT-48.vlw"); // Load the default font that the subclasses will be able to use
fontHeight=48; // set a default value for the font height (determined by the font size limit)
marginSpacing=5;
}
// 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 void display();
}
class PictureGallery extends InteractiveBoxes {
PImage[] images=new PImage[15];
int imageIndex;
color boxClr;
// constructor of the Picture Gallery class
PictureGallery (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color tempBoxClr) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
boxClr=tempBoxClr;
imageIndex=0;
for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( "picture" + i + ".jpg" );
}
} // end of the constructor
// methods of the PictureGallery class
int getArtworksX () {
return (boxPosX);
}
int getArtworksY () {
return (boxPosY);
}
int getArtworksW () {
return (boxPosW);
}
int getArtworksH () {
return (boxPosH);
}
int getIconY () {
return (boxPosY+boxPosH);
}
PImage getImage () {
return images[imageIndex];
}
void flipThrough() {
if (key == CODED) {
if (keyCode == KeyEvent.VK_F1)
{
imageIndex++;
println("imageindeix is:" + imageIndex);
if (imageIndex>images.length-1)
{
imageIndex=0;
}
}
}
}
void display () {
try {
for (int i = 0; i < images.length; i ++ ) {
strokeWeight(4);
strokeJoin(ROUND);
fill (boxClr);
rect (boxPosX-2, boxPosY, boxPosW+4, boxPosH+100);
fill(240); // Set the fill for text instructions
fontHeight=16;
textFont(fontA, fontHeight); // Set the font type and size at Arial 16 for text instructions
text("Drag this box where you please. Press F1 key \nto flip through images in this picture gallery.", boxPosX+marginSpacing, ((boxPosY+boxPosH)+fontHeight+marginSpacing));
text("Click on selection tool then CTRL \nkey to select. Press ALT to paste", boxPosX+marginSpacing+97, ((boxPosY+boxPosH)+3*fontHeight+4*marginSpacing));
rect (boxPosX-2, boxPosY-2, boxPosW+4, boxPosH+4);
image (images[imageIndex], boxPosX, boxPosY, boxPosW, boxPosH);
}
}
catch (ArrayIndexOutOfBoundsException e) {
println ("Hey, that’s not a valid index!");
}
catch (NullPointerException e) {
println( "I can't find this array! ");
}
} // end of the display function
} // end of the Picture Gallery class
abstract class SelectionTool extends InteractiveBoxes {
PImage icon;
int iconXPos, iconYPos, iconW, iconH;
color boxClr;
int selectX, selectY, selectW, selectH;
boolean inside;
// constructor of the abstract SelectionTool class
SelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color tempBoxClr, int tempIconW, int tempIconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
boxClr=tempBoxClr;
iconW=tempIconW;
iconH=tempIconH;
inside=false;
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
} // end of the constructor
// methods of the abstract SelectionTool class
boolean insidePictureGallery () {
if (mousePressed && (mouseX>=artWorks.getArtworksX())&&(mouseX <=(artWorks.getArtworksX()+artWorks.getArtworksW()))&&(mouseY>=artWorks.getArtworksY())&& (mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH())))
{
inside=true;
}
else {
inside=false;
}
return inside;
} // end of the inside function
void click (int mX, int mY) {
if (over==true) {
}
else {
boxPosX=mouseX;
boxPosY=mouseY;
boxPosW=mouseX-boxPosX;
boxPosH=mouseY-boxPosY;
}
} // end the click function
int getSelectionX () {
return (selectX);
}
int getSelectionY () {
return (selectY);
}
int getSelectionW () {
return (selectW);
}
int getSelectionH () {
return (selectH);
}
void release () {
pressed=false;
selectX=boxPosX;
selectY=boxPosY;
selectW=mouseX-boxPosX;
selectH=mouseY-boxPosY;
} // end of release function
abstract void select ();
abstract void display ();
} // end of the SelectionTool class
class RectSelectionTool extends SelectionTool {
// constructor of the RectSelectionTool class
RectSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color boxClr, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, boxClr, iconW, iconH);
icon=loadImage("rectangularmarquee.jpg");
} // end of the constructor
// methods of the RectSelectionTool class
void select () {
if (inside==true && mouseX<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
if (mousePressed) {
rect (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
stroke(0);
}
}
}
void drawSelection () {
if (inside==true && selectX+selectW<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && selectY+selectH<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
rect (selectX, selectY, selectW, selectH);
stroke(0);
}
}
void setToggle () {
if (mousePressed && (mouseX>=iconXPos+iconW) && (mouseX <=iconXPos+2*iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
toggle=2;
println("toggle2");
}
}
void display () {
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
image (icon, iconXPos+iconW, iconYPos);
} // end of the display function
} // end of the RectSelectionTool class
class EllipseSelectionTool extends SelectionTool {
// constructor of the EllipseSelectionTool class
EllipseSelectionTool (int boxPosX, int boxPosY, int boxPosW, int boxPosH, color boxClr, int iconW, int iconH) {
super (boxPosX, boxPosY, boxPosW, boxPosH, boxClr, iconW, iconH);
icon=loadImage ("ellipticalmarquee.jpg");
} // end of the constructor
// methods of the EllipseSelectionTool class
void select () {
if (inside==true && mouseX<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && mouseY<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
if (mousePressed) {
ellipse (boxPosX, boxPosY, mouseX-boxPosX, mouseY-boxPosY);
stroke(0);
}
}
}
void drawSelection () {
if (inside==true && selectX+selectW<=(artWorks.getArtworksX()+artWorks.getArtworksW()) && selectY+selectH<=(artWorks.getArtworksY()+artWorks.getArtworksH()))
{
strokeWeight(1);
stroke(boxClr);
fill (0, 0, 0, 0);
ellipseMode(CORNER);
ellipse (selectX, selectY, selectW, selectH);
stroke(0);
}
}
void setToggle () {
if (mousePressed && (mouseX>=iconXPos) && (mouseX <=iconXPos+iconW) && (mouseY>=iconYPos) && (mouseY<=iconYPos+iconH))
{
toggle=1;
println("toggle1");
}
}
void display () {
iconXPos=artWorks.getArtworksX();
iconYPos=iconH+artWorks.getIconY();
image (icon, iconXPos, iconYPos);
} // end of the display function
} // end of the EllipseSelectionTool class
class ImageCollage extends InteractiveBoxes {
PImage destination;
int collageX, collageY;
// constructor of the ImageCollage class
ImageCollage (int boxPosX, int boxPosY, int boxPosW, int boxPosH) {
super (boxPosX, boxPosY, boxPosW, boxPosH);
collageX=0;
collageY=0;
destination=createImage(selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), RGB);
artWorks.getImage().loadPixels();
for (int x = selectRectangle.getSelectionX(); x < selectRectangle.getSelectionX()+selectRectangle.getSelectionW(); x++ ) {
for (int y = selectRectangle.getSelectionY(); y < selectRectangle.getSelectionY()+selectRectangle.getSelectionH(); y++ ) {
int loc = x + y*artWorks.getImage().width;
float r = red(artWorks.getImage().pixels [loc]);
float g = green(artWorks.getImage().pixels[loc]);
float b = blue(artWorks.getImage().pixels[loc]);
// Set the display pixel to the image pixel
destination.pixels[loc] = color (r, g, b);
}
}
destination.updatePixels();
} // end of the constructor
void copySelection () {
copy (artWorks.getImage(), selectRectangle.getSelectionX(), selectRectangle.getSelectionY(), selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), mouseX, mouseY, selectRectangle.getSelectionW(), selectRectangle.getSelectionH());
}
void click (int mX, int mY) {
collageX=mouseX;
collageY=mouseY;
} // end the click function
void display () {
}
void display(int mX, int mY) {
copy (artWorks.getImage(), selectRectangle.getSelectionX(), selectRectangle.getSelectionY(), selectRectangle.getSelectionW(), selectRectangle.getSelectionH(), collageX, collageY, selectRectangle.getSelectionW(), selectRectangle.getSelectionH());
}
}
1