Pen Tablet Support/Unconstrained Drawing API

From OLPC

< Pen Tablet Support
Revision as of 15:15, 15 April 2008 by Pdubroy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

"Unconstrained drawing" describes the case where the area that the user wishes to draw on is bigger and/or does not have the same aspect ratio as the physical Pen Tablet. The Paint activity is a good example of this case.

This is a first cut at an API for unconstrained drawing. Comments are welcome.

API

An activity that already supports some form of drawing using the mouse/touchpad can add tablet support by using the TabletBox container widget to wrap the window that receives the mouse events for drawing (e.g. a gtk.gdk.Window or a gtk.DrawingArea)

 from sugar.graphics.tabletbox import TabletBox
 
 ...
 
 class MyDrawingActivity(activity.Activity):
 
     def __init__(self, handle):
         activity.Activity.__init__(self, handle)
         self._drawing_area = gtk.DrawingArea()
         self._tablet_box = TabletBox()
         self._tablet_box.add(self._drawing_area)
 
         self.set_canvas(self._tablet_box)

then the activity can connect to the appropriate tablet events:

         self.connect("tablet_down_event", self._handle_tablet_down)
         self.connect("tablet_up_event", self._handle_tablet_up)
         self.connect("tablet_motion_event", self._handle_tablet_motion)

If your activity already supports drawing with the mouse, the event handlers should trivially map to your existing event handlers -- i.e., tablet_down_event -> button_press_event; tablet_up_event -> button_release_event; tablet_motion_event -> motion_notify_event (with the mouse button held down)

Notes

  • the TabletBox needs to be a container widget, because the Pen Tablet UI requires that we draw UI elements on top of the activity's drawing area
  • this solution may not work for a canvas that needs to be scrolled. It might be necessary for the TabletBox to inherit from gtk.Layout to provide scrolling capabilities.
Personal tools
  • Log in
  • Login with OpenID
About OLPC
About the laptop
About the tablet
Projects
OLPC wiki
Toolbox
In other languages