xref: /haiku/src/preferences/input/InputTouchpadPrefView.h (revision 0a6ab6bbcad60e2998ac4d317ec0b37386647543)
1 /*
2  * Copyright 2019, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  *
5  * Author:
6  *		Preetpal Kaur <preetpalok123@gmail.com>
7  */
8 
9 
10 #ifndef TOUCHPAD_PREF_VIEW_H
11 #define TOUCHPAD_PREF_VIEW_H
12 
13 #include <Bitmap.h>
14 #include <Button.h>
15 #include <CheckBox.h>
16 #include <GroupView.h>
17 #include <Invoker.h>
18 #include <Slider.h>
19 #include <StringView.h>
20 #include <View.h>
21 
22 #include "InputTouchpadPref.h"
23 #include "touchpad_settings.h"
24 
25 #include <Debug.h>
26 
27 #if DEBUG
28 #	define LOG(text...) PRINT((text))
29 #else
30 #	define LOG(text...)
31 #endif
32 
33 const uint SCROLL_AREA_CHANGED = '&sac';
34 const uint SCROLL_CONTROL_CHANGED = '&scc';
35 const uint TAP_CONTROL_CHANGED = '&tcc';
36 const uint DEFAULT_SETTINGS = '&dse';
37 const uint REVERT_SETTINGS = '&rse';
38 const uint PADBLOCK_TIME_CHANGED = '&ptc';
39 
40 class DeviceListView;
41 
42 
43 //! Shows a touchpad
44 class TouchpadView : public BView, public BInvoker {
45 public:
46 							TouchpadView(BRect frame);
47 	virtual					~TouchpadView();
48 	virtual void			Draw(BRect updateRect);
49 	virtual void			MouseDown(BPoint point);
50 	virtual void			MouseUp(BPoint point);
51 	virtual void			MouseMoved(BPoint point, uint32 transit,
52 								const BMessage* dragMessage);
53 
54 	virtual void			AttachedToWindow();
55 	virtual void			GetPreferredSize(float* width, float* height);
56 
57 			void			SetValues(float rightRange, float bottomRange);
GetRightScrollRatio()58 			float			GetRightScrollRatio()
59 								{ return 1 - fXScrollRange / fPadRect.Width(); }
GetBottomScrollRatio()60 			float			GetBottomScrollRatio()
61 								{ return 1
62 									- fYScrollRange / fPadRect.Height(); }
63 private:
64 	virtual void 			DrawSliders();
65 
66 			BRect			fPrefRect;
67 			BRect			fPadRect;
68 			BRect			fXScrollDragZone;
69 			float			fXScrollRange;
70 			float			fOldXScrollRange;
71 			BRect			fYScrollDragZone;
72 			float			fYScrollRange;
73 			float			fOldYScrollRange;
74 
75 			bool			fXTracking;
76 			bool			fYTracking;
77 			BView*			fOffScreenView;
78 			BBitmap*		fOffScreenBitmap;
79 };
80 
81 
82 class TouchpadPrefView : public BGroupView {
83 public:
84 							TouchpadPrefView(BInputDevice* dev);
85 	virtual					~TouchpadPrefView();
86 	virtual	void			MessageReceived(BMessage* message);
87 	virtual	void			AttachedToWindow();
88 	virtual	void			DetachedFromWindow();
89 			void			SetupView();
90 
91 			void			SetValues(touchpad_settings *settings);
92 private:
93 			TouchpadPref	fTouchpadPref;
94 			TouchpadView*	fTouchpadView;
95 			BCheckBox*		fTwoFingerBox;
96 			BCheckBox*		fTwoFingerHorizontalBox;
97 			BSlider*		fScrollStepXSlider;
98 			BSlider*		fScrollStepYSlider;
99 			BSlider*		fScrollAccelSlider;
100 			BSlider*		fPadBlockerSlider;
101 			BSlider*		fTapSlider;
102 			BButton*		fDefaultButton;
103 			BButton*		fRevertButton;
104 };
105 
106 #endif	// TOUCHPAD_PREF_VIEW_H
107