AGS: Simplified the use of get_overlay_position()

From upstream d673fb3822907fd01bf0e2c6f98bee04a8a5b17b
This commit is contained in:
Paul Gilbert 2022-05-05 20:41:51 -07:00
parent 97c12e8435
commit 84a3925442
3 changed files with 22 additions and 32 deletions

View File

@ -1876,9 +1876,8 @@ void draw_gui_and_overlays() {
over.ddb->SetStretch(over.scaleWidth, over.scaleHeight);
over.ddb->SetAlpha(GfxDef::LegacyTrans255ToAlpha255(over.transparency));
int tdxp, tdyp;
get_overlay_position(over, &tdxp, &tdyp);
add_to_sprite_list(over.ddb, tdxp, tdyp, over.zorder, false, -1);
Point pos = get_overlay_position(over);
add_to_sprite_list(over.ddb, pos.X, pos.Y, over.zorder, false);
}
// Add GUIs

View File

@ -19,6 +19,7 @@
*
*/
#include "ags/lib/std/algorithm.h"
#include "ags/engine/ac/overlay.h"
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/view.h"
@ -70,10 +71,8 @@ int Overlay_GetX(ScriptOverlay *scover) {
if (ovri < 0)
quit("!invalid overlay ID specified");
int tdxp, tdyp;
get_overlay_position(_GP(screenover)[ovri], &tdxp, &tdyp);
return game_to_data_coord(tdxp);
Point pos = get_overlay_position(_GP(screenover)[ovri]);
return game_to_data_coord(pos.X);
}
void Overlay_SetX(ScriptOverlay *scover, int newx) {
@ -89,10 +88,8 @@ int Overlay_GetY(ScriptOverlay *scover) {
if (ovri < 0)
quit("!invalid overlay ID specified");
int tdxp, tdyp;
get_overlay_position(_GP(screenover)[ovri], &tdxp, &tdyp);
return game_to_data_coord(tdyp);
Point pos = get_overlay_position(_GP(screenover)[ovri]);
return game_to_data_coord(pos.Y);
}
void Overlay_SetY(ScriptOverlay *scover, int newy) {
@ -347,11 +344,9 @@ size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic
return _GP(screenover).size() - 1;
}
void get_overlay_position(const ScreenOverlay &over, int *x, int *y) {
int tdxp, tdyp;
const Rect &ui_view = _GP(play).GetUIViewport();
Point get_overlay_position(const ScreenOverlay &over) {
if (over.x == OVR_AUTOPLACE) {
const Rect &ui_view = _GP(play).GetUIViewport();
// auto place on character
int charid = over.y;
@ -359,13 +354,12 @@ void get_overlay_position(const ScreenOverlay &over, int *x, int *y) {
const int charpic = _GP(views)[_GP(game).chars[charid].view].loops[_GP(game).chars[charid].loop].frames[0].pic;
const int height = (_GP(charextra)[charid].height < 1) ? _GP(game).SpriteInfos[charpic].Height : _GP(charextra)[charid].height;
Point screenpt = view->RoomToScreen(
data_to_game_coord(_GP(game).chars[charid].x),
data_to_game_coord(_GP(game).chars[charid].get_effective_y()) - height).first;
tdxp = screenpt.X - over.pic->GetWidth() / 2;
if (tdxp < 0) tdxp = 0;
tdyp = screenpt.Y - get_fixed_pixel_size(5);
data_to_game_coord(_GP(game).chars[charid].x),
data_to_game_coord(_GP(game).chars[charid].get_effective_y()) - height).first;
int tdxp = std::max(0, screenpt.X - over.pic->GetWidth() / 2);
int tdyp = screenpt.Y - get_fixed_pixel_size(5);
tdyp -= over.pic->GetHeight();
if (tdyp < 5) tdyp = 5;
tdyp = std::max(5, tdyp);
if ((tdxp + over.pic->GetWidth()) >= ui_view.GetWidth())
tdxp = (ui_view.GetWidth() - over.pic->GetWidth()) - 1;
@ -373,20 +367,16 @@ void get_overlay_position(const ScreenOverlay &over, int *x, int *y) {
tdxp = ui_view.GetWidth() / 2 - over.pic->GetWidth() / 2;
tdyp = ui_view.GetHeight() / 2 - over.pic->GetHeight() / 2;
}
return Point(tdxp, tdyp);
} else {
// Note: the internal offset is only needed when x,y coordinates are specified
// and only in the case where the overlay is using a GUI. See issue #1098
tdxp = over.x + over.offsetX;
tdyp = over.y + over.offsetY;
if (!over.positionRelativeToScreen) {
Point tdxy = _GP(play).RoomToScreen(tdxp, tdyp);
tdxp = tdxy.X;
tdyp = tdxy.Y;
}
int tdxp = over.x + over.offsetX;
int tdyp = over.y + over.offsetY;
if (over.positionRelativeToScreen)
return Point(tdxp, tdyp);
return _GP(play).RoomToScreen(tdxp, tdyp);
}
*x = tdxp;
*y = tdyp;
}
void recreate_overlay_ddbs() {

View File

@ -22,6 +22,7 @@
#ifndef AGS_ENGINE_AC_OVERLAY_H
#define AGS_ENGINE_AC_OVERLAY_H
#include "ags/shared/util/geometry.h"
#include "ags/engine/ac/screen_overlay.h"
#include "ags/engine/ac/dynobj/script_overlay.h"
@ -48,7 +49,7 @@ ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colo
int find_overlay_of_type(int type);
void remove_screen_overlay(int type);
// Calculates overlay position in screen coordinates
void get_overlay_position(const ScreenOverlay &over, int *x, int *y);
Point get_overlay_position(const ScreenOverlay &over);
size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, bool alphaChannel = false);
size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic_offx, int pic_offy, bool alphaChannel = false);
void remove_screen_overlay_index(size_t over_idx);