HISE Logo Forum
    • Categories
    • Register
    • Login

    Context to setPaintRoutine

    Scheduled Pinned Locked Moved Newbie League
    7 Posts 3 Posters 203 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.
    • D
      daniloprates
      last edited by daniloprates

      I'm trying to pass some context to the setPaintRoutine function, but when I try this:

      for (i=0;i<items.length;i++) {
      	Console.print('A - ' + i);
      	
      	instruments[i].setPaintRoutine(function (g) {
      		Console.print('B - ' + i);
      	});
      	
      	Console.print('C - ' + i);
      	
      };
      

      It prints:

      Interface: "C - 0"
      Interface: "A - 1"
      Interface: "C - 1"
      Interface: "A - 2"
      Interface: "C - 2"
      Interface: "A - 3"
      Interface: "C - 3"
      Interface: "A - 4"
      Interface: "C - 4"
      Interface: "B - 5"
      Interface: "B - 5"
      Interface: "B - 5"
      Interface: "B - 5"
      Interface: "B - 5"
      

      And it always gets the context of the last item. Is there a way to pass the context (or the index) inside setPaintRoutine?

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

        I find the best way to access stuff in the paint routine is to set it as the panel's value, or text. That way it's all self contained.

        If you want an index, you could just use instruments.indexOf(this) inside the paint routine I think.

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

        D 1 Reply Last reply Reply Quote 1
        • D
          daniloprates @d.healey
          last edited by

          @d-healey good idea. I ended up using this.getId(), which gave me what I needed. Thanks!

          Christoph HartC 1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart @daniloprates
            last edited by

            @daniloprates there‘s a data object for each panel that you can populate with anything and then access it in the callback with this.data.

            D 2 Replies Last reply Reply Quote 1
            • D
              daniloprates @Christoph Hart
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • D
                daniloprates @Christoph Hart
                last edited by

                @Christoph-Hart I've added this to the panel's setPropertiesFromJSON, but this.data is returning an empty object:

                ...
                data: { "test": "testing" },
                ...
                Christoph HartC 1 Reply Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart @daniloprates
                  last edited by

                  @daniloprates data is not a property that you can set through this call, but directly:

                  for(i = 0; i < 5; i++)
                  {
                  	var p = Content.addPanel("P"+i, i * 100, 0);
                  	p.data.index = i;
                  	p.setPaintRoutine(function(g)
                  	{
                  		g.setColour(Colours.white);
                  		g.drawAlignedText(this.data.index, this.getLocalBounds(0), "centred");
                  	});
                  };
                  
                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post

                  39

                  Online

                  1.9k

                  Users

                  12.5k

                  Topics

                  108.5k

                  Posts