We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Changing colour of a cursor possible
Page Index Toggle Pages: 1
Changing colour of a cursor possible? (Read 1541 times)
Changing colour of a cursor possible?
May 12th, 2010, 11:01am
 
Hi all,

Thoroughly impressed with Processing!  Thank you!

I have a question:-

I am writing  a paint application and have a circle as a custom cursor.  The circle is white.  Is it possible to change the colour of the cursor?

Thanks! Smiley
Re: Changing colour of a cursor possible?
Reply #1 - May 12th, 2010, 1:04pm
 
Not 100% sure of what you're trying to achieve, but perhaps this function could help you. More specifically: cursor(image, x, y)
Re: Changing colour of a cursor possible?
Reply #2 - May 12th, 2010, 1:11pm
 
not with the standard cursor. but like amnonP5 suggested, just replace the cursor with a cursor drawn by yourself. Hide the cursor using
http://processing.org/reference/noCursor_.html
and use begin/endshape or an svg as cursor. But you can also use an image and tint()to color it would be possible.

Re: Changing colour of a cursor possible?
Reply #3 - May 13th, 2010, 9:07am
 
Thanks for the feedback.

I wish to change to colour of the cursor dependant on what colour is selected from a colour picker.  

So if the user picks red, I want the colour of the cursor to change to red so they can see they will be painting with a red brush.

Hope this helps?

I can't create a custom icon for every size and every colour selectable - this would mean in excess of 1000 cursors Wink
Re: Changing colour of a cursor possible?
Reply #4 - May 13th, 2010, 11:24am
 
ok, if that is what you want. you just draw an ellipse(or whatever your brush looks like ) as cursor and fill() and scale it.

something like this

fill(brushColor);
ellipse(mouseX,mouseY,brushScale,brushScale);

Re: Changing colour of a cursor possible?
Reply #5 - May 13th, 2010, 11:43am
 
In addition to all the above suggestions, here is a code example of using a SVG as a cursor and then custom coloring it in Processing. Just threw this together quickly, so there may be better ways of doing it. Put the SVG in the data folder of your sketch.

Code:
PShape cursorsvg;
PGraphics cursorcolored;

void setup() {
 size(500,500);
 background(0);

 // load the custom cursor shape from svg
 cursorsvg = loadShape("cursor.svg");

 // create PGraphic for changing colors
 cursorcolored = createGraphics(30, 30, JAVA2D);
}

void draw() {

 // draw the svg with custom colors to PGraphic
 // this is just an example with different fill and stroke
 // when the mouse goes either left or right from the center
 cursorcolored.beginDraw();
   cursorsvg.disableStyle();
   if (mouseX < width/2)
   {cursorcolored.fill(200, 0, 0);cursorcolored.stroke(255);}
   if (mouseX >= width/2)
   {cursorcolored.fill(0,0,200);cursorcolored.stroke(255,255,0);}
   cursorcolored.shape(cursorsvg, 0, 0);
 cursorcolored.endDraw();

 // use the PGraphic as an image for cursor function
 cursor(cursorcolored);
}

Re: Changing colour of a cursor possible?
Reply #6 - May 14th, 2010, 6:38am
 
Thanks very much for you help - this worked extremely well!!  THANK YOU!!!!!!!!!!! Smiley
Page Index Toggle Pages: 1