Skip to content

Commit

Permalink
Make render and alpha values use the modified struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Jan 29, 2025
1 parent 8bcdf28 commit 4ca565e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
11 changes: 6 additions & 5 deletions YUViewLib/src/statistics/StatisticsDataPainting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void paintVector(QPainter *painter,
if (vector.mapToColor)
arrowColor.setHsvF(
functions::clip((std::atan2(vy, vx) + M_PI) / (2 * M_PI), 0.0, 1.0), 1.0, 1.0);
arrowColor.setAlpha(arrowColor.alpha() * ((float)statisticsType.alphaFactor / 100.0));
arrowColor.setAlpha(
functions::scaleValueByPercent(arrowColor.alpha(), *statisticsType.alphaFactor));

if (vector.scaleToZoom)
vectorStyle.width = vectorStyle.width * zoomFactor / 8;
Expand Down Expand Up @@ -347,7 +348,7 @@ void stats::paintStatisticsData(QPainter *painter,
float(value) / (valueItem.size[0] * valueItem.size[1]));
else
rectColor = it->valueDataOptions->colorMapper.getColor(value);
rectColor.setAlpha(rectColor.alpha() * ((float)it->alphaFactor / 100.0));
rectColor.setAlpha(functions::scaleValueByPercent(rectColor.alpha(), *it->alphaFactor));

auto rectQColor = functionsGui::toQColor(rectColor);
painter->setBrush(rectQColor);
Expand Down Expand Up @@ -436,7 +437,7 @@ void stats::paintStatisticsData(QPainter *painter,
float(value) / (boundingRect.size().width() * boundingRect.size().height()));
else
color = valueOptions.colorMapper.getColor(value);
color.setAlpha(color.alpha() * ((float)it->alphaFactor / 100.0));
color.setAlpha(functions::scaleValueByPercent(color.alpha(), *it->alphaFactor));

// Fill polygon
QPainterPath path;
Expand Down Expand Up @@ -563,7 +564,7 @@ void stats::paintStatisticsData(QPainter *painter,
if (it->vectorDataOptions->mapToColor)
arrowColor.setHsvF(
functions::clip((std::atan2(vy, vx) + M_PI) / (2 * M_PI), 0.0, 1.0), 1.0, 1.0);
arrowColor.setAlpha(arrowColor.alpha() * ((float)it->alphaFactor / 100.0));
arrowColor.setAlpha(functions::scaleValueByPercent(arrowColor.alpha(), *it->alphaFactor));
if (it->vectorDataOptions->scaleToZoom)
vectorStyle.width = vectorStyle.width * zoomFactor / 8;

Expand Down Expand Up @@ -887,7 +888,7 @@ void stats::paintStatisticsData(QPainter *painter,
if (it->vectorDataOptions->mapToColor)
arrowColor.setHsvF(
functions::clip((std::atan2(vy, vx) + M_PI) / (2 * M_PI), 0.0, 1.0), 1.0, 1.0);
arrowColor.setAlpha(arrowColor.alpha() * ((float)it->alphaFactor / 100.0));
arrowColor.setAlpha(functions::scaleValueByPercent(arrowColor.alpha(), *it->alphaFactor));
if (it->vectorDataOptions->scaleToZoom)
vectorStyle.width = vectorStyle.width * zoomFactor / 8;

Expand Down
3 changes: 0 additions & 3 deletions YUViewLib/src/statistics/StatisticsType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ StatisticsType::StatisticsType(int typeId, std::string typeName)

void StatisticsType::saveInitialState()
{
this->init.render = this->render;
this->init.alphaFactor = this->alphaFactor;

this->init.valueDataOptions = this->valueDataOptions;
this->init.vectorDataOptions = this->vectorDataOptions;
this->init.gridOptions = this->gridOptions;
Expand Down
10 changes: 3 additions & 7 deletions YUViewLib/src/statistics/StatisticsType.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#pragma once

#include <common/Modified.h>
#include <common/Typedef.h>

#include "ColorMapper.h"
Expand Down Expand Up @@ -71,7 +72,6 @@ class StatisticsType
friend class StatisticsTypePlaylistHandler;

public:

int typeID{};
std::string typeName{};
std::string description{};
Expand All @@ -80,10 +80,9 @@ class StatisticsType

void setMappingValues(std::vector<std::string> values);

// Is this statistics type rendered and what is the alpha value?
// These are corresponding to the controls in the properties panel
bool render{};
int alphaFactor{50};
modified<bool> render{};
modified<int> alphaFactor{50};

struct ValueDataOptions
{
Expand Down Expand Up @@ -137,9 +136,6 @@ class StatisticsType

struct initialState
{
bool render;
int alphaFactor;

std::optional<ValueDataOptions> valueDataOptions;
std::optional<VectorDataOptions> vectorDataOptions;
GridOptions gridOptions;
Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/statistics/StatisticsTypePlaylistHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void StatisticsTypePlaylistHandler::saveToPlaylist(const StatisticsType &type,
YUViewDomElement &root)
{
bool allValuesIdenticalToInitialValues =
(type.init.render == type.render && //
type.init.alphaFactor == type.alphaFactor && //
(!type.render.wasModified() && //
!type.alphaFactor.wasModified() && //
type.init.valueDataOptions == type.valueDataOptions && //
type.init.vectorDataOptions == type.vectorDataOptions && //
type.init.gridOptions == type.gridOptions);
Expand All @@ -142,9 +142,9 @@ void StatisticsTypePlaylistHandler::saveToPlaylist(const StatisticsType &type,
newChild.appendChild(root.ownerDocument().createTextNode(QString::fromStdString(type.typeName)));

// Append only the parameters that changed
if (type.init.render != type.render)
if (type.render.wasModified())
newChild.setAttribute("render", type.render);
if (type.init.alphaFactor != type.alphaFactor)
if (type.alphaFactor.wasModified())
newChild.setAttribute("alphaFactor", type.alphaFactor);

addModifiedValuesToElement(newChild, type.valueDataOptions, type.init.valueDataOptions);
Expand Down

0 comments on commit 4ca565e

Please sign in to comment.