HISE Logo Forum
    • Categories
    • Register
    • Login

    Reducing repetition with paint routines based on object text property?

    Scheduled Pinned Locked Moved Scripting
    5 Posts 2 Posters 381 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tomekslesicki
      last edited by

      I have a couple panels, with paint routines dependent on slider values. I'm already using an inline function to reduce a bit of the code in the paint routine, but I'm wondering if I can slim it even further. The setup looks like this:

      Panel 1 has alpha based on the Current Level of Slider 1.
      Panel 2 has alpha based on the Current Level of Slider 2.
      ...and so on.

      I put the Slider numbers into the text property of the panels, hoping I could do something like this:

      local rowname = this.get("text");
      local rowvalue = rowname.getValue();
      g.setColour(Colours.withAlpha(0xFFFFFF, rowvalue));
      

      but it doesn't work unfortunately. I'm sure I'm missing something obvius, but I'd really appreciate some help!

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @tomekslesicki
        last edited by d.healey

        @tomekslesicki

        Put your panels into an array, put your sliders into an array.

        Then you can do something like

        local index = panelArray.indexOf(this);
        g.setColour(Colours.withAlpha(myColour, sliderArray[index].getValue());
        

        Another approach is inside the slider's callback you set one of the colour properties of the panel. Then in the panel's paint routine you read that property and don't bother with the Colours.withAlpha() stuff.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        T 1 Reply Last reply Reply Quote 0
        • T
          tomekslesicki @d.healey
          last edited by

          @d-healey thanks! If it's not too much to ask, would you be so kind and put this:

          local index = panelArray.indexOf(this);
          g.setColour(Colours.withAlpha(myColour, sliderArray[index].getValue());
          

          into a quick little snippet for me? Just two sliders and panels would be enough for me to understand the logic behind it :-) Thank you!

          1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey
            last edited by d.healey

            This is a slight improvement on my original suggestion.

            HiseSnippet 1020.3ocsV0saaaCElxILq1asXEXO.B4JYfLC6j9y.FFhSrSF7ZS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EDiPaw+GwX9aHdH9nf.pmZV.tI93eXcevvGX4MCMFdBQEyfC.3SSCcgcZOJr5B8jIPmUE8QIibSsrtB3RE9YBSfe4FaoksxM1pvHJj3EKekm45H8qTdPlFHlDYOJqJ75PP1d5MfXbyFMQgvCldkmmN8+b3V1EiY20.ydqAlmrFXd5Zf4YqAlmuFX9hkhQ+V0CRUxPS6.nn+QYyCrrNRPfSVYmBQ+G.PktDE
            

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            T 1 Reply Last reply Reply Quote 0
            • T
              tomekslesicki @d.healey
              last edited by

              @d-healey awesome, thanks so much, this helps me understand it! :-)

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              16

              Online

              1.8k

              Users

              12.1k

              Topics

              104.9k

              Posts