Selecting a circle and filling color in it

Hi

I am writing a Doodle like program. In this i am drawing figures like
square, circle line etc on screen as user clicks on the screen. I am
able to do that. I have created a color panel where user can select
the color. Now I want to fill color in them. How do I go about it? any
Ideas or suggestions or code snippets are welcome!!!

Main Concerns

1) How do I decide if the user has clicked within the figure for
different figures rect/square/line?
2) What if there are more than one figures on screen? How do I decide
which one is selected
3) Do I have to use pyOpenGl for all this?. Idont have much experience
in that? Is there any other method?

Thanks

madhura wrote:

1) How do I decide if the user has clicked within the figure for
different figures rect/square/line?

> 2) What if there are more than one figures on screen? How do I decide
> which one is selected

There are lots of ways, but I think the easiest and most robust is some version of drawing the figures, each in a different color, and then checking the color of the pixel where clicked -- or, on the click, just draw each figure to a small off-screen bitmap, and see if the pixel in consideration changes color. (you can do a bounding box check first, so that you don't draw everything, or even better, use a spatial index, such as an rtree)

An alternative is to use math (coordinate geometry), but this gets difficult really fast if your figures are complex.

3) Do I have to use pyOpenGl for all this?

Not at all -- unless you want really fast rendering of lots of data -- but it's much harder to use than DCs or GraphicsContext.

Is there any other method?

unless you are doing this primarily as a learning exercise (and even if you are...), don't do it all from scratch. See:

wx.lib.floatcanvas

or the new version (FloatCanvas2)in SVN:

http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/branches/FloatCanvas/SOC2008_FloatCanvas/floatcanvas2/

or PySketch, the simple drawing demo that comes with wxPython:

http://svn.wxwidgets.org/svn/wx/wxPython/trunk/samples/pySketch/

or this nifty project from Steve sproat:

https://launchpad.net/whyteboard

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks for the suggestions!

That helps a lot. I will look through all of it and try implementing
it.

···

On Dec 4, 11:59 am, Christopher Barker <Chris.Bar...@noaa.gov> wrote:

madhura wrote:
> 1) How do I decide if the user has clicked within the figure for
> different figures rect/square/line?

> 2) What if there are more than one figures on screen? How do I decide
> which one is selected

There are lots of ways, but I think the easiest and most robust is some
version of drawing the figures, each in a different color, and then
checking the color of the pixel where clicked -- or, on the click, just
draw each figure to a small off-screen bitmap, and see if the pixel in
consideration changes color. (you can do a bounding box check first, so
that you don't draw everything, or even better, use a spatial index,
such as an rtree)

An alternative is to use math (coordinate geometry), but this gets
difficult really fast if your figures are complex.

> 3) Do I have to use pyOpenGl for all this?

Not at all -- unless you want really fast rendering of lots of data --
but it's much harder to use than DCs or GraphicsContext.

> Is there any other method?

unless you are doing this primarily as a learning exercise (and even if
you are...), don't do it all from scratch. See:

wx.lib.floatcanvas

or the new version (FloatCanvas2)in SVN:

http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/branches/FloatCanva

or PySketch, the simple drawing demo that comes with wxPython:

http://svn.wxwidgets.org/svn/wx/wxPython/trunk/samples/pySketch/

or this nifty project from Steve sproat:

Whyteboard in Launchpad

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Bar...@noaa.gov