[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Huff!
I finally found some time to spend on BeAllegro... Here's the result so far:
this patch fixes the desktop_color_depth() problem reported a while ago (I've
checked the routine now, and it works), and adds support for the new window
close behaviour. The window close button can be enabled and disabled, and by
default (close hook NULL) on close requests it displays a system alert box
prompting the shutdown message discussed earlier. About this message: I've
added an ALLEGRO_WINDOW_CLOSE_MESSAGE that #defines it to allegro.h to avoid
message typing errors, so other ports can use this.
Next I'll work on the X window closing support; it'll probably come tomorrow.
Out of topic: I've seen the best improvement to the lib while I was away from
the list was the scene3d support... Am I right? Really great work Bertrand
(and Adrian)! Now we only need a cool new example - maybe something with a
big moveable model in it. :-)
--
Angelo Mottola
a.mottola@xxxxxxxxxx
ICQ UIN #66972680
diff -Nru allegro.cvs/include/allegro/aintbeos.h allegro/include/allegro/aintbeos.h
--- allegro.cvs/include/allegro/aintbeos.h Fri Feb 16 12:43:44 2001
+++ allegro/include/allegro/aintbeos.h Fri Feb 16 19:38:35 2001
@@ -36,7 +36,9 @@
void be_key_exit(void);
void be_key_set_leds(int leds);
void be_key_wait_for_input(void);
-void be_key_stop_waiting_for_input(void);
+void be_key_stop_waiting_for_input(void);
+void be_key_suspend(void);
+void be_key_resume(void);
int be_sys_init(void);
void be_sys_exit(void);
@@ -44,6 +46,8 @@
void be_sys_get_executable_name(char *output, int size);
int be_sys_find_resource(char *dest, AL_CONST char *resource, int size);
void be_sys_set_window_title(AL_CONST char *name);
+int be_sys_set_window_close_button(int enable);
+void be_sys_set_window_close_hook(void (*proc)(void));
void be_sys_message(AL_CONST char *msg);
int be_sys_desktop_color_depth(void);
void be_sys_yield_timeslice(void);
diff -Nru allegro.cvs/include/allegro.h allegro/include/allegro.h
--- allegro.cvs/include/allegro.h Fri Feb 16 12:43:45 2001
+++ allegro/include/allegro.h Fri Feb 16 13:52:03 2001
@@ -121,6 +121,11 @@
AL_PRINTFUNC(void, allegro_message, (AL_CONST char *msg, ...), 1, 2);
+#define ALLEGRO_WINDOW_CLOSE_MESSAGE \
+ "Warning: forcing program shutdown may lead to data loss and unexpected " \
+ "results. It is preferable to use the exit command inside the window.\n\n" \
+ "Proceed anyway?"
+
AL_FUNC(void, al_assert, (AL_CONST char *file, int line));
AL_PRINTFUNC(void, al_trace, (AL_CONST char *msg, ...), 1, 2);
diff -Nru allegro.cvs/include/bealleg.h allegro/include/bealleg.h
--- allegro.cvs/include/bealleg.h Fri Feb 16 12:43:45 2001
+++ allegro/include/bealleg.h Fri Feb 16 19:18:43 2001
@@ -217,10 +217,10 @@
extern const BE_MODE_TABLE be_mode_table[];
extern int32 (*be_sync_func)();
extern int _be_switch_mode;
+extern void (*be_window_close_hook)();
-
-void be_terminate(thread_id caller);
+void be_terminate(thread_id caller, bool exit_caller);
diff -Nru allegro.cvs/src/beos/bgfxapi.cpp allegro/src/beos/bgfxapi.cpp
--- allegro.cvs/src/beos/bgfxapi.cpp Fri Feb 16 12:44:01 2001
+++ allegro/src/beos/bgfxapi.cpp Fri Feb 16 21:37:19 2001
@@ -80,7 +80,9 @@
BeAllegroWindow *be_allegro_window = NULL;
BeAllegroView *be_allegro_view = NULL;
BeAllegroScreen *be_allegro_screen = NULL;
-
+
+void (*be_window_close_hook)() = NULL;
+
static uint32 cmap[0x1000];
static uint32 rmap[256];
static uint32 gmap[256];
@@ -394,6 +396,7 @@
if (_be_switch_mode == SWITCH_BACKAMNESIA)
break;
case SWITCH_PAUSE:
+ be_key_resume();
be_sound_resume();
be_time_resume();
be_sys_resume();
@@ -419,6 +422,7 @@
case SWITCH_PAUSE:
if (be_midisynth)
be_midisynth->AllNotesOff(false);
+ be_key_suspend();
be_sound_suspend();
be_time_suspend();
be_sys_suspend();
@@ -431,6 +435,24 @@
+static inline bool handle_window_close(const char *title)
+{
+ if (be_window_close_hook != NULL) {
+ be_window_close_hook();
+ }
+ else {
+ BAlert *close_alert = new BAlert(title,
+ uconvert_toascii(get_config_text(ALLEGRO_WINDOW_CLOSE_MESSAGE), NULL),
+ "Yes", "No", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
+ close_alert->SetShortcut(1, B_ESCAPE);
+ if (close_alert->Go() == 0)
+ be_terminate(0, false);
+ }
+ return false;
+}
+
+
+
/* BeAllegroScreen::BeAllegroScreen:
*/
BeAllegroScreen::BeAllegroScreen(const char *title, uint32 space, status_t *error, bool debugging)
@@ -460,7 +482,7 @@
*/
bool BeAllegroScreen::QuitRequested(void)
{
- return false;
+ return handle_window_close(be_allegro_screen->Title());
}
@@ -1169,7 +1191,7 @@
*/
bool BeAllegroWindow::QuitRequested(void)
{
- return false;
+ return handle_window_close(be_allegro_window->Title());
}
diff -Nru allegro.cvs/src/beos/bkeyapi.cpp allegro/src/beos/bkeyapi.cpp
--- allegro.cvs/src/beos/bkeyapi.cpp Fri Feb 16 12:44:01 2001
+++ allegro/src/beos/bkeyapi.cpp Fri Feb 16 19:19:21 2001
@@ -495,7 +495,7 @@
(_key_shifts & KB_CTRL_FLAG) &&
(_key_shifts & KB_ALT_FLAG) &&
(key_info_new.key_states[52 / 8] & (52 % 8)) ) {
- be_terminate(keyboard_thread_id);
+ be_terminate(keyboard_thread_id, true);
}
for(i = 0; i < 16; i++) {
diff -Nru allegro.cvs/src/beos/bsysapi.cpp allegro/src/beos/bsysapi.cpp
--- allegro.cvs/src/beos/bsysapi.cpp Fri Feb 16 12:44:01 2001
+++ allegro/src/beos/bsysapi.cpp Fri Feb 16 21:54:07 2001
@@ -276,13 +276,39 @@
if (be_allegro_window != NULL) {
be_allegro_window->SetTitle(uname);
}
- else {
+ else if (be_allegro_screen != NULL) {
be_allegro_screen->SetTitle(uname);
}
}
+extern "C" int be_sys_set_window_close_button(int enable)
+{
+ if (be_allegro_window != NULL) {
+ if (enable)
+ be_allegro_window->SetFlags(be_allegro_window->Flags() & ~B_NOT_CLOSABLE);
+ else
+ be_allegro_window->SetFlags(be_allegro_window->Flags() | B_NOT_CLOSABLE);
+ }
+ else if (be_allegro_screen != NULL) {
+ if (enable)
+ be_allegro_screen->SetFlags(be_allegro_screen->Flags() & ~B_NOT_CLOSABLE);
+ else
+ be_allegro_screen->SetFlags(be_allegro_screen->Flags() | B_NOT_CLOSABLE);
+ }
+ return 0;
+}
+
+
+
+extern "C" void be_sys_set_window_close_hook(void (*proc)(void))
+{
+ be_window_close_hook = proc;
+}
+
+
+
extern "C" void be_sys_message(AL_CONST char *msg)
{
char filename[MAXPATHLEN];
@@ -303,14 +329,20 @@
extern "C" int be_sys_desktop_color_depth(void)
{
display_mode current_mode;
- int index = 0;
BScreen(be_allegro_screen).GetMode(¤t_mode);
- while (be_mode_table[index].d > 0) {
- if (be_mode_table[index].mode == current_mode.space)
- return be_mode_table[index].d;
- index++;
- }
+ switch(current_mode.space) {
+ case B_CMAP8:
+ return 8;
+ case B_RGB15:
+ case B_RGBA15:
+ return 15;
+ case B_RGB16:
+ return 16;
+ case B_RGB32:
+ case B_RGBA32:
+ return 32;
+ }
return -1;
}
@@ -374,12 +406,13 @@
-void be_terminate(thread_id caller)
+void be_terminate(thread_id caller, bool exit_caller)
{
thread_id killer;
killer = spawn_thread(killer_thread, "son of sam", 120, NULL);
resume_thread(killer);
- exit_thread(1);
+ if (exit_caller)
+ exit_thread(1);
}
diff -Nru allegro.cvs/src/beos/bsystem.c allegro/src/beos/bsystem.c
--- allegro.cvs/src/beos/bsystem.c Fri Feb 16 12:44:01 2001
+++ allegro/src/beos/bsystem.c Fri Feb 16 12:59:40 2001
@@ -35,8 +35,8 @@
be_sys_get_executable_name, // AL_METHOD(void, get_executable_name, (char *output, int size));
be_sys_find_resource, // AL_METHOD(int, find_resource, (char *dest, char *resource, int size));
be_sys_set_window_title, // AL_METHOD(void, set_window_title, (char *name));
- NULL, // AL_METHOD(int, set_window_close_button, (int enable));
- NULL, // AL_METHOD(void, set_window_close_hook, (void (*proc)()));
+ be_sys_set_window_close_button, // AL_METHOD(int, set_window_close_button, (int enable));
+ be_sys_set_window_close_hook, // AL_METHOD(void, set_window_close_hook, (void (*proc)()));
be_sys_message, // AL_METHOD(void, message, (char *msg));
NULL, // AL_METHOD(void, assert, (char *msg));
NULL, // AL_METHOD(void, save_console_state, (void));