mirror of https://github.com/mgba-emu/mgba.git
Qt: Add color picker to tile viewer
This commit is contained in:
parent
536dc8f7ab
commit
d62df68058
|
@ -10,6 +10,8 @@
|
|||
#include <QFontDatabase>
|
||||
|
||||
extern "C" {
|
||||
// TODO: Move color macros elsewhere
|
||||
#include "gba/video.h"
|
||||
#ifdef M_CORE_GBA
|
||||
#include "gba/memory.h"
|
||||
#endif
|
||||
|
@ -30,11 +32,18 @@ AssetTile::AssetTile(QWidget* parent)
|
|||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.preview->setDimensions(QSize(8, 8));
|
||||
m_ui.color->setDimensions(QSize(1, 1));
|
||||
m_ui.color->setSize(50);
|
||||
|
||||
connect(m_ui.preview, SIGNAL(indexPressed(int)), this, SLOT(selectColor(int)));
|
||||
|
||||
const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
|
||||
|
||||
m_ui.tileId->setFont(font);
|
||||
m_ui.address->setFont(font);
|
||||
m_ui.r->setFont(font);
|
||||
m_ui.g->setFont(font);
|
||||
m_ui.b->setFont(font);
|
||||
}
|
||||
|
||||
void AssetTile::setController(GameController* controller) {
|
||||
|
@ -93,3 +102,24 @@ void AssetTile::selectIndex(int index) {
|
|||
m_ui.preview->update();
|
||||
}
|
||||
|
||||
void AssetTile::selectColor(int index) {
|
||||
const uint16_t* data;
|
||||
mTileCacheSetPalette(m_tileCache.get(), m_paletteSet);
|
||||
unsigned bpp = 8 << m_tileCache->bpp;
|
||||
if (m_index < m_boundary) {
|
||||
data = mTileCacheGetTile(m_tileCache.get(), m_index, m_paletteId);
|
||||
} else {
|
||||
data = mTileCacheGetTile(m_tileCache.get(), m_index, m_paletteId + m_tileCache->count / 2);
|
||||
}
|
||||
uint16_t color = data[index];
|
||||
m_ui.color->setColor(0, color);
|
||||
m_ui.color->update();
|
||||
|
||||
uint32_t r = GBA_R5(color);
|
||||
uint32_t g = GBA_G5(color);
|
||||
uint32_t b = GBA_B5(color);
|
||||
m_ui.r->setText(tr("0x%0 (%1)").arg(r, 2, 16, QChar('0')).arg(r, 2, 10, QChar('0')));
|
||||
m_ui.g->setText(tr("0x%0 (%1)").arg(g, 2, 16, QChar('0')).arg(g, 2, 10, QChar('0')));
|
||||
m_ui.b->setText(tr("0x%0 (%1)").arg(b, 2, 16, QChar('0')).arg(b, 2, 10, QChar('0')));
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ public slots:
|
|||
void setPalette(int);
|
||||
void setPaletteSet(int, int boundary, int max);
|
||||
void selectIndex(int);
|
||||
void selectColor(int);
|
||||
|
||||
private:
|
||||
Ui::AssetTile m_ui;
|
||||
|
|
|
@ -1,87 +1,153 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AssetTile</class>
|
||||
<widget class="QGroupBox" name="AssetTile">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>120</x>
|
||||
<y>50</y>
|
||||
<width>160</width>
|
||||
<height>168</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="AssetTile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>AssetTile</string>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGBA::Swatch" name="preview" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>87</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Tile #</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="tileId">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="address">
|
||||
<property name="text">
|
||||
<string>0x06000000</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QGBA::Swatch" name="preview" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>87</width>
|
||||
<height>87</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Tile #</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="tileId">
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="address">
|
||||
<property name="text">
|
||||
<string>0x06000000</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QGBA::Swatch" name="color" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Red</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Green</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Blue</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<property name="leftMargin">
|
||||
<number>8</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="r">
|
||||
<property name="text">
|
||||
<string>0x00 (00)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="g">
|
||||
<property name="text">
|
||||
<string>0x00 (00)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="b">
|
||||
<property name="text">
|
||||
<string>0x00 (00)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Reference in New Issue