Help - Search - Members - Calendar
Full Version: Tidying up some layout code
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
macca
I currently use this code to switch between layouts in Panels UI:

CODE
// Background
$drawrect(0,0,%_width%,%_height%,pencolor-0-0-0 brushcolor-0-0-0)

// PerTrack
$setpvar(mem1,
$if($or(%isplaying%,%ispaused%),1,0)
)
$select($add(1,$getpvar(mem1),$getpvar(mem2)),
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)
,
$panel(main trackinfo,Track Display,0,0,%_width%,$sub(%_height%,130),)
$panel(speca,Spectrum analyser,0,$sub(%_height%,130),%_width%,20,)
$panel(peakmeter,Peakmeter,0,$sub(%_height%,110),%_width%,40,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)
,
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)
)


But I just want to clean it up a bit to make it neater/ easier to read, so I tried to change it to this:

CODE
// Global
// Layout1
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)
// Layout2
$panel(main trackinfo,Track Display,0,0,%_width%,$sub(%_height%,130),)
$panel(speca,Spectrum analyser,0,$sub(%_height%,130),%_width%,20,)
$panel(peakmeter,Peakmeter,0,$sub(%_height%,110),%_width%,40,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

// Background
$drawrect(0,0,%_width%,%_height%,pencolor-0-0-0 brushcolor-0-0-0)

// PerTrack
$setpvar(mem1,
$if($or(%isplaying%,%ispaused%),1,0)
)
$select($add(1,$getpvar(mem1),$getpvar(mem2)),
// Layout1
,
// Layout2
,
// Layout1
)


But that didn't work either, It just seemed to place both layouts on top of each other. I'm not sure if what I'm trying is at all possible, but if it is then where am I going wrong?

Thanks alot
-mac
The Judge
Didn't understand what you were doing at first but now I see. I didn't think it was even possible to do what you have attempted in your second code. Instead of simply putting // Layout1, try setting it as a PVAR and then $getpvar in your $select code. That should work I believe - I could be wrong though!
Yotsuya
Is something like this more to your liking? Unless there were some recent changes to Panels UI I do not think there is any way to declare a subroutine like you were attempting with the // comments.

CODE
// Background
$drawrect(0,0,%_width%,%_height%,pencolor-0-0-0 brushcolor-0-0-0)

// PerTrack
$setpvar(mem1,$if($or(%isplaying%,%ispaused%),1,0))
$select($add(1,$getpvar(mem1),$getpvar(mem2)),

// Layout 1
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

,

// Layout 2
$panel(main trackinfo,Track Display,0,0,%_width%,$sub(%_height%,130),)
$panel(speca,Spectrum analyser,0,$sub(%_height%,130),%_width%,20,)
$panel(peakmeter,Peakmeter,0,$sub(%_height%,110),%_width%,40,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

,

// Layout 3
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

)
macca
QUOTE(Yotsuya @ Jul 23 2007, 05:47) *

Is something like this more to your liking? Unless there were some recent changes to Panels UI I do not think there is any way to declare a subroutine like you were attempting with the // comments.

CODE
// Background
$drawrect(0,0,%_width%,%_height%,pencolor-0-0-0 brushcolor-0-0-0)

// PerTrack
$setpvar(mem1,$if($or(%isplaying%,%ispaused%),1,0))
$select($add(1,$getpvar(mem1),$getpvar(mem2)),

// Layout 1
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

,

// Layout 2
$panel(main trackinfo,Track Display,0,0,%_width%,$sub(%_height%,130),)
$panel(speca,Spectrum analyser,0,$sub(%_height%,130),%_width%,20,)
$panel(peakmeter,Peakmeter,0,$sub(%_height%,110),%_width%,40,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

,

// Layout 3
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

)



Thanks, what happened to your account? smile.gif

What you have written above is right, but I'm trying to have only one instance of layout1 and one instance of layout2, instead of having to write out layout1 twice within the $select() function. The reason is so I can make the code a bit neater and shorter, and if I want to change layout1 then I will only need to change it once, and it will take effect in both instances of the $select().

QUOTE

Didn't understand what you were doing at first but now I see. I didn't think it was even possible to do what you have attempted in your second code. Instead of simply putting // Layout1, try setting it as a PVAR and then $getpvar in your $select code. That should work I believe - I could be wrong though!


Thanks, I tried setting pvars for each of the layouts, but it didn't work. When I start foobar I just get layout2 (the 'now playing' layout) and If I click the toggle button (toggle the mem2 pvar) to try and switch to layout1 (playlist layout) then I get something weird - It kind of draws layout1 and layout2 at the same time (and in the same place), so I get my big 'now playing' track display panel displayed, and the scrollbar of the playlist kind of flickers through it, as if foobar doesn't know which one to draw on top. I don't know how else to describe it.

What should happen when I open foobar, is that layout1 (playlist) is displayed (because mem1 and mem2 are both undefined), but when I play a track it will switch to layout2 ('now playing' - mem1 is set), and then if I click the 'library' button mem2 will be set, and it will switch back to layout1. For some reason though it isn't working with the pvars.

This is the code that I tried:

CODE

// Background
$imageabs2(%_width%,%_height%,,,,,0,0,C:\Program files\foobar2000\images\mainback1.jpg,nokeepaspect)
$imageabs2($eval(%_width%-60),$eval(%_height%-175),,,,,30,70,C:\Program files\foobar2000\images\frameback.png,nokeepaspect)
$drawrect(29,69,$eval(%_width%-58),$eval(%_height%-173),pencolor-0-0-0 brushcolor-null)
$drawrect(29,19,$eval(%_width%-58),32,pencolor-0-0-0 brushcolor-null)

// PerTrack
//-----------define layouts-----------//
$setpvar(layout1,
$panel(playtitle,Track Display,30,20,$eval(%_width%-60),30,)
$panel(playlist,Single Column Playlist,30,70,$eval(%_width%-60),$eval(%_height%-175),)
$panel(pswitcher,Playlist switcher,30,$sub(%_height%,85),$eval(%_width%-60),15,)
$panel(seekbar,Seekbar,30,$sub(%_height%,70),$eval(%_width%-60),20,)
$panel(trackinfo,Track Display,30,$sub(%_height%,50),$eval(%_width%-60),30,)
$panel(buttons,Buttons,30,$sub(%_height%,20),$eval(%_width%-60),20,)
)
$setpvar(layout2,
$panel(main trackinfo,Track Display,30,70,$eval(%_width%-60),$sub(%_height%,200),)
$panel(speca,Spectrum analyser,30,$sub(%_height%,130),$eval(%_width%-60),20,)
$panel(seekbar,Seekbar,30,$sub(%_height%,70),$eval(%_width%-60),20,)
$panel(trackinfo,Track Display,30,$sub(%_height%,50),$eval(%_width%-60),30,)
$panel(buttons,Buttons,30,$sub(%_height%,20),$eval(%_width%-60),20,)
)
//-----------define behaviour---------//
$setpvar(mem1,
$if($or(%isplaying%,%ispaused%),1,0)
)
$select($add(1,$getpvar(mem1),$getpvar(mem2)),
$getpvar(layout1)
,
$getpvar(layout2)
,
$getpvar(layout1)
)


Do you think it might have something to do with restrictions on what a PVAR can hold? For example maybe I'm just trying to stuff to much into it (an entire layout), as usually I just store a short numerical value or phrase in it.

Thanks
-mac
Yotsuya
Maybe something like this would be more to your liking? Using your original code to set a temporary variable to choose the layout, and then a separate $select() to actually render the layout?

CODE
// Background
$drawrect(0,0,%_width%,%_height%,pencolor-0-0-0 brushcolor-0-0-0)

// PerTrack
$setpvar(mem1,$if($or(%isplaying%,%ispaused%),1,0))
$select($add(1,$getpvar(mem1),$getpvar(mem2)),
$puts(desired.layout,1)
,
$puts(desired.layout,2)
,
$puts(desired.layout,1)
)

$select($get(desired.layout),

// Layout 1
$panel(playtitle,Track Display,0,0,%_width%,30,)
$panel(playlist,Single Column Playlist,0,30,%_width%,$sub(%_height%,135),)
$panel(pswitcher,Playlist switcher,0,$sub(%_height%,85),%_width%,15,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

,

// Layout 2
$panel(main trackinfo,Track Display,0,0,%_width%,$sub(%_height%,130),)
$panel(speca,Spectrum analyser,0,$sub(%_height%,130),%_width%,20,)
$panel(peakmeter,Peakmeter,0,$sub(%_height%,110),%_width%,40,)
$panel(seekbar,Seekbar,0,$sub(%_height%,70),%_width%,20,)
$panel(trackinfo,Track Display,0,$sub(%_height%,50),%_width%,30,)
$panel(buttons,Buttons,0,$sub(%_height%,20),%_width%,20,)

)
macca
Thanks that works well, just what I'm looking for.
-mac
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.