New class FSize for storing dimensions

This commit is contained in:
Markus Gans 2019-01-16 16:00:15 +01:00
parent cb090e8aff
commit 4dcc573be7
33 changed files with 883 additions and 240 deletions

View File

@ -1,3 +1,6 @@
2019-01-16 Markus Gans <guru.mail@muenster.de>
* New class FSize for storing dimensions
2019-01-12 Markus Gans <guru.mail@muenster.de>
* Refactoring FFileDialog::fileOpenChooser
* Refactoring FFileDialog::fileSaveChooser

View File

@ -365,7 +365,7 @@ MouseDraw::MouseDraw (finalcut::FWidget* parent)
brush.setPos (1, 12);
finalcut::FPoint no_shadow(0, 0);
finalcut::FSize no_shadow(0, 0);
finalcut::FRect scroll_geometry(0, 0, 1, 1);
createArea (scroll_geometry, no_shadow, canvas);
}
@ -381,7 +381,7 @@ void MouseDraw::setGeometry ( int x, int y
{
int old_w, old_h;
finalcut::FDialog::setGeometry (x, y, w, h, adjust);
finalcut::FPoint no_shadow(0, 0);
finalcut::FSize no_shadow(0, 0);
finalcut::FRect scroll_geometry (0, 0, w - 11, h - 3);
old_w = canvas->width;
old_h = canvas->height;

View File

@ -11,6 +11,7 @@ lib_LTLIBRARIES = libfinal.la
libfinal_la_SOURCES = \
fstring.cpp \
fpoint.cpp \
fsize.cpp \
frect.cpp \
fscrollbar.cpp \
fprogressbar.cpp \
@ -99,6 +100,7 @@ finalcutinclude_HEADERS = \
include/final/ftooltip.h \
include/final/fobject.h \
include/final/fpoint.h \
include/final/fsize.h \
include/final/foptiattr.h \
include/final/foptimove.h \
include/final/ftermbuffer.h \

View File

@ -34,6 +34,7 @@ INCLUDE_HEADERS = \
foptimove.h \
ftermbuffer.h \
fpoint.h \
fsize.h \
fprogressbar.h \
fradiobutton.h \
frect.h \
@ -74,6 +75,7 @@ LIB = libfinal.so
OBJS = \
fstring.o \
fpoint.o \
fsize.o \
frect.o \
fscrollbar.o \
fprogressbar.o \

View File

@ -34,6 +34,7 @@ INCLUDE_HEADERS = \
foptimove.h \
ftermbuffer.h \
fpoint.h \
fsize.h \
fprogressbar.h \
fradiobutton.h \
frect.h \
@ -74,6 +75,7 @@ LIB = libfinal.so
OBJS = \
fstring.o \
fpoint.o \
fsize.o \
frect.o \
fscrollbar.o \
fprogressbar.o \

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2012-2018 Markus Gans *
* Copyright 2012-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -417,46 +417,22 @@ void FButton::init()
detectHotkey();
}
//----------------------------------------------------------------------
uChar FButton::getHotkey()
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i = 0; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
void FButton::setHotkeyAccelerator()
{
uChar hotkey = getHotkey();
FKey hotkey = getHotkey(text);
if ( hotkey )
{
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(hotkey)));
addAccelerator (FKey(std::toupper(hotkey)));
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (getHotkey());
addAccelerator (hotkey);
}
else
delAccelerator();

View File

@ -382,45 +382,22 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
// protected methods of FButtonGroup
//----------------------------------------------------------------------
uChar FButtonGroup::getHotkey()
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i = 0; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
void FButtonGroup::setHotkeyAccelerator()
{
uChar hotkey = getHotkey();
FKey hotkey = getHotkey(text);
if ( hotkey )
{
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(hotkey)));
addAccelerator (FKey(std::toupper(hotkey)));
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (getHotkey());
addAccelerator (hotkey);
}
else
delAccelerator();

View File

@ -197,8 +197,8 @@ void FDialog::setPos (int x, int y, bool)
, old_x = getTermX()
, old_y = getTermY();
const auto& shadow = getShadow();
rsw = shadow.getX(); // right shadow width;
bsh = shadow.getY(); // bottom shadow height
rsw = int(shadow.getWidth()); // right shadow width;
bsh = int(shadow.getHeight()); // bottom shadow height
old_geometry = getTermGeometryWithShadow();
// move to the new position
@ -307,8 +307,8 @@ void FDialog::setSize (std::size_t w, std::size_t h, bool adjust)
, dw = old_width - int(w)
, dh = old_height - int(h);
const auto& shadow = getShadow();
int rsw = shadow.getX(); // right shadow width;
int bsh = shadow.getY(); // bottom shadow height
int rsw = int(shadow.getWidth()); // right shadow width;
int bsh = int(shadow.getHeight()); // bottom shadow height
FWindow::setSize (w, h, adjust);
@ -548,7 +548,7 @@ void FDialog::onMouseUp (FMouseEvent* ev)
int titlebar_x = titlebar_click_pos.getX()
, titlebar_y = titlebar_click_pos.getY();
if ( ! titlebar_click_pos.isNull()
if ( ! titlebar_click_pos.isOrigin()
&& titlebar_x > int(getTermX()) + 3
&& titlebar_x < getTermX() + int(getWidth())
&& titlebar_y == int(getTermY()) )
@ -595,7 +595,7 @@ void FDialog::onMouseMove (FMouseEvent* ev)
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! titlebar_click_pos.isNull() )
if ( ! titlebar_click_pos.isOrigin() )
{
FPoint deltaPos = ms.termPos - titlebar_click_pos;
move (deltaPos);
@ -951,7 +951,7 @@ void FDialog::drawBorder()
, y1 = 2
, y2 = 1 + int(getHeight()) - 1;
if ( (getMoveSizeWidget() == this || ! resize_click_pos.isNull() )
if ( (getMoveSizeWidget() == this || ! resize_click_pos.isOrigin() )
&& ! isZoomed() )
setColor (wc.dialog_resize_fg, getBackgroundColor());
else
@ -1527,7 +1527,7 @@ void FDialog::resizeMouseDown (const mouseStates& ms)
void FDialog::resizeMouseUpMove (const mouseStates& ms, bool mouse_up)
{
// Resize the dialog
if ( isResizeable() && ! resize_click_pos.isNull() )
if ( isResizeable() && ! resize_click_pos.isOrigin() )
{
auto r = getRootWidget();
resize_click_pos = ms.termPos;
@ -1578,7 +1578,7 @@ void FDialog::cancelMouseResize()
{
// Cancel resize by mouse
if ( resize_click_pos.isNull() )
if ( resize_click_pos.isOrigin() )
return;
resize_click_pos.setPoint (0, 0);

View File

@ -345,30 +345,6 @@ void FLabel::init()
}
}
//----------------------------------------------------------------------
uChar FLabel::getHotkey()
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i = 0; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
std::size_t FLabel::getHotkeyPos ( wchar_t src[]
, wchar_t dest[]
@ -397,19 +373,19 @@ std::size_t FLabel::getHotkeyPos ( wchar_t src[]
//----------------------------------------------------------------------
void FLabel::setHotkeyAccelerator()
{
uChar hotkey = getHotkey();
FKey hotkey = getHotkey(text);
if ( hotkey )
{
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(hotkey)));
addAccelerator (FKey(std::toupper(hotkey)));
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (getHotkey());
addAccelerator (hotkey);
}
else
delAccelerator();

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2018 Markus Gans *
* Copyright 2018-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -576,7 +576,7 @@ void FMouseX11::setMoveState (const FPoint& mouse_position, int btn)
{
if ( (btn & button_mask) >= button1_pressed_move
&& (btn & button_mask) <= button3_pressed_move
&& mouse_position != zero_point )
&& ! mouse_position.isOrigin() )
{
b_state.mouse_moved = true;
}
@ -811,7 +811,7 @@ void FMouseSGR::setMoveState (const FPoint& mouse_position, int btn)
{
if ( (btn & button_mask) >= button1_move
&& (btn & button_mask) <= button3_move
&& mouse_position != zero_point )
&& ! mouse_position.isOrigin() )
{
b_state.mouse_moved = true;
}
@ -1078,7 +1078,7 @@ void FMouseUrxvt::setMoveState (const FPoint& mouse_position, int btn)
{
if ( (btn & button_mask) >= button1_pressed_move
&& (btn & button_mask) <= button3_pressed_move
&& mouse_position != zero_point )
&& ! mouse_position.isOrigin() )
{
b_state.mouse_moved = true;
}

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -77,7 +77,7 @@ void FPoint::setPoint (int x, int y)
}
//----------------------------------------------------------------------
bool FPoint::isNull() const
bool FPoint::isOrigin() const
{
return xpos == 0 && ypos == 0;
}

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -32,6 +32,14 @@ namespace finalcut
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FRect::FRect (const FPoint& p, const FSize& s)
: X1(p.getX())
, Y1(p.getY())
, X2(p.getX() + int(s.getWidth()) - 1)
, Y2(p.getY() + int(s.getHeight()) - 1)
{ }
//----------------------------------------------------------------------
FRect::FRect (const FPoint& p1, const FPoint& p2)
: X1(p1.getX())
@ -47,7 +55,7 @@ FRect::~FRect() // destructor
// public methods of FRect
//----------------------------------------------------------------------
bool FRect::isNull() const
bool FRect::isEmpty() const
{
return X2 == X1 - 1 && Y2 == Y1 - 1;
}
@ -133,6 +141,13 @@ void FRect::setSize (std::size_t w, std::size_t h)
Y2 = Y1 + int(h) - 1;
}
//----------------------------------------------------------------------
void FRect::setSize (const FSize& s)
{
X2 = X1 + int(s.getWidth()) - 1;
Y2 = Y1 + int(s.getHeight()) - 1;
}
//----------------------------------------------------------------------
void FRect::setRect (const FRect& r)
{
@ -247,21 +262,21 @@ FRect& FRect::operator = (const FRect& r)
}
//----------------------------------------------------------------------
FRect operator + (const FRect& r, const FPoint& p)
FRect operator + (const FRect& r, const FSize& s)
{
return FRect ( r.X1
, r.Y1
, std::size_t(r.X2 - r.X1 + 1 + p.getX())
, std::size_t(r.Y2 - r.Y1 + 1 + p.getY()) );
, std::size_t(r.X2 - r.X1) + 1 + s.getWidth()
, std::size_t(r.Y2 - r.Y1) + 1 + s.getHeight() );
}
//----------------------------------------------------------------------
FRect operator - (const FRect& r, const FPoint& p)
FRect operator - (const FRect& r, const FSize& s)
{
return FRect ( r.X1
, r.Y1
, std::size_t(r.X2 - r.X1 + 1 - p.getX())
, std::size_t(r.Y2 - r.Y1 + 1 - p.getY()) );
, std::size_t(r.X2 - r.X1 + 1) - s.getWidth()
, std::size_t(r.Y2 - r.Y1 + 1) - s.getHeight() );
}
//----------------------------------------------------------------------

