From 825c919e86d1f76f68ae5a97edc587895d4e59ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20M=C3=BCller?= <d_muel20@uni-muenster.de>
Date: Wed, 11 Sep 2019 23:05:56 +0200
Subject: [PATCH] * Blocks are now shown transparent if bypassed

---
 Grinder/engine/processors/ResizeProcessor.cpp |   2 +-
 Grinder/ui/graph/GraphBlockNode.cpp           |  53 ++--
 Grinder/ui/graph/GraphPortNode.cpp            |  25 +-
 Grinder/ui/graph/GraphStyle.h                 | 263 +++++++++---------
 4 files changed, 177 insertions(+), 166 deletions(-)

diff --git a/Grinder/engine/processors/ResizeProcessor.cpp b/Grinder/engine/processors/ResizeProcessor.cpp
index 02688a6..f834420 100644
--- a/Grinder/engine/processors/ResizeProcessor.cpp
+++ b/Grinder/engine/processors/ResizeProcessor.cpp
@@ -37,7 +37,7 @@ void ResizeProcessor::execute(EngineExecutionContext& ctx)
 				double sx = *_block->targetFactorX() / 100.0;
 				double sy = *_block->targetFactorY() / 100.0;
 
-				newSize = cv::Size{std::lround(dataBlob->getMatrix().cols * sx), std::lround(dataBlob->getMatrix().rows * sy)};
+				newSize = cv::Size{static_cast<int>(std::lround(dataBlob->getMatrix().cols * sx)), static_cast<int>(std::lround(dataBlob->getMatrix().rows * sy))};
 			}
 
 			if (newSize.width < 1)
diff --git a/Grinder/ui/graph/GraphBlockNode.cpp b/Grinder/ui/graph/GraphBlockNode.cpp
index d1f1524..d64f753 100644
--- a/Grinder/ui/graph/GraphBlockNode.cpp
+++ b/Grinder/ui/graph/GraphBlockNode.cpp
@@ -60,38 +60,43 @@ void GraphBlockNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* op
 
 	painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform);
 
-	// Draw the node background (including outer glow if selected)
-	if (isSelected())
+	if (auto block = _block.lock())	// Make sure that the underlying block still exists
 	{
-		bool inactive = !_scene->hasFocus();
-
-		painter->save();
-		painter->setPen(QPen{Qt::NoPen});
-		painter->setBrush(inactive ? _blockStyle.selectionColorInactive : _blockStyle.selectionColor);
-		painter->setOpacity(_blockStyle.selectionOpacity);
-		painter->drawRoundedRect(_nodeRectSelected, _blockStyle.borderRadius, _blockStyle.borderRadius);
-		painter->restore();
-	}
+		// Draw the node background (including outer glow if selected)
+		if (isSelected())
+		{
+			bool inactive = !_scene->hasFocus();
+
+			painter->save();
+			painter->setPen(QPen{Qt::NoPen});
+			painter->setBrush(inactive ? _blockStyle.selectionColorInactive : _blockStyle.selectionColor);
+			painter->setOpacity(_blockStyle.selectionOpacity);
+			painter->drawRoundedRect(_nodeRectSelected, _blockStyle.borderRadius, _blockStyle.borderRadius);
+			painter->restore();
+		}
 
-	painter->fillRect(_nodeRect, _blockStyle.lightBackgroundColor);
+		if (block->isBypassSet())
+			painter->setOpacity(_blockStyle.bypassOpacity);
 
-	// Draw node contents
-	if (auto block = _block.lock())	// Make sure that the underlying block still exists
+		painter->fillRect(_nodeRect, _blockStyle.lightBackgroundColor);
+
+		// Draw node contents
 		drawHeader(painter, block.get());
 
-	// Draw node borders
-	auto borderWidth = _blockStyle.borderWidth;
-	auto borderWidthHalf = borderWidth * 0.5;
+		// Draw node borders
+		auto borderWidth = _blockStyle.borderWidth;
+		auto borderWidthHalf = borderWidth * 0.5;
 
