Multi slider colour question

leemorgan's icon

Is there any way to change the colour of individual sliders on a multi slider? I want to be able to show when a given slider is on 'full' - and leave all the others' colours unchanged. I'm about to set up a parallel multi slider to do this (with just on/off) but it's kind of clunky. Is there no other way? Thanks!

tyler mazaika's icon

Like this? jspainter, once you know how to do the mgraphics drawing things. Maybe this will get you started down that (pretty useful!) rabbit hole.

/*
multislider_peakingcolor_example.js

jspainter file adapted for a Forum inquiry.

Author: Tyler Mazaika. 2022-09-15

----------------------------------------------------

When a slider is at the max level, it will draw using the "peakcolor" color rather than the "slidercolor".
*/

if ( this.box.maxclass != "multislider" ) {
    // Alert user if they're using a jspainter somewhere they shouldn't.
    throw new TypeError("multislider_peakingcolor_example.js should only be used with multislider objects.")
}

function paint() {

    var values = box.getvalueof()

    with (mgraphics) {
        // Fill the background
        set_source_rgba( box.getattr("bgcolor") )
        rectangle( 0, 0, mgraphics.size[0], mgraphics.size[1] )
        fill()

        set_line_width( box.getattr("thickness")+0.5 )
        set_source_rgba( box.getattr("slidercolor") )
        var width = mgraphics.size[0]
        var height = mgraphics.size[1]
        var stepsize = width / values.length
        var x = 0
        var y = 0
        var range = box.getattr("setminmax")
        var yfactor = height/(range[1]-range[0])
        var ghostbar = box.getattr("ghostbar") / 100.

        // Establish the y coordinate of zero value. Useful for signed/bipolar drawing.
        var zero_y = (range[1]-0)*yfactor

        // Bar width. Refactored to avoid repeat calculation in the loop.
        var bar_width = stepsize-box.getattr("spacing")

        for (var i = 0; i < values.length; i++) {
            y = (range[1]-values[i])*yfactor

            if ( values[i] == range[1] ) {
                // Value is a Max, so use peakcolor.
                set_source_rgba( box.getattr("peakcolor") )
            } else {
                set_source_rgba( box.getattr("slidercolor") )
            }

            if ( box.getattr("signed") ) {
                if ( y<zero_y ) {
                    // positive value
                    rectangle(x, y, bar_width, zero_y-y)
                } else {
                    // negative value (since y is drawing coordinate, not value)
                    rectangle(x, zero_y, bar_width, y-zero_y)
                }
            } else {
                rectangle(x, y, bar_width, height-y)
            }
            fill()
            x += stepsize
        }
    }
}

leemorgan's icon

This gives me the Supercolldier heebie-jeebies, just from looking at your code. But it's a tempting path. Thanks!

Roman Thilenius's icon


or single multisliders.