From 4dcc573be7b30ff3a55701dba049cfd7adc3de2e Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 16 Jan 2019 16:00:15 +0100 Subject: [PATCH] New class FSize for storing dimensions --- ChangeLog | 3 + examples/mouse.cpp | 4 +- src/Makefile.am | 2 + src/Makefile.clang | 2 + src/Makefile.gcc | 2 + src/fbutton.cpp | 38 +--- src/fbuttongroup.cpp | 35 +--- src/fdialog.cpp | 18 +- src/flabel.cpp | 36 +--- src/fmouse.cpp | 8 +- src/fpoint.cpp | 4 +- src/frect.cpp | 31 ++- src/fscrollview.cpp | 41 ++-- src/fsize.cpp | 110 ++++++++++ src/ftogglebutton.cpp | 40 +--- src/fvterm.cpp | 18 +- src/fwindow.cpp | 12 +- src/include/final/fbutton.h | 3 +- src/include/final/fbuttongroup.h | 3 - src/include/final/flabel.h | 3 +- src/include/final/fmouse.h | 1 - src/include/final/fpoint.h | 8 +- src/include/final/frect.h | 24 ++- src/include/final/fscrollview.h | 5 +- src/include/final/fsize.h | 184 +++++++++++++++++ src/include/final/ftogglebutton.h | 3 +- src/include/final/fvterm.h | 4 +- src/include/final/fwidget.h | 59 +++++- src/include/final/fwindow.h | 4 +- test/Makefile.am | 3 + test/fpoint-test.cpp | 22 +- test/frect-test.cpp | 61 +++++- test/fsize-test.cpp | 332 ++++++++++++++++++++++++++++++ 33 files changed, 883 insertions(+), 240 deletions(-) create mode 100644 src/fsize.cpp create mode 100644 src/include/final/fsize.h create mode 100644 test/fsize-test.cpp diff --git a/ChangeLog b/ChangeLog index 23a35c20..ea2f365d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2019-01-16 Markus Gans + * New class FSize for storing dimensions + 2019-01-12 Markus Gans * Refactoring FFileDialog::fileOpenChooser * Refactoring FFileDialog::fileSaveChooser diff --git a/examples/mouse.cpp b/examples/mouse.cpp index 7ff85c74..a68c279e 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -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; diff --git a/src/Makefile.am b/src/Makefile.am index 66424afb..83b87c9e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 18e3f3d8..a0952cdc 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -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 \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index 5e25c80d..41328af7 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -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 \ diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 119d2b7f..0f382b40 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -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(); diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index f91a1949..f224949d 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -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(); diff --git a/src/fdialog.cpp b/src/fdialog.cpp index ac1825c3..a74f0666 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -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); diff --git a/src/flabel.cpp b/src/flabel.cpp index 0221e21f..3bab21b4 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -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(); diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 05789e65..f05be3e8 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -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; } diff --git a/src/fpoint.cpp b/src/fpoint.cpp index 51d93d4e..d6a8a614 100644 --- a/src/fpoint.cpp +++ b/src/fpoint.cpp @@ -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; } diff --git a/src/frect.cpp b/src/frect.cpp index 1233b595..61cbb157 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -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() ); } //---------------------------------------------------------------------- diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 5d5bc56f..8eb0ee93 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -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(fc::vertical, this); - hbar = std::make_shared(fc::horizontal, this); + bar = std::make_shared(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) ); } diff --git a/src/fsize.cpp b/src/fsize.cpp new file mode 100644 index 00000000..b3aa40b5 --- /dev/null +++ b/src/fsize.cpp @@ -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 * +* . * +***********************************************************************/ + +#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::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 diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index cba850a6..25d58f83 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -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(); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 589cbfc2..7818c14f 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -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; diff --git a/src/fwindow.cpp b/src/fwindow.cpp index 92dae41f..b33287aa 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -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) ) diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index 61a7b797..5ec9abad 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -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); diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index 5c6a590f..a5b91de3 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -117,9 +117,6 @@ class FButtonGroup : public FScrollView virtual void onFocusIn (FFocusEvent*) override; protected: - // Accessor - uChar getHotkey(); - // Mutator void setHotkeyAccelerator(); diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index 6651d74d..285d3e18 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -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); diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 6118788b..fd22986f 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -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{}; }; diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 2c3c1515..a8a89f73 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -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 * @@ -64,8 +64,8 @@ class FPoint FPoint& operator += (const FPoint&); FPoint& operator -= (const FPoint&); - friend bool operator == (const FPoint&, const FPoint&); - friend bool operator != (const FPoint&, const FPoint&); + friend bool operator == (const FPoint&, const FPoint&); + friend bool operator != (const FPoint&, const FPoint&); friend FPoint operator + (const FPoint&, const FPoint&); friend FPoint operator - (const FPoint&, const FPoint&); friend FPoint operator - (const FPoint&); @@ -81,7 +81,7 @@ class FPoint void setPoint (int, int); // Inquiry - bool isNull() const; + bool isOrigin() const; // Point references int& x_ref(); diff --git a/src/include/final/frect.h b/src/include/final/frect.h index 94bb0eaf..7ada102b 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -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 #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; } diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index 4f26c674..ad77c64f 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -156,6 +156,7 @@ class FScrollView : public FWidget private: // Typedef typedef std::shared_ptr 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(); diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h new file mode 100644 index 00000000..c97150e1 --- /dev/null +++ b/src/include/final/fsize.h @@ -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 * +* . * +***********************************************************************/ + +/* Standalone class + * ════════════════ + * + * ▕▔▔▔▔▔▔▔▏ + * ▕ FSize ▏ + * ▕▁▁▁▁▁▁▁▏ + */ + +#ifndef FSIZE_H +#define FSIZE_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include +#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::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 diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 233e75e9..dae44bfe 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -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 diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index a604aad9..af4d14e2 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -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 diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index e7b26d30..6d92aff1 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -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 diff --git a/src/include/final/fwindow.h b/src/include/final/fwindow.h index 6ba1f0e6..6939018b 100644 --- a/src/include/final/fwindow.h +++ b/src/include/final/fwindow.h @@ -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 diff --git a/test/Makefile.am b/test/Makefile.am index d68f5c4b..10c868ec 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 diff --git a/test/fpoint-test.cpp b/test/fpoint-test.cpp index 24c26b62..18c5ad1a 100644 --- a/test/fpoint-test.cpp +++ b/test/fpoint-test.cpp @@ -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::max() @@ -164,9 +164,9 @@ void FPointTest::additionAssignmentTest() CPPUNIT_ASSERT ( p2.getX() == std::numeric_limits::max() ); CPPUNIT_ASSERT ( p2.getY() == std::numeric_limits::min() ); p2 += finalcut::FPoint ( -std::numeric_limits::max() - , -std::numeric_limits::min() ); + , std::numeric_limits::max() ); CPPUNIT_ASSERT ( p2.getX() == 0 ); - CPPUNIT_ASSERT ( p2.getY() == 0 ); + CPPUNIT_ASSERT ( p2.getY() == std::numeric_limits::min() + std::numeric_limits::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::max() diff --git a/test/frect-test.cpp b/test/frect-test.cpp index 17d2324c..2ef7592a 100644 --- a/test/frect-test.cpp +++ b/test/frect-test.cpp @@ -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 ); } diff --git a/test/fsize-test.cpp b/test/fsize-test.cpp new file mode 100644 index 00000000..1785a289 --- /dev/null +++ b/test/fsize-test.cpp @@ -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 * +* . * +***********************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +//---------------------------------------------------------------------- +// 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::min() + , std::numeric_limits::max() ); + CPPUNIT_ASSERT ( s3.getWidth() == std::numeric_limits::min() ); + CPPUNIT_ASSERT ( s3.getHeight() == std::numeric_limits::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::max() + , std::numeric_limits::min() ); + CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits::max() ); + CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits::min() ); + s2 += finalcut::FSize{1, 1}; + CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits::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::max() + , std::numeric_limits::min() ); + CPPUNIT_ASSERT ( s2.getWidth() == std::numeric_limits::max() ); + CPPUNIT_ASSERT ( s2.getHeight() == std::numeric_limits::min() ); + CPPUNIT_ASSERT ( ! s2.isEmpty() ); + s2 -= finalcut::FSize ( std::numeric_limits::max(), + std::numeric_limits::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