diff --git a/drawing/drawing.pde b/drawing/drawing.pde index da26bf0..aa773dd 100644 --- a/drawing/drawing.pde +++ b/drawing/drawing.pde @@ -1,10 +1,23 @@ final int DRAW_NORMAL=1; final int DRAW_DRAG=2; final int Vertex_Rad=8; +// define parameters for rectangular button + int rectX=500, rectY=500; + int rectwidth=80; + int rectheight=40; + color rectColor; + color rectHighlight; + boolean rectover=false; + Vertex drag_start; Vertex vertex_under_mouse; void setup() { - size(640, 360); + size(600, 600); + background(255); + rectColor=(150); + rectHighlight=color(255,0,0); + rectX=500; + rectY=500; noStroke(); } Graph G=new Graph(); @@ -17,6 +30,9 @@ void draw() { for(Vertex i:G.V){ i.draw(); } + + mouse_over_BUTTON(); + //Draw Edges strokeWeight(2); for(Edge i:G.E){ @@ -30,6 +46,15 @@ void draw() { //Draw the dragged line; } } + +boolean check_mouse_over_button(int x, int y,int _height,int _width){ + if(mouseY>=y && (mouseY-y<_height) &&(mouseX-x<_width)&& mouseX>=x) + rectover=true; + else rectover=false; + + return rectover; + +} void mouseMoved(){ vertex_under_mouse=null; for(Vertex i:G.V){ @@ -45,7 +70,7 @@ void mouseDragged(){ } void mousePressed(){ - if(vertex_under_mouse==null){ + if(vertex_under_mouse==null && !check_mouse_over_button(rectX,rectY,rectheight,rectwidth)){ G.V.add(new Vertex(mouseX, mouseY,true)); } } @@ -63,3 +88,50 @@ void mouseReleased(){ } } } + + +void mouse_over_BUTTON(){ + + if(check_mouse_over_button(rectX,rectY,rectheight,rectwidth)){ + fill(255,0,0); + }else { + fill(rectColor); + } + noStroke(); + rect(rectX,rectY,rectwidth,rectheight); + textSize(10); + fill(0, 0, 0); + text("Initial Graph",rectX+rectwidth/8,rectY+rectheight/2); + +} + + + +void mouseClicked(){ + if(check_mouse_over_button(rectX,rectY,rectheight,rectwidth)) + //draw edges should be implemented by pressing button. + for(int i=0;i