~landronimirc/impressive/trunk

« back to all changes in this revision

Viewing changes to src/event.py

  • Committer: keyj
  • Date: 2018-01-31 21:38:44 UTC
  • Revision ID: svn-v4:58003caa-664d-4c56-a378-6d187ff66ee1:trunk/impressive:218
major new feature: box-zoom mode

Ctrl+LMB-drag now enters a special zoom mode
where the selected rectangle is zoomed in to
cover the whole screen, and the rest of the
screen is considerably dimmed down (even more
so than in highlight box and spotlight mode).

This also decouples the visual zoom factor
from the page resolution zoom factor;
in other words, it's possible to zoom in
*really* far now, even though the rendering
resolution is limited to only 5x, 2x or
even 1x (see new --maxzoom option).

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
    def _zoom_pan_ACTIVATE(self):
145
145
        "pan visible region in zoom mode"
146
146
        global PanValid, Panning, PanBaseX, PanBaseY, PanAnchorX, PanAnchorY
147
 
        ActionValidIf(ZoomMode)
 
147
        ActionValidIf(ZoomMode and not(BoxZoom))
148
148
        PanValid = True
149
149
        Panning = False
150
150
        PanBaseX, PanBaseY = Platform.GetMousePos()
161
161
        "enter zoom mode"
162
162
        ActionValidIf(not(ZoomMode))
163
163
        tx, ty = MouseToScreen(Platform.GetMousePos())
164
 
        EnterZoomMode((1.0 - 1.0 / ZoomFactor) * tx, \
165
 
                      (1.0 - 1.0 / ZoomFactor) * ty)
 
164
        EnterZoomMode(DefaultZoomFactor,
 
165
                      (1.0 - 1.0 / DefaultZoomFactor) * tx, \
 
166
                      (1.0 - 1.0 / DefaultZoomFactor) * ty)
166
167
    def _zoom_exit(self):
167
168
        "leave zoom mode"
168
169
        ActionValidIf(ZoomMode)
179
180
        global Marking
180
181
        ActionValidIf(Marking)
181
182
        Marking = False
182
 
        # reject too small boxes
183
 
        if  ((abs(MarkUL[0] - MarkLR[0]) * ScreenWidth)  >= MinBoxSize) \
184
 
        and ((abs(MarkUL[1] - MarkLR[1]) * ScreenHeight) >= MinBoxSize):
185
 
            boxes = GetPageProp(Pcurrent, 'boxes', [])
186
 
            oldboxcount = len(boxes)
187
 
            boxes.append(NormalizeRect(MarkUL[0], MarkUL[1], MarkLR[0], MarkLR[1]))
188
 
            SetPageProp(Pcurrent, 'boxes', boxes)
189
 
            if not(oldboxcount) and not(Tracing):
190
 
                BoxFade(lambda t: t)
191
 
        else:
 
183
        if BoxTooSmall():
192
184
            raise ActionNotHandled()
 
185
        boxes = GetPageProp(Pcurrent, 'boxes', [])
 
186
        oldboxcount = len(boxes)
 
187
        boxes.append(NormalizeRect(MarkUL[0], MarkUL[1], MarkLR[0], MarkLR[1]))
 
188
        SetPageProp(Pcurrent, 'boxes', boxes)
 
189
        if not(oldboxcount) and not(Tracing):
 
190
            BoxFade(lambda t: t)
193
191
        DrawCurrentPage()
194
192
    def _box_add_RELEASE(self):
195
193
        global MarkValid
220
218
        DelPageProp(Pcurrent, 'boxes')
221
219
        DrawCurrentPage()
222
220
 
 
221
    def _box_zoom_ACTIVATE(self):
 
222
        "draw a box to zoom into [mouse-only]"
 
223
        ActionValidIf(not(BoxZoom) and not(Tracing) and not(GetPageProp(Pcurrent, 'boxes')))
 
224
        return self._box_add_ACTIVATE()
 
225
    def _box_zoom(self):
 
