Add set_opacity command for icons.

This commit is contained in:
Sergey Vartanov 2021-08-31 01:17:13 +03:00
parent f821ea0917
commit b3560cfdc7
6 changed files with 41 additions and 19 deletions

View file

@ -220,7 +220,7 @@ class Constructor:
if not line.tags:
return
building_mode: BuildingMode = self.configuration.building_mode
building_mode: str = self.configuration.building_mode
if "building" in line.tags or (
building_mode == BuildingMode.ISOMETRIC
and "building:part" in line.tags

View file

@ -329,6 +329,7 @@ class Icon:
"""
shape_specifications: list[ShapeSpecification]
opacity: float = 1.0
def get_shape_ids(self) -> list[str]:
"""Get all shape identifiers in the icon."""
@ -356,16 +357,19 @@ class Icon:
:param tags: tags to be displayed as hint
:param outline: draw outline for the icon
"""
target = Group(opacity=self.opacity) if self.opacity != 1.0 else svg
if outline:
bright: bool = is_bright(self.shape_specifications[0].color)
opacity: float = 0.7 if bright else 0.5
if outline:
outline_group: Group = Group(opacity=opacity)
for shape_specification in self.shape_specifications:
shape_specification.draw(outline_group, point, tags, True)
svg.add(outline_group)
target.add(outline_group)
else:
for shape_specification in self.shape_specifications:
shape_specification.draw(svg, point, tags)
shape_specification.draw(target, point, tags)
if self.opacity != 1.0:
svg.add(target)
def draw_to_file(
self,

View file

@ -159,7 +159,7 @@ class Point(Tagged):
self,
svg: svgwrite.Drawing,
occupied: Optional[Occupied] = None,
label_mode: LabelMode = LabelMode.MAIN,
label_mode: str = LabelMode.MAIN,
) -> None:
"""Draw all labels."""
labels: list[Label]

View file

@ -201,6 +201,10 @@ class NodeMatcher(Matcher):
if "set_main_color" in structure:
self.set_main_color = structure["set_main_color"]
self.set_opacity: Optional[float] = None
if "set_opacity" in structure:
self.set_opacity = structure["set_opacity"]
self.under_icon: Optional[IconDescription] = None
if "under_icon" in structure:
self.under_icon = structure["under_icon"]
@ -408,6 +412,8 @@ class Scheme:
processed |= matcher_tags
if matcher.set_main_color and main_icon:
main_icon.recolor(self.get_color(matcher.set_main_color))
if matcher.set_opacity and main_icon:
main_icon.opacity = matcher.set_opacity
index += 1

View file

@ -14,7 +14,7 @@ BOXES: str = " ▏▎▍▌▋▊▉"
BOXES_LENGTH: int = len(BOXES)
def parse_options(args: argparse.Namespace) -> argparse.Namespace:
def parse_options(args: list[str]) -> argparse.Namespace:
"""Parse Röntgen command-line options."""
parser: argparse.ArgumentParser = argparse.ArgumentParser(
description="Röntgen. OpenStreetMap renderer with custom icon set"

View file

@ -949,30 +949,42 @@ node_icons:
shapes: [lander]
- tags: {man_made: rover, condition: landed}
shapes: [{shape: lunokhod, opacity: 0.8}]
shapes: [lunokhod]
set_opacity: 0.8
- tags: {man_made: probe, condition: landed}
shapes: [{shape: probe, opacity: 0.8}]
shapes: [probe]
set_opacity: 0.8
- tags: {man_made: orbiter, condition: landed}
shapes: [{shape: orbiter, opacity: 0.8}]
shapes: [orbiter]
set_opacity: 0.8
- tags: {man_made: descent_stage, condition: landed}
shapes: [{shape: descent_stage, opacity: 0.8}]
shapes: [descent_stage]
set_opacity: 0.8
- tags: {man_made: third_stage, condition: landed}
shapes: [{shape: third_stage, opacity: 0.8}]
shapes: [third_stage]
set_opacity: 0.8
- tags: {man_made: lander, condition: landed}
shapes: [{shape: lander, opacity: 0.8}]
shapes: [lander]
set_opacity: 0.8
- tags: {man_made: rover, condition: crashed}
shapes: [{shape: lunokhod, opacity: 0.5}]
shapes: [lunokhod]
set_opacity: 0.5
- tags: {man_made: probe, condition: crashed}
shapes: [{shape: probe, opacity: 0.5}]
shapes: [probe]
set_opacity: 0.5
- tags: {man_made: orbiter, condition: crashed}
shapes: [{shape: orbiter, opacity: 0.5}]
shapes: [orbiter]
set_opacity: 0.5
- tags: {man_made: descent_stage, condition: crashed}
shapes: [{shape: descent_stage, opacity: 0.5}]
shapes: [descent_stage]
set_opacity: 0.5
- tags: {man_made: third_stage, condition: crashed}
shapes: [{shape: third_stage, opacity: 0.5}]
shapes: [third_stage]
set_opacity: 0.5
- tags: {man_made: lander, condition: crashed}
shapes: [{shape: lander, opacity: 0.5}]
shapes: [lander]
set_opacity: 0.5
- group: "Important small objects"
start_zoom_level: 17