View File

@ -61,7 +61,7 @@ void FScrollView::setScrollWidth (std::size_t width)
if ( viewport )
{
FPoint no_shadow(0, 0);
FSize no_shadow(0, 0);
scroll_geometry.setWidth (width);
resizeArea (scroll_geometry, no_shadow, viewport);
@ -89,7 +89,7 @@ void FScrollView::setScrollHeight (std::size_t height)
if ( viewport )
{
FPoint no_shadow(0, 0);
FSize no_shadow(0, 0);
scroll_geometry.setHeight (height);
resizeArea (scroll_geometry, no_shadow, viewport);
addPreprocessingHandler
@ -122,7 +122,7 @@ void FScrollView::setScrollSize (std::size_t width, std::size_t height)
if ( viewport )
{
FPoint no_shadow(0, 0);
FSize no_shadow(0, 0);
scroll_geometry.setSize (width, height);
resizeArea (scroll_geometry, no_shadow, viewport);
addPreprocessingHandler
@ -722,9 +722,10 @@ void FScrollView::init (FWidget* parent)
assert ( parent != 0 );
assert ( ! parent->isInstanceOf("FScrollView") );
initScrollbar (vbar, fc::vertical, &FScrollView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FScrollView::cb_HBarChange);
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
init_scrollbar();
setGeometry (1, 1, 4, 4);
setMinimumSize (4, 4);
int xoffset_end = int(getScrollWidth() - getViewportWidth());
@ -734,7 +735,7 @@ void FScrollView::init (FWidget* parent)
setLeftPadding (1 - getScrollX());
setBottomPadding (1 - (yoffset_end - getScrollY()));
setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset);
FPoint no_shadow(0, 0);
FSize no_shadow(0, 0);
std::size_t w = getViewportWidth();
std::size_t h = getViewportHeight();
@ -756,12 +757,13 @@ void FScrollView::init (FWidget* parent)
}
//----------------------------------------------------------------------
void FScrollView::init_scrollbar()
void FScrollView::initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
, FScrollViewCallback callback )
{
try
{
vbar = std::make_shared<FScrollbar>(fc::vertical, this);
hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
bar = std::make_shared<FScrollbar>(o, this);
}
catch (const std::bad_alloc& ex)
{
@ -770,26 +772,15 @@ void FScrollView::init_scrollbar()
}
term_area* area = getPrintArea();
vbar->setPrintArea(area);
vbar->setMinimum(0);
vbar->setValue(0);
vbar->hide();
bar->setPrintArea(area);
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
hbar->setPrintArea(area);
hbar->setMinimum(0);
hbar->setValue(0);
hbar->hide();
vbar->addCallback
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, &FScrollView::cb_VBarChange)
);
hbar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, &FScrollView::cb_HBarChange)
F_METHOD_CALLBACK (this, callback)
);
}

110
src/fsize.cpp Normal file
View File

