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 (Read 137348 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: JScript Panel

Reply #801
gr.DrawImage(utils.LoadImage("o:\\1.jpg"),0,0,200,200,0,0,0,200);
A picture with zero size will invalidate all drawings.

Not sure what you mean?? If the image is not valid, utils.LoadImage should return null which should cause a script error.

If you unsure about an image existing or being valid then you should check it something like this...

Code: [Select]
var image = utils.LoadImage("o:\\1.jpg");

function on_paint(gr) {
    if (image) {
        gr.DrawImage(image,0,0,200,200,0,0,0,200);
    }
}

Image is valid.
gr.DrawImage(......, srcW, srcH);
When srcW or srcH equals 0, the script does not crash, but all drawings fail and the whole panel turn black.
By comparison, foo_jscript_panel3 and foo_jscript_panel perform differently. You can try it yourself.

Re: JScript Panel

Reply #802
Well the previous behaviour of silently ignoring idiotic bad arguments is just as bad as displaying a black panel so the next version will correctly throw script errors so everyone knows not to be so stupid. Thanks for reporting.

Re: JScript Panel

Reply #803
Well the previous behaviour of silently ignoring idiotic bad arguments is just as bad as displaying a black panel so the next version will correctly throw script errors so everyone knows not to be so stupid. Thanks for reporting.

I think 0 is a perfectly normal value, which is inevitable in many cases.
I remember there was a similar problem in Spider Monkey Panel. When you draw a rectangle, it crashes if the width or height is equal to 0. It's ridiculous. (Now it must have been repaired.)
In a natural process of change, the emergence of a natural number is not allowed.

Re: JScript Panel

Reply #804
Width or height of 0 is not normal in drawing, though. If either dimension is 0, the object is effectively not being drawn.

 

Re: JScript Panel

Reply #805
Width or height of 0 is not normal in drawing, though. If either dimension is 0, the object is effectively not being drawn.

As you said, a size of 0 means nothing is painted. (JScript Panel 2).
This is exactly what I want.

Re: JScript Panel

Reply #806
Then don't call the function? You do know you can conditionally not call something.

Re: JScript Panel

Reply #807
I've been setting a bad example in my own scripts by not checking the src width/height before drawing but the only way that could happen was if they were calculated from the panel width/height which would have to be zero and therefore not visible. Default UI won't even let you resize that low but I guess it's possible with Columns/Panel Stack Splitter.

Setting these args as zero when the panel has proper dimensions and is visible is just really stupid. If calling the function succeeded, what exactly do you expect to see??

I really hate doing it but I've updated the function to silently bail if the src w/h are bad,

https://github.com/marc2k3/jscript-panel/releases

edit: the difference in behaviour between v3 and previous versions is because I'm using Direct2D instead of Gdiplus. Gdiplus was generally very tolerant of bad args everywhere but it seems more care is needed now. I already have special conditions in place where drawing text isn't even attempted if the width/height are less than 12px. I discovered this quite early on in my testing!

Re: JScript Panel

Reply #808
gr.DrawRectangle(50, 50, 100, 100, 1, 0xffffffff);
Is my method wrong? I can't draw a line with a pixel width.
The minimum width is 2 pixels and the color is not correct.

Re: JScript Panel

Reply #809
Well I'm passing the args untouched to the windows APIs so not really sure what is going on there. You could try adding or subtracting 0.5 from the x and y values and see if that makes any difference??


Re: JScript Panel

Reply #810
Possibly relevant is the strokeWidth documentation here...

https://docs.microsoft.com/en-us/windows/win32/api/d2d1/nf-d2d1-id2d1rendertarget-drawrectangle(constd2d1_rect_f__id2d1brush_float_id2d1strokestyle)

Quote
The width of the stroke, in device-independent pixels. The value must be greater than or equal to 0.0f. If this parameter isn't specified, it defaults to 1.0f. The stroke is centered on the line.