Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-object opacity #4031

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions docs/reference/json-map-format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ Object
polyline, array, "Array of :ref:`Points <json-point>`, in case the object is a polyline"
properties, array, "Array of :ref:`Properties <json-property>`"
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 </manual/using-templates>`"
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)"
Expand All @@ -241,6 +242,7 @@ Object Example
"value":12
}],
"rotation":0,
"opacity":1,
"type":"npc",
"visible":true,
"width":0,
Expand All @@ -259,6 +261,7 @@ Ellipse Example
"id":13,
"name":"",
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":248,
Expand All @@ -276,6 +279,7 @@ Rectangle Example
"id":14,
"name":"",
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":368,
Expand All @@ -294,6 +298,7 @@ Point Example
"name":"",
"point":true,
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":0,
Expand Down Expand Up @@ -332,6 +337,7 @@ Polygon Example
"y":-288
}],
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":0,
Expand Down Expand Up @@ -374,6 +380,7 @@ Polyline Example
"y":0
}],
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":0,
Expand All @@ -396,6 +403,7 @@ Text Example
"wrap":true
},
"rotation":0,
"opacity":1,
"type":"",
"visible":true,
"width":248,
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/tmx-map-format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/libtiled/minimaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ void MiniMapRenderer::renderToImage(QImage &image, RenderFlags renderFlags) cons
painter.translate(-origin);
}

painter.setOpacity(object->opacity());
Copy link
Member

@bjorn bjorn Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to store the above layer->effectiveOpacity() in a variable and set the opacity to layerOpacity * object->opacity() here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. I don't think I would have even considered that. This is one of my fears of being a contributor. I do not know the full requirements for such a project. I am just learning qt to be honest.


mRenderer->drawMapObject(&painter, object, object->effectiveColors());

if (object->rotation() != qreal(0))
Expand Down
2 changes: 2 additions & 0 deletions src/tmxrasterizer/tmxrasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down