<p>I'm not sure of the current state of the art, but this style of drawing windows with rounded corners originated in the NeWS graphical environment for Unix workstations. And it was accompanied by an additional nonstandard operator <code>arcto</code> into Sun's customized PostScript dialect which was then adopted into PostScript Level 2.</p>
<p><em>x<sub>1</sub> y<sub>1</sub> x<sub>2</sub> y<sub>2</sub> r</em> <strong>arcto</strong> <em>xt<sub>1</sub> yt<sub>1</sub> xt<sub>2</sub> yt<sub>2</sub></em>         append tangent arc<br />
returns the two tangent point coordinates
(<em>xt<sub>1</sub></em>, <em>yt<sub>1</sub></em>) and (<em>xt<sub>2</sub></em>, <em>yt<sub>2</sub></em>) in user space.</p>
<p>The usage of this operator can be seen in the example of the similar operator <code>arct</code> which does the same drawing but does not return tangent points.</p>
<p><a href="https://i.sstatic.net/FdH6B.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FdH6B.png" alt="arcto usage snipped from PLRM2" /></a></p>
<p>Changing <code>arct</code> to <code>arcto</code> in this example would return the points <code>0 3</code> and <code>1 4</code> while the programmer only needs to specify the points <code>0 0</code>, <code>0 4</code>, <code>4 4</code> and the radius <code>1</code>.</p>
<p>I was given a longer usage example that draws a full rectangle (er ... <em>rectar</em>) when I asked about this operator in <a href="https://groups.google.com/g/comp.lang.postscript/c/AvLVpYr2TuE/m/PjQgDUUlBwAJ" rel="nofollow noreferrer">comp.lang.postscript</a>.</p>
<p>So, a broader answer to the question is that rounded corners can be handled at the vector graphics level, pre-rendering. You can insert arc segments in the places where the corners would be into a path and then either stroke or fill the result and apply any anti-aliasing or blurring effects at the rasterization stage.</p>

CC BY-SA 4.0
2021-08-28T02:17:06.280Z
2021-08-28T04:30:53.320Z
2021-08-28T04:30:53.320Z
luser droog
<p>Speaking from my own experience...</p>
<p>There is no one answer to the question of &quot;how is this UI interface element drawn&quot;.</p>
<p>Under windows you can get them as freebies where the OS gives you a helping hand but windows tends to be very inflexible with its ready made UI element and tends to boil down to &quot;styles&quot;. But windows also provides its own graphics environment which is powerful enough that the text CGP&amp;P uses it to introduce graphics programming.</p>
<p>Linux is similar but with its own strange and wonderful quirks. But without the manufacturer provided graphics environment.</p>
<p>Beyond that, browser designers are on their own and can use a variety of techniques, here are some:</p>
<p>Bitmap graphics: This is a bit old in terms of windows... but you can just save your own &quot;bitmaps&quot; rendered however you like, then load them up and blast them to the screen just like any other texture map. But the usual caveats apply.</p>
<p>Just draw them on the fly: Basically create functions that have all the details of drawing the UI the way the project demands. Then when a UI element is needed the function provides the details on drawing the element. This approach can be kept simple or you can go crazy and end up with a vast and complex interface that only the designer understands.</p>
<p>Many graphics environments provide some sort of help with all this, but it sounds like you are writing that environment.</p>
<p>There are some new techniques that are emerging, the <a href="http://sluglibrary.com" rel="nofollow noreferrer">slug</a> library (which is a font rendering algorithm but can be used to draw many other UI elements) allow &quot;glyphs&quot; to be drawn. Using glyphs you can draw beautifully rounded and even complex corners that render surprisingly fast, scale almost perfectly, look great from any angle, the list goes on. But the algorithm behind slug is patented so you have to pay for the privilege.</p>
<p>For a simple rounded edge that looks good as a 2d element you can draw a circle at each corner, then connect the corners with straight lines. For a &quot;shadow&quot; draw 2 circles slightly offset from one another, draw the shadow circle slightly darker. Then draw a rectangle inside the entire works, and then the text or whatever is needed inside the rectangle. I know this sounds simplistic, but if done well it can look really nice, is straight forward to implement and performant. Be sure to draw the UI first and use depth buffering to help with whatever is drawn behind the UI.</p>

