2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fscrollbar.cpp - Widget FScrollbar *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2012-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* 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/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fevent.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fscrollbar.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fsize.h"
|
|
|
|
#include "final/fwidgetcolors.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FScrollbar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FScrollbar::FScrollbar(FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWidget{parent}
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
// The default scrollbar orientation is vertical
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry(FPoint{1, 1}, FSize{1, length}, false);
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-12 09:11:22 +01:00
|
|
|
FScrollbar::FScrollbar(fc::orientation o, FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWidget{parent}
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
setOrientation (o);
|
2015-09-22 04:18:20 +02:00
|
|
|
init();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FScrollbar::~FScrollbar() // destructor
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// public methods of FScrollbar
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::setMinimum (int minimum)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
min = minimum;
|
|
|
|
calculateSliderValues();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::setMaximum (int maximum)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
max = maximum;
|
|
|
|
calculateSliderValues();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-12-27 23:51:32 +01:00
|
|
|
void FScrollbar::setRange (int minimum, int maximum)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
min = minimum;
|
|
|
|
max = maximum;
|
|
|
|
calculateSliderValues();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::setValue (int value)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( value < min )
|
|
|
|
val = min;
|
|
|
|
else if ( value > max )
|
|
|
|
val = max;
|
|
|
|
else
|
|
|
|
val = value;
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
calculateSliderValues();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-04-09 20:08:53 +02:00
|
|
|
void FScrollbar::setSteps (double st)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( st <= 0.0 )
|
|
|
|
steps = 1.0;
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
|
|
|
steps = st;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
if ( pagesize == 0 )
|
|
|
|
pagesize = int(double(max)/steps);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::setPageSize (int document_size, int page_size)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( page_size == 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
pagesize = document_size;
|
2016-11-02 00:37:58 +01:00
|
|
|
steps = 1.0;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
pagesize = page_size;
|
2018-12-09 18:24:31 +01:00
|
|
|
|
|
|
|
if ( document_size <= 0 || page_size <= 0 )
|
|
|
|
steps = 1.0;
|
|
|
|
else
|
|
|
|
steps = double(double(document_size) / double(page_size));
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-12 09:11:22 +01:00
|
|
|
void FScrollbar::setOrientation (fc::orientation o)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-12-16 11:14:24 +01:00
|
|
|
length = ( o == fc::vertical ) ? getHeight() : getWidth();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( o == fc::vertical && bar_orientation == fc::horizontal )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setWidth(1);
|
|
|
|
setHeight(length);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
else if ( o == fc::horizontal && bar_orientation == fc::vertical )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setWidth(length);
|
|
|
|
setHeight(1);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
calculateSliderValues();
|
2016-11-02 00:37:58 +01:00
|
|
|
bar_orientation = o;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2019-12-23 03:53:32 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::setSize (const FSize& size, bool adjust)
|
|
|
|
{
|
|
|
|
// Set the scrollbar size
|
|
|
|
|
|
|
|
FWidget::setSize (size, adjust);
|
|
|
|
changeOnResize();
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-01-21 03:42:18 +01:00
|
|
|
void FScrollbar::setGeometry ( const FPoint& pos, const FSize& size
|
2018-11-20 21:11:04 +01:00
|
|
|
, bool adjust )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-08-06 17:02:19 +02:00
|
|
|
// Set the scrollbar geometry
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
FWidget::setGeometry (pos, size, adjust);
|
2019-12-23 03:53:32 +01:00
|
|
|
changeOnResize();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::resize()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget::resize();
|
|
|
|
setOrientation (bar_orientation);
|
|
|
|
setValue (val);
|
|
|
|
calculateSliderValues();
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::redraw()
|
|
|
|
{
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( isShown() )
|
|
|
|
draw();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::calculateSliderValues()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() && bar_orientation == fc::horizontal )
|
2018-12-09 18:24:31 +01:00
|
|
|
bar_length = ( length > 2 ) ? length - 4 : 1;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2018-12-09 18:24:31 +01:00
|
|
|
bar_length = ( length > 2 ) ? length - 2 : 1;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
slider_length = std::size_t(double(bar_length) / steps);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( slider_length < 1 )
|
|
|
|
slider_length = 1;
|
|
|
|
else if ( slider_length > bar_length )
|
|
|
|
slider_length = bar_length;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( val == min )
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
slider_pos = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( val == max )
|
|
|
|
{
|
2018-10-14 06:25:33 +02:00
|
|
|
slider_pos = int(bar_length - slider_length);
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t v = ( min < 0 ) ? std::size_t(val - min) : std::size_t(val);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-12-09 18:24:31 +01:00
|
|
|
if ( slider_length >= bar_length )
|
2016-09-27 00:46:05 +02:00
|
|
|
slider_pos = 0;
|
2018-12-09 18:24:31 +01:00
|
|
|
else
|
|
|
|
slider_pos = int( round ( double((bar_length - slider_length) * v)
|
|
|
|
/ double(max - min) ) );
|
|
|
|
|
|
|
|
if ( slider_pos > int(bar_length - slider_length) )
|
2018-10-14 06:25:33 +02:00
|
|
|
slider_pos = int(bar_length - slider_length);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 00:01:59 +02:00
|
|
|
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::drawBar()
|
|
|
|
{
|
2019-01-09 20:05:29 +01:00
|
|
|
if ( ! isShown() )
|
|
|
|
return;
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
if ( slider_pos == current_slider_pos || length < 3 )
|
|
|
|
return;
|
2017-02-20 00:00:53 +01:00
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
drawVerticalBar();
|
|
|
|
else // horizontal
|
|
|
|
drawHorizontalBar();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
current_slider_pos = slider_pos;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FScrollbar::onMouseDown (FMouseEvent* ev)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& ev->getButton() != fc::MiddleButton )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ( min == max )
|
|
|
|
return;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const int mouse_x = ev->getX();
|
|
|
|
const int mouse_y = ev->getY();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( ev->getButton() == fc::MiddleButton )
|
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
jumpToClickPos (mouse_x, mouse_y);
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Process left mouse button
|
2016-11-02 00:37:58 +01:00
|
|
|
scroll_type = getClickedScrollType(mouse_x, mouse_y);
|
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
if ( scroll_type == FScrollbar::noScroll )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
slider_click_pos = getSliderClickPos (mouse_x, mouse_y);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-02-20 00:00:53 +01:00
|
|
|
if ( slider_click_pos > 0 )
|
|
|
|
scroll_type = FScrollbar::scrollJump;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( scroll_type == FScrollbar::scrollPageBackward
|
2017-11-26 22:37:18 +01:00
|
|
|
|| scroll_type == FScrollbar::scrollPageForward )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
slider_click_stop_pos = mouse_y - 2;
|
|
|
|
else
|
2018-11-20 21:11:04 +01:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2016-11-02 00:37:58 +01:00
|
|
|
slider_click_stop_pos = mouse_x - 3;
|
|
|
|
else
|
|
|
|
slider_click_stop_pos = mouse_x - 2;
|
2018-11-20 21:11:04 +01:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
slider_click_stop_pos = -1;
|
|
|
|
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( scroll_type >= FScrollbar::scrollStepBackward
|
2017-11-26 22:37:18 +01:00
|
|
|
&& scroll_type <= FScrollbar::scrollPageForward )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
processScroll();
|
|
|
|
threshold_reached = false;
|
|
|
|
addTimer(threshold_time);
|
|
|
|
}
|
|
|
|
}
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::onMouseUp (FMouseEvent* ev)
|
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& ev->getButton() != fc::MiddleButton )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
slider_click_pos = -1;
|
|
|
|
|
|
|
|
if ( scroll_type != FScrollbar::noScroll )
|
|
|
|
{
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
scroll_type = FScrollbar::noScroll;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::onMouseMove (FMouseEvent* ev)
|
|
|
|
{
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ev->getButton() != fc::LeftButton
|
2017-11-26 22:37:18 +01:00
|
|
|
&& ev->getButton() != fc::MiddleButton )
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const int mouse_x = ev->getX();
|
|
|
|
const int mouse_y = ev->getY();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( ev->getButton() == fc::MiddleButton )
|
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
jumpToClickPos (mouse_x, mouse_y);
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Process left mouse button
|
2020-02-02 22:34:27 +01:00
|
|
|
const int new_scroll_type = getClickedScrollType(mouse_x, mouse_y);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( scroll_type == FScrollbar::scrollJump )
|
|
|
|
{
|
2019-10-01 23:14:00 +02:00
|
|
|
int new_val{};
|
2015-10-11 21:56:16 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int dy = mouse_y - slider_click_pos;
|
2016-11-02 00:37:58 +01:00
|
|
|
slider_click_pos = mouse_y;
|
2017-04-09 20:08:53 +02:00
|
|
|
new_val = int( round ( double((max - min) * (slider_pos + dy))
|
|
|
|
/ double(bar_length - slider_length) ) );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int dx = mouse_x - slider_click_pos;
|
2016-11-02 00:37:58 +01:00
|
|
|
slider_click_pos = mouse_x;
|
2017-04-09 20:08:53 +02:00
|
|
|
new_val = int( round ( double((max - min) * (slider_pos + dx))
|
|
|
|
/ double(bar_length - slider_length) ) );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( new_val != val )
|
|
|
|
{
|
|
|
|
setValue(new_val);
|
|
|
|
drawBar();
|
|
|
|
updateTerminal();
|
|
|
|
processScroll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( mouse_x < 1 || mouse_x > int(getWidth())
|
|
|
|
|| mouse_y < 1 || mouse_y > int(getHeight()) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else if ( scroll_type != FScrollbar::scrollJump )
|
|
|
|
{
|
|
|
|
addTimer(repeat_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( scroll_type != new_scroll_type )
|
|
|
|
{
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::onWheel (FWheelEvent* ev)
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int wheel = ev->getWheel();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( scroll_type != FScrollbar::noScroll )
|
|
|
|
{
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
scroll_type = FScrollbar::noScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( wheel == fc::WheelUp )
|
|
|
|
scroll_type = FScrollbar::scrollWheelUp;
|
|
|
|
else if ( wheel == fc::WheelDown )
|
|
|
|
scroll_type = FScrollbar::scrollWheelDown;
|
|
|
|
|
|
|
|
processScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::onTimer (FTimerEvent*)
|
|
|
|
{
|
|
|
|
if ( scroll_type == FScrollbar::noScroll )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( ! threshold_reached )
|
|
|
|
{
|
|
|
|
threshold_reached = true;
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
addTimer(repeat_time);
|
|
|
|
}
|
|
|
|
|
2018-02-18 21:50:24 +01:00
|
|
|
// Timer stop condition
|
2016-12-18 23:34:11 +01:00
|
|
|
if ( ( scroll_type == FScrollbar::scrollPageBackward
|
2018-02-18 21:50:24 +01:00
|
|
|
&& slider_pos == slider_click_stop_pos )
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ( scroll_type == FScrollbar::scrollPageForward
|
2018-02-18 21:50:24 +01:00
|
|
|
&& slider_pos == slider_click_stop_pos ) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const int max_slider_pos = int(bar_length - slider_length);
|
2018-02-18 21:50:24 +01:00
|
|
|
|
|
|
|
if ( scroll_type == FScrollbar::scrollPageBackward
|
|
|
|
&& slider_pos == 0 )
|
2017-01-02 08:07:46 +01:00
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
jumpToClickPos(0); // Scroll to the start
|
|
|
|
processScroll();
|
|
|
|
}
|
|
|
|
else if ( scroll_type == FScrollbar::scrollPageForward
|
|
|
|
&& slider_pos == max_slider_pos )
|
|
|
|
{
|
|
|
|
jumpToClickPos (max_slider_pos); // Scroll to the end
|
2017-01-02 08:07:46 +01:00
|
|
|
processScroll();
|
|
|
|
}
|
|
|
|
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-11-02 00:37:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
processScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// private methods of FScrollbar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::init()
|
|
|
|
{
|
|
|
|
unsetFocusable();
|
|
|
|
ignorePadding();
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry(FPoint{1, 1}, FSize{getWidth(), getHeight()});
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::draw()
|
|
|
|
{
|
2017-02-20 00:00:53 +01:00
|
|
|
if ( length < 2 )
|
|
|
|
return;
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
if ( isShown() )
|
|
|
|
drawButtons();
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
current_slider_pos = -1;
|
2020-06-06 21:10:06 +02:00
|
|
|
max_color = FTerm::getMaxColor();
|
2016-11-02 00:37:58 +01:00
|
|
|
drawBar();
|
|
|
|
}
|
|
|
|
|
2019-08-11 20:07:39 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::drawVerticalBar()
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setColor (wc->scrollbar_fg, wc->scrollbar_bg);
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int z{1}; z <= slider_pos; z++)
|
2019-08-11 20:07:39 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1 + z};
|
2019-08-11 20:07:39 +02:00
|
|
|
drawVerticalBackgroundLine();
|
|
|
|
}
|
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
setColor (wc->scrollbar_bg, wc->scrollbar_fg);
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(false);
|
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int z{1}; z <= int(slider_length); z++) // Draw slider
|
2019-08-11 20:07:39 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1 + slider_pos + z};
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2019-08-11 20:07:39 +02:00
|
|
|
print (' ');
|
|
|
|
|
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(true);
|
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
setColor (wc->scrollbar_fg, wc->scrollbar_bg);
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int z = slider_pos + int(slider_length) + 1; z <= int(bar_length); z++)
|
2019-08-11 20:07:39 +02:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1 + z};
|
2019-08-11 20:07:39 +02:00
|
|
|
drawVerticalBackgroundLine();
|
|
|
|
}
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollbar::drawVerticalBackgroundLine()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2019-08-11 20:07:39 +02:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() || max_color < 16 )
|
2019-08-11 20:07:39 +02:00
|
|
|
print (fc::MediumShade); // ▒
|
|
|
|
else
|
|
|
|
print (fc::NF_border_line_left); // ⎸
|
|
|
|
}
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() || max_color < 16 )
|
2019-08-11 20:07:39 +02:00
|
|
|
print (fc::MediumShade); // ▒
|
2020-05-16 22:24:36 +02:00
|
|
|
else if ( FTerm::isNewFont() )
|
2020-05-30 23:02:53 +02:00
|
|
|
print (fc::NF_rev_border_line_right); //⎹
|
2020-08-23 00:32:41 +02:00
|
|
|
else
|
2019-08-11 20:07:39 +02:00
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::drawHorizontalBar()
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setColor (wc->scrollbar_fg, wc->scrollbar_bg);
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{3, 1};
|
2019-08-11 20:07:39 +02:00
|
|
|
else
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{2, 1};
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int z{0}; z < slider_pos; z++)
|
2019-08-11 20:07:39 +02:00
|
|
|
drawHorizontalBackgroundColumn();
|
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
setColor (wc->scrollbar_bg, wc->scrollbar_fg);
|
2019-08-11 20:07:39 +02:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(false);
|
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int z{0}; z < int(slider_length); z++) // Draw slider
|
2019-08-11 20:07:39 +02:00
|
|
|
print (' ');
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(true);
|
|
|
|
|
2020-05-26 21:37:39 +02:00
|
|
|
setColor (wc->scrollbar_fg, wc->scrollbar_bg);
|
2019-08-25 22:16:00 +02:00
|
|
|
int z = slider_pos + int(slider_length) + 1;
|
2019-08-11 20:07:39 +02:00
|
|
|
|
|
|
|
for (; z <= int(bar_length); z++)
|
|
|
|
drawHorizontalBackgroundColumn();
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2019-08-11 20:07:39 +02:00
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollbar::drawHorizontalBackgroundColumn()
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() && max_color > 8 )
|
2019-11-06 02:40:47 +01:00
|
|
|
print (fc::NF_border_line_up_and_down); // ニ
|
2020-05-16 22:24:36 +02:00
|
|
|
else if ( FTerm::isMonochron() || max_color < 16 )
|
2019-08-11 20:07:39 +02:00
|
|
|
print (fc::MediumShade); // ▒
|
|
|
|
else
|
|
|
|
print (' ');
|
|
|
|
}
|
|
|
|
|
2017-12-27 23:51:32 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::drawButtons()
|
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setColor (wc->scrollbar_button_fg, wc->scrollbar_button_bg);
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2017-12-27 23:51:32 +01:00
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1};
|
2017-12-27 23:51:32 +01:00
|
|
|
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2019-11-03 23:34:47 +01:00
|
|
|
print() << NF_button_arrow_up
|
2020-05-02 00:07:35 +02:00
|
|
|
<< FPoint{1, int(length)}
|
2019-11-03 23:34:47 +01:00
|
|
|
<< NF_button_arrow_down;
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
2019-11-03 23:34:47 +01:00
|
|
|
print() << NF_button_arrow_left
|
2020-05-02 00:07:35 +02:00
|
|
|
<< FPoint{int(length) - 1, 1}
|
2019-11-03 23:34:47 +01:00
|
|
|
<< NF_button_arrow_right;
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{1, 1};
|
2017-12-27 23:51:32 +01:00
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2017-12-27 23:51:32 +01:00
|
|
|
setReverse(true);
|
|
|
|
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << fc::BlackUpPointingTriangle // ▲
|
2020-05-02 00:07:35 +02:00
|
|
|
<< FPoint{1, int(length)}
|
2019-01-27 13:44:13 +01:00
|
|
|
<< fc::BlackDownPointingTriangle; // ▼
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
2019-01-27 13:44:13 +01:00
|
|
|
print() << fc::BlackLeftPointingPointer // ◄
|
2020-05-02 00:07:35 +02:00
|
|
|
<< FPoint{int(length), 1}
|
2019-01-27 13:44:13 +01:00
|
|
|
<< fc::BlackRightPointingPointer; // ►
|
2017-12-27 23:51:32 +01:00
|
|
|
}
|
|
|
|
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isMonochron() )
|
2017-12-27 23:51:32 +01:00
|
|
|
setReverse(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 17:00:16 +02:00
|
|
|
FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y) const
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2020-02-05 08:57:13 +01:00
|
|
|
return getVerticalClickedScrollType(y);
|
2018-02-08 00:25:51 +01:00
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
|
|
|
return getHorizontalClickedScrollType(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 15:25:21 +02:00
|
|
|
FScrollbar::sType FScrollbar::getVerticalClickedScrollType (int y) const
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
if ( y == 1 )
|
|
|
|
{
|
|
|
|
return FScrollbar::scrollStepBackward; // decrement button
|
|
|
|
}
|
|
|
|
else if ( y > 1 && y <= slider_pos + 1 )
|
|
|
|
{
|
|
|
|
return FScrollbar::scrollPageBackward; // before slider
|
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( y > slider_pos + int(slider_length) + 1 && y < int(getHeight()) )
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
return FScrollbar::scrollPageForward; // after slider
|
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( y == int(getHeight()) )
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
return FScrollbar::scrollStepForward; // increment button
|
|
|
|
}
|
|
|
|
|
|
|
|
return FScrollbar::noScroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 15:25:21 +02:00
|
|
|
FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) const
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
if ( x == 1 || x == 2 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollStepBackward; // decrement button
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-08 00:25:51 +01:00
|
|
|
else if ( x > 2 && x <= slider_pos + 2 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollPageBackward; // before slider
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( x > slider_pos + int(slider_length) + 2 && x < int(getWidth()) - 1 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollPageForward; // after slider
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( x == int(getWidth()) - 1 || x == int(getWidth()) )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollStepForward; // increment button
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-08 00:25:51 +01:00
|
|
|
|
|
|
|
return FScrollbar::noScroll;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-08 00:25:51 +01:00
|
|
|
else
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
if ( x == 1 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollStepBackward; // decrement button
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-08 00:25:51 +01:00
|
|
|
else if ( x > 1 && x <= slider_pos + 1 )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::scrollPageBackward; // before slider
|
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( x > slider_pos + int(slider_length) + 1 && x < int(getWidth()) )
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
return FScrollbar::scrollPageForward; // after slider
|
|
|
|
}
|
2018-10-14 06:25:33 +02:00
|
|
|
else if ( x == int(getWidth()) )
|
2018-02-08 00:25:51 +01:00
|
|
|
{
|
|
|
|
return FScrollbar::scrollStepForward; // increment button
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-02-08 00:25:51 +01:00
|
|
|
return FScrollbar::noScroll;
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-07-12 15:25:21 +02:00
|
|
|
int FScrollbar::getSliderClickPos (int mouse_x, int mouse_y) const
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
// Get the clicked position on the slider
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-02-18 21:50:24 +01:00
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
|
|
|
if ( mouse_y > slider_pos + 1
|
2018-10-14 06:25:33 +02:00
|
|
|
&& mouse_y <= slider_pos + int(slider_length) + 1 )
|
2018-02-18 21:50:24 +01:00
|
|
|
return mouse_y; // on slider
|
|
|
|
}
|
|
|
|
else // horizontal bar orientation
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
if ( mouse_x > slider_pos + 2
|
2018-10-14 06:25:33 +02:00
|
|
|
&& mouse_x <= slider_pos + int(slider_length) + 2 )
|
2018-02-18 21:50:24 +01:00
|
|
|
return mouse_x; // on slider
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-02-18 21:50:24 +01:00
|
|
|
else
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2018-02-18 21:50:24 +01:00
|
|
|
if ( mouse_x > slider_pos + 1
|
2018-10-14 06:25:33 +02:00
|
|
|
&& mouse_x <= slider_pos + int(slider_length) + 1 )
|
2018-02-18 21:50:24 +01:00
|
|
|
return mouse_x; // on slider
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2018-02-18 21:50:24 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::jumpToClickPos (int x, int y)
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
int new_val{};
|
2018-02-18 21:50:24 +01:00
|
|
|
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2020-06-11 23:00:18 +02:00
|
|
|
if ( y > 1 && y < int(getHeight()) )
|
2018-02-18 21:50:24 +01:00
|
|
|
{
|
2020-06-11 23:00:18 +02:00
|
|
|
new_val = int( round ( double(max - min) * (y - 2.0 - double(slider_length/2))
|
2018-02-18 21:50:24 +01:00
|
|
|
/ double(bar_length - slider_length) ) );
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-02-18 21:50:24 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
const int nf = FTerm::isNewFont() ? 1 : 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2018-10-14 06:25:33 +02:00
|
|
|
if ( x > 1 + nf && x < int(getWidth()) - nf )
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2020-06-11 23:00:18 +02:00
|
|
|
new_val = int( round ( double(max - min) * (x - 2.0 - nf - double(slider_length/2))
|
2018-02-18 21:50:24 +01:00
|
|
|
/ double(bar_length - slider_length) ) );
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
2018-02-18 21:50:24 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( new_val != val )
|
|
|
|
{
|
|
|
|
setValue(new_val);
|
|
|
|
drawBar();
|
|
|
|
updateTerminal();
|
|
|
|
scroll_type = FScrollbar::scrollJump;
|
|
|
|
processScroll();
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2018-02-18 21:50:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::jumpToClickPos (int pos)
|
|
|
|
{
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
jumpToClickPos (0, pos + 2);
|
|
|
|
else
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
if ( FTerm::isNewFont() )
|
2018-02-18 21:50:24 +01:00
|
|
|
jumpToClickPos (pos + 3, 0);
|
|
|
|
else
|
|
|
|
jumpToClickPos (pos + 2, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::avoidScrollOvershoot()
|
|
|
|
{
|
|
|
|
// Avoid overshoot
|
|
|
|
if ( ( scroll_type == FScrollbar::scrollPageBackward
|
|
|
|
&& slider_pos < slider_click_stop_pos )
|
|
|
|
|| ( scroll_type == FScrollbar::scrollPageForward
|
|
|
|
&& slider_pos > slider_click_stop_pos ) )
|
|
|
|
{
|
|
|
|
jumpToClickPos (slider_click_stop_pos);
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2018-02-18 21:50:24 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::processScroll()
|
|
|
|
{
|
|
|
|
emitCallback("change-value");
|
2018-02-18 21:50:24 +01:00
|
|
|
avoidScrollOvershoot();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
2019-12-23 03:53:32 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FScrollbar::changeOnResize()
|
|
|
|
{
|
|
|
|
const FSize& size = getSize();
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t w = size.getWidth();
|
|
|
|
const std::size_t h = size.getHeight();
|
2019-12-23 03:53:32 +01:00
|
|
|
length = ( bar_orientation == fc::vertical ) ? h : w;
|
|
|
|
|
|
|
|
if ( bar_orientation == fc::vertical )
|
|
|
|
{
|
2020-05-16 22:24:36 +02:00
|
|
|
setWidth(FTerm::isNewFont() ? 2 : 1);
|
2019-12-23 03:53:32 +01:00
|
|
|
setHeight(length);
|
|
|
|
}
|
|
|
|
else // horizontal
|
|
|
|
{
|
|
|
|
setWidth(length);
|
|
|
|
setHeight(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateSliderValues();
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|