From 24b42fb0e006192d07cbb67da39d16098d841ee7 Mon Sep 17 00:00:00 2001 From: jcbk101 Date: Wed, 14 Aug 2024 21:30:21 -0400 Subject: [PATCH 01/10] Per-object opacity initial push --- src/libtiled/mapobject.cpp | 11 +++++++++ src/libtiled/mapobject.h | 22 ++++++++++++++++++ src/libtiled/mapreader.cpp | 7 ++++++ src/libtiled/maprenderer.cpp | 4 +++- src/libtiled/maptovariantconverter.cpp | 4 ++++ src/libtiled/mapwriter.cpp | 5 +++++ src/libtiled/tilelayer.h | 5 +++++ src/libtiled/varianttomapconverter.cpp | 8 +++++++ src/plugins/lua/luaplugin.cpp | 2 ++ src/plugins/python/pythonbind.cpp | 31 ++++++++++++++++++++++++++ src/plugins/python/tiledbinding.py | 3 +++ src/tiled/editablemapobject.cpp | 6 +++++ src/tiled/editablemapobject.h | 12 ++++++++++ src/tiled/mapobjectitem.cpp | 2 ++ src/tiled/objectselectionitem.cpp | 2 ++ src/tiled/objectselectiontool.cpp | 4 +++- src/tiled/objectselectiontool.h | 2 ++ src/tiled/propertybrowser.cpp | 15 +++++++++++++ src/tmxviewer/tmxviewer.cpp | 2 ++ 19 files changed, 145 insertions(+), 2 deletions(-) diff --git a/src/libtiled/mapobject.cpp b/src/libtiled/mapobject.cpp index a517801a98..dfaf31e22e 100644 --- a/src/libtiled/mapobject.cpp +++ b/src/libtiled/mapobject.cpp @@ -312,6 +312,8 @@ QVariant MapObject::mapObjectProperty(Property property) const case PositionProperty: return mPos; case SizeProperty: return mSize; case RotationProperty: return mRotation; + // BONGO + case OpacityProperty: return mOpacity; case CellProperty: Q_ASSERT(false); break; case ShapeProperty: return mShape; case TemplateProperty: Q_ASSERT(false); break; @@ -334,6 +336,7 @@ void MapObject::setMapObjectProperty(Property property, const QVariant &value) case PositionProperty: setPosition(value.toPointF()); break; case SizeProperty: setSize(value.toSizeF()); break; case RotationProperty: setRotation(value.toReal()); break; + case OpacityProperty: setOpacity(value.toReal()); break; case CellProperty: Q_ASSERT(false); break; case ShapeProperty: setShape(value.value()); break; case TemplateProperty: Q_ASSERT(false); break; @@ -374,6 +377,8 @@ MapObject *MapObject::clone() const o->setShape(mShape); o->setCell(mCell); o->setRotation(mRotation); + // BONGO + o->setOpacity(mOpacity); o->setVisible(mVisible); o->setChangedProperties(mChangedProperties); o->setObjectTemplate(mObjectTemplate); @@ -389,6 +394,8 @@ void MapObject::copyPropertiesFrom(const MapObject *object) setShape(object->shape()); setCell(object->cell()); setRotation(object->rotation()); + // BONGO + setOpacity(object->opacity()); setVisible(object->isVisible()); setProperties(object->properties()); setChangedProperties(object->changedProperties()); @@ -428,6 +435,10 @@ void MapObject::syncWithTemplate() if (!propertyChanged(MapObject::RotationProperty)) setRotation(base->rotation()); + // BONGO + if (!propertyChanged(MapObject::OpacityProperty)) + setOpacity(base->opacity()); + if (!propertyChanged(MapObject::VisibleProperty)) setVisible(base->isVisible()); } diff --git a/src/libtiled/mapobject.h b/src/libtiled/mapobject.h index 4e8ae8ab27..54a1c39faa 100644 --- a/src/libtiled/mapobject.h +++ b/src/libtiled/mapobject.h @@ -121,6 +121,8 @@ class TILEDSHARED_EXPORT MapObject : public Object ShapeProperty = 1 << 11, TemplateProperty = 1 << 12, CustomProperties = 1 << 13, + // BONGO + OpacityProperty = 1 << 14, AllProperties = 0xFF }; @@ -200,6 +202,10 @@ class TILEDSHARED_EXPORT MapObject : public Object qreal rotation() const; void setRotation(qreal rotation); + // BONGO + qreal opacity() const; + void setOpacity(qreal opacity); + Alignment alignment(const Map *map = nullptr) const; bool isVisible() const; @@ -247,6 +253,8 @@ class TILEDSHARED_EXPORT MapObject : public Object const ObjectTemplate *mObjectTemplate = nullptr; ObjectGroup *mObjectGroup = nullptr; qreal mRotation = 0.0; + // BONGO + qreal mOpacity = 1.0; bool mVisible = true; bool mTemplateBase = false; ChangedProperties mChangedProperties; @@ -479,6 +487,20 @@ inline qreal MapObject::rotation() const inline void MapObject::setRotation(qreal rotation) { mRotation = rotation; } +/** + * BONGO: Add Opacity for objects + * returns current opacity +*/ +inline qreal MapObject::opacity() const +{ return mOpacity; } + +/** + * BONGO: Add Opacity for objects + * sets new opacity +*/ +inline void MapObject::setOpacity(qreal opacity) +{ mOpacity = opacity; } + inline bool MapObject::isVisible() const { return mVisible; } diff --git a/src/libtiled/mapreader.cpp b/src/libtiled/mapreader.cpp index 820eed8b43..06b8f9e9b6 100644 --- a/src/libtiled/mapreader.cpp +++ b/src/libtiled/mapreader.cpp @@ -1222,6 +1222,13 @@ std::unique_ptr MapReaderPrivate::readObject() object->setPropertyChanged(MapObject::RotationProperty); } + // BONGO + const qreal opacity = atts.value(QLatin1String("opacity")).toDouble(&ok); + if (ok) { + object->setOpacity(opacity); + object->setPropertyChanged(MapObject::OpacityProperty); + } + if (gid) { object->setCell(cellForGid(gid)); object->setPropertyChanged(MapObject::CellProperty); diff --git a/src/libtiled/maprenderer.cpp b/src/libtiled/maprenderer.cpp index acfa47e284..50e510da40 100644 --- a/src/libtiled/maprenderer.cpp +++ b/src/libtiled/maprenderer.cpp @@ -452,7 +452,9 @@ void CellRenderer::render(const Cell &cell, const QPointF &screenPos, const QSiz fragment.scaleX = size.width() / imageRect.width(); fragment.scaleY = size.height() / imageRect.height(); fragment.rotation = 0; - fragment.opacity = 1; +// fragment.opacity = 1; + // BONGO + fragment.opacity = cell.getOpacity(); const auto fillMode = tile->tileset()->fillMode(); if (fillMode == Tileset::PreserveAspectFit) { diff --git a/src/libtiled/maptovariantconverter.cpp b/src/libtiled/maptovariantconverter.cpp index 93e7fb882f..0ef41d65b1 100644 --- a/src/libtiled/maptovariantconverter.cpp +++ b/src/libtiled/maptovariantconverter.cpp @@ -586,6 +586,10 @@ QVariant MapToVariantConverter::toVariant(const MapObject &object) const if (notTemplateInstance || object.propertyChanged(MapObject::RotationProperty)) objectVariant[QStringLiteral("rotation")] = object.rotation(); + // BONGO + if (notTemplateInstance || object.propertyChanged(MapObject::OpacityProperty)) + objectVariant[QStringLiteral("opacity")] = object.opacity(); + if (notTemplateInstance || object.propertyChanged(MapObject::VisibleProperty)) objectVariant[QStringLiteral("visible")] = object.isVisible(); diff --git a/src/libtiled/mapwriter.cpp b/src/libtiled/mapwriter.cpp index d6c4f3265d..f4bd3be6b0 100644 --- a/src/libtiled/mapwriter.cpp +++ b/src/libtiled/mapwriter.cpp @@ -756,6 +756,11 @@ void MapWriterPrivate::writeObject(QXmlStreamWriter &w, if (shouldWrite(rotation != 0.0, isTemplateInstance, mapObject.propertyChanged(MapObject::RotationProperty))) w.writeAttribute(QStringLiteral("rotation"), QString::number(rotation)); + // BONGO + const qreal opacity = mapObject.opacity(); + if (shouldWrite(opacity != 1.0, isTemplateInstance, mapObject.propertyChanged(MapObject::OpacityProperty))) + w.writeAttribute(QStringLiteral("opacity"), QString::number(opacity)); + if (shouldWrite(!mapObject.isVisible(), isTemplateInstance, mapObject.propertyChanged(MapObject::VisibleProperty))) w.writeAttribute(QStringLiteral("visible"), QLatin1String(mapObject.isVisible() ? "1" : "0")); diff --git a/src/libtiled/tilelayer.h b/src/libtiled/tilelayer.h index e38aa40c4b..4fe1a6b625 100644 --- a/src/libtiled/tilelayer.h +++ b/src/libtiled/tilelayer.h @@ -123,6 +123,9 @@ class TILEDSHARED_EXPORT Cell void setRotatedHexagonal120(bool v) { v ? _flags |= RotatedHexagonal120 : _flags &= ~RotatedHexagonal120; } void rotate(RotateDirection direction); + // BONGO + float getOpacity() const { return _opacity; } + void setOpacity(float mOpacity) { _opacity = mOpacity; } bool checked() const { return _flags & Checked; } void setChecked(bool checked) { checked ? _flags |= Checked : _flags &= ~Checked; } @@ -138,6 +141,8 @@ class TILEDSHARED_EXPORT Cell Tileset *_tileset = nullptr; int _tileId = -1; int _flags = 0; + //BONGO + float _opacity = 1.0; }; inline Tile *Cell::tile() const diff --git a/src/libtiled/varianttomapconverter.cpp b/src/libtiled/varianttomapconverter.cpp index 2c2b9bf3b5..7db16731f2 100644 --- a/src/libtiled/varianttomapconverter.cpp +++ b/src/libtiled/varianttomapconverter.cpp @@ -722,6 +722,8 @@ std::unique_ptr VariantToMapConverter::toMapObject(const QVariantMap const qreal width = variantMap[QStringLiteral("width")].toReal(); const qreal height = variantMap[QStringLiteral("height")].toReal(); const qreal rotation = variantMap[QStringLiteral("rotation")].toReal(); + // BONGO + const qreal opacity = variantMap[QStringLiteral("opacity")].toReal(); QString className = variantMap[QStringLiteral("class")].toString(); if (className.isEmpty()) // fallback for compatibility @@ -738,6 +740,12 @@ std::unique_ptr VariantToMapConverter::toMapObject(const QVariantMap object->setPropertyChanged(MapObject::RotationProperty); } + // BONGO + if (variantMap.contains(QLatin1String("opacity"))) { + object->setOpacity(opacity); + object->setPropertyChanged(MapObject::OpacityProperty); + } + if (!templateVariant.isNull()) { // This object is a template instance QString templateFileName = resolvePath(mDir, templateVariant); auto objectTemplate = TemplateManager::instance()->loadObjectTemplate(templateFileName); diff --git a/src/plugins/lua/luaplugin.cpp b/src/plugins/lua/luaplugin.cpp index e8d53b2d37..de9bbae3d2 100644 --- a/src/plugins/lua/luaplugin.cpp +++ b/src/plugins/lua/luaplugin.cpp @@ -730,6 +730,8 @@ void LuaWriter::writeMapObject(const Tiled::MapObject *mapObject) mWriter.writeKeyAndValue("width", mapObject->width()); mWriter.writeKeyAndValue("height", mapObject->height()); mWriter.writeKeyAndValue("rotation", mapObject->rotation()); + // BONGO + mWriter.writeKeyAndValue("opacity", mapObject->opacity()); if (!mapObject->cell().isEmpty()) mWriter.writeKeyAndValue("gid", mGidMapper.cellToGid(mapObject->cell())); diff --git a/src/plugins/python/pythonbind.cpp b/src/plugins/python/pythonbind.cpp index 18d5f5cb3d..8cf1e2a32c 100644 --- a/src/plugins/python/pythonbind.cpp +++ b/src/plugins/python/pythonbind.cpp @@ -6996,6 +6996,17 @@ _wrap_PyTiledMapObject_rotation(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUS return py_retval; } +/* BONGO */ +PyObject * +_wrap_PyTiledMapObject_opacity(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUSED(_args), PyObject *PYBINDGEN_UNUSED(_kwargs)) +{ + PyObject *py_retval; + double retval; + + retval = self->obj->opacity(); + py_retval = Py_BuildValue((char *) "d", retval); + return py_retval; +} PyObject * _wrap_PyTiledMapObject_setCell(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) @@ -7082,6 +7093,22 @@ _wrap_PyTiledMapObject_setRotation(PyTiledMapObject *self, PyObject *args, PyObj return py_retval; } +/* BONGO */ +PyObject * +_wrap_PyTiledMapObject_setOpacity(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *py_retval; + double r; + const char *keywords[] = {"r", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "d", (char **) keywords, &r)) { + return NULL; + } + self->obj->setOpacity(r); + Py_INCREF(Py_None); + py_retval = Py_None; + return py_retval; +} PyObject * _wrap_PyTiledMapObject_setShape(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) @@ -7272,11 +7299,15 @@ static PyMethodDef PyTiledMapObject_methods[] = { {(char *) "name", (PyCFunction) _wrap_PyTiledMapObject_name, METH_NOARGS, "name()\n\n" }, {(char *) "objectGroup", (PyCFunction) _wrap_PyTiledMapObject_objectGroup, METH_NOARGS, "objectGroup()\n\n" }, {(char *) "rotation", (PyCFunction) _wrap_PyTiledMapObject_rotation, METH_NOARGS, "rotation()\n\n" }, + /* BONGO */ + {(char *) "opacity", (PyCFunction) _wrap_PyTiledMapObject_opacity, METH_NOARGS, "opacity()\n\n" }, {(char *) "setCell", (PyCFunction) _wrap_PyTiledMapObject_setCell, METH_KEYWORDS|METH_VARARGS, "setCell(c)\n\ntype: c: Tiled::Cell const" }, {(char *) "setHeight", (PyCFunction) _wrap_PyTiledMapObject_setHeight, METH_KEYWORDS|METH_VARARGS, "setHeight(h)\n\ntype: h: double" }, {(char *) "setName", (PyCFunction) _wrap_PyTiledMapObject_setName, METH_KEYWORDS|METH_VARARGS, "setName(n)\n\ntype: n: QString" }, {(char *) "setPosition", (PyCFunction) _wrap_PyTiledMapObject_setPosition, METH_KEYWORDS|METH_VARARGS, "setPosition(pos)\n\ntype: pos: QPointF" }, {(char *) "setRotation", (PyCFunction) _wrap_PyTiledMapObject_setRotation, METH_KEYWORDS|METH_VARARGS, "setRotation(r)\n\ntype: r: double" }, + /* BONGO */ + {(char *) "setOpacity", (PyCFunction) _wrap_PyTiledMapObject_setOpacity, METH_KEYWORDS|METH_VARARGS, "setOpacity(r)\n\ntype: r: double" }, {(char *) "setShape", (PyCFunction) _wrap_PyTiledMapObject_setShape, METH_KEYWORDS|METH_VARARGS, "setShape(s)\n\ntype: s: Tiled::MapObject::Shape" }, {(char *) "setSize", (PyCFunction) _wrap_PyTiledMapObject_setSize, METH_KEYWORDS|METH_VARARGS, "setSize(size)\n\ntype: size: QSizeF" }, {(char *) "setType", (PyCFunction) _wrap_PyTiledMapObject_setType, METH_KEYWORDS|METH_VARARGS, "setType(n)\n\ntype: n: QString" }, diff --git a/src/plugins/python/tiledbinding.py b/src/plugins/python/tiledbinding.py index 2901f270aa..30db3fb834 100755 --- a/src/plugins/python/tiledbinding.py +++ b/src/plugins/python/tiledbinding.py @@ -280,6 +280,9 @@ def _decorate(obj, *args, **kwargs): cls_mapobject.add_method('objectGroup', retval('Tiled::ObjectGroup*',reference_existing_object=True), []) cls_mapobject.add_method('rotation', 'double', []) cls_mapobject.add_method('setRotation', None, [('double','r')]) +# BONGO +cls_mapobject.add_method('opacity', 'double', []) +cls_mapobject.add_method('setOpacity', None, [('double','opacity')]) cls_mapobject.add_method('isVisible', 'bool', []) cls_mapobject.add_method('setVisible', None, [('bool','v')]) cls_mapobject.add_method('name', 'QString', []) diff --git a/src/tiled/editablemapobject.cpp b/src/tiled/editablemapobject.cpp index 23e67ec53f..4a931a0fcf 100644 --- a/src/tiled/editablemapobject.cpp +++ b/src/tiled/editablemapobject.cpp @@ -190,6 +190,12 @@ void EditableMapObject::setRotation(qreal rotation) setMapObjectProperty(MapObject::RotationProperty, rotation); } +// BONGO +void EditableMapObject::setOpacity(qreal opacity) +{ + setMapObjectProperty(MapObject::OpacityProperty, opacity); +} + void EditableMapObject::setVisible(bool visible) { setMapObjectProperty(MapObject::VisibleProperty, visible); diff --git a/src/tiled/editablemapobject.h b/src/tiled/editablemapobject.h index a43b971f1f..080ad1ee46 100644 --- a/src/tiled/editablemapobject.h +++ b/src/tiled/editablemapobject.h @@ -63,6 +63,8 @@ class EditableMapObject : public EditableObject Q_PROPERTY(qreal height READ height WRITE setHeight) Q_PROPERTY(QSizeF size READ size WRITE setSize) Q_PROPERTY(qreal rotation READ rotation WRITE setRotation) + // BONGO + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) Q_PROPERTY(bool visible READ isVisible WRITE setVisible) Q_PROPERTY(QJSValue polygon READ polygon WRITE setPolygon) Q_PROPERTY(QString text READ text WRITE setText) @@ -114,6 +116,8 @@ class EditableMapObject : public EditableObject qreal height() const; QSizeF size() const; qreal rotation() const; + // BONGO + qreal opacity() const; bool isVisible() const; QJSValue polygon() const; QString text() const; @@ -149,6 +153,8 @@ public slots: void setHeight(qreal height); void setSize(QSizeF size); void setRotation(qreal rotation); + // BONGO + void setOpacity(qreal opacity); void setVisible(bool visible); void setPolygon(QJSValue polygon); void setPolygon(const QPolygonF &polygon); @@ -219,6 +225,12 @@ inline qreal EditableMapObject::rotation() const return mapObject()->rotation(); } +// BONGO +inline qreal EditableMapObject::opacity() const +{ + return mapObject()->opacity(); +} + inline bool EditableMapObject::isVisible() const { return mapObject()->isVisible(); diff --git a/src/tiled/mapobjectitem.cpp b/src/tiled/mapobjectitem.cpp index 70c679fecb..173fb4e293 100644 --- a/src/tiled/mapobjectitem.cpp +++ b/src/tiled/mapobjectitem.cpp @@ -89,6 +89,8 @@ void MapObjectItem::syncWithMapObject() setPos(pixelPos); setRotation(mObject->rotation()); + // BONGO + setOpacity(mObject->opacity()); if (mBoundingRect != bounds) { // Notify the graphics scene about the geometry change in advance diff --git a/src/tiled/objectselectionitem.cpp b/src/tiled/objectselectionitem.cpp index 572e6650d2..1cfeeafe57 100644 --- a/src/tiled/objectselectionitem.cpp +++ b/src/tiled/objectselectionitem.cpp @@ -110,6 +110,8 @@ void MapObjectOutline::syncWithMapObject(const MapRenderer &renderer) setPos(pixelPos); setRotation(mObject->rotation()); + // BONGO + setOpacity(mObject->opacity()); setFlag(QGraphicsItem::ItemIgnoresTransformations, mObject->shape() == MapObject::Point); diff --git a/src/tiled/objectselectiontool.cpp b/src/tiled/objectselectiontool.cpp index 758eb7a113..a778639a30 100644 --- a/src/tiled/objectselectiontool.cpp +++ b/src/tiled/objectselectiontool.cpp @@ -1657,7 +1657,9 @@ void ObjectSelectionTool::saveSelectionState() mapObject->position(), mapObject->size(), mapObject->polygon(), - mapObject->rotation() + mapObject->rotation(), + // BONGO + mapObject->opacity() }; mMovingObjects.append(object); } diff --git a/src/tiled/objectselectiontool.h b/src/tiled/objectselectiontool.h index 6b01a4b66a..4cd9e739c6 100644 --- a/src/tiled/objectselectiontool.h +++ b/src/tiled/objectselectiontool.h @@ -167,6 +167,8 @@ class ObjectSelectionTool : public AbstractObjectTool QSizeF oldSize; QPolygonF oldPolygon; qreal oldRotation; + // BONGO + qreal oldOpacity; }; QVector mMovingObjects; diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 511a33eee1..4fa085faa7 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -845,6 +845,12 @@ void PropertyBrowser::addMapObjectProperties() tr("Flipping"), groupProperty); flippingProperty->setAttribute(QLatin1String("flagNames"), mFlippingFlagNames); + + // BONGO + QtVariantProperty *opacityProperty = addProperty(OpacityProperty, QMetaType::Double, tr("Opacity"), groupProperty); + opacityProperty->setAttribute(QLatin1String("minimum"), 0.0); + opacityProperty->setAttribute(QLatin1String("maximum"), 1.0); + opacityProperty->setAttribute(QLatin1String("singleStep"), 0.1); } if (mMapObjectFlags & ObjectIsText) { @@ -1296,6 +1302,13 @@ QUndoCommand *PropertyBrowser::applyMapObjectValueTo(PropertyId id, const QVaria val.toDouble()); } break; + // BONGO + case OpacityProperty:{ + command = new ChangeMapObject(mDocument, mapObject, + MapObject::OpacityProperty, + val.toReal()); + break; + } case FlippingProperty: { const int flippingFlags = val.toInt(); @@ -1913,6 +1926,8 @@ void PropertyBrowser::updateProperties() if (mapObject->cell().flippedVertically()) flippingFlags |= 2; mIdToProperty[FlippingProperty]->setValue(flippingFlags); + // BONGO + mIdToProperty[OpacityProperty]->setValue(mapObject->opacity()); } if (flags & ObjectIsText) { diff --git a/src/tmxviewer/tmxviewer.cpp b/src/tmxviewer/tmxviewer.cpp index e00ea748ef..52065f6427 100644 --- a/src/tmxviewer/tmxviewer.cpp +++ b/src/tmxviewer/tmxviewer.cpp @@ -65,6 +65,8 @@ class MapObjectItem : public QGraphicsItem setPos(pixelPos); setRotation(mapObject->rotation()); + // BONGO + setOpacity(mapObject->opacity()); } QRectF boundingRect() const override From 1897839c58c398d79c524350a7071f58ec3e5a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:02:20 +0200 Subject: [PATCH 02/10] Removed // BONGO Commit history can be used to see who changed what. :-) --- src/libtiled/mapobject.cpp | 4 ---- src/libtiled/mapobject.h | 3 --- src/libtiled/mapreader.cpp | 1 - src/libtiled/maprenderer.cpp | 2 -- src/libtiled/maptovariantconverter.cpp | 1 - src/libtiled/mapwriter.cpp | 1 - src/libtiled/tilelayer.h | 2 +- src/libtiled/varianttomapconverter.cpp | 2 -- src/plugins/lua/luaplugin.cpp | 1 - src/tiled/editablemapobject.cpp | 1 - src/tiled/editablemapobject.h | 4 ---- src/tiled/mapobjectitem.cpp | 1 - src/tiled/objectselectionitem.cpp | 1 - src/tiled/objectselectiontool.cpp | 1 - src/tiled/objectselectiontool.h | 1 - src/tiled/propertybrowser.cpp | 3 --- src/tmxviewer/tmxviewer.cpp | 1 - 17 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/libtiled/mapobject.cpp b/src/libtiled/mapobject.cpp index dfaf31e22e..58595702eb 100644 --- a/src/libtiled/mapobject.cpp +++ b/src/libtiled/mapobject.cpp @@ -312,7 +312,6 @@ QVariant MapObject::mapObjectProperty(Property property) const case PositionProperty: return mPos; case SizeProperty: return mSize; case RotationProperty: return mRotation; - // BONGO case OpacityProperty: return mOpacity; case CellProperty: Q_ASSERT(false); break; case ShapeProperty: return mShape; @@ -377,7 +376,6 @@ MapObject *MapObject::clone() const o->setShape(mShape); o->setCell(mCell); o->setRotation(mRotation); - // BONGO o->setOpacity(mOpacity); o->setVisible(mVisible); o->setChangedProperties(mChangedProperties); @@ -394,7 +392,6 @@ void MapObject::copyPropertiesFrom(const MapObject *object) setShape(object->shape()); setCell(object->cell()); setRotation(object->rotation()); - // BONGO setOpacity(object->opacity()); setVisible(object->isVisible()); setProperties(object->properties()); @@ -435,7 +432,6 @@ void MapObject::syncWithTemplate() if (!propertyChanged(MapObject::RotationProperty)) setRotation(base->rotation()); - // BONGO if (!propertyChanged(MapObject::OpacityProperty)) setOpacity(base->opacity()); diff --git a/src/libtiled/mapobject.h b/src/libtiled/mapobject.h index 54a1c39faa..2ee6c4285e 100644 --- a/src/libtiled/mapobject.h +++ b/src/libtiled/mapobject.h @@ -121,7 +121,6 @@ class TILEDSHARED_EXPORT MapObject : public Object ShapeProperty = 1 << 11, TemplateProperty = 1 << 12, CustomProperties = 1 << 13, - // BONGO OpacityProperty = 1 << 14, AllProperties = 0xFF }; @@ -202,7 +201,6 @@ class TILEDSHARED_EXPORT MapObject : public Object qreal rotation() const; void setRotation(qreal rotation); - // BONGO qreal opacity() const; void setOpacity(qreal opacity); @@ -253,7 +251,6 @@ class TILEDSHARED_EXPORT MapObject : public Object const ObjectTemplate *mObjectTemplate = nullptr; ObjectGroup *mObjectGroup = nullptr; qreal mRotation = 0.0; - // BONGO qreal mOpacity = 1.0; bool mVisible = true; bool mTemplateBase = false; diff --git a/src/libtiled/mapreader.cpp b/src/libtiled/mapreader.cpp index 06b8f9e9b6..c5454cc11b 100644 --- a/src/libtiled/mapreader.cpp +++ b/src/libtiled/mapreader.cpp @@ -1222,7 +1222,6 @@ std::unique_ptr MapReaderPrivate::readObject() object->setPropertyChanged(MapObject::RotationProperty); } - // BONGO const qreal opacity = atts.value(QLatin1String("opacity")).toDouble(&ok); if (ok) { object->setOpacity(opacity); diff --git a/src/libtiled/maprenderer.cpp b/src/libtiled/maprenderer.cpp index 50e510da40..68be73d119 100644 --- a/src/libtiled/maprenderer.cpp +++ b/src/libtiled/maprenderer.cpp @@ -452,8 +452,6 @@ void CellRenderer::render(const Cell &cell, const QPointF &screenPos, const QSiz fragment.scaleX = size.width() / imageRect.width(); fragment.scaleY = size.height() / imageRect.height(); fragment.rotation = 0; -// fragment.opacity = 1; - // BONGO fragment.opacity = cell.getOpacity(); const auto fillMode = tile->tileset()->fillMode(); diff --git a/src/libtiled/maptovariantconverter.cpp b/src/libtiled/maptovariantconverter.cpp index 0ef41d65b1..32cde229b4 100644 --- a/src/libtiled/maptovariantconverter.cpp +++ b/src/libtiled/maptovariantconverter.cpp @@ -586,7 +586,6 @@ QVariant MapToVariantConverter::toVariant(const MapObject &object) const if (notTemplateInstance || object.propertyChanged(MapObject::RotationProperty)) objectVariant[QStringLiteral("rotation")] = object.rotation(); - // BONGO if (notTemplateInstance || object.propertyChanged(MapObject::OpacityProperty)) objectVariant[QStringLiteral("opacity")] = object.opacity(); diff --git a/src/libtiled/mapwriter.cpp b/src/libtiled/mapwriter.cpp index f4bd3be6b0..265d708c13 100644 --- a/src/libtiled/mapwriter.cpp +++ b/src/libtiled/mapwriter.cpp @@ -756,7 +756,6 @@ void MapWriterPrivate::writeObject(QXmlStreamWriter &w, if (shouldWrite(rotation != 0.0, isTemplateInstance, mapObject.propertyChanged(MapObject::RotationProperty))) w.writeAttribute(QStringLiteral("rotation"), QString::number(rotation)); - // BONGO const qreal opacity = mapObject.opacity(); if (shouldWrite(opacity != 1.0, isTemplateInstance, mapObject.propertyChanged(MapObject::OpacityProperty))) w.writeAttribute(QStringLiteral("opacity"), QString::number(opacity)); diff --git a/src/libtiled/tilelayer.h b/src/libtiled/tilelayer.h index 4fe1a6b625..7f07ab0fb3 100644 --- a/src/libtiled/tilelayer.h +++ b/src/libtiled/tilelayer.h @@ -123,7 +123,7 @@ class TILEDSHARED_EXPORT Cell void setRotatedHexagonal120(bool v) { v ? _flags |= RotatedHexagonal120 : _flags &= ~RotatedHexagonal120; } void rotate(RotateDirection direction); - // BONGO + float getOpacity() const { return _opacity; } void setOpacity(float mOpacity) { _opacity = mOpacity; } diff --git a/src/libtiled/varianttomapconverter.cpp b/src/libtiled/varianttomapconverter.cpp index 7db16731f2..fdb5a2c75a 100644 --- a/src/libtiled/varianttomapconverter.cpp +++ b/src/libtiled/varianttomapconverter.cpp @@ -722,7 +722,6 @@ std::unique_ptr VariantToMapConverter::toMapObject(const QVariantMap const qreal width = variantMap[QStringLiteral("width")].toReal(); const qreal height = variantMap[QStringLiteral("height")].toReal(); const qreal rotation = variantMap[QStringLiteral("rotation")].toReal(); - // BONGO const qreal opacity = variantMap[QStringLiteral("opacity")].toReal(); QString className = variantMap[QStringLiteral("class")].toString(); @@ -740,7 +739,6 @@ std::unique_ptr VariantToMapConverter::toMapObject(const QVariantMap object->setPropertyChanged(MapObject::RotationProperty); } - // BONGO if (variantMap.contains(QLatin1String("opacity"))) { object->setOpacity(opacity); object->setPropertyChanged(MapObject::OpacityProperty); diff --git a/src/plugins/lua/luaplugin.cpp b/src/plugins/lua/luaplugin.cpp index de9bbae3d2..36493cc773 100644 --- a/src/plugins/lua/luaplugin.cpp +++ b/src/plugins/lua/luaplugin.cpp @@ -730,7 +730,6 @@ void LuaWriter::writeMapObject(const Tiled::MapObject *mapObject) mWriter.writeKeyAndValue("width", mapObject->width()); mWriter.writeKeyAndValue("height", mapObject->height()); mWriter.writeKeyAndValue("rotation", mapObject->rotation()); - // BONGO mWriter.writeKeyAndValue("opacity", mapObject->opacity()); if (!mapObject->cell().isEmpty()) diff --git a/src/tiled/editablemapobject.cpp b/src/tiled/editablemapobject.cpp index 4a931a0fcf..537432176f 100644 --- a/src/tiled/editablemapobject.cpp +++ b/src/tiled/editablemapobject.cpp @@ -190,7 +190,6 @@ void EditableMapObject::setRotation(qreal rotation) setMapObjectProperty(MapObject::RotationProperty, rotation); } -// BONGO void EditableMapObject::setOpacity(qreal opacity) { setMapObjectProperty(MapObject::OpacityProperty, opacity); diff --git a/src/tiled/editablemapobject.h b/src/tiled/editablemapobject.h index 080ad1ee46..68c2e5a302 100644 --- a/src/tiled/editablemapobject.h +++ b/src/tiled/editablemapobject.h @@ -63,7 +63,6 @@ class EditableMapObject : public EditableObject Q_PROPERTY(qreal height READ height WRITE setHeight) Q_PROPERTY(QSizeF size READ size WRITE setSize) Q_PROPERTY(qreal rotation READ rotation WRITE setRotation) - // BONGO Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) Q_PROPERTY(bool visible READ isVisible WRITE setVisible) Q_PROPERTY(QJSValue polygon READ polygon WRITE setPolygon) @@ -116,7 +115,6 @@ class EditableMapObject : public EditableObject qreal height() const; QSizeF size() const; qreal rotation() const; - // BONGO qreal opacity() const; bool isVisible() const; QJSValue polygon() const; @@ -153,7 +151,6 @@ public slots: void setHeight(qreal height); void setSize(QSizeF size); void setRotation(qreal rotation); - // BONGO void setOpacity(qreal opacity); void setVisible(bool visible); void setPolygon(QJSValue polygon); @@ -225,7 +222,6 @@ inline qreal EditableMapObject::rotation() const return mapObject()->rotation(); } -// BONGO inline qreal EditableMapObject::opacity() const { return mapObject()->opacity(); diff --git a/src/tiled/mapobjectitem.cpp b/src/tiled/mapobjectitem.cpp index 173fb4e293..f44a1e6352 100644 --- a/src/tiled/mapobjectitem.cpp +++ b/src/tiled/mapobjectitem.cpp @@ -89,7 +89,6 @@ void MapObjectItem::syncWithMapObject() setPos(pixelPos); setRotation(mObject->rotation()); - // BONGO setOpacity(mObject->opacity()); if (mBoundingRect != bounds) { diff --git a/src/tiled/objectselectionitem.cpp b/src/tiled/objectselectionitem.cpp index 1cfeeafe57..99166ba2c9 100644 --- a/src/tiled/objectselectionitem.cpp +++ b/src/tiled/objectselectionitem.cpp @@ -110,7 +110,6 @@ void MapObjectOutline::syncWithMapObject(const MapRenderer &renderer) setPos(pixelPos); setRotation(mObject->rotation()); - // BONGO setOpacity(mObject->opacity()); setFlag(QGraphicsItem::ItemIgnoresTransformations, mObject->shape() == MapObject::Point); diff --git a/src/tiled/objectselectiontool.cpp b/src/tiled/objectselectiontool.cpp index a778639a30..9f355d0c9a 100644 --- a/src/tiled/objectselectiontool.cpp +++ b/src/tiled/objectselectiontool.cpp @@ -1658,7 +1658,6 @@ void ObjectSelectionTool::saveSelectionState() mapObject->size(), mapObject->polygon(), mapObject->rotation(), - // BONGO mapObject->opacity() }; mMovingObjects.append(object); diff --git a/src/tiled/objectselectiontool.h b/src/tiled/objectselectiontool.h index 4cd9e739c6..c9bf4c2925 100644 --- a/src/tiled/objectselectiontool.h +++ b/src/tiled/objectselectiontool.h @@ -167,7 +167,6 @@ class ObjectSelectionTool : public AbstractObjectTool QSizeF oldSize; QPolygonF oldPolygon; qreal oldRotation; - // BONGO qreal oldOpacity; }; diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 4fa085faa7..5e410f149b 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -846,7 +846,6 @@ void PropertyBrowser::addMapObjectProperties() flippingProperty->setAttribute(QLatin1String("flagNames"), mFlippingFlagNames); - // BONGO QtVariantProperty *opacityProperty = addProperty(OpacityProperty, QMetaType::Double, tr("Opacity"), groupProperty); opacityProperty->setAttribute(QLatin1String("minimum"), 0.0); opacityProperty->setAttribute(QLatin1String("maximum"), 1.0); @@ -1302,7 +1301,6 @@ QUndoCommand *PropertyBrowser::applyMapObjectValueTo(PropertyId id, const QVaria val.toDouble()); } break; - // BONGO case OpacityProperty:{ command = new ChangeMapObject(mDocument, mapObject, MapObject::OpacityProperty, @@ -1926,7 +1924,6 @@ void PropertyBrowser::updateProperties() if (mapObject->cell().flippedVertically()) flippingFlags |= 2; mIdToProperty[FlippingProperty]->setValue(flippingFlags); - // BONGO mIdToProperty[OpacityProperty]->setValue(mapObject->opacity()); } diff --git a/src/tmxviewer/tmxviewer.cpp b/src/tmxviewer/tmxviewer.cpp index 52065f6427..4a741fc83f 100644 --- a/src/tmxviewer/tmxviewer.cpp +++ b/src/tmxviewer/tmxviewer.cpp @@ -65,7 +65,6 @@ class MapObjectItem : public QGraphicsItem setPos(pixelPos); setRotation(mapObject->rotation()); - // BONGO setOpacity(mapObject->opacity()); } From c8860458753e180c6fe9c611bee4f9e6e0b5d18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:06:53 +0200 Subject: [PATCH 03/10] Enable changing Opacity also for non-tile objects I didn't see a good reason to limit this feature to tile objects. --- src/tiled/propertybrowser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tiled/propertybrowser.cpp b/src/tiled/propertybrowser.cpp index 5e410f149b..bc511dc122 100644 --- a/src/tiled/propertybrowser.cpp +++ b/src/tiled/propertybrowser.cpp @@ -839,17 +839,17 @@ void PropertyBrowser::addMapObjectProperties() bool isPoint = mapObject->shape() == MapObject::Point; addProperty(RotationProperty, QMetaType::Double, tr("Rotation"), groupProperty)->setEnabled(!isPoint); + QtVariantProperty *opacityProperty = addProperty(OpacityProperty, QMetaType::Double, tr("Opacity"), groupProperty); + opacityProperty->setAttribute(QLatin1String("minimum"), 0.0); + opacityProperty->setAttribute(QLatin1String("maximum"), 1.0); + opacityProperty->setAttribute(QLatin1String("singleStep"), 0.1); + if (mMapObjectFlags & ObjectHasTile) { QtVariantProperty *flippingProperty = addProperty(FlippingProperty, VariantPropertyManager::flagTypeId(), tr("Flipping"), groupProperty); flippingProperty->setAttribute(QLatin1String("flagNames"), mFlippingFlagNames); - - QtVariantProperty *opacityProperty = addProperty(OpacityProperty, QMetaType::Double, tr("Opacity"), groupProperty); - opacityProperty->setAttribute(QLatin1String("minimum"), 0.0); - opacityProperty->setAttribute(QLatin1String("maximum"), 1.0); - opacityProperty->setAttribute(QLatin1String("singleStep"), 0.1); } if (mMapObjectFlags & ObjectIsText) { @@ -1916,6 +1916,7 @@ void PropertyBrowser::updateProperties() } mIdToProperty[RotationProperty]->setValue(mapObject->rotation()); + mIdToProperty[OpacityProperty]->setValue(mapObject->opacity()); if (flags & ObjectHasTile) { int flippingFlags = 0; @@ -1924,7 +1925,6 @@ void PropertyBrowser::updateProperties() if (mapObject->cell().flippedVertically()) flippingFlags |= 2; mIdToProperty[FlippingProperty]->setValue(flippingFlags); - mIdToProperty[OpacityProperty]->setValue(mapObject->opacity()); } if (flags & ObjectIsText) { From d28b801328b75d9fa5c1fc8cddd03e10272e3bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:09:09 +0200 Subject: [PATCH 04/10] Removed the unused Cell::_opacity It's never set to anything else than 1.0. --- src/libtiled/maprenderer.cpp | 2 +- src/libtiled/tilelayer.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libtiled/maprenderer.cpp b/src/libtiled/maprenderer.cpp index 68be73d119..acfa47e284 100644 --- a/src/libtiled/maprenderer.cpp +++ b/src/libtiled/maprenderer.cpp @@ -452,7 +452,7 @@ void CellRenderer::render(const Cell &cell, const QPointF &screenPos, const QSiz fragment.scaleX = size.width() / imageRect.width(); fragment.scaleY = size.height() / imageRect.height(); fragment.rotation = 0; - fragment.opacity = cell.getOpacity(); + fragment.opacity = 1; const auto fillMode = tile->tileset()->fillMode(); if (fillMode == Tileset::PreserveAspectFit) { diff --git a/src/libtiled/tilelayer.h b/src/libtiled/tilelayer.h index 7f07ab0fb3..e38aa40c4b 100644 --- a/src/libtiled/tilelayer.h +++ b/src/libtiled/tilelayer.h @@ -124,9 +124,6 @@ class TILEDSHARED_EXPORT Cell void rotate(RotateDirection direction); - float getOpacity() const { return _opacity; } - void setOpacity(float mOpacity) { _opacity = mOpacity; } - bool checked() const { return _flags & Checked; } void setChecked(bool checked) { checked ? _flags |= Checked : _flags &= ~Checked; } @@ -141,8 +138,6 @@ class TILEDSHARED_EXPORT Cell Tileset *_tileset = nullptr; int _tileId = -1; int _flags = 0; - //BONGO - float _opacity = 1.0; }; inline Tile *Cell::tile() const From adacbdf91d1a2923dc92cb3524d421c24e1a8498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:11:00 +0200 Subject: [PATCH 05/10] Don't fade out selection outline based on object opacity The selection outline should stay clearly visible. --- src/tiled/objectselectionitem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tiled/objectselectionitem.cpp b/src/tiled/objectselectionitem.cpp index 99166ba2c9..572e6650d2 100644 --- a/src/tiled/objectselectionitem.cpp +++ b/src/tiled/objectselectionitem.cpp @@ -110,7 +110,6 @@ void MapObjectOutline::syncWithMapObject(const MapRenderer &renderer) setPos(pixelPos); setRotation(mObject->rotation()); - setOpacity(mObject->opacity()); setFlag(QGraphicsItem::ItemIgnoresTransformations, mObject->shape() == MapObject::Point); From 09552e55ae115994ce07ee51ed186dc885a5408a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:12:36 +0200 Subject: [PATCH 06/10] Removed unused MovingObject::oldOpacity Opacity is irrelevant here since it doesn't change when an object is moved. --- src/tiled/objectselectiontool.cpp | 3 +-- src/tiled/objectselectiontool.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tiled/objectselectiontool.cpp b/src/tiled/objectselectiontool.cpp index 9f355d0c9a..758eb7a113 100644 --- a/src/tiled/objectselectiontool.cpp +++ b/src/tiled/objectselectiontool.cpp @@ -1657,8 +1657,7 @@ void ObjectSelectionTool::saveSelectionState() mapObject->position(), mapObject->size(), mapObject->polygon(), - mapObject->rotation(), - mapObject->opacity() + mapObject->rotation() }; mMovingObjects.append(object); } diff --git a/src/tiled/objectselectiontool.h b/src/tiled/objectselectiontool.h index c9bf4c2925..6b01a4b66a 100644 --- a/src/tiled/objectselectiontool.h +++ b/src/tiled/objectselectiontool.h @@ -167,7 +167,6 @@ class ObjectSelectionTool : public AbstractObjectTool QSizeF oldSize; QPolygonF oldPolygon; qreal oldRotation; - qreal oldOpacity; }; QVector mMovingObjects; From 39675f571c18bdfe4e6ec0b51f869e128d963b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:16:14 +0200 Subject: [PATCH 07/10] Use a more consistent enum order We don't need these values to stay the same, so we can put Opacity after Rotation like everywhere else in the code. --- src/libtiled/mapobject.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libtiled/mapobject.h b/src/libtiled/mapobject.h index 2ee6c4285e..23e0b3670c 100644 --- a/src/libtiled/mapobject.h +++ b/src/libtiled/mapobject.h @@ -117,11 +117,11 @@ class TILEDSHARED_EXPORT MapObject : public Object PositionProperty = 1 << 7, SizeProperty = 1 << 8, RotationProperty = 1 << 9, - CellProperty = 1 << 10, - ShapeProperty = 1 << 11, - TemplateProperty = 1 << 12, - CustomProperties = 1 << 13, - OpacityProperty = 1 << 14, + OpacityProperty = 1 << 10, + CellProperty = 1 << 11, + ShapeProperty = 1 << 12, + TemplateProperty = 1 << 13, + CustomProperties = 1 << 14, AllProperties = 0xFF }; From dbbc6bc4cfdc9f44ecf6491817d8118e88d75d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 15 Aug 2024 14:20:23 +0200 Subject: [PATCH 08/10] Removed remaining "BONGO" occurrences and regenerated Python bindings --- src/libtiled/mapobject.h | 10 +++---- src/plugins/python/pythonbind.cpp | 44 +++++++++++++++--------------- src/plugins/python/tiledbinding.py | 1 - 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/libtiled/mapobject.h b/src/libtiled/mapobject.h index 23e0b3670c..bd24ae362c 100644 --- a/src/libtiled/mapobject.h +++ b/src/libtiled/mapobject.h @@ -485,16 +485,14 @@ inline void MapObject::setRotation(qreal rotation) { mRotation = rotation; } /** - * BONGO: Add Opacity for objects - * returns current opacity -*/ + * Returns the opacity of the object. + */ inline qreal MapObject::opacity() const { return mOpacity; } /** - * BONGO: Add Opacity for objects - * sets new opacity -*/ + * Sets the opacity of the object. + */ inline void MapObject::setOpacity(qreal opacity) { mOpacity = opacity; } diff --git a/src/plugins/python/pythonbind.cpp b/src/plugins/python/pythonbind.cpp index 8cf1e2a32c..8613c0637c 100644 --- a/src/plugins/python/pythonbind.cpp +++ b/src/plugins/python/pythonbind.cpp @@ -6986,28 +6986,29 @@ _wrap_PyTiledMapObject_objectGroup(PyTiledMapObject *self, PyObject *PYBINDGEN_U PyObject * -_wrap_PyTiledMapObject_rotation(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUSED(_args), PyObject *PYBINDGEN_UNUSED(_kwargs)) +_wrap_PyTiledMapObject_opacity(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUSED(_args), PyObject *PYBINDGEN_UNUSED(_kwargs)) { PyObject *py_retval; double retval; - retval = self->obj->rotation(); + retval = self->obj->opacity(); py_retval = Py_BuildValue((char *) "d", retval); return py_retval; } -/* BONGO */ + PyObject * -_wrap_PyTiledMapObject_opacity(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUSED(_args), PyObject *PYBINDGEN_UNUSED(_kwargs)) +_wrap_PyTiledMapObject_rotation(PyTiledMapObject *self, PyObject *PYBINDGEN_UNUSED(_args), PyObject *PYBINDGEN_UNUSED(_kwargs)) { PyObject *py_retval; double retval; - retval = self->obj->opacity(); + retval = self->obj->rotation(); py_retval = Py_BuildValue((char *) "d", retval); return py_retval; } + PyObject * _wrap_PyTiledMapObject_setCell(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) { @@ -7061,16 +7062,16 @@ _wrap_PyTiledMapObject_setName(PyTiledMapObject *self, PyObject *args, PyObject PyObject * -_wrap_PyTiledMapObject_setPosition(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) +_wrap_PyTiledMapObject_setOpacity(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) { PyObject *py_retval; - PyQPointF *pos; - const char *keywords[] = {"pos", NULL}; + double opacity; + const char *keywords[] = {"opacity", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "O!", (char **) keywords, &PyQPointF_Type, &pos)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "d", (char **) keywords, &opacity)) { return NULL; } - self->obj->setPosition(*((PyQPointF *) pos)->obj); + self->obj->setOpacity(opacity); Py_INCREF(Py_None); py_retval = Py_None; return py_retval; @@ -7078,24 +7079,24 @@ _wrap_PyTiledMapObject_setPosition(PyTiledMapObject *self, PyObject *args, PyObj PyObject * -_wrap_PyTiledMapObject_setRotation(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) +_wrap_PyTiledMapObject_setPosition(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) { PyObject *py_retval; - double r; - const char *keywords[] = {"r", NULL}; + PyQPointF *pos; + const char *keywords[] = {"pos", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "d", (char **) keywords, &r)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "O!", (char **) keywords, &PyQPointF_Type, &pos)) { return NULL; } - self->obj->setRotation(r); + self->obj->setPosition(*((PyQPointF *) pos)->obj); Py_INCREF(Py_None); py_retval = Py_None; return py_retval; } -/* BONGO */ + PyObject * -_wrap_PyTiledMapObject_setOpacity(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) +_wrap_PyTiledMapObject_setRotation(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) { PyObject *py_retval; double r; @@ -7104,12 +7105,13 @@ _wrap_PyTiledMapObject_setOpacity(PyTiledMapObject *self, PyObject *args, PyObje if (!PyArg_ParseTupleAndKeywords(args, kwargs, (char *) "d", (char **) keywords, &r)) { return NULL; } - self->obj->setOpacity(r); + self->obj->setRotation(r); Py_INCREF(Py_None); py_retval = Py_None; return py_retval; } + PyObject * _wrap_PyTiledMapObject_setShape(PyTiledMapObject *self, PyObject *args, PyObject *kwargs) { @@ -7298,16 +7300,14 @@ static PyMethodDef PyTiledMapObject_methods[] = { {(char *) "isVisible", (PyCFunction) _wrap_PyTiledMapObject_isVisible, METH_NOARGS, "isVisible()\n\n" }, {(char *) "name", (PyCFunction) _wrap_PyTiledMapObject_name, METH_NOARGS, "name()\n\n" }, {(char *) "objectGroup", (PyCFunction) _wrap_PyTiledMapObject_objectGroup, METH_NOARGS, "objectGroup()\n\n" }, - {(char *) "rotation", (PyCFunction) _wrap_PyTiledMapObject_rotation, METH_NOARGS, "rotation()\n\n" }, - /* BONGO */ {(char *) "opacity", (PyCFunction) _wrap_PyTiledMapObject_opacity, METH_NOARGS, "opacity()\n\n" }, + {(char *) "rotation", (PyCFunction) _wrap_PyTiledMapObject_rotation, METH_NOARGS, "rotation()\n\n" }, {(char *) "setCell", (PyCFunction) _wrap_PyTiledMapObject_setCell, METH_KEYWORDS|METH_VARARGS, "setCell(c)\n\ntype: c: Tiled::Cell const" }, {(char *) "setHeight", (PyCFunction) _wrap_PyTiledMapObject_setHeight, METH_KEYWORDS|METH_VARARGS, "setHeight(h)\n\ntype: h: double" }, {(char *) "setName", (PyCFunction) _wrap_PyTiledMapObject_setName, METH_KEYWORDS|METH_VARARGS, "setName(n)\n\ntype: n: QString" }, + {(char *) "setOpacity", (PyCFunction) _wrap_PyTiledMapObject_setOpacity, METH_KEYWORDS|METH_VARARGS, "setOpacity(opacity)\n\ntype: opacity: double" }, {(char *) "setPosition", (PyCFunction) _wrap_PyTiledMapObject_setPosition, METH_KEYWORDS|METH_VARARGS, "setPosition(pos)\n\ntype: pos: QPointF" }, {(char *) "setRotation", (PyCFunction) _wrap_PyTiledMapObject_setRotation, METH_KEYWORDS|METH_VARARGS, "setRotation(r)\n\ntype: r: double" }, - /* BONGO */ - {(char *) "setOpacity", (PyCFunction) _wrap_PyTiledMapObject_setOpacity, METH_KEYWORDS|METH_VARARGS, "setOpacity(r)\n\ntype: r: double" }, {(char *) "setShape", (PyCFunction) _wrap_PyTiledMapObject_setShape, METH_KEYWORDS|METH_VARARGS, "setShape(s)\n\ntype: s: Tiled::MapObject::Shape" }, {(char *) "setSize", (PyCFunction) _wrap_PyTiledMapObject_setSize, METH_KEYWORDS|METH_VARARGS, "setSize(size)\n\ntype: size: QSizeF" }, {(char *) "setType", (PyCFunction) _wrap_PyTiledMapObject_setType, METH_KEYWORDS|METH_VARARGS, "setType(n)\n\ntype: n: QString" }, diff --git a/src/plugins/python/tiledbinding.py b/src/plugins/python/tiledbinding.py index 30db3fb834..084e11a065 100755 --- a/src/plugins/python/tiledbinding.py +++ b/src/plugins/python/tiledbinding.py @@ -280,7 +280,6 @@ def _decorate(obj, *args, **kwargs): cls_mapobject.add_method('objectGroup', retval('Tiled::ObjectGroup*',reference_existing_object=True), []) cls_mapobject.add_method('rotation', 'double', []) cls_mapobject.add_method('setRotation', None, [('double','r')]) -# BONGO cls_mapobject.add_method('opacity', 'double', []) cls_mapobject.add_method('setOpacity', None, [('double','opacity')]) cls_mapobject.add_method('isVisible', 'bool', []) From e9fa5b9b2a824333c57d71c6abca56de0df3d65a Mon Sep 17 00:00:00 2001 From: jcbk101 Date: Thu, 15 Aug 2024 14:22:31 -0400 Subject: [PATCH 09/10] Update .gitignore Remove build files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d4ed9dd45c..7b030950ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # General build artifacts default/ +build/ # clangd cache .cache/ From b65718f1e8844c2bfff7280b8b16681dd618e682 Mon Sep 17 00:00:00 2001 From: jcbk101 Date: Thu, 15 Aug 2024 16:57:11 -0400 Subject: [PATCH 10/10] Opacity adjustments Opacity adjusted for tmxrasterizer and minimaprederer --- docs/reference/json-map-format.rst | 8 ++++++++ docs/reference/tmx-map-format.rst | 2 ++ src/libtiled/minimaprenderer.cpp | 2 ++ src/tmxrasterizer/tmxrasterizer.cpp | 2 ++ 4 files changed, 14 insertions(+) diff --git a/docs/reference/json-map-format.rst b/docs/reference/json-map-format.rst index b4cd7faf86..73d8b4db38 100644 --- a/docs/reference/json-map-format.rst +++ b/docs/reference/json-map-format.rst @@ -216,6 +216,7 @@ Object polyline, array, "Array of :ref:`Points `, in case the object is a polyline" properties, array, "Array of :ref:`Properties `" rotation, double, "Angle in degrees clockwise" + opacity, double, "The opacity of the object as a value from 0 to 1. Defaults to 1." template, string, "Reference to a template file, in case object is a :doc:`template instance `" text, :ref:`json-object-text`, "Only used for text objects" type, string, "The class of the object (was saved as ``class`` in 1.9, optional)" @@ -241,6 +242,7 @@ Object Example "value":12 }], "rotation":0, + "opacity":1, "type":"npc", "visible":true, "width":0, @@ -259,6 +261,7 @@ Ellipse Example "id":13, "name":"", "rotation":0, + "opacity":1, "type":"", "visible":true, "width":248, @@ -276,6 +279,7 @@ Rectangle Example "id":14, "name":"", "rotation":0, + "opacity":1, "type":"", "visible":true, "width":368, @@ -294,6 +298,7 @@ Point Example "name":"", "point":true, "rotation":0, + "opacity":1, "type":"", "visible":true, "width":0, @@ -332,6 +337,7 @@ Polygon Example "y":-288 }], "rotation":0, + "opacity":1, "type":"", "visible":true, "width":0, @@ -374,6 +380,7 @@ Polyline Example "y":0 }], "rotation":0, + "opacity":1, "type":"", "visible":true, "width":0, @@ -396,6 +403,7 @@ Text Example "wrap":true }, "rotation":0, + "opacity":1, "type":"", "visible":true, "width":248, diff --git a/docs/reference/tmx-map-format.rst b/docs/reference/tmx-map-format.rst index 1df38f5e57..49a5a96b48 100644 --- a/docs/reference/tmx-map-format.rst +++ b/docs/reference/tmx-map-format.rst @@ -549,6 +549,8 @@ Can contain any number: :ref:`tmx-object` - **height:** The height of the object in pixels. (defaults to 0) - **rotation:** The rotation of the object in degrees clockwise around (x, y). (defaults to 0) +- **opacity:** The opacity of the object as a value from 0 to 1. (defaults + to 1) - **gid:** A reference to a tile. (optional) - **visible:** Whether the object is shown (1) or hidden (0). (defaults to 1) diff --git a/src/libtiled/minimaprenderer.cpp b/src/libtiled/minimaprenderer.cpp index de7e125578..b3bfadff64 100644 --- a/src/libtiled/minimaprenderer.cpp +++ b/src/libtiled/minimaprenderer.cpp @@ -203,6 +203,8 @@ void MiniMapRenderer::renderToImage(QImage &image, RenderFlags renderFlags) cons painter.translate(-origin); } + painter.setOpacity(object->opacity()); + mRenderer->drawMapObject(&painter, object, object->effectiveColors()); if (object->rotation() != qreal(0)) diff --git a/src/tmxrasterizer/tmxrasterizer.cpp b/src/tmxrasterizer/tmxrasterizer.cpp index 05b081fca6..eff40eee06 100644 --- a/src/tmxrasterizer/tmxrasterizer.cpp +++ b/src/tmxrasterizer/tmxrasterizer.cpp @@ -85,6 +85,8 @@ void TmxRasterizer::drawMapLayers(const MapRenderer &renderer, painter.translate(-origin); } + painter.setOpacity(object->opacity()); + renderer.drawMapObject(&painter, object, object->effectiveColors()); if (object->rotation() != qreal(0))