forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.h
68 lines (51 loc) · 1.6 KB
/
slider.h
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
// Aseprite UI Library
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UI_SLIDER_H_INCLUDED
#define UI_SLIDER_H_INCLUDED
#pragma once
#include "obs/signal.h"
#include "ui/widget.h"
namespace ui {
class SliderDelegate {
public:
virtual ~SliderDelegate() { }
virtual std::string onGetTextFromValue(int value) = 0;
virtual int onGetValueFromText(const std::string& text) = 0;
};
class Slider : public Widget {
public:
Slider(int min, int max, int value, SliderDelegate* delegate = nullptr);
int getMinValue() const { return m_min; }
int getMaxValue() const { return m_max; }
int getValue() const { return m_value; }
void setRange(int min, int max);
void setValue(int value);
bool isReadOnly() const { return m_readOnly; }
void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
void getSliderThemeInfo(int* min, int* max, int* value) const;
std::string convertValueToText(int value) const;
int convertTextToValue(const std::string& text) const;
// Signals
obs::signal<void()> Change;
obs::signal<void()> SliderReleased;
protected:
// Events
bool onProcessMessage(Message* msg) override;
void onPaint(PaintEvent& ev) override;
// New events
virtual void onChange();
virtual void onSliderReleased();
private:
void setupSliderCursor();
int m_min;
int m_max;
int m_value;
bool m_readOnly;
SliderDelegate* m_delegate;
};
} // namespace ui
#endif