papyrus logo

Papyrus' use of the MVC (Model-View-Controller) paradigm

Papyrus utilizes the MVC paradigm to separate the scenegraph from its display and manipulation.
The Scenegraph is the Model
All papyrus drawables, shapes, rectangles, circles, et. al. inherit from the base class Renderable which provides Renderable::render.
Although the common case is that the root of a scenegraph consists of a Group or Canvas object, in fact a scenegraph in papyrus can consist of anything that inherits from Renderable and is capable of being rendered into a cairo context.
The Cairo Context is the View
The scenegraph by itself provides no mechanism for actually viewing the scenegraph, and no mechanisms exist within the papyrus library. To be viewed a scenegraph must be rendered into a cairo context.
Within the papyrus-gtkmm library is the Viewport class which creates a cairo context suitable for rendering into a Gtkmm window. The Viewport class also creates a Canvas and associates the canvas with the Gtkmm cairo context. Thus, the Viewport brings together the Model and View.
The Controller
In the MVC paradigm the controller processes and handles events effecting changes upon the model. In papyrus the classes derived from Renderable have mechanisms for manipulating their characteristics within the scenegraph, but do not have methods for responding to events such as mouse button clicks, mouse motion, et. al.
Papyrus provides a framework representing the controller in the MVC paradigm with the base class Controller. Derived classes such as Selector, Translator, AffineAnimator, et. al. respond to events and cause various effects upon the objects associated with them.
You'll notice that not all controllers respond to user driven events. A key example of this is the Animator class which also responds to time based events.
The aforementioned Viewport class within the papyrus-gtkmm library also allows papyrus controllers to be associated with it. When a controller is associated with the Viewport all Gtkmm events are passed from the Viewport to the associated controllers.
As a result, the Viewport class is a prime example of how to bring all three components of the MVC paradigm (papyrus scenegraph, cairo context, papyrus controller) together.

Generated on Fri Apr 16 12:41:04 2010 for papyrus by doxygen 1.6.1