Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to make toolbars for paint program

$
0
0

I'm very, VERY new to Processing and coding in general (I know a little bit of JavaScript and Python, but that's about it). I'm trying to build a simple paint program and am having trouble constructing the toolbar. I want it to work where the user right-clicks within a certain box and the tool changes (eventually, I'll have draw, fill, etc.) Right now I'm working on choosing to create shapes (the commented out 'newShape' function at the bottom), but I can't put mousePressed within a new function I'm trying to create, and I'm not sure how else to do it. Can someone break this down for me (ELI5?) Thank you!

int button_height =35;
int button_width = 100;
color fill_color;
import controlP5.*;

ControlP5 cp5;

Textlabel drawRectangleLabel;
Textlabel myTextlabelB;


void setup()
{
 size(800, 500);
  cp5 = new ControlP5( this );
  background(255);
  drawRectangleLabel = cp5.addTextlabel("label")
                    .setText("Create a rectangle")
                    .setPosition(0,12)
                    .setColorValue(0)
                    .setFont(createFont("Georgia",11))
                    ;
}

void draw()
{
     drawTools();
}
void drawTools()
{
     stroke (0,0,0);
     fill (255);
     rect (0, 0, button_width, button_height);
     stroke (0,0,0);
     fill (255,0,0);
     rect (button_width, 0, button_width, button_height); // right now I'm testing this by creating ellipses with different colors when different boxes are selected, but eventually these will be different tools
     stroke (0,0,0);
     fill (0, 0, 255);
     rect (button_width*2, 0, button_width, button_height);
}
void mousePressed()
{
    if (mouseButton==RIGHT)
    {
         int toolnumber = (int)(mouseX /
button_width);
         println(toolnumber);
         switch(toolnumber)
{
              case 0:
                   println("newShape");
                   //newShape();//When users right-click in this box, I want them to be able to create shapes using the function below
                   break;
              case 1:
                    fill_color = color (255,0,0);
                    break;
              case 2: //set colour to blue
                  fill_color = color(0, 0, 255);
                  break;
         }
    }
    if (mouseButton==LEFT)
     {
           fill (fill_color);
           ellipse( mouseX, mouseY, 100, 100);
     }
}

//void newShape()
//{
//  int startx,starty;
//  int endx,endy;
//  int sizex,sizey;
//  void mousePressed()
//  {
//    startx=mouseX;
//    starty=mouseY;
//  }
//  void mouseReleased()
//  {
//    endx=mouseX;
//    endy=mouseY;
//    sizex = endx-startx;
//    sizey=endy-starty;
//    rect(startx,starty,sizex,sizey);
//  }
//

Viewing all articles
Browse latest Browse all 2896

Trending Articles