[nostalgia/core] Rename core::Color to core::Color16 and add core::Color32
This commit is contained in:
parent
1b08d0f851
commit
a9f55ebd02
@ -40,7 +40,7 @@ struct GbaTileMapTarget {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error modelRead(T *io, GbaPaletteTarget *t) {
|
ox::Error modelRead(T *io, GbaPaletteTarget *t) {
|
||||||
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
|
io->setTypeInfo("nostalgia::core::NostalgiaPalette", NostalgiaPalette::Fields);
|
||||||
oxReturnError(io->template field<Color>("colors", [t](auto i, Color *c) {
|
oxReturnError(io->template field<Color16>("colors", [t](auto i, Color16 *c) {
|
||||||
t->palette[i] = *c;
|
t->palette[i] = *c;
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}));
|
}));
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
// map ASCII values to the nostalgia charset
|
// map ASCII values to the nostalgia charset
|
||||||
char charMap[128] = {
|
static char charMap[128] = {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -141,6 +141,14 @@ char charMap[128] = {
|
|||||||
0, // ~
|
0, // ~
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Color32 toColor32(Color16 nc) {
|
||||||
|
auto r = ((nc & 0b0000000000011111) >> 0) * 8;
|
||||||
|
auto g = ((nc & 0b0000001111100000) >> 5) * 8;
|
||||||
|
auto b = ((nc & 0b0111110000000000) >> 10) * 8;
|
||||||
|
auto a = 255;
|
||||||
|
return a | (b << 8) | (g << 16) | (r << 24);
|
||||||
|
}
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, const char *str) {
|
void puts(Context *ctx, int column, int row, const char *str) {
|
||||||
for (int i = 0; str[i]; i++) {
|
for (int i = 0; str[i]; i++) {
|
||||||
setTile(ctx, 0, column + i, row, charMap[static_cast<int>(str[i])]);
|
setTile(ctx, 0, column + i, row, charMap[static_cast<int>(str[i])]);
|
||||||
|
@ -20,11 +20,17 @@ enum class TileSheetSpace {
|
|||||||
Sprite
|
Sprite
|
||||||
};
|
};
|
||||||
|
|
||||||
using Color = uint16_t;
|
using Color16 = uint16_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nostalgia Core logically uses 16 bit colors, but must translate that to 32
|
||||||
|
* bit colors in some implementations.
|
||||||
|
*/
|
||||||
|
using Color32 = uint32_t;
|
||||||
|
|
||||||
struct NostalgiaPalette {
|
struct NostalgiaPalette {
|
||||||
static constexpr auto Fields = 1;
|
static constexpr auto Fields = 1;
|
||||||
ox::Vector<Color> colors;
|
ox::Vector<Color16> colors;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NostalgiaGraphic {
|
struct NostalgiaGraphic {
|
||||||
@ -63,7 +69,7 @@ ox::Error model(T *io, NostalgiaGraphic *ng) {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] ox::Error loadTileSheet(Context *ctx, TileSheetSpace tss, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr);
|
[[nodiscard]] ox::Error loadTileSheet(Context *ctx, TileSheetSpace tss, int section, ox::FileAddress tilesheet, ox::FileAddress palette = nullptr);
|
||||||
|
|
||||||
ox::Error loadTileSheet(Context *ctx, ox::FileAddress file);
|
[[nodiscard]] Color32 toColor32(Color16 nc);
|
||||||
|
|
||||||
void puts(Context *ctx, int column, int row, const char *str);
|
void puts(Context *ctx, int column, int row, const char *str);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ ox::Error initConsole(Context *ctx) {
|
|||||||
return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr);
|
return loadTileSheet(ctx, TileSheetSpace::Background, 0, TilesheetAddr, PaletteAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Color createSDL_Color(Color nc) {
|
SDL_Color createSDL_Color(Color16 nc) {
|
||||||
SDL_Color c;
|
SDL_Color c;
|
||||||
// extract the color chanels and scale them up for a 24 bit color
|
// extract the color chanels and scale them up for a 24 bit color
|
||||||
c.r = ((nc & 0b0000000000011111) >> 0) * 8;
|
c.r = ((nc & 0b0000000000011111) >> 0) * 8;
|
||||||
|
@ -14,6 +14,7 @@ target_link_libraries(
|
|||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
Qt5::QuickWidgets
|
Qt5::QuickWidgets
|
||||||
NostalgiaStudio
|
NostalgiaStudio
|
||||||
|
NostalgiaCore
|
||||||
OxFS
|
OxFS
|
||||||
OxStd
|
OxStd
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@ Rectangle {
|
|||||||
anchors.horizontalCenter: tileSheetEditor.horizontalCenter
|
anchors.horizontalCenter: tileSheetEditor.horizontalCenter
|
||||||
anchors.verticalCenter: tileSheetEditor.verticalCenter
|
anchors.verticalCenter: tileSheetEditor.verticalCenter
|
||||||
rows: 2
|
rows: 2
|
||||||
columns: 3
|
columns: 2
|
||||||
Repeater {
|
Repeater {
|
||||||
model: tileGrid.rows * tileGrid.columns
|
model: tileGrid.rows * tileGrid.columns
|
||||||
Tile {
|
Tile {
|
||||||
|
@ -16,7 +16,7 @@ using namespace nostalgia::studio;
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
QVector<studio::WizardMaker> Plugin::newWizards(const Context *ctx) {
|
QVector<studio::WizardMaker> Plugin::newWizards(const studio::Context *ctx) {
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
tr("Tile Sheet"),
|
tr("Tile Sheet"),
|
||||||
|
@ -12,29 +12,19 @@
|
|||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include <nostalgia/core/gfx.hpp>
|
|
||||||
|
|
||||||
#include "consts.hpp"
|
#include "consts.hpp"
|
||||||
#include "tilesheeteditor.hpp"
|
#include "tilesheeteditor.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
uint32_t toColor32(Color nc) {
|
|
||||||
auto r = ((nc & 0b0000000000011111) >> 0) * 8;
|
|
||||||
auto g = ((nc & 0b0000001111100000) >> 5) * 8;
|
|
||||||
auto b = ((nc & 0b0111110000000000) >> 10) * 8;
|
|
||||||
auto a = 255;
|
|
||||||
return a | (b << 8) | (g << 16) | (r << 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
QVector<uint32_t> toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) {
|
QVector<Color32> toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *npal) {
|
||||||
if (!npal) {
|
if (!npal) {
|
||||||
npal = &ng->pal;
|
npal = &ng->pal;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<uint32_t> out;
|
QVector<Color32> out;
|
||||||
out.reserve(ng->tiles.size() * sizeof(Color));
|
out.reserve(ng->tiles.size() * sizeof(Color16));
|
||||||
|
|
||||||
if (ng->bpp == 8) {
|
if (ng->bpp == 8) {
|
||||||
for (std::size_t i = 0; i < ng->tiles.size(); i++) {
|
for (std::size_t i = 0; i < ng->tiles.size(); i++) {
|
||||||
@ -59,7 +49,7 @@ QVector<uint32_t> toPixels(const NostalgiaGraphic *ng, const NostalgiaPalette *n
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
QVector<uint32_t> toPixels(const studio::Context *ctx, QString ngPath, QString palPath = "") {
|
QVector<Color32> toPixels(const studio::Context *ctx, QString ngPath, QString palPath = "") {
|
||||||
auto ng = ctx->project->loadObj<NostalgiaGraphic>(ngPath);
|
auto ng = ctx->project->loadObj<NostalgiaGraphic>(ngPath);
|
||||||
std::unique_ptr<NostalgiaPalette> npal;
|
std::unique_ptr<NostalgiaPalette> npal;
|
||||||
if (palPath == "" && ng->defaultPalette.type() == ox::FileAddressType::Path) {
|
if (palPath == "" && ng->defaultPalette.type() == ox::FileAddressType::Path) {
|
||||||
@ -124,7 +114,7 @@ void TileSheetEditor::saveState() {
|
|||||||
void TileSheetEditor::restoreState() {
|
void TileSheetEditor::restoreState() {
|
||||||
QSettings settings(m_ctx->orgName, PluginName);
|
QSettings settings(m_ctx->orgName, PluginName);
|
||||||
settings.beginGroup("TileSheetEditor/state");
|
settings.beginGroup("TileSheetEditor/state");
|
||||||
m_splitter->restoreState(settings.value("m_splitter/state").toByteArray());
|
m_splitter->restoreState(settings.value("m_splitter/state", m_splitter->saveState()).toByteArray());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <nostalgia/core/gfx.hpp>
|
||||||
#include <nostalgia/studio/studio.hpp>
|
#include <nostalgia/studio/studio.hpp>
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
@ -21,7 +22,7 @@ class SheetData: public QObject {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<uint32_t> m_pixels;
|
QVector<Color32> m_pixels;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE QString pixel(int index);
|
Q_INVOKABLE QString pixel(int index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user