[0.18.1][Modding] Icon scaling/shifting not working

Things that has been reported already before.
Post Reply
User avatar
lovely_santa
Filter Inserter
Filter Inserter
Posts: 502
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

[0.18.1][Modding] Icon scaling/shifting not working

Post by lovely_santa »

Hi,

It's me again, again with the same bug report as in 0.17.. I can not scale icons correctly:
- Scaling the icon with a scale < 1 (as in shrinking the icon) does nothing.
- Shifting the icon seems to be shifting relative to the size (changing the scale influences the shifting)

An example:

Code: Select all

local compressed_landfill_scale = .1
local compressed_landfill_shift = 2
...
  icons =
  {
    {
      icon = "__base__/graphics/icons/landfill.png",
      icon_size = 64, icon_mipmaps = 4,
      scale = compressed_landfill_scale,
      shift = {-compressed_landfill_shift, compressed_landfill_shift},
    },
    {
      icon = "__base__/graphics/icons/landfill.png",
      icon_size = 64, icon_mipmaps = 4,
      scale = compressed_landfill_scale,
      shift = {compressed_landfill_shift, compressed_landfill_shift},
    },
    {
      icon = "__base__/graphics/icons/landfill.png",
      icon_size = 64, icon_mipmaps = 4,
      scale = compressed_landfill_scale,
      shift = {0, -compressed_landfill_shift},
    },
  },
In the code above, I add 3 icons of the landfill, I scale them to be extremely tiny (10% of the original scale) and shift them over by 2 pixels (so basically they should almost appear fully on top of each other, instead I get this result:
Capture.PNG
Capture.PNG (36.29 KiB) Viewed 717 times
As you can see, the icons aren't scaled at all, and the shift is way to much. I've attached this example with a save file where the item is in my inventory.

Kind regards
lovely santa
Attachments
LandMover_0.2.7.zip
(110.94 KiB) Downloaded 29 times
_autosave3.zip
(2.34 MiB) Downloaded 28 times
You can find all my mods on the mod portal. Also helping on Arch666Angel's mods.
Image

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.18.1][Modding] Icon scaling/shifting not working

Post by Optera »

Can't confirm this.
Apart from Icons requiring to be scaled by 0.75 * 0.5 to actually scale to 75% it's pretty straight forward:

Code: Select all

    icons = {
      { icon = "__base__/graphics/icons/signal/signal_green.png", icon_size = 64, icon_mipmaps = 4 },
      { icon = "__base__/graphics/icons/cargo-wagon.png", icon_size = 64, icon_mipmaps = 4, scale = 0.375 },
    },

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.1][Modding] Icon scaling/shifting not working

Post by posila »

Ah, you weren't part of this icon scaling issue thread
posila wrote:
Mon Jun 03, 2019 11:05 pm
The problem is essentially this: "icons" definition is not "icon composition", it is "icon with overlays"
The first layer is expected to be 'base icon', rest are expected to be overlays on top of it. But the definition doesn't communicate it well (or at all), allows you to shoot yourself into a foot and it is beyond simple bugfix to make it so it is not that. I don't know if that's what it was intended to be initially, but it is what it ended up being.

GUI, which doesn't care about layers in sprites at all, but happens to render them, stretches a base icon to fill a slot. So if you define it as 1x1 px image with scale 1, and the slot is 32x32 pixels, it'll scale the whole thing by factor 32. If you hadn't specified scale at all, the game would infer the scale to be 32 (not 1) and it would have worked. Except, not quite. Because you would have to know what is the expected size for this icon, so you can define your other layers with correct scale and shift. For that reason it is better to be explicit with scale of the base icon. And you can even use 1x1 image with scale 1 as a base, then you just have to operate in range <0, 1> in layers (just divide your values by 32). Except you can't actually do that, because in the alt mode the icon would have size of just 1/32th of a tile. So you still need to know what is expected size of the base icon.

From my point of view the main issue is that the base icon definition allows you to override scale and shift, and scale and shift of overlays are not defined in coordinate space of unscaled base icon.

(Side note, just for completeness: black outlines in alt-mode, and shadows around icons in some GUIs are also calculated just from the base icon)

Ref: 71480
posila wrote:
Mon Jun 10, 2019 1:00 pm
So, after thinking about it more, I decided to declare the current system as good enough.

There is no real reason for us to ever change internally expected sizes, we will just change icon_size in lua as everyone else, so having to know that the icon will be rescaled so that the first layer is 32x32px is not as big of a deal as I thought.

User avatar
lovely_santa
Filter Inserter
Filter Inserter
Posts: 502
Joined: Sat Feb 18, 2017 9:41 pm
Contact:

Re: [0.18.1][Modding] Icon scaling/shifting not working

Post by lovely_santa »

posila wrote:
Thu Jan 23, 2020 9:10 pm
Ah, you weren't part of this icon scaling issue thread

...
I am aware of that thread, I am also aware that the scale is 0.5 for icon size 64 due to the reference of 32 pixels, the issue I am describing is that since 0.18 the icon is not scaling at all (when scale < 'normal' aka .5 for 64px or 1 for 32px) versus the 0.17 issue doesn't work as intended

And my issue with the shifting (which was fixed in 0.17) did reappear in 0.18, in exactly the same way, that the shifting doesn't work in 'pixels' as it used to do...
You can find all my mods on the mod portal. Also helping on Arch666Angel's mods.
Image

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.1][Modding] Icon scaling/shifting not working

Post by posila »

Scale factor is calculated such that your base layer fills the button.
scale_factor = 32 / (64 * 0.1) = 5
And that's what is used to render the icon. So your 2px shift will become 10px, etc.

Scale on the base layer is only relevant for the game view (alt-mode, belts, items on ground) ... so I think what needs to be fixed is that shift is allowed on the base layer as it won't work in GUI.

Post Reply

Return to “Duplicates”