-	QPen pen{_blockStyle.borderColor, borderWidth};
-	pen.setCapStyle(Qt::RoundCap);
-	pen.setJoinStyle(Qt::RoundJoin);
+		QPen pen{_blockStyle.borderColor, borderWidth};
+		pen.setCapStyle(Qt::RoundCap);
+		pen.setJoinStyle(Qt::RoundJoin);
 
-	painter->setPen(pen);
-	painter->drawRoundedRect(_nodeRect, _blockStyle.borderRadius, _blockStyle.borderRadius);
+		painter->setPen(pen);
+		painter->drawRoundedRect(_nodeRect, _blockStyle.borderRadius, _blockStyle.borderRadius);
 
-	qreal y = _nodeRect.top() + _geometry.headerRect.height() - borderWidthHalf;
-	painter->drawLine(_nodeRect.left() + borderWidthHalf, y, _nodeRect.right() - borderWidthHalf, y);
+		qreal y = _nodeRect.top() + _geometry.headerRect.height() - borderWidthHalf;
+		painter->drawLine(_nodeRect.left() + borderWidthHalf, y, _nodeRect.right() - borderWidthHalf, y);
+	}
 }
 
 void GraphBlockNode::beginRenameBlock()
diff --git a/Grinder/ui/graph/GraphPortNode.cpp b/Grinder/ui/graph/GraphPortNode.cpp
index 3b7daec..f89a18c 100644
--- a/Grinder/ui/graph/GraphPortNode.cpp
+++ b/Grinder/ui/graph/GraphPortNode.cpp
@@ -67,20 +67,23 @@ void GraphPortNode::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt
 
 	painter->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform);
 
