108 lines
2.9 KiB
C++
108 lines
2.9 KiB
C++
#include "gui/common/NamedField.hpp"
|
|
#include "gui/containers/ConfigItem.hpp"
|
|
#include "params.h"
|
|
#include <cstdint>
|
|
#include <gui/vehicleconfig_screen/VehicleConfigView.hpp>
|
|
|
|
VehicleConfigView::VehicleConfigView() : selectedParam{0} {}
|
|
|
|
void VehicleConfigView::setupScreen() {
|
|
VehicleConfigViewBase::setupScreen();
|
|
params.setNumberOfItems(ParamType_COUNT);
|
|
}
|
|
|
|
void VehicleConfigView::tearDownScreen() {
|
|
VehicleConfigViewBase::tearDownScreen();
|
|
}
|
|
|
|
void VehicleConfigView::paramsUpdateItem(ConfigItem &item, int16_t itemIndex) {
|
|
item.setType(static_cast<ParamType>(itemIndex));
|
|
item.setSelected(itemIndex == selectedParam);
|
|
item.setDirty(paramsDirty[itemIndex]);
|
|
}
|
|
|
|
void VehicleConfigView::selectPrevParam() {
|
|
if (selectedParam == 0) {
|
|
updateSelectedParam(ParamType_COUNT - 1);
|
|
} else {
|
|
updateSelectedParam(selectedParam - 1);
|
|
}
|
|
}
|
|
|
|
void VehicleConfigView::selectNextParam() {
|
|
updateSelectedParam((selectedParam + 1) % ParamType_COUNT);
|
|
}
|
|
|
|
void VehicleConfigView::decParam() {
|
|
params_dec(static_cast<ParamType>(selectedParam));
|
|
paramsDirty[selectedParam] = true;
|
|
params.itemChanged(selectedParam);
|
|
}
|
|
void VehicleConfigView::incParam() {
|
|
params_inc(static_cast<ParamType>(selectedParam));
|
|
paramsDirty[selectedParam] = true;
|
|
params.itemChanged(selectedParam);
|
|
}
|
|
|
|
void VehicleConfigView::confirmParam() {
|
|
params_broadcast(static_cast<ParamType>(selectedParam));
|
|
}
|
|
|
|
void VehicleConfigView::paramConfirmed(ParamType param) {
|
|
paramsDirty[param] = false;
|
|
params.itemChanged(param);
|
|
}
|
|
|
|
void VehicleConfigView::updateSelectedParam(int select) {
|
|
int previousSelected = selectedParam;
|
|
selectedParam = select;
|
|
params.itemChanged(previousSelected);
|
|
params.itemChanged(selectedParam);
|
|
|
|
ConfigItem *firstItem = nullptr;
|
|
int16_t firstY = INT16_MAX;
|
|
ConfigItem *lastItem = nullptr;
|
|
int16_t lastY = INT16_MIN;
|
|
for (int16_t i = 0; i < paramsListItems.getNumberOfDrawables(); ++i) {
|
|
ConfigItem *item =
|
|
static_cast<ConfigItem *>(paramsListItems.getDrawable(i));
|
|
int16_t y = item->getY();
|
|
if (y + item->getHeight() > params.getHeight() || y < 0) {
|
|
continue;
|
|
}
|
|
if (y < firstY) {
|
|
firstY = y;
|
|
firstItem = item;
|
|
}
|
|
if (y > lastY) {
|
|
lastY = y;
|
|
lastItem = item;
|
|
}
|
|
}
|
|
|
|
int16_t firstVisible = firstItem->getType();
|
|
int16_t lastVisible = lastItem->getType();
|
|
if (lastVisible < firstVisible) {
|
|
return;
|
|
}
|
|
int16_t numVisible = lastVisible - firstVisible + 1;
|
|
if (selectedParam >= firstVisible && selectedParam <= lastVisible) {
|
|
return;
|
|
}
|
|
|
|
int16_t firstWanted;
|
|
if (selectedParam == 0 && previousSelected == ParamType_COUNT - 1) {
|
|
firstWanted = 0;
|
|
} else if (selectedParam > previousSelected) {
|
|
firstWanted = selectedParam - numVisible + 1;
|
|
} else {
|
|
firstWanted = selectedParam;
|
|
}
|
|
if (firstWanted < 0) {
|
|
firstWanted = 0;
|
|
} else if (firstWanted > (int16_t)(ParamType_COUNT - 1)) {
|
|
firstWanted = ParamType_COUNT - 1;
|
|
}
|
|
params.animateToItem(firstWanted, 0);
|
|
}
|