@ -0,0 +1,110 @@
/***********************************************************************
* fsize.cpp - Height and width of a two-dimensional surface *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include "final/fsize.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FSize
//----------------------------------------------------------------------
FSize::~FSize() // destructor
{ }
// public methods of FSize
//----------------------------------------------------------------------
FSize& FSize::operator = (const FSize& s)
{
width = s.width;
height = s.height;
return *this;
}
//----------------------------------------------------------------------
FSize& FSize::operator += (const FSize& s)
{
std::size_t max = std::numeric_limits<std::size_t>::max();
width = ( width < max - s.width) ? width + s.width : max;
height = ( height < max - s.height) ? height + s.height : max;
return *this;
}
//----------------------------------------------------------------------
FSize& FSize::operator -= (const FSize& s)
{
width = ( width >= s.width ) ? width - s.width : 0;
height = ( height >= s.height ) ? height - s.height : 0;
return *this;
}
//----------------------------------------------------------------------
void FSize::setWidth (std::size_t w)
{
width = w;
}
//----------------------------------------------------------------------
void FSize::setHeight (std::size_t h)
{
height = h;
}
//----------------------------------------------------------------------
void FSize::setSize (FSize s)
{
width = s.width;
height = s.height;
}
//----------------------------------------------------------------------
void FSize::setSize (std::size_t w, std::size_t h)
{
width = w;
height = h;
}
//----------------------------------------------------------------------
bool FSize::isEmpty() const
{
return width == 0 && height == 0;
}
//----------------------------------------------------------------------
std::ostream& operator << (std::ostream& outstr, const FSize& s)
{
outstr << s.getWidth() << " " << s.getHeight();
return outstr;
}
//----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FSize& s)
{
std::size_t w, h;
instr >> w;
instr >> h;
s.setSize (w, h);
return instr;
}
} // namespace finalcut

View File

@ -82,7 +82,7 @@ void FToggleButton::setGeometry ( int x, int y
{
// Set the toggle button geometry
std::size_t hotkey_mark = ( getHotkey() ) ? 1 : 0;
std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0;
std::size_t min_width = button_width + text.getLength() - hotkey_mark;
if ( w < min_width )
@ -188,7 +188,7 @@ bool FToggleButton::setChecked (bool enable)
void FToggleButton::setText (const FString& txt)
{
text = txt;
std::size_t hotkey_mark = ( getHotkey() ) ? 1 : 0;
std::size_t hotkey_mark = ( getHotkey(text) ) ? 1 : 0;
setWidth(button_width + text.getLength() - hotkey_mark);
@ -361,46 +361,22 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev)
// protected methods of FToggleButton
//----------------------------------------------------------------------
uChar FToggleButton::getHotkey()
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i = 0; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return uChar(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
void FToggleButton::setHotkeyAccelerator()
{
uChar hotkey = getHotkey();
FKey hotkey = getHotkey(text);
if ( hotkey )
{
if ( std::isalpha(hotkey) || std::isdigit(hotkey) )
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(hotkey)));
addAccelerator (FKey(std::toupper(hotkey)));
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(hotkey)));
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (getHotkey());
addAccelerator (hotkey);
}
else
delAccelerator();

View File

@ -180,7 +180,7 @@ void FVTerm::clearArea (int fillchar)
void FVTerm::createVTerm (const FRect& r)
{
// initialize virtual terminal
const FPoint shadow(0, 0);
const FSize shadow(0, 0);
createArea (r, shadow, vterm);
}
@ -194,7 +194,7 @@ void FVTerm::createVTerm (int width, int height)
//----------------------------------------------------------------------
void FVTerm::resizeVTerm (const FRect& r)
{
const FPoint shadow(0, 0);
const FSize shadow(0, 0);
resizeArea (r, shadow, vterm);
}
@ -594,15 +594,15 @@ FVTerm::term_area* FVTerm::getPrintArea()
//----------------------------------------------------------------------
void FVTerm::createArea ( const FRect& r
, const FPoint& p
, const FSize& s
, term_area*& area )
{
createArea ( r.getX()
, r.getY()
, int(r.getWidth())
, int(r.getHeight())
, p.getX()
, p.getY()
, int(s.getWidth())
, int(s.getHeight())
, area );
}
@ -630,15 +630,15 @@ void FVTerm::createArea ( int offset_left, int offset_top
//----------------------------------------------------------------------
void FVTerm::resizeArea ( const FRect& r
, const FPoint& p
, const FSize& s
, term_area* area )
{
resizeArea ( r.getX()
, r.getY()
, int(r.getWidth())
, int(r.getHeight())
, p.getX()
, p.getY()
, int(s.getWidth())
, int(s.getHeight())
, area );
}
@ -1966,7 +1966,7 @@ void FVTerm::init (bool disable_alt_screen)
createVTerm (term_geometry);
// Create virtual desktop area
FPoint shadow_size(0, 0);
FSize shadow_size(0, 0);
createArea (term_geometry, shadow_size, vdesktop);
vdesktop->visible = true;
active_area = vdesktop;

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2018 Markus Gans *
* Copyright 2015-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -767,15 +767,15 @@ bool FWindow::activatePrevWindow()
}
//----------------------------------------------------------------------
void FWindow::setShadowSize (int right, int bottom)
void FWindow::setShadowSize (std::size_t right, std::size_t bottom)
{
int old_right = getShadow().getX()
, old_bottom = getShadow().getY();
std::size_t old_right = getShadow().getWidth();
std::size_t old_bottom = getShadow().getHeight();
FWidget::setShadowSize (right, bottom);
int new_right = getShadow().getX()
, new_bottom = getShadow().getY();
std::size_t new_right = getShadow().getWidth();
std::size_t new_bottom = getShadow().getHeight();
if ( isVirtualWindow()
&& (new_right != old_right || new_bottom != old_bottom) )

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2012-2018 Markus Gans *
* Copyright 2012-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -144,7 +144,6 @@ class FButton : public FWidget
// Methods
void init();
uChar getHotkey();
void setHotkeyAccelerator();
void detectHotkey();
std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t);

View File

@ -117,9 +117,6 @@ class FButtonGroup : public FScrollView
virtual void onFocusIn (FFocusEvent*) override;
protected:
// Accessor
uChar getHotkey();
// Mutator
void setHotkeyAccelerator();

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -143,7 +143,6 @@ class FLabel : public FWidget
// Methods
void init();
uChar getHotkey();
std::size_t getHotkeyPos (wchar_t[], wchar_t[], std::size_t);
void setHotkeyAccelerator();
std::size_t getAlignOffset (std::size_t);

View File

@ -177,7 +177,6 @@ class FMouse
uInt16 max_width{80};
uInt16 max_height{25};
struct timeval time_mousepressed{};
FPoint zero_point{0, 0}; // zero point (x=0, y=0)
FPoint mouse{0, 0}; // mouse click position
FPoint new_mouse_position{};
};

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -81,7 +81,7 @@ class FPoint
void setPoint (int, int);
// Inquiry
bool isNull() const;
bool isOrigin() const;
// Point references
int& x_ref();

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -24,8 +24,12 @@
*
*
* 1 *
* FRect - - - - FPoint
*
* FRect -- - - FPoint
* :
* :
* : 1
* - - - FSize
*
*/
#ifndef FRECT_H
@ -37,6 +41,7 @@
#include <algorithm>
#include "final/fpoint.h"
#include "final/fsize.h"
namespace finalcut
{
@ -55,6 +60,7 @@ class FRect
FRect () = default;
FRect (const FRect&); // copy constructor
FRect (int, int, std::size_t, std::size_t);
FRect (const FPoint&, const FSize&);
FRect (const FPoint&, const FPoint&);
// Destructor
@ -63,8 +69,8 @@ class FRect
// Overloaded operators
FRect& operator = (const FRect&);
friend FRect operator + (const FRect&, const FPoint&);
friend FRect operator - (const FRect&, const FPoint&);
friend FRect operator + (const FRect&, const FSize&);
friend FRect operator - (const FRect&, const FSize&);
friend bool operator == (const FRect&, const FRect&);
friend bool operator != (const FRect&, const FRect&);
friend std::ostream& operator << (std::ostream&, const FRect&);
@ -85,6 +91,7 @@ class FRect
FPoint getLowerRightPos() const;
std::size_t getWidth() const;
std::size_t getHeight() const;
FSize getSize() const;
// Mutators
void setX1 (int);
@ -98,13 +105,14 @@ class FRect
void setWidth (std::size_t);
void setHeight (std::size_t);
void setSize (std::size_t, std::size_t);
void setSize (const FSize&);
void setRect (const FRect&);
void setRect (int, int, std::size_t, std::size_t);
void setCoordinates (const FPoint&, const FPoint&);
void setCoordinates (int, int, int, int);
// Inquiry
bool isNull() const;
bool isEmpty() const;
// Coordinate references
int& x1_ref();
@ -211,6 +219,10 @@ inline std::size_t FRect::getHeight() const
return ( h < 0 ) ? 0 : std::size_t(h);
}
//----------------------------------------------------------------------
inline FSize FRect::getSize() const
{ return FSize(getWidth(), getHeight()); }
//----------------------------------------------------------------------
inline int& FRect::x1_ref()
{ return X1; }

