diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index 4fb29390..3d3e2eb5 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -42,7 +42,8 @@ template } ox::Error initGfx(Context*) { - window = SDL_CreateWindow("nostalgia", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow("nostalgia", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, + SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); return OxError(window == nullptr); } diff --git a/src/nostalgia/core/studio/CMakeLists.txt b/src/nostalgia/core/studio/CMakeLists.txt index 6f2cc2e6..91052545 100644 --- a/src/nostalgia/core/studio/CMakeLists.txt +++ b/src/nostalgia/core/studio/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries( OxStd ) -target_compile_definitions(NostalgiaCore-Studio PRIVATE QT_QML_DEBUG) +#target_compile_definitions(NostalgiaCore-Studio PRIVATE QT_QML_DEBUG) install( TARGETS diff --git a/src/nostalgia/core/studio/Pixel.qml b/src/nostalgia/core/studio/Pixel.qml index 41fa465e..b448ebfb 100644 --- a/src/nostalgia/core/studio/Pixel.qml +++ b/src/nostalgia/core/studio/Pixel.qml @@ -11,7 +11,7 @@ import QtQuick 2.0 Rectangle { id: pixel; property int pixelNumber: index - color: sheetData.palette[sheetData.pixels[pixelNumber]] + color: sheetData.palette[pixelNumber < sheetData.pixels.length ? sheetData.pixels[pixelNumber] : 0] width: parent.width / 8 height: parent.height / 8 border.color: '#717d7e' diff --git a/src/nostalgia/core/studio/TileSheetEditor.qml b/src/nostalgia/core/studio/TileSheetEditor.qml index 053dc948..de4f5964 100644 --- a/src/nostalgia/core/studio/TileSheetEditor.qml +++ b/src/nostalgia/core/studio/TileSheetEditor.qml @@ -7,11 +7,20 @@ */ import QtQuick 2.0 +import QtQuick.Controls 2.14 import 'qrc:/qml/' -Rectangle { +ScrollView { id: tileSheetEditor - color: '#717d7e' + ScrollBar.horizontal.policy: ScrollBar.AsNeeded + ScrollBar.vertical.policy: ScrollBar.AsNeeded + contentWidth: tileGrid.width + contentHeight: tileGrid.height + clip: true + + background: Rectangle { + color: '#717d7e' + } MouseArea { id: mouseArea @@ -26,29 +35,24 @@ Rectangle { } } - onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY)) - onReleased: sheetData.endCmd(); - onCanceled: sheetData.endCmd(); - - Grid { - id: tileGrid - property int baseTileSize: Math.min(parent.width / tileGrid.columns, parent.height / tileGrid.rows) - width: tileGrid.columns * tileGrid.baseTileSize * 0.90 - height: tileGrid.rows * tileGrid.baseTileSize * 0.90 - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - rows: sheetData.rows - columns: sheetData.columns - Repeater { - model: tileGrid.rows * tileGrid.columns - Tile { - tileNumber: index - width: tileGrid.width / tileGrid.columns - height: tileGrid.height / tileGrid.rows + onWheel: { + if (wheel.modifiers & Qt.ControlModifier) { + const mod = tileGrid.scaleFactor / 10; + if (wheel.angleDelta.y > 0 && tileGrid.scaleFactor < 7) { + tileGrid.scaleFactor += mod; + } else if (tileGrid.scaleFactor > 0.9) { + tileGrid.scaleFactor -= mod; } + wheel.accepted = true; + } else { + wheel.accepted = false; } } + onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY)) + onReleased: sheetData.endCmd() + onCanceled: sheetData.endCmd() + function pixelAt(x, y) { var gridX = x - tileGrid.x; var gridY = y - tileGrid.y; @@ -64,4 +68,24 @@ Rectangle { } + Grid { + id: tileGrid + property double scaleFactor: 0.9 + property int baseTileSize: Math.min(2000 / tileGrid.columns, 1000 / tileGrid.rows) + width: tileGrid.columns * tileGrid.baseTileSize * tileGrid.scaleFactor + height: tileGrid.rows * tileGrid.baseTileSize * tileGrid.scaleFactor + //anchors.horizontalCenter: parent.horizontalCenter + //anchors.verticalCenter: parent.verticalCenter + rows: sheetData.rows + columns: sheetData.columns + Repeater { + model: tileGrid.rows * tileGrid.columns + Tile { + tileNumber: index + width: tileGrid.width / tileGrid.columns + height: tileGrid.height / tileGrid.rows + } + } + } + } diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index 0415c087..e04f9ed0 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -10,7 +10,6 @@ #include -#include #include #include @@ -20,20 +19,11 @@ namespace nostalgia::studio { -struct Context: public QObject { - Q_OBJECT - - public: - QString appName; - QString orgName; - QWidget *tabParent = nullptr; - const Project *project = nullptr; - - signals: - void addToolBar(QToolBar *tb); - - void removeToolBar(QToolBar *tb); - +struct Context { + QString appName; + QString orgName; + QWidget *tabParent = nullptr; + const Project *project = nullptr; }; struct EditorMaker { diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index b6645d1b..7c111a8e 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -19,25 +18,6 @@ using namespace std; using namespace ox; -using namespace nostalgia::common; - -[[nodiscard]] ox::ValErr> loadFileBuff(std::string path, ::size_t *sizeOut = nullptr) { - auto file = fopen(path.c_str(), "rb"); - if (file) { - fseek(file, 0, SEEK_END); - const auto size = ftell(file); - rewind(file); - std::vector buff(size); - auto itemsRead = fread(buff.data(), buff.size(), 1, file); - fclose(file); - if (sizeOut) { - *sizeOut = itemsRead ? size : 0; - } - return buff; - } else { - return {{}, OxError(1)}; - } -} [[nodiscard]] static ox::Error writeFileBuff(const std::string &path, const std::vector &buff) { auto file = fopen(path.c_str(), "wb");