Qt: Initial mask support for transformed sprites
Vicki Pfau vi@endrift.com
Sat, 01 Jun 2019 23:41:28 -0700
4 files changed,
31 insertions(+),
16 deletions(-)
M
include/mgba/internal/gba/video.h
→
include/mgba/internal/gba/video.h
@@ -81,20 +81,20 @@ GBAObjAttributesC c;
uint16_t d; }; +struct GBAOAMMatrix { + int16_t padding0[3]; + int16_t a; + int16_t padding1[3]; + int16_t b; + int16_t padding2[3]; + int16_t c; + int16_t padding3[3]; + int16_t d; +}; + union GBAOAM { struct GBAObj obj[128]; - - struct GBAOAMMatrix { - int16_t padding0[3]; - int16_t a; - int16_t padding1[3]; - int16_t b; - int16_t padding2[3]; - int16_t c; - int16_t padding3[3]; - int16_t d; - } mat[32]; - + struct GBAOAMMatrix mat[32]; uint16_t raw[512]; };
M
src/platform/qt/AssetView.cpp
→
src/platform/qt/AssetView.cpp
@@ -204,9 +204,18 @@ !GBAObjAttributesAIsDisable(obj->a) || GBAObjAttributesAIsTransformed(obj->a),
GBAObjAttributesCGetPriority(obj->c), GBAObjAttributesBGetX(obj->b), GBAObjAttributesAGetY(obj->a), - bool(GBAObjAttributesBIsHFlip(obj->b)), - bool(GBAObjAttributesBIsVFlip(obj->b)), + false, + false, }; + if (GBAObjAttributesAIsTransformed(obj->a)) { + int matIndex = GBAObjAttributesBGetMatIndex(obj->b); + const GBAOAMMatrix* mat = &gba->video.oam.mat[matIndex]; + QTransform invXform(mat->a / 256., mat->c / 256., mat->b / 256., mat->d / 256., 0, 0); + newInfo.xform = invXform.inverted(); + } else { + newInfo.hflip = bool(GBAObjAttributesBIsHFlip(obj->b)); + newInfo.vflip = bool(GBAObjAttributesBIsVFlip(obj->b)); + } GBARegisterDISPCNT dispcnt = gba->memory.io[0]; // FIXME: Register name can't be imported due to namespacing issues if (!GBARegisterDISPCNTIsObjCharacterMapping(dispcnt)) { newInfo.stride = 0x20 >> (GBAObjAttributesAGet256Color(obj->a));
M
src/platform/qt/AssetView.h
→
src/platform/qt/AssetView.h
@@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once #include <QTimer> +#include <QTransform> #include <QWidget> #include <mgba/core/cache-set.h>@@ -58,6 +59,7 @@ unsigned x : 9;
unsigned y : 9; bool hflip : 1; bool vflip : 1; + QTransform xform; bool operator!=(const ObjInfo&) const; };
M
src/platform/qt/FrameView.cpp
→
src/platform/qt/FrameView.cpp
@@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FrameView.h" #include <QMouseEvent> -#include <QPainter> #include <QPalette> #include <array>@@ -177,6 +176,11 @@ QImage obj(compositeObj(info));
if (info.hflip || info.vflip) { obj = obj.mirrored(info.hflip, info.vflip); } + if (!info.xform.isIdentity()) { + offset += QPointF(obj.width(), obj.height()) / 2; + obj = obj.transformed(info.xform); + offset -= QPointF(obj.width() / 2, obj.height() / 2); + } m_queue.append({ { LayerId::SPRITE, sprite }, !m_disabled.contains({ LayerId::SPRITE, sprite }),@@ -243,7 +247,7 @@ gba->video.renderer->highlightOBJ[i] = false;
} QPalette palette; gba->video.renderer->highlightColor = palette.color(QPalette::HighlightedText).rgb(); - gba->video.renderer->highlightAmount = sin(m_glowFrame * M_PI / 30) * 64 + 64; + gba->video.renderer->highlightAmount = sin(m_glowFrame * M_PI / 30) * 48 + 64; if (!m_overrideBackdrop.isValid()) { QRgb backdrop = M_RGB5_TO_RGB8(gba->video.palette[0]) | 0xFF000000; m_backdropPicker.setColor(backdrop);