View File

@ -156,6 +156,7 @@ class FScrollView : public FWidget
private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
typedef void (FScrollView::*FScrollViewCallback)(FWidget*, FDataPtr);
// Constants
static constexpr int vertical_border_spacing = 2;
@ -166,7 +167,9 @@ class FScrollView : public FWidget
// Methods
void init (FWidget*);
void init_scrollbar();
void initScrollbar ( FScrollbarPtr&
, fc::orientation
, FScrollViewCallback );
void calculateScrollbarPos();
void setHorizontalScrollBarVisibility();
void setVerticalScrollBarVisibility();

184
src/include/final/fsize.h Normal file
View File

@ -0,0 +1,184 @@
/***********************************************************************
* fsize.h - Height and width of a two-dimensional surface *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
/* Standalone class
*
*
*
* FSize
*
*/
#ifndef FSIZE_H
#define FSIZE_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include <iostream>
#include "final/ftypes.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FSize
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FSize
{
public:
// Constructors
FSize () = default;
FSize (const FSize&); // copy constructor
FSize (std::size_t, std::size_t);
// Destructor
virtual ~FSize();
// Overloaded operators
FSize& operator = (const FSize&);
FSize& operator += (const FSize&);
FSize& operator -= (const FSize&);
friend bool operator < (const FSize&, const FSize&);
friend bool operator <= (const FSize&, const FSize&);
friend bool operator == (const FSize&, const FSize&);
friend bool operator != (const FSize&, const FSize&);
friend bool operator >= (const FSize&, const FSize&);
friend bool operator > (const FSize&, const FSize&);
friend FSize operator + (const FSize&, const FSize&);
friend FSize operator - (const FSize&, const FSize&);
friend std::ostream& operator << (std::ostream&, const FSize&);
friend std::istream& operator >> (std::istream&, FSize&);
// Accessors
virtual const char* getClassName();
std::size_t getWidth() const;
std::size_t getHeight() const;
std::size_t getArea() const;
void setWidth (std::size_t);
void setHeight (std::size_t);
void setSize (FSize);
void setSize (std::size_t, std::size_t);
// Inquiry
bool isEmpty() const;
// Side references
std::size_t& width_ref();
std::size_t& height_ref();
private:
// Data Members
std::size_t width{0};
std::size_t height{0};
};
#pragma pack(pop)
// FSize inline functions
//----------------------------------------------------------------------
inline FSize::FSize (const FSize& s) // copy constructor
: width(s.width)
, height(s.height)
{ }
//----------------------------------------------------------------------
inline FSize::FSize (std::size_t w, std::size_t h)
: width(w)
, height(h)
{ }
//----------------------------------------------------------------------
inline bool operator < (const FSize& s1, const FSize& s2)
{ return s1.width < s2.width && s1.height < s2.height; }
//----------------------------------------------------------------------
inline bool operator <= (const FSize& s1, const FSize& s2)
{ return s1.width <= s2.width && s1.height <= s2.height; }
//----------------------------------------------------------------------
inline bool operator == (const FSize& s1, const FSize& s2)
{ return s1.width == s2.width && s1.height == s2.height; }
//----------------------------------------------------------------------
inline bool operator != (const FSize& s1, const FSize& s2)
{ return s1.width != s2.width || s1.height != s2.height; }
//----------------------------------------------------------------------
inline bool operator >= (const FSize& s1, const FSize& s2)
{ return s1.width >= s2.width && s1.height >= s2.height; }
//----------------------------------------------------------------------
inline bool operator > (const FSize& s1, const FSize& s2)
{ return s1.width > s2.width && s1.height > s2.height; }
//----------------------------------------------------------------------
inline FSize operator + (const FSize& s1, const FSize& s2)
{
std::size_t max = std::numeric_limits<std::size_t>::max();
std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max;
std::size_t h = ( s1.height < max - s2.height) ? s1.height + s2.height : max;
return FSize(w, h);
}
//----------------------------------------------------------------------
inline FSize operator - (const FSize& s1, const FSize& s2)
{
std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0;
std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0;
return FSize(w, h);
}
//----------------------------------------------------------------------
inline const char* FSize::getClassName()
{ return "FSize"; }
//----------------------------------------------------------------------
inline std::size_t FSize::getWidth() const
{ return width; }
//----------------------------------------------------------------------
inline std::size_t FSize::getHeight() const
{ return height; }
//----------------------------------------------------------------------
inline std::size_t FSize::getArea() const
{ return width * height; }
//----------------------------------------------------------------------
inline std::size_t& FSize::width_ref()
{ return width; }
//----------------------------------------------------------------------
inline std::size_t& FSize::height_ref()
{ return height; }
} // namespace finalcut
#endif // FSIZE_H

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2014-2018 Markus Gans *
* Copyright 2014-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -125,7 +125,6 @@ class FToggleButton : public FWidget
protected:
// Accessor
uChar getHotkey();
FButtonGroup* getGroup() const;
// Mutator

View File

