📄 rect.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: rect.hpp,v $ * PRODUCTION Revision 1000.0 2004/06/01 19:56:42 gouriano * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== */#ifndef GUI_WIDGETS_FL___RECT__HPP#define GUI_WIDGETS_FL___RECT__HPP/* $Id: rect.hpp,v 1000.0 2004/06/01 19:56:42 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Andrey Yazhuk * * File Description: * *//** @addtogroup GUI_FltkWidgets * * @{ */BEGIN_NCBI_SCOPEclass CPoint{public: CPoint() : m_X(0), m_Y(0) {} CPoint(int x, int y) : m_X(x), m_Y(y) {} int X() const { return m_X; } int Y() const { return m_Y; } inline CPoint& operator+=(const CPoint& pt) { m_X += pt.m_X; m_Y += pt.m_Y; return *this; }public: int m_X; int m_Y;};/// CRect represent a rectangle int screen coordinate system (origin in the top /// left corner).class CRect{public: CRect() : m_Left(0), m_Top(0), m_Right(0), m_Bottom(0) { } CRect(int x, int y) : m_Left(x), m_Top(y), m_Right(x), m_Bottom(y) { } CRect(int left, int top, int right, int bottom) : m_Left(left), m_Top(top), m_Bottom(bottom), m_Right(right) { } void Init(); void Init(int x, int y); void Init(int left, int top, int right, int bottom); inline int Left() const; inline int Top() const; inline int Right() const; inline int Bottom() const; inline int Width() const; inline int Height() const; inline CPoint CenterPoint() const; inline void SetLeft(int left); inline void SetBottom(int bottom); inline void SetRight(int right); inline void SetTop(int top); inline void SetHorz(int left, int right); inline void SetVert(int bottom, int top); inline void SetSize(int width, int height); inline void MoveLeft(int shift); inline void MoveRight(int shift); inline void MoveBottom(int shift); inline void MoveTop(int shift); inline bool operator==(const CRect& rc) const; inline bool operator!=(const CRect& rc) const; inline bool IsEmpty() const; inline bool PtInRect(int x, int ) const; bool PtInRect(const CPoint& pt) const; bool Intersects(const CRect& rc) const; // operations inline void Inflate(int d_x, int d_y); inline void Offset(int d_x, int d_y); inline CRect& IntersectWith(const CRect& r); inline CRect& CombineWith(const CRect& r);public: int m_Left; int m_Top; int m_Right; int m_Bottom;};inline void CRect::Init() { m_Left = m_Top = m_Right = m_Bottom = 0; }inline void CRect::Init(int x, int y){ m_Left = m_Right = x; m_Bottom = m_Top = y;}inline void CRect::Init(int left, int top, int right, int bottom){ m_Left = left; m_Top = top; m_Right = right; m_Bottom = bottom;}inline int CRect::Left() const { return m_Left; }inline int CRect::Top() const { return m_Top; }inline int CRect::Right() const { return m_Right; }inline int CRect::Bottom() const { return m_Bottom; }inline int CRect::Width() const{ return m_Right - m_Left + 1; } inline int CRect::Height() const{ return m_Bottom - m_Top + 1; }inline CPoint CRect::CenterPoint() const{ return CPoint((m_Left + m_Right) / 2, (m_Top + m_Bottom) / 2);}inline void CRect::SetLeft(int left) { m_Left = left; }inline void CRect::SetBottom(int bottom) { m_Bottom = bottom; }inline void CRect::SetRight(int right) { m_Right = right; }inline void CRect::SetTop(int top) { m_Top = top; }inline void CRect::SetHorz(int left, int right){ m_Left = left; m_Right = right;}inline void CRect::SetVert(int bottom, int top){ m_Bottom = bottom; m_Top = top;}inline void CRect::SetSize(int width, int height){ m_Right = m_Left + width - 1; m_Top = m_Bottom + height - 1;}inline void CRect::MoveLeft(int shift) { m_Left += shift; }inline void CRect::MoveRight(int shift) { m_Right += shift; }inline void CRect::MoveBottom(int shift) { m_Bottom += shift; }inline void CRect::MoveTop(int shift) { m_Top += shift; }inline bool CRect::operator==(const CRect& rc) const{ return m_Left == rc.m_Left && m_Right == rc.m_Right && m_Bottom == rc.m_Bottom && m_Top == rc.m_Top;}inline bool CRect::operator!=(const CRect& rc) const{ return ! (*this == rc);}inline bool CRect::IsEmpty() const{ return (m_Left == m_Right) || (m_Bottom == m_Top);}inline bool CRect::PtInRect(int X, int Y) const{ return (X >= m_Left && X<=m_Right) && (Y >= m_Bottom && Y <= m_Top);}inline bool CRect::PtInRect(const CPoint& pt) const{ return (pt.X() >= m_Left && pt.X() <= m_Right) && (pt.Y() >= m_Bottom && pt.Y() <= m_Top);}inline bool CRect::Intersects(const CRect& R) const{ return ! ( (R.m_Bottom > m_Top) || (R.m_Top < m_Bottom) || (R.m_Left > m_Right) || (R.m_Right < m_Left) );}inline void CRect::Inflate(int d_x, int d_y){ m_Left -= d_x; m_Right += d_x; m_Bottom -= d_y; m_Top += d_y; }inline void CRect::Offset(int d_x, int d_y){ m_Left += d_x; m_Right += d_x; m_Bottom += d_y; m_Top += d_y; }inline CRect& CRect::IntersectWith(const CRect& r){ m_Left = max(m_Left, r.m_Left); m_Right = min(m_Right, r.m_Right); m_Bottom = max(m_Bottom, r.m_Bottom); m_Top = min(m_Top, r.m_Top); // correcting Right and Top if intersection is empty m_Right = max(m_Right, m_Left); m_Top = max(m_Top, m_Bottom); return *this;}inline CRect& CRect::CombineWith(const CRect& r){ m_Left = min(m_Left, r.m_Left); m_Right = max(m_Right, r.m_Right); m_Bottom = min(m_Bottom, r.m_Bottom); m_Top = max(m_Top, r.m_Top); return *this;}END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: rect.hpp,v $ * Revision 1000.0 2004/06/01 19:56:42 gouriano * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4 2004/05/13 17:25:34 yazhuk * Addressed GCC warning * * Revision 1.3 2004/05/11 18:55:14 dicuccio * Added doxygen modules info * * Revision 1.2 2004/05/03 20:02:54 rsmith * took out CRect:: qualifiers inside CRect definition. * * Revision 1.1 2004/04/22 16:53:18 yazhuk * Initial revision: menu_window.hpp * * =========================================================================== */#endif // GUI_WIDGETS_FL___RECT__HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -