[4] | 1 | ############################################################################ |
---|
| 2 | # |
---|
| 3 | # DIM - A Direct Interaction Manager for SAGE |
---|
| 4 | # Copyright (C) 2007 Electronic Visualization Laboratory, |
---|
| 5 | # University of Illinois at Chicago |
---|
| 6 | # |
---|
| 7 | # All rights reserved. |
---|
| 8 | # |
---|
| 9 | # Redistribution and use in source and binary forms, with or without |
---|
| 10 | # modification, are permitted provided that the following conditions are met: |
---|
| 11 | # |
---|
| 12 | # * Redistributions of source code must retain the above copyright |
---|
| 13 | # notice, this list of conditions and the following disclaimer. |
---|
| 14 | # * Redistributions in binary form must reproduce the above |
---|
| 15 | # copyright notice, this list of conditions and the following disclaimer |
---|
| 16 | # in the documentation and/or other materials provided with the distribution. |
---|
| 17 | # * Neither the name of the University of Illinois at Chicago nor |
---|
| 18 | # the names of its contributors may be used to endorse or promote |
---|
| 19 | # products derived from this software without specific prior written permission. |
---|
| 20 | # |
---|
| 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 22 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 23 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 24 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 25 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 26 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 28 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | # |
---|
| 33 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum |
---|
| 34 | # |
---|
| 35 | # Author: Ratko Jagodic |
---|
| 36 | # |
---|
| 37 | ############################################################################ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | from overlay import Overlay |
---|
| 43 | from globals import * |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | def makeNew(overlayId): |
---|
| 48 | """ this is how we instantiate the device object from |
---|
| 49 | the main program that loads this plugin """ |
---|
| 50 | return Pointer(overlayId) |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | # pointer states |
---|
| 55 | RESET = 0 # normal |
---|
| 56 | MOVE = 1 |
---|
| 57 | DRAG = 2 |
---|
| 58 | RESIZE = 3 |
---|
| 59 | DOWN = 4 |
---|
| 60 | UP = 5 |
---|
| 61 | IN_APP = 6 # just change the color |
---|
| 62 | ANGLE = 7 # where the down side of the cursor is |
---|
| 63 | ZOOM = 8 |
---|
| 64 | ROTATE = 9 |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | class Pointer(Overlay): |
---|
| 69 | |
---|
| 70 | def __init__(self, overlayId): |
---|
| 71 | Overlay.__init__(self, OVERLAY_POINTER, overlayId) |
---|
| 72 | self.state = RESET |
---|
| 73 | self.lastOrientation = 0 |
---|
| 74 | self.inApp = False |
---|
| 75 | self.__savedState = [self.state, self.lastOrientation, self.inApp] |
---|
| 76 | |
---|
| 77 | # some devices only produce one analog event so set it here if so |
---|
| 78 | # (e.g. a zoom-only puck) |
---|
| 79 | # this is used when the device enters an application in order to show |
---|
| 80 | # the correct pointer shape describing what the device can do |
---|
| 81 | self.onlyAnalogEvent = None |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | def pushState(self): |
---|
| 85 | self.__savedState = [self.state, self.lastOrientation, self.inApp] |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | def popState(self): |
---|
| 89 | state, lastOrientation, inApp = self.__savedState |
---|
| 90 | |
---|
| 91 | # apply the state |
---|
| 92 | if self.state != state and state != RESIZE: |
---|
| 93 | self.sendOverlayMessage(state) |
---|
| 94 | self.state = state |
---|
| 95 | |
---|
| 96 | # apply the orientation |
---|
| 97 | if self.state != state and state == RESIZE: |
---|
| 98 | self.showResizePointer(self.lastOrientation) |
---|
| 99 | |
---|
| 100 | # apply the inApp modifier |
---|
| 101 | if inApp: self.showInApp() |
---|
| 102 | else: self.showOutApp() |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | def setAnalogEvent(self, eventId): |
---|
| 106 | self.onlyAnalogEvent = eventId |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | def resetPointer(self): |
---|
| 110 | if self.state != RESET: |
---|
| 111 | self.sendOverlayMessage(RESET) |
---|
| 112 | self.state = RESET |
---|
| 113 | self.lastOrientation = 0 |
---|
| 114 | #print "RESET" |
---|
| 115 | #self.inApp = False |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | def showDownPointer(self): |
---|
| 119 | if self.state != DOWN: |
---|
| 120 | self.sendOverlayMessage(DOWN) |
---|
| 121 | self.state = DOWN |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | def showUpPointer(self): |
---|
| 125 | if self.state != UP: |
---|
| 126 | self.sendOverlayMessage(UP) |
---|
| 127 | self.state = UP |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | def showResizePointer(self, orientation): |
---|
| 131 | if self.state != RESIZE or self.lastOrientation != orientation: |
---|
| 132 | self.sendOverlayMessage(RESIZE, orientation) |
---|
| 133 | self.state = RESIZE |
---|
| 134 | self.lastOrientation = orientation |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | def showDragPointer(self): |
---|
| 138 | if self.state != DRAG: |
---|
| 139 | self.sendOverlayMessage(DRAG) |
---|
| 140 | self.state = DRAG |
---|
| 141 | #print "DRAG" |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | def showZoomPointer(self): |
---|
| 145 | if self.state != ZOOM: |
---|
| 146 | self.sendOverlayMessage(ZOOM) |
---|
| 147 | self.state = ZOOM |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | def showRotatePointer(self): |
---|
| 151 | if self.state != ROTATE: |
---|
| 152 | self.sendOverlayMessage(ROTATE) |
---|
| 153 | self.state = ROTATE |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | def movePointer(self, x, y): |
---|
| 157 | self.sendOverlayMessage(MOVE, x, y) |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | def pointerAngle(self, angle): |
---|
| 161 | self.sendOverlayMessage(ANGLE, int(angle)) |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | def showInApp(self): |
---|
| 165 | if not self.inApp: |
---|
| 166 | self.sendOverlayMessage(IN_APP, 1) |
---|
| 167 | self.inApp = True |
---|
| 168 | #print "IN APP" |
---|
| 169 | # set the correct pointer shape if the device |
---|
| 170 | # can produce only one analog event |
---|
| 171 | if self.onlyAnalogEvent == EVT_DRAG: |
---|
| 172 | self.showDragPointer() |
---|
| 173 | elif self.onlyAnalogEvent == EVT_ROTATE: |
---|
| 174 | self.showRotatePointer() |
---|
| 175 | elif self.onlyAnalogEvent == EVT_ZOOM: |
---|
| 176 | self.showZoomPointer() |
---|
| 177 | elif self.onlyAnalogEvent == None: |
---|
| 178 | self.resetPointer() |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | def showOutApp(self): |
---|
| 182 | if self.inApp: |
---|
| 183 | #print "OUT APP" |
---|
| 184 | self.sendOverlayMessage(IN_APP, 0) |
---|
| 185 | self.inApp = False |
---|
| 186 | #self.resetPointer() |
---|
| 187 | |
---|
| 188 | |
---|