Merge branch 'master' into master

This commit is contained in:
MrBlockCat 2020-03-16 16:22:45 -04:00 committed by GitHub
commit 11f04a37f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 334 deletions

View file

@ -1,273 +0,0 @@
#include "tgraphics.h"
extern "C" {
#include "Tw/Gf.h"
#include "tvis.h"
}
TGraphics::TGraphics(_TWIDGET *_gf, int ras_x0, int ras_y0, int ras_x1,
int ras_y1, int gf_x0, int gf_y0, int gf_x1, int gf_y1,
int zoom_level)
: gf(_gf)
, currentPoint(0, 0)
, gfRegion(gf_x0, gf_y0, gf_x1, gf_y1)
, rasterRegion(ras_x0 - 1, ras_y0 - 1, ras_x1 + 1, ras_y1 + 1)
//, rasterRegion(ras_x0,ras_y0,ras_x1,ras_y1)
, zoomFactor(1)
, pixelSize(1) {
double dx, dy;
int blx, bly;
if (zoom_level > 0)
zoomFactor = 1 << zoom_level;
else if (zoom_level < 0)
zoomFactor = 1.0 / (1 << -zoom_level);
pixelSize = 1.0 / zoomFactor;
blx = ras_x0 - gf_x0 / zoomFactor;
bly = ras_y0 - gf_y0 / zoomFactor;
dx = 0.5 - blx;
dy = 0.5 - bly;
GfPushMatrix(gf);
GfTranslate(gf, -0.5, -0.5);
GfScale(gf, zoomFactor, zoomFactor);
GfTranslate(gf, dx, dy);
}
//---------------------------------------------------
TGraphics::~TGraphics() { GfPopMatrix(gf); }
//---------------------------------------------------
void TGraphics::setColor(int r, int g, int b) {
_r = r;
_g = g;
_b = b;
GfCpack(gf, r, g, b);
}
//---------------------------------------------------
void TGraphics::drawLine(const TPointI &a, const TPointI &b) {
if (a.x < rasterRegion.x0 && b.x < rasterRegion.x0 ||
a.x > rasterRegion.x1 && b.x > rasterRegion.x1 ||
a.y < rasterRegion.y0 && b.y < rasterRegion.y0 ||
a.y > rasterRegion.y1 && b.y > rasterRegion.y1)
return;
int v[2];
GfBgnLine(gf);
v[0] = a.x;
v[1] = a.y;
GfV2i(gf, v);
v[0] = b.x;
v[1] = b.y;
GfV2i(gf, v);
GfEndLine(gf);
}
//---------------------------------------------------
void TGraphics::drawLine(const TPointD &a, const TPointD &b) {
if (a.x < rasterRegion.x0 && b.x < rasterRegion.x0 ||
a.x > rasterRegion.x1 && b.x > rasterRegion.x1 ||
a.y < rasterRegion.y0 && b.y < rasterRegion.y0 ||
a.y > rasterRegion.y1 && b.y > rasterRegion.y1)
return;
double v[2];
GfBgnLine(gf);
v[0] = a.x;
v[1] = a.y;
GfV2d(gf, v);
v[0] = b.x;
v[1] = b.y;
GfV2d(gf, v);
GfEndLine(gf);
}
//---------------------------------------------------
void TGraphics::beginPolygon() { GfBgnPolygon(gf); }
//---------------------------------------------------
void TGraphics::endPolygon() { GfEndPolygon(gf); }
//---------------------------------------------------
void TGraphics::beginLine() { GfBgnLine(gf); }
//---------------------------------------------------
void TGraphics::endLine() { GfEndLine(gf); }
//---------------------------------------------------
void TGraphics::vertex(const TPointI &a) {
int v[2];
v[0] = a.x;
v[1] = a.y;
GfV2i(gf, v);
}
//---------------------------------------------------
void TGraphics::vertex(const TPointD &a) {
double v[2];
v[0] = a.x;
v[1] = a.y;
GfV2d(gf, v);
}
//---------------------------------------------------
void TGraphics::drawRect(const TPointI &a, const TPointI &b) {
GfRecti(gf, a.x, a.y, b.x, b.y);
}
//---------------------------------------------------
void TGraphics::drawRect(const TPointD &a, const TPointD &b) {
GfRect(gf, a.x, a.y, b.x, b.y);
}
//---------------------------------------------------
void TGraphics::drawRect(const TRectI &rect) {
GfRecti(gf, rect.x0, rect.y0, rect.x1, rect.y1);
}
//---------------------------------------------------
void TGraphics::drawRect(const TRectD &rect) {
GfRect(gf, rect.x0, rect.y0, rect.x1, rect.y1);
}
//---------------------------------------------------
void TGraphics::drawArc(const TBezierArc &arc) {
int n = 50;
beginLine();
for (int i = 0; i <= n; i++) vertex(arc.getPoint((double)i / (double)n));
endLine();
}
//---------------------------------------------------
void TGraphics::drawArc(const TCubicCurve &arc) {
int n = 80;
beginLine();
for (int i = 0; i <= n; i++) vertex(arc.getPoint((double)i / (double)n));
endLine();
}
//---------------------------------------------------
void TGraphics::drawArcTo(const TPointD &d1, const TPointD &d2,
const TPointD &d3) {
TPointD oldPoint = currentPoint;
currentPoint += d1 + d2 + d3;
drawArc(
TBezierArc(oldPoint, oldPoint + d1, oldPoint + d1 + d2, currentPoint));
}
//---------------------------------------------------
void TGraphics::drawDiamond(const TPointD &p, double r) {
beginPolygon();
vertex(p + TPointD(r, 0));
vertex(p + TPointD(0, r));
vertex(p + TPointD(-r, 0));
vertex(p + TPointD(0, -r));
endPolygon();
}
//---------------------------------------------------
void TGraphics::drawCross(const TPointD &p, double r) {
drawLine(p - TPointD(r, r), p + TPointD(r, r));
drawLine(p - TPointD(-r, r), p + TPointD(-r, r));
}
//---------------------------------------------------
void TGraphics::drawSquare(const TPointD &p, double r) {
beginLine();
vertex(p + TPointD(-r, -r));
vertex(p + TPointD(-r, r));
vertex(p + TPointD(r, r));
vertex(p + TPointD(r, -r));
vertex(p + TPointD(-r, -r));
endLine();
}
//---------------------------------------------------
void TGraphics::drawArc(const TPointD &p0, const TPointD &p1,
const TPointD &p2) {
TRectD rect = convert(rasterRegion.enlarge(+10));
// TRectD rect(rasterRegion.x0, rasterRegion.y0, rasterRegion.x1,
// rasterRegion.y1);
TRectD bBox = boundingBox(p0, p1, p2);
if (!rect.overlaps(bBox)) {
/*
unsigned char tmp_r = _r;
unsigned char tmp_g = _g;
unsigned char tmp_b = _b;
setColor(100,100,100);
drawRect(bBox);
drawLine(TLineD(bBox.x0, bBox.y0, bBox.x1, bBox.y1));
drawLine(TLineD(bBox.x0, bBox.y1, bBox.x1, bBox.y0));
setColor(tmp_r, tmp_g, tmp_b);
*/
return;
}
double threshold = pixelSize * 0.125;
TPointD v = p2 - p0;
TPointD u = p1 - p0;
TPointD r = rotate90(v);
double sqr_tsh = (threshold * threshold) * (v * v);
double dist = r * u;
if ((dist * dist) > sqr_tsh) {
TPointD l1 = 0.5 * (p0 + p1);
TPointD r1 = 0.5 * (p1 + p2);
TPointD l2 = 0.5 * (l1 + r1);
drawArc(p0, l1, l2);
drawArc(l2, r1, p2);
} else {
beginLine();
vertex(p0);
vertex(p2);
endLine();
}
}
//---------------------------------------------------
void TGraphics::drawCircle(TPointD p, double radius) {
GfCirc(gf, p.x, p.y, radius);
}
//---------------------------------------------------
void TGraphics::fillCircle(TPointD p, double radius) {
GfCircf(gf, p.x, p.y, radius);
}
//---------------------------------------------------
void TGraphics::rectWrap(int wrap_pixels) { GfRectWrap(gf, wrap_pixels); }
//---------------------------------------------------
void TGraphics::rectWrite(int x0, int y0, int x1, int y1, void *buffer) {
GfRectWrite(gf, x0, y0, x1, y1, buffer);
}

