Is there a way to disable mousewheel in processing?

edited May 2016 in Python Mode

Pretty self explanatory, however I am also using proscene2. Is it possible to disable the mousewheel in either proscene or processing.

Love,

Pizzagui

Answers

  • edited April 2016 Answer ✓
    • Processing by itself does nothing at all for all input events.
    • Be it keyPressed(), mouseDragged(), mouseWheel().
    • We have to write the code by ourselves if we need for something to happen for some trigger.
    • In short, just don't write any code for mouseWheel() if you wish for nothing to happen for it.
    • Having said all of that, indeed library ProScene actively seeks out for various user inputs apart from Processing.
    • If there's some way to deactivate that mechanism for ProScene I dunno. You'll have to look up its API.
    • However, in order for ProScene to update its bounded PGraphics, it needs an extra beginDraw()/endDraw() pair.
    • I've added an extra boolean variable called active from my previous "ProScene MultiColor Box Test" from https://forum.Processing.org/two/discussion/16220/can-t-seem-to-get-a-proscene-3d-drawing-inside-a-2d-canvas-python-mode
    • The spacebar key turn variable active True or False.
    • Yet ProScene invisibly updates its internal variables while active is False.
    • Therefore a real solution needs to come outta its API instead. #-o

    '''
     ' ProScene MultiColor Box Test (v3.3)
     ' by CodeAntiCode (2013-Nov)
     ' forum.Processing.org/two/discussion/1297/3d-window-in-2d-sketch
     '
     ' mod GoToLoop (2016-Apr-24)
     ' forum.Processing.org/two/discussion/16220/
     ' can-t-seem-to-get-a-proscene-3d-drawing-inside-a-2d-canvas-python-mode
     '
     ' update (2016-Apr-27)
     ' forum.Processing.org/two/discussion/16281/
     ' is-there-a-way-to-disable-mousewheel-in-processing
    '''
    
    add_library('proscene')
    
    def setup():
        size(640, 360, P2D)
        smooth(8)
        frameRate(60)
        imageMode(CORNER)
    
        global canvas, scene, cubes, active
        w, h, active = width >> 1, height >> 1, True
    
        canvas = createGraphics(w, h, P3D)
        canvas.smooth(4)
        canvas.beginDraw()
    
        canvas.stroke(0)
        canvas.strokeWeight(1.5)
    
        canvas.endDraw()
    
        scene = Scene(this, canvas)
        scene.setCameraType(Camera.Type.ORTHOGRAPHIC)
        scene.setGridVisualHint(False)
        scene.setAxesVisualHint(False)
        scene.setRadius(100);
        scene.showAll();
    
        cubes = Cube(0, 0, color(255, 127, 0)),\
                Cube(w, 0, color(255, 0, 127)),\
                Cube(0, h, color(127, 255, 0)),\
                Cube(w, h, color(0, 127, 255))
    
    
    def draw():
        for cube in cubes: cube.render()
    
    
    def keyPressed():
        global active
        active ^= key == ' '
    
    
    class Cube:
        W, H, D = 20, 30, 50
    
        def __init__(_, x, y, ink): _.x, _.y, _.ink = x, y, ink
    
        def render(_):
            canvas.beginDraw()
            active and scene.beginDraw()
    
            canvas.background(0)
            canvas.fill(_.ink)
            canvas.box(Cube.W, Cube.H, Cube.D)
    
            active and scene.endDraw()
            canvas.endDraw()
    
            image(canvas, _.x, _.y)
    
  • The api does have a method which disables mouse actions completely called disableMotionAgent() but I was kinda hoping that there was some sort of implementation in Processing... I Think I'll just add an action listener to the mouse wheel and call the method whenever it's being used.

  • edited November 2017

    I've also looked ProScene's Scene class up and found out both disableMotionAgent() & disableMouseAgent() can do the trick.

    Then I've modified keyPressed() in such a way it toggles the MouseAgent by hitting space:
    if key == ' ': scene.disableMouseAgent() or scene.enableMouseAgent()

    Here's latest v3.4 btW: \m/

    """
     ' ProScene MultiColor Box Test (v3.4)
     ' by CodeAntiCode (2013-Nov)
     ' Forum.Processing.org/two/discussion/1297/3d-window-in-2d-sketch
     '
     ' mod GoToLoop (2016-Apr-24)
     ' Forum.Processing.org/two/discussion/16220/
     ' can-t-seem-to-get-a-proscene-3d-drawing-inside-a-2d-canvas-python-mode
     '
     ' update (2016-Apr-27)
     ' Forum.Processing.org/two/discussion/16281/
     ' is-there-a-way-to-disable-mousewheel-in-processing#Item_3
    """
    
    add_library('proscene')
    
    def setup():
        size(640, 360, P2D)
        smooth(8)
        frameRate(60)
        imageMode(CORNER)
    
        global canvas, scene, cubes
        w, h = width >> 1, height >> 1
    
        canvas = createGraphics(w, h, P3D)
        canvas.smooth(4)
        canvas.beginDraw()
    
        canvas.stroke(0)
        canvas.strokeWeight(1.5)
    
        canvas.endDraw()
    
        scene = Scene(this, canvas)
        scene.setCameraType(Camera.Type.ORTHOGRAPHIC)
        scene.setGridVisualHint(False)
        scene.setAxesVisualHint(False)
        scene.setRadius(100);
        scene.showAll();
    
        print scene.info(), ENTER, scene.prettyVersion
    
        cubes = Cube(0, 0, color(255, 127, 0)),\
                Cube(w, 0, color(255, 0, 127)),\
                Cube(0, h, color(127, 255, 0)),\
                Cube(w, h, color(0, 127, 255))
    
    
    def draw():
        for cube in cubes: cube.render()
    
    
    def keyPressed():
        if key == ' ': scene.disableMotionAgent() or scene.enableMotionAgent()
    
    
    class Cube:
        W, H, D = 20, 30, 50
    
        def __init__(_, x, y, ink): _.x, _.y, _.ink = x, y, ink
    
        def render(_):
            canvas.beginDraw()
            scene.beginDraw()
    
            canvas.background(0)
            canvas.fill(_.ink)
            canvas.box(Cube.W, Cube.H, Cube.D)
    
            scene.endDraw()
            canvas.endDraw()
    
            image(canvas, _.x, _.y)
    

    P.S.: Just found out that MouseAgent is only the same as MotionEvent when running as desktop. #-o

  • I'd highly recommend you to update to proscene-3.x where motion bindings are defined in a per frame basis.

    Use code like this: frame.removeMotionBinding(processing.event.MouseEvent.WHEEL) to disable the wheel for frame; and scene.eyeFrame().removeMotionBinding(processing.event.MouseEvent.WHEEL) to disable it for the eye.

  • @nakednous, removeMotionBinding() gets rid of it permanently it seems.
    W/ disableMotionAgent() we can still enableMotionAgent() later. >-)

  • @GoToLoop you can re-enable it with myFrame.setMotionBinding(processing.event.MouseEvent.WHEEL, DOF1CallbackRoutine), e.g., myFrame.setMotionBinding(processing.event.MouseEvent.WHEEL, "translateY"). Please also observe that the DOF1CallbackRoutine may be either some GenericFrame method that takes a DOF1Event or your custom routine that takes a DOF1Event.

  • edited May 2016

    Thx, @nakednous. But I guess I'd stick w/ disableMotionAgent().
    Much simpler, less headache and no parameters. :ar!

Sign In or Register to comment.