1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/***********************************************************************
* fscrollbar.h - Widget FScrollbar *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2012-2022 Markus Gans *
* *
* 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. *
* *
* 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
* ═══════════════════
*
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
* ▕ FVTerm ▏ ▕ FObject ▏
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
* ▲ ▲
* │ │
* └─────┬─────┘
* │
* ▕▔▔▔▔▔▔▔▔▔▏
* ▕ FWidget ▏
* ▕▁▁▁▁▁▁▁▁▁▏
* ▲
* │
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▏
* ▕ FScrollbar ▏
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▏
*/
#ifndef FSCROLLBAR_H
#define FSCROLLBAR_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include <functional>
#include <memory>
#include "final/fapplication.h"
#include "final/fwidget.h"
#include "final/util/flog.h"
namespace finalcut
{
// class forward declaration
class FScrollbar;
// Global using-declaration
using FScrollbarPtr = std::shared_ptr<FScrollbar>;
//----------------------------------------------------------------------
// class FScrollbar
//----------------------------------------------------------------------
class FScrollbar : public FWidget
{
public:
// Using-declaration
using FWidget::setGeometry;
// Enumeration
enum class ScrollType
{
None = 0,
Jump = 1,
StepBackward = 2,
StepForward = 3,
PageBackward = 4,
PageForward = 5,
WheelUp = 6,
WheelDown = 7
};
// Constructors
explicit FScrollbar (FWidget* = nullptr);
explicit FScrollbar (Orientation = Orientation::Vertical, FWidget* = nullptr);
// Destructor
~FScrollbar() override;
// Accessors
auto getClassName() const -> FString override;
auto getValue() const noexcept -> int;
auto getScrollType() const -> ScrollType;
// Mutators
void setMinimum (int);
void setMaximum (int);
void setRange (int, int);
void setValue (int);
void setSteps (double);
void setPageSize (int, int);
void setOrientation (Orientation);
void setSize (const FSize&, bool = true) override;
void setGeometry (const FPoint&, const FSize&, bool = true) override;
// Methods
void resize() override;
void redraw() override;
void calculateSliderValues();
void drawBar();
// Event handlers
void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override;
void onMouseMove (FMouseEvent*) override;
void onWheel (FWheelEvent*) override;
void onTimer (FTimerEvent*) override;
private:
// Methods
void init();
void draw() override;
void drawVerticalBar();
void drawVerticalBackgroundLine();
void drawHorizontalBar();
void drawHorizontalBackgroundColumn();
void drawButtons();
auto getClickedScrollType (int, int) const -> ScrollType;
auto getVerticalClickedScrollType (int) const -> ScrollType;
auto getHorizontalClickedScrollType (int) const -> ScrollType;
auto getSliderClickPos (int, int) const -> int;
void jumpToClickPos (int, int);
void jumpToClickPos (int);
void avoidScrollOvershoot();
void processScroll();
void changeOnResize();
// Data members
ScrollType scroll_type{ScrollType::None};
bool threshold_reached{false};
int threshold_time{500};
int repeat_time{80};
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};
Orientation bar_orientation{Orientation::Vertical};
int max_color{FVTerm::getFOutput()->getMaxColor()};
};
// non-member functions
//----------------------------------------------------------------------
template <typename Instance
, typename Callback>
void initScrollbar ( FScrollbarPtr& bar
, Orientation o
, Instance cb_instance
, const Callback& cb_handler )
{
bar = std::make_shared<FScrollbar>(o, cb_instance);
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
std::bind(cb_handler, cb_instance, bar.get())
);
}
// FScrollbar inline functions
//----------------------------------------------------------------------
inline auto FScrollbar::getClassName() const -> FString
{ return "FScrollbar"; }
//----------------------------------------------------------------------
inline auto FScrollbar::getValue() const noexcept -> int
{ return val; }
//----------------------------------------------------------------------
inline auto FScrollbar::getScrollType() const -> ScrollType
{ return scroll_type; }
} // namespace finalcut
#endif // FSCROLLBAR_H
|