@ -338,7 +338,7 @@ class FVTerm
// Methods
void createArea ( const FRect&
, const FPoint&
, const FSize&
, term_area*& );
void createArea ( int, int, int, int
@ -346,7 +346,7 @@ class FVTerm
, term_area*& );
void resizeArea ( const FRect&
, const FPoint&
, const FSize&
, term_area* );
void resizeArea ( int, int, int, int

View File

@ -210,7 +210,7 @@ class FWidget : public FVTerm, public FObject
std::size_t getClientHeight() const;
std::size_t getMaxWidth() const;
std::size_t getMaxHeight() const;
const FPoint& getShadow() const;
const FSize& getShadow() const;
const FRect& getGeometry() const;
const FRect& getGeometryWithShadow();
const FRect& getTermGeometry();
@ -257,6 +257,7 @@ class FWidget : public FVTerm, public FObject
virtual void setPos (int, int, bool = true);
virtual void setWidth (std::size_t, bool = true);
virtual void setHeight (std::size_t, bool = true);
virtual void setSize (FSize, bool = true);
virtual void setSize (std::size_t, std::size_t, bool = true);
void setTopPadding (int, bool = true);
void setLeftPadding (int, bool = true);
@ -267,10 +268,11 @@ class FWidget : public FVTerm, public FObject
void setTermOffsetWithPadding();
void setTermSize (std::size_t, std::size_t);
virtual void setGeometry (const FRect&, bool = true);
virtual void setGeometry (const FPoint&, const FSize&, bool = true);
virtual void setGeometry ( int, int
, std::size_t, std::size_t
, bool = true );
virtual void setShadowSize (int, int);
virtual void setShadowSize (std::size_t, std::size_t);
void setMinimumWidth (std::size_t);
void setMinimumHeight (std::size_t);
void setMinimumSize (std::size_t, std::size_t);
@ -493,7 +495,7 @@ class FWidget : public FVTerm, public FObject
// offset of the widget client area
FRect client_offset{};
// widget shadow size (on the right and bottom side)
FPoint wshadow{0, 0};
FSize wshadow{0, 0};
// default widget foreground and background color
FColor foreground_color{fc::Default};
@ -634,7 +636,7 @@ inline std::size_t FWidget::getMaxHeight() const
{ return offset.getHeight(); }
//----------------------------------------------------------------------
inline const FPoint& FWidget::getShadow() const
inline const FSize& FWidget::getShadow() const
{ return wshadow; }
//----------------------------------------------------------------------
@ -648,8 +650,8 @@ inline const FRect& FWidget::getGeometryWithShadow()
(
adjust_wsize.x1_ref(),
adjust_wsize.y1_ref(),
adjust_wsize.x2_ref() + wshadow.x_ref(),
adjust_wsize.y2_ref() + wshadow.y_ref()
adjust_wsize.x2_ref() + int(wshadow.width_ref()),
adjust_wsize.y2_ref() + int(wshadow.height_ref())
);
return adjust_wsize_shadow;
@ -676,8 +678,8 @@ inline const FRect& FWidget::getTermGeometryWithShadow()
(
adjust_wsize.x1_ref() + offset.x1_ref(),
adjust_wsize.y1_ref() + offset.y1_ref(),
adjust_wsize.x2_ref() + offset.x1_ref() + wshadow.x_ref(),
adjust_wsize.y2_ref() + offset.y1_ref() + wshadow.y_ref()
adjust_wsize.x2_ref() + offset.x1_ref() + int(wshadow.width_ref()),
adjust_wsize.y2_ref() + offset.y1_ref() + int(wshadow.height_ref())
);
return adjust_wsize_term_shadow;
@ -806,6 +808,10 @@ inline void FWidget::setBackgroundColor (FColor color)
inline void FWidget::setPos (const FPoint& p, bool adjust)
{ setPos (p.getX(), p.getY(), adjust); }
//----------------------------------------------------------------------
inline void FWidget::setSize (FSize s, bool adjust)
{ setSize(s.getWidth(), s.getHeight(), adjust); }
//----------------------------------------------------------------------
inline void FWidget::setGeometry (const FRect& box, bool adjust)
{
@ -817,8 +823,18 @@ inline void FWidget::setGeometry (const FRect& box, bool adjust)
}
//----------------------------------------------------------------------
inline void FWidget::setShadowSize (int right, int bottom)
{ wshadow.setPoint (right, bottom); }
inline void FWidget::setGeometry (const FPoint& p, const FSize& s, bool adjust)
{
setGeometry ( p.getX()
, p.getY()
, s.getWidth()
, s.getHeight()
, adjust );
}
//----------------------------------------------------------------------
inline void FWidget::setShadowSize (std::size_t right, std::size_t bottom)
{ wshadow.setSize (right, bottom); }
//----------------------------------------------------------------------
inline void FWidget::setMinimumWidth (std::size_t min_width)
@ -1044,6 +1060,29 @@ inline void destroyBlankArray (char blank[])
delete[] blank;
}
//----------------------------------------------------------------------
inline FKey getHotkey (const FString& text)
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i = 0; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return FKey(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
} // namespace finalcut
#endif // FWIDGET_H

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2018 Markus Gans *
* Copyright 2015-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -157,7 +157,7 @@ class FWindow : public FWidget
bool zoomWindow ();
static void switchToPrevWindow (FWidget*);
static bool activatePrevWindow();
virtual void setShadowSize (int, int) override;
virtual void setShadowSize (std::size_t, std::size_t) override;
protected:
// Method

View File

