From 9f79e40f7f9fbec3bcc1508557724f91121bd25f Mon Sep 17 00:00:00 2001 From: perepujal Date: Fri, 27 May 2011 21:14:15 +0000 Subject: Joystick should now work. --- diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index b45ae86..fdc3821 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -6,9 +6,10 @@ Copyright (c) 2002-2011 by Bill Kendrick and others bill@newbreedsoftware.com http://www.tuxpaint.org/ -$Id: CHANGES.txt,v 1.778 2011/05/25 18:53:13 wkendrick Exp $ +$Id: CHANGES.txt,v 1.779 2011/05/27 21:14:15 perepujal Exp $ + +2011.May.27 (0.9.22) -2011.May.25 (0.9.22) * New Tools: ---------- * Label - A tool to add text to a drawing, which can be modified or @@ -112,7 +113,23 @@ $Id: CHANGES.txt,v 1.778 2011/05/25 18:53:13 wkendrick Exp $ via config. * ASDW is QWERTY-centric; drop it, or add ways to support other keyboard layouts. - * Who wrote this, so we can credit!?!? + + * Joystick can be used to drive Tuxpaint + by Ankit Choudary (GSOC 2010) + with integration and fixes by Pere Pujal i Carabantes + + * Uses the first joystick found on the system, so should work out of the box + * Uses any of the buttons found in the joystick, no need for configuration. + * The hat of the joystick moves one pixel at a time, usefull to carefully place the pointer. + * The ball of the joystick should also trigger pointer motion. FIXME: This should work but is not tested. + * The responsivity of the joystick can be configured via command line or config files: + * --joystick-slownes sets a delay at each axis motion event. + Allowed values from 0 to 500, defaults to 15. + * --joystick-threshold sets the minimum value of axis motion to begin move the pointer. + Allowed values from 0 to 32766, defaults to 3200. + * --joystick_maxsteps sets the maximum number of pixels that the pointer will move at a time. + Allowed values from 1 to 7, defaults to 7. + * Magic Tool Improvememnts: -------------------------- @@ -228,6 +245,12 @@ $Id: CHANGES.txt,v 1.778 2011/05/25 18:53:13 wkendrick Exp $ Albert Cahalan , Bill Kendrick + * Packaging all the metadata in the PNG file. Before a draw based on a starter + would have need 3 files: the draw, the starter and the .dat file, whith + the addition of the Labels tool this increased to 5 files. Now all this stuff + is packed in customs chunks inside the PNG file. + + * New Starters: ------------- * Elephant diff --git a/docs/OPTIONS.txt b/docs/OPTIONS.txt index 1637442..8eb3da0 100644 --- a/docs/OPTIONS.txt +++ b/docs/OPTIONS.txt @@ -378,6 +378,18 @@ Windows Users Presents a clickable on-screen keyboard when using the Text and Label tools. + joystick-slowness=number + Sets a delay at each axis motion, allowing to slow the joystick. + Allowed values are 0 to 500. Default value is 15. + + joystick-threshold + Sets the minimum level of axis motion to start moving the pointer. + Allowed values are from 0 to 32766. Default value is 3200. + + joystick-maxsteps + Sets the maximum pixels the pointer will move at once. + Allowed values are from 1 to 7. Default value is 7. + stampsize=SIZE Use this option to force Tux Paint to set the starting size of @@ -760,8 +772,7 @@ Windows Users --noquit --noprint --printdelay=SECONDS - --printcfg - --altprintnever + --printcfg --altprintnever --altprintalways --papersize=PAPERSIZE --nolockfile @@ -780,6 +791,9 @@ Windows Users --nolabel --mouse-accessibility --onscreen-keyboard + --joystick-slowness + --joystick-threshold + --joystick-maxsteps --sysfonts --alllocalefonts --mirrorstamps diff --git a/src/parse.gperf b/src/parse.gperf index 4c3f527..df5ef71 100644 --- a/src/parse.gperf +++ b/src/parse.gperf @@ -155,6 +155,9 @@ windowed, NEGBOOL(fullscreen) windowsize, MULTI(parsertmp_windowsize) mouse-accessibility, POSBOOL(mouseaccessibility) onscreen-keyboard, POSBOOL(onscreen_keyboard) +joystick-slowness, MULTI(joystick_slowness) +joystick-threshold, MULTI(joystick_lowthreshold) +joystick-maxsteps, MULTI(joystick_maxsteps) %% void parse_one_option(struct cfginfo *restrict tmpcfg, const char *str, const char *opt, const char *restrict src) diff --git a/src/parse.h b/src/parse.h index 7ba8fc6..eda5777 100644 --- a/src/parse.h +++ b/src/parse.h @@ -52,7 +52,10 @@ struct cfginfo const char *use_sound; const char *wheely; const char *mouseaccessibility; - const char *onscreen_keyboard; + const char *onscreen_keyboard; + const char *joystick_slowness; + const char *joystick_lowthreshold; + const char *joystick_maxsteps; }; #define CFGINFO_MAXOFFSET (sizeof(struct cfginfo)) diff --git a/src/tuxpaint-completion.bash b/src/tuxpaint-completion.bash index a8fdda5..796a209 100644 --- a/src/tuxpaint-completion.bash +++ b/src/tuxpaint-completion.bash @@ -3,7 +3,7 @@ # Bill Kendrick ; http://www.tuxpaint.org/ # Based on inkscape's completion file, by allali@univ-mlv.fr # -# $Id: tuxpaint-completion.bash,v 1.2 2011/04/14 06:26:46 wkendrick Exp $ +# $Id: tuxpaint-completion.bash,v 1.3 2011/05/27 21:14:15 perepujal Exp $ # FIXME: See http://www.debian-administration.org/articles/316 for an intro # to how we should be doing this... -bjk 2009.09.09 @@ -62,6 +62,9 @@ _tuxpaint() --nolockfile \ --mouse-accessibility \ --onscreen-keyboard \ + --joystick-slowness \ + --joystick-threshold \ + --joystick-maxsteps \ --colorfile' -- $cur ) ) # We don't accept filenames on the command-line yet -bjk 2009.09.09 # else diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 0f05aa5..376f354 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -973,6 +973,11 @@ static void update_canvas(int x1, int y1, int x2, int y2) static int emulate_button_pressed = 0; static int mouseaccessibility = 0; static int onscreen_keyboard = 0; +static int joystick_low_threshold = 3200; +static int joystick_slowness = 15; +static int joystick_maxsteps = 7; +static int oldpos_x; +static int oldpos_y; static int disable_screensaver; #ifdef NOKIA_770 static int fullscreen = 1; @@ -1105,6 +1110,10 @@ static void set_label_fonts(void); static void tmp_apply_uncommited_text(void); static void undo_tmp_applied_text(void); +static void handle_joyaxismotion(SDL_Event event, int *motioner, int *val_x, int *val_y); +static void handle_joyhatmotion(SDL_Event event, int oldpos_x, int oldpos_y); +static void handle_joyballmotion(SDL_Event event, int oldpos_x, int oldpos_y); +static void handle_joybuttonupdown(SDL_Event event, int oldpos_x, int oldpos_y); /* Magic tools API and tool handles: */ @@ -3127,94 +3136,18 @@ static void mainloop(void) } } } - else if (event.type == SDL_JOYAXISMOTION) - { - motioner = event.jaxis.value; - if ( ( event.jaxis.value < -3200 ) || (event.jaxis.value > 3200 )) - { - val_x = (int)((SDL_JoystickGetAxis(joystick, 0) / 32768.0f) * 3); - val_y = (int)((SDL_JoystickGetAxis(joystick, 1) / 32768.0f) * 3); -// printf ("\n value : %d , %d, %d, %d\n",event.jaxis.value, event.jaxis.axis, val_x, val_y); - old_x += val_x; - old_y += val_y; - new_x = old_x + button_w * 2; - new_y = old_y; - SDL_WarpMouse(old_x + button_w * 2, old_y); - update_canvas(0, 0, WINDOW_WIDTH - 96, (48 * 7) + 40 + HEIGHTOFFSET); - } - } - else if (motioner == -32768) - { -// printf ("\n values are : %d , %d\n",val_x, val_y); - old_x += val_x; - old_y += val_y; - new_x = old_x + button_w * 2; - new_y = old_y; - SDL_WarpMouse(old_x + button_w * 2, old_y); - update_canvas(0, 0, WINDOW_WIDTH - 96, (48 * 7) + 40 + HEIGHTOFFSET); - } - - else if (motioner == 32767) - { - old_x += val_x; - old_y += val_y; - new_x = old_x + button_w * 2; - new_y = old_y; - SDL_WarpMouse(old_x + button_w * 2, old_y); - update_canvas(0, 0, WINDOW_WIDTH - 96, (48 * 7) + 40 + HEIGHTOFFSET); - } + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); - else if (event.type == SDL_JOYBALLMOTION) - { - if ( event.jball.ball == 0 ) - { - printf("\n ball movement \n"); - val_x = event.jball.xrel; - val_y = event.jball.yrel; - old_x += val_x; - old_y += val_y; - new_x = old_x + button_w * 2; - new_y = old_y; - SDL_WarpMouse(old_x + button_w * 2, old_y); - update_canvas(0, 0, WINDOW_WIDTH - 96, (48 * 7) + 40 + HEIGHTOFFSET); - } - } + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); - else if (event.type == SDL_JOYBUTTONDOWN) - { -// printf("\n button num : %d \n", event.jbutton.button); - - if (event.jbutton.button == 0) - { -// printf("\n button pressed \n"); - ev.type = SDL_MOUSEBUTTONDOWN; - ev.button.which = 0; - ev.button.state = SDL_PRESSED; - ev.button.x = old_x + button_w * 2; - ev.button.y = old_y; - ev.button.button = SDL_BUTTON_LEFT; - SDL_PushEvent(&ev); - playsound(screen, 1, SND_CLICK, 0, SNDPOS_LEFT, SNDDIST_NEAR); - update_screen(0,0,WINDOW_WIDTH,WINDOW_HEIGHT); - } - } + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); - else if (event.type == SDL_JOYBUTTONUP) - { -// printf("\n button num : %d \n", event.jbutton.button); - - if (event.jbutton.button == 0) - { -// printf("\n button released \n"); - ev.type = SDL_MOUSEBUTTONUP; - ev.button.which = 0; - ev.button.state = SDL_RELEASED; - ev.button.button = SDL_BUTTON_LEFT; - SDL_PushEvent(&ev); - update_screen(0,0,WINDOW_WIDTH,WINDOW_HEIGHT); - } - } + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button >= 2 && @@ -5086,14 +5019,16 @@ static void mainloop(void) } } } - button_down = 0; } else if (event.type == SDL_MOUSEMOTION && !ignoring_motion) { new_x = event.button.x - r_canvas.x; new_y = event.button.y - r_canvas.y; - + + oldpos_x = event.motion.x; + oldpos_y = event.motion.y; + if (keybd_flag == 1) { // uistate.mousedown = 1; @@ -5506,6 +5441,8 @@ static void mainloop(void) old_x = new_x; old_y = new_y; + oldpos_x = event.button.x; + oldpos_y = event.button.y; } } @@ -5523,6 +5460,13 @@ static void mainloop(void) } } + if (motioner) + { + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); + if (joystick_slowness) + SDL_Delay(joystick_slowness); + } + SDL_Delay(1); } while (!done); @@ -6492,6 +6436,11 @@ void show_usage(int exitcode) " %s [--nosysconfig]\n" " %s [--nolockfile]\n" " %s [--colorfile FILE]\n" + " %s [--mouse-accessibility]\n" + " %s [--onscreen-keyboard]\n" + " %s [--joystick-slowness] (0-500). Default value is 15\n" + " %s [--joystick-threshold] (0-32766). Default value is 3200\n" + " %s [--joystick-maxsteps] (1-7). Default value is 7\n" "\n", progname, progname, blank, blank, blank, blank, @@ -6507,7 +6456,7 @@ void show_usage(int exitcode) #if !defined(WIN32) && !defined(__APPLE__) && !defined(__BEOS__) && !defined(__HAIKU__) blank, #endif - blank, blank, blank, blank, blank); + blank, blank, blank, blank, blank, blank, blank, blank, blank, blank); free(blank); } @@ -11683,7 +11632,9 @@ static int do_prompt_image_flash_snd(const char *const text, SDL_Surface *img1b; int free_img1b; int txt_left, txt_right, img_left, btn_left, txt_btn_left, txt_btn_right; + int val_x, val_y, motioner; + val_x = val_y = motioner = 0; emulate_button_pressed = 0; hide_blinking_cursor(); @@ -12025,10 +11976,31 @@ static int do_prompt_image_flash_snd(const char *const text, { do_setcursor(cursor_arrow); } + oldpos_x = event.button.x; + oldpos_y = event.button.y; } + + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); + + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); } - SDL_Delay(100); + if (motioner) + { + if (joystick_slowness) + SDL_Delay(joystick_slowness); + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); + } + + SDL_Delay(10); if (animate) { @@ -13552,7 +13524,8 @@ static int do_quit(int tool) draw_tux_text(TUX_BORED, "", 0); cur_tool = tmp_tool; } - SDL_JoystickClose(joystick); + if (done) + SDL_JoystickClose(joystick); return (done); } @@ -13596,6 +13569,9 @@ static int do_open(void) int last_click_which, last_click_button; int places_to_look; int opened_something; + int val_x, val_y, motioner; + + val_x = val_y = motioner = 0; opened_something = 0; @@ -14080,9 +14056,8 @@ static int do_open(void) update_list = 0; } - - SDL_WaitEvent(&event); - + while (SDL_PollEvent(&event)) + { if (event.type == SDL_QUIT) { done = 1; @@ -14388,8 +14363,30 @@ static int do_open(void) do_setcursor(cursor_arrow); } - } + oldpos_x = event.button.x; + oldpos_y = event.button.y; + } + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); + + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); + } + + if (motioner) + { + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); + if (joystick_slowness) + SDL_Delay(joystick_slowness); + } + SDL_Delay(10); if (want_erase) { @@ -14503,7 +14500,6 @@ static int do_open(void) update_list = 1; } } - } while (!done); @@ -14684,6 +14680,9 @@ static int do_slideshow(void) float x_per, y_per; int xx, yy; SDL_Surface *btn, *blnk; + int val_x, val_y, motioner; + + val_x = val_y = motioner = 0; do_setcursor(cursor_watch); @@ -15099,289 +15098,310 @@ static int do_slideshow(void) update_list = 0; } - - SDL_WaitEvent(&event); - - if (event.type == SDL_QUIT) - { - done = 1; - - /* FIXME: Handle SDL_Quit better */ - } - else if (event.type == SDL_ACTIVEEVENT) - { - handle_active(&event); - } - else if (event.type == SDL_KEYUP) - { - key = event.key.keysym.sym; - - handle_keymouse(key, SDL_KEYUP); - } - else if (event.type == SDL_KEYDOWN) + /* Was a call to SDL_WaitEvent(&event); before, + changed to this while loop in order to get joystick working */ + while (SDL_PollEvent(&event)) { - key = event.key.keysym.sym; - - handle_keymouse(key, SDL_KEYDOWN); - - if (key == SDLK_RETURN || key == SDLK_SPACE) + if (event.type == SDL_QUIT) { - /* Play */ - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); + + /* FIXME: Handle SDL_Quit better */ + } + else if (event.type == SDL_ACTIVEEVENT) + { + handle_active(&event); } - else if (key == SDLK_ESCAPE) + else if (event.type == SDL_KEYUP) { - /* Go back: */ + key = event.key.keysym.sym; - go_back = 1; - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); + handle_keymouse(key, SDL_KEYUP); } - } - else if (event.type == SDL_MOUSEBUTTONDOWN && - valid_click(event.button.button)) - { - if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && - event.button.y >= 24 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 48)) + else if (event.type == SDL_KEYDOWN) { - /* Picked an icon! */ + key = event.key.keysym.sym; - which = ((event.button.x - 96) / (THUMB_W) + - (((event.button.y - 24) / THUMB_H) * 4)) + cur; + handle_keymouse(key, SDL_KEYDOWN); - if (which < num_files) + if (key == SDLK_RETURN || key == SDLK_SPACE) { - playsound(screen, 1, SND_BLEEP, 1, event.button.x, SNDDIST_NEAR); + /* Play */ - /* Is it selected already? */ + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); + } + else if (key == SDLK_ESCAPE) + { + /* Go back: */ - found = -1; - for (i = 0; i < num_selected && found == -1; i++) - { - if (selected[i] == which) - found = i; - } + go_back = 1; + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); + } + } + else if (event.type == SDL_MOUSEBUTTONDOWN && + valid_click(event.button.button)) + { + if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && + event.button.y >= 24 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 48)) + { + /* Picked an icon! */ - if (found == -1) - { - /* No! Select it! */ + which = ((event.button.x - 96) / (THUMB_W) + + (((event.button.y - 24) / THUMB_H) * 4)) + cur; - selected[num_selected++] = which; - } - else + if (which < num_files) { - /* Yes! Unselect it! */ + playsound(screen, 1, SND_BLEEP, 1, event.button.x, SNDDIST_NEAR); - for (i = found; i < num_selected - 1; i++) - selected[i] = selected[i + 1]; + /* Is it selected already? */ - num_selected--; - } + found = -1; + for (i = 0; i < num_selected && found == -1; i++) + { + if (selected[i] == which) + found = i; + } - update_list = 1; - } - } - else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2) - { - if (event.button.y < 24) - { - /* Up scroll button: */ + if (found == -1) + { + /* No! Select it! */ - if (cur > 0) - { - cur = cur - 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + selected[num_selected++] = which; + } + else + { + /* Yes! Unselect it! */ - if (cur == 0) - do_setcursor(cursor_arrow); - } + for (i = found; i < num_selected - 1; i++) + selected[i] = selected[i + 1]; - if (which >= cur + 16) - which = which - 4; + num_selected--; + } + + update_list = 1; + } } - else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24)) + else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2) { - /* Down scroll button: */ - - if (cur < num_files - 16) + if (event.button.y < 24) { - cur = cur + 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + /* Up scroll button: */ - if (cur >= num_files - 16) - do_setcursor(cursor_arrow); + if (cur > 0) + { + cur = cur - 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + + if (cur == 0) + do_setcursor(cursor_arrow); + } + + if (which >= cur + 16) + which = which - 4; } + else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24)) + { + /* Down scroll button: */ - if (which < cur) - which = which + 4; + if (cur < num_files - 16) + { + cur = cur + 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + + if (cur >= num_files - 16) + do_setcursor(cursor_arrow); + } + + if (which < cur) + which = which + 4; + } } - } - else if (event.button.x >= 96 && event.button.x < 96 + 48 && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) - { - /* Play */ + else if (event.button.x >= 96 && event.button.x < 96 + 48 && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* Play */ - playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); + playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); - /* If none selected, select all, in order! */ + /* If none selected, select all, in order! */ - if (num_selected == 0) - { - for (i = 0; i < num_files; i++) - selected[i] = i; - num_selected = num_files; - } + if (num_selected == 0) + { + for (i = 0; i < num_files; i++) + selected[i] = i; + num_selected = num_files; + } - play_slideshow(selected, num_selected, dirname, d_names, d_exts, speed); + play_slideshow(selected, num_selected, dirname, d_names, d_exts, speed); - /* Redraw entire screen, after playback: */ + /* Redraw entire screen, after playback: */ - SDL_FillRect(screen, NULL, SDL_MapRGB(canvas->format, 255, 255, 255)); - draw_toolbar(); - draw_colors(COLORSEL_CLOBBER_WIPE); - draw_none(); + SDL_FillRect(screen, NULL, SDL_MapRGB(canvas->format, 255, 255, 255)); + draw_toolbar(); + draw_colors(COLORSEL_CLOBBER_WIPE); + draw_none(); - /* Instructions for Slideshow file dialog (FIXME: Make a #define) */ - freeme = textdir(gettext_noop("Choose the pictures you want, " - "then click “Play”.")); - draw_tux_text(TUX_BORED, freeme, 1); - free(freeme); + /* Instructions for Slideshow file dialog (FIXME: Make a #define) */ + freeme = textdir(gettext_noop("Choose the pictures you want, " "then click “Play”.")); + draw_tux_text(TUX_BORED, freeme, 1); + free(freeme); - SDL_Flip(screen); + SDL_Flip(screen); - update_list = 1; - } - else if (event.button.x >= 96 + 48 && event.button.x < 96 + 48 + 96 && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) - { - /* Speed slider */ + update_list = 1; + } + else if (event.button.x >= 96 + 48 && event.button.x < 96 + 48 + 96 && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* Speed slider */ + + int old_speed, control_sound, click_x; - int old_speed, control_sound, click_x; + old_speed = speed; - old_speed = speed; + click_x = event.button.x - 96 - 48; + speed = ((10 * click_x) / 96); - click_x = event.button.x - 96 - 48; - speed = ((10 * click_x) / 96); + control_sound = -1; - control_sound = -1; + if (speed < old_speed) + control_sound = SND_SHRINK; + else if (speed > old_speed) + control_sound = SND_GROW; - if (speed < old_speed) - control_sound = SND_SHRINK; - else if (speed > old_speed) - control_sound = SND_GROW; + if (control_sound != -1) + { + playsound(screen, 0, control_sound, 0, SNDPOS_CENTER, SNDDIST_NEAR); - if (control_sound != -1) + update_list = 1; + } + } + else if (event.button.x >= (WINDOW_WIDTH - 96 - 48) && + event.button.x < (WINDOW_WIDTH - 96) && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) { - playsound(screen, 0, control_sound, 0, SNDPOS_CENTER, - SNDDIST_NEAR); + /* Back */ - update_list = 1; + go_back = 1; + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); } } - else if (event.button.x >= (WINDOW_WIDTH - 96 - 48) && - event.button.x < (WINDOW_WIDTH - 96) && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + else if (event.type == SDL_MOUSEBUTTONDOWN && + event.button.button >= 4 && event.button.button <= 5 && wheely) { - /* Back */ + /* Scroll wheel! */ - go_back = 1; - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); - } - } - else if (event.type == SDL_MOUSEBUTTONDOWN && - event.button.button >= 4 && event.button.button <= 5 && wheely) - { - /* Scroll wheel! */ + if (event.button.button == 4 && cur > 0) + { + cur = cur - 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); - if (event.button.button == 4 && cur > 0) - { - cur = cur - 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + if (cur == 0) + do_setcursor(cursor_arrow); - if (cur == 0) - do_setcursor(cursor_arrow); + if (which >= cur + 16) + which = which - 4; + } + else if (event.button.button == 5 && cur < num_files - 16) + { + cur = cur + 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + + if (cur >= num_files - 16) + do_setcursor(cursor_arrow); - if (which >= cur + 16) - which = which - 4; + if (which < cur) + which = which + 4; + } } - else if (event.button.button == 5 && cur < num_files - 16) + else if (event.type == SDL_MOUSEMOTION) { - cur = cur + 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + /* Deal with mouse pointer shape! */ - if (cur >= num_files - 16) - do_setcursor(cursor_arrow); + if (event.button.y < 24 && + event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && cur > 0) + { + /* Scroll up button: */ - if (which < cur) - which = which + 4; - } - } - else if (event.type == SDL_MOUSEMOTION) - { - /* Deal with mouse pointer shape! */ + do_setcursor(cursor_up); + } + else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24) && + event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && + cur < num_files - 16) + { + /* Scroll down button: */ - if (event.button.y < 24 && - event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && cur > 0) - { - /* Scroll up button: */ + do_setcursor(cursor_down); + } + else if (((event.button.x >= 96 && event.button.x < 96 + 48 + 96) || + (event.button.x >= (WINDOW_WIDTH - 96 - 48) && + event.button.x < (WINDOW_WIDTH - 96))) && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* One of the command buttons: */ - do_setcursor(cursor_up); - } - else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24) && - event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && - cur < num_files - 16) - { - /* Scroll down button: */ + do_setcursor(cursor_hand); + } + else if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 + && event.button.y > 24 + && event.button.y < (48 * 7 + 40 + HEIGHTOFFSET) - 48 + && + ((((event.button.x - 96) / (THUMB_W) + + (((event.button.y - 24) / THUMB_H) * 4)) + cur) < + num_files)) + { + /* One of the thumbnails: */ - do_setcursor(cursor_down); - } - else if (((event.button.x >= 96 && event.button.x < 96 + 48 + 96) || - (event.button.x >= (WINDOW_WIDTH - 96 - 48) && - event.button.x < (WINDOW_WIDTH - 96))) && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) - { - /* One of the command buttons: */ + do_setcursor(cursor_hand); + } + else + { + /* Unclickable... */ - do_setcursor(cursor_hand); + do_setcursor(cursor_arrow); + } + oldpos_x = event.button.x; + oldpos_y = event.button.y; } - else if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 - && event.button.y > 24 - && event.button.y < (48 * 7 + 40 + HEIGHTOFFSET) - 48 - && - ((((event.button.x - 96) / (THUMB_W) + - (((event.button.y - 24) / THUMB_H) * 4)) + cur) < - num_files)) - { - /* One of the thumbnails: */ + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); - do_setcursor(cursor_hand); - } - else - { - /* Unclickable... */ + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); - do_setcursor(cursor_arrow); - } + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); + } + + if (motioner) + { + if (joystick_slowness) + SDL_Delay(joystick_slowness); + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); } + SDL_Delay(10); } while (!done); @@ -15413,6 +15433,7 @@ static void play_slideshow(int * selected, int num_selected, char * dirname, char **d_names, char **d_exts, int speed) { int i, which, next, done; + int val_x, val_y, motioner; SDL_Surface * img; char * tmp_starter_id, * tmp_template_id, * tmp_file_id; int tmp_starter_mirrored, tmp_starter_flipped, tmp_starter_personal; @@ -15422,6 +15443,7 @@ static void play_slideshow(int * selected, int num_selected, char * dirname, SDL_Rect dest; Uint32 last_ticks; + val_x = val_y = motioner = 0; /* Back up the current image's IDs, because they will get clobbered below! */ @@ -15597,10 +15619,32 @@ static void play_slideshow(int * selected, int num_selected, char * dirname, do_setcursor(cursor_tiny); } + oldpos_x = event.button.x; + oldpos_y = event.button.y; } + + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); + + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); + } - SDL_Delay(100); + if (motioner) + { + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); + if (joystick_slowness) + SDL_Delay(joystick_slowness); + } + + SDL_Delay(10); /* Automatically skip to the next one after time expires: */ @@ -17966,7 +18010,9 @@ static int do_new_dialog(void) int added; Uint8 r, g, b; int white_in_palette; + int val_x, val_y, motioner; + val_x = val_y = motioner = 0; do_setcursor(cursor_watch); @@ -18560,280 +18606,304 @@ static int do_new_dialog(void) update_list = 0; } + /* Was a call to SDL_WaitEvent(&event); before, + changed to this while loop in order to get joystick working */ + while(SDL_PollEvent(&event)) + { + if (event.type == SDL_QUIT) + { + done = 1; - SDL_WaitEvent(&event); + /* FIXME: Handle SDL_Quit better */ + } + else if (event.type == SDL_ACTIVEEVENT) + { + handle_active(&event); + } + else if (event.type == SDL_KEYUP) + { + key = event.key.keysym.sym; - if (event.type == SDL_QUIT) - { - done = 1; + handle_keymouse(key, SDL_KEYUP); + } + else if (event.type == SDL_KEYDOWN) + { + key = event.key.keysym.sym; - /* FIXME: Handle SDL_Quit better */ - } - else if (event.type == SDL_ACTIVEEVENT) - { - handle_active(&event); - } - else if (event.type == SDL_KEYUP) - { - key = event.key.keysym.sym; + handle_keymouse(key, SDL_KEYDOWN); - handle_keymouse(key, SDL_KEYUP); - } - else if (event.type == SDL_KEYDOWN) - { - key = event.key.keysym.sym; + if (key == SDLK_LEFT) + { + if (which > 0) + { + which--; - handle_keymouse(key, SDL_KEYDOWN); + if (which < cur) + cur = cur - 4; - if (key == SDLK_LEFT) - { - if (which > 0) - { - which--; + update_list = 1; + } + } + else if (key == SDLK_RIGHT) + { + if (which < num_files - 1) + { + which++; - if (which < cur) - cur = cur - 4; + if (which >= cur + 16) + cur = cur + 4; - update_list = 1; - } - } - else if (key == SDLK_RIGHT) - { - if (which < num_files - 1) - { - which++; + update_list = 1; + } + } + else if (key == SDLK_UP) + { + if (which >= 0) + { + which = which - 4; - if (which >= cur + 16) - cur = cur + 4; + if (which < 0) + which = 0; - update_list = 1; - } - } - else if (key == SDLK_UP) - { - if (which >= 0) - { - which = which - 4; + if (which < cur) + cur = cur - 4; - if (which < 0) - which = 0; + update_list = 1; + } + } + else if (key == SDLK_DOWN) + { + if (which < num_files) + { + which = which + 4; - if (which < cur) - cur = cur - 4; + if (which >= num_files) + which = num_files - 1; - update_list = 1; - } - } - else if (key == SDLK_DOWN) - { - if (which < num_files) - { - which = which + 4; + if (which >= cur + 16) + cur = cur + 4; - if (which >= num_files) - which = num_files - 1; + update_list = 1; + } + } + else if (key == SDLK_RETURN || key == SDLK_SPACE) + { + /* Open */ - if (which >= cur + 16) - cur = cur + 4; + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); + } + else if (key == SDLK_ESCAPE) + { + /* Go back: */ - update_list = 1; - } + which = -1; + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); + } } - else if (key == SDLK_RETURN || key == SDLK_SPACE) + else if (event.type == SDL_MOUSEBUTTONDOWN && + valid_click(event.button.button)) { - /* Open */ + if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && + event.button.y >= 24 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 48)) + { + /* Picked an icon! */ - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); - } - else if (key == SDLK_ESCAPE) - { - /* Go back: */ + which = ((event.button.x - 96) / (THUMB_W) + + (((event.button.y - 24) / THUMB_H) * 4)) + cur; - which = -1; - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); - } - } - else if (event.type == SDL_MOUSEBUTTONDOWN && - valid_click(event.button.button)) - { - if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && - event.button.y >= 24 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 48)) - { - /* Picked an icon! */ + if (which < num_files) + { + playsound(screen, 1, SND_BLEEP, 1, event.button.x, SNDDIST_NEAR); + update_list = 1; - which = ((event.button.x - 96) / (THUMB_W) + - (((event.button.y - 24) / THUMB_H) * 4)) + cur; - if (which < num_files) - { - playsound(screen, 1, SND_BLEEP, 1, event.button.x, SNDDIST_NEAR); - update_list = 1; + if (which == last_click_which && + SDL_GetTicks() < last_click_time + 1000 && + event.button.button == last_click_button) + { + /* Double-click! */ + done = 1; + } - if (which == last_click_which && - SDL_GetTicks() < last_click_time + 1000 && - event.button.button == last_click_button) - { - /* Double-click! */ + last_click_which = which; + last_click_time = SDL_GetTicks(); + last_click_button = event.button.button; + } + } + else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2) + { + if (event.button.y < 24) + { + /* Up scroll button: */ - done = 1; - } + if (cur > 0) + { + cur = cur - 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, + SNDDIST_NEAR); - last_click_which = which; - last_click_time = SDL_GetTicks(); - last_click_button = event.button.button; - } - } - else if (event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2) - { - if (event.button.y < 24) - { - /* Up scroll button: */ + if (cur == 0) + do_setcursor(cursor_arrow); + } - if (cur > 0) - { - cur = cur - 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, - SNDDIST_NEAR); + if (which >= cur + 16) + which = which - 4; + } + else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24)) + { + /* Down scroll button: */ - if (cur == 0) - do_setcursor(cursor_arrow); - } + if (cur < num_files - 16) + { + cur = cur + 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, + SNDDIST_NEAR); - if (which >= cur + 16) - which = which - 4; - } - else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24)) - { - /* Down scroll button: */ + if (cur >= num_files - 16) + do_setcursor(cursor_arrow); + } - if (cur < num_files - 16) - { - cur = cur + 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, - SNDDIST_NEAR); + if (which < cur) + which = which + 4; + } + } + else if (event.button.x >= 96 && event.button.x < 96 + 48 && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* Open */ - if (cur >= num_files - 16) - do_setcursor(cursor_arrow); - } + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); + } + else if (event.button.x >= (WINDOW_WIDTH - 96 - 48) && + event.button.x < (WINDOW_WIDTH - 96) && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* Back */ - if (which < cur) - which = which + 4; - } + which = -1; + done = 1; + playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); + } } - else if (event.button.x >= 96 && event.button.x < 96 + 48 && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + else if (event.type == SDL_MOUSEBUTTONDOWN && + event.button.button >= 4 && event.button.button <= 5 && wheely) { - /* Open */ + /* Scroll wheel! */ - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_LEFT, SNDDIST_NEAR); - } - else if (event.button.x >= (WINDOW_WIDTH - 96 - 48) && - event.button.x < (WINDOW_WIDTH - 96) && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) - { - /* Back */ + if (event.button.button == 4 && cur > 0) + { + cur = cur - 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); - which = -1; - done = 1; - playsound(screen, 1, SND_CLICK, 1, SNDPOS_RIGHT, SNDDIST_NEAR); - } - } - else if (event.type == SDL_MOUSEBUTTONDOWN && - event.button.button >= 4 && event.button.button <= 5 && wheely) - { - /* Scroll wheel! */ + if (cur == 0) + do_setcursor(cursor_arrow); - if (event.button.button == 4 && cur > 0) - { - cur = cur - 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + if (which >= cur + 16) + which = which - 4; + } + else if (event.button.button == 5 && cur < num_files - 16) + { + cur = cur + 4; + update_list = 1; + playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); - if (cur == 0) - do_setcursor(cursor_arrow); + if (cur >= num_files - 16) + do_setcursor(cursor_arrow); - if (which >= cur + 16) - which = which - 4; + if (which < cur) + which = which + 4; + } } - else if (event.button.button == 5 && cur < num_files - 16) + else if (event.type == SDL_MOUSEMOTION) { - cur = cur + 4; - update_list = 1; - playsound(screen, 1, SND_SCROLL, 1, SNDPOS_CENTER, SNDDIST_NEAR); + /* Deal with mouse pointer shape! */ - if (cur >= num_files - 16) - do_setcursor(cursor_arrow); + if (event.button.y < 24 && + event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && + cur > 0) + { + /* Scroll up button: */ - if (which < cur) - which = which + 4; - } - } - else if (event.type == SDL_MOUSEMOTION) - { - /* Deal with mouse pointer shape! */ + do_setcursor(cursor_up); + } + else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24) && + event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && + event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && + cur < num_files - 16) + { + /* Scroll down button: */ - if (event.button.y < 24 && - event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && - cur > 0) - { - /* Scroll up button: */ + do_setcursor(cursor_down); + } + else if (((event.button.x >= 96 && event.button.x < 96 + 48 + 48) || + (event.button.x >= (WINDOW_WIDTH - 96 - 48) && + event.button.x < (WINDOW_WIDTH - 96)) || + (event.button.x >= (WINDOW_WIDTH - 96 - 48 - 48) && + event.button.x < (WINDOW_WIDTH - 48 - 96) && + d_places[which] != PLACE_STARTERS_DIR && + d_places[which] != PLACE_PERSONAL_STARTERS_DIR)) && + event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) + { + /* One of the command buttons: */ - do_setcursor(cursor_up); - } - else if (event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET - 48) && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET - 24) && - event.button.x >= (WINDOW_WIDTH - img_scroll_up->w) / 2 && - event.button.x <= (WINDOW_WIDTH + img_scroll_up->w) / 2 && - cur < num_files - 16) - { - /* Scroll down button: */ + do_setcursor(cursor_hand); + } + else if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && + event.button.y > 24 && + event.button.y < (48 * 7 + 40 + HEIGHTOFFSET) - 48 && + ((((event.button.x - 96) / (THUMB_W) + + (((event.button.y - 24) / THUMB_H) * 4)) + + cur) < num_files)) + { + /* One of the thumbnails: */ - do_setcursor(cursor_down); - } - else if (((event.button.x >= 96 && event.button.x < 96 + 48 + 48) || - (event.button.x >= (WINDOW_WIDTH - 96 - 48) && - event.button.x < (WINDOW_WIDTH - 96)) || - (event.button.x >= (WINDOW_WIDTH - 96 - 48 - 48) && - event.button.x < (WINDOW_WIDTH - 48 - 96) && - d_places[which] != PLACE_STARTERS_DIR && - d_places[which] != PLACE_PERSONAL_STARTERS_DIR)) && - event.button.y >= (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET)) - { - /* One of the command buttons: */ + do_setcursor(cursor_hand); + } + else + { + /* Unclickable... */ - do_setcursor(cursor_hand); + do_setcursor(cursor_arrow); + } + oldpos_x = event.button.x; + oldpos_y = event.button.y; } - else if (event.button.x >= 96 && event.button.x < WINDOW_WIDTH - 96 && - event.button.y > 24 && - event.button.y < (48 * 7 + 40 + HEIGHTOFFSET) - 48 && - ((((event.button.x - 96) / (THUMB_W) + - (((event.button.y - 24) / THUMB_H) * 4)) + - cur) < num_files)) - { - /* One of the thumbnails: */ - do_setcursor(cursor_hand); - } - else - { - /* Unclickable... */ + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); - do_setcursor(cursor_arrow); - } + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); + } + + if (motioner) + { + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); + if (joystick_slowness) + SDL_Delay(joystick_slowness); } + SDL_Delay(10); } while (!done); @@ -19114,6 +19184,7 @@ static int do_color_picker(void) SDL_Rect dest; int x, y, w; int ox, oy, oox, ooy, nx, ny; + int val_x, val_y, motioner; SDL_Surface * tmp_btn_up, * tmp_btn_down; Uint32(*getpixel_tmp_btn_up) (SDL_Surface *, int, int); Uint32(*getpixel_tmp_btn_down) (SDL_Surface *, int, int); @@ -19129,6 +19200,7 @@ static int do_color_picker(void) SDL_Rect color_example_dest; SDL_Surface * backup; + val_x = val_y = motioner = 0; hide_blinking_cursor(); @@ -19315,6 +19387,7 @@ static int do_color_picker(void) done = 0; chose = 0; x = y = 0; + SDL_WarpMouse(back_left + button_w / 2, back_top - button_w / 2); do { @@ -19434,7 +19507,28 @@ static int do_color_picker(void) else do_setcursor(cursor_arrow); } + + oldpos_x = event.motion.x; + oldpos_y = event.motion.y; } + else if (event.type == SDL_JOYAXISMOTION) + handle_joyaxismotion(event, &motioner, &val_x, &val_y); + + else if (event.type == SDL_JOYHATMOTION) + handle_joyhatmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBALLMOTION) + handle_joyballmotion(event, oldpos_x, oldpos_y); + + else if (event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) + handle_joybuttonupdown(event, oldpos_x, oldpos_y); + } + + if (motioner) + { + if (joystick_slowness) + SDL_Delay(joystick_slowness); + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); } SDL_Delay(10); @@ -21349,6 +21443,35 @@ static void setup_config(char *argv[]) if(tmpcfg.papersize) papersize = tmpcfg.papersize; #endif + if(tmpcfg.joystick_slowness) + { + if(strtof(tmpcfg.joystick_slowness, NULL) < 0 || strtof(tmpcfg.joystick_slowness, NULL) > 500) + { + printf("Joystick slowness (now %s) must be between 0 and 500.\n", tmpcfg.joystick_slowness); + exit(1); + } + joystick_slowness = strtof(tmpcfg.joystick_slowness, NULL); + } + if(tmpcfg.joystick_lowthreshold) + { + if (strtof(tmpcfg.joystick_lowthreshold, NULL) < 0 || strtof(tmpcfg.joystick_lowthreshold, NULL) > 32766) + { + /* FIXME: Find better exit code */ + printf("Joystick lower threshold (now %s) must be between 0 and 32766", tmpcfg.joystick_lowthreshold); + exit(1); + } + joystick_low_threshold = strtof(tmpcfg.joystick_lowthreshold, NULL); + } + if(tmpcfg.joystick_maxsteps) + { + if (strtof(tmpcfg.joystick_maxsteps, NULL) < 1 || strtof(tmpcfg.joystick_maxsteps, NULL) > 7) + { + /* FIXME: Find better exit code */ + printf("Joystick lower threshold (now %s) must be between 1 and 7", tmpcfg.joystick_maxsteps); + exit(1); + } + joystick_maxsteps = strtof(tmpcfg.joystick_maxsteps, NULL); + } } @@ -21630,6 +21753,7 @@ int TP_EventFilter(const SDL_Event * event) event->type == SDL_ACTIVEEVENT || event->type == SDL_JOYAXISMOTION || event->type == SDL_JOYBALLMOTION || + event->type == SDL_JOYHATMOTION || event->type == SDL_JOYBUTTONDOWN || event->type == SDL_JOYBUTTONUP || event->type == SDL_KEYDOWN || @@ -22659,6 +22783,10 @@ static void claim_to_be_ready(void) mouse_x = WINDOW_WIDTH / 2; mouse_y = WINDOW_HEIGHT / 2; + + oldpos_x = mouse_x; + oldpos_y = mouse_y; + SDL_WarpMouse(mouse_x, mouse_y); mousekey_up = SDL_KEYUP; @@ -22761,8 +22889,9 @@ int main(int argc, char *argv[]) printf(" %s\n", SDL_JoystickName(i)); } - SDL_JoystickEventState(SDL_ENABLE); joystick = SDL_JoystickOpen(0); + SDL_JoystickEventState(SDL_ENABLE); + printf("Number of Axes: %d\n", SDL_JoystickNumAxes(joystick)); printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(joystick)); printf("Number of Balls: %d\n", SDL_JoystickNumBalls(joystick)); @@ -23968,3 +24097,119 @@ int file_exists(char * path) { return(res == 0); } +/* Don't move the mouse here as this is only called when an event triggers it + and the joystick can be holded withouth sending any event. */ +static void handle_joyaxismotion(SDL_Event event, int *motioner, int *val_x, int *val_y) { + int i, j, step; + + if (event.jaxis.which != 0) + return; + + i = SDL_JoystickGetAxis(joystick, 0); + j = SDL_JoystickGetAxis(joystick, 1); + step = 5000; + if (abs(i) < joystick_low_threshold && abs(j) < joystick_low_threshold) + *motioner = FALSE; + else + { + if (i > joystick_low_threshold) + *val_x = min((i - joystick_low_threshold) / step + 1, joystick_maxsteps); + else if (i < -joystick_low_threshold) + *val_x = max((i + joystick_low_threshold) / step - 1, -joystick_maxsteps); + else + *val_x = 0; + + if (j > joystick_low_threshold) + *val_y = min((j - joystick_low_threshold) / step + 1, joystick_maxsteps); + else if (j < -joystick_low_threshold) + *val_y = max((j + joystick_low_threshold) / step - 1, -joystick_maxsteps); + else + *val_y = 0; + + // printf("i %d valx %d j %d val_y %d\n", i, val_x, j, val_y); + if (*val_x || *val_y) + { + *motioner = TRUE; + } + else + *motioner = FALSE; + } +} + +static void handle_joyhatmotion(SDL_Event event, int oldpos_x, int oldpos_y) { + int val_x, val_y; + val_x = val_y = 0; + + switch (event.jhat.value) { + case SDL_HAT_CENTERED: + val_x = 0; + val_y = 0; + break; + case SDL_HAT_UP: + val_x = 0; + val_y = -1; + break; + case SDL_HAT_RIGHTUP: + val_x = 1; + val_y = -1; + break; + case SDL_HAT_RIGHT: + val_x = 1; + val_y = 0; + break; + case SDL_HAT_RIGHTDOWN: + val_x = 1; + val_y = 1; + break; + case SDL_HAT_DOWN: + val_x = 0; + val_y = 1; + break; + case SDL_HAT_LEFTDOWN: + val_x = -1; + val_y = 1; + break; + case SDL_HAT_LEFT: + val_x = -1; + val_y = 0; + break; + case SDL_HAT_LEFTUP: + val_x = -1; + val_y = -1; + break; + } + if(val_x || val_y) + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); +} + +static void handle_joyballmotion(SDL_Event event, int oldpos_x, int oldpos_y) { + int val_x, val_y; + /* FIXME: NOT TESTED Should this act like handle_joyaxismotion? + in the sense of setting the values for the moving but don't move the mouse here? */ + /* printf("\n ball movement \n"); */ + val_x = event.jball.xrel; + val_y = event.jball.yrel; + SDL_WarpMouse(oldpos_x + val_x, oldpos_y + val_y); +} + +static void handle_joybuttonupdown(SDL_Event event, int oldpos_x, int oldpos_y) { + SDL_Event ev; + + ev.button.x = oldpos_x; + ev.button.y = oldpos_y; + ev.button.button = SDL_BUTTON_LEFT; + + if (event.type == SDL_JOYBUTTONDOWN) + { + ev.button.type = SDL_MOUSEBUTTONDOWN; + ev.button.state = SDL_PRESSED; + } + else + { + ev.button.type = SDL_MOUSEBUTTONUP; + ev.button.state = SDL_RELEASED; + } + + SDL_PushEvent(&ev); +} + -- cgit v0.9.1