xref: /haiku/src/tests/kits/interface/SliderTest.cpp (revision aa3083e086e5a929c061c72983e09d916c548a38)
1 /*
2  * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <Application.h>
8 #include <Window.h>
9 #include <Slider.h>
10 #include <StringView.h>
11 
12 #include <stdio.h>
13 
14 
15 class Window : public BWindow {
16 	public:
17 		Window();
18 
19 		virtual bool QuitRequested();
20 };
21 
22 
23 void
24 downBy(BRect &rect, BView* view)
25 {
26 	rect.bottom = rect.top + view->Bounds().Height() + 10;
27 	rect.OffsetBy(0, rect.Height());
28 }
29 
30 
31 void
32 rightBy(BRect &rect, BView* view)
33 {
34 	rect.right = rect.left + view->Bounds().Width() + 10;
35 	rect.OffsetBy(rect.Width(), 0);
36 }
37 
38 
39 //	#pragma mark -
40 
41 
42 Window::Window()
43 	: BWindow(BRect(100, 100, 600, 400), "Slider-Test",
44 			B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
45 {
46 	BRect rect = Bounds();
47 	BView* view = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
48 	view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
49 	AddChild(view);
50 
51 	// horizontal sliders
52 
53 	rect.InsetBy(10, 10);
54 	rect.right = rect.left + 250;
55 	rect.bottom = rect.top + 30;
56 
57 	BSlider* slider = new BSlider(rect, "Slider1", "Test 1", NULL, 0, 100);
58 	slider->ResizeToPreferred();
59 	view->AddChild(slider);
60 
61 	downBy(rect, slider);
62 
63 	slider = new BSlider(rect, "Slider2", "Test 2", NULL, 0, 100, B_TRIANGLE_THUMB);
64 	slider->ResizeToPreferred();
65 	view->AddChild(slider);
66 
67 	downBy(rect, slider);
68 
69 	slider = new BSlider(rect, "Slider3", "Test 3", NULL, 0, 100);
70 	rgb_color color = { 200, 80, 80, 255 };
71 	slider->UseFillColor(true, &color);
72 	slider->SetHashMarks(B_HASH_MARKS_BOTTOM);
73 	slider->SetHashMarkCount(11);
74 	slider->SetLimitLabels("0", "100");
75 	slider->SetBarThickness(12.0);
76 	slider->ResizeToPreferred();
77 	view->AddChild(slider);
78 
79 	downBy(rect, slider);
80 
81 	slider = new BSlider(rect, "Slider4", "Test 4", NULL, 0, 100, B_TRIANGLE_THUMB);
82 	slider->SetLimitLabels("0", "100");
83 	slider->UseFillColor(true, &color);
84 	slider->SetBarThickness(20.0);
85 	slider->SetHashMarks(B_HASH_MARKS_BOTH);
86 	slider->SetHashMarkCount(21);
87 	slider->ResizeToPreferred();
88 	view->AddChild(slider);
89 
90 	downBy(rect, slider);
91 	rect.right = rect.left + 100;
92 	rect.bottom = rect.top + 100;
93 
94 	slider = new BSlider(rect, "SliderA", "Test A", NULL, 0, 100);
95 	slider->SetLimitLabels("0", "100");
96 	slider->UseFillColor(true, &color);
97 	slider->SetHashMarks(B_HASH_MARKS_BOTH);
98 	slider->SetHashMarkCount(5);
99 	view->AddChild(slider);
100 
101 	// vertical sliders
102 
103 	rect.left = 270;
104 	rect.right = rect.left + 30;
105 	rect.top = 10;
106 	rect.bottom = view->Bounds().Height() - 20;
107 
108 	slider = new BSlider(rect, "Slider5", "Test 5", NULL, 0, 100);
109 	slider->SetOrientation(B_VERTICAL);
110 	slider->SetBarThickness(12.0);
111 	slider->SetHashMarks(B_HASH_MARKS_RIGHT);
112 	slider->SetHashMarkCount(5);
113 	slider->ResizeToPreferred();
114 	view->AddChild(slider);
115 
116 	rightBy(rect, slider);
117 
118 	slider = new BSlider(rect, "Slider6", "Test 6", NULL, 0, 100, B_TRIANGLE_THUMB);
119 	slider->SetOrientation(B_VERTICAL);
120 	slider->ResizeToPreferred();
121 	view->AddChild(slider);
122 
123 	rightBy(rect, slider);
124 
125 	slider = new BSlider(rect, "Slider7", "Test 7", NULL, 0, 100);
126 	slider->SetOrientation(B_VERTICAL);
127 	slider->UseFillColor(true, &color);
128 	slider->SetHashMarks(B_HASH_MARKS_BOTH);
129 	slider->SetBarThickness(6.0);
130 	slider->SetHashMarkCount(11);
131 	slider->SetLimitLabels("0", "100");
132 	slider->ResizeToPreferred();
133 	view->AddChild(slider);
134 
135 	rightBy(rect, slider);
136 
137 	slider = new BSlider(rect, "Slider8", "Test 8", NULL, 0, 100, B_TRIANGLE_THUMB);
138 	slider->SetOrientation(B_VERTICAL);
139 	slider->UseFillColor(true, &color);
140 	slider->SetBarThickness(20.0);
141 	slider->SetHashMarks(B_HASH_MARKS_BOTH);
142 	slider->SetHashMarkCount(21);
143 	slider->SetLimitLabels("0", "100");
144 	slider->ResizeToPreferred();
145 	view->AddChild(slider);
146 }
147 
148 
149 bool
150 Window::QuitRequested()
151 {
152 	be_app->PostMessage(B_QUIT_REQUESTED);
153 	return true;
154 }
155 
156 
157 //	#pragma mark -
158 
159 
160 class Application : public BApplication {
161 	public:
162 		Application();
163 
164 		virtual void ReadyToRun(void);
165 };
166 
167 
168 Application::Application()
169 	: BApplication("application/x-vnd.haiku-test")
170 {
171 }
172 
173 
174 void
175 Application::ReadyToRun(void)
176 {
177 	BWindow *window = new Window();
178 	window->Show();
179 }
180 
181 
182 //	#pragma mark -
183 
184 
185 int
186 main(int argc, char **argv)
187 {
188 	Application app;
189 
190 	app.Run();
191 	return 0;
192 }
193 
194