AGS: Engine: ScreenOverlay.SetImage() accepts offset as arguments

+ Fixed overlays losing offsets when restoring a save.

From upstream 2002caf32882ab28accd544369c9991675a0dcb1
This commit is contained in:
Walter Agazzi 2023-01-18 02:03:22 +01:00 committed by Thierry Crozat
parent 7e3c3f1f0b
commit 300379a2d6
5 changed files with 13 additions and 17 deletions

View File

@ -81,12 +81,8 @@ void Overlay_SetText(ScriptOverlay *scover, int width, int fontid, int text_colo
width, fontid, allow_shrink, has_alpha);
// Update overlay properties
over.SetImage(image);
over.SetImage(image, adj_x - dummy_x, adj_y - dummy_y);
over.SetAlphaChannel(has_alpha);
over.x = x;
over.y = y;
over.offsetX = adj_x - dummy_x;
over.offsetY = adj_y - dummy_y;
over.ddb = nullptr; // is generated during first draw pass
}
@ -390,17 +386,15 @@ size_t add_screen_overlay_impl(bool roomlayer, int x, int y, int type, int sprnu
}
ScreenOverlay over;
if (piccy) {
over.SetImage(piccy);
over.SetImage(piccy, pic_offx, pic_offy);
over.SetAlphaChannel(has_alpha);
} else {
over.SetSpriteNum(sprnum);
over.SetSpriteNum(sprnum, pic_offx, pic_offy);
over.SetAlphaChannel((_GP(game).SpriteInfos[sprnum].Flags & SPF_ALPHACHANNEL) != 0);
}
over.ddb = nullptr; // is generated during first draw pass
over.x = x;
over.y = y;
over.offsetX = pic_offx;
over.offsetY = pic_offy;
// by default draw speech and portraits over GUI, and the rest under GUI
over.zorder = (roomlayer || type == OVER_TEXTMSG || type == OVER_PICTURE || type == OVER_TEXTSPEECH) ?
INT_MAX : INT_MIN;

View File

@ -35,11 +35,12 @@ Bitmap *ScreenOverlay::GetImage() const {
_pic.get();
}
void ScreenOverlay::SetImage(Shared::Bitmap *pic) {
void ScreenOverlay::SetImage(Shared::Bitmap *pic, int offx, int offy) {
_flags &= ~kOver_SpriteReference;
_pic.reset(pic);
_sprnum = -1;
offsetX = offsetY = 0;
offsetX = offx;
offsetY = offy;
scaleWidth = scaleHeight = 0;
const auto *img = GetImage();
if (img) {
@ -49,11 +50,12 @@ void ScreenOverlay::SetImage(Shared::Bitmap *pic) {
MarkChanged();
}
void ScreenOverlay::SetSpriteNum(int sprnum) {
void ScreenOverlay::SetSpriteNum(int sprnum, int offx, int offy) {
_flags |= kOver_SpriteReference;
_pic.reset();
_sprnum = sprnum;
offsetX = offsetY = 0;
offsetX = offx;
offsetY = offy;
scaleWidth = scaleHeight = 0;
const auto *img = GetImage();
if (img) {

View File

@ -99,8 +99,8 @@ struct ScreenOverlay {
int GetSpriteNum() const {
return _sprnum;
}
void SetImage(Shared::Bitmap *pic);
void SetSpriteNum(int sprnum);
void SetImage(Shared::Bitmap *pic, int offx = 0, int offy = 0);
void SetSpriteNum(int sprnum, int offx = 0, int offy = 0);
// Tells if Overlay has graphically changed recently
bool HasChanged() const {
return _hasChanged;

View File

@ -773,7 +773,7 @@ HSaveError ReadOverlays(Stream *in, int32_t cmp_ver, const PreservedParams & /*p
bool has_bitmap;
over.ReadFromFile(in, has_bitmap, cmp_ver);
if (has_bitmap)
over.SetImage(read_serialized_bitmap(in));
over.SetImage(read_serialized_bitmap(in), over.offsetX, over.offsetY);
if (over.scaleWidth <= 0 || over.scaleHeight <= 0) {
over.scaleWidth = over.GetImage()->GetWidth();
over.scaleHeight = over.GetImage()->GetHeight();

View File

@ -286,7 +286,7 @@ static void restore_game_overlays(Stream *in) {
ReadOverlays_Aligned(in, has_bitmap, num_overs);
for (size_t i = 0; i < num_overs; ++i) {
if (has_bitmap[i])
_GP(screenover)[i].SetImage(read_serialized_bitmap(in));
_GP(screenover)[i].SetImage(read_serialized_bitmap(in), _GP(screenover)[i].offsetX, _GP(screenover)[i].offsetY);
}
}