Skip to main content
Topic: Spider Monkey Panel (foo_spider_monkey_panel) (Read 58326 times) previous topic - next topic
davideleo and 1 Guest are viewing this topic.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #350
There is `Function.caller` (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller), which can be abused to get the name of the function. But this will not be performance friendly (constant regexp parsing) and this method is unavailable in strict mode anyway.

Yes, I tried that and it actually crashed the panel, because indeed I am using strict mode. But then, why does this function I use for debugging purposes work in strict mode?
Spoiler (click to show/hide)


Retrieving caller information was deemed a problematic feature for multiple reasons:
- Makes some optimizations impossible.
- Easy to abuse to make code unreadable.
- (Web-specific) potential security vulnerabilities.

I read a bit about this topic in the last days, in search for a solution, and I understand that these caller methods are vestiges of a pre-named-functions era in javascript, but it is exactly the name of the function that I need to have, not the function itself, which is probably the only case when a caller method makes sense. I also understand how uncertain it is to rely on a "function name", which is actually not a property of the function, just one of many possible references to it. But when that reference is an object property, it is definitely more reliable.

Whatever. All in all it seems that the ECMA guys know what they are doing. The thesis that if you think you need the caller method, there is likely a better way to do what you are trying to do, turned out to be true, at least for me. As is often the case, posting the problem on the forum cleared my mind and I realized I actually don't need the method's name, I actually don't need all those methods at all, but just the forward method with an argument, from the head of the chain, so my container constructor is now something like this:
Spoiler (click to show/hide)

It might be a little meaningless out of context, but I got rid of several lines of code and the final result is a lot more concise than it would have been with a caller-like workaround. Sorry if this was a waste of time, but I just wanted to witness the wisdom of javascript constraints, which I was cursing until yesterday night, and blessing today for pushing me into better coding.


Are you using SMP panel as a standalone CUI/DUI panel? Or is it a part of smth like PSS?

I was using PSS, but since I don't need it (thanks for reminding me!), I removed it and tested it again, with CUI and with DUI. The on_size() callback is always triggered three times in a row, and the window size is always 0x0 on the first, full width x full height on the third and intermediate values in the second, but these are different with DUI, CUI and PSS.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #351
For reasons I don't understand, it only works with columns ui, maybe some more advanced coder can figure out why,

I still don't understand the reason, but at least now I know that to make it work in DUI I need to set the window dialog code to 4 (DLGC_WANTALLKEYS). At first I thought the reason was the default dlgcode in CUI, but I checked and with both UI, SMP has a default dlgcode set to 0. Can anybody explain me why DUI needs a different dlg code to take key events?

I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #352
dear developer(s)

I am facing the following message after installing the latest fsmp version.
I am using latest foobar 1.5 and I have attached a report of installed components.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #353
But today I found out that the second on_size() sets the window to an intermediate measure, which my code was not expecting.
I could not reproduce this behaviour, do you have a reproducible scenario?

