/*-----------------------------------------------------------------------------*/ void DefineButtons() { // Define and create image button for RUN panel PImage b = loadImage("BtnConfigN.gif"); PImage r = loadImage("BtnConfigO.gif"); PImage d = loadImage("BtnConfigP.gif"); int x = 845; int y = 765; int w = b.width; int h = b.height; BtnConfig = new ImageButtons(x, y, w, h, b, r, d); PImage b2 = loadImage("BtnQuitN.gif"); PImage r2 = loadImage("BtnQuitO.gif"); PImage d2 = loadImage("BtnQuitP.gif"); int x2 = 945; int y2 = 765; int w2 = b.width; int h2 = b.height; BtnQuit = new ImageButtons(x2, y2, w2, h2, b2, r2, d2); PImage b4 = loadImage("BtnRunN.gif"); PImage r4 = loadImage("BtnRunO.gif"); PImage d4 = loadImage("BtnRunP.gif"); int x4 = 845; int y4 = 765; int w4 = b.width; int h4 = b.height; BtnRun = new ImageButtons(x4, y4, w4, h4, b4, r4, d4); PImage b3 = loadImage("BtnSendN.gif"); PImage r3 = loadImage("BtnSendO.gif"); PImage d3 = loadImage("BtnSendP.gif"); int x3 = 1170; int y3 = 500; int w3 = b.width; int h3 = b.height; BtnSendSpeed = new ImageButtons(x3, y3, w3, h3, b3, r3, d3); PImage b6 = loadImage("BtnSendN.gif"); PImage r6 = loadImage("BtnSendO.gif"); PImage d6 = loadImage("BtnSendP.gif"); int x6 = 1170; int y6 = 550; int w6 = b.width; int h6 = b.height; BtnSendDist = new ImageButtons(x6, y6, w6, h6, b6, r6, d6); PImage b5 = loadImage("BtnSendN.gif"); PImage r5 = loadImage("BtnSendO.gif"); PImage d5 = loadImage("BtnSendP.gif"); int x5 = 1170; int y5 = 600; int w5 = b.width; int h5 = b.height; BtnSendXY = new ImageButtons(x5, y5, w5, h5, b5, r5, d5); PImage b7 = loadImage("BtnVersionN.gif"); PImage r7 = loadImage("BtnVersionO.gif"); PImage d7 = loadImage("BtnVersionP.gif"); int x7 = 1170; int y7 = 650; int w7 = b.width; int h7 = b.height; BtnSendVersion = new ImageButtons(x7, y7, w7, h7, b7, r7, d7); PImage b8 = loadImage("BtnHaltN.gif"); PImage r8 = loadImage("BtnHaltO.gif"); PImage d8 = loadImage("BtnHaltP.gif"); int x8 = 845; int y8 = 715; int w8 = b.width; int h8 = b.height; BtnSendHalt = new ImageButtons(x8, y8, w8, h8, b8, r8, d8); PImage b9 = loadImage("BtnResetN.gif"); PImage r9 = loadImage("BtnResetO.gif"); PImage d9 = loadImage("BtnResetP.gif"); int x9 = 945; int y9 = 715; int w9 = b.width; int h9 = b.height; BtnSendReset = new ImageButtons(x9, y9, w9, h9, b9, r9, d9); // Define and create image button for Config panel PImage b10 = loadImage("BtnSendN.gif"); PImage r10 = loadImage("BtnSendO.gif"); PImage d10 = loadImage("BtnSendP.gif"); int x10 = 1190; int y10 = 48; int w10 = b.width; int h10 = b.height; BtnSendCfgKSpeed1 = new ImageButtons(x10, y10, w10, h10, b10, r10, d10); PImage b11 = loadImage("BtnSendN.gif"); PImage r11 = loadImage("BtnSendO.gif"); PImage d11 = loadImage("BtnSendP.gif"); int x11 = 1190; int y11 = 98; int w11 = b.width; int h11 = b.height; BtnSendCfgKSpeed2 = new ImageButtons(x11, y11, w11, h11, b11, r11, d11); PImage b12 = loadImage("BtnSendN.gif"); PImage r12 = loadImage("BtnSendO.gif"); PImage d12 = loadImage("BtnSendP.gif"); int x12 = 1190; int y12 = 148; int w12 = b.width; int h12 = b.height; BtnSendCfgKAngle = new ImageButtons(x12, y12, w12, h12, b12, r12, d12); PImage b13 = loadImage("BtnSendN.gif"); PImage r13 = loadImage("BtnSendO.gif"); PImage d13 = loadImage("BtnSendP.gif"); int x13 = 1190; int y13 = 198; int w13 = b.width; int h13 = b.height; BtnSendCfgKDist = new ImageButtons(x13, y13, w13, h13, b13, r13, d13); PImage b14 = loadImage("BtnSendN.gif"); PImage r14 = loadImage("BtnSendO.gif"); PImage d14 = loadImage("BtnSendP.gif"); int x14 = 1190; int y14 = 258; int w14 = b.width; int h14 = b.height; BtnSendCfgWheels = new ImageButtons(x14, y14, w14, h14, b14, r14, d14); PImage b18 = loadImage("BtnSendN.gif"); PImage r18 = loadImage("BtnSendO.gif"); PImage d18 = loadImage("BtnSendP.gif"); int x18 = 1190; int y18 = 313; int w18 = b.width; int h18 = b.height; BtnSendCfgKvel = new ImageButtons(x18, y18, w18, h18, b18, r18, d18); PImage b15 = loadImage("BtnSendN.gif"); PImage r15 = loadImage("BtnSendO.gif"); PImage d15 = loadImage("BtnSendP.gif"); int x15 = 1190; int y15 = 368; int w15 = b.width; int h15 = b.height; BtnSendCfgRS232 = new ImageButtons(x15, y15, w15, h15, b15, r15, d15); PImage b16 = loadImage("BtnLoadN.gif"); PImage r16 = loadImage("BtnLoadO.gif"); PImage d16 = loadImage("BtnLoadP.gif"); int x16 = 845; int y16 = 715; int w16 = b.width; int h16 = b.height; BtnSendCfgLoad = new ImageButtons(x16, y16, w16, h16, b16, r16, d16); PImage b17 = loadImage("BtnSaveN.gif"); PImage r17 = loadImage("BtnSaveO.gif"); PImage d17 = loadImage("BtnSaveP.gif"); int x17 = 945; int y17 = 715; int w17 = b.width; int h17 = b.height; BtnSendCfgSave = new ImageButtons(x17, y17, w17, h17, b17, r17, d17); } /*-----------------------------------------------------------------------------*/ void InputFieldsDefinition() { // Define and create input fields for Main panel GuiRun = new GUIController(this); InputSpeed = new IFTextField("", 1043, 503, 67); InputSpeed.addActionListener(this); GuiRun.add(InputSpeed); InputDist = new IFTextField("", 1043, 553, 67); InputDist.addActionListener(this); GuiRun.add(InputDist); InputCoordY = new IFTextField("", 1043, 603, 67); InputCoordY.addActionListener(this); GuiRun.add(InputCoordY); InputCoordX = new IFTextField("", 923, 603, 67); InputCoordX.addActionListener(this); GuiRun.add(InputCoordX); int YbaseInputFields = 53; int XbaseInputFields = 893; // Define and create input fields for Config panel GuiConfig = new GUIController(this); InputSpeed1Kp = new IFTextField("", XbaseInputFields, YbaseInputFields, 73); InputSpeed1Kp.addActionListener(this); InputSpeed1Ki = new IFTextField("", XbaseInputFields+100, YbaseInputFields, 73); InputSpeed1Ki.addActionListener(this); InputSpeed1Kd = new IFTextField("", XbaseInputFields+200, YbaseInputFields, 73); InputSpeed1Kd.addActionListener(this); InputSpeed2Kp = new IFTextField("", XbaseInputFields, YbaseInputFields+50, 73); InputSpeed2Kp.addActionListener(this); InputSpeed2Ki = new IFTextField("", XbaseInputFields+100, YbaseInputFields+50, 73); InputSpeed2Ki.addActionListener(this); InputSpeed2Kd = new IFTextField("", XbaseInputFields+200, YbaseInputFields+50, 73); InputSpeed2Kd.addActionListener(this); InputAngleKp = new IFTextField("", XbaseInputFields, YbaseInputFields+100, 73); InputAngleKp.addActionListener(this); InputAngleKi = new IFTextField("", XbaseInputFields+100, YbaseInputFields+100, 73); InputAngleKi.addActionListener(this); InputAngleKd = new IFTextField("", XbaseInputFields+200, YbaseInputFields+100, 73); InputAngleKd.addActionListener(this); InputDistKp = new IFTextField("", XbaseInputFields, YbaseInputFields+150, 73); InputDistKp.addActionListener(this); InputDistKi = new IFTextField("", XbaseInputFields+100, YbaseInputFields+150, 73); InputDistKi.addActionListener(this); InputDistKd = new IFTextField("", XbaseInputFields+200, YbaseInputFields+150, 73); InputDistKd.addActionListener(this); InputAxle = new IFTextField("", XbaseInputFields, YbaseInputFields+210, 73); InputAxle.addActionListener(this); InputKsp1 = new IFTextField("", XbaseInputFields+100, YbaseInputFields+210, 73); InputKsp1.addActionListener(this); InputKsp2 = new IFTextField("", XbaseInputFields+200, YbaseInputFields+210, 73); InputKsp2.addActionListener(this); InputKvel1 = new IFTextField("", XbaseInputFields+100, YbaseInputFields+265, 73); InputKvel1.addActionListener(this); InputKvel2 = new IFTextField("", XbaseInputFields+200, YbaseInputFields+265, 73); InputKvel2.addActionListener(this); InputRS232bps = new IFTextField("", XbaseInputFields+100, YbaseInputFields+320, 73); InputRS232bps.addActionListener(this); InputRS232Com = new IFTextField("", XbaseInputFields+200, YbaseInputFields+320, 73); InputRS232Com.addActionListener(this); } /*-----------------------------------------------------------------------------*/ void InputFieldsRun() // input fields for Main panel { GuiConfig.remove(InputSpeed1Kp); GuiConfig.remove(InputSpeed1Ki); GuiConfig.remove(InputSpeed1Kd); GuiConfig.remove(InputSpeed2Kp); GuiConfig.remove(InputSpeed2Ki); GuiConfig.remove(InputSpeed2Kd); GuiConfig.remove(InputAngleKp); GuiConfig.remove(InputAngleKi); GuiConfig.remove(InputAngleKd); GuiConfig.remove(InputDistKp); GuiConfig.remove(InputDistKi); GuiConfig.remove(InputDistKd); GuiConfig.remove(InputAxle); GuiConfig.remove(InputKsp1); GuiConfig.remove(InputKsp2); GuiConfig.remove(InputKvel1); GuiConfig.remove(InputKvel2); GuiConfig.remove(InputRS232bps); GuiConfig.remove(InputRS232Com); GuiRun.add(InputSpeed); GuiRun.add(InputDist); GuiRun.add(InputCoordX); GuiRun.add(InputCoordY); } /*-----------------------------------------------------------------------------*/ void InputFieldsConfig() // input fields for Config panel { GuiRun.remove(InputSpeed); GuiRun.remove(InputDist); GuiRun.remove(InputCoordX); GuiRun.remove(InputCoordY); GuiConfig.add(InputSpeed1Kp); GuiConfig.add(InputSpeed1Ki); GuiConfig.add(InputSpeed1Kd); GuiConfig.add(InputSpeed2Kp); GuiConfig.add(InputSpeed2Ki); GuiConfig.add(InputSpeed2Kd); GuiConfig.add(InputAngleKp); GuiConfig.add(InputAngleKi); GuiConfig.add(InputAngleKd); GuiConfig.add(InputDistKp); GuiConfig.add(InputDistKi); GuiConfig.add(InputDistKd); GuiConfig.add(InputAxle); GuiConfig.add(InputKsp1); GuiConfig.add(InputKsp2); GuiConfig.add(InputKvel1); GuiConfig.add(InputKvel2); GuiConfig.add(InputRS232bps); GuiConfig.add(InputRS232Com); } /*-----------------------------------------------------------------------------*/ void actionPerformed(GUIEvent e) // an event on input fields { if (e.getMessage().equals("Completed")) { //SendSpeed(); } } /*-----------------------------------------------------------------------------*/ void mouseReleased() { ReleasedFlag = true; } /*-----------------------------------------------------------------------------*/ class Button { int x, y; int w, h; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; boolean released = false; void pressed() { if(over && mousePressed) { pressed = true; } else { pressed = false; } } void released() { if(over && ReleasedFlag) { released = true; ReleasedFlag = false; } else { released = false; } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } } } class ImageButtons extends Button { PImage base; PImage roll; PImage down; PImage currentimage; ImageButtons(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll, PImage idown) { x = ix; y = iy; w = iw; h = ih; base = ibase; roll = iroll; down = idown; currentimage = base; } void update() { over(); pressed(); released(); if(pressed) { currentimage = down; } else if (over){ currentimage = roll; } else { currentimage = base; } } void over() { if( overRect(x, y, w, h) ) { over = true; } else { over = false; } } void display() { image(currentimage, x, y); } }