CC BY-SA 4.0
2021-06-30T12:36:58.793Z
2021-06-30T12:36:58.793Z
pmw1234
<p>I'm just trying to figure out, how rounded corners are usual drawn for user interfaces in a performant way &amp; as insight also try to figure out how it's done in Browser, as they allow for variable round corners (without being blurry) :)</p>
<p>In the end I try to use some of this information for the implementation of the user-interface of my game.</p>

<rendering><ui><gui>
How are rounded corners of user interfaces usually rendered in modern applications like browsers?
realvictorprm
# How are rounded corners of user interfaces usually rendered in modern applications like browsers?

(Asked by: username_0 on 2021-06-27)

I'm just trying to figure out, how rounded corners are usual drawn for user interfaces in a performant way & as insight also try to figure out how it's done in Browser, as they allow for variable round corners (without being blurry) :)

In the end I try to use some of this information for the implementation of the user-interface of my game.

**Tags:** rendering, ui, gui


---

## 2 answers

### Answer by username_1 on 2021-08-28. Score: 2 | Accepted answer

I'm not sure of the current state of the art, but this style of drawing windows with rounded corners originated in the NeWS graphical environment for Unix workstations. And it was accompanied by an additional nonstandard operator `arcto` into Sun's customized PostScript dialect which was then adopted into PostScript Level 2.

*x1 y1 x2 y2 r* **arcto** *xt1 yt1 xt2 yt2*         append tangent arc  
returns the two tangent point coordinates
(*xt1*, *yt1*) and (*xt2*, *yt2*) in user space.

The usage of this operator can be seen in the example of the similar operator `arct` which does the same drawing but does not return tangent points.

[![arcto usage snipped from PLRM2](https://i.sstatic.net/FdH6B.png)](https://i.sstatic.net/FdH6B.png)

Changing `arct` to `arcto` in this example would return the points `0 3` and `1 4` while the programmer only needs to specify the points `0 0`, `0 4`, `4 4` and the radius `1`.

I was given a longer usage example that draws a full rectangle (er ... *rectar*) when I asked about this operator in [comp.lang.postscript](https://groups.google.com/g/comp.lang.postscript/c/AvLVpYr2TuE/m/PjQgDUUlBwAJ).

So, a broader answer to the question is that rounded corners can be handled at the vector graphics level, pre-rendering. You can insert arc segments in the places where the corners would be into a path and then either stroke or fill the result and apply any anti-aliasing or blurring effects at the rasterization stage.


---

### Answer by username_2 on 2021-06-30. Score: 2

Speaking from my own experience...

There is no one answer to the question of "how is this UI interface element drawn".

Under windows you can get them as freebies where the OS gives you a helping hand but windows tends to be very inflexible with its ready made UI element and tends to boil down to "styles". But windows also provides its own graphics environment which is powerful enough that the text CGP&P uses it to introduce graphics programming.

Linux is similar but with its own strange and wonderful quirks. But without the manufacturer provided graphics environment.

Beyond that, browser designers are on their own and can use a variety of techniques, here are some:

Bitmap graphics: This is a bit old in terms of windows... but you can just save your own "bitmaps" rendered however you like, then load them up and blast them to the screen just like any other texture map. But the usual caveats apply.

Just draw them on the fly: Basically create functions that have all the details of drawing the UI the way the project demands. Then when a UI element is needed the function provides the details on drawing the element. This approach can be kept simple or you can go crazy and end up with a vast and complex interface that only the designer understands.

Many graphics environments provide some sort of help with all this, but it sounds like you are writing that environment.

There are some new techniques that are emerging, the [slug](http://sluglibrary.com) library (which is a font rendering algorithm but can be used to draw many other UI elements) allow "glyphs" to be drawn. Using glyphs you can draw beautifully rounded and even complex corners that render surprisingly fast, scale almost perfectly, look great from any angle, the list goes on. But the algorithm behind slug is patented so you have to pay for the privilege.

For a simple rounded edge that looks good as a 2d element you can draw a circle at each corner, then connect the corners with straight lines. For a "shadow" draw 2 circles slightly offset from one another, draw the shadow circle slightly darker. Then draw a rectangle inside the entire works, and then the text or whatever is needed inside the rectangle. I know this sounds simplistic, but if done well it can look really nice, is straight forward to implement and performant. Be sure to draw the UI first and use depth buffering to help with whatever is drawn behind the UI.


---

