📄 glrect.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: glrect.hpp,v $ * PRODUCTION Revision 1000.3 2004/06/01 19:50:19 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * PRODUCTION * =========================================================================== */#ifndef GUI_OPENGL___GLRECT__HPP#define GUI_OPENGL___GLRECT__HPP/* $Id: glrect.hpp,v 1000.3 2004/06/01 19:50:19 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: * */#include <corelib/ncbistd.hpp>#include <gui/opengl/glpoint.hpp>/** @addtogroup GUI_OPENGL * * @{ */BEGIN_NCBI_SCOPE/// CGlRect reprsents rectangle in the coordinate system with origin located in /// the left bottom corner.template <class T> class CGlRect{public: // Construction CGlRect() : m_Left(0), m_Bottom(0), m_Right(0), m_Top(0) {} CGlRect(T x, T y) : m_Left(x), m_Bottom(y), m_Right(x), m_Top(y) {} CGlRect(T left, T bottom, T right, T top) : m_Left(left), m_Bottom(bottom), m_Right(right), m_Top(top) {} void Init() { m_Left = m_Bottom = m_Right = m_Top = 0; } void Init(T x, T y) { m_Left = m_Right = x; m_Bottom = m_Top = y; } void Init(T left, T bottom, T right, T top) { m_Left = left; m_Bottom = bottom; m_Right = right; m_Top = top; } T Left() const { return m_Left; } T Bottom() const { return m_Bottom; } T Right() const { return m_Right; } T Top() const { return m_Top; } T Width() const { return m_Right - m_Left; } T Height() const { return m_Top - m_Bottom; } CGlPoint<T> CenterPoint() { return CGlPoint<T>( (m_Left + m_Right) / 2, (m_Bottom + m_Top) / 2); } void SetLeft(T left) { m_Left = left; } void SetBottom(T bottom) { m_Bottom = bottom; } void SetRight(T right) { m_Right = right; } void SetTop(T top) { m_Top = top; } void SetHorz(T left, T right) { m_Left = left; m_Right = right; } void SetVert(T bottom, T top) { m_Bottom = bottom; m_Top = top; } void SetSize(T width, T height) { m_Right = m_Left + width; m_Top = m_Bottom + height; } void MoveLeft(T shift) { m_Left += shift; } void MoveRight(T shift) { m_Right += shift; } void MoveBottom(T shift) { m_Bottom += shift; } void MoveTop(T shift) { m_Top += shift; } // tests bool operator==(const CGlRect<T>& rc) const { return m_Left == rc.m_Left && m_Right == rc.m_Right && m_Bottom == rc.m_Bottom && m_Top == rc.m_Top; } bool operator!=(const CGlRect<T>& rc) const { return ! *this == rc; } bool IsEmpty() const { return (m_Left == m_Right) || (m_Bottom == m_Top); } bool PtInRect(T x, T y) const { return (x >= m_Left && x <= m_Right) && (y >= m_Bottom && y <= m_Top); } bool PtInRect(const CGlPoint<T>& pt) const { return (pt.X() >= m_Left && pt.X() <= m_Right) && (pt.Y() >= m_Bottom && pt.Y() <= m_Top); } bool Intersects(const CGlRect& R) const { return ! ((R.m_Bottom > m_Top) || (R.m_Top < m_Bottom) || (R.m_Left > m_Right) || (R.m_Right < m_Left)); } // operations void Inflate(T d_x, T d_y) { m_Left -= d_x; m_Right += d_x; m_Bottom -= d_y; m_Top += d_y; } void Offset(T d_x, T d_y) { m_Left += d_x; m_Right += d_x; m_Bottom += d_y; m_Top += d_y; } CGlRect& IntersectWith(const CGlRect& 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; } CGlRect& CombineWith(const CGlRect& 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; }private: T m_Left; T m_Bottom; T m_Right; T m_Top;};template<> inline int CGlRect<int>::Width() const{ return m_Right - m_Left + 1; }template<> inline int CGlRect<int>::Height() const{ return m_Top - m_Bottom + 1; }template<> inline void CGlRect<int>::SetSize(int Width, int Height){ m_Right = m_Left + Width - 1; m_Top = m_Bottom + Height - 1;}END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: glrect.hpp,v $ * Revision 1000.3 2004/06/01 19:50:19 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6 * * Revision 1.6 2004/05/11 18:54:22 dicuccio * Added doxygne modules info * * Revision 1.5 2004/04/22 16:55:25 yazhuk * Cosmetic fixes * * Revision 1.4 2003/11/17 20:25:59 yazhuk * Added operators == and != * * Revision 1.3 2003/11/03 16:59:20 yazhuk * Added PtInRect(const CGlPoint<>) member function * * Revision 1.2 2003/10/29 22:22:22 yazhuk * Added SetHorz() SetVert() functions, enforced coding policy * * Revision 1.1 2003/10/08 12:53:02 dicuccio * Moved from gui/graph library * * =========================================================================== */#endif // GUI_OPENGL___GLRECT__HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -