Skip to content

Commit

Permalink
Add resize support to Allegro library (Windows port is ready).
Browse files Browse the repository at this point in the history
+ Add acknowledge_resize() function.
+ Add set_resize_callback() function and RESIZE_DISPLAY_EVENT structure.
  • Loading branch information
dacap committed Oct 30, 2010
1 parent 6cfc398 commit 9562e3e
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 99 deletions.
2 changes: 2 additions & 0 deletions src/allegro/include/allegro/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typedef struct GFX_DRIVER /* creates and manages the screen bitmap */
AL_METHOD(void, restore_video_state, (void));
AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a));
AL_METHOD(GFX_MODE_LIST *, fetch_mode_list, (void));
AL_METHOD(struct BITMAP *, acknowledge_resize, (void));
int w, h; /* physical (not virtual!) screen size */
int linear; /* true if video memory is linear */
long bank_size; /* bank size, in bytes */
Expand Down Expand Up @@ -410,6 +411,7 @@ AL_FUNC(int, get_color_conversion, (void));
AL_FUNC(void, request_refresh_rate, (int rate));
AL_FUNC(int, get_refresh_rate, (void));
AL_FUNC(int, set_gfx_mode, (int card, int w, int h, int v_w, int v_h));
AL_FUNC(int, acknowledge_resize, (void));
AL_FUNC(int, scroll_screen, (int x, int y));
AL_FUNC(int, request_scroll, (int x, int y));
AL_FUNC(int, poll_scroll, (void));
Expand Down
1 change: 1 addition & 0 deletions src/allegro/include/allegro/platform/aintwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ AL_VAR(int, wnd_height);
AL_VAR(int, wnd_sysmenu);

AL_FUNCPTR(void, user_close_proc, (void));
AL_FUNCPTR(void, user_resize_proc, (RESIZE_DISPLAY_EVENT *ev));


/* gfx synchronization */
Expand Down
11 changes: 10 additions & 1 deletion src/allegro/include/allegro/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ struct BITMAP;
struct GFX_VTABLE;
struct GFX_MODE;

typedef struct RESIZE_DISPLAY_EVENT
{
int old_w, old_h;
int new_w, new_h;
int is_maximized : 1; /* 1 if this event is because the user maximized the window */
int is_restored : 1; /* 1 if this event is because the user restored the window */
} RESIZE_DISPLAY_EVENT;

#define ALLEGRO_ERROR_SIZE 256

AL_ARRAY(char, allegro_id);
Expand Down Expand Up @@ -95,7 +103,7 @@ AL_FUNC(void, allegro_exit, (void));
AL_PRINTFUNC(void, allegro_message, (AL_CONST char *msg, ...), 1, 2);
AL_FUNC(void, get_executable_name, (char *output, int size));
AL_FUNC(int, set_close_button_callback, (AL_METHOD(void, proc, (void))));

AL_FUNC(int, set_resize_callback, (AL_METHOD(void, proc, (RESIZE_DISPLAY_EVENT *ev))));

AL_FUNC(void, check_cpu, (void));

Expand Down Expand Up @@ -207,6 +215,7 @@ typedef struct SYSTEM_DRIVER
AL_METHOD(int, find_resource, (char *dest, AL_CONST char *resource, int size));
AL_METHOD(void, set_window_title, (AL_CONST char *name));
AL_METHOD(int, set_close_button_callback, (AL_METHOD(void, proc, (void))));
AL_METHOD(int, set_resize_callback, (AL_METHOD(void, proc, (RESIZE_DISPLAY_EVENT *ev))));
AL_METHOD(void, message, (AL_CONST char *msg));
AL_METHOD(void, assert, (AL_CONST char *msg));
AL_METHOD(void, save_console_state, (void));
Expand Down
21 changes: 20 additions & 1 deletion src/allegro/src/allegro.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ static int _install_allegro(int system_id, int *errno_ptr, int (*atexit_ptr)(voi
/* disable close button */
set_close_button_callback(NULL);

/* disable resize */
set_resize_callback(NULL);

/* detect CPU type */
check_cpu();

Expand Down Expand Up @@ -541,6 +544,22 @@ int set_close_button_callback(void (*proc)(void))



/* set_resize_callback:
* Installs a callback function to be called when the window is
* resized.
*/
int set_resize_callback(void (*proc)(RESIZE_DISPLAY_EVENT *ev))
{
ASSERT(system_driver);

if (system_driver->set_resize_callback)
return system_driver->set_resize_callback(proc);

return -1;
}



/* debug_exit:
* Closes the debugging output files.
*/
Expand Down Expand Up @@ -753,7 +772,7 @@ SYSTEM_DRIVER system_none =
sys_none_exit,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
sys_no_driver, sys_no_driver, sys_no_driver, sys_no_driver
};

29 changes: 29 additions & 0 deletions src/allegro/src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,35 @@ int set_gfx_mode(int card, int w, int h, int v_w, int v_h)



int acknowledge_resize(void)
{
ASSERT(system_driver);
ASSERT(gfx_driver);

TRACE(PREFIX_I "acknowledge_resize init.\n");

if (gfx_driver->acknowledge_resize) {
BITMAP *new_screen = gfx_driver->acknowledge_resize();
if (!new_screen) {
TRACE(PREFIX_I "acknowledge_resize failed.\n");
return -1;
}

TRACE(PREFIX_I "acknowledge_resize succeeded.\n");

screen = new_screen;

if (_al_linker_mouse)
_al_linker_mouse->set_mouse_etc();

return 0;
}

return 0;
}



/* _set_gfx_mode:
* Called by set_gfx_mode(). Separated to make a clear difference between
* the virtual GFX_SAFE driver and the rest. The allow_config parameter,
Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/macosx/qzfull.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
NULL, /* AL_METHOD(void, restore_video_state, (void)); */
NULL, /* AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a)); */
osx_qz_fetch_mode_list, /* AL_METHOD(int, fetch_mode_list, (void)); */
NULL, /* acknowledge_resize */
0, 0, /* physical (not virtual!) screen size */
TRUE, /* true if video memory is linear */
0, /* bank size, in bytes */
Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/macosx/qzwindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
NULL, /* AL_METHOD(void, restore_video_state, (void)); */
NULL, /* AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a)); */
NULL, /* AL_METHOD(int, fetch_mode_list, (void)); */
NULL, /* acknowledge_resize */
0, 0, /* physical (not virtual!) screen size */
TRUE, /* true if video memory is linear */
0, /* bank size, in bytes */
Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/macosx/system.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
osx_sys_find_resource,
osx_sys_set_window_title,
osx_sys_set_close_button_callback,
NULL, /* set_resize_callback */
osx_sys_message,
NULL, /* AL_METHOD(void, assert, (AL_CONST char *msg)); */
NULL, /* AL_METHOD(void, save_console_state, (void)); */
Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/misc/vbeaf.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ GFX_DRIVER gfx_vbeaf =
vbeaf_restore,
NULL, /* AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a)); */
vbeaf_fetch_mode_list, /* fetch mode hook */
NULL, /* acknowledge_resize */
0, 0, FALSE, 0, 0, 0, 0, FALSE
};

Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/misc/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ GFX_DRIVER gfx_vga =
_restore_vga_mode,
NULL, /* AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a)); */
vga_fetch_mode_list,
NULL, /* acknowledge_resize */
320, 200,
TRUE,
0, 0,
Expand Down
4 changes: 3 additions & 1 deletion src/allegro/src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,9 @@ static void set_mouse_etc(void)

set_mouse_range(0, 0, SCREEN_W-1, SCREEN_H-1);
set_mouse_speed(2, 2);
position_mouse(SCREEN_W/2, SCREEN_H/2);

/* As now we support window resizing, it's not recommended to change the mouse position. */
/*position_mouse(SCREEN_W/2, SCREEN_H/2);*/
}


Expand Down
3 changes: 3 additions & 0 deletions src/allegro/src/win/wddfull.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GFX_DRIVER gfx_directx_accel =
NULL, // AL_METHOD(void, restore_video_state, (void*));
NULL, // AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a));
gfx_directx_fetch_mode_list,
NULL, /* acknowledge_resize */
0, 0, // physical (not virtual!) screen size
TRUE, // true if video memory is linear
0, // bank size, in bytes
Expand Down Expand Up @@ -95,6 +96,7 @@ GFX_DRIVER gfx_directx_soft =
NULL, // AL_METHOD(void, restore_video_state, (void*));
NULL, // AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a));
gfx_directx_fetch_mode_list,
NULL, /* acknowledge_resize */
0, 0, // physical (not virtual!) screen size
TRUE, // true if video memory is linear
0, // bank size, in bytes
Expand Down Expand Up @@ -129,6 +131,7 @@ GFX_DRIVER gfx_directx_safe =
NULL, // AL_METHOD(void, restore_video_state, (void*));
NULL, // AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a));
gfx_directx_fetch_mode_list,
NULL, /* acknowledge_resize */
0, 0, // physical (not virtual!) screen size
TRUE, // true if video memory is linear
0, // bank size, in bytes
Expand Down
1 change: 1 addition & 0 deletions src/allegro/src/win/wddovl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ GFX_DRIVER gfx_directx_ovl =
NULL, // AL_METHOD(void, restore_video_state, (void*));
NULL, // AL_METHOD(void, set_blender_mode, (int mode, int r, int g, int b, int a));
NULL, // AL_METHOD(int, fetch_mode_list, (void));
NULL, /* acknowledge_resize */
0, 0, // int w, h; /* physical (not virtual!) screen size */
TRUE, // int linear; /* true if video memory is linear */
0, // long bank_size; /* bank size, in bytes */
Expand Down
Loading

0 comments on commit 9562e3e

Please sign in to comment.