Skip to content

Commit

Permalink
Added Auto Crop Image inputevent, possible to map in Custom Controls.…
Browse files Browse the repository at this point in the history
… Does the same thing auto-height did, but only once and on-demand.
  • Loading branch information
midwan committed Mar 19, 2022
1 parent c9f63c7 commit b62a9ac
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/aks.def
Expand Up @@ -141,4 +141,5 @@ AKS(MOUSE_SPEED_DOWN)
AKS(MOUSE_SPEED_UP)
AKS(SHUTDOWN)
AKS(TOGGLE_JIT)
AKS(TOGGLE_JIT_FPU)
AKS(TOGGLE_JIT_FPU)
AKS(AUTO_CROP_IMAGE)
3 changes: 3 additions & 0 deletions src/inputdevice.cpp
Expand Up @@ -4773,6 +4773,9 @@ static bool inputdevice_handle_inputcode2(int monid, int code, int state, const
#endif
break;
#endif
case AKS_AUTO_CROP_IMAGE:
auto_crop_image();
break;
}
end:
if (tracer_enable) {
Expand Down
2 changes: 2 additions & 0 deletions src/inputevents.def
Expand Up @@ -470,6 +470,8 @@ DEFEVENT(SPC_SHUTDOWN, _T("Shutdown System"),AM_K,0,0,AKS_SHUTDOWN)
DEFEVENT(SPC_TOGGLE_JIT, _T("Toggle JIT"),AM_K,0,0,AKS_TOGGLE_JIT)
DEFEVENT(SPC_TOGGLE_JIT_FPU, _T("Toggle JIT FPU"),AM_K,0,0,AKS_TOGGLE_JIT_FPU)

DEFEVENT(SPC_AUTO_CROP_IMAGE, _T("Auto crop image"),AM_K,0,0,AKS_AUTO_CROP_IMAGE)

#endif

DEFEVENT(SPC_LAST, _T(""), AM_DUMMY, 0,0,0)
58 changes: 33 additions & 25 deletions src/osdep/amiberry_gfx.cpp
Expand Up @@ -899,44 +899,52 @@ extern int vstrt; // vertical start
extern int vstop; // vertical stop
extern int hstrt; // horizontal start
extern int hstop; // horizontal stop

void auto_crop_image()
{
static int new_height;

auto start_y = minfirstline; // minfirstline = first line to be written to screen buffer
auto stop_y = MAXVPOS_PAL + minfirstline; // last line to be written to screen buffer
if (vstrt > minfirstline)
start_y = vstrt; // if vstrt > minfirstline then there is a black border
if (start_y > 200)
start_y = minfirstline; // shouldn't happen but does for donkey kong
if (vstop < stop_y)
stop_y = vstop; // if vstop < stop_y then there is a black border

new_height = stop_y - start_y;

if (new_height < 200)
new_height = 200;
new_height = new_height * 2 <= 568 ? new_height * 2 : 568;
if (new_height != currprefs.gfx_monitor[0].gfx_size_win.height)
{
display_height = new_height;
currprefs.gfx_monitor[0].gfx_size_win.height = new_height;
copy_prefs(&currprefs, &changed_prefs);
open_screen(&currprefs);
init_custom();
}
}

void flush_screen(const vidbuffer* vidbuffer, int ystart, int ystop)
{
if (vidbuffer->bufmem == nullptr) return; // no buffer allocated return

static bool last_autoheight;
if (currprefs.gfx_auto_height)
{
static int last_vstrt, last_vstop, new_height;
if (last_autoheight != currprefs.gfx_auto_height
|| last_vstrt != vstrt
static int last_vstrt, last_vstop;
if (last_autoheight != currprefs.gfx_auto_height
|| last_vstrt != vstrt
|| last_vstop != vstop
)
{
last_vstrt = vstrt;
last_vstop = vstop;

auto start_y = ystart > 0 ? ystart : minfirstline; // minfirstline = first line to be written to screen buffer
auto stop_y = ystop > 0 ? ystop : MAXVPOS_PAL + minfirstline; // last line to be written to screen buffer
if (vstrt > minfirstline)
start_y = vstrt; // if vstrt > minfirstline then there is a black border
if (start_y > 200)
start_y = minfirstline; // shouldn't happen but does for donkey kong
if (vstop < stop_y)
stop_y = vstop; // if vstop < stop_y then there is a black border

new_height = stop_y - start_y;

if (new_height < 200)
new_height = 200;
new_height = new_height * 2 <= 568 ? new_height * 2 : 568;
if (new_height != currprefs.gfx_monitor[0].gfx_size_win.height)
{
display_height = new_height;
currprefs.gfx_monitor[0].gfx_size_win.height = new_height;
copy_prefs(&currprefs, &changed_prefs);
open_screen(&currprefs);
init_custom();
}
auto_crop_image();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/osdep/amiberry_gfx.h
Expand Up @@ -153,4 +153,5 @@ void DX_Blit(int x, int y, int w, int h);
struct MultiDisplay* getdisplay(struct uae_prefs* p, int monid);
extern int getrefreshrate(int monid, int width, int height);
void SDL2_guimode(int monid, int guion);
void SDL2_toggle_vsync(bool vsync);
void SDL2_toggle_vsync(bool vsync);
extern void auto_crop_image();
3 changes: 2 additions & 1 deletion src/osdep/amiberry_input.cpp
Expand Up @@ -233,7 +233,8 @@ constexpr int remap_event_list[] = {
INPUTEVENT_SPC_MOUSEMAP_PORT0_LEFT, INPUTEVENT_SPC_MOUSEMAP_PORT0_RIGHT,
INPUTEVENT_SPC_MOUSEMAP_PORT1_LEFT, INPUTEVENT_SPC_MOUSEMAP_PORT1_RIGHT,
INPUTEVENT_SPC_MOUSE_SPEED_DOWN, INPUTEVENT_SPC_MOUSE_SPEED_UP, INPUTEVENT_SPC_SHUTDOWN,
INPUTEVENT_SPC_WARP, INPUTEVENT_SPC_TOGGLE_JIT, INPUTEVENT_SPC_TOGGLE_JIT_FPU
INPUTEVENT_SPC_WARP, INPUTEVENT_SPC_TOGGLE_JIT, INPUTEVENT_SPC_TOGGLE_JIT_FPU,
INPUTEVENT_SPC_AUTO_CROP_IMAGE
};

constexpr int remap_event_list_size = std::size(remap_event_list);
Expand Down

0 comments on commit b62a9ac

Please sign in to comment.