Advanced Events

F

frank

Good Morning All,
I am working on a CAD application. At the time of this writing I am
currently working on the GraphicsEngine. The structure is as follows:

GraphicsObject (Base Class, Must Inherit)
ShapeObject (Must Inherit)
Derived Classes()
TestObject (Must Inherite)
Derived Classes()
Derived Classes()

GraphicsObject does not inherit form anyone.
I am working with VB.NET 2005 enterprise edition.

My problem is as such: I need to handle mouse events. I can easly
enough fire them using an outside class and performing a HitTest on the
region. However I would like the indivudal objects to handle there own
events to some extend.
E.G:
If a rectangle is draw on the screen. The rectangle is a derived class
of the shapeObject. When the mouse is clicked inside its bounds the
border should be "Selected." As I said I know how to do this from
another class, but I can't figure out how to link the mouse/ keyboard
events to the base class.

Thank You,
Frank
 
L

Larry Lard

frank said:
Good Morning All,
I am working on a CAD application. At the time of this writing I am
currently working on the GraphicsEngine. The structure is as follows:

GraphicsObject (Base Class, Must Inherit)
ShapeObject (Must Inherit)
Derived Classes()
TestObject (Must Inherite)
Derived Classes()
Derived Classes()

GraphicsObject does not inherit form anyone.
I am working with VB.NET 2005 enterprise edition.

My problem is as such: I need to handle mouse events. I can easly
enough fire them using an outside class and performing a HitTest on the
region. However I would like the indivudal objects to handle there own
events to some extend.
E.G:
If a rectangle is draw on the screen. The rectangle is a derived class
of the shapeObject.

Careful - it might be that you have a Ractangle derived from
ShapeObject, but the thing that's actually *drawn* is just some pixels
on an image.
When the mouse is clicked inside its bounds the
border should be "Selected." As I said I know how to do this from
another class, but I can't figure out how to link the mouse/ keyboard
events to the base class.

Yes, this is the key to the problem. How about this: when you ask the
objects to draw themselves on some Graphics, also ask them to return a
Region representing their presence on the Graphics. Each time you
refresh the drawing, recreate a map (hashtable) of
Region->GraphicsObject. When you receive a mouse click (or whatever),
go through that map and check Region.IsVisible for the point where the
mouse was clicked. If you get a hit, then call (say)
GraphicsObject.OnClick for that object. Make OnClick a MustInherit
method in the base base class.

There might be issues with z-ordering with this method, so I suppose
store a z-order with each region and only OnMouseClick for the latest
drawn GraphicsObject.

Actually wiring up events direct to the objects without any middle
layer looks hard to me, since in the first instance it's always a
PictureBox or whatever that actually receives the Click event.
 
F

frank

Larry,
It's good to "meet" you. Thank you for the advice. I will look into it
this afternoon. I'll let you know how I turn out, and provide some more
information. I realize that there is probally not enough space for all
the infomation needed here.

Best regards,
Frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top