diff --git a/qrenderdoc/Code/Interface/Extensions.h b/qrenderdoc/Code/Interface/Extensions.h index ddd8253d8..e64be9767 100644 --- a/qrenderdoc/Code/Interface/Extensions.h +++ b/qrenderdoc/Code/Interface/Extensions.h @@ -694,6 +694,22 @@ The widget needs to be added to a parent to become part of a panel or window. )"); virtual QWidget *CreateLabel() = 0; + DOCUMENT(R"(Set an image for a label widget. If the widget isn't a label, this call has no effect. + +The label will be resized to a fixed size to display the image at 100% scale. Any text in the label +will not be displayed, but passing an empty image will revert the label back to being text-based. + +The data must be in RGB(A) format with the first byte of each texel being R. + +:param QWidget widget: The widget to set the picture for. +:param bytes data: The image data itself, tightly packed. +:param int width: The width of the image in pixels. +:param int height: The height of the image in pixels. +:param bool alpha: ``True`` if the image data contains an alpha channel. +)"); + virtual void SetLabelImage(QWidget *widget, const bytebuf &data, int32_t width, int32_t height, + bool alpha) = 0; + DOCUMENT(R"(Create a widget suitable for rendering to with a :class:`renderdoc.ReplayOutput`. This widget takes care of painting on demand and recreating the internal display widget when necessary, however this means you must use :meth:`GetWidgetWindowingData` to retrieve the windowing data for diff --git a/qrenderdoc/Code/MiniQtHelper.cpp b/qrenderdoc/Code/MiniQtHelper.cpp index 913a91449..6bdc050b7 100644 --- a/qrenderdoc/Code/MiniQtHelper.cpp +++ b/qrenderdoc/Code/MiniQtHelper.cpp @@ -312,6 +312,26 @@ void MiniQtHelper::SetWidgetText(QWidget *widget, const rdcstr &text) return w->setText(text); \ } + // setting text on a QLabel removes its pixmap + { + QLabel *label = qobject_cast(widget); + if(label) + { + label->setMinimumSize(QSize()); + label->setMaximumSize(QSize(10000, 10000)); + label->setPixmap(QPixmap()); + } + } + { + RDLabel *label = qobject_cast(widget); + if(label) + { + label->setMinimumSize(QSize()); + label->setMaximumSize(QSize(10000, 10000)); + label->setPixmap(QPixmap()); + } + } + SET_TEXT(RDLabel); SET_TEXT(QLabel); SET_TEXT(RDLineEdit); @@ -460,6 +480,36 @@ QWidget *MiniQtHelper::CreateLabel() return new RDLabel(); } +void MiniQtHelper::SetLabelImage(QWidget *widget, const bytebuf &data, int32_t width, + int32_t height, bool alpha) +{ + if(!widget) + return; + + RDLabel *label = qobject_cast(widget); + + if(label) + { + QPixmap pixmap; + + int32_t bpp = alpha ? 4 : 3; + if(width > 0 && height > 0 && width * height * bpp == data.size()) + { + label->setFixedSize(width, height); + label->setPixmap( + QPixmap::fromImage(QImage(data.data(), width, height, width * bpp, + alpha ? QImage::Format_RGBA8888 : QImage::Format_RGB888) + .copy(0, 0, width, height))); + } + else + { + label->setMinimumSize(QSize()); + label->setMaximumSize(QSize(10000, 10000)); + label->setPixmap(QPixmap()); + } + } +} + QWidget *MiniQtHelper::CreateOutputRenderingWidget() { CustomPaintWidget *widget = new CustomPaintWidget(NULL); diff --git a/qrenderdoc/Code/MiniQtHelper.h b/qrenderdoc/Code/MiniQtHelper.h index 514dca5d7..9dbb6686f 100644 --- a/qrenderdoc/Code/MiniQtHelper.h +++ b/qrenderdoc/Code/MiniQtHelper.h @@ -89,6 +89,8 @@ public: QWidget *CreateButton(WidgetCallback pressed) override; QWidget *CreateLabel() override; + void SetLabelImage(QWidget *widget, const bytebuf &data, int32_t width, int32_t height, + bool alpha) override; QWidget *CreateOutputRenderingWidget() override; diff --git a/qrenderdoc/Windows/PythonShell.cpp b/qrenderdoc/Windows/PythonShell.cpp index be5f2a209..47102d341 100644 --- a/qrenderdoc/Windows/PythonShell.cpp +++ b/qrenderdoc/Windows/PythonShell.cpp @@ -225,6 +225,11 @@ struct MiniQtInvoker : ObjectForwarder } QWidget *CreateLabel() { return InvokeRetFunction(&IMiniQtHelper::CreateLabel); } + void SetLabelImage(QWidget *widget, const bytebuf &data, int32_t width, int32_t height, + bool alpha) override + { + InvokeVoidFunction(&IMiniQtHelper::SetLabelImage, widget, data, width, height, alpha); + } QWidget *CreateOutputRenderingWidget() { return InvokeRetFunction(&IMiniQtHelper::CreateOutputRenderingWidget);