How do you draw precise borders around a rectangle?

For general discussion related FlowStone
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

How do you draw precise borders around a rectangle?

Post by Nowhk »

This is my basic code for draw a rectlangle with a small border around it:

Code: Select all

def draw i,v
   # Background
   rc = [0,0,v.width,v.height]   
   brushBackground = Brush.new Color.new(69,75,79)
   v.drawRectangle brushBackground,rc

   # Border
   pb = Pen.new Color.new(255,255,255),0.5
   v.drawRoundRect pb,rc,0
end

def event i,v
   redraw 0
end

but as you can see, the borders in the bottom and right is tiny than top/left:

Immagine.png
Immagine.png (3.71 KiB) Viewed 19975 times

I don't know the reason. I've also tried to draw a rectangle within a rectangle (on the same (V)iew), but the problem is the same.

Maybe the conversion between points and pixels?
How can I do precise draw? Can I specify sizes in pixels?

I don't see any in the manual about this :?:

Here if you want to try the example:

# Border.fsm
(454 Bytes) Downloaded 876 times
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: How do you draw precise borders around a rectangle?

Post by Nowhk »

I've tried this suggestion: viewtopic.php?f=2&t=1074

but when I render the plug, the border bottom seems incorrect anyway:

Immagine.png
Immagine.png (5.43 KiB) Viewed 19971 times


Code: Select all

def init
   @borderWidth = 0.4
end

def draw i,v
   # Background
   rc = [@borderWidth/2,@borderWidth/2,v.width-@borderWidth,v.height-@borderWidth]   
   brushBackground = Brush.new Color.new(69,75,79)
   v.drawRectangle brushBackground,rc

   # Border
   pb = Pen.new Color.new(255,0,0),@borderWidth
   v.drawRoundRect pb,rc,0
end

def event i,v
   redraw 0
end

even thought right side is still tiny than left, even if less tiny than before...
User avatar
rocknrollkat
Posts: 213
Joined: Mon Jan 04, 2016 7:04 pm
Location: Oakland Gardens, New York City, U.S.A.
Contact:

Re: How do you draw precise borders around a rectangle?

Post by rocknrollkat »

Oh dear, a year and a half late, but anyway, here's a screenshot from the world of v.3.0.0
I don't see a problem here, could the later versions be the cause ?

ROXY
Attachments
Better late than never, does this help anyone ?
Better late than never, does this help anyone ?
screenshot-borders.png (676.62 KiB) Viewed 19935 times
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: How do you draw precise borders around a rectangle?

Post by Nowhk »

I don't know? 3.0.8 (FL) and 3.0.7 (standalone, demo) does it :shock:
Did you try with my code?
User avatar
Loopeytunes
Posts: 57
Joined: Tue Jul 13, 2010 11:07 am
Location: Yorkshire, UK
Contact:

Re: How do you draw precise borders around a rectangle?

Post by Loopeytunes »

The only work around for now that I can see is setting the "rc = [0,0,v.width,v.height]" to "rc = [-0.08,-0.08,v.width,v.height]".

It's not precise but it's a possible work around until they fix it if it is an issue with the later versions?
User avatar
Spogg
Posts: 3368
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England
Contact:

Re: How do you draw precise borders around a rectangle?

Post by Spogg »

Loopeytunes wrote:The only work around for now that I can see is setting the "rc = [0,0,v.width,v.height]" to "rc = [-0.08,-0.08,v.width,v.height]".

It's not precise but it's a possible work around until they fix it if it is an issue with the later versions?


Ruby isn't my thing but I have noticed when messing with old Synthmaker non-Ruby stuff that a border may not fit correctly to the view area (FS 3.08.1). I remember fiddling around for ages trying to get a dropbox menu selector to have the right border. The right-hand and bottom edges were reduced in thickness.

It might be to do with the co-ordinates system which, I believe, start at the upper left corner. In this case if the drawing starts at a specified width and height then the right and lower lines will be created outside of the view area. If this is the case it would mean the co-ordinates for the start positions of the right and lower edges would have to depend on the thickness specified; change the thickness and you'd have to change the co-ordinates.

I bet someone knows about this...?

Cheers

Spogg
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: How do you draw precise borders around a rectangle?

Post by tulamide »

What's so difficult in using the search function/Google?

http://www.dsprobotics.com/support/viewtopic.php?f=2&t=3246&p=17305#p17295
"There lies the dog buried" (German saying translated literally)
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: How do you draw precise borders around a rectangle?

Post by Nowhk »

tulamide wrote:What's so difficult in using the search function/Google?

http://www.dsprobotics.com/support/viewtopic.php?f=2&t=3246&p=17305#p17295

But this does not address to my problem with border. Ive already set middle of the pen on the angles, but borders are still differents. :shock:
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: How do you draw precise borders around a rectangle?

Post by tulamide »

Nowhk wrote:
tulamide wrote:What's so difficult in using the search function/Google?

http://www.dsprobotics.com/support/viewtopic.php?f=2&t=3246&p=17305#p17295

But this does not address to my problem with border. Ive already set middle of the pen on the angles, but borders are still differents. :shock:

They look different because it is drawn partly outside the view. If you want to make sure that there is no interpolation going on, try the same with pixel accurate values. If you didn't change the grid settings, 1 grid unit refers to 8 pixels. Then 0.4 means 3.2 pixels. Instead try it with multiples of 0.125 (which is 1 pixel) and see if the issue stays.

If not, then the interpolation because of subpixels were the cause and you should avoid using them.
"There lies the dog buried" (German saying translated literally)
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: How do you draw precise borders around a rectangle?

Post by Nowhk »

tulamide wrote:
Nowhk wrote:
tulamide wrote:What's so difficult in using the search function/Google?

http://www.dsprobotics.com/support/viewtopic.php?f=2&t=3246&p=17305#p17295

But this does not address to my problem with border. Ive already set middle of the pen on the angles, but borders are still differents. :shock:

They look different because it is drawn partly outside the view. If you want to make sure that there is no interpolation going on, try the same with pixel accurate values. If you didn't change the grid settings, 1 grid unit refers to 8 pixels. Then 0.4 means 3.2 pixels. Instead try it with multiples of 0.125 (which is 1 pixel) and see if the issue stays.

If not, then the interpolation because of subpixels were the cause and you should avoid using them.

Thanks for the help, even if you tell me you will never help to me anymore :roll:
However, the problem happens the same. My grid is 1. I've set borderWidth 0.5 (which is a multiple of 0.125):

Code: Select all

def init
   @borderWidth = 0.5
end

def draw i,v
   # Background
   rc = [@borderWidth/2,@borderWidth/2,v.width-@borderWidth,v.height-@borderWidth]   
   brushBackground = Brush.new Color.new(69,75,79)
   v.drawRectangle brushBackground,rc

   # Border
   pb = Pen.new Color.new(255,0,0),@borderWidth
   v.drawRoundRect pb,rc,0
end

def event i,v
   redraw 0
end

but I see the same. Or better: inside the schematic "maybe" it's a bit better (even if not precise at 100%; border top is slightly bigger than bottom):

001.png
001.png (3.44 KiB) Viewed 19900 times

When I switch to Focus Mode (i.e. the result when I'll render the plugin) the difference is even more noticeable:

002.png
002.png (10.58 KiB) Viewed 19900 times

Do you see the same?

Rectangle Border.fsm
(484 Bytes) Downloaded 930 times
Post Reply