mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
cscore: Add properties support to VideoSink (#1228)
Refactor the Property internals into PropertyContainer.
This commit is contained in:
64
cscore/src/main/native/cpp/PropertyImpl.cpp
Normal file
64
cscore/src/main/native/cpp/PropertyImpl.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "PropertyImpl.h"
|
||||
|
||||
using namespace cs;
|
||||
|
||||
PropertyImpl::PropertyImpl(wpi::StringRef name_) : name{name_} {}
|
||||
PropertyImpl::PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_,
|
||||
int step_, int defaultValue_, int value_)
|
||||
: name{name_},
|
||||
propKind{kind_},
|
||||
step{step_},
|
||||
defaultValue{defaultValue_},
|
||||
value{value_} {}
|
||||
PropertyImpl::PropertyImpl(wpi::StringRef name_, CS_PropertyKind kind_,
|
||||
int minimum_, int maximum_, int step_,
|
||||
int defaultValue_, int value_)
|
||||
: name{name_},
|
||||
propKind{kind_},
|
||||
hasMinimum{true},
|
||||
hasMaximum{true},
|
||||
minimum{minimum_},
|
||||
maximum{maximum_},
|
||||
step{step_},
|
||||
defaultValue{defaultValue_},
|
||||
value{value_} {}
|
||||
|
||||
void PropertyImpl::SetValue(int v) {
|
||||
int oldValue = value;
|
||||
if (hasMinimum && v < minimum)
|
||||
value = minimum;
|
||||
else if (hasMaximum && v > maximum)
|
||||
value = maximum;
|
||||
else
|
||||
value = v;
|
||||
bool wasValueSet = valueSet;
|
||||
valueSet = true;
|
||||
if (!wasValueSet || value != oldValue) changed();
|
||||
}
|
||||
|
||||
void PropertyImpl::SetValue(wpi::StringRef v) {
|
||||
bool valueChanged = false;
|
||||
if (valueStr != v) {
|
||||
valueStr = v;
|
||||
valueChanged = true;
|
||||
}
|
||||
bool wasValueSet = valueSet;
|
||||
valueSet = true;
|
||||
if (!wasValueSet || valueChanged) changed();
|
||||
}
|
||||
|
||||
void PropertyImpl::SetDefaultValue(int v) {
|
||||
if (hasMinimum && v < minimum)
|
||||
defaultValue = minimum;
|
||||
else if (hasMaximum && v > maximum)
|
||||
defaultValue = maximum;
|
||||
else
|
||||
defaultValue = v;
|
||||
}
|
||||
Reference in New Issue
Block a user