Skip to main content
GameDev.net gamedev.net
🔒 Locked

MVC Help

Started by hick18 Jun 23, 2010 at 7:45 AM 0 replies 500+ views
Original Post
hick18
hick18
Im creating an application that basically just displays nodes linked by lines, which the user can perform the following :

- Add a node
- Delete a node
- Move a node
- Join a node to another node

So i figured for this I could use the MVC design pattern, where the model would store the list of nodes, the view would display the nodes on screen, and then the controller would allow for the previously mentioned operations. But I'm having trouble implementing it. I basically have a single win32 window, and I use GDI to draw the nodes and lines, and at the moment I have the operations be performed on windows notifications, as the window has a pointer to the node list.

So when I recieve a message from a drop down menu to add a node, a node is added to the list.

when I recieve a message from a drop down menu to delete a node, a node is deleted, provided one has been selected. Where I store the selected node on mouse click events.

Same with moving, provided a node is selected, and a mouse move event occurs, I move the selected node.

Node joining just works by joined the node on a mouse down event with the node on a mouse up event.

But this doesnt sound like the MVC controller. I seem to have mixed the View and controller into one, and the View modifies the model. How would you go about doing what Im doing?

There is some stuff I can move such as, intstead the model coud register with the view, so that messages such as Add and delete node are instead sent to the model. But what about moving nodes? The view needs access to the nodelist so it can perform the collision detection of the clicking to mark selected nodes. And movement is all really done in the views window dimensions.
Buckeye
Buckeye
First, there's nothing wrong with a custom MVC implementation. Do what works for you.

However, in 2 MVC architectures I've implemented, the view does not interpret any relationship between the model and user events. The view reports user events (perhaps converting from screen space to world space) to the controller and the controller would either interpret the event with regard to the model or pass the information to the model to interpret.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.