-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for importing symbols from fonts as a spritesheet
- Loading branch information
1 parent
6278bf3
commit f3f2264
Showing
7 changed files
with
599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "importdialog.h" | ||
|
||
#include <QColorDialog> | ||
#include <QFileDialog> | ||
#include <QFontDatabase> | ||
#include <QImageWriter> | ||
#include <QMessageBox> | ||
#include <QPainter> | ||
#include <algorithm> | ||
|
||
#include "mainwindow.h" | ||
#include "ui_importdialog.h" | ||
|
||
ImportDialog::ImportDialog(QWidget *parent) | ||
: QDialog(parent) | ||
, ui(new Ui::ImportDialog()) | ||
{ | ||
ui->setupUi(this); | ||
} | ||
|
||
ImportDialog::~ImportDialog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void ImportDialog::initialize() | ||
{ | ||
// - remember the last selected type | ||
QComboBox *typeBox = this->ui->typeComboBox; | ||
QString lastFmt = typeBox->currentText(); | ||
if (lastFmt.isEmpty()) { | ||
lastFmt = "Font"; | ||
} | ||
typeBox->clear(); | ||
typeBox->addItem("Font"); | ||
typeBox->setCurrentIndex(typeBox->findText(lastFmt)); | ||
|
||
setRenderColor(this->renderColor); | ||
} | ||
|
||
void ImportDialog::setRenderColor(QColor color) | ||
{ | ||
QString styleSheet = QString(std::format("background: rgb({}, {}, {})", color.red(), color.green(), color.blue()).c_str()); | ||
ui->fontColorButton->setStyleSheet(styleSheet); | ||
this->renderColor = color; | ||
} | ||
|
||
QString ImportDialog::getFileFormatExtension() | ||
{ | ||
return "." + this->ui->typeComboBox->currentText().toLower(); | ||
} | ||
|
||
void ImportDialog::on_inputFileBrowseButton_clicked() | ||
{ | ||
QString selectedDirectory = QFileDialog::getOpenFileName( | ||
this, "Select Font File", QString(), "Fonts (*.ttf *.otf)"); | ||
|
||
if (selectedDirectory.isEmpty()) | ||
return; | ||
|
||
ui->inputFileEdit->setText(selectedDirectory); | ||
} | ||
|
||
void ImportDialog::on_fontSymbolsEdit_textChanged(const QString &text) | ||
{ | ||
bool ok = false; | ||
uint test = text.toUInt(&ok, 16); | ||
if (!ok) { | ||
ui->fontSymbolsRangeLabel->setText("Error"); | ||
return; | ||
} | ||
|
||
QString pad = text.toLower(); | ||
while (pad.size() < 2) | ||
pad = "0" + pad; | ||
|
||
QString start = "U+" + pad + "00"; | ||
QString end = "U+" + pad + "ff"; | ||
ui->fontSymbolsRangeLabel->setText(start + " - " + end); | ||
} | ||
|
||
void ImportDialog::on_fontColorButton_clicked() | ||
{ | ||
QColor color = QColorDialog::getColor(); | ||
setRenderColor(color); | ||
} | ||
|
||
void ImportDialog::on_importButton_clicked() | ||
{ | ||
if (ui->inputFileEdit->text() == "") { | ||
QMessageBox::warning(this, "Warning", "Input file is missing, please choose an input folder."); | ||
return; | ||
} | ||
|
||
try { | ||
MainWindow *mainWindow = dynamic_cast<MainWindow *>(this->parent()); | ||
if (mainWindow == nullptr) { | ||
QMessageBox::critical(this, "Error", "Window not found."); | ||
return; | ||
} | ||
|
||
QString filePath = ui->inputFileEdit->text(); | ||
int pointSize = ui->fontSizeEdit->text().toInt(); | ||
uint symbolPrefix = ui->fontSymbolsEdit->text().toUInt() << 8; | ||
mainWindow->openFontFile(filePath, this->renderColor, pointSize, symbolPrefix); | ||
} catch (...) { | ||
QMessageBox::critical(this, "Error", "Import Failed."); | ||
return; | ||
} | ||
|
||
this->close(); | ||
} | ||
|
||
void ImportDialog::on_importCancelButton_clicked() | ||
{ | ||
this->close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QProgressDialog> | ||
|
||
#include "d1formats/d1amp.h" | ||
#include "d1formats/d1gfx.h" | ||
#include "d1formats/d1min.h" | ||
#include "d1formats/d1sol.h" | ||
#include "d1formats/d1til.h" | ||
|
||
namespace Ui { | ||
class ImportDialog; | ||
} | ||
|
||
// subtiles per line if the output is groupped, an odd number to ensure it is not recognized as a flat tile | ||
#define EXPORT_SUBTILES_PER_LINE 15 | ||
|
||
// frames per line if the output of a tileset-frames is groupped, an odd number to ensure it is not recognized as a flat tile or as subtiles | ||
#define EXPORT_LVLFRAMES_PER_LINE 31 | ||
|
||
class ImportDialog : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ImportDialog(QWidget *parent = nullptr); | ||
~ImportDialog(); | ||
|
||
void initialize(); | ||
|
||
private slots: | ||
void on_inputFileBrowseButton_clicked(); | ||
void on_fontSymbolsEdit_textChanged(const QString &text); | ||
void on_fontColorButton_clicked(); | ||
void on_importButton_clicked(); | ||
void on_importCancelButton_clicked(); | ||
|
||
private: | ||
void setRenderColor(QColor color); | ||
QString getFileFormatExtension(); | ||
|
||
Ui::ImportDialog *ui; | ||
QColor renderColor = QColor::fromRgb(204, 183, 117); | ||
}; |
Oops, something went wrong.