/* * @note Scrolling by `:pixel` may not actually be by real pixels, but instead * correspond to Cocoa co-ords (I don't have a retina display, so I * haven't checked it out yet). * * Generate `amount` scroll events at the current cursor position * * Returns number of lines/pixels scrolled, default `units` are by `line`. * A positive `amount` will scroll up and a negative `amount` will scroll down. * * An animation duration can also be specified, which defaults to 0.2 seconds. * * @overload scroll(amount) * @param amount [Number] * @return [Number] * @overload scroll(amount, units) * @param amount [Number] * @param units [Symbol] `:pixel` or `:line` * @return [Number] * @overload scroll(amount, units, duration) * @param amount [Number] * @param units [Symbol] `:pixel` or `:line` * @param duration [Number] animation time, in seconds * @return [Number] */ static VALUE rb_mouse_scroll(const int argc, VALUE* const argv, UNUSED const VALUE self) { if (argc == 0 || argc > 3) rb_raise(rb_eArgError, "scroll requires 1..3 arguments, you gave %d", argc); const int amt = NUM2INT(argv[0]); if (argc == 1) { mouse_scroll(amt); } else { const VALUE input_units = argv[1]; CGScrollEventUnit units = kCGScrollEventUnitLine; if (input_units == sym_pixel) units = kCGScrollEventUnitPixel; else if (input_units == sym_line) units = kCGScrollEventUnitLine; else rb_raise(rb_eArgError, "unknown units `%s'", rb_id2name(SYM2ID(input_units))); if (argc == 2) mouse_scroll2(amt, units); else mouse_scroll3(amt, units, NUM2DBL(argv[2])); } return argv[0]; }
static void process_event(const SDL_Event &event) { switch (event.type) { case SDL_MOUSEMOTION: if (get_game_state() == _game_in_progress) { mouse_moved(event.motion.xrel, event.motion.yrel); } break; case SDL_MOUSEWHEEL: if (get_game_state() == _game_in_progress) { bool up = (event.wheel.y > 0); #if SDL_VERSION_ATLEAST(2,0,4) if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) up = !up; #endif mouse_scroll(up); } break; case SDL_MOUSEBUTTONDOWN: if (get_game_state() == _game_in_progress) { if (!get_keyboard_controller_status()) { hide_cursor(); validate_world_window(); set_keyboard_controller_status(true); } else { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_MOUSE_BUTTON + event.button.button - 1); process_game_key(e2); } } else process_screen_click(event); break; case SDL_JOYBUTTONDOWN: if (get_game_state() == _game_in_progress) { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_JOYSTICK_BUTTON + event.button.button); process_game_key(e2); } break; case SDL_KEYDOWN: process_game_key(event); break; case SDL_TEXTINPUT: if (Console::instance()->input_active()) { Console::instance()->textEvent(event); } break; case SDL_QUIT: set_game_state(_quit_game); break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: if (get_game_state() == _game_in_progress && get_keyboard_controller_status() && !Movie::instance()->IsRecording()) { darken_world_window(); set_keyboard_controller_status(false); show_cursor(); } break; case SDL_WINDOWEVENT_EXPOSED: #if !defined(__APPLE__) && !defined(__MACH__) // double buffering :) #ifdef HAVE_OPENGL if (MainScreenIsOpenGL()) MainScreenSwap(); else #endif update_game_window(); #endif break; } break; } }