Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • util
blitrect.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "blitrect.h"
19
20BlitRect::BlitRect()
21{
22}
23
24BlitRect::BlitRect(const QRect rect)
25{
26 setTopLeft(rect.topLeft());
27 setBottomRight(rect.bottomRight());
28 mInitialized = true;
29}
30
31BlitRect::BlitRect(const QPoint p)
32{
33 extend(p);
34}
35
36void BlitRect::extend(const QPoint p)
37{
38 if (mInitialized == false)
39 {
40 setBottomLeft(p);
41 setTopRight(p);
42 mInitialized = true;
43 }
44 else
45 {
46 if (left() > p.x()) { setLeft(p.x()); }
47 if (right() < p.x()) { setRight(p.x()); }
48 if (top() > p.y()) { setTop(p.y()); }
49 if (bottom() < p.y()) { setBottom(p.y()); }
50 }
51}
52
53void BlitRect::extend(const QRect& rect)
54{
55 // For historical reasons the values returned by the bottom() and
56 // right() functions deviate from the true bottom-right corner of the rectangle:
57 // The right() function returns left() + width() - 1 and the bottom()
58 // function returns top() + height() - 1
59 // In order to counter that, we subtract 1 from width and height
60 extend(rect.topLeft(), QSize(rect.width() - 1, rect.height() - 1));
61}
62
63void BlitRect::extend(const QPoint& p, const QSize& size)
64{
65 if (mInitialized == false)
66 {
67 setTopLeft(p);
68 setBottomRight(p + QPoint(size.width(), size.height()));
69 mInitialized = true;
70 }
71 else
72 {
73 if (left() > p.x()) { setLeft(p.x()); }
74 if (top() > p.y()) { setTop(p.y()); }
75 if (right() - size.width() < p.x()) { setRight(p.x() + size.width()); }
76 if (bottom() - size.height() < p.y()) { setBottom(p.y() + size.height()); }
77 }
78}
QPoint
QPoint::x
int x() const const
QPoint::y
int y() const const
QRect
QRect::bottom
int bottom() const const
QRect::bottomRight
QPoint bottomRight() const const
QRect::height
int height() const const
QRect::left
int left() const const
QRect::right
int right() const const
QRect::setBottom
void setBottom(int y)
QRect::setBottomLeft
void setBottomLeft(const QPoint &position)
QRect::setBottomRight
void setBottomRight(const QPoint &position)
QRect::setLeft
void setLeft(int x)
QRect::setRight
void setRight(int x)
QRect::setTop
void setTop(int y)
QRect::setTopLeft
void setTopLeft(const QPoint &position)
QRect::setTopRight
void setTopRight(const QPoint &position)
QRect::size
QSize size() const const
QRect::top
int top() const const
QRect::topLeft
QPoint topLeft() const const
QRect::width
int width() const const
QSize
QSize::height
int height() const const
QSize::width
int width() const const
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39