diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 269ae6185..592df6776 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D1X-Rebirth Changelog -------- editor/med.c, editor/texpage.c, include/editor/editor.h, main/game.c: Do a bit of a tidy up for the editor, dump code from editor() within the loop into new editor_handler() editor/info.c, editor/med.c, editor/medmisc.c, editor/objpage.c, editor/texpage.c, include/editor/objpage.h, include/editor/texpage.h, include/ui.h, ui/userbox.c: Make editor_handler into a proper callback, iron some problems out. Seems to draw a different bunch of stuff now (still erroneous) +SConstruct, arch/include/event.h, arch/include/mouse.h, arch/sdl/event.c, d1x-rebirth.xcodeproj/project.pbxproj, editor/info.c, editor/macro.c, editor/med.c, editor/meddraw.c, editor/medmisc.c, include/ui.h, ui/button.c, ui/checkbox.c, ui/dialog.c, ui/file.c, ui/icon.c, ui/inputbox.c, ui/listbox.c, ui/menubar.c, ui/mouse.c, ui/radio.c, ui/scroll.c, ui/ui.c, ui/userbox.c: Remove redundant ui_event_process and duplicate mouse.c in ui/. All editor input is now event-based. 20120317 -------- diff --git a/SConstruct b/SConstruct index f68e21b74..dc15b8be4 100644 --- a/SConstruct +++ b/SConstruct @@ -224,7 +224,6 @@ editor_sources = [ 'ui/menu.c', 'ui/menubar.c', 'ui/message.c', -'ui/mouse.c', 'ui/popup.c', 'ui/radio.c', 'ui/scroll.c', diff --git a/arch/include/event.h b/arch/include/event.h index e30a2c533..85543ba89 100644 --- a/arch/include/event.h +++ b/arch/include/event.h @@ -60,4 +60,8 @@ void event_process(); void event_toggle_focus(int activate_focus); +// See how long we were idle for +void event_reset_idle_seconds(); +int32_t event_get_idle_seconds(); + #endif diff --git a/arch/include/mouse.h b/arch/include/mouse.h index 272a7fa6d..4432021f5 100644 --- a/arch/include/mouse.h +++ b/arch/include/mouse.h @@ -45,5 +45,6 @@ extern int mouse_in_window(struct window *wind); extern void mouse_get_delta( int *dx, int *dy, int *dz ); extern void event_mouse_get_delta(struct d_event *event, int *dx, int *dy, int *dz); extern int mouse_get_btns(); +extern void mouse_toggle_cursor(int activate); #endif diff --git a/arch/sdl/event.c b/arch/sdl/event.c index 81cd4e026..4b68aa478 100644 --- a/arch/sdl/event.c +++ b/arch/sdl/event.c @@ -10,6 +10,7 @@ #include #include "event.h" #include "key.h" +#include "mouse.h" #include "window.h" #include "timer.h" #include "config.h" @@ -23,7 +24,6 @@ extern void joy_button_handler(SDL_JoyButtonEvent *jbe); extern void joy_hat_handler(SDL_JoyHatEvent *jhe); extern int joy_axis_handler(SDL_JoyAxisEvent *jae); extern void mouse_cursor_autohide(); -extern void mouse_toggle_cursor(int activate); static int initialised=0; @@ -87,6 +87,8 @@ void event_poll() ievent.type = EVENT_IDLE; event_send(&ievent); } + else + event_reset_idle_seconds(); mouse_cursor_autohide(); } @@ -187,3 +189,15 @@ void event_toggle_focus(int activate_focus) mouse_toggle_cursor(!activate_focus); } +static fix64 last_event = 0; + +void event_reset_idle_seconds() +{ + last_event = timer_query(); +} + +fix event_get_idle_seconds() +{ + return (timer_query() - last_event)/F1_0; +} + diff --git a/d1x-rebirth.xcodeproj/project.pbxproj b/d1x-rebirth.xcodeproj/project.pbxproj index 525dead84..2724df543 100755 --- a/d1x-rebirth.xcodeproj/project.pbxproj +++ b/d1x-rebirth.xcodeproj/project.pbxproj @@ -392,7 +392,6 @@ EBECB67012C041C100D660B3 /* menu.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC6519E0890CEAE004FCAA3 /* menu.c */; }; EBECB67112C041C700D660B3 /* menubar.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC6519F0890CEAE004FCAA3 /* menubar.c */; }; EBECB67212C041CD00D660B3 /* message.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC651A00890CEAE004FCAA3 /* message.c */; }; - EBECB67312C041D100D660B3 /* mouse.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC651A10890CEAE004FCAA3 /* mouse.c */; }; EBECB67412C041D200D660B3 /* popup.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC651A30890CEAE004FCAA3 /* popup.c */; }; EBECB67512C041D500D660B3 /* radio.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC651A40890CEAE004FCAA3 /* radio.c */; }; EBECB67612C041DC00D660B3 /* scroll.c in Sources */ = {isa = PBXBuildFile; fileRef = EBC651A50890CEAE004FCAA3 /* scroll.c */; }; @@ -765,7 +764,6 @@ EBC6519E0890CEAE004FCAA3 /* menu.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = menu.c; sourceTree = ""; }; EBC6519F0890CEAE004FCAA3 /* menubar.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = menubar.c; sourceTree = ""; }; EBC651A00890CEAE004FCAA3 /* message.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = message.c; sourceTree = ""; }; - EBC651A10890CEAE004FCAA3 /* mouse.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = mouse.c; sourceTree = ""; }; EBC651A30890CEAE004FCAA3 /* popup.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = popup.c; sourceTree = ""; }; EBC651A40890CEAE004FCAA3 /* radio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = radio.c; sourceTree = ""; }; EBC651A50890CEAE004FCAA3 /* scroll.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = scroll.c; sourceTree = ""; }; @@ -832,8 +830,6 @@ EBF658940F93684000CB5C73 /* ipx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx.c; sourceTree = ""; }; EBF658950F93684000CB5C73 /* ipx_kali.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx_kali.c; sourceTree = ""; }; EBF658960F93686000CB5C73 /* ipx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx.c; sourceTree = ""; }; - EBF658990F936A8400CB5C73 /* net_ipx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = net_ipx.c; sourceTree = ""; }; - EBF6589A0F936A8400CB5C73 /* net_ipx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = net_ipx.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1141,7 +1137,6 @@ 676032DC066B399A008A67A3 /* multi.c */, 676032DD066B399A008A67A3 /* multibot.c */, EBEEB2660D2B364300FF39B4 /* mute.c */, - EBF658990F936A8400CB5C73 /* net_ipx.c */, 17DFA6AF10C1A29500674D11 /* net_udp.c */, 67B4473D06687CF400DF26D8 /* newdemo.c */, 67B4473F06687CF400DF26D8 /* newmenu.c */, @@ -1209,7 +1204,6 @@ EB0420B90A341041002CC961 /* multi.h */, EB0420E70A341042002CC961 /* multibot.h */, EBEEB2670D2B364300FF39B4 /* mute.h */, - EBF6589A0F936A8400CB5C73 /* net_ipx.h */, 17DFA6B210C1A2A300674D11 /* net_udp.h */, EB01AFA90A65323200EA4C7C /* newdemo.h */, EB0420DE0A341042002CC961 /* newmenu.h */, @@ -1463,7 +1457,6 @@ EBC6519E0890CEAE004FCAA3 /* menu.c */, EBC6519F0890CEAE004FCAA3 /* menubar.c */, EBC651A00890CEAE004FCAA3 /* message.c */, - EBC651A10890CEAE004FCAA3 /* mouse.c */, EBC651A30890CEAE004FCAA3 /* popup.c */, EBC651A40890CEAE004FCAA3 /* radio.c */, EBC651A50890CEAE004FCAA3 /* scroll.c */, @@ -1915,7 +1908,6 @@ EBECB67012C041C100D660B3 /* menu.c in Sources */, EBECB67112C041C700D660B3 /* menubar.c in Sources */, EBECB67212C041CD00D660B3 /* message.c in Sources */, - EBECB67312C041D100D660B3 /* mouse.c in Sources */, EBECB67412C041D200D660B3 /* popup.c in Sources */, EBECB67512C041D500D660B3 /* radio.c in Sources */, EBECB67612C041DC00D660B3 /* scroll.c in Sources */, diff --git a/editor/info.c b/editor/info.c index a9248a367..b1c63539e 100644 --- a/editor/info.c +++ b/editor/info.c @@ -317,10 +317,6 @@ int info_display_all(window *wind, d_event *event, void *userdata) int padnum,show_all = 0; grs_canvas *save_canvas = grd_curcanv; - // HACK: Make sure all the state-based input variables are set, until we fully migrate to event-based input - if (wind == window_get_front()) - ui_event_handler(event); - switch (event->type) { case EVENT_WINDOW_DRAW: diff --git a/editor/macro.c b/editor/macro.c index 98edbd93d..498225a7a 100644 --- a/editor/macro.c +++ b/editor/macro.c @@ -85,7 +85,7 @@ int MacroPlayFast() { if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer ) { - ui_mouse_hide(); + mouse_toggle_cursor(0); ui_play_events_fast(MacroNumEvents, RecordBuffer); MacroStatus = UI_STATUS_FASTPLAY; } diff --git a/editor/med.c b/editor/med.c index bb40097e9..709659c63 100644 --- a/editor/med.c +++ b/editor/med.c @@ -437,9 +437,7 @@ void init_editor() // _MARK_("start of editor");//Nuked to compile -KRB - ui_mouse_hide(); - - ui_reset_idle_seconds(); + mouse_toggle_cursor(0); //@@ //create a camera for viewing in the editor. copy position from ConsoleObject //@@ camera_objnum = obj_create(OBJ_CAMERA,0,ConsoleObject->segnum,&ConsoleObject->pos,&ConsoleObject->orient,0); @@ -468,7 +466,7 @@ void init_editor() //gr_deaccent_canvas(); //gr_grey_canvas(); - ui_mouse_show(); + mouse_toggle_cursor(1); gr_set_curfont(editor_font); ui_pad_goto(padnum); @@ -1121,10 +1119,10 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) } } - if ( ui_get_idle_seconds() > COMPRESS_INTERVAL ) + if ( event_get_idle_seconds() > COMPRESS_INTERVAL ) { med_compress_mine(); - ui_reset_idle_seconds(); + event_reset_idle_seconds(); } // Commented out because it occupies about 25% of time in twirling the mine. @@ -1295,11 +1293,11 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) x = GameViewBox->b1_drag_x2; y = GameViewBox->b1_drag_y2; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( GameViewBox->canvas ); gr_setcolor( 15 ); gr_rect( x-1, y-1, x+1, y+1 ); - ui_mouse_show(); + mouse_toggle_cursor(1); } @@ -1347,7 +1345,7 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) texpage_grab_current(tmap); editor_status( "Texture grabbed." ); } else if (keyd_pressed[ KEY_LAPOSTRO] ) { - ui_mouse_hide(); + mouse_toggle_cursor(0); move_object_to_mouse_click(); } else { Cursegp = &Segments[seg]; @@ -1370,7 +1368,7 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) int dx, dy, dz; event_mouse_get_delta(event, &dx, &dy, &dz); - ui_mouse_hide(); + mouse_toggle_cursor(0); if ((dx != 0) && (dy != 0)) { vms_matrix MouseRotMat,tempm; @@ -1383,7 +1381,7 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) rval = 1; } } else { - ui_mouse_show(); + mouse_toggle_cursor(1); } if (event->type == EVENT_MOUSE_MOVED && keyd_pressed[ KEY_Z ]) @@ -1391,14 +1389,14 @@ int editor_handler(UI_DIALOG *dlg, d_event *event, void *data) int dx, dy, dz; event_mouse_get_delta(event, &dx, &dy, &dz); - ui_mouse_hide(); + mouse_toggle_cursor(0); if (dy != 0) { current_view->ev_dist += dy*10000; current_view->ev_changed = 1; } } else { - ui_mouse_show(); + mouse_toggle_cursor(1); } return rval; diff --git a/editor/meddraw.c b/editor/meddraw.c index f947e2d52..3b07e268d 100644 --- a/editor/meddraw.c +++ b/editor/meddraw.c @@ -31,6 +31,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "wall.h" #include "switch.h" #include "key.h" +#include "mouse.h" #include "error.h" #include "medlisp.h" #include "u_mem.h" @@ -799,7 +800,7 @@ void draw_world(grs_canvas *screen_canvas,editor_view *v,segment *mine_ptr,int d gr_set_current_canvas(screen_canvas); #endif - ui_mouse_hide(); + mouse_toggle_cursor(0); //g3_set_points(Segment_points,Vertices); @@ -906,7 +907,7 @@ void draw_world(grs_canvas *screen_canvas,editor_view *v,segment *mine_ptr,int d #endif - ui_mouse_show(); + mouse_toggle_cursor(1); } @@ -928,7 +929,7 @@ void find_segments(short x,short y,grs_canvas *screen_canvas,editor_view *v,segm gr_set_current_canvas(screen_canvas); #endif - ui_mouse_hide(); + mouse_toggle_cursor(0); //g3_set_points(Segment_points,Vertices); diff --git a/editor/medmisc.c b/editor/medmisc.c index 23fff0656..af8e9cebf 100644 --- a/editor/medmisc.c +++ b/editor/medmisc.c @@ -27,6 +27,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "u_mem.h" #include "error.h" #include "key.h" +#include "mouse.h" #include "func.h" #include "inferno.h" #include "editor/editor.h" @@ -299,10 +300,10 @@ if (!render_3d_in_big_window) Assert(render_canv->cv_bitmap.bm_w == show_canv->cv_bitmap.bm_w && render_canv->cv_bitmap.bm_h == show_canv->cv_bitmap.bm_h); - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_bm_ubitblt(show_canv->cv_bitmap.bm_w,show_canv->cv_bitmap.bm_h, 0,0,0,0,&render_canv->cv_bitmap,&show_canv->cv_bitmap); - ui_mouse_show(); + mouse_toggle_cursor(1); } Update_flags=UF_NONE; //clear flags diff --git a/include/ui.h b/include/ui.h index 2ed51073b..940805c6a 100644 --- a/include/ui.h +++ b/include/ui.h @@ -264,14 +264,6 @@ int MessageBox( short x, short y, int NumButtons, char * text, ... ); void ui_string_centered( short x, short y, char * s ); int PopupMenu( int NumItems, char * text[] ); -extern void ui_mouse_init(); -extern grs_bitmap * ui_mouse_set_pointer( grs_bitmap * new ); - -extern int ui_mouse_button_process(struct d_event *event); -extern int ui_mouse_motion_process(struct d_event *event); -extern void ui_mouse_hide(); -extern void ui_mouse_show(); - extern UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_flags flags, int (*callback)(UI_DIALOG *, struct d_event *, void *), void *userdata ); extern struct window *ui_dialog_get_window(UI_DIALOG *dlg); extern void ui_dialog_set_current_canvas(UI_DIALOG *dlg); @@ -296,7 +288,6 @@ extern void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox ); extern UI_GADGET_LISTBOX *ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list); extern void ui_mega_process(); -extern int ui_event_handler(struct d_event *event); extern void ui_get_button_size( char * text, int * width, int * height ); @@ -349,8 +340,6 @@ void ui_free( void * buffer ); UI_GADGET_KEYTRAP * ui_add_gadget_keytrap( UI_DIALOG * dlg, int key_to_trap, int (*function_to_call)(void) ); int ui_keytrap_do( UI_GADGET_KEYTRAP * keytrap, struct d_event *event ); -void ui_mouse_close(); - #define UI_RECORD_MOUSE 1 #define UI_RECORD_KEYS 2 #define UI_STATUS_NORMAL 0 @@ -399,9 +388,6 @@ void ui_barbox_open( char * text, int length ); void ui_barbox_update( int position ); void ui_barbox_close(); -void ui_reset_idle_seconds(void); -int ui_get_idle_seconds(void); - extern int ui_button_any_drawn; #endif diff --git a/ui/button.c b/ui/button.c index 3d7f75cc9..20a08f8e7 100644 --- a/ui/button.c +++ b/ui/button.c @@ -58,7 +58,7 @@ void ui_draw_button(UI_DIALOG *dlg, UI_GADGET_BUTTON * button) if ((button->status==1) || (button->position != button->oldposition)) { ui_button_any_drawn = 1; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( button->canvas ); color = button->canvas->cv_color; @@ -96,7 +96,7 @@ void ui_draw_button(UI_DIALOG *dlg, UI_GADGET_BUTTON * button) } } button->canvas->cv_color = color; - ui_mouse_show(); + mouse_toggle_cursor(1); } } diff --git a/ui/checkbox.c b/ui/checkbox.c index 3daff6227..303a84d2d 100644 --- a/ui/checkbox.c +++ b/ui/checkbox.c @@ -37,7 +37,7 @@ void ui_draw_checkbox( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox ) { checkbox->status = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( checkbox->canvas ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)checkbox) @@ -62,7 +62,7 @@ void ui_draw_checkbox( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox ) gr_ustring( checkbox->width+4, 2, checkbox->text ); - ui_mouse_show(); + mouse_toggle_cursor(1); } } diff --git a/ui/dialog.c b/ui/dialog.c index 450917a21..d34d68870 100644 --- a/ui/dialog.c +++ b/ui/dialog.c @@ -47,8 +47,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define _enable() #endif -int last_keypress = 0; - #define BORDER_WIDTH 8 static unsigned int FrameCount = 0; @@ -143,30 +141,20 @@ int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) { int rval = 0; - if (event->type == EVENT_WINDOW_CLOSED) + if (event->type == EVENT_WINDOW_CLOSED || + event->type == EVENT_WINDOW_ACTIVATED || + event->type == EVENT_WINDOW_DEACTIVATED) return 0; - // HACK: Make sure all the state-based input variables are set, until we fully migrate to event-based input - if (wind == window_get_front()) - ui_event_handler(event); - -#if 0 // must only call this once, after the gadget actions are determined - // until all the dialogs use the gadget events instead if (dlg->callback) if ((*dlg->callback)(dlg, event, dlg->userdata)) return 1; // event handled -#endif + + if (!window_exists(wind)) + return 1; switch (event->type) { - case EVENT_WINDOW_ACTIVATED: - return 0; - break; - - case EVENT_WINDOW_DEACTIVATED: - return 0; - break; - case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: case EVENT_MOUSE_MOVED: @@ -199,10 +187,6 @@ int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) break; } - if (window_exists(wind) && dlg->callback) - if ((*dlg->callback)(dlg, event, dlg->userdata)) - return 1; // event handled - return rval; } @@ -245,7 +229,7 @@ UI_DIALOG * ui_create_dialog( short x, short y, short w, short h, enum dialog_fl D_GADGET = NULL; dlg->keyboard_focus_gadget = NULL; - ui_mouse_hide(); + mouse_toggle_cursor(0); if (flags & DF_SAVE_BG) { @@ -305,7 +289,7 @@ void ui_dialog_set_current_canvas(UI_DIALOG *dlg) void ui_close_dialog( UI_DIALOG * dlg ) { - ui_mouse_hide(); + mouse_toggle_cursor(0); ui_gadget_delete_all( dlg ); @@ -329,7 +313,7 @@ void ui_close_dialog( UI_DIALOG * dlg ) d_free( dlg ); - ui_mouse_show(); + mouse_toggle_cursor(1); } void restore_state() @@ -344,18 +328,6 @@ void restore_state() } -fix64 last_event = 0; - -void ui_reset_idle_seconds() -{ - last_event = timer_query(); -} - -int ui_get_idle_seconds() -{ - return (timer_query() - last_event)/F1_0; -} - #if 0 void ui_mega_process() { @@ -609,46 +581,6 @@ void ui_mega_process() } #endif // 0 -// For setting global variables for state-based event polling, -// which will eventually be replaced with direct event handling -int ui_event_handler(d_event *event) -{ - last_keypress = 0; - - switch (event->type) - { - case EVENT_MOUSE_BUTTON_DOWN: - case EVENT_MOUSE_BUTTON_UP: - ui_mouse_button_process(event); - last_event = timer_query(); - break; - - case EVENT_MOUSE_MOVED: - ui_mouse_motion_process(event); - last_event = timer_query(); - break; - - case EVENT_KEY_COMMAND: - last_keypress = event_key_get(event); - last_event = timer_query(); - break; - - case EVENT_IDLE: - // Make sure button pressing works correctly - // Won't be needed when all of the editor uses mouse button events rather than polling - return ui_mouse_button_process(event); - - case EVENT_QUIT: - //Quitting = 1; - return 1; - - default: - break; - } - - return 0; -} - void ui_dprintf( UI_DIALOG * dlg, char * format, ... ) { char buffer[1000]; @@ -659,9 +591,9 @@ void ui_dprintf( UI_DIALOG * dlg, char * format, ... ) ui_dialog_set_current_canvas( dlg ); - ui_mouse_hide(); + mouse_toggle_cursor(0); D_TEXT_X = gr_string( D_TEXT_X, D_TEXT_Y, buffer ); - ui_mouse_show(); + mouse_toggle_cursor(1); } void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, char * format, ... ) @@ -674,8 +606,8 @@ void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, char * format, ... ) ui_dialog_set_current_canvas( dlg ); - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_string( x, y, buffer ); - ui_mouse_show(); + mouse_toggle_cursor(1); } diff --git a/ui/file.c b/ui/file.c index 2d221d3b1..38e912850 100644 --- a/ui/file.c +++ b/ui/file.c @@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "pstypes.h" #include "gr.h" #include "key.h" +#include "mouse.h" #include "strutil.h" #include "ui.h" #include "window.h" @@ -158,7 +159,7 @@ static int browser_handler(UI_DIALOG *dlg, d_event *event, browser *b) { char *p; - ui_mouse_hide(); + mouse_toggle_cursor(0); if (ui_event_get_gadget(event) == (UI_GADGET *)b->listbox2) strcpy(b->user_file->text, b->directory_list[b->listbox2->current_item]); @@ -247,7 +248,7 @@ static int browser_handler(UI_DIALOG *dlg, d_event *event, browser *b) } - ui_mouse_show(); + mouse_toggle_cursor(1); rval = 1; } diff --git a/ui/icon.c b/ui/icon.c index 1d7e57105..2c84c34dc 100644 --- a/ui/icon.c +++ b/ui/icon.c @@ -76,7 +76,7 @@ void ui_draw_icon( UI_GADGET_ICON * icon ) { icon->status = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( icon->canvas ); gr_get_string_size(icon->text, &width, &height, &avg ); @@ -105,7 +105,7 @@ void ui_draw_icon( UI_GADGET_ICON * icon ) gr_set_fontcolor( CBLACK, -1 ); gr_ustring( x, y, icon->text ); - ui_mouse_show(); + mouse_toggle_cursor(1); } } diff --git a/ui/inputbox.c b/ui/inputbox.c index 05137ecc7..c7a778a42 100644 --- a/ui/inputbox.c +++ b/ui/inputbox.c @@ -26,6 +26,7 @@ static char rcsid[] = "$Id: inputbox.c,v 1.1.1.1 2006/03/17 19:52:23 zicodxx Exp #include "gr.h" #include "ui.h" #include "key.h" +#include "mouse.h" // insert character c into string s at position p. void strcins(char *s, int p, char c) @@ -50,7 +51,7 @@ void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox ) if ((inputbox->status==1) || (inputbox->position != inputbox->oldposition)) { - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( inputbox->canvas ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)inputbox) @@ -78,7 +79,7 @@ void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox ) Vline( 2,inputbox->height-3, 2+w+2 ); } - ui_mouse_show(); + mouse_toggle_cursor(1); } } diff --git a/ui/listbox.c b/ui/listbox.c index fe86fee5a..024162155 100644 --- a/ui/listbox.c +++ b/ui/listbox.c @@ -50,7 +50,7 @@ void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox ) listbox->status = 0; x = y = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( listbox->canvas ); for (i= listbox->first_item; i< stop; i++ ) @@ -91,7 +91,7 @@ void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox ) } //gr_ubox( -1, -1, listbox->width, listbox->height); - ui_mouse_show(); + mouse_toggle_cursor(1); } diff --git a/ui/menubar.c b/ui/menubar.c index d25255453..c80c1a15e 100644 --- a/ui/menubar.c +++ b/ui/menubar.c @@ -126,7 +126,7 @@ void menu_show( MENU * menu ) window_set_visible(menu->wind, 1); - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas(NULL); // Don't save background it if it's already drawn @@ -150,7 +150,7 @@ void menu_show( MENU * menu ) for (i=0; i< menu->NumItems; i++ ) item_show( menu, i ); - ui_mouse_show(); + mouse_toggle_cursor(1); // Mark as displayed. menu->Displayed = 1; @@ -171,11 +171,11 @@ void menu_hide( MENU * menu ) window_set_modal(Menu[0].wind, 0); // Restore the background - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_bm_ubitblt(menu->w, menu->h, menu->x, menu->y, 0, 0, menu->Background, &(grd_curscreen->sc_canvas.cv_bitmap)); - ui_mouse_show(); + mouse_toggle_cursor(1); // Mark as hidden. menu->Displayed = 0; @@ -193,12 +193,12 @@ void menu_move_bar_to( MENU * menu, int number ) if (menu->Displayed && (number != old_item)) { - ui_mouse_hide(); + mouse_toggle_cursor(0); item_show( menu, old_item ); item_show( menu, number ); - ui_mouse_show(); + mouse_toggle_cursor(1); } } @@ -676,10 +676,6 @@ int menubar_handler(window *wind, d_event *event, MENU *menu) { int rval = 0; - // HACK: Make sure all the state-based input variables are set, until we fully migrate to event-based input - if (wind == window_get_front()) - ui_event_handler(event); - switch (state) { case 0: diff --git a/ui/mouse.c b/ui/mouse.c deleted file mode 100644 index d1d83b50e..000000000 --- a/ui/mouse.c +++ /dev/null @@ -1,366 +0,0 @@ -/* $Id: mouse.c,v 1.1.1.1 2006/03/17 19:52:18 zicodxx Exp $ */ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - -/* - * - * Mouse interface routines. - * - */ - -#include -#include - -#include "event.h" -#include "u_mem.h" -#include "error.h" -#include "console.h" -#include "fix.h" -#include "pstypes.h" -#include "gr.h" -#include "mouse.h" -#include "ui.h" -#include "timer.h" - -// 16x16 - -#define PTR_W 11 -#define PTR_H 19 - -unsigned char ui_converted_mouse_pointer[PTR_W*PTR_H]; -#if 0 -char ui_mouse_pointer[] = \ -"1111100000000000"\ -"1111111111000000"\ -"1144411111111111"\ -"1144444444111111"\ -"1144444444444110"\ -"0114444444441100"\ -"0114444444411000"\ -"0114444444411000"\ -"0114444444441100"\ -"0114444444444110"\ -"0011444444444411"\ -"0011444444444411"\ -"0011411144444411"\ -"0011111111444111"\ -"0011100011111110"\ -"0011000000111100"; -#else - -char ui_mouse_pointer[] = \ -"10000000000"\ -"11000000000"\ -"14100000000"\ -"14410000000"\ -"14441000000"\ -"14444100000"\ -"14444410000"\ -"14444441000"\ -"14444444100"\ -"14444444410"\ -"14444411111"\ -"14114410000"\ -"11014410000"\ -"10001441000"\ -"00001441000"\ -"00001441000"\ -"00000144100"\ -"00000144100"\ -"00000111100"; -#endif - -static grs_bitmap * default_pointer; - - -UI_MOUSE Mouse; - - -/* -int ui_mouse_find_gadget(short n) -{ - int i; - - for (i=1; i<=Window[n].NumItems; i++ ) { - if ((Mouse.x >= (Window[n].Item[i].x1+Window[n].x)) && - (Mouse.x <= (Window[n].Item[i].x2+Window[n].x)) && - (Mouse.y >= (Window[n].Item[i].y1+Window[n].y)) && - (Mouse.y <= (Window[n].Item[i].y2+Window[n].y)) ) - return i; - } - return 0; -} -*/ - -void ui_mouse_show() -{ -#ifndef __MSDOS__ - event_toggle_focus(0); -#else - if (Mouse.hidden==1 ) { - Mouse.hidden = 0; - // Save the background under new pointer - Mouse.bg_saved=1; - Mouse.bg_x = Mouse.x; Mouse.bg_y = Mouse.y; - gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, 0, 0, Mouse.bg_x, Mouse.bg_y, &(grd_curscreen->sc_canvas.cv_bitmap),Mouse.background ); - // Draw the new pointer - gr_bm_ubitbltm( Mouse.pointer->bm_w, Mouse.pointer->bm_h, Mouse.x, Mouse.y, 0, 0, Mouse.pointer, &(grd_curscreen->sc_canvas.cv_bitmap) ); - } -#endif -} - -void ui_mouse_hide() -{ -#ifndef __MSDOS__ -// event_toggle_focus(1); // causes cursor to recenter -#else - if (Mouse.hidden==0 ) { - Mouse.hidden = 1; - if (Mouse.bg_saved==1) { - gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, Mouse.bg_x, Mouse.bg_y, 0, 0, Mouse.background,&(grd_curscreen->sc_canvas.cv_bitmap) ); - Mouse.bg_saved = 0; - } - } -#endif -} - -int ui_mouse_motion_process(d_event *event) -{ - int w,h; - int mx, my, mz; - - Assert(event->type == EVENT_MOUSE_MOVED); - event_mouse_get_delta(event, &mx, &my, &mz); - - Mouse.dx = mx; - Mouse.dy = my; - - //Mouse.x += Mouse.dx; - //Mouse.y += Mouse.dy; - mouse_get_pos(&mx, &my, &mz); - Mouse.x = mx; - Mouse.y = my; - - w = grd_curscreen->sc_w; - h = grd_curscreen->sc_h; - - if (Mouse.x < 0 ) Mouse.x = 0; - if (Mouse.y < 0 ) Mouse.y = 0; -// if (Mouse.x > w-Mouse.pointer->bm_w ) Mouse.x = w - Mouse.pointer->bm_w; -// if (Mouse.y > h-Mouse.pointer->bm_h ) Mouse.y = h - Mouse.pointer->bm_h; - - if (Mouse.x > w-3 ) Mouse.x = w - 3; - if (Mouse.y > h-3 ) Mouse.y = h - 3; - - if ( (Mouse.bg_x!=Mouse.x) || (Mouse.bg_y!=Mouse.y) ) - Mouse.moved = 1; - - if ( (Mouse.bg_x!=Mouse.x) || (Mouse.bg_y!=Mouse.y) || (Mouse.bg_saved==0) ) - { -#ifdef __MSDOS__ - // Restore the background under old pointer - if (Mouse.bg_saved==1) { - gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, Mouse.bg_x, Mouse.bg_y, 0, 0, Mouse.background, &(grd_curscreen->sc_canvas.cv_bitmap) ); - } - Mouse.bg_saved = 0; - - if (!Mouse.hidden) - { - // Save the background under new pointer - Mouse.bg_saved=1; - Mouse.bg_x = Mouse.x; Mouse.bg_y = Mouse.y; - - gr_bm_ubitblt( Mouse.background->bm_w, Mouse.background->bm_h, 0, 0, Mouse.bg_x, Mouse.bg_y, &(grd_curscreen->sc_canvas.cv_bitmap),Mouse.background ); - - // Draw the new pointer - gr_bm_ubitbltm( Mouse.pointer->bm_w, Mouse.pointer->bm_h, Mouse.x, Mouse.y, 0, 0, Mouse.pointer, &(grd_curscreen->sc_canvas.cv_bitmap) ); - } -#endif /* __MSDOS__*/ - } - - return 1; -} - -// straight from mouse.c's counterpart in arch/sdl -typedef struct d_event_mousebutton -{ - event_type type; - int button; -} d_event_mousebutton; - -int ui_mouse_button_process(d_event *event) -{ -// int mx, my, mz; - int button = -1; - int pressed; - - Assert((event->type == EVENT_MOUSE_BUTTON_DOWN) || (event->type == EVENT_MOUSE_BUTTON_UP) || (event->type == EVENT_IDLE)); - - if (event->type != EVENT_IDLE) - button = event_mouse_get_button(event); - - // Get the mouse's position - //mouse_get_pos(&mx, &my, &mz); - //Mouse.x = mx; - //Mouse.y = my; - - pressed = event->type == EVENT_MOUSE_BUTTON_DOWN; - - Mouse.b1_last_status = Mouse.b1_status; - Mouse.b2_last_status = Mouse.b2_status; - Mouse.b1_status &= (BUTTON_PRESSED | BUTTON_RELEASED); - Mouse.b2_status &= (BUTTON_PRESSED | BUTTON_RELEASED); - - if (event->type == EVENT_IDLE) - return 0; - - if ( Mouse.backwards== 0 ) - { - if (button == MBTN_LEFT) - Mouse.b1_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED; - else if (button == MBTN_RIGHT) - Mouse.b2_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED; - } else { - if (button == MBTN_LEFT) - Mouse.b2_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED; - else if (button == MBTN_RIGHT) - Mouse.b1_status = pressed ? BUTTON_PRESSED : BUTTON_RELEASED; - } - - if ((Mouse.b1_status & BUTTON_PRESSED) && (Mouse.b1_last_status & BUTTON_RELEASED) ) - { - if ((timer_query() <= Mouse.time_lastpressed + F1_0/5)) //&& (Mouse.moved==0) - { - Mouse.b1_status |= BUTTON_DOUBLE_CLICKED; - } - - Mouse.moved = 0; - Mouse.time_lastpressed = timer_query(); - Mouse.b1_status |= BUTTON_JUST_PRESSED; - - } - else if ((Mouse.b1_status & BUTTON_RELEASED) && (Mouse.b1_last_status & BUTTON_PRESSED) ) - Mouse.b1_status |= BUTTON_JUST_RELEASED; - - if ((Mouse.b2_status & BUTTON_PRESSED) && (Mouse.b2_last_status & BUTTON_RELEASED) ) - Mouse.b2_status |= BUTTON_JUST_PRESSED; - else if ((Mouse.b2_status & BUTTON_RELEASED) && (Mouse.b2_last_status & BUTTON_PRESSED) ) - Mouse.b2_status |= BUTTON_JUST_RELEASED; - - return 1; -} - -void ui_mouse_flip_buttons() -{ short x; - - x = Mouse.b1_status; - Mouse.b1_status = Mouse.b2_status; - Mouse.b2_status = x; - - x = Mouse.b1_last_status; - Mouse.b1_last_status = Mouse.b2_last_status; - Mouse.b2_last_status = x; - - Mouse.backwards ^= 1; - -} - - -void ui_mouse_init() -{ - int i, w,h; - -#ifndef __MSDOS__ - SDL_ShowCursor(1); -#endif - //mouse_init(); - - w = grd_curscreen->sc_w; - h = grd_curscreen->sc_h; - - //mouse_set_limits(0, 0, w - 1, h - 1); - - Mouse.x = w/2; - Mouse.y = h/2; - - //mouse_set_pos( w/2, h/2 ); - - for (i=0; i < PTR_W*PTR_H; i++ ) { - switch (ui_mouse_pointer[i]) { - case '0': - ui_converted_mouse_pointer[i]=255; - break; - case '1': - ui_converted_mouse_pointer[i]=CBLACK; - break; - case '2': - ui_converted_mouse_pointer[i]=CGREY; - break; - case '3': - ui_converted_mouse_pointer[i]=CWHITE; - break; - case '4': - ui_converted_mouse_pointer[i]=CBRIGHT; - break; - case '5': - ui_converted_mouse_pointer[i]=CRED; - break; - } - } - - default_pointer = gr_create_bitmap_raw( PTR_W, PTR_H, ui_converted_mouse_pointer ); - Mouse.x = Mouse.y = 0; - Mouse.backwards = 0; - Mouse.hidden = 1; - Mouse.b1_status = Mouse.b1_last_status = BUTTON_RELEASED; - Mouse.b2_status = Mouse.b2_last_status = BUTTON_RELEASED; - Mouse.b3_status = Mouse.b3_last_status = BUTTON_RELEASED; - Mouse.bg_x = Mouse.bg_y = 0; - Mouse.bg_saved = 0; -#ifdef __MSDOS__ - Mouse.pointer = default_pointer; - Mouse.background = gr_create_bitmap( Mouse.pointer->bm_w, Mouse.pointer->bm_h ); -#endif - Mouse.time_lastpressed = 0; - Mouse.moved = 0; - -} - -#ifdef __MSDOS__ -grs_bitmap * ui_mouse_set_pointer( grs_bitmap * new ) -{ - grs_bitmap * temp = Mouse.pointer; - - gr_free_bitmap( Mouse.background ); - - if (new == NULL ) { - Mouse.pointer = default_pointer; - } else { - Mouse.pointer = new; - } - Mouse.background = gr_create_bitmap( Mouse.pointer->bm_w, Mouse.pointer->bm_h ); - - return temp; - -} - -#endif -void ui_mouse_close() -{ -#ifdef __MSDOS__ - gr_free_sub_bitmap(default_pointer); - - gr_free_bitmap(Mouse.background); -#endif -} - diff --git a/ui/radio.c b/ui/radio.c index 4c1b54b03..7b8346c8c 100644 --- a/ui/radio.c +++ b/ui/radio.c @@ -37,7 +37,7 @@ void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio ) { radio->status = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( radio->canvas ); if (dlg->keyboard_focus_gadget == (UI_GADGET *) radio) @@ -62,7 +62,7 @@ void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio ) gr_ustring( radio->width+4, 2, radio->text ); - ui_mouse_show(); + mouse_toggle_cursor(1); } } diff --git a/ui/scroll.c b/ui/scroll.c index a4cdf2a5f..5bf8c4c4e 100644 --- a/ui/scroll.c +++ b/ui/scroll.c @@ -33,7 +33,7 @@ void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ) return; scrollbar->status = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( scrollbar->canvas ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)scrollbar) @@ -46,7 +46,7 @@ void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ) ui_draw_box_out(0, scrollbar->fake_position, scrollbar->width-1, scrollbar->fake_position+scrollbar->fake_size-1 ); - ui_mouse_show(); + mouse_toggle_cursor(1); } diff --git a/ui/ui.c b/ui/ui.c index cc9bbbc92..e1b105a62 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -54,8 +54,6 @@ void ui_init() //key_init(); - ui_mouse_init(); - gr_set_fontcolor( CBLACK, CWHITE ); ui_pad_init(); @@ -74,11 +72,6 @@ void ui_close() ui_pad_close(); - ui_mouse_close(); - -// mouse_close(); -// key_close(); - gr_close_font( ui_small_font ); } diff --git a/ui/userbox.c b/ui/userbox.c index 023695dd7..e3c26e337 100644 --- a/ui/userbox.c +++ b/ui/userbox.c @@ -34,7 +34,7 @@ void ui_draw_userbox( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox ) { userbox->status = 0; - ui_mouse_hide(); + mouse_toggle_cursor(0); gr_set_current_canvas( userbox->canvas ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)userbox) @@ -44,7 +44,7 @@ void ui_draw_userbox( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox ) gr_rect( -1, -1, userbox->width, userbox->height ); - ui_mouse_show(); + mouse_toggle_cursor(1); } }