View file

@ -17,6 +17,7 @@
#endif
#include <QString>
#include <QSet>
//=============================================================================
// forward declarations
@ -113,7 +114,7 @@ If scene is untitled update save path.
void updatePath(TFilePath &fp);
virtual bool isDirty() = 0;
virtual QString getResourceName() = 0;
virtual QStringList getResourceName() = 0;
};
//=============================================================================
@ -157,7 +158,7 @@ Set simple level path to old path.
}
bool isDirty() override;
QString getResourceName() override;
QStringList getResourceName() override;
};
//=============================================================================
@ -203,7 +204,7 @@ Set simple level path to old path.
}
bool isDirty() override;
QString getResourceName() override;
QStringList getResourceName() override;
};
//=============================================================================
@ -247,7 +248,7 @@ Set sound track path to old path.
}
bool isDirty() override { return false; }
QString getResourceName() override { return QString(); }
QStringList getResourceName() override { return QStringList(); }
};
//=============================================================================
@ -316,7 +317,7 @@ If doesn't make \b commit() destroyer calls \b rollbackPaths().
void accept(ResourceProcessor *processor, bool autoCommit = true);
// return the name list of dirty resources
void getDirtyResources(std::vector<QString> &dirtyResources);
void getDirtyResources(QStringList &dirtyResources);
private:
// not implemented