Regarding repeated on_size calls: these are only invoked when the panel receives WM_SIZE message (except for one extra invocation which will be removed in the next version. These messages might be triggered by fb2k, by DUI, by CUI or by system itself. SMP just translates this native system message to JS callback.

I am facing the following message after installing the latest fsmp version.
I am using latest foobar 1.5 and I have attached a report of installed components.

You probably didn't install all the required fonts (which are listed in readme.md in samples folder).

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #354
I could not reproduce this behaviour, do you have a reproducible scenario?

Yes, a very simple one: clean portable installation (v1.5.1 beta 2) with only two extra components: spider monkey panel and columns ui. No library, no playlists.
The columns ui layout is just one spider monkey panel, as a base, with this script:
Code: [Select]
function on_size(){
    console.log("width: " + window.Width, "height: " + window.Height);
}

And here's the console output on startup:
Quote from:  the console log
width: 0 height: 0
width: 0 height: 0
width: 1139 height: 593
width: 1366 height: 705

Regarding repeated on_size calls: these are only invoked when the panel receives WM_SIZE message (except for one extra invocation which will be removed in the next version. These messages might be triggered by fb2k, by DUI, by CUI or by system itself. SMP just translates this native system message to JS callback.

I get it. After reading your explanation I recreated the above scenario without CUI and here's the console log:
Quote from: the console log
width: 0 height: 0
width: 1364 height: 653

The height is lower than CUI in the final size because of the toolbars.
So, it looks like the intermediate sizing is triggered by CUI. Problem solved. I don't need CUI actually, but for removing toolbars. BTW, replacing a whole interface only to get rid of the toolbars is kind of ridiculous, isn't it?
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #355
Hello @TheQwertiest, I have a big problem with Foobar 1.5 beta 2 crashing at start while loading SMP.

I also tried the last nightly build having the same crash on start.
Probably the case to notify also Peter. I didn't do yet.

Attached the crash report files

Kind regards, Andrea

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #356
But today I found out that the second on_size() sets the window to an intermediate measure, which my code was not expecting.
I could not reproduce this behaviour, do you have a reproducible scenario?

Regarding repeated on_size calls: these are only invoked when the panel receives WM_SIZE message (except for one extra invocation which will be removed in the next version. These messages might be triggered by fb2k, by DUI, by CUI or by system itself. SMP just translates this native system message to JS callback.

I am facing the following message after installing the latest fsmp version.
I am using latest foobar 1.5 and I have attached a report of installed components.

You probably didn't install all the required fonts (which are listed in readme.md in samples folder).

I have all fonts installed (Guifx v2 Transports, fontawesome-webfont,wingdings2.ttf and wingdings3.ttf).


Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #358
Hello @TheQwertiest, thanks for the prompt reply.
Please, if you don't mind, kindly drop me a message (here or private) when the new Nightly Build is ready for testing.
Many thanks and kind regards, Andrea

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #359
@AndreaT, nightly build with the fix is up.

@zoumbro , I was reminded by @marc2k3 that it's a known (and fixed) problem in the script. Regrettably, there is no release build yet which has the fix. So, you can either download the nightly build (see OP for the link), or download and replace all the scripts manually (https://github.com/TheQwertiest/foo_spider_monkey_panel/tree/master/component/samples)

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #360
Hello @TheQwertiest, well done! Now it works fine again. Many thanks. Regards, Andrea

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #361
I'd like to get back to this clipping procedure, which as far as I understand is the SMP translation of this windows GDI+ clipping technique. As far as clipping i concerned, it works as it should, but the text rendering sucks. I didn't realize this at first because I was working with white text on black background. In the code below, I added some text in the clipped region and changed the colours to make the problem visible.

Code: [Select]
include(fb.ComponentPath + "docs\\helpers.js");

let font = gdi.Font("segoe UI", 16);
let myRegion = new PaintRegion(100, 100, 200, 200)


function on_paint(gr){
gr.FillSolidRect(0, 0, window.Width, window.Height, colours.DarkGray);
gr.GdiDrawText("TEST", font, colours.White,110, 70, 100, 20)
    myRegion.paint(gr);
}


function PaintRegion(x, y, w, h){
    this.x = x;
    this.y = y;
    this.w = w;
    this.h = h;
    this.paint = (gr) => {
gr.FillSolidRect(this.x, this.y, this.w, this.h, colours.Pink);
        var clipImg = gdi.CreateImage(this.w, this.h)
        var grClip = clipImg.GetGraphics();

grClip.GdiDrawText("TEST", font, colours.White, 10, 10, 100, 20)
grClip.DrawEllipse(100, 50, 200, 200, 2, colours.White);

        clipImg.ReleaseGraphics(grClip);
        gr.DrawImage(clipImg, this.x, this.y, this.w, this.h, 0, 0, this.w, this.h)
    }
}

In the attached picture you can see the outcome. The first line of text on gray background is drawn with the regular graphics object passed by the on_paint callback, the one below, in the pink clipped region is drawn with the clipped graphics object. SetTextRenderingHint and SetSmoothingMode didn't help.

How can I avoid this blurred effect?
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #362
How can I avoid this blurred effect?

So, apparently the problem is the DrawText function. Once more posting to the forum helped me find the answer. I finally found a case where you actually need the DrawString method.

P. S.
Upon reading some window .NET docs on GDI+ and TextRender, I have the impression that the use of DrawString is strongly encouraged, whereas I get the opposite idea from the SMP docs. Are the two methods actually the same? And what are the drawbacks of replacing DrawText with DrawString, anyway?
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #363
Upon reading some window .NET docs on GDI+ and TextRender, I have the impression that the use of DrawString is strongly encouraged, whereas I get the opposite idea from the SMP docs. Are the two methods actually the same? And what are the drawbacks of replacing DrawText with DrawString, anyway?
DrawString is worse than DrawText in most cases. DrawText has better performance and better rendering unless used on a transparent surface (as mentioned in SMP docs).
One of the sources: https://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number/6404811#6404811

Regarding your problem. Quote from docs (https://theqwertiest.github.io/foo_spider_monkey_panel/assets/generated_files/docs/html/GdiGraphics.html#GdiDrawText):
Quote
GdiDrawText
    Provides faster and better rendering than GdiGraphics#DrawString.

    Do not use this to draw text on transparent background or with GdiGraphics other than the one passed in on_paint callback: this will result in visual artifacts caused by ClearType hinting.
    Use GdiGraphics#DrawString instead in such cases.

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #364
DrawString is worse than DrawText in most cases. DrawText has better performance and better rendering unless used on a transparent surface (as mentioned in SMP docs).
One of the sources: https://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-number/6404811#6404811

Thanks, this was very, very useful.
I'm late

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #365
Firstly, MERRY X MAS! and thx for the great component.
It looks like DrawImage() in SMP is generating left and top border by default. How can I avoid this?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #366
Firstly, MERRY X MAS! and thx for the great component.
It looks like DrawImage() in SMP is generating left and top border by default. How can I avoid this?
o/
What version of SMP are you using?

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #367
o/
What version of SMP are you using?
I am using v1.2.2-preview+0db3c6a4. I tried simply comment out the relevant line in JScommon.js as below, but the borders are still there in jssb.
Code: [Select]
function drawImage(gr, img, src_x, src_y, src_w, src_h, auto_fill, border, alpha) {

if (border) {
// gr.DrawRect(src_x, src_y, src_w - 1, src_h - 1, 1, border);
}
}

-eidt-
I digged google a little bit, it looks like borders are generated during resizing images
https://mariusschulz.com/blog/preventing-ghost-borders-when-resizing-images-with-system-drawing

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #368
Hi
Today my AV shows info about virus in file foo_lastfm_img.vbs. Anyone have the same problem?



Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #370
@seongbin , glad to hear that your problem was resolved. Sorry for the lack of answers - was on a vacation and (mostly) away from the internet...

@kowal24 , false-positive (you can view the code of the script to manually verify that).

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #371
Hi,

I've got an issue related to search query and multi values tags.
I'm searching in my whole library the tracks by an artist simply named "bob".
I could do
fb.GetQueryItems(fb.GetLibraryItems(), "%artist% IS bob");
but then it won't return the tracks tagged with multi values, like "bob; nirvana".

In order to include the tracks tagged with multiple artists, I could do
fb.GetQueryItems(fb.GetLibraryItems(), "%artist% HAS bob");
but then it will return all tracks with bob inside their artist name, like bob dylan, and not all tracks by the artist simply named "bob".

Does someone there have an idea? Thanks!

Re: Spider Monkey Panel (foo_spider_monkey_panel)

Reply #372
Does someone there have an idea? Thanks!
fb.GetQueryItems uses fb2k query rules. I.e. you can use and test this query in default CUI playlist_view search. So I think you are more likely to get a proper answer if you create a separate thread in General forum section.

 
SimplePortal 1.0.0 RC1 © 2008-2020