private void AddIcon(int houseIndex, MissionSet set, short regionID, string[] unitDescriptions) { if (regionID <= 0 || houseIndex < 0 || houseIndex > _iconSprite.Length) { return; } if (ParentForm is GameForm f) { // regionIDs are one-based int regIndex = regionID - 1; SpriteBox sp = new SpriteBox(); // Add first _missionBoxes.Add(sp); spTerritories.Controls.Add(sp); sp.BaseImage = _iconSprite[houseIndex]; sp.Click += (o, e) => { AudioEngine.Click(); f.Push(new MissionBriefingScreen(set, unitDescriptions), TransitionStyle.FADE_BLACK); }; float2 iconLoc = _centers[regIndex]; float2 sz = spTerritories.Size.ToFloat2() / _territoryBitmapSize.ToFloat2() * _iconSprite[houseIndex].Size.ToFloat2() * ICON_SCALE; float2 loc = spTerritories.Size.ToFloat2() * iconLoc / _territoryBitmapSize.ToFloat2() - sz / 2; sp.Location = loc.ToPoint(); sp.Size = sz.ToSize(); } }
internal void Rescale() { if (IsDisposed) { return; } if (DesignMode) { return; } if (_orgSize == Size.Empty) { return; } foreach (Control c in Controls) { if (c is SpriteBox sp) { float2 sploc = sp.Size.ToFloat2(); float2 spsz = sp.Size.ToFloat2(); switch (BackgroundImageLayout) { case ImageLayout.Zoom: { sploc = _displacement + sp._relLocation * _effSize; spsz = sp._relSize * _effSize; break; } case ImageLayout.Stretch: { sploc = sp._relLocation * Size.ToFloat2(); spsz = sp._relSize * Size.ToFloat2(); break; } case ImageLayout.Center: { sploc = sp._relLocation * Size.ToFloat2(); spsz = sp._relSize * Size.ToFloat2(); // convert negative displacement to 0 as ImageLayout.Center keeps the top left corner anchored Image bgImg = BackgroundImage; if (bgImg != null) { float2 spdisp = (Size.ToFloat2() - bgImg.Size.ToFloat2()) / 2; spdisp.x = spdisp.x.Max(0); spdisp.y = spdisp.y.Max(0); sploc += spdisp; } break; } // ImageLayout.Tile and ImageLayout.None keep elements aligned to top left corner default: break; } float2 preserveLoc = sp._relLocation; float2 preserveSz = sp._relSize; sp.Location = sploc.ToPoint(); sp.Size = spsz.ToSize(); // write back the old values to prevent accumulation of rounding errors if (preserveLoc != float2.Empty) { sp._relLocation = preserveLoc; } if (preserveSz != float2.Empty) { sp._relSize = preserveSz; } } } }