How to draw a rectangle with only two rounded corners?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to draw a rectangle with only two rounded corners?
Hi to all )
I have been struggling with trigonometric functions and looking up mathematical formulas for plotting to draw rectangles that have two upper rounded corners and two usual lower 90 degree corners.
This is required for an app supporting Material Design where it is used and forms the outline of a field. A field here consists of several elements, and I am using a group to combine all those elements as a field object to make it look and behave like a text field as defined in Material Design.
Reference: https://material.io/components/text-fields#usage
I was thinking using our graphics "line" or "curve" tool, but the results are not promising so far.
Conceptionally, the upper round of the upper corners are defined by circles inside the rectangle and touching the left or right and upper lines at two offset points from the corners.
I was thinking of drawing the rectangle based on x,y coordinates starting at some coordinate point and going all the way around. But how are the rounded x,y coordinates calculated? Or is this the wrong approach? Or could it be better done using SVG paths?
Has anybody done something like this before, or how to approach such a problem?
Ideally, of course, there is a predefined object that can just be drawn like the "rounded rectangle" we have. The result must be an object for which at least all the standard properties can be defined: Border size/color, background color, etc.
Thank you for ideas... )
Roland (golife)
I have been struggling with trigonometric functions and looking up mathematical formulas for plotting to draw rectangles that have two upper rounded corners and two usual lower 90 degree corners.
This is required for an app supporting Material Design where it is used and forms the outline of a field. A field here consists of several elements, and I am using a group to combine all those elements as a field object to make it look and behave like a text field as defined in Material Design.
Reference: https://material.io/components/text-fields#usage
I was thinking using our graphics "line" or "curve" tool, but the results are not promising so far.
Conceptionally, the upper round of the upper corners are defined by circles inside the rectangle and touching the left or right and upper lines at two offset points from the corners.
I was thinking of drawing the rectangle based on x,y coordinates starting at some coordinate point and going all the way around. But how are the rounded x,y coordinates calculated? Or is this the wrong approach? Or could it be better done using SVG paths?
Has anybody done something like this before, or how to approach such a problem?
Ideally, of course, there is a predefined object that can just be drawn like the "rounded rectangle" we have. The result must be an object for which at least all the standard properties can be defined: Border size/color, background color, etc.
Thank you for ideas... )
Roland (golife)
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
Presumably you could make a vector image in Inkscape, export it as an SVG and then bring
it into a LiveCode stack?
it into a LiveCode stack?
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
I drew a picture in GIMP:
- -
Imported it into Inkscape and traced the bitmap to end up with a vector:
- -
and then used my own SVG importer stack to turn it into an SVG widget in LiveCode:
-
- -
Imported it into Inkscape and traced the bitmap to end up with a vector:
- -
and then used my own SVG importer stack to turn it into an SVG widget in LiveCode:
-
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
Have a happy time . . .
-
-
- Attachments
-
- SVG Importer.livecode.zip
- Here's the stack.
- (105.73 KiB) Downloaded 125 times
-
- VIP Livecode Opensource Backer
- Posts: 4028
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: How to draw a rectangle with only two rounded corners?
Hi Roland,
Maybe Ralf Bitters widget can help
https://github.com/revig/universal-button-widget
Download
https://github.com/revig/universal-butt ... .1.0.5.lce
and then use the "Extension Manager" from menu "Tools" to install the widget. It will show up in your "Tool" floating window. Drag it from there and use the Properties Inspector to set the top corners to rounded.
Kind regards
Bernd
Maybe Ralf Bitters widget can help
https://github.com/revig/universal-button-widget
Download
https://github.com/revig/universal-butt ... .1.0.5.lce
and then use the "Extension Manager" from menu "Tools" to install the widget. It will show up in your "Tool" floating window. Drag it from there and use the Properties Inspector to set the top corners to rounded.
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 9754
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to draw a rectangle with only two rounded corners?
I do this all the time, building 1,2,3 and 4 rounded-corner-rectangles. But I have to do it by joining arcs onto straight lines, because, as you know, LC does not have those native shapes. In fact, the CAD programs I use do not either.
So just as in a CAD program, I would have to set the arcAngles and radii, and join them all as required. I use native tools to make that happen. In CAD, to use one method, objects snap to vertices. In LC, the several properties like "topLeft" or "right" can be used once the shapes are drawn, as in:
Craig
So just as in a CAD program, I would have to set the arcAngles and radii, and join them all as required. I use native tools to make that happen. In CAD, to use one method, objects snap to vertices. In LC, the several properties like "topLeft" or "right" can be used once the shapes are drawn, as in:
Code: Select all
set the topLeft of grc "myUpperRightArc" to the right of grc "myUpperStraightLine"
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
It is a pity that:
1. The rounded rectangle vectors provided in LC since version 8 cannot really have a zero rounded corner.
2. That each corner is not adjustable.
1. The rounded rectangle vectors provided in LC since version 8 cannot really have a zero rounded corner.
2. That each corner is not adjustable.
Re: How to draw a rectangle with only two rounded corners?
Use Ralf Bitters widget, as Bernd wrote earlier.
It does exactly what you need, e.g. "Each corner IS adjustable there" and more.
It does exactly what you need, e.g. "Each corner IS adjustable there" and more.
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
Certainly a lot better than the 20 minutes I spent on importing an SVG.Use Ralf Bitters widget
Re: How to draw a rectangle with only two rounded corners?
Oh, thanks a lot, Bernd, and all. I will check it out the widget.
Roland
Roland
Re: How to draw a rectangle with only two rounded corners?
There is a widget that will let you draw a rect and make any of the corners rounded independently of each other - but alas, i cannot for the life of me recall where i got it from. It works really well.
I attach the .zip file from my extensions folder (remember you need to import this via Tools menu -> extension manager).
Hope this helps,
Stam
-- edited to include screen shot (and to hide my missing the link to Ralph's extension - this isn't it i don't think).
I attach the .zip file from my extensions folder (remember you need to import this via Tools menu -> extension manager).
I believe this will do exactly what you need it to Roland, just edit the top right/top left and it will do exactly what you've requested...
Hope this helps,
Stam
-- edited to include screen shot (and to hide my missing the link to Ralph's extension - this isn't it i don't think).
- Attachments
-
- community.livecode.hoerwi.customrect.1.1.0.zip
- (10.9 KiB) Downloaded 130 times
Last edited by stam on Thu Nov 18, 2021 7:42 pm, edited 3 times in total.
-
- Livecode Opensource Backer
- Posts: 9455
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: How to draw a rectangle with only two rounded corners?
I wrote:
can have many more properties adjusted than those of a widget.
Because a LiveCode vector and a widget are 2 different beasts, and a LiveCode vector (graphic object)It is a pity that:
can have many more properties adjusted than those of a widget.
Re: How to draw a rectangle with only two rounded corners?
Further to my previous post, as i just zipped the the extension folder it may not work and it probably won't work if you try to 'import' via extensions manager. If that is the case, try just putting the folder in your 'extensions' folder (not the 'plugins' folder)
Looks like this was created by Andreas Strauch, but i can't find the source - if i do, i'll post it here...
S.
PS: absolutely no sign of this anywhere. I wonder if it's been actively 'disappeared' as it was a community project...
Looks like this was created by Andreas Strauch, but i can't find the source - if i do, i'll post it here...
S.
PS: absolutely no sign of this anywhere. I wonder if it's been actively 'disappeared' as it was a community project...
-
- VIP Livecode Opensource Backer
- Posts: 9857
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: How to draw a rectangle with only two rounded corners?
That would depend on what you mean by "disappeared".
In the history of these forums I've seen only a small handful of non-spam posts deleted by the forum managers, most in two recent threads which had descended into forum members insulting each other, and both of which had several days of advance notice before deletion.
On the other hand, I've seen many forum members delete their own content here, sometimes with surprising thoroughness.
Did the file even originate here? Might it have been posted in any of the other more likely venues like GitHub or the author's website?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: How to draw a rectangle with only two rounded corners?
Sadly i have absolutely no recollection where i got this from.
Googling this led nowhere - even including the name of the author, which is embedded in the extension.
In fact google takes me to a page saying that some results may be hidden, as possibly the EU 'right to be forgotten' seems have been invoked.
Looking on LiveCodeShare, this author does have other stacks there but this doesn't show.
Trying various related searches only show a facebook post from this author with a youtube video demo'ing it in the LC devs facebook group, but i could not see a link to download it.
link: https://www.facebook.com/groups/liveco ... 987097973/
It's possible i'm missing something obvious but i cannot find the source anywhere - and it's such a useful extension!
Googling this led nowhere - even including the name of the author, which is embedded in the extension.
In fact google takes me to a page saying that some results may be hidden, as possibly the EU 'right to be forgotten' seems have been invoked.
Looking on LiveCodeShare, this author does have other stacks there but this doesn't show.
Trying various related searches only show a facebook post from this author with a youtube video demo'ing it in the LC devs facebook group, but i could not see a link to download it.
link: https://www.facebook.com/groups/liveco ... 987097973/
It's possible i'm missing something obvious but i cannot find the source anywhere - and it's such a useful extension!