int SDL_AddMouse(const SDL_Mouse * mouse, char *name, int pressure_max, int pressure_min, int ends) { SDL_Mouse **mice; int selected_mouse; int index; size_t length; if (SDL_GetMouseIndexId(mouse->id) != -1) { SDL_SetError("Mouse ID already in use"); } /* Add the mouse to the list of mice */ mice = (SDL_Mouse **) SDL_realloc(SDL_mice, (SDL_num_mice + 1) * sizeof(*mice)); if (!mice) { SDL_OutOfMemory(); return -1; } SDL_mice = mice; index = SDL_num_mice++; SDL_mice[index] = (SDL_Mouse *) SDL_malloc(sizeof(*SDL_mice[index])); if (!SDL_mice[index]) { SDL_OutOfMemory(); return -1; } *SDL_mice[index] = *mouse; /* we're setting the mouse properties */ length = 0; length = SDL_strlen(name); SDL_mice[index]->focus = 0; SDL_mice[index]->name = SDL_malloc((length + 2) * sizeof(char)); SDL_strlcpy(SDL_mice[index]->name, name, length + 1); SDL_mice[index]->pressure_max = pressure_max; SDL_mice[index]->pressure_min = pressure_min; SDL_mice[index]->cursor_shown = SDL_TRUE; selected_mouse = SDL_SelectMouse(index); SDL_mice[index]->cur_cursor = NULL; SDL_mice[index]->def_cursor = SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); SDL_SetCursor(SDL_mice[index]->def_cursor); /* we're assuming that all mice are in the computer sensing zone */ SDL_mice[index]->proximity = SDL_TRUE; /* we're assuming that all mice are working in the absolute position mode thanx to that, the users that don't want to use many mice don't have to worry about anything */ SDL_mice[index]->relative_mode = SDL_FALSE; SDL_mice[index]->current_end = 0; SDL_mice[index]->total_ends = ends; SDL_SelectMouse(selected_mouse); return index; }
void iphone_controls::read_controls() { active_mice.clear(); #if defined(TARGET_OS_HARMATTAN) || defined(TARGET_BLACKBERRY) || defined(__ANDROID__) // there is no SDL_Get_NumMice and SDL_SelectMouse support on // Harmattan, so all_mice has been updated via calls to handle_event const int nmice = all_mice.size(); #else const int nmice = SDL_GetNumMice(); if(all_mice.size() > nmice) { all_mice.resize(nmice); } for(int i = 0; i < nmice; i++) { int x, y; SDL_SelectMouse(i); Uint8 button_state = SDL_GetMouseState(&x, &y); translate_mouse_coords(&x, &y); if(all_mice.size() == i) { all_mice.push_back(Mouse()); all_mice[i].active = false; } if(!all_mice[i].active) { all_mice[i].starting_x = x; all_mice[i].starting_y = y; } all_mice[i].x = x; all_mice[i].y = y; all_mice[i].active = button_state & SDL_BUTTON(SDL_BUTTON_LEFT); } #endif for(int i = 0; i < nmice; i++) { if(all_mice[i].active) { active_mice.push_back(all_mice[i]); } } }
variant playable_custom_object::get_player_value_by_slot(int slot) const { switch(slot) { case CUSTOM_OBJECT_PLAYER_DIFFICULTY: { if(preferences::force_difficulty() != INT_MIN) { return variant(preferences::force_difficulty()); } return variant(difficulty_); } case CUSTOM_OBJECT_PLAYER_CAN_INTERACT: { return variant(can_interact_); } case CUSTOM_OBJECT_PLAYER_UNDERWATER_CONTROLS: { return variant(underwater_controls_); } case CUSTOM_OBJECT_PLAYER_CTRL_MOD_KEY: { return variant(SDL_GetModState()); } case CUSTOM_OBJECT_PLAYER_CTRL_KEYS: { std::vector<variant> result; if(level_runner::get_current() && level_runner::get_current()->get_debug_console() && level_runner::get_current()->get_debug_console()->has_keyboard_focus()) { //the debug console is stealing all keystrokes. return variant(&result); } #if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR int ary_length; const Uint8* key_state = SDL_GetKeyboardState(&ary_length); #ifndef NO_EDITOR if(level_runner::get_current()) { const editor* e = level_runner::get_current()->get_editor(); if(e && e->has_keyboard_focus()) { //the editor has the focus, so we tell the game there //are no keys pressed. ary_length = 0; } } #endif for(int count = 0; count < ary_length; ++count) { if(key_state[count]) { //Returns only keys that are down so the list that ffl has to deal with is small. SDL_Keycode k = SDL_GetKeyFromScancode(SDL_Scancode(count)); if(k < 128 && util::c_isprint(k)) { std::string str(1,k); result.push_back(variant(str)); } else { result.push_back(variant(k)); } } } #endif return variant(&result); } case CUSTOM_OBJECT_PLAYER_CTRL_MICE: { std::vector<variant> result; #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR const int nmice = SDL_GetNumMice(); #else const int nmice = 1; #endif for(int n = 0; n != nmice; ++n) { #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR SDL_SelectMouse(n); #endif std::vector<variant> info; int x, y; Uint8 button_state = input::sdl_get_mouse_state(&x, &y); translate_mouse_coords(&x, &y); info.push_back(variant(x)); info.push_back(variant(y)); if(button_state & SDL_BUTTON(SDL_BUTTON_LEFT)) { info.push_back(variant("left")); } if(button_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) { info.push_back(variant("right")); } if(button_state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) { info.push_back(variant("middle")); } if(button_state & SDL_BUTTON(SDL_BUTTON_X1)) { //these aren't tested info.push_back(variant("x1")); } if(button_state & SDL_BUTTON(SDL_BUTTON_X2)) { info.push_back(variant("x2")); } result.push_back(variant(&info)); } return variant(&result); } case CUSTOM_OBJECT_PLAYER_CTRL_TILT: { return variant(-joystick::iphone_tilt()); } case CUSTOM_OBJECT_PLAYER_CTRL_X: { return variant(underwater_ctrl_x_); } case CUSTOM_OBJECT_PLAYER_CTRL_Y: { return variant(underwater_ctrl_y_); } case CUSTOM_OBJECT_PLAYER_CTRL_REVERSE_AB: { return variant::from_bool(reverse_ab_); } case CUSTOM_OBJECT_PLAYER_CONTROL_SCHEME: { return variant(preferences::control_scheme()); } case CUSTOM_OBJECT_PLAYER_VERTICAL_LOOK: { return variant(vertical_look_); } case CUSTOM_OBJECT_PLAYER_CONTROL_LOCK: { std::vector<variant> result; const unsigned char* locked_control_frame = controls::get_local_control_lock(); if (locked_control_frame == nullptr) { return variant(); } for(int i = 0; i < 8; ++i){ if((*locked_control_frame & (0x01 << i)) ){ result.push_back( variant(ctrl[i]) ); } else { //this key isn't pressed } } return variant(&result); } } ASSERT_LOG(false, "unknown slot in get_player_value_by_slot: " << slot); }
static int SDL_CompatEventFilter(void *userdata, SDL_Event * event) { SDL_Event fake; switch (event->type) { case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_EXPOSED: if (!SDL_HasEvent(SDL_VIDEOEXPOSEMASK)) { fake.type = SDL_VIDEOEXPOSE; SDL_PushEvent(&fake); } break; case SDL_WINDOWEVENT_RESIZED: SDL_PeepEvents(&fake, 1, SDL_GETEVENT, SDL_VIDEORESIZEMASK); fake.type = SDL_VIDEORESIZE; fake.resize.w = event->window.data1; fake.resize.h = event->window.data2; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_MINIMIZED: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 0; fake.active.state = SDL_APPACTIVE; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_RESTORED: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 1; fake.active.state = SDL_APPACTIVE; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_ENTER: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 1; fake.active.state = SDL_APPMOUSEFOCUS; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_LEAVE: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 0; fake.active.state = SDL_APPMOUSEFOCUS; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_FOCUS_GAINED: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 1; fake.active.state = SDL_APPINPUTFOCUS; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_FOCUS_LOST: fake.type = SDL_ACTIVEEVENT; fake.active.gain = 0; fake.active.state = SDL_APPINPUTFOCUS; SDL_PushEvent(&fake); break; case SDL_WINDOWEVENT_CLOSE: fake.type = SDL_QUIT; SDL_PushEvent(&fake); break; } case SDL_KEYDOWN: case SDL_KEYUP: { Uint32 unicode = 0; if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) { unicode = event->key.keysym.sym; if (unicode >= 'a' && unicode <= 'z') { int shifted = !!(event->key.keysym.mod & KMOD_SHIFT); int capslock = !!(event->key.keysym.mod & KMOD_CAPS); if ((shifted ^ capslock) != 0) { unicode = SDL_toupper(unicode); } } } if (unicode) { event->key.keysym.unicode = unicode; } break; } case SDL_TEXTINPUT: { /* FIXME: Generate an old style key repeat event if needed */ //printf("TEXTINPUT: '%s'\n", event->text.text); break; } case SDL_MOUSEWHEEL: { Uint8 button; int selected; int x, y; if (event->wheel.y == 0) { break; } selected = SDL_SelectMouse(event->wheel.which); SDL_GetMouseState(selected, &x, &y); SDL_SelectMouse(selected); if (event->wheel.y > 0) { button = SDL_BUTTON_WHEELUP; } else { button = SDL_BUTTON_WHEELDOWN; } fake.button.which = event->wheel.windowID; fake.button.button = button; fake.button.x = x; fake.button.y = y; fake.button.windowID = event->wheel.windowID; fake.type = SDL_MOUSEBUTTONDOWN; fake.button.state = SDL_PRESSED; SDL_PushEvent(&fake); fake.type = SDL_MOUSEBUTTONUP; fake.button.state = SDL_RELEASED; SDL_PushEvent(&fake); break; } } return 1; }