开发者

MVC Mouse events in view design question

This is a design question regarding an MVC implementation. I am creating a 2D graphic app using QT and OpenGL but I do not think the technology matters.

So my view is an openGL widget, whatever is to be drawn is stored n the model and the controller should modify the model and have the OpenGL widget redraw the scene.

The view should capture the following mouse events, MouseRelease, MouseDown and MouseMove and then transfer them to the controller to make the proper decision on what to do when the user clicks or drags the mouse.

I am debating between 2 approaches, incapsulate the mouse handling inside the OpenGL widget and just report the click and drag back to the controller? Or transfer the mouse events as is to the controller and let it handle all the logic to determine the 开发者_开发问答clicks and drags.

Any advise is very apreciated. Thank you


I think the widget is going to be getting mouse coordinates in the viewport/"view space" coordinate system, which may not make much sense to the controller. I think your widget should convert the co-ordinates of any clicks and drags to world space, then pass them to the controller.

Why is this good? Because it avoids your controller needing any special knowledge of the viewport/widget, and so preserves encapulation. If you add more viewports/widgets or maybe even a console or a script that also wants to feed the controller, they can all pass their "instructions" in world space and the controller will function quite happily. Your viewport is already "aware" of "world space" and "view space" or it couldn't have rendered your model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