HISE Logo Forum
    • Categories
    • Register
    • Login

    panel repaint and mousecallback - inconsistencies..

    Scheduled Pinned Locked Moved General Questions
    8 Posts 2 Posters 284 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.
    • LindonL
      Lindon
      last edited by

      So given all these are panels:

      mainRadioButtons[0] = Content.getComponent("Main");
      mainRadioButtons[1] = Content.getComponent("Editor");
      mainRadioButtons[2] = Content.getComponent("Effects");
      mainRadioButtons[3] = Content.getComponent("Arps");
      

      apparently I can say this(and it works):

      var RadioButtonPainter = function(g)
      {
         g.setColour(Colours.grey);
         g.setFont("Verdana", this.getHeight()-11);
         g.drawAlignedText(this.get("text"), [0,0,this.getWidth(),this.getHeight()], "centred");
         //this.setValue(1);
         if(this.getValue() == 1)
         {
             g.setColour(hilightColour);
             g.fillRect([0,this.getHeight()-3,this.getWidth(),3]);
         }
      };
      
      for (dx=0;dx<mainRadioButtons.length;dx++)
      {
          mainRadioButtons[dx].setPaintRoutine(RadioButtonPainter);
      }
      

      but this doesn't fire the function call back

      var mainRadioCallBack = function(event)
      {
          Console.print("in main callback");
        if (!event.mouseUp)
        {
          if (event.clicked)
          {
              for(dx=0;dx<mainRadioButtons.length;dx++)
              {
                  mainRadioButtons[dx].setValue(0);
                  mainRadioButtons[dx].repaint();
                  mainPanels[dx].showControl(false);       
              };
              var pos = mainRadioButtons.indexOf(this);
              Console.print("showing pos:" + pos);
              mainRadioButtons[pos].setValue(1);
              mainRadioButtons[pos].repaint();
              mainPanels[pos].showControl(true); 
          };
        };
      };
      
      for (dx=0;dx<mainRadioButtons.length;dx++)
      {
          mainRadioButtons[dx].setMouseCallback(mainRadioCallBack); 
      }
      

      Unless I'm doing something silly - always likely...

      HISE Development for hire.
      www.channelrobot.com

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

        Got a snippet?

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

        LindonL 1 Reply Last reply Reply Quote 0
        • LindonL
          Lindon @d.healey
          last edited by

          @d-healey I will go make one...

          HISE Development for hire.
          www.channelrobot.com

          1 Reply Last reply Reply Quote 1
          • LindonL
            Lindon @Lindon
            last edited by

            you see this bit here......?

            Unless I'm doing something silly - always likely...

            • seems I must declare my mouse callback function BEFORE I try and assign it....
              go figure....

            HISE Development for hire.
            www.channelrobot.com

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

              @Lindon I think you can avoid that if you don't declare them as var and instead declare them directly as arguments to the functions.

              HiseSnippet 850.3ocsU8taSCCD2tqYrVnHPhGfH9TpznjBaCjPH5V2JpB5VgtMw2l7RbarpicTryFUHd.3siGEdCfywsMsP2DTI7mx8Oe+xc+ty8SkATkRlhvUNcRBEgumyfIBcT6HBSf5dHBeemdDkll5ZUcvjDhRQCQX7Fu0n.WoLJ+7i2b.gSDAzBUHz4RV.88rXltPa+Vuiw4cHgzSYwK38Ns5FHEskbYFfmMb7QIjfwjQziIF2J4fvadTHSKSGnIZpB74.Y3jAQxqEV+OmoXWxoFglnAvEYUiZGw3g8m8upPHb49E+4aX+yejSOVHat9hJvCxM3VDwh0.bokgT4kfTyaBRcj7PyEbCvCu.7Jag2CcFDjxRzEVLX6tNcEPyYHAJ6KBKqunReG6zVBdHzMhIiocRAg4Q3smu+1t656W+U0pVqJT7UZ2qHot8IBJuo6qcmE6HptsLNQJ.AuGaM+XaTVgFJptOTvzeTloYBp2vLQflIEdipWq5WpU0ENiZLDZ76y4d8H5nFoDQHfEOaGW0fvAtxk7L51tyTwYihzILw35lj80eOi8jYJZaBmeIPTJRI8J.lEokMz0ppQ.jgwzv5V8liNhoZjRSLP2q9qLpxyyr6xUJNVpomH7pW8KUqT8qUc+cSCGtRalRWpjyooqzrg5mdaA5IxhujltMzPfRxbGA9vxDtM+6HbA1N4BNJEcEL8IIzoxETxlqfRhlREfuNq6gDMwvRmpC7KglpYF3fOjdEzFsb1JNGRUi0xjbemxeP36nysVaFi1zOQLH0a4X6snOWrU3CslLWn0YstlEpiPXG72vHTD0vOLROEj.df75YrAk49aa52J2SD7IvZm+XjBFrkgYbhd4ocyZsoFfNxRiUlQGghomr3Zu+gU.9qbEvJq2+kv8gN8Y5fnUi2Rq.uPe6+MdmtPslyQCGRCzEfsrSmOstaO+GfhcGzHXISJCXRNGmEO.VmDPAjH.9kxvXJY3zVYeiroxLfJByE9IblZroQFO0XyYFQwjfT4EA1YUyJ6sx0.XRj+ZUE3YSP1sIJe9EhywugOJFdI4hf.So3I.1WcLOaMh44qQL6rFwr6ZDydqQLuXMh4k2ZLlGw2OSKisiIfh9GkuHCiORP.VVNiD8K.i+GchB
              

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

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

                If you need to use the same mousecallback for multiple panels then declare it as a const var and it does need to be declared before it's used as you've mentioned.

                For paint routines used by multiple panels you can just use a regular inline function.

                Panel1.setPaintRoutine(paintRoutine);
                Panel2.setPaintRoutine(paintRoutine);
                
                inline function paintRoutine(g)
                {
                    g.fillAll(Math.randInt(Colours.aliceblue, Colours.lightpink));
                }
                

                Edit: Actually the same is true for paint routines if you need access to this you should declare them as const var.

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

                1 Reply Last reply Reply Quote 0
                • LindonL
                  Lindon @d.healey
                  last edited by Lindon

                  @d-healey yes clearly - and usually how I would do it for one off panels -but here Im replacing radio buttons with panels, and each panel has nearly the exact same call back:

                  • close all the panels,
                  • set the value of all other radio buttons to zero
                  • set value of yourself to 1
                  • open your panel
                  • repaint all the panels

                  so if I put them all in arrays I can refer to them with indexOf, and I can assign them all the same paint and mouse callbacks to save me some space, effort, time and is extnsible:

                  like this:

                  var mainRadioCallBack = function(event)
                  {
                    if (!event.mouseUp)
                    {
                      if (event.clicked)
                      {
                          // for each radio button/panel
                          for(dx=0;dx<mainRadioButtons.length;dx++)
                          {
                              // turn off the radio buttons
                              mainRadioButtons[dx].setValue(0);
                              // repaint the buttons as off
                              mainRadioButtons[dx].repaint();
                              // close each display panel
                              mainPanels[dx].showControl(false);       
                          };
                          // find out who we are
                          var pos = mainRadioButtons.indexOf(this);
                          // turn this on
                          mainRadioButtons[pos].setValue(1);
                          // repaint yourself as on
                          mainRadioButtons[pos].repaint();
                          // show your display panel...
                          mainPanels[pos].showControl(true); 
                      };
                    };
                  };
                  

                  see that indexOf(this) there?

                  HISE Development for hire.
                  www.channelrobot.com

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

                    Yup makes sense. Use const var instead of var though.

                    Writing const before a variable declaration tells the interpreter that this variable will not be changed (it differs from the const keyword in C++ in the way that you can still call methods on it that change something). Especially in combination with API calls it yields a huge performance boost (because it can resolve the function call on compile time):

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

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

                    46

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    102.2k

                    Posts