-	// Draw the port connector
-	QPen pen{_portStyle.borderColor, _portStyle.borderWidth};
-	pen.setCapStyle(Qt::FlatCap);
-	pen.setJoinStyle(Qt::MiterJoin);
+	if (auto port = _port.lock())	// Make sure that the underlying port still exists
+	{
+		if (port->block()->isBypassSet())
+			painter->setOpacity(_portStyle.bypassOpacity);
 
-	painter->setPen(pen);
-	painter->fillRect(_geometry.portRect, _portStyle.darkBackgroundColor);
-	painter->drawRect(_geometry.portRect);
+		// Draw the port connector
+		QPen pen{_portStyle.borderColor, _portStyle.borderWidth};
+		pen.setCapStyle(Qt::FlatCap);
+		pen.setJoinStyle(Qt::MiterJoin);
 
-	auto sizeDiff = (_portStyle.outerSize - _portStyle.innerSize) / 2.0;
-	auto innerRect = _geometry.portRect - QMarginsF{sizeDiff, sizeDiff, sizeDiff, sizeDiff};
+		painter->setPen(pen);
+		painter->fillRect(_geometry.portRect, _portStyle.darkBackgroundColor);
+		painter->drawRect(_geometry.portRect);
+
+		auto sizeDiff = (_portStyle.outerSize - _portStyle.innerSize) / 2.0;
+		auto innerRect = _geometry.portRect - QMarginsF{sizeDiff, sizeDiff, sizeDiff, sizeDiff};
 
-	if (auto port = _port.lock())	// Make sure that the underlying port still exists
-	{
 		if (!port->isConnected())
 			painter->fillRect(innerRect, _portStyle.lightBackgroundColor);
 
diff --git a/Grinder/ui/graph/GraphStyle.h b/Grinder/ui/graph/GraphStyle.h
index dba0c08..12d4cf6 100644
--- a/Grinder/ui/graph/GraphStyle.h
+++ b/Grinder/ui/graph/GraphStyle.h
@@ -1,130 +1,133 @@
-/******************************************************************************
- * File: GraphStyle.h
- * Date: 20.1.2018
- *****************************************************************************/
-
-#ifndef GRAPHSTYLE_H
-#define GRAPHSTYLE_H
-
-#include <QColor>
-#include <QFont>
-#include <QSizeF>
-#include <QMarginsF>
-#include <QPalette>
-#include <memory>
-
-#include "ui/visscene/VisualSceneStyle.h"
-#include "pipeline/BlockCategory.h"
-
-namespace grndr
-{
-	class GraphScene;
-
-	class GraphStyle : public VisualSceneStyle
-	{
-	public:
-		struct LayoutStyle
-		{
-			QSizeF layoutMargins{100.0, 50.0};
-		};
-
-		struct NodeStyle
-		{
-			QFont font{};
-
-			QColor darkBackgroundColor{100, 100, 100};
-			QColor lightBackgroundColor{200, 200, 200};
-			QColor borderColor{0, 0, 0};
-			float borderRadius{3.0f};
-
-			QColor selectionColor{QPalette{}.highlight().color().lighter()};
-			QColor selectionColorInactive{QPalette{}.color(QPalette::Inactive, QPalette::Highlight).darker()};
-			QColor selectionColorHighlight{80, 210, 95};
-			float selectionMargin{6.0f};
-			float selectionOpacity{0.6f};
-
-			NodeStyle();
-		};
-
-		struct BlockNodeStyle : public NodeStyle
-		{
-			QSizeF minimumSize{150.0, 60.0};
-
-			QFont nameFont{font};
-			QFont typeFont{font};
-			QColor textColor{0, 0, 0};
-			QMarginsF textMargins{20.0, 3.0, 20.0, 3.0};
-
-			float borderWidth{3.0};
-
-			QMarginsF portMargins{6.0, 6.0, 6.0, 6.0};
-
-			QPointF bypassOffset{5.0, 5.0};
-			QSizeF bypassSize{12.0, 12.0};
-			float bypassBorderWidth{1.0f};
-			QColor bypassColorOn{255, 0, 0};
-			QColor bypassColorOff{0, 255, 0};
-
-			QColor getBlockCategoryColor(BlockCategory category) const;
-
-			BlockNodeStyle();
-		};
-
-		struct PortNodeStyle : public NodeStyle
-		{
-			float outerSize{15.0};
-			float innerSize {7.5};
-
-			QFont nameFont{font};
-			QColor textColor{0, 0, 0};
-			QMarginsF textMargins{5.0, 0.0, 5.0, 0.0};
-
-			float borderWidth{1.0};
-		};
-
-		struct ConnectionNodeStyle : public NodeStyle
-		{
-			float lineWidth{5.0f};
-
-			float blueprintOpacity{0.7f};
-			QColor blueprintPendingColor{50, 150, 255};
-			QColor blueprintValidColor{50, 255, 150};
-			QColor blueprintInvalidColor{255, 50, 50};			
-		};
-
-		struct ConnectionMessageStyle : public ConnectionNodeStyle
-		{
-			float messageOpacity{0.8f};
-			QFont messageFont{font};
-			QColor messageColor{255, 255, 255};
-			QMarginsF messageMargins{7.5, 7.5, 7.5, 7.5};
-		};
-
-	public:
-		static const GraphStyle& style() { if (!s_graphStyle) s_graphStyle = std::make_unique<GraphStyle>(); return *s_graphStyle; }
-
-	public:
-		GraphStyle();
-
-	public:		
-		const LayoutStyle& layoutStyle() const { return _layoutStyle; }
-
-		const BlockNodeStyle& blockNodeStyle() const { return _blockNodeStyle; }
-		const PortNodeStyle& portNodeStyle() const { return _portNodeStyle; }
-		const ConnectionNodeStyle& connectionNodeStyle() const { return _connectionNodeStyle; }
-		const ConnectionMessageStyle& connectionMessageStyle() const { return _connectionMessageStyle; }
-
-	private:		
-		LayoutStyle _layoutStyle;
-
-		BlockNodeStyle _blockNodeStyle;
-		PortNodeStyle _portNodeStyle;
-		ConnectionNodeStyle _connectionNodeStyle;
-		ConnectionMessageStyle _connectionMessageStyle;
-
-	private:
-		static std::unique_ptr<GraphStyle> s_graphStyle;
-	};
-}
-
-#endif
+/******************************************************************************
+ * File: GraphStyle.h
+ * Date: 20.1.2018
+ *****************************************************************************/
+
+#ifndef GRAPHSTYLE_H
+#define GRAPHSTYLE_H
+
+#include <QColor>
+#include <QFont>
+#include <QSizeF>
+#include <QMarginsF>
+#include <QPalette>
+#include <memory>
+
+#include "ui/visscene/VisualSceneStyle.h"
+#include "pipeline/BlockCategory.h"
+
+namespace grndr
+{
+	class GraphScene;
+
+	class GraphStyle : public VisualSceneStyle
+	{
+	public:
+		struct LayoutStyle
+		{
+			QSizeF layoutMargins{100.0, 50.0};
+		};
+
+		struct NodeStyle
+		{
+			QFont font{};
+
+			QColor darkBackgroundColor{100, 100, 100};
+			QColor lightBackgroundColor{200, 200, 200};
+			QColor borderColor{0, 0, 0};
+			float borderRadius{3.0f};
+
+			QColor selectionColor{QPalette{}.highlight().color().lighter()};
+			QColor selectionColorInactive{QPalette{}.color(QPalette::Inactive, QPalette::Highlight).darker()};
+			QColor selectionColorHighlight{80, 210, 95};
+			float selectionMargin{6.0f};
+			float selectionOpacity{0.6f};
+
+			NodeStyle();
+		};
+
+		struct BlockNodeStyle : public NodeStyle
+		{
+			QSizeF minimumSize{150.0, 60.0};
+
+			QFont nameFont{font};
+			QFont typeFont{font};
+			QColor textColor{0, 0, 0};
+			QMarginsF textMargins{20.0, 3.0, 20.0, 3.0};
+
+			float borderWidth{3.0};
+
+			QMarginsF portMargins{6.0, 6.0, 6.0, 6.0};
+
+			QPointF bypassOffset{5.0, 5.0};
+			QSizeF bypassSize{12.0, 12.0};
+			float bypassBorderWidth{1.0f};
+			QColor bypassColorOn{255, 0, 0};
+			QColor bypassColorOff{0, 255, 0};
+			float bypassOpacity{0.5f};
+
+			QColor getBlockCategoryColor(BlockCategory category) const;
+
+			BlockNodeStyle();
+		};
+
+		struct PortNodeStyle : public NodeStyle
+		{
+			float outerSize{15.0};
+			float innerSize {7.5};
+
+			QFont nameFont{font};
+			QColor textColor{0, 0, 0};
+			QMarginsF textMargins{5.0, 0.0, 5.0, 0.0};
+
+			float borderWidth{1.0};
+
+			float bypassOpacity{0.5f};
+		};
+
+		struct ConnectionNodeStyle : public NodeStyle
+		{
+			float lineWidth{5.0f};
+
+			float blueprintOpacity{0.7f};
+			QColor blueprintPendingColor{50, 150, 255};
+			QColor blueprintValidColor{50, 255, 150};
+			QColor blueprintInvalidColor{255, 50, 50};			
+		};
+
+		struct ConnectionMessageStyle : public ConnectionNodeStyle
+		{
+			float messageOpacity{0.8f};
+			QFont messageFont{font};
+			QColor messageColor{255, 255, 255};
+			QMarginsF messageMargins{7.5, 7.5, 7.5, 7.5};
+		};
+
+	public:
+		static const GraphStyle& style() { if (!s_graphStyle) s_graphStyle = std::make_unique<GraphStyle>(); return *s_graphStyle; }
+
+	public:
+		GraphStyle();
+
+	public:		
+		const LayoutStyle& layoutStyle() const { return _layoutStyle; }
+
+		const BlockNodeStyle& blockNodeStyle() const { return _blockNodeStyle; }
+		const PortNodeStyle& portNodeStyle() const { return _portNodeStyle; }
+		const ConnectionNodeStyle& connectionNodeStyle() const { return _connectionNodeStyle; }
+		const ConnectionMessageStyle& connectionMessageStyle() const { return _connectionMessageStyle; }
+
+	private:		
+		LayoutStyle _layoutStyle;
+
+		BlockNodeStyle _blockNodeStyle;
+		PortNodeStyle _portNodeStyle;
+		ConnectionNodeStyle _connectionNodeStyle;
+		ConnectionMessageStyle _connectionMessageStyle;
+
+	private:
+		static std::unique_ptr<GraphStyle> s_graphStyle;
+	};
+}
+
+#endif
-- 
GitLab