226
        global Marking, BoxZoom, ZoomBox
 
227
        ActionValidIf(Marking and not(BoxZoom) and not(Tracing) and not(GetPageProp(Pcurrent, 'boxes')))
 
228
        Marking = False
 
229
        if BoxTooSmall():
 
230
            raise ActionNotHandled()
 
231
        z = min(1.0 / abs(MarkUL[0] - MarkLR[0]), 1.0 / abs(MarkUL[1] - MarkLR[1]))
 
232
        if z <= 1:
 
233
            return DrawCurrentPage()
 
234
        tx = (MarkUL[0] + MarkLR[0]) * 0.5
 
235
        ty = (MarkUL[1] + MarkLR[1]) * 0.5
 
236
        tx = tx + (tx - 0.5) / (z - 1.0)
 
237
        ty = ty + (ty - 0.5) / (z - 1.0)
 
238
        tx = (1.0 - 1.0 / z) * tx
 
239
        ty = (1.0 - 1.0 / z) * ty
 
240
        BoxZoom = NormalizeRect(MarkUL[0], MarkUL[1], MarkLR[0], MarkLR[1])
 
241
        EnterZoomMode(z, tx, ty)
 
242
    def _box_zoom_RELEASE(self):
 
243
        return self._box_add_RELEASE()
 
244
 
 
245
    def _box_zoom_exit(self):
 
246
        "leave box-zoom mode"
 
247
        ActionValidIf(BoxZoom)
 
248
        LeaveZoomMode()
 
249
 
223
250
    def _hyperlink(self, allow_transition=True):
224
251
        "navigate to the hyperlink under the mouse cursor"
225
252
        x, y = Platform.GetMousePos()
346
373
 
347
374
    def _fade_less(self):
348
375
        "decrease the spotlight/box background darkness"
349
 
        global BoxFadeDarkness
350
 
        BoxFadeDarkness = max(0.0, BoxFadeDarkness - BoxFadeDarknessStep)
 
376
        global BoxFadeDarkness, BoxZoomDarkness
 
377
        if BoxZoom:
 
378
            BoxZoomDarkness = max(0.0, BoxZoomDarkness - BoxFadeDarknessStep)
 
379
        else:
 
380
            BoxFadeDarkness = max(0.0, BoxFadeDarkness - BoxFadeDarknessStep)
351
381
        DrawCurrentPage()
352
382
    def _fade_more(self):
353
383
        "increase the spotlight/box background darkness"
354
 
        global BoxFadeDarkness
355
 
        BoxFadeDarkness = min(1.0, BoxFadeDarkness + BoxFadeDarknessStep)
 
384
        global BoxFadeDarkness, BoxZoomDarkness
 
385
        if BoxZoom:
 
386
            BoxZoomDarkness = min(1.0, BoxZoomDarkness + BoxFadeDarknessStep)
 
387
        else:
 
388
            BoxFadeDarkness = min(1.0, BoxFadeDarkness + BoxFadeDarknessStep)
356
389
        DrawCurrentPage()
357
390
    def _fade_reset(self):
358
391
        "reset spotlight/box background darkness to default"
359
 
        global BoxFadeDarkness
 
392
        global BoxFadeDarkness, BoxZoomDarkness
360
393
        BoxFadeDarkness = BoxFadeDarknessBase
 
394
        BoxZoomDarkness = BoxZoomDarknessBase
361
395
        DrawCurrentPage()
362
396
 
363
397
    def _gamma_decrease(self):
377
411
        SetGamma(1.0, 0)
378
412
 
379
413
PageDisplayActions = PageDisplayActions()
380
 
ForcedActions.update(("-zoom-pan", "+zoom-pan", "-box-add", "+box-add"))
 
414
ForcedActions.update(("-zoom-pan", "+zoom-pan", "-box-add", "+box-add", "-box-zoom", "+box-zoom"))
381
415
 
382
416
# main event handling function
383
417
# takes care that $page-timeout events are handled with least priority