I'm trying to optimize my program's excessive amount redraw. I'm wanting to derive a technique that checks to see if the state of things has changed visually and if they have, redraw, update whatever. If they haven't then I want to put these items into some sort of image buffer. so that there is only ever one image being redrawn of on the canvas (in the main draw loop) when things are idol.
Hope this makes sense. Here is a small section of the code from what I am working on. It would be awesome if someone could edit this code and show me an example of how to implement this. Please note I am not looking to use the loop() and noLoop() functions as this means that the rollover functions cant not update when the entire program is at a halt.
Thanks in advance!
BezierSection bezSection1;
void setup() { size(600, 400); noStroke(); smooth(); bezSection1 = new BezierSection(1, new PVector(60, 300), new PVector(300, 300), new PVector( 200,90), new PVector(440,90)); }
// release any point attached to the mouse void mouseReleased () { bezSection1.release(); }
// for dragg'n dem points void mousePressed () { bezSection1.press(); }
class BezierSection {
// variables for control and anchor points. int pts = 4; int ptSize = 8; float[]x = new float[4]; float[]y = new float[4]; boolean[]isDragSafe = new boolean[4]; float[]xOld = new float[4]; float[]yOld = new float[4]; float[]xOffset = new float[4]; float[]yOffset = new float[4]; boolean[]over = new boolean[4]; boolean hasChanged =false;
I'm writing my own text field and was wondering how I might go supporting copy and paste. I want to be able to copy and paste from one field to another and also from outside of the app. Like copying from a text editor to the processing applet.
I'm having some trouble with the cursor() function. If you run the code below you will see that the cursor only turns into a hand when rolling over button2. button1 changes colour when you roll over it but the cursor does not change to a hand.
Can anyone tell me if I am doing this wrong? The example is straight out the Processing Hand Book. I just added Cursor (Hand); to the void display() block.
Thanks in Advance,
Dan.
Button button1, button2;
void setup() { size(200, 200); // Inputs: x, y, size, // base color, over color, press color button1 = new Button(25, 25, 20, color(204), color(255), color(0)); button2 = new Button(25, 80, 20, color(204), color(255), color(0)); }
void mouseReleased() { button1.release(); button2.release(); } class Button { int x, y; // The x- and y-coordinates int size; // Dimension (width and height) color baseGray; // Default gray value color overGray; // Value when mouse is over the button color pressGray; // Value when mouse is over and pressed boolean over = false; // True when the mouse is over boolean pressed = false; // True when the mouse is over and pressed
Button(int xp, int yp, int s, color b, color o, color p) { x = xp; y = yp; size = s; baseGray = b; overGray = o; pressGray = p; }
// Updates the over field every frame void update() { if ((mouseX >= x) && (mouseX <= x + size) && (mouseY >= y) && (mouseY <= y + size)) { over = true; } else { over = false; } }