This repository was archived by the owner on Aug 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFrameRateView.cpp
More file actions
105 lines (91 loc) · 2.44 KB
/
FrameRateView.cpp
File metadata and controls
105 lines (91 loc) · 2.44 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright 2017-2024 Stefano Ceccherini <stefano.ceccherini@gmail.com>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "FrameRateView.h"
#include "BSCApp.h"
#include "ControllerObserver.h"
#include "Settings.h"
#include "SliderTextControl.h"
#include <Box.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <Debug.h>
#include <GroupLayoutBuilder.h>
#include <LayoutBuilder.h>
#include <LayoutUtils.h>
#include <Message.h>
#include <TextControl.h>
#include <StringView.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "FrameRateView"
const static char* kFrameRateLabel = B_TRANSLATE("Target frame rate");
const static uint32 kLocalFrameRateChanged = 'FrCh';
FrameRateView::FrameRateView()
:
BView("frame_rate_view", B_WILL_DRAW)
{
fFrameRateSlider = new SliderTextControl("frame_rate_slider",
kFrameRateLabel, new BMessage(kLocalFrameRateChanged), 1, 60, 1, B_TRANSLATE("fps"));
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.AddGroup(B_HORIZONTAL)
.Add(fFrameRateSlider)
.End();
}
void
FrameRateView::AttachedToWindow()
{
if (be_app->LockLooper()) {
be_app->StartWatching(this, kMsgControllerCaptureStarted);
be_app->StartWatching(this, kMsgControllerCaptureStopped);
be_app->StartWatching(this, kMsgControllerResetSettings);
be_app->UnlockLooper();
}
fFrameRateSlider->SetValue(Settings::Current().CaptureFrameRate());
fFrameRateSlider->SetTarget(this);
}
void
FrameRateView::MessageReceived(BMessage* message)
{
BSCApp* app = dynamic_cast<BSCApp*>(be_app);
ASSERT(app != NULL);
switch (message->what) {
case kLocalFrameRateChanged:
{
int32 rate = fFrameRateSlider->Value();
app->SetCaptureFrameRate(rate);
break;
}
case B_OBSERVER_NOTICE_CHANGE:
{
int32 code;
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &code);
switch (code) {
case kMsgControllerCaptureStarted:
fFrameRateSlider->SetEnabled(false);
break;
case kMsgControllerCaptureStopped:
fFrameRateSlider->SetEnabled(true);
break;
case kMsgControllerCaptureFrameRateChanged:
{
int32 fps;
if (message->FindInt32("frame_rate", &fps) == B_OK)
fFrameRateSlider->SetValue(fps);
break;
}
case kMsgControllerResetSettings:
{
int32 fps = Settings::Current().CaptureFrameRate();
fFrameRateSlider->SetValue(fps);
break;
}
default:
break;
}
}
default:
BView::MessageReceived(message);
break;
}
}