Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* **************************************** Constructors ********************************************
- * Author : r0k
- * Those functions are used by my WSH scripts to create custom objects. Feel free to use them in your
- * scripts but don't change them nor rename this file or my scripts won't work.
- * Please note that those functions might be changed in the future to adress bugs or add features.
- * There is no guarantee updates will be backward compatibles. If if you use one of those functions
- * for one of your script it might be a good idea to keep a copy of this file somewhere.
- */
- function ButtonObject(label, x, y, w, h, action, args, style) {
- this.label = label;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.state = $buttonStates.normal;
- this.action = action;
- this.args = args ? args : null;
- this.style = style || "text";
- this.onScreen = true;
- this.img = null;
- this.getImage = function(_imgPath) {
- __img = _imgPath+this.label+".jpg";
- doPrint("GetImage : "+__img,this.label);
- switch (true) {
- case utils.FileTest(__img, "e") :
- doPrint("true");
- this.img = gdi.Image(__img);
- break;
- default :
- this.style = "text";
- doPrint("false");
- }
- }
- this.getActiveStatus = function (x, y) {
- return (this.x <= x) && (x <= this.x + this.w) && (this.y <= y) && (y <= this.y + this.h);
- }
- this.setState = function (state) {
- __old = this.state;
- this.state = state;
- return __old;
- }
- this.draw = function(gr) {
- switch (this.style) {
- case "text":
- $system.themeButton.SetPartAndStateId(1, this.state);
- $system.themeButton.DrawThemeBackground(gr, this.x, this.y, this.w, this.h);
- gr.GdiDrawText(this.label, $options.font, RGB(0,0,0), this.x, this.y, this.w, this.h, 0x00000C05);
- break;
- case "img":
- // this.img.Resize(this.w, this.h, 0);
- gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, 0, this.img.Width, this.img.Height);
- // gr.DrawImage(this.img, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h);
- break;
- case "mixed":
- break;
- }
- }
- this.onClick = function () {
- this.action();
- }
- }
- function PlayListObject(id, name, sort, auto, query) {
- this.idx = id;
- this.name = name;
- this.auto = (auto == true) ? true : false;
- this.query = (auto != true) ? false : (query || $default.query);
- this.sort = (sort) ? ((sort.charAt(0) == "%" || "$") ? sort : ((sort = "random") ? "" : $default.sort))
- : $default.sort;
- this.getIdx = function() {
- var idx = this.idx;
- if (fb.GetPlaylistName(idx) != this.name) {
- idx = -1;
- for (var i=0; i<fb.PlaylistCount; i++) {
- if (fb.GetPlaylistName(i) == this.name) {
- idx = i;
- break;
- }
- }
- this.idx = (idx > -1) ? idx : this.idx;
- }
- return (idx > -1) ? idx : false;
- }
- this.doCreate = function() {
- if (this.getIdx()>=0) this.doRemove();
- if (this.auto) {
- fb.CreateAutoPlaylist(this.idx, this.name, this.query, this.sort);
- } else {
- fb.CreatePlaylist(this.idx, this.name);
- }
- }
- this.doRemove = function() {
- if (this.getIdx()>=0) plman.RemovePlaylist(this.idx);
- }
- this.getMeta = function(metaName) {
- var metaHandles = plman.GetPlaylistItems(this.idx);
- var orderBy = fb.TitleFormat("%" + metaName + "%");
- metaHandles.OrderByFormat(orderBy, 1);
- orderBy.Dispose();
- var metaList=[];
- var lastMeta="";
- var meta="";
- for (var i=0; i < metaHandles.Count; i++) {
- meta = metaHandles.Item(i).GetFileInfo().
- MetaValue(metaHandles.Item(i).GetFileInfo().MetaFind(metaName), 0);
- if (lastMeta != meta) {
- lastMeta = meta;
- metaList.push(meta);
- }
- }
- metaHandles.Dispose();
- return metaList;
- }
- this.setQuery = function(query) {
- this.query = (this.queryBase = ".") ? query : this.queryBase + " AND " + query;
- this.create();
- }
- this.doClear = function() {
- if (this.getIdx()>=0) {
- plman.SetPlaylistSelectionSingle(this.idx, 0, true);
- plman.RemovePlaylistSelection(this.idx, true);
- plman.RemovePlaylistSelection(this.idx, false);
- }
- }
- this.setContent = function(hndList) {
- if (this.getIdx()>=0) {
- // __active = plman.ActivePlaylist;
- this.doClear();
- plman.InsertPlaylistItems(this.idx, 0, hndList);
- plman.ActivePlaylist = this.idx;
- // plman.ActivePlaylist = __active;
- }
- }
- this.doPlay = function(_mode) {
- _mode = _mode || "now"
- if (this.getIdx()>=0) {
- plman.SetPlaylistFocusItem(this.idx, 0);
- fb.PlayingPlaylist = this.idx;
- if (!(fb.IsPlaying)) fb.Play();
- }
- }
- }
- function ToolbarObject(id,_style,y,h,w,btnH,btnW) {
- this.ownId = id;
- this.align = (_style) ? _style.split("|")[0] : "hLeft";
- this.style = (_style) ? _style.split("|")[1] : "text";
- this.buttonsHeight = btnH || 25;
- this.buttonsWidth = btnW || 80;
- this.buttonsList = [];
- // this.buttons = {height : (btnH || 26), width : (btnW || 80), list : null};
- this.top = y || 0;
- this.height = h || 30;
- this.bottom = this.top + this.height;
- this.width = w || 250;
- this.visible = {row1 : 0, rowN : 0, col1 : 0, colN : 0}; // Columns are not used currently
- this.updateHeight = function(h) {
- this.height = h;
- this.bottom = this.top + this.height;
- }
- this.addButton = function(label, action, args) {
- this.visible.rowN = Math.floor(this.height/(5+this.buttonsHeight));
- __w = this.buttonsWidth;
- __h = this.buttonsHeight;
- __buttonID = this.buttonsList.length;
- doPrint("Adding button : "+__buttonID+label+" - "+__w+"x"+__h,this.ownId);
- switch (this.align) {
- case "hLeft" :
- __x = 5 + ((__w+5) * __buttonID);
- __y = 5 + this.top;
- __row = false;
- break;
- case "vLeft" :
- __x = 5;
- __y = (5 + this.top) + ((5+__h) * __buttonID);
- __row = false;
- break;
- case "grid" :
- __rowSize = Math.floor((this.width-10)/(__w+5));
- __row = Math.floor(__buttonID/__rowSize);
- __rowPos = __buttonID-(__row*__rowSize);
- __x = 5 + ((__w+5) * __rowPos);
- __y = (5 + this.top) + ((5+__h) * __row);
- doPrint("Grid. Row : "+__row+" - Visi : "+this.visible.row1+"-"+this.visible.rowN,this.ownId);
- break;
- }
- this.buttonsList[__buttonID] = new ButtonObject(label,__x,__y,__w,__h,action,args,this.style);
- if (__row >= this.visible.rowN) this.buttonsList[__buttonID].onScreen = false;
- if (this.style == "img") this.buttonsList[__buttonID].getImage($system.imgPath);
- }
- this.doRecalculateLayout = function(_newW,_newH) {
- this.visible.rowN = Math.floor(this.height/(5+this.buttonsHeight));
- this.height = _newH || this.height;
- this.bottom = this.top + this.height;
- this.width = _newW || this.width;
- __w = this.buttonsWidth; __h = this.buttonsHeight;
- doPrint("Rcalculate layout : "+this.width+"x"+this.height+
- " -Rows : "+this.visible.row1+"-"+this.visible.rowN,this.ownId);
- for (var i in this.buttonsList) {
- this.buttonsList[i].onScreen = true;
- switch (this.align) {
- case "hLeft" :
- __x = 5 + ((__w+5) * i);
- __y = 5 + this.top;
- __row = false;
- break;
- case "vLeft" :
- __x = 5;
- __y = (5 + this.top) + ((5+__h) * i);
- __row = false;
- break;
- case "grid" :
- __rowSize = Math.floor((this.width-10)/(__w+5));
- __row = Math.floor(i/__rowSize);
- __rowPos = i-(__row*__rowSize);
- __x = 5 + ((__w+5) * __rowPos);
- __y = (5 + this.top) + ((5+__h) * (__row-this.visible.row1));
- break;
- }
- this.buttonsList[i].x = __x; this.buttonsList[i].y = __y;
- if ((__row < this.visible.row1) || (__row >= this.visible.rowN + this.visible.row1))
- this.buttonsList[i].onScreen = false;
- }
- }
- this.doClear = function() {
- this.buttonsList = [];
- CollectGarbage();
- }
- this.drawButtons = function(gr) {
- for (var i in this.buttonsList) {
- if (this.buttonsList[i].onScreen) this.buttonsList[i].draw(gr);
- }
- }
- this.getActiveStatus = function (y) {
- return (this.top <= y) && (y <= this.bottom);
- }
- this.getActiveButton = function(x, y) {
- for (var i in this.buttonsList) {
- if (this.buttonsList[i].onScreen && this.buttonsList[i].getActiveStatus(x, y))
- return this.buttonsList[i];
- }
- return null;
- }
- }
- function MetaDBObject(id, query, sortBy, groupBy) {
- this.ownId = id;
- this.query = (query) ? query : $default.query;
- this.sortBy = (sortBy) ? sortBy : $default.sort;
- this.groupBy = (groupBy) ? groupBy : $default.group;
- this.groups = {};
- this.doListHandles = function(_query,_sort) {
- __query = _query || this.query
- __sort = _sort || this.sortBy
- var __idx = fb.PlaylistCount;
- fb.CreateAutoPlaylist(__idx, "temp", __query, __sort);
- this.hndListAll = plman.GetPlaylistItems(__idx);
- this.hndList = this.hndListAll.Clone();
- plman.RemovePlaylist(__idx);
- }
- this.doResetHandles = function() {
- this.hndList.RemoveAll();
- this.hndList = this.hndListAll.Clone();
- }
- this.doFilterHandles = function(__filter) {
- this.hndList.RemoveAll();
- this.hndList = this.groups[__filter].Clone();
- }
- this.doGroups = function(_key,_sort) {
- __key = _key || this.groupBy;
- __sort = (_sort) ? fb.TitleFormat(__key + _sort) : fb.TitleFormat(__key + this.sortBy);
- __group = fb.TitleFormat(__key);
- this.hndList.OrderByFormat(__sort, 1);
- this.groups = {};
- for (var i=0; i < this.hndList.Count; i++) {
- __hnd = this.hndList.Item(i);
- __groupName = (__group.EvalWithMetadb(__hnd)) || "MISSING";
- if (!(__groupName in this.groups)) {
- this.groups[__groupName] = fb.getSelections(1);
- this.groups[__groupName].RemoveAll();
- doPrint("Group found : "+__groupName,this.ownId);
- }
- this.groups[__groupName].Add(__hnd);
- }
- }
- this.getGroups = function() {
- var __groups = [];
- for(i in this.groups) {
- if (this.groups.hasOwnProperty(i)) __groups.push(i);
- }
- return __groups;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement