Changeset 245 for trunk/LocalPlayer


Ignore:
Timestamp:
May 21, 2020, 7:58:42 PM (5 years ago)
Author:
chronos
Message:
  • Added: Inactive scaling functions for future HighDPI support.
Location:
trunk/LocalPlayer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Help.pas

    r206 r245  
    441441const
    442442  nHeaven = 28;
    443   maxsum = 9 * 9 * 255 * 75 div 100;
     443  MaxSum = 9 * 9 * 255 * 75 div 100;
    444444var
    445445  x, y, dx, dy, xSrc, ySrc, sum, xx: integer;
     
    457457  xSrc := iix mod 7 * xSizeBig;
    458458  ySrc := (iix div 7 + 1) * ySizeBig;
    459   for y := 0 to ySizeBig * 2 - 1 do
    460     if ((y0 + y) >= 0) and ((y0 + y) < InnerHeight) then begin
    461       PaintPtr := PixelPointer(OffScreen, 0, y0 + y);
    462       CoalPtr := PixelPointer(Templates, 0, yCoal + y);
     459  for y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do
     460    if ((ScaleToNative(y0) + y) >= 0) and ((ScaleToNative(y0) + y) < ScaleToNative(InnerHeight)) then begin
     461      PaintPtr := PixelPointer(OffScreen, 0, ScaleToNative(y0) + y);
     462      CoalPtr := PixelPointer(Templates, 0, ScaleToNative(yCoal) + y);
    463463      for dy := -1 to 1 do
    464         if ((Max(y + dy, 0) shr 1) >= 0) and ((Max(y + dy, 0) shr 1) < ySizeBig) then
    465           ImpPtr[dy] := PixelPointer(BigImp, 0, ySrc + (Max(y + dy, 0) shr 1));
    466       for x := 0 to xSizeBig * 2 - 1 do begin
     464        if ((Max(y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then
     465          ImpPtr[dy] := PixelPointer(BigImp, 0, ScaleToNative(ySrc) + (Max(y + ScaleToNative(dy), 0) shr 1));
     466      for x := 0 to ScaleToNative(xSizeBig) * 2 - 1 do begin
    467467        sum := 0;
    468468        for dx := -1 to 1 do begin
    469           xx := xSrc + Max((x + dx), 0) shr 1;
     469          xx := ScaleToNative(xSrc) + Max((x + ScaleToNative(dx)), 0) shr 1;
    470470          for dy := -1 to 1 do begin
    471471            ImpPtr[dy].SetX(xx);
    472             if ((y + dy) shr 1 < 0) or ((y + dy) shr 1 >= ySizeBig) or
    473               ((x + dx) shr 1 < 0) or ((x + dx) shr 1 >= xSizeBig) or
    474               ((y + dy) shr 1 < nHeaven) and
     472            if ((y + ScaleToNative(dy)) shr 1 < 0) or ((y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or
     473              ((x + ScaleToNative(dx)) shr 1 < 0) or ((x + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or
     474              ((y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and
    475475              (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 +
    476               ImpPtr[dy].Pixel^.R = Heaven[(y + dy) shr 1]) then
     476              ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(y) + dy) shr 1]) then
    477477              sum := sum + 9 * 255
    478478            else
     
    481481          end;
    482482        end;
    483         if sum < maxsum then begin // no saturation
    484           CoalPtr.SetX(xCoal + x);
    485           sum := 1 shl 22 - (maxsum - sum) * (256 - CoalPtr.Pixel^.B * 2);
     483        if sum < MaxSum then begin // no saturation
     484          CoalPtr.SetX(ScaleToNative(xCoal) + x);
     485          sum := 1 shl 22 - (MaxSum - sum) * (256 - CoalPtr.Pixel^.B * 2);
    486486          PaintPtr.SetX(x0 + x);
    487487          PaintPtr.Pixel^.B := PaintPtr.Pixel^.B * sum shr 22;
  • trunk/LocalPlayer/IsoEngine.pas

    r206 r245  
    3434    function IsShoreTile(Loc: integer): boolean;
    3535    procedure MakeDark(Line: PPixelPointer; Length: Integer);
    36     procedure ShadeOutside(x0, y0, x1, y1, xm, ym: integer);
     36    procedure ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
    3737  protected
    3838    FOutput: TBitmap;
     
    10151015            1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
    10161016          Borders.BeginUpdate;
    1017           for dy := 0 to yyt * 2 - 1 do
    1018           begin
    1019             PixelPtr := PixelPointer(Borders, 0, p1 * (yyt * 2) + dy);
    1020             for dx := 0 to xxt * 2 - 1 do begin
     1017          PixelPtr := PixelPointer(Borders, ScaleToNative(0), ScaleToNative(p1 * (yyt * 2)));
     1018          for dy := 0 to ScaleToNative(yyt * 2) - 1 do begin
     1019            for dx := 0 to ScaleToNative(xxt * 2) - 1 do begin
    10211020              if PixelPtr.Pixel^.B = 99 then begin
    10221021                PixelPtr.Pixel^.B := Tribe[p1].Color shr 16 and $FF;
     
    10261025              PixelPtr.NextPixel;
    10271026            end;
     1027            PixelPtr.NextLine;
    10281028          end;
    10291029          Borders.EndUpdate;
     
    13301330end;
    13311331
    1332 procedure TIsoMap.ShadeOutside(x0, y0, x1, y1, xm, ym: integer);
     1332procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
    13331333const
    13341334  rShade = 3.75;
     
    13391339begin
    13401340  FOutput.BeginUpdate;
    1341   for y := y0 to y1 - 1 do begin
    1342     Line := PixelPointer(FOutput, 0, y);
    1343     y_n := (y - ym) / yyt;
     1341  Line := PixelPointer(FOutput, ScaleToNative(x0), ScaleToNative(y0));
     1342  for y := 0 to ScaleToNative(Height) - 1 do begin
     1343    y_n := (ScaleFromNative(y) + y0 - ym) / yyt;
    13441344    if abs(y_n) < rShade then begin
    13451345      // Darken left and right parts of elipsis
    13461346      w_n := sqrt(sqr(rShade) - sqr(y_n));
    13471347      wBright := trunc(w_n * xxt + 0.5);
    1348       Line.SetX(x0);
    1349       MakeDark(@Line, xm - x0 - wBright);
    1350       Line.SetX(xm + wBright);
    1351       MakeDark(@Line, x1 - xm - wBright);
     1348      Line.SetX(0);
     1349      MakeDark(@Line, ScaleToNative(xm - wBright));
     1350      Line.SetX(ScaleToNative(xm + wBright));
     1351      MakeDark(@Line, ScaleToNative(Width - xm - wBright));
    13521352    end else begin
    13531353      // Darken entire line
    1354       Line.SetX(x0);
    1355       MakeDark(@Line, x1 - x0);
     1354      Line.SetX(0);
     1355      MakeDark(@Line, ScaleToNative(Width));
    13561356    end;
     1357    Line.NextLine;
    13571358  end;
    13581359  FOutput.EndUpdate;
     
    15761577    xm := x + (dx + 1) * xxt;
    15771578    ym := y + (dy + 1) * yyt + yyt;
    1578     ShadeOutside(FLeft, FTop, FRight, FBottom, xm, ym);
     1579    ShadeOutside(FLeft, FTop, FRight - FLeft, FBottom - FTop, xm, ym);
    15791580    CityGrid(xm, ym, CityAllowClick);
    15801581    for dy := -2 to ny + 1 do
  • trunk/LocalPlayer/MessgEx.pas

    r227 r245  
    237237  Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;
    238238  SrcPtr: TPixelPointer;
    239 begin
     239  Width: Integer;
     240  Height: Integer;
     241begin
     242  Width := 56;
     243  Height := 40;
    240244  if IconIndex >= 0 then begin
    241245    xIcon := IconIndex mod 7 * xSizeBig;
    242246    yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig;
    243247    // prepare screwed icon
    244     fillchar(Screwed, sizeof(Screwed), 0);
     248    FillChar(Screwed, sizeof(Screwed), 0);
    245249    BigImp.BeginUpdate;
    246     for iy := 0 to 39 do begin
    247       for ix := 0 to 55 do begin
    248         SrcPtr := PixelPointer(BigImp, ix + xIcon, iy + yIcon);
    249         xR := ix * (37 + iy * 5 / 40) / 56;
     250    SrcPtr := PixelPointer(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
     251    for iy := 0 to ScaleToNative(Height) - 1 do begin
     252      for ix := 0 to ScaleToNative(Width) - 1 do begin
     253        xR := ScaleFromNative(ix) * (37 + ScaleFromNative(iy) * 5 / Height) / Width;
    250254        xDst := Trunc(xR);
    251255        xR := Frac(xR);
    252         x1 := (120 - ix) * (120 - ix) - 10000;
    253         yR := iy * 18 / 40 + x1 * x1 / 4000000;
     256        x1 := (120 - ScaleFromNative(ix)) * (120 - ScaleFromNative(ix)) - 10000;
     257        yR := ScaleFromNative(iy) * 18 / Height + x1 * x1 / 4000000;
    254258        yDst := Trunc(yR);
    255259        yR := Frac(yR);
     
    272276            Screwed[xDst + dx, yDst + dy, 3] := Screwed[xDst + dx, yDst + dy,
    273277              3] + share;
    274           end;
    275       end;
     278        end;
     279        SrcPtr.NextPixel;
     280      end;
     281      SrcPtr.NextLine;
    276282    end;
    277283    BigImp.EndUpdate;
  • trunk/LocalPlayer/Term.pas

    r227 r245  
    554554  Sharpen = 80;
    555555type
    556   TBuffer = array [0 .. 99999, 0 .. 2] of integer;
     556  TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    557557var
    558   sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch, xdivider,
    559     ydivider: integer;
    560   resampled: ^TBuffer;
     558  Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;
     559  xdivider, ydivider: Integer;
     560  Resampled: ^TBuffer;
    561561  PixelPtr: TPixelPointer;
    562562begin
    563   nx := BigImp.width div xSizeBig * xSizeSmall;
    564   ny := BigImp.height div ySizeBig * ySizeSmall;
     563  nx := BigImp.Width div xSizeBig * xSizeSmall;
     564  ny := BigImp.Height div ySizeBig * ySizeSmall;
    565565
    566566  // resample icons
    567   GetMem(resampled, nx * ny * 12);
    568   FillChar(resampled^, nx * ny * 12, 0);
     567  GetMem(Resampled, nx * ny * 12);
     568  FillChar(Resampled^, nx * ny * 12, 0);
    569569  BigImp.BeginUpdate;
    570   for ix := 0 to BigImp.width div xSizeBig - 1 do
    571     for iy := 0 to BigImp.height div ySizeBig - 1 do
    572       for y := 0 to ySizeBig - 2 * cut - 1 do
    573       begin
    574         ydivider := (y * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
    575           (ySizeBig - 2 * cut) - y * ySizeSmall;
     570  for ix := 0 to BigImp.Width div xSizeBig - 1 do
     571    for iy := 0 to BigImp.Height div ySizeBig - 1 do begin
     572      PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig),
     573        ScaleToNative(cut + iy * ySizeBig));
     574      for y := 0 to ScaleToNative(ySizeBig - 2 * cut) - 1 do begin
     575        ydivider := (ScaleFromNative(y) * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
     576          (ySizeBig - 2 * cut) - ScaleFromNative(y) * ySizeSmall;
    576577        if ydivider > ySizeSmall then
    577578          ydivider := ySizeSmall;
    578         PixelPtr := PixelPointer(BigImp, 0, cut + iy * ySizeBig + y);
    579         for x := 0 to xSizeBig - 1 do
    580         begin
    581           ir := ix * xSizeSmall + iy * nx * ySizeSmall + x *
    582             xSizeSmall div xSizeBig + y *
     579        for x := 0 to ScaleToNative(xSizeBig) - 1 do begin
     580          ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(x) *
     581            xSizeSmall div xSizeBig + ScaleFromNative(y) *
    583582            ySizeSmall div (ySizeBig - 2 * cut) * nx;
    584           xdivider := (x * xSizeSmall div xSizeBig + 1) * xSizeBig - x *
    585             xSizeSmall;
     583          xdivider := (ScaleFromNative(x) * xSizeSmall div xSizeBig + 1) *
     584            xSizeBig - ScaleFromNative(x) * xSizeSmall;
    586585          if xdivider > xSizeSmall then
    587586            xdivider := xSizeSmall;
    588           for ch := 0 to 2 do
    589           begin
    590             PixelPtr.SetX(ix * xSizeBig + x);
     587          for ch := 0 to 2 do begin
    591588            c := PixelPtr.Pixel^.Planes[ch];
    592             inc(resampled[ir, ch], c * xdivider * ydivider);
     589            Inc(Resampled[ir, ch], c * xdivider * ydivider);
    593590            if xdivider < xSizeSmall then
    594               inc(resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
     591              Inc(Resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
    595592                ydivider);
    596593            if ydivider < ySizeSmall then
    597               inc(resampled[ir + nx, ch],
     594              Inc(Resampled[ir + nx, ch],
    598595                c * xdivider * (ySizeSmall - ydivider));
    599596            if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    600               inc(resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
     597              Inc(Resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
    601598                (ySizeSmall - ydivider));
    602599          end;
     600          PixelPtr.NextPixel;
    603601        end;
     602        PixelPtr.NextLine;
    604603      end;
     604    end;
    605605  BigImp.EndUpdate;
    606606
    607   // sharpen resampled icons
     607  // Sharpen Resampled icons
    608608  SmallImp.SetSize(nx, ny);
    609609  SmallImp.BeginUpdate;
    610   for y := 0 to ny - 1 do begin
    611     PixelPtr := PixelPointer(SmallImp, 0, y);
    612     for x := 0 to nx - 1 do
     610  PixelPtr := PixelPointer(SmallImp);
     611  for y := 0 to ScaleToNative(ny) - 1 do begin
     612    for x := 0 to ScaleToNative(nx) - 1 do begin
    613613      for ch := 0 to 2 do begin
    614         sum := 0;
     614        Sum := 0;
    615615        Cnt := 0;
    616616        for dy := -1 to 1 do
    617           if ((dy >= 0) or (y mod ySizeSmall > 0)) and
    618             ((dy <= 0) or (y mod ySizeSmall < ySizeSmall - 1)) then
     617          if ((dy >= 0) or (ScaleFromNative(y) mod ySizeSmall > 0)) and
     618            ((dy <= 0) or (ScaleFromNative(y) mod ySizeSmall < ySizeSmall - 1)) then
    619619            for dx := -1 to 1 do
    620               if ((dx >= 0) or (x mod xSizeSmall > 0)) and
    621                 ((dx <= 0) or (x mod xSizeSmall < xSizeSmall - 1)) then
     620              if ((dx >= 0) or (ScaleFromNative(x) mod xSizeSmall > 0)) and
     621                ((dx <= 0) or (ScaleFromNative(x) mod xSizeSmall < xSizeSmall - 1)) then
    622622              begin
    623                 inc(sum, resampled[x + dx + nx * (y + dy), ch]);
    624                 inc(Cnt);
     623                Inc(Sum, Resampled[ScaleFromNative(x) + dx + nx * (ScaleFromNative(y) + dy), ch]);
     624                Inc(Cnt);
    625625              end;
    626         sum := ((Cnt * Sharpen + 800) * resampled[x + nx * y, ch] - sum *
     626        Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(x) + nx * ScaleFromNative(y), ch] - Sum *
    627627          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * cut));
    628         if sum < 0 then sum := 0;
    629         if sum > 255 then sum := 255;
    630         PixelPtr.SetX(x);
    631         PixelPtr.Pixel^.Planes[ch] := sum;
     628        if Sum < 0 then Sum := 0;
     629        if Sum > 255 then Sum := 255;
     630        PixelPtr.Pixel^.Planes[ch] := Sum;
    632631      end;
     632      PixelPtr.NextPixel;
     633    end;
     634    PixelPtr.NextLine;
    633635  end;
    634636  SmallImp.EndUpdate;
    635   FreeMem(resampled);
     637  FreeMem(Resampled);
    636638end;
    637639
     
    40664068  MiniPixel := PixelPointer(Mini);
    40674069  PrevMiniPixel := PixelPointer(Mini);
    4068   for y := 0 to G.ly - 1 do
    4069   begin
    4070     for x := 0 to G.lx - 1 do
    4071       if MyMap[x + G.lx * y] and fTerrain <> fUNKNOWN then
    4072       begin
    4073         Loc := x + G.lx * y;
     4070  for y := 0 to ScaleToNative(G.ly) - 1 do
     4071  begin
     4072    for x := 0 to ScaleToNative(G.lx) - 1 do
     4073      if MyMap[ScaleFromNative(x) + G.lx * ScaleFromNative(y)] and fTerrain <> fUNKNOWN then
     4074      begin
     4075        Loc := ScaleFromNative(x) + G.lx * ScaleFromNative(y);
    40744076        for i := 0 to 1 do
    40754077        begin
    4076           xm := ((x - xwMini) * 2 + i + y and 1 - hw + G.lx * 5) mod (G.lx * 2);
     4078          xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
     4079            ScaleToNative(G.lx) * 5) mod (ScaleToNative(G.lx) * 2);
    40774080          MiniPixel.SetXY(xm, y);
    40784081          cm := MiniColors[MyMap[Loc] and fTerrain, i];
  • trunk/LocalPlayer/Wonders.pas

    r230 r245  
    104104  Ch: Integer;
    105105  Line: array [0..3] of TPixelPointer;
    106 begin
     106  Width: Integer;
     107  Height: Integer;
     108begin
     109  Width := ScaleToNative(180);
     110  Height := ScaleToNative(128);
    107111  Offscreen.BeginUpdate;
    108   Line[0] := PixelPointer(Offscreen, Center.X, Center.Y);
    109   Line[1] := PixelPointer(Offscreen, Center.X, Center.Y - 1);
    110   Line[2] := PixelPointer(Offscreen, Center.X - 1, Center.Y);
    111   Line[3] := PixelPointer(Offscreen, Center.X - 1, Center.Y - 1);
    112   for Y := 0 to 127 do begin
    113     for X := 0 to 179 do begin
    114       r := X * X * (32 * 32) + Y * Y * (45 * 45);
    115       ax := ((1 shl 16 div 32) * 45) * Y;
    116       if (r < 8 * 128 * 180 * 180) and
    117         ((r >= 32 * 64 * 90 * 90) and (ax < amax2 * X) and
     112  Line[0] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y));
     113  Line[1] := PixelPointer(Offscreen, ScaleToNative(Center.X), ScaleToNative(Center.Y) - 1);
     114  Line[2] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y));
     115  Line[3] := PixelPointer(Offscreen, ScaleToNative(Center.X) - 1, ScaleToNative(Center.Y) - 1);
     116  for Y := 0 to Height - 1 do begin
     117    for X := 0 to Width - 1 do begin
     118      r := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
     119      ax := ((1 shl 16 div (Height div 4)) * (Width div 4)) * Y;
     120      if (r < ScaleToNative(8) * Height * Width * Width) and
     121        ((r >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
    118122        ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and
    119123        ((ax < amax1 * X) or (ax > amin3 * X))) then begin
     
    156160  x0Src := (i mod 7) * xSizeBig;
    157161  y0Src := (i div 7 + SystemIconLines) * ySizeBig;
    158   Src := PixelPointer(BigImp, x0Src, y0Src);
    159   Dst := PixelPointer(Offscreen, x0Dst, y0Dst);
    160   for Y := 0 to ySizeBig - 1 do begin
    161     for X := 0 to xSizeBig - 1 do begin
     162  Src := PixelPointer(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src));
     163  Dst := PixelPointer(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst));
     164  for Y := 0 to ScaleToNative(ySizeBig) - 1 do begin
     165    for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
    162166      Darken := ((255 - Src.Pixel^.B) * 3 + (255 - Src.Pixel^.G) *
    163167        15 + (255 - Src.Pixel^.R) * 9) div 128;
     
    229233              ySizeBig + 6, (wMaintexture - ClientWidth) div 2,
    230234              (hMaintexture - ClientHeight) div 2);
    231             //DarkIcon(I);
     235            DarkIcon(I);
    232236          end;
    233237        -2: // destroyed
Note: See TracChangeset for help on using the changeset viewer.