haiku-website/static/legacy-docs/bebook/BRect_Overview.html

53 lines
8.8 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Interface Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheInterfaceKit_Overview.html" title="The Interface Kit" /><link rel="prev" href="BRadioButton_Overview.html" title="BRadioButton" /><link rel="next" href="BRegion_Overview.html" title="BRegion" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BRadioButton_Overview.html" title="BRadioButton"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheInterfaceKit_Overview.html" title="The Interface Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BRegion_Overview.html" title="BRegion"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Interface Kit</div></div><div id="headerB">Prev: <a href="BRadioButton_Overview.html">BRadioButton</a>  Up: <a href="TheInterfaceKit_Overview.html">The Interface Kit</a>  Next: <a href="BRegion_Overview.html">BRegion</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BRect_Overview"></a>BRect</h2></div></div></div><a id="id555033" class="indexterm"></a><p>A <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>
object represents a rectangle.
<a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>s are used throughout the
Interface Kit to define the frames of windows, views, bitmaps—even
the screen itself. A <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>
is defined by its four sides, expressed as the
public data members <code class="varname">left</code>, <code class="varname">top</code>,
<code class="varname">right</code>, and <code class="varname">bottom</code>.</p><div class="mediaobject"><img src="./images/TheInterfaceKit/rect1.png" alt="A rectangle" /></div><p>
When used in the screen coordinate system(as a window or view's frame,
for example) a
<a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>'s
sides are aligned with the x and y axes (as shown
here), and its coordinate values, which are stored as floats, are floored.
</p><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id555122"></a>Rectangle Size and Area</h3></div></div></div><p>
You would expect a <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a> defined thus…:
</p><pre class="programlisting example cpp"><a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a> <code class="varname">rect</code>(0, 0, 3, 3);</pre><p>
…to have a width of 3.0 and a height of 3.0. These, indeed, are the
values returned by the
<a class="link" href="BRect.html#BRect_Width" title="Width(), IntegerWidth(), Height(), IntegerHeight()"><code class="methodname">Width()</code></a> and
<a class="link" href="BRect.html#BRect_Height"><code class="methodname">Height()</code></a> functions. However, the
coordinate system considers integer coordinates to fall in the center of
pixels, so the rectangle "touches" a 4x4 pixel grid when it's applied to
the screen—it appears one pixel wider and one higher than
<a class="link" href="BRect.html#BRect_Width" title="Width(), IntegerWidth(), Height(), IntegerHeight()"><code class="methodname">Width()</code></a> and
<a class="link" href="BRect.html#BRect_Height"><code class="methodname">Height()</code></a>
would have you believe. The mapping of rectangle coordinates
to pixels is explained in greater detail in
"<a class="xref" href="TheInterfaceKit_The_Coordinate_Space.html" title="The Coordinate Space">The Coordinate Space</a>".
</p><div class="mediaobject"><img src="./images/TheInterfaceKit/pix_grid.png" alt="Pixels Covered By A Rectangle" /></div><p>
A rectangle's area includes the points that lie along its sides, but it
doesn't necessarily contain the entire area of the pixels that it "lights
up." For example, consider the point at (3.1, 3.1). This point falls
outside the (0,0,3,3) <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a> defined above (i.e the point doesn't
Intersect() with the <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>), even though it corresponds to one of the
pixels that the <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a> touches (as shown here).
</p><div class="mediaobject"><img src="./images/TheInterfaceKit/rect_point.png" alt="Point Outside Rectangle But Drawn Anyway" /></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="id555261"></a>Rectangle Validity</h3></div></div></div><p>
To represent a valid rectangle, a
<a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>'s
top value must be less than or equal to bottom, and its left must be less than or equal to right.
Invalid rectangles are meaningless and can't be used (to define a window
or view's area, etc.) Note that the <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a>
constructor and <code class="methodname">Set…()</code>
function don't prevent you from creating an invalid rectangle. Use the
<a class="link" href="BRect.html#BRect_IsValid" title="IsValid()"><code class="methodname">IsValid()</code></a>
boolean function to test a <a class="link" href="BRect.html" title="BRect"><code class="classname">BRect</code></a> object's validity.
</p></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BRadioButton_Overview.html">BRadioButton</a>  Up: <a href="TheInterfaceKit_Overview.html">The Interface Kit</a>  Next: <a href="BRegion_Overview.html">BRegion</a> </div><div id="footerB"><div id="footerBL"><a href="BRadioButton_Overview.html" title="BRadioButton"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheInterfaceKit_Overview.html" title="The Interface Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BRegion_Overview.html" title="BRegion"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>