xref: /haiku/src/preferences/screen/RefreshSlider.cpp (revision 3cb015b1ee509d69c643506e8ff573808c86dcfc)
1 /*
2  * Copyright 2001-2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Rafael Romo
7  *		Stefano Ceccherini (burton666@libero.it)
8  *		Axel Dörfler, axeld@pinc-software.de
9  */
10 
11 
12 #include "RefreshSlider.h"
13 #include "Constants.h"
14 
15 #include <String.h>
16 #include <Window.h>
17 
18 #include <new>
19 #include <stdio.h>
20 
21 
22 RefreshSlider::RefreshSlider(BRect frame, float min, float max, uint32 resizingMode)
23 	: BSlider(frame, "Screen", "Refresh Rate:",
24 		new BMessage(SLIDER_INVOKE_MSG), rintf(min * 10), rintf(max * 10),
25 		B_BLOCK_THUMB, resizingMode),
26 	fStatus(new (std::nothrow) char[32])
27 {
28 	BString minRefresh;
29 	minRefresh << (uint32)min;
30 	BString maxRefresh;
31 	maxRefresh << (uint32)max;
32 	SetLimitLabels(minRefresh.String(), maxRefresh.String());
33 
34 	SetHashMarks(B_HASH_MARKS_BOTTOM);
35 	SetHashMarkCount(uint32(max - min) / 5 + 1);
36 
37 	SetKeyIncrementValue(1);
38 }
39 
40 
41 RefreshSlider::~RefreshSlider()
42 {
43 	delete[] fStatus;
44 }
45 
46 
47 void
48 RefreshSlider::DrawFocusMark()
49 {
50 	if (IsFocus()) {
51 		rgb_color blue = { 0, 0, 229, 255 };
52 
53 		BRect rect(ThumbFrame());
54 		BView *view = OffscreenView();
55 
56 		rect.InsetBy(2.0, 2.0);
57 		rect.right--;
58 		rect.bottom--;
59 
60 		view->SetHighColor(blue);
61 		view->StrokeRect(rect);
62 	}
63 }
64 
65 
66 void
67 RefreshSlider::KeyDown(const char *bytes, int32 numBytes)
68 {
69 	switch (*bytes) {
70 		case B_LEFT_ARROW:
71 		{
72 			SetValue(Value() - 1);
73 			Invoke();
74 			break;
75 		}
76 
77 		case B_RIGHT_ARROW:
78 		{
79 			SetValue(Value() + 1);
80 			Invoke();
81 			break;
82 		}
83 
84 		default:
85 			break;
86 	}
87 }
88 
89 
90 char*
91 RefreshSlider::UpdateText() const
92 {
93 	if (fStatus != NULL)
94 		snprintf(fStatus, 32, "%.1f Hz", (float)Value() / 10);
95 
96 	return fStatus;
97 }
98