Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: JScript Panel script discussion/help (Read 290310 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

Re: JScript Panel script discussion/help

Reply #425
Do you mean something like this? (.gif under spoiler) (right-click is handled via JScript, Spectrum is a PSS panel)

Indeed. Although I'd probably opt for a button instead of the r-click. Did you alter cattrox for that?

Re: JScript Panel script discussion/help

Reply #426
Indeed. Although I'd probably opt for a button instead of the r-click. Did you alter cattrox for that?

Well, my version of CaTRoX had been mostly rewritten: replaced WSH with JScript, integrated marc2003's helpers, refactored code, optimizations, new features and etc. Music spectrum toggle is one of those additions.

The idea behind this is the usual PSS switch via file communication (and the only way to communicate between script from PSS panel and JScript AFAIK): you use some file to store a variable, which you can change from JScript. On every such change you execute Play and Pause from JScript. This triggers PSS PerTrack script, in which you can change panel's positions and\or size.

If you need, I can post a source code with an example later. Or if you want to figure it out yourself, you can Google "PSS Switch" =)

Re: JScript Panel script discussion/help

Reply #427
if you wish to switch panels using jscript I would like to introduce you shutter by jensen and dreamxis whitch doesnot use pss script at all.
WSH-splitter is used in the Shutter. A gif:

Re: JScript Panel script discussion/help

Reply #428
WSH-splitter is used in the Shutter.
I've tried searching for Shutter and WSH-splitter, but could not find anything. Do you by chance have a link to either of them?

[EDIT]: Nvm, found it on some chinese site. Wow, that is a lot of hacks in a single script =) Thanks for pointing it out ;)

 

Re: JScript Panel script discussion/help

Reply #429
Shutter
  —— by Jensen (coding) & dReamxis (design)



>FB_Shutter_v1.1_U(Original version): based on wsh panel mod v1.5.6 & foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll
>FB_Shutter_v1.1_U+(Modified a little, may have bugs): based on wsh panel mod plus v1.5.7.4, without foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll. Replace WSH Lyric with ESLyric. Replace Albumlist with Library Tree.
>ShutterIcon: specifically designed for the shutter.
>Wsh-splitter_by_jensen(Original version): based on wsh panel mod v1.5.6 & foo_ui_hacks.dll+dsound.dll+AutoItX3.dll+dynwrapx.dll. Use Chinese to write the interface description. Looking for a good translator.
Download!

Re: JScript Panel script discussion/help

Reply #430
Anyways, I think I might've found a bug, when using arrays with your latest helpers.js, caused by Array.prototype.srt.

Yes, it's a side effect of me messing around with the prototype. But I'll be keeping it as it has no effect on my own scripts.

Lots of workarounds...

#1
Code: [Select]
var my_array = ["a", "b", "c"];
for (var i in my_array){
    if (my_array.hasOwnProperty(i))
        fb.trace("my_array: ", i);
}

#2
Code: [Select]
var my_array = ["a", "b", "c"];
for (var i = 0; i < my_array.length; i++){
    fb.trace("my_array: ", i);
}

#3
Code: [Select]
var my_array = ["a", "b", "c"];
_.forEach(my_array, function (item, i) {
    fb.trace("my_array: ", i);
});

_.forEach is a lodash function documented here... https://lodash.com/docs/3.10.1#forEach

#4
Code: [Select]
// ==PREPROCESSOR==
// @name "Test Script"
// @import "%fb2k_profile_path%your_scripts\your_helpers.js"
// ==/PREPROCESSOR==

Re: JScript Panel script discussion/help

Reply #431
Yes, it's a side effect of me messing around with the prototype. But I'll be keeping it as it has no effect on my own scripts.
Thanks for the suggestions!
I've googled a bit and it seems that using "for var in" is considered a bad practice in JavaScript precisely because of things like that (properties and methods appearing while looping)... Additionally, "for var in" is worse performance-wise than classical "for; ;" loop and _.forEach loop. I.e. no reason at all for using "for var in" =)


Shutter
  —— by Jensen (coding) & dReamxis (design)

Thanks for the wsh_splitter tip! Incorporated needed functions in JScript from WSH-Plus and now panel toggles are much more manageable! And I can resize everything without editing every var manually =)
Though now I will have to recompile JScript every release, because of these hacks -_-""



Re: JScript Panel script discussion/help

Reply #434
Well there are no .txt files to support the changes to list.js so I have no idea what you're talking about.  :P

I don't understand your last post or what you're trying to do.

Re: JScript Panel script discussion/help

Reply #435
Well there are no .txt files to support the changes to list.js so I have no idea what you're talking about.  :P
That is unless I don't have your old scripts saved =)

