finalcut/src/include/final/fscrollbar.h

221 lines
7.4 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fscrollbar.h - Widget FScrollbar *
* *
* This file is part of the Final Cut widget toolkit *
* *
* 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FTerm
*
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
*
* FScrollbar
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FSCROLLBAR_H
#define FSCROLLBAR_H
2015-05-23 13:35:12 +02: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>
#include "final/fwidget.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
// 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
explicit FScrollbar (FWidget* = nullptr);
2019-01-12 09:11:22 +01:00
explicit FScrollbar (fc::orientation = fc::vertical, FWidget* = nullptr);
// Disable copy constructor
FScrollbar (const FScrollbar&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
virtual ~FScrollbar();
// 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&
, 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;
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
// 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
};
// non-member function forward declarations
//----------------------------------------------------------------------
2019-10-05 23:20:07 +02:00
template<typename Instance, typename Callback>
void initScrollbar ( FScrollbarPtr& bar
, fc::orientation o
2019-10-05 23:20:07 +02:00
, Instance cb_instance
, const Callback& cb_handler )
{
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;
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)
);
}
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; }
//----------------------------------------------------------------------
inline FScrollbar::sType FScrollbar::getScrollType() const
{ return scroll_type; }
2015-05-23 13:35:12 +02:00
} // namespace finalcut
#endif // FSCROLLBAR_H