Some usefull way to change values in modal operator with MMB scroll


(JoseConseco) #1

It is *10 or /10 on scroll, and then +1 or -1 to the last digit, on shift + MMB scroll. It is useful if you want to change value in big range eg. from 0.000001 to 10, with control of last digit value.
Maybe some people will find this usefull for addons and modal operators.

And the code:

if event.type == 'WHEELUPMOUSE':
    if event.shift:
        # detect when log10(0.001) - is close to round number
        if abs(round(log10(obj.wpt_delta)) - log10(obj.wpt_delta)) < 1.0e-4:  #detect when log10(0.001) - is close to round number
            obj.wpt_delta *= 2
        else:
            obj.wpt_delta += pow(10,floor(log10(obj.wpt_delta)))
    else:
        obj.wpt_delta *= 10

    
elif event.type == 'WHEELDOWNMOUSE':
    if event.shift:
        # detect when log10(0.001) - is close to round number
        if abs(round(log10(obj.wpt_delta)) - log10(obj.wpt_delta)) < 1.0e-4:  
            obj.wpt_delta *= 0.9
        else:
            obj.wpt_delta -= pow(10,floor(log10(obj.wpt_delta)))
    else:
        obj.wpt_delta /= 10