xref: /haiku/src/preferences/input/InputTouchpadPrefView.h (revision 15fb7d88e971c4d6c787c6a3a5c159afb1ebf77b)
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 <StringView.h>
19 #include <Slider.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 
39 class DeviceListView;
40 
41 
42 //! Shows a touchpad
43 class TouchpadView : public BView, public BInvoker {
44 public:
45 							TouchpadView(BRect frame);
46 	virtual					~TouchpadView();
47 	virtual void			Draw(BRect updateRect);
48 	virtual void			MouseDown(BPoint point);
49 	virtual void			MouseUp(BPoint point);
50 	virtual void			MouseMoved(BPoint point, uint32 transit,
51 								const BMessage* dragMessage);
52 
53 	virtual void			AttachedToWindow();
54 	virtual void			GetPreferredSize(float* width, float* height);
55 
56 			void			SetValues(float rightRange, float bottomRange);
57 			float			GetRightScrollRatio()
58 								{ return 1 - fXScrollRange / fPadRect.Width(); }
59 			float			GetBottomScrollRatio()
60 								{ return 1
61 									- fYScrollRange / fPadRect.Height(); }
62 private:
63 	virtual void 			DrawSliders();
64 
65 			BRect			fPrefRect;
66 			BRect			fPadRect;
67 			BRect			fXScrollDragZone;
68 			float			fXScrollRange;
69 			float			fOldXScrollRange;
70 			BRect			fYScrollDragZone;
71 			float			fYScrollRange;
72 			float			fOldYScrollRange;
73 
74 			bool			fXTracking;
75 			bool			fYTracking;
76 			BView*			fOffScreenView;
77 			BBitmap*		fOffScreenBitmap;
78 };
79 
80 
81 class TouchpadPrefView : public BGroupView {
82 public:
83 							TouchpadPrefView(BInputDevice* dev);
84 	virtual					~TouchpadPrefView();
85 	virtual	void			MessageReceived(BMessage* message);
86 	virtual	void			AttachedToWindow();
87 	virtual	void			DetachedFromWindow();
88 			void			SetupView();
89 
90 			void			SetValues(touchpad_settings *settings);
91 private:
92 			TouchpadPref	fTouchpadPref;
93 			TouchpadView*	fTouchpadView;
94 			BCheckBox*		fTwoFingerBox;
95 			BCheckBox*		fTwoFingerHorizontalBox;
96 			BSlider*		fScrollStepXSlider;
97 			BSlider*		fScrollStepYSlider;
98 			BSlider*		fScrollAccelSlider;
99 			BSlider*		fTapSlider;
100 			BButton*		fDefaultButton;
101 			BButton*		fRevertButton;
102 };
103 
104 #endif	// TOUCHPAD_PREF_VIEW_H