@ -16,6 +16,7 @@ noinst_PROGRAMS = \
foptimove_test \
foptiattr_test \
fstring_test \
fsize_test \
fpoint_test \
frect_test
@ -28,6 +29,7 @@ ftermcapquirks_test_SOURCES = ftermcapquirks-test.cpp
foptimove_test_SOURCES = foptimove-test.cpp
foptiattr_test_SOURCES = foptiattr-test.cpp
fstring_test_SOURCES = fstring-test.cpp
fsize_test_SOURCES = fsize-test.cpp
fpoint_test_SOURCES = fpoint-test.cpp
frect_test_SOURCES = frect-test.cpp
@ -40,6 +42,7 @@ TESTS = fobject_test \
foptimove_test \
foptiattr_test \
fstring_test \
fsize_test \
fpoint_test \
frect_test

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2018 Markus Gans *
* Copyright 2018-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -98,7 +98,7 @@ void FPointTest::noArgumentTest()
const finalcut::FPoint point{};
CPPUNIT_ASSERT ( point.getX() == 0 );
CPPUNIT_ASSERT ( point.getY() == 0 );
CPPUNIT_ASSERT ( point.isNull() );
CPPUNIT_ASSERT ( point.isOrigin() );
}
//----------------------------------------------------------------------
@ -156,7 +156,7 @@ void FPointTest::additionAssignmentTest()
p1 += finalcut::FPoint (-4,-3);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
CPPUNIT_ASSERT ( p1.isOrigin() );
// Value limit
finalcut::FPoint p2 ( std::numeric_limits<int>::max()
@ -164,9 +164,9 @@ void FPointTest::additionAssignmentTest()
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() );
, std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p2.getX() == 0 );
CPPUNIT_ASSERT ( p2.getY() == 0 );
CPPUNIT_ASSERT ( p2.getY() == std::numeric_limits<int>::min() + std::numeric_limits<int>::max() );
}
//----------------------------------------------------------------------
@ -180,32 +180,32 @@ void FPointTest::subtractionAssignmentTest()
p1 -= finalcut::FPoint (-5,20);
CPPUNIT_ASSERT ( p1.getX() == 10 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
CPPUNIT_ASSERT ( ! p1.isOrigin() );
p1 -= finalcut::FPoint (-10,0);
CPPUNIT_ASSERT ( p1.getX() == 20 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
CPPUNIT_ASSERT ( ! p1.isOrigin() );
p1 -= finalcut::FPoint (20,0);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == -5 );
CPPUNIT_ASSERT ( ! p1.isNull() );
CPPUNIT_ASSERT ( ! p1.isOrigin() );
p1 -= finalcut::FPoint (0,-6);
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 1 );
CPPUNIT_ASSERT ( ! p1.isNull() );
CPPUNIT_ASSERT ( ! p1.isOrigin() );
p1 -= finalcut::FPoint (1,0);
CPPUNIT_ASSERT ( p1.getX() == -1 );
CPPUNIT_ASSERT ( p1.getY() == 1 );
CPPUNIT_ASSERT ( ! p1.isNull() );
CPPUNIT_ASSERT ( ! p1.isOrigin() );
p1 -= (finalcut::FPoint (0,1) + finalcut::FPoint (-1,0));
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p1.isNull() );
CPPUNIT_ASSERT ( p1.isOrigin() );
// Value limit
finalcut::FPoint p2 ( std::numeric_limits<int>::max()

View File

@ -3,7 +3,7 @@
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2018 Markus Gans *
* Copyright 2018-2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
@ -104,7 +104,7 @@ void FRectTest::noArgumentTest()
CPPUNIT_ASSERT ( rectangle.getY1() == 0 );
CPPUNIT_ASSERT ( rectangle.getX2() == -1 );
CPPUNIT_ASSERT ( rectangle.getY2() == -1 );
CPPUNIT_ASSERT ( rectangle.isNull() );
CPPUNIT_ASSERT ( rectangle.isEmpty() );
CPPUNIT_ASSERT ( rectangle.getWidth() == 0 );
CPPUNIT_ASSERT ( rectangle.getHeight() == 0 );
CPPUNIT_ASSERT ( rectangle.getPos() == finalcut::FPoint(0, 0) );
@ -121,7 +121,7 @@ void FRectTest::copyConstructorTest()
const finalcut::FRect r2 (r1);
CPPUNIT_ASSERT ( r2.getX() == 1 );
CPPUNIT_ASSERT ( r2.getY() == 1 );
CPPUNIT_ASSERT ( ! r2.isNull() );
CPPUNIT_ASSERT ( ! r2.isEmpty() );
CPPUNIT_ASSERT ( r2.getWidth() == 20 );
CPPUNIT_ASSERT ( r2.getHeight() == 10 );
}
@ -136,6 +136,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r1.getY2() == 18 );
CPPUNIT_ASSERT ( r1.getWidth() == 45 );
CPPUNIT_ASSERT ( r1.getHeight() == 14 );
CPPUNIT_ASSERT ( r1.getSize() == finalcut::FSize(45, 14) );
finalcut::FRect r2 (r1);
CPPUNIT_ASSERT ( r2 == r1 );
@ -145,6 +146,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r2.getY2() == 18 );
CPPUNIT_ASSERT ( r2.getWidth() == 45 );
CPPUNIT_ASSERT ( r2.getHeight() == 14 );
CPPUNIT_ASSERT ( r2.getSize() == finalcut::FSize(45, 14) );
finalcut::FRect r3(3, 3, 10, 10);
r3 = r2;
@ -155,6 +157,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 18 );
CPPUNIT_ASSERT ( r3.getWidth() == 45 );
CPPUNIT_ASSERT ( r3.getHeight() == 14 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(45, 14) );
r3.setPos(finalcut::FPoint(1, 1));
CPPUNIT_ASSERT ( r3 != r2 );
@ -164,6 +167,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 14 );
CPPUNIT_ASSERT ( r3.getWidth() == 45 );
CPPUNIT_ASSERT ( r3.getHeight() == 14 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(45, 14) );
r3.setPos(-5, -5);
CPPUNIT_ASSERT ( r3 != r2 );
@ -173,6 +177,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 8 );
CPPUNIT_ASSERT ( r3.getWidth() == 45 );
CPPUNIT_ASSERT ( r3.getHeight() == 14 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(45, 14) );
r3.setRect(-3, -3, 6, 6);
CPPUNIT_ASSERT ( r3.getX1() == -3 );
@ -181,6 +186,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 2 );
CPPUNIT_ASSERT ( r3.getWidth() == 6 );
CPPUNIT_ASSERT ( r3.getHeight() == 6 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(6, 6) );
r3.setRect(r1);
CPPUNIT_ASSERT ( r3 == r1 );
@ -190,6 +196,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 18 );
CPPUNIT_ASSERT ( r3.getWidth() == 45 );
CPPUNIT_ASSERT ( r3.getHeight() == 14 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(45, 14) );
r3.setX1(1);
CPPUNIT_ASSERT ( r3 != r1 );
@ -199,6 +206,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 18 );
CPPUNIT_ASSERT ( r3.getWidth() == 47 );
CPPUNIT_ASSERT ( r3.getHeight() == 14 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(47, 14) );
r3.setY1(1);
CPPUNIT_ASSERT ( r3.getX1() == 1 );
@ -207,6 +215,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 18 );
CPPUNIT_ASSERT ( r3.getWidth() == 47 );
CPPUNIT_ASSERT ( r3.getHeight() == 18 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(47, 18) );
r3.setX2(10);
CPPUNIT_ASSERT ( r3.getX1() == 1 );
@ -215,6 +224,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 18 );
CPPUNIT_ASSERT ( r3.getWidth() == 10 );
CPPUNIT_ASSERT ( r3.getHeight() == 18 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(10, 18) );
r3.setY2(10);
CPPUNIT_ASSERT ( r3.getX1() == 1 );
@ -223,6 +233,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 10 );
CPPUNIT_ASSERT ( r3.getWidth() == 10 );
CPPUNIT_ASSERT ( r3.getHeight() == 10 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(10, 10) );
r3.setX(2);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
@ -231,6 +242,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 10 );
CPPUNIT_ASSERT ( r3.getWidth() == 10 );
CPPUNIT_ASSERT ( r3.getHeight() == 10 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(10, 10) );
r3.setY(2);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
@ -239,6 +251,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 11 );
CPPUNIT_ASSERT ( r3.getWidth() == 10 );
CPPUNIT_ASSERT ( r3.getHeight() == 10 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(10, 10) );
r3.setWidth(8);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
@ -247,6 +260,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 11 );
CPPUNIT_ASSERT ( r3.getWidth() == 8 );
CPPUNIT_ASSERT ( r3.getHeight() == 10 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(8, 10) );
r3.setHeight(8);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
@ -255,6 +269,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 9 );
CPPUNIT_ASSERT ( r3.getWidth() == 8 );
CPPUNIT_ASSERT ( r3.getHeight() == 8 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(8, 8) );
r3.setSize(5, 5);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
@ -263,6 +278,17 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 6 );
CPPUNIT_ASSERT ( r3.getWidth() == 5 );
CPPUNIT_ASSERT ( r3.getHeight() == 5 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(5, 5) );
const finalcut::FSize s(6, 6);
r3.setSize(s);
CPPUNIT_ASSERT ( r3.getX1() == 2 );
CPPUNIT_ASSERT ( r3.getY1() == 2 );
CPPUNIT_ASSERT ( r3.getX2() == 7 );
CPPUNIT_ASSERT ( r3.getY2() == 7 );
CPPUNIT_ASSERT ( r3.getWidth() == 6 );
CPPUNIT_ASSERT ( r3.getHeight() == 6 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(6, 6) );
const finalcut::FPoint p1(3, 3);
const finalcut::FPoint p2(30, 10);
@ -273,6 +299,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 10 );
CPPUNIT_ASSERT ( r3.getWidth() == 28 );
CPPUNIT_ASSERT ( r3.getHeight() == 8 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(28, 8) );
r3.setCoordinates (10, 12, 40, 50);
CPPUNIT_ASSERT ( r3.getX1() == 10 );
@ -281,6 +308,7 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r3.getY2() == 50 );
CPPUNIT_ASSERT ( r3.getWidth() == 31 );
CPPUNIT_ASSERT ( r3.getHeight() == 39 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(31, 39) );
finalcut::FRect r4(p1, p2);
CPPUNIT_ASSERT ( r4.getX1() == 3 );
@ -289,6 +317,16 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r4.getY2() == 10 );
CPPUNIT_ASSERT ( r4.getWidth() == 28 );
CPPUNIT_ASSERT ( r4.getHeight() == 8 );
CPPUNIT_ASSERT ( r4.getSize() == finalcut::FSize(28, 8) );
finalcut::FRect r5(finalcut::FPoint(2, 9), finalcut::FSize(10, 10));
CPPUNIT_ASSERT ( r5.getX1() == 2 );
CPPUNIT_ASSERT ( r5.getY1() == 9 );
CPPUNIT_ASSERT ( r5.getX2() == 11 );
CPPUNIT_ASSERT ( r5.getY2() == 18 );
CPPUNIT_ASSERT ( r5.getWidth() == 10 );
CPPUNIT_ASSERT ( r5.getHeight() == 10 );
CPPUNIT_ASSERT ( r5.getSize() == finalcut::FSize(10, 10) );
}
//----------------------------------------------------------------------
@ -320,28 +358,30 @@ void FRectTest::notEqualTest()
void FRectTest::additionTest()
{
const finalcut::FRect r1 (1, 2, 10, 10);
const finalcut::FPoint p (3, 5);
const finalcut::FRect r2 = r1 + p;
const finalcut::FSize s (3, 5);
const finalcut::FRect r2 = r1 + s;
CPPUNIT_ASSERT ( r2.getX1() == 1 );
CPPUNIT_ASSERT ( r2.getY1() == 2 );
CPPUNIT_ASSERT ( r2.getX2() == 13 );
CPPUNIT_ASSERT ( r2.getY2() == 16 );
CPPUNIT_ASSERT ( r2.getWidth() == 13 );
CPPUNIT_ASSERT ( r2.getHeight() == 15 );
CPPUNIT_ASSERT ( r2.getSize() == finalcut::FSize(13, 15) );
}
//----------------------------------------------------------------------
void FRectTest::subtractionTest()
{
const finalcut::FRect r1 (2, 2, 12, 12);
const finalcut::FPoint p (5, 5);
const finalcut::FRect r2 = r1 - p;
const finalcut::FSize s (5, 5);
const finalcut::FRect r2 = r1 - s;
CPPUNIT_ASSERT ( r2.getX1() == 2 );
CPPUNIT_ASSERT ( r2.getY1() == 2 );
CPPUNIT_ASSERT ( r2.getX2() == 8 );
CPPUNIT_ASSERT ( r2.getY2() == 8 );
CPPUNIT_ASSERT ( r2.getWidth() == 7 );
CPPUNIT_ASSERT ( r2.getHeight() == 7 );
CPPUNIT_ASSERT ( r2.getSize() == finalcut::FSize(7, 7) );
}
//----------------------------------------------------------------------
@ -385,6 +425,7 @@ void FRectTest::moveTest()
CPPUNIT_ASSERT ( r1.getY() == 2 );
CPPUNIT_ASSERT ( r1.getWidth() == 10 );
CPPUNIT_ASSERT ( r1.getHeight() == 20 );
CPPUNIT_ASSERT ( r1.getSize() == finalcut::FSize(10, 20) );
CPPUNIT_ASSERT ( r1.getX2() == 10 );
CPPUNIT_ASSERT ( r1.getY2() == 21 );
@ -394,6 +435,7 @@ void FRectTest::moveTest()
CPPUNIT_ASSERT ( r1.getY() == 5 );
CPPUNIT_ASSERT ( r1.getWidth() == 10 );
CPPUNIT_ASSERT ( r1.getHeight() == 20 );
CPPUNIT_ASSERT ( r1.getSize() == finalcut::FSize(10, 20) );
CPPUNIT_ASSERT ( r1.getX2() == 12 );
CPPUNIT_ASSERT ( r1.getY2() == 24 );
@ -402,6 +444,7 @@ void FRectTest::moveTest()
CPPUNIT_ASSERT ( r1.getY() == 0 );
CPPUNIT_ASSERT ( r1.getWidth() == 10 );
CPPUNIT_ASSERT ( r1.getHeight() == 20 );
CPPUNIT_ASSERT ( r1.getSize() == finalcut::FSize(10, 20) );
CPPUNIT_ASSERT ( r1.getX2() == 7 );
CPPUNIT_ASSERT ( r1.getY2() == 19 );
}
@ -450,6 +493,7 @@ void FRectTest::intersectTest()
CPPUNIT_ASSERT ( r3.getY() == 2 );
CPPUNIT_ASSERT ( r3.getWidth() == 5 );
CPPUNIT_ASSERT ( r3.getHeight() == 5 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(5, 5) );
CPPUNIT_ASSERT ( r3.getX2() == 5 );
CPPUNIT_ASSERT ( r3.getY2() == 6 );
@ -459,6 +503,7 @@ void FRectTest::intersectTest()
CPPUNIT_ASSERT ( r3.getY() == 2 );
CPPUNIT_ASSERT ( r3.getWidth() == 2 );
CPPUNIT_ASSERT ( r3.getHeight() == 5 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(2, 5) );
CPPUNIT_ASSERT ( r3.getX2() == 5 );
CPPUNIT_ASSERT ( r3.getY2() == 6 );
}
@ -473,6 +518,7 @@ void FRectTest::combinedTest()
CPPUNIT_ASSERT ( r3.getY() == 2 );
CPPUNIT_ASSERT ( r3.getWidth() == 5 );
CPPUNIT_ASSERT ( r3.getHeight() == 5 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(5, 5) );
CPPUNIT_ASSERT ( r3.getX2() == 5 );
CPPUNIT_ASSERT ( r3.getY2() == 6 );
@ -482,6 +528,7 @@ void FRectTest::combinedTest()
CPPUNIT_ASSERT ( r3.getY() == 2 );
CPPUNIT_ASSERT ( r3.getWidth() == 8 );
CPPUNIT_ASSERT ( r3.getHeight() == 6 );
CPPUNIT_ASSERT ( r3.getSize() == finalcut::FSize(8, 6) );
CPPUNIT_ASSERT ( r3.getX2() == 8 );
CPPUNIT_ASSERT ( r3.getY2() == 7 );
}

