2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fscrollbar.h - Widget FScrollbar *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-21 03:42:18 +01:00
|
|
|
* Copyright 2012-2019 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTerm ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FScrollbar ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FSCROLLBAR_H
|
|
|
|
#define FSCROLLBAR_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwidget.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-09-25 21:37:19 +02:00
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
// class forward declaration
|
|
|
|
class FScrollbar;
|
|
|
|
|
|
|
|
// Global typedef
|
|
|
|
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FScrollbar
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FScrollbar : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declarations
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
|
|
|
// Enumeration
|
|
|
|
enum sType
|
|
|
|
{
|
|
|
|
noScroll = 0,
|
|
|
|
scrollJump = 1,
|
|
|
|
scrollStepBackward = 2,
|
|
|
|
scrollStepForward = 3,
|
|
|
|
scrollPageBackward = 4,
|
|
|
|
scrollPageForward = 5,
|
|
|
|
scrollWheelUp = 6,
|
|
|
|
scrollWheelDown = 7
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constructors
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FScrollbar (FWidget* = nullptr);
|
2019-01-12 09:11:22 +01:00
|
|
|
explicit FScrollbar (fc::orientation = fc::vertical, FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FScrollbar (const FScrollbar&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
|
|
|
virtual ~FScrollbar();
|
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
FScrollbar& operator = (const FScrollbar&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
const FString getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
int getValue() const;
|
|
|
|
sType getScrollType() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2018-12-31 06:18:39 +01:00
|
|
|
void setMinimum (int);
|
|
|
|
void setMaximum (int);
|
|
|
|
void setRange (int, int);
|
|
|
|
void setValue (int);
|
|
|
|
void setSteps (double);
|
|
|
|
void setPageSize (int, int);
|
2019-01-12 09:11:22 +01:00
|
|
|
void setOrientation (fc::orientation);
|
2019-08-06 23:45:28 +02:00
|
|
|
void setGeometry ( const FPoint&, const FSize&
|
2019-01-21 03:42:18 +01:00
|
|
|
, bool = true ) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2019-08-06 23:45:28 +02:00
|
|
|
void resize() override;
|
|
|
|
void redraw() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void calculateSliderValues();
|
|
|
|
void drawBar();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onMouseDown (FMouseEvent*) override;
|
|
|
|
void onMouseUp (FMouseEvent*) override;
|
|
|
|
void onMouseMove (FMouseEvent*) override;
|
|
|
|
void onWheel (FWheelEvent*) override;
|
|
|
|
void onTimer (FTimerEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void init();
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2019-08-11 20:07:39 +02:00
|
|
|
void drawVerticalBar();
|
|
|
|
void drawVerticalBackgroundLine();
|
|
|
|
void drawHorizontalBar();
|
|
|
|
void drawHorizontalBackgroundColumn();
|
2018-12-31 06:18:39 +01:00
|
|
|
void drawButtons();
|
|
|
|
sType getClickedScrollType (int, int);
|
|
|
|
sType getVerticalClickedScrollType (int);
|
|
|
|
sType getHorizontalClickedScrollType (int);
|
|
|
|
int getSliderClickPos (int, int);
|
|
|
|
void jumpToClickPos (int, int);
|
|
|
|
void jumpToClickPos (int);
|
|
|
|
void avoidScrollOvershoot();
|
|
|
|
void processScroll();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2019-09-08 02:04:24 +02:00
|
|
|
sType scroll_type{FScrollbar::noScroll};
|
|
|
|
bool threshold_reached{false};
|
|
|
|
int threshold_time{500};
|
|
|
|
int repeat_time{10};
|
|
|
|
int slider_click_pos{-1};
|
|
|
|
int slider_click_stop_pos{-1};
|
|
|
|
int current_slider_pos{-1};
|
|
|
|
int slider_pos{0};
|
|
|
|
std::size_t slider_length{18}; // = bar_length
|
|
|
|
std::size_t bar_length{18}; // = length - 2
|
|
|
|
int val{0};
|
|
|
|
int min{0};
|
|
|
|
int max{99};
|
|
|
|
int pagesize{0};
|
|
|
|
double steps{1};
|
|
|
|
std::size_t length{20};
|
|
|
|
fc::orientation bar_orientation{fc::vertical};
|
|
|
|
int max_color{getMaxColor()};
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
|
|
|
|
// non-member function forward declarations
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
template<typename Instance, typename Callback>
|
2019-10-01 23:14:00 +02:00
|
|
|
void initScrollbar ( FScrollbarPtr& bar
|
|
|
|
, fc::orientation o
|
2019-10-05 23:20:07 +02:00
|
|
|
, Instance cb_instance
|
|
|
|
, const Callback& cb_handler )
|
2019-10-01 23:14:00 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bar = std::make_shared<FScrollbar>(o, cb_instance);
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << bad_alloc_str << ex.what() << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
using namespace std::placeholders;
|
2019-10-01 23:14:00 +02:00
|
|
|
bar->setMinimum(0);
|
|
|
|
bar->setValue(0);
|
|
|
|
bar->hide();
|
|
|
|
|
|
|
|
bar->addCallback
|
|
|
|
(
|
|
|
|
"change-value",
|
2019-10-05 23:20:07 +02:00
|
|
|
std::bind(cb_handler, cb_instance, _1, _2)
|
2019-10-01 23:14:00 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// FScrollbar inline functions
|
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FScrollbar::getClassName() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return "FScrollbar"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FScrollbar::getValue() const
|
|
|
|
{ return val; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-27 00:46:05 +02:00
|
|
|
inline FScrollbar::sType FScrollbar::getScrollType() const
|
|
|
|
{ return scroll_type; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FSCROLLBAR_H
|