mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 13:20:54 +00:00
Add helper for setting images in labels
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<QLabel *>(widget);
|
||||
if(label)
|
||||
{
|
||||
label->setMinimumSize(QSize());
|
||||
label->setMaximumSize(QSize(10000, 10000));
|
||||
label->setPixmap(QPixmap());
|
||||
}
|
||||
}
|
||||
{
|
||||
RDLabel *label = qobject_cast<RDLabel *>(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<RDLabel *>(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -225,6 +225,11 @@ struct MiniQtInvoker : ObjectForwarder<IMiniQtHelper>
|
||||
}
|
||||
|
||||
QWidget *CreateLabel() { return InvokeRetFunction<QWidget *>(&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<QWidget *>(&IMiniQtHelper::CreateOutputRenderingWidget);
|
||||
|
||||
Reference in New Issue
Block a user