hedgewars/uLandGraphics.pas
changeset 5692 753ae5d0776c
parent 5687 fac606654317
child 5832 f730c8a9777b
equal deleted inserted replaced
5691:54b12cc39e95 5692:753ae5d0776c
    45 uses SDLh, uLandTexture, uVariables, uUtils, uDebug;
    45 uses SDLh, uLandTexture, uVariables, uUtils, uDebug;
    46 
    46 
    47 function addBgColor(OldColor, NewColor: LongWord): LongWord;
    47 function addBgColor(OldColor, NewColor: LongWord): LongWord;
    48 // Factor ranges from 0 to 100% NewColor
    48 // Factor ranges from 0 to 100% NewColor
    49 var
    49 var
    50     oRed, oBlue, oGreen, oAlpha, nRed, nBlue, nGreen, nAlpha: Byte;
    50     oRed, oBlue, oGreen, oAlpha, nRed, nBlue, nGreen, nAlpha: LongWord;
    51 begin
    51 begin
       
    52     oAlpha := (OldColor shr AShift) and $FF;
       
    53     nAlpha := (NewColor shr AShift) and $FF;
       
    54     // shortcircuit
       
    55     if (oAlpha = 0) or (nAlpha = $FF) then
       
    56         begin
       
    57         addBgColor:= NewColor;
       
    58         exit
       
    59         end; 
    52     // Get colors
    60     // Get colors
    53     oAlpha := (OldColor shr AShift) and $FF;
       
    54     oRed   := (OldColor shr RShift) and $FF;
    61     oRed   := (OldColor shr RShift) and $FF;
    55     oGreen := (OldColor shr GShift) and $FF;
    62     oGreen := (OldColor shr GShift) and $FF;
    56     oBlue  := (OldColor shr BShift) and $FF;
    63     oBlue  := (OldColor shr BShift) and $FF;
    57 
    64 
    58     nAlpha := (NewColor shr AShift) and $FF;
       
    59     nRed   := (NewColor shr RShift) and $FF;
    65     nRed   := (NewColor shr RShift) and $FF;
    60     nGreen := (NewColor shr GShift) and $FF;
    66     nGreen := (NewColor shr GShift) and $FF;
    61     nBlue  := (NewColor shr BShift) and $FF;
    67     nBlue  := (NewColor shr BShift) and $FF;
    62 
    68 
    63     // Mix colors
    69     // Mix colors
       
    70     nRed   := min(255,((nRed*nAlpha) div 255) + ((oRed*oAlpha*(255-nAlpha)) div 65025));
       
    71     nGreen := min(255,((nGreen*nAlpha) div 255) + ((oGreen*oAlpha*(255-nAlpha)) div 65025));
       
    72     nBlue  := min(255,((nBlue*nAlpha) div 255) + ((oBlue*oAlpha*(255-nAlpha)) div 65025)); 
    64     nAlpha := min(255, oAlpha + nAlpha);
    73     nAlpha := min(255, oAlpha + nAlpha);
    65     nRed   := ((oRed * oAlpha) + (nRed * Byte(255-oAlpha))) div 255;
       
    66     nGreen := ((oGreen * oAlpha) + (nGreen * Byte(255-oAlpha))) div 255;
       
    67     nBlue  := ((oBlue * oAlpha) + (nBlue * Byte(255-oAlpha))) div 255;
       
    68 
    74 
    69     addBgColor := (nAlpha shl AShift) or (nRed shl RShift) or (nGreen shl GShift) or (nBlue shl BShift);
    75     addBgColor := (nAlpha shl AShift) or (nRed shl RShift) or (nGreen shl GShift) or (nBlue shl BShift);
    70 end;
    76 end;
    71 
    77 
    72 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
    78 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);