The integer type of FPoint and FRect changed from short to int

This commit is contained in:
Markus Gans 2018-11-21 22:15:14 +01:00
parent 1f64843fb6
commit f6df9585f5
8 changed files with 144 additions and 135 deletions

View File

@ -1,5 +1,6 @@
2018-11-21 Markus Gans <guru.mail@muenster.de>
* New type FKey for key inputs
* The integer type of FPoint and FRect changed from short to int
2018-11-18 Markus Gans <guru.mail@muenster.de>
* The FListViewItem class now provides checkable list view items

View File

@ -44,36 +44,36 @@ FPoint& FPoint::operator = (const FPoint& p)
//----------------------------------------------------------------------
FPoint& FPoint::operator += (const FPoint& p)
{
xpos = short(xpos + p.xpos);
ypos = short(ypos + p.ypos);
xpos = xpos + p.xpos;
ypos = ypos + p.ypos;
return *this;
}
//----------------------------------------------------------------------
FPoint& FPoint::operator -= (const FPoint& p)
{
xpos = short(xpos - p.xpos);
ypos = short(ypos - p.ypos);
xpos = xpos - p.xpos;
ypos = ypos - p.ypos;
return *this;
}
//----------------------------------------------------------------------
void FPoint::setX (int x)
{
xpos = short(x);
xpos = x;
}
//----------------------------------------------------------------------
void FPoint::setY (int y)
{
ypos = short(y);
ypos = y;
}
//----------------------------------------------------------------------
void FPoint::setPoint (int x, int y)
{
xpos = short(x);
ypos = short(y);
xpos = x;
ypos = y;
}
//----------------------------------------------------------------------
@ -92,7 +92,7 @@ std::ostream& operator << (std::ostream& outstr, const FPoint& p)
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FPoint& p)
{
short x, y;
int x, y;
instr >> x;
instr >> y;
p.setPoint (x, y);

View File

@ -34,10 +34,10 @@ namespace finalcut
// constructor and destructor
//----------------------------------------------------------------------
FRect::FRect (const FPoint& p1, const FPoint& p2)
: X1(short(p1.getX()))
, Y1(short(p1.getY()))
, X2(short(p2.getX()))
, Y2(short(p2.getY()))
: X1(p1.getX())
, Y1(p1.getY())
, X2(p2.getX())
, Y2(p2.getY())
{ }
//----------------------------------------------------------------------
@ -55,82 +55,82 @@ bool FRect::isNull() const
//----------------------------------------------------------------------
void FRect::setX1 (int n)
{
X1 = short(n);
X1 = n;
}
//----------------------------------------------------------------------
void FRect::setY1 (int n)
{
Y1 = short(n);
Y1 = n;
}
//----------------------------------------------------------------------
void FRect::setX2 (int n)
{
X2 = short(n);
X2 = n;
}
//----------------------------------------------------------------------
void FRect::setY2 (int n)
{
Y2 = short(n);
Y2 = n;
}
//----------------------------------------------------------------------
void FRect::setX (int n)
{
short dX = short(X2 - X1);
X1 = short(n);
X2 = short(X1 + dX);
int dX = X2 - X1;
X1 = n;
X2 = X1 + dX;
}
//----------------------------------------------------------------------
void FRect::setY (int n)
{
short dY = short(Y2 - Y1);
Y1 = short(n);
Y2 = short(Y1 + dY);
int dY = Y2 - Y1;
Y1 = n;
Y2 = Y1 + dY;
}
//----------------------------------------------------------------------
void FRect::setPos (int x, int y)
{
short dX = short(X2 - X1);
short dY = short(Y2 - Y1);
X1 = short(x);
Y1 = short(y);
X2 = short(X1 + dX);
Y2 = short(Y1 + dY);
int dX = X2 - X1;
int dY = Y2 - Y1;
X1 = x;
Y1 = y;
X2 = X1 + dX;
Y2 = Y1 + dY;
}
//----------------------------------------------------------------------
void FRect::setPos (const FPoint& p)
{
short dX = short(X2 - X1);
short dY = short(Y2 - Y1);
X1 = short(p.getX());
Y1 = short(p.getY());
X2 = short(X1 + dX);
Y2 = short(Y1 + dY);
int dX = X2 - X1;
int dY = Y2 - Y1;
X1 = p.getX();
Y1 = p.getY();
X2 = X1 + dX;
Y2 = Y1 + dY;
}
//----------------------------------------------------------------------
void FRect::setWidth (std::size_t w)
{
X2 = short(X1 + short(w) - 1);
X2 = X1 + int(w) - 1;
}
//----------------------------------------------------------------------
void FRect::setHeight (std::size_t h)
{
Y2 = short(Y1 + short(h) - 1);
Y2 = Y1 + int(h) - 1;
}
//----------------------------------------------------------------------
void FRect::setSize (std::size_t w, std::size_t h)
{
X2 = short(X1 + short(w) - 1);
Y2 = short(Y1 + short(h) - 1);
X2 = X1 + int(w) - 1;
Y2 = Y1 + int(h) - 1;
}
//----------------------------------------------------------------------
@ -145,10 +145,10 @@ void FRect::setRect (const FRect& r)
//----------------------------------------------------------------------
void FRect::setRect (int x, int y, std::size_t width, std::size_t height)
{
X1 = short(x);
Y1 = short(y);
X2 = short(x + int(width) - 1);
Y2 = short(y + int(height) - 1);
X1 = x;
Y1 = y;
X2 = x + int(width) - 1;
Y2 = y + int(height) - 1;
}
//----------------------------------------------------------------------
@ -160,28 +160,28 @@ void FRect::setCoordinates (const FPoint& p1, const FPoint& p2)
//----------------------------------------------------------------------
void FRect::setCoordinates (int x1, int y1, int x2, int y2)
{
X1 = short(x1);
Y1 = short(y1);
X2 = short(x2);
Y2 = short(y2);
X1 = x1;
Y1 = y1;
X2 = x2;
Y2 = y2;
}
//----------------------------------------------------------------------
void FRect::move (int dx, int dy)
{
X1 = short(X1 + dx);
Y1 = short(Y1 + dy);
X2 = short(X2 + dx);
Y2 = short(Y2 + dy);
X1 = X1 + dx;
Y1 = Y1 + dy;
X2 = X2 + dx;
Y2 = Y2 + dy;
}
//----------------------------------------------------------------------
void FRect::move (const FPoint& d)
{
X1 = short(X1 + d.getX());
Y1 = short(Y1 + d.getY());
X2 = short(X2 + d.getX());
Y2 = short(Y2 + d.getY());
X1 = X1 + d.getX();
Y1 = Y1 + d.getY();
X2 = X2 + d.getX();
Y2 = Y2 + d.getY();
}
//----------------------------------------------------------------------
@ -239,10 +239,10 @@ FRect FRect::combined (const FRect& r) const
//----------------------------------------------------------------------
FRect& FRect::operator = (const FRect& r)
{
X1 = short(r.getX1());
Y1 = short(r.getY1());
X2 = short(r.getX2());
Y2 = short(r.getY2());
X1 = r.getX1();
Y1 = r.getY1();
X2 = r.getX2();
Y2 = r.getY2();
return *this;
}
@ -295,7 +295,7 @@ std::ostream& operator << (std::ostream& outstr, const FRect& r)
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FRect& r)
{
short x1, y1, x2, y2;
int x1, y1, x2, y2;
instr >> x1;
instr >> y1;
instr >> x2;

View File

@ -333,12 +333,12 @@ void FScrollView::scrollToY (int y)
//----------------------------------------------------------------------
void FScrollView::scrollTo (int x, int y)
{
short& xoffset = viewport_geometry.x1_ref();
short& yoffset = viewport_geometry.y1_ref();
short xoffset_before = xoffset;
short yoffset_before = yoffset;
short xoffset_end = short(getScrollWidth() - getViewportWidth());
short yoffset_end = short(getScrollHeight() - getViewportHeight());
int& xoffset = viewport_geometry.x1_ref();
int& yoffset = viewport_geometry.y1_ref();
int xoffset_before = xoffset;
int yoffset_before = yoffset;
int xoffset_end = int(getScrollWidth() - getViewportWidth());
int yoffset_end = int(getScrollHeight() - getViewportHeight());
std::size_t save_width = viewport_geometry.getWidth();
std::size_t save_height = viewport_geometry.getHeight();
bool changeX = false;
@ -346,11 +346,11 @@ void FScrollView::scrollTo (int x, int y)
x--;
y--;
if ( xoffset == short(x) && yoffset == short(y) )
if ( xoffset == x && yoffset == y )
return;
xoffset = short(x);
yoffset = short(y);
xoffset = x;
yoffset = y;
if ( yoffset < 0 )
yoffset = 0;
@ -374,7 +374,7 @@ void FScrollView::scrollTo (int x, int y)
{
viewport_geometry.setWidth(save_width);
setLeftPadding (1 - xoffset);
setRightPadding (1 - (xoffset_end - xoffset) + short(nf_offset));
setRightPadding (1 - (xoffset_end - xoffset) + int(nf_offset));
if ( update_scrollbar )
{
@ -440,7 +440,7 @@ void FScrollView::draw()
//----------------------------------------------------------------------
void FScrollView::onKeyPress (FKeyEvent* ev)
{
short yoffset_end = short(getScrollHeight() - getViewportHeight());
int yoffset_end = int(getScrollHeight() - getViewportHeight());
switch ( ev->key() )
{
@ -492,7 +492,7 @@ void FScrollView::onKeyPress (FKeyEvent* ev)
//----------------------------------------------------------------------
void FScrollView::onWheel (FWheelEvent* ev)
{
short distance = 4;
int distance = 4;
switch ( ev->getWheel() )
{
@ -694,10 +694,10 @@ void FScrollView::copy2area()
ac = &print_area->text[(ay + y) * a_line_len + ax];
std::memcpy (ac, vc, sizeof(charData) * unsigned(x_end));
if ( short(print_area->changes[ay + y].xmin) > ax )
if ( int(print_area->changes[ay + y].xmin) > ax )
print_area->changes[ay + y].xmin = uInt(ax);
if ( short(print_area->changes[ay + y].xmax) < ax + x_end - 1 )
if ( int(print_area->changes[ay + y].xmax) < ax + x_end - 1 )
print_area->changes[ay + y].xmax = uInt(ax + x_end - 1);
}
@ -892,8 +892,8 @@ void FScrollView::setViewportCursor()
void FScrollView::cb_VBarChange (FWidget*, data_ptr)
{
FScrollbar::sType scrollType = vbar->getScrollType();
short distance = 1;
short wheel_distance = 4;
int distance = 1;
int wheel_distance = 4;
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
@ -911,21 +911,21 @@ void FScrollView::cb_VBarChange (FWidget*, data_ptr)
break;
case FScrollbar::scrollPageBackward:
distance = short(getViewportHeight());
distance = int(getViewportHeight());
// fall through
case FScrollbar::scrollStepBackward:
scrollBy (0, -distance);
break;
case FScrollbar::scrollPageForward:
distance = short(getViewportHeight());
distance = int(getViewportHeight());
// fall through
case FScrollbar::scrollStepForward:
scrollBy (0, distance);
break;
case FScrollbar::scrollJump:
scrollToY (1 + short(vbar->getValue()));
scrollToY (1 + int(vbar->getValue()));
break;
case FScrollbar::scrollWheelUp:
@ -944,8 +944,8 @@ void FScrollView::cb_VBarChange (FWidget*, data_ptr)
void FScrollView::cb_HBarChange (FWidget*, data_ptr)
{
FScrollbar::sType scrollType = hbar->getScrollType();
short distance = 1;
short wheel_distance = 4;
int distance = 1;
int wheel_distance = 4;
if ( scrollType >= FScrollbar::scrollStepBackward
&& scrollType <= FScrollbar::scrollWheelDown )
@ -963,21 +963,21 @@ void FScrollView::cb_HBarChange (FWidget*, data_ptr)
break;
case FScrollbar::scrollPageBackward:
distance = short(getViewportWidth());
distance = int(getViewportWidth());
// fall through
case FScrollbar::scrollStepBackward:
scrollBy (-distance, 0);
break;
case FScrollbar::scrollPageForward:
distance = short(getViewportWidth());
distance = int(getViewportWidth());
// fall through
case FScrollbar::scrollStepForward:
scrollBy (distance, 0);
break;
case FScrollbar::scrollJump:
scrollToX (1 + short(hbar->getValue()));
scrollToX (1 + int(hbar->getValue()));
break;
case FScrollbar::scrollWheelUp:

View File

@ -36,6 +36,7 @@
#endif
#include <iostream>
#include "final/ftypes.h"
namespace finalcut
{
@ -83,13 +84,13 @@ class FPoint
bool isNull() const;
// Point references
short& x_ref();
short& y_ref();
int& x_ref();
int& y_ref();
private:
// Data Members
short xpos;
short ypos;
int xpos;
int ypos;
};
#pragma pack(pop)
@ -109,8 +110,8 @@ inline FPoint::FPoint (const FPoint& p) // copy constructor
//----------------------------------------------------------------------
inline FPoint::FPoint (int x, int y)
: xpos(short(x))
, ypos(short(y))
: xpos(x)
, ypos(y)
{ }
//----------------------------------------------------------------------
@ -146,11 +147,11 @@ inline int FPoint::getY() const
{ return ypos; }
//----------------------------------------------------------------------
inline short& FPoint::x_ref()
inline int& FPoint::x_ref()
{ return xpos; }
//----------------------------------------------------------------------
inline short& FPoint::y_ref()
inline int& FPoint::y_ref()
{ return ypos; }
} // namespace finalcut

View File

@ -107,10 +107,10 @@ class FRect
bool isNull() const;
// Coordinate references
short& x1_ref();
short& y1_ref();
short& x2_ref();
short& y2_ref();
int& x1_ref();
int& y1_ref();
int& x2_ref();
int& y2_ref();
// Methods
void move (int, int);
@ -124,10 +124,10 @@ class FRect
private:
// Data Members
short X1;
short Y1;
short X2;
short Y2;
int X1;
int Y1;
int X2;
int Y2;
};
#pragma pack(pop)
@ -151,10 +151,10 @@ inline FRect::FRect (const FRect& r) // copy constructor
//----------------------------------------------------------------------
inline FRect::FRect (int x, int y, std::size_t width, std::size_t height)
: X1(short(x))
, Y1(short(y))
, X2(short(x + short(width) - 1))
, Y2(short(y + short(height) - 1))
: X1(x)
, Y1(y)
, X2(x + int(width) - 1)
, Y2(y + int(height) - 1)
{ }
//----------------------------------------------------------------------
@ -208,31 +208,31 @@ inline FPoint FRect::getLowerRightPos() const
//----------------------------------------------------------------------
inline std::size_t FRect::getWidth() const
{
short w = X2 - X1 + 1;
int w = X2 - X1 + 1;
return ( w < 0 ) ? 0 : std::size_t(w);
}
//----------------------------------------------------------------------
inline std::size_t FRect::getHeight() const
{
short h = Y2 - Y1 + 1;
int h = Y2 - Y1 + 1;
return ( h < 0 ) ? 0 : std::size_t(h);
}
//----------------------------------------------------------------------
inline short& FRect::x1_ref()
inline int& FRect::x1_ref()
{ return X1; }
//----------------------------------------------------------------------
inline short& FRect::y1_ref()
inline int& FRect::y1_ref()
{ return Y1; }
//----------------------------------------------------------------------
inline short& FRect::x2_ref()
inline int& FRect::x2_ref()
{ return X2; }
//----------------------------------------------------------------------
inline short& FRect::y2_ref()
inline int& FRect::y2_ref()
{ return Y2; }
} // namespace finalcut

View File

@ -20,6 +20,8 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <limits>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
@ -136,10 +138,11 @@ void FPointTest::assignmentTest()
CPPUNIT_ASSERT ( p2.getX() == 40 );
CPPUNIT_ASSERT ( p2.getY() == 12 );
// Value limit exceeded
const finalcut::FPoint p3 (-999999,1000000);
CPPUNIT_ASSERT ( p3.getX() != -999999 );
CPPUNIT_ASSERT ( p3.getY() != 1000000 );
// Value limit
const finalcut::FPoint p3 ( std::numeric_limits<int>::min()
, std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p3.getX() == std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p3.getY() == std::numeric_limits<int>::max() );
}
//----------------------------------------------------------------------
@ -155,13 +158,15 @@ void FPointTest::additionAssignmentTest()
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
// Value limit exceeded
finalcut::FPoint p2 (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() == 18000 );
CPPUNIT_ASSERT ( p2.getY() == -18000 );
p2 += finalcut::FPoint (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() != 36000 );
CPPUNIT_ASSERT ( p2.getY() != -36000 );
// Value limit
finalcut::FPoint p2 ( std::numeric_limits<int>::max()
, std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p2.getX() == std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p2.getY() == std::numeric_limits<int>::min() );
p2 += finalcut::FPoint ( -std::numeric_limits<int>::max()
, -std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p2.getX() == 0 );
CPPUNIT_ASSERT ( p2.getY() == 0 );
}
//----------------------------------------------------------------------
@ -202,13 +207,15 @@ void FPointTest::subtractionAssignmentTest()
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
// Value limit exceeded
finalcut::FPoint p2 (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() == 18000 );
CPPUNIT_ASSERT ( p2.getY() == -18000 );
p2 += finalcut::FPoint (18000,-18000);
CPPUNIT_ASSERT ( p2.getX() != 36000 );
CPPUNIT_ASSERT ( p2.getY() != -36000 );
// Value limit
finalcut::FPoint p2 ( std::numeric_limits<int>::max()
, std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p2.getX() == std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p2.getY() == std::numeric_limits<int>::min() );
p2 -= finalcut::FPoint ( std::numeric_limits<int>::max(),
std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p2.getX() == 0 );
CPPUNIT_ASSERT ( p2.getY() == 0 );
}
//----------------------------------------------------------------------
@ -276,8 +283,8 @@ void FPointTest::referenceTest()
CPPUNIT_ASSERT ( p1.getX() == 2 );
CPPUNIT_ASSERT ( p1.getY() == 2 );
short& x = p1.x_ref();
short& y = p1.y_ref();
int& x = p1.x_ref();
int& y = p1.y_ref();
x += 4;
y += 2;
CPPUNIT_ASSERT ( p1.getX() == 6 );

View File

@ -363,10 +363,10 @@ void FRectTest::referenceTest()
CPPUNIT_ASSERT ( r1.getX2() == 9 );
CPPUNIT_ASSERT ( r1.getY2() == 19 );
short& x1 = r1.x1_ref();
short& y1 = r1.y1_ref();
short& x2 = r1.x2_ref();
short& y2 = r1.y2_ref();
int& x1 = r1.x1_ref();
int& y1 = r1.y1_ref();
int& x2 = r1.x2_ref();
int& y2 = r1.y2_ref();
x1 += 2;
y1 -= 2;
x2 -= 3;