332
test/fsize-test.cpp Normal file
View File

@ -0,0 +1,332 @@
/***********************************************************************
* fsize-test.cpp - FSize unit tests *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <limits>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include <final/final.h>
//----------------------------------------------------------------------
// class FSizeTest
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FSizeTest : public CPPUNIT_NS::TestFixture
{
public:
FSizeTest()
{ }
protected:
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void assignmentTest();
void additionAssignmentTest();
void subtractionAssignmentTest();
void equalTest();
void notEqualTest();
void additionTest();
void subtractionTest();
void referenceTest();
void streamInsertionTest();
void streamExtractionTest();
private:
// Adds code needed to register the test suite
CPPUNIT_TEST_SUITE (FSizeTest);
// Add a methods to the test suite
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (additionAssignmentTest);
CPPUNIT_TEST (subtractionAssignmentTest);
CPPUNIT_TEST (equalTest);
CPPUNIT_TEST (notEqualTest);
CPPUNIT_TEST (additionTest);
CPPUNIT_TEST (subtractionTest);
CPPUNIT_TEST (referenceTest);
CPPUNIT_TEST (streamInsertionTest);
CPPUNIT_TEST (streamExtractionTest);
// End of test suite definition
CPPUNIT_TEST_SUITE_END();
};
#pragma pack(pop)
//----------------------------------------------------------------------
void FSizeTest::classNameTest()
{
finalcut::FSize p;
const char* const classname = p.getClassName();
CPPUNIT_ASSERT ( std::strcmp(classname, "FSize") == 0 );
}
//----------------------------------------------------------------------
void FSizeTest::noArgumentTest()
{
const finalcut::FSize size{};
CPPUNIT_ASSERT ( size.getWidth() == 0 );
CPPUNIT_ASSERT ( size.getHeight() == 0 );
CPPUNIT_ASSERT ( size.isEmpty() );
}
//----------------------------------------------------------------------
void FSizeTest::copyConstructorTest()
{
const finalcut::FSize s1 (333, 80);
const finalcut::FSize s2 (s1);
CPPUNIT_ASSERT ( s2.getWidth() == 333 );
CPPUNIT_ASSERT ( s2.getHeight() == 80 );
}
//----------------------------------------------------------------------
void FSizeTest::assignmentTest()
{
const finalcut::FSize s1 (0,100);
CPPUNIT_ASSERT ( s1.getWidth() == 0 );
CPPUNIT_ASSERT ( s1.getHeight() == 100 );
finalcut::FSize s2;
s2 = s1;
CPPUNIT_ASSERT ( s2.getWidth() == 0 );
CPPUNIT_ASSERT ( s2.getHeight() == 100 );
s2.setSize (80, 24);
CPPUNIT_ASSERT ( s2.getWidth() == 80 );
CPPUNIT_ASSERT ( s2.getHeight() == 24 );
s2.setWidth(40);
CPPUNIT_ASSERT ( s2.getWidth() == 40 );
CPPUNIT_ASSERT ( s2.getHeight() == 24 );
s2.setHeight(12);
CPPUNIT_ASSERT ( s2.getWidth() == 40 );
CPPUNIT_ASSERT ( s2.getHeight() == 12 );
// Value limit
const finalcut::FSize s3 ( std::numeric_limits<std::size_t>::min()
, std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s3.getWidth() == std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s3.getHeight() == std::numeric_limits<std::size_t>::max() );
}
//----------------------------------------------------------------------
void FSizeTest::additionAssignmentTest()
{
finalcut::FSize s1 (1,2);
s1 += finalcut::FSize{3,1};
CPPUNIT_ASSERT ( s1.getWidth() == 4 );
CPPUNIT_ASSERT ( s1.getHeight() == 3 );
s1 += finalcut::FSize{0, 0};
CPPUNIT_ASSERT ( s1.getWidth() == 4 );
CPPUNIT_ASSERT ( s1.getHeight() == 3 );
s1 += finalcut::FSize{1, 2};
CPPUNIT_ASSERT ( s1.getWidth() == 5 );
CPPUNIT_ASSERT ( s1.getHeight() == 5 );
CPPUNIT_ASSERT ( ! s1.isEmpty() );
// Value limit
finalcut::FSize s2 ( std::numeric_limits<std::size_t>::max()
, std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits<std::size_t>::min() );
s2 += finalcut::FSize{1, 1};
CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s2.getHeight() == 1 );
}
//----------------------------------------------------------------------
void FSizeTest::subtractionAssignmentTest()
{
finalcut::FSize s1 (10, 20);
s1 -= finalcut::FSize (2, 5);
CPPUNIT_ASSERT ( s1.getWidth() == 8 );
CPPUNIT_ASSERT ( s1.getHeight() == 15 );
s1 -= finalcut::FSize (1, 0);
CPPUNIT_ASSERT ( s1.getWidth() == 7 );
CPPUNIT_ASSERT ( s1.getHeight() == 15 );
CPPUNIT_ASSERT ( ! s1.isEmpty() );
s1 -= finalcut::FSize (0, 5);
CPPUNIT_ASSERT ( s1.getWidth() == 7 );
CPPUNIT_ASSERT ( s1.getHeight() == 10 );
CPPUNIT_ASSERT ( ! s1.isEmpty() );
s1 -= finalcut::FSize (2, 222);
CPPUNIT_ASSERT ( s1.getWidth() == 5 );
CPPUNIT_ASSERT ( s1.getHeight() == 0 );
CPPUNIT_ASSERT ( ! s1.isEmpty() );
s1 -= finalcut::FSize (1, 0);
CPPUNIT_ASSERT ( s1.getWidth() == 4 );
CPPUNIT_ASSERT ( s1.getHeight() == 0 );
CPPUNIT_ASSERT ( ! s1.isEmpty() );
s1 -= (finalcut::FSize (3, 0) + finalcut::FSize (1, 0));
CPPUNIT_ASSERT ( s1.getWidth() == 0 );
CPPUNIT_ASSERT ( s1.getHeight() == 0 );
CPPUNIT_ASSERT ( s1.isEmpty() );
// Value limit
finalcut::FSize s2 ( std::numeric_limits<std::size_t>::max()
, std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( ! s2.isEmpty() );
s2 -= finalcut::FSize ( std::numeric_limits<std::size_t>::max(),
std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s2.getWidth() == 0 );
CPPUNIT_ASSERT ( s2.getHeight() == 0 );
CPPUNIT_ASSERT ( s2.isEmpty() );
s2 -= finalcut::FSize(10, 10);
CPPUNIT_ASSERT ( s2.getWidth() == 0 );
CPPUNIT_ASSERT ( s2.getHeight() == 0 );
CPPUNIT_ASSERT ( s2.isEmpty() );
}
//----------------------------------------------------------------------
void FSizeTest::equalTest()
{
const finalcut::FSize s1 (1,2);
const finalcut::FSize s2 (1,2);
CPPUNIT_ASSERT ( s1 == s2 );
CPPUNIT_ASSERT ( finalcut::FSize(1,2) == s2 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(1,2) );
const finalcut::FSize s3{};
const finalcut::FSize s4{};
CPPUNIT_ASSERT ( s3 == s4 );
}
//----------------------------------------------------------------------
void FSizeTest::notEqualTest()
{
const finalcut::FSize s1 (3,5);
const finalcut::FSize s2 (2,4);
CPPUNIT_ASSERT ( s1 != s2 );
CPPUNIT_ASSERT ( finalcut::FSize(1,2) != s2 );
CPPUNIT_ASSERT ( s1 != finalcut::FSize(2,4) );
CPPUNIT_ASSERT ( finalcut::FSize() != s2 );
CPPUNIT_ASSERT ( s1 != finalcut::FSize() );
}
//----------------------------------------------------------------------
void FSizeTest::additionTest()
{
const finalcut::FSize s1 (1 ,2);
const finalcut::FSize s2 (5 ,8);
const finalcut::FSize s3 = s1 + s2;
CPPUNIT_ASSERT ( s3.getWidth() == 6 );
CPPUNIT_ASSERT ( s3.getHeight() == 10 );
CPPUNIT_ASSERT ( s1 + s2 == finalcut::FSize(6 ,10) );
CPPUNIT_ASSERT ( s1 + finalcut::FSize() == s1 );
CPPUNIT_ASSERT ( finalcut::FSize() + s2 == s2 );
CPPUNIT_ASSERT ( finalcut::FSize() + finalcut::FSize() == finalcut::FSize() );
}
//----------------------------------------------------------------------
void FSizeTest::subtractionTest()
{
const finalcut::FSize s1 (100, 20);
const finalcut::FSize s2 (10, 3);
const finalcut::FSize s3 = s1 - s2;
CPPUNIT_ASSERT ( s3.getWidth() == 90 );
CPPUNIT_ASSERT ( s3.getHeight() == 17 );
CPPUNIT_ASSERT ( s1 - s2 == finalcut::FSize(90, 17) );
CPPUNIT_ASSERT ( s1 - finalcut::FSize() == s1 );
CPPUNIT_ASSERT ( finalcut::FSize() - finalcut::FSize() == finalcut::FSize() );
CPPUNIT_ASSERT ( s3 - finalcut::FSize(100, 20) == finalcut::FSize(0, 0) );
}
//----------------------------------------------------------------------
void FSizeTest::referenceTest()
{
finalcut::FSize s1 (1,1);
CPPUNIT_ASSERT ( s1.getWidth() == 1 );
CPPUNIT_ASSERT ( s1.getHeight() == 1 );
s1.width_ref()++;
s1.height_ref()++;
CPPUNIT_ASSERT ( s1.getWidth() == 2 );
CPPUNIT_ASSERT ( s1.getHeight() == 2 );
std::size_t& width = s1.width_ref();
std::size_t& height = s1.height_ref();
width += 4;
height += 2;
CPPUNIT_ASSERT ( s1.getWidth() == 6 );
CPPUNIT_ASSERT ( s1.getHeight() == 4 );
}
//----------------------------------------------------------------------
void FSizeTest::streamInsertionTest()
{
finalcut::FSize out;
std::stringstream stream;
stream.str("10 5");
stream >> out;
CPPUNIT_ASSERT ( out.getWidth() == 10 );
CPPUNIT_ASSERT ( out.getHeight() == 5 );
stream.clear();
stream.str("0 9");
stream >> out;
CPPUNIT_ASSERT ( out.getWidth() == 0 );
CPPUNIT_ASSERT ( out.getHeight() == 9 );
}
//----------------------------------------------------------------------
void FSizeTest::streamExtractionTest()
{
finalcut::FSize in;
in.setSize (7, 5);
std::stringstream stream;
stream << in;
CPPUNIT_ASSERT ( stream.str() == "7 5" );
in.setSize (127, 150);
stream.clear();
stream.str("");
stream << in;
CPPUNIT_ASSERT ( stream.str() == "127 150" );
}
// Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FSizeTest);
// The general unit test main part
#include <main-test.inc>