Author Topic: How do I use the API to create an element within the panels?  (Read 5966 times)

atajsic

  • Newbie
  • *
  • Posts: 6
I'm currently making a plugin that I would like to have a graphical user interface within the sidebars of the panels (see screenshot)



I've crawled through the API and it seems that maybe it's to do with PluginType.PanelView - however that's a guess. I've crawled through what plugins are open source but i'm stuck, i've tried to work it out for 4 hours and just can't.


Ideally I would like it to appear as an element in the panels configuration




Please Help!

Kindest Regards,
Andrew

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
to do what you want i would need to make an enhancement and something i was planning to do anyway, so its no problem. I will do it this weekend

atajsic

  • Newbie
  • *
  • Posts: 6

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
you need this patch version - unzip into the folder MB is installed:
http://musicbee.niblseed.com/V3_0/MusicBee3_Patched.zip

and add the following to the example plugin TestCSharpDll.cs
Code
        //  presence of this function indicates to MusicBee that this plugin has a dockable panel. MusicBee will create the control and pass it as the panel parameter
        //  you can add your own controls to the panel if needed
        //  you can control the scrollable area of the panel using the mbApiInterface.MB_SetPanelScrollableArea function
        //  to set a MusicBee header for the panel, set about.TargetApplication in the Initialise function above to the panel header text
        public int OnDockablePanelCreated(Control panel)
        {
          //    return the height of the panel and perform any initialisation here
          //    MusicBee will call panel.Dispose() when the user removes this panel from the layout configuration
          //    < 0 indicates to MusicBee this control is resizable and should be sized to fill the panel it is docked to in MusicBee
          //    = 0 indicates to MusicBee this control resizeable
          //    > 0 indicates to MusicBee the fixed height for the control.Note it is recommended you scale the height for high DPI screens(create a graphics object and get the DpiY value)
             float dpiScaling = 0;
            using (Graphics g = panel.CreateGraphics())
            {
                dpiScaling = g.DpiY / 96f;
            }
            panel.Paint += panel_Paint;
            return Convert.ToInt32(100 * dpiScaling);
        }

        // presence of this function indicates to MusicBee that the dockable panel created above will show menu items when the panel header is clicked
        // return the list of ToolStripMenuItems that will be displayed
        public List<ToolStripItem> GetHeaderMenuItems()
        {
            List<ToolStripItem> list = new List<ToolStripItem>();
            list.Add(new ToolStripMenuItem("A menu item"));
            return list;
        }

        private void panel_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(Color.Red);
            TextRenderer.DrawText(e.Graphics, "hello", SystemFonts.CaptionFont, new Point(10, 10), Color.Blue);
        }
to have MusicBee create a panel header for the panel, in the initialise function
Code
            about.TargetApplication = "Panel Header Text";   //  the name of a Plugin Storage device or panel header for a dockable panel

when the user selects the plugin in the layout configuration dialog, MusicBee will create an empty panel and call OnDockablePanelCreated(panel)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
i made a small update so the panel can also be docked at the top or bottom of the main panel
http://musicbee.niblseed.com/V3_0/MusicBee3_Patched.zip

could you confirm its working ok for you at a basic level even if you dont have your plugin completed

atajsic

  • Newbie
  • *
  • Posts: 6
Thanks Steven,

I have the panel populated on creation as the function says - however I can't find a way to update the panel- for example on an event notification.
In addition, would it be possible to call the skin's settings to set the colours, fonts, and the like?

Is this possible?

Kindest Regards,
Andrew

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
not sure what you mean by event notification. You can add event handlers to the panel as with any .net control.
if you mean musicbee events then set about.ReceiveNotifications
and handle events in the ReceiveNotification() function
The panel will have the skin colours already set. You can access some using Setting_GetSkinElementColor

edit:
i see the default colours for the panel are not always set correctly depending on the skin so i will fix that for the next patch update
Last Edit: September 26, 2016, 07:12:18 AM by Steven

atajsic

  • Newbie
  • *
  • Posts: 6
How do I update 'panel' outside the scope of the OnDockablePanelCreated method?

In your example, you have it defined with the text being 'hello'



Let's say on track change, i want to change that 'hello' to say the track title - how would I access the panel?

Cheers

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
the panel is a .net control so you can do anything you can do with any .NET control eg. you get it to repaint by invalidating it.
As i said, the musicbee events (such as track change) are signalled in the ReceiveNotification() function. Keep in mind ReceiveNotification() is messaged in a separate thread from the GUI. So you can safely invalidate a control but other actions will require invoking to the GUI thread to perform the action. You can use the Invoke() method on the panel control order to invoke to the gui thread.
The OnDockablePanelCreated() function is called in the GUI thread.
I dont really have time to provide one-on-one help with this so i hope that is enough for you.
Last Edit: September 27, 2016, 06:29:49 PM by Steven

atajsic

  • Newbie
  • *
  • Posts: 6
Thanks Steven,

I was able to finish my plugin with your inclusions.


Thankyou so much :)


Little video of the plugin in action: https://u.atajsic.me/2016-09-30_06.24.17.mp4


Kindest Regards,
Andrew

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34361
I am sure others would be interested to use it so feel free to submit it to the add-ons page if you want.