I don't understand your last post or what you're trying to do.
Here is what I'm trying to do.
Let's say I have my_script.js:
Code: [Select]
function Func()
{
    fb.trace("script name is ", GetMyName() );
}

function GetMyName()
{
/* magic here */
}

The result output of Func() should be "script name is my_script.js"
So I was wondering if it is possible to make such GetMyName() function (googling didn't help).

Re: JScript Panel script discussion/help

Reply #436
If you have the old .txt files then you more than likely have the old .js files. :/

As for your script name thing, it's beyond nonsensical. It serves no purpose. Type it in manually if you must.

edit: you must realise each preprocessor must contain functions that have unique names for the them to work properly. If you define the same function multiple times with the same name, only the last instance will ever get called.

Re: JScript Panel script discussion/help

Reply #437
If you have the old .txt files then you more than likely have the old .js files. :/
Yeah, but now it went from "unsupported legacy" script to "supported up-to-date" script. I.e. bug-fixes and all =)

As for your script name thing, it's beyond nonsensical. It serves no purpose. Type it in manually if you must.
Well, there is at least some value in my usage scenario: since I'm fiddling a lot with scripts, I have "Edit this script" menu item in every panel, which opens the required script file in the editor (e.g. _.run("notepad++.exe " + pathToScriptFolder + "Panel_MainScript.js") ). And if there was a way to get a script name, I could use the same code everywhere, without editing it manually.

edit: you must realise each preprocessor must contain functions that have unique names for the them to work properly. If you define the same function multiple times with the same name, only the last instance will ever get called.
Yes, of course. As far as I understand, @import is somewhat like #include, so unique name for every globally accessible function/var is a must.

Re: JScript Panel script discussion/help

Reply #438
I still don't get it. If you have a single preprocessor file then you'd use a variable containing the file name inside the .js file itself.

Code: [Select]
var script_name = "helpers.js";

Getting the filename dynamically isn't doing anything for you. If you're constantly renaming your file... then stop being a doofus.

If you have multiple preprocessor files, I'd do one of 2 things.

a) Get all .js files in a given folder in to an array and have a custom menu that lists them all. Use utils.glob or if using my helpers.js, there is my _.getFiles function

Code: [Select]
var scripts = _.getFiles(path_to_folder, "js"); // if you want to get more than one file type, separate each one with | like "txt|log"

b) Always import a given file first and initialise a new array inside that .js file..

Code: [Select]
var scripts = ["my_script.js"];

Then in any subsequent files, add this code

Code: [Select]
scripts.push("my_script2.js");

Now build a custom menu and it will only contain menu items for the specific files used by the current script.

Re: JScript Panel script discussion/help

Reply #439
If you're constantly renaming your file... then stop being a doofus.
I probably should stop...

Now build a custom menu and it will only contain menu items for the specific files used by the current script.
Now that's a neat idea! Not sure how to implement it in my existing code yet, but I do like the concept!

Re: JScript Panel script discussion/help

Reply #440
Sorry for disturbing back again...
If GdiDrawText is called in gdi.CreateImage(), is it impossible to avoid the black edge, even if having filled a solid background behind that?

The highlighted "Oh Nana" was drawn in an image created, with the pink background just behind it in the same image, while the "(2016)" was drawn directly in on_paint() callback.

I know that drawstring() could solve this problem, but I just do not like its look, and wonder if there is a way to perfectly use GDI.
Thanks for any help or hints...

Re: JScript Panel script discussion/help

Reply #441
By the way, my reason to use temp images, is to make some scrolling effect. Like this:

Re: JScript Panel script discussion/help

Reply #442
This seems to work??

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==

var font = _.gdiFont("Segoe UI", 16, 1);
var white = _.RGB(255, 255, 255);
var black = _.RGB(0, 0, 0);
var x = 0;
var img = gdi.CreateImage(100, 30);
var gb = img.GetGraphics();
gb.gdiDrawText("JScript", font, white, 0, 0, 100, 30, CENTRE); //using my own CENTRE flag, normally you'd combine your own DT_XXX
img.ReleaseGraphics(gb);


function on_paint(gr) {
gr.FillSolidRect(0, 0, window.Width, window.Height, black);
gr.DrawImage(img, x, 0, 100, 30, 0, 0, 100, 30);
}

window.SetInterval(function () {
if (x < window.Width - 100) {
x++;
window.Repaint();
}
}, 10);

Re: JScript Panel script discussion/help

Reply #443
This seems to work??

Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==

var font = _.gdiFont("Segoe UI", 16, 1);
var white = _.RGB(255, 255, 255);
var black = _.RGB(0, 0, 0);
var x = 0;
var img = gdi.CreateImage(100, 30);
var gb = img.GetGraphics();
gb.gdiDrawText("JScript", font, white, 0, 0, 100, 30, CENTRE)
img.ReleaseGraphics(gb);


function on_paint(gr) {
gr.FillSolidRect(0, 0, window.Width, window.Height, black);
gr.DrawImage(img, x, 0, 100, 30, 0, 0, 100, 30);
}

window.SetInterval(function () {
if (x < window.Width - 100) {
x++;
window.Repaint();
}
}, 10);

It doesn't. The black edge is unsurprisingly hard to recognize when the background is also black... And if the background is red, it looks like this:

Just change "var black = _.RGB(0, 0, 0);" to any brighter color, and you'll notice the difference......

It's frustrating to see a... feature? bug? like this. I guess it's Windows's fault. Now I have to use some dirty hacks, such as caching the pseudo-transparent background and use it to overlay the hidden parts. I feel sorry of my CPU for the extra process to do...

Re: JScript Panel script discussion/help

Reply #444
Well I used black because I thought your 2nd image was your desired end result!

I very much doubt I'll be able to do anything but I'll have a look.

Re: JScript Panel script discussion/help

Reply #445
Forgot to say, even if adding "gb.FillSolidRect(0, 0, 100, 30, black);" in the temp image part, the problem remains the same.
Code: [Select]
// ==PREPROCESSOR==
// @import "%fb2k_component_path%samples\complete\js\lodash.min.js"
// @import "%fb2k_component_path%samples\complete\js\helpers.js"
// ==/PREPROCESSOR==

var font = _.gdiFont("Segoe UI", 16, 1);
var white = _.RGB(255, 255, 255);
var black = _.RGB(200, 0, 0);
var x = 0;
var img = gdi.CreateImage(100, 30);
var gb = img.GetGraphics();
gb.FillSolidRect(0, 0, 100, 30, black);
gb.gdiDrawText("JScript", font, white, 0, 0, 100, 30, CENTRE)
img.ReleaseGraphics(gb);


function on_paint(gr) {
 gr.FillSolidRect(0, 0, window.Width, window.Height, black);
 gr.DrawImage(img, x, 0, 100, 30, 0, 0, 100, 30);
}

window.SetInterval(function () {
 if (x < window.Width - 100) {
 x++;
 window.Repaint();
 }
}, 10);

Re: JScript Panel script discussion/help

Reply #446
Well I used black because I thought your 2nd image was your desired end result!

I very much doubt I'll be able to do anything but I'll have a look.
Sorry for the confusion. The second image is "what it looks if left alone", and if the mouse hovers on the text, it should have a grey background to highlight itself. In the first image I used pink to have a trial...
And the background in the second image is not "black"... It's 20-20-20, and you can recognize the 0-0-0 black edge if looking carefully.

Re: JScript Panel script discussion/help

Reply #447
Interestingly, it seems that, when selection is changed, if you have Window.Repaint() inside on_playlist_items_selection_change, on_paint method won't be called, not until on_item_focus_change is called :\

Re: JScript Panel script discussion/help

Reply #448
This works for me without an on_item_focus_change function.

Code: [Select]
var path = fb.GetFocusItem() ? fb.GetFocusItem().Path : "<nothing selected>";
var font = gdi.Font("Segoe UI", 12);

function on_playlist_items_selection_change() {
    path = fb.GetFocusItem() ? fb.GetFocusItem().Path : "<nothing selected>";
    window.Repaint();
}

function on_paint(gr) {
    gr.GdiDrawText(path, font, 0, 0, 0, window.Width, window.Height, 0);
}

I also added an empty one and it works the same.

Re: JScript Panel script discussion/help

Reply #449
This works for me without an on_item_focus_change function.
What I meant is a little different. Here is an example:

Code: [Select]
var path = fb.GetFocusItem() ? fb.GetFocusItem().Path : "<nothing selected>";
var font = gdi.Font("Segoe UI", 12);

function on_playlist_items_selection_change() {
    fb.trace("on_playlist_items_selection_change");
    path = fb.GetFocusItem().Path;
    window.Repaint();
}

function on_item_focus_change()
{
    fb.trace("on_item_focus_change");
    window.Repaint();
}

function on_paint(gr) {
    fb.trace("on_paint");
    gr.GdiDrawText(path, font, 0, 0, 0, window.Width, window.Height, 0);
}

Trace log when focus is changed:
Code: [Select]
on_playlist_items_selection_change
on_playlist_items_selection_change
on_item_focus_change
on_paint

on_paint was called only once instead of thrice. It might be an optimization feature, but it's not very intuitive and I could not find any mention about it in docs =)

[EDIT]: Do you know the difference between on_playlist_items_selection_change and on_selection_changed? What I gathered from docs is that on_selection_changed might not always work, but then why use it at all instead of always using on_playlist_items_selection_change?