View file

@ -501,7 +501,7 @@ void ExportLevelPopup::checkAlpha() {
for (int i = 0; i < props->getPropertyCount(); ++i) {
TProperty *p = props->getProperty(i);
const QString &name = p->getQStringName();
const std::string &name = p->getName();
const QString &val = QString::fromStdString(p->getValueAsString());
if (name == "Bits Per Pixel") {

View file

@ -1202,21 +1202,29 @@ bool IoCmd::saveSceneIfNeeded(QString msg) {
ToonzScene *scene = app->getCurrentScene()->getScene();
if (scene) {
std::vector<QString> dirtyResources;
QStringList dirtyResources;
{
SceneResources resources(scene, 0);
resources.getDirtyResources(dirtyResources);
}
if (!dirtyResources.empty()) {
// show up to 5 items
int extraCount = dirtyResources.count() - 5;
if (extraCount > 0) {
dirtyResources = dirtyResources.mid(0, 5);
dirtyResources.append(
QObject::tr("and %1 more item(s).").arg(extraCount));
}
QString question;
question = msg + ":" +
QObject::tr(" The following file(s) have been modified.\n\n");
for (int i = 0; i < dirtyResources.size(); i++) {
question += " " + dirtyResources[i] + "\n";
}
question += QObject::tr("\nWhat would you like to do? ");
question += " " + dirtyResources.join("\n ");
question += "\n" + QObject::tr("\nWhat would you like to do? ");
int ret =
DVGui::MsgBox(question, QObject::tr("Save Changes"),

View file

@ -1494,10 +1494,6 @@ PencilTestPopup::PencilTestPopup()
m_subHeightFld = new IntLineEdit(this);
QWidget* subCamWidget = new QWidget(this);
#ifdef MACOSX
m_dummyViewFinder = new QCameraViewfinder(this);
m_dummyViewFinder->hide();
#endif
//----
m_resolutionCombo->setMaximumWidth(fontMetrics().width("0000 x 0000") + 25);
@ -1903,10 +1899,6 @@ void PencilTestPopup::onCameraListComboActivated(int comboIndex) {
m_currentCamera = new QCamera(cameras.at(index), this);
m_deviceName = cameras.at(index).deviceName();
#ifdef MACOSX
// this line is needed only in macosx
m_currentCamera->setViewfinder(m_dummyViewFinder);
#endif
// loading new camera
m_currentCamera->load();
@ -1952,22 +1944,22 @@ void PencilTestPopup::onResolutionComboActivated(const QString& itemText) {
// the splited text must be "<width>" "x" and "<height>"
if (texts.size() != 3) return;
#ifndef MACOSX
m_currentCamera->stop();
m_currentCamera->unload();
#endif
QCameraViewfinderSettings settings = m_currentCamera->viewfinderSettings();
QSize newResolution(texts[0].toInt(), texts[2].toInt());
settings.setResolution(newResolution);
m_currentCamera->setViewfinderSettings(settings);
#ifdef MACOSX
m_dummyViewFinder->resize(newResolution);
#endif
// reset white bg
m_whiteBGImg = QImage();
m_bgReductionFld->setDisabled(true);
#ifndef MACOSX
m_currentCamera->start();
#endif
m_videoWidget->setImage(QImage());
// update env
@ -2146,8 +2138,9 @@ void PencilTestPopup::onFrameCaptured(QImage& image) {
m_videoWidget->setImage(image.copy());
if (m_captureCue) {
#ifndef MACOSX
m_currentCamera->stop();
#endif
m_captureCue = false;
bool scanBtoT =
@ -2186,8 +2179,9 @@ void PencilTestPopup::onFrameCaptured(QImage& image) {
m_captureButton->setChecked(false);
onCaptureButtonClicked(false);
}
#ifndef MACOSX
m_currentCamera->start();
#endif
}
}

View file

@ -314,10 +314,6 @@ class PencilTestPopup : public DVGui::Dialog {
DVGui::IntLineEdit *m_subWidthFld, *m_subHeightFld;
QSize m_allowedCameraSize;
#ifdef MACOSX
QCameraViewfinder* m_dummyViewFinder;
#endif
bool m_captureWhiteBGCue;
bool m_captureCue;
bool m_alwaysOverwrite = false;

View file

@ -334,7 +334,8 @@ bool SceneLevel::isDirty() {
}
//-----------------------------------------------------------------------------
QString SceneLevel::getResourceName() {
QStringList SceneLevel::getResourceName() {
QStringList ret;
QString string;
bool levelIsDirty = false;
if (m_sl->getProperties()->getDirtyFlag()) {
@ -342,16 +343,23 @@ QString SceneLevel::getResourceName() {
levelIsDirty = true;
}
if (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()) {
QString paletteName =
QString::fromStdWString(m_sl->getPalette()->getPaletteName());
if (m_sl->getType() & FULLCOLOR_TYPE) {
if (levelIsDirty) ret << string;
ret << paletteName + ".tpl";
} else {
if (levelIsDirty) string += " and ";
if (m_sl->getPath().getType() == "pli")
string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) +
".pli (palette)";
string += paletteName + ".pli (palette)";
else
string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) +
".tpl";
string += paletteName + ".tpl";
ret << string;
}
} else if (levelIsDirty)
ret << string;
return string;
return ret;
}
//=============================================================================
@ -403,8 +411,8 @@ bool ScenePalette::isDirty() { return m_pl->getPalette()->getDirtyFlag(); }
//-----------------------------------------------------------------------------
QString ScenePalette::getResourceName() {
return QString::fromStdString(m_pl->getPath().getLevelName());
QStringList ScenePalette::getResourceName() {
return QStringList(QString::fromStdString(m_pl->getPath().getLevelName()));
}
//=============================================================================
@ -496,19 +504,24 @@ void SceneResources::save(const TFilePath newScenePath) {
TFilePath oldScenePath = m_scene->getScenePath();
m_scene->setScenePath(newScenePath);
bool failedSave = false;
QString failedList;
for (int i = 0; i < (int)m_resources.size(); i++) {
m_resources[i]->save();
if (m_resources[i]->isDirty()) // didn't save for some reason
{
failedList += "\n" + m_resources[i]->getResourceName();
failedSave = true;
}
}
if (failedSave)
QStringList failedList;
getDirtyResources(failedList);
if (!failedList.isEmpty()) { // didn't save for some reason
// show up to 5 items
int extraCount = failedList.count() - 5;
if (extraCount > 0) {
failedList = failedList.mid(0, 5);
failedList.append(QObject::tr("and %1 more item(s).").arg(extraCount));
}
DVGui::warning(QObject::tr("Failed to save the following resources:\n") +
failedList);
" " + failedList.join("\n "));
}
m_scene->setScenePath(oldScenePath);
}
@ -536,11 +549,12 @@ void SceneResources::accept(ResourceProcessor *processor, bool autoCommit) {
//-----------------------------------------------------------------------------
// return the name list of dirty resources
void SceneResources::getDirtyResources(std::vector<QString> &dirtyResources) {
for (int i = 0; i < (int)m_resources.size(); i++)
if (m_resources[i]->isDirty()) {
dirtyResources.push_back(m_resources[i]->getResourceName());
void SceneResources::getDirtyResources(QStringList &dirtyResources) {
for (SceneResource *resource : m_resources)
if (resource->isDirty()) {
dirtyResources << resource->getResourceName();
}
dirtyResources.removeDuplicates();
}
//=============================================================================

View file

@ -744,7 +744,13 @@ static void drawAutocloses(TVectorImage *vi, TVectorRenderData &rd) {
rd.m_palette = plt;
buildAutocloseImage(vaux, vi, startPoints, endPoints);
// temporarily disable fill check, to preserve the gap indicator color
bool tCheckEnabledOriginal = rd.m_tcheckEnabled;
rd.m_tcheckEnabled = false;
// draw
tglDraw(rd, vaux);
// restore original value
rd.m_tcheckEnabled = tCheckEnabledOriginal;
delete vaux;
}