void SDL::setMousePosition(uint16_t x, uint16_t y) { SDL_WarpMouse(x, y); }
bool SDLInput::SetCursorPosition(math::Vector2i v2Pos) { m_cursorPos = v2Pos; SDL_WarpMouse(static_cast<Uint16>(v2Pos.x), static_cast<Uint16>(v2Pos.y)); return true; }
void RenderWindow::SetCursorPosition(int x, int y) { SDL_WarpMouse(x, y); }
/** * Funktion zum Setzen der Mauskoordinaten. * * @param[in] x X-Koordinate * @param[in] y Y-Koordinate * * @author FloSoft */ void VideoSDL::SetMousePos(int x, int y) { mouse_xy.x = x; mouse_xy.y = y; SDL_WarpMouse(x, y); }
/** * Set the current position of the mouse. * @param x The new X-position of the mouse. * @param y The new Y-position of the mouse. */ void Video_Mouse_SetPosition(uint16 x, uint16 y) { SDL_WarpMouse(x * SCREEN_MAGNIFICATION, y * SCREEN_MAGNIFICATION); }
void set_mouse_loc(int x, int y) { SDL_WarpMouse(x, y); }
void CApp::OnEvent(SDL_Event* Event) { int x,y; switch (Event->type) { case SDL_QUIT: Running = false; break; case SDL_MOUSEMOTION: x = screenX/2-Event->motion.x; y = screenY/2-Event->motion.y; if(x != 0 || y != 0) { player->RotationVec.y += x / 1000.0f; player->RotationVec.x += y / 1000.0f; } SDL_WarpMouse(screenX/2,screenY/2); break; case SDL_MOUSEBUTTONDOWN: if(lastMouseFire + 0.05 < gameTime) { player->Click(Event->button.button); lastMouseFire = gameTime; } break; case SDL_MOUSEBUTTONUP: if(lastMouseFireUp + 0.05 < gameTime) { player->ClickUp(Event->button.button); lastMouseFireUp = gameTime; } break; case SDL_KEYDOWN: switch(Event->key.keysym.sym){ case SDLK_a: player->MovingVec.x += -1; break; case SDLK_d: player->MovingVec.x += +1; break; case SDLK_w: player->MovingVec.z += +1; break; case SDLK_s: player->MovingVec.z += -1; break; case SDLK_ESCAPE: Running = false; break; default: break; } break; case SDL_KEYUP: switch(Event->key.keysym.sym){ case SDLK_a: player->MovingVec.x -= -1; break; case SDLK_d: player->MovingVec.x -= +1; break; case SDLK_w: player->MovingVec.z -= +1; break; case SDLK_s: player->MovingVec.z -= -1; break; case SDLK_ESCAPE: Running = false; break; default: break; } break; default: break; } }
void middleclickup (void) { arrowkey[UP] = 0; SDL_WarpMouse (oldmouse_x, oldmouse_y); }
void SDLWindow::setRelativeMousePosition(double x, double y) { SDL_WarpMouse(iRound(x), iRound(y)); }
//----------------------------------- Main ------------------------------------- int main(int argc, char *argv[]) { std::string cheat_string = "cheat"; //std::locale::global( std::locale( "" ) ); events_init(); game.log.File_Set("Star.P.G..log"); game.log.File_Clear(); if (argc > 1) { for (int count = 0; count < (argc+1); count++) { //game.log.File_Write(argv[count]); if (cheat_string.compare(argv[count]) == 0) game_o.cheats_enabled = true; } } //game_o.cheats_enabled = true; /// test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! game.log.File_Write("------------------"); game.log.File_Write("| Star.P.G V1.01 |"); game.log.File_Write("------------------\n"); game.log.File_Write("Starting up!"); game.log.File_Write(""); game.log.File_Write("------------------\n"); //if (game_o.cheats_enabled) game.log.File_Write("Cheating enabled!\n"); game.config.File_Set("Star.P.G..cfg"); game.config.Set_Defaults(); game.log.File_Write("Loading config..."); game.config.File_Set("Star.P.G..cfg"); game.config.File_Read(); game.log.File_Write("Loading language file -> data/configuration/languages/"+game.config.language+".txt"); game_o.language.load("data/configuration/languages/"+game.config.language+".txt"); //----------------------------------- Start the PhysicsFS ---------------------- //game.log.File_Write("Starting PhysicsFS..."); //PHYSFS_init(argv[0]); //PHYSFS_addToSearchPath("Star.P.G..spg", 1); //----------------------------------- SDL Video -------------------------------- game.log.File_Write("Starting SDL..."); char SDL_VID_WIN_POS[] = "SDL_VIDEO_WINDOW_POS"; char SDL_VID_CENTERD[] = "SDL_VIDEO_CENTERED=1"; putenv(SDL_VID_WIN_POS); putenv(SDL_VID_CENTERD); getenv("SDL_VIDEO_WINDOW_POS"); getenv("SDL_VIDEO_CENTERED"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD); game.log.File_Write("Starting OpenGL..."); if (game.config.Display_Fullscreen) SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL | SDL_FULLSCREEN); else SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL/* | SDL_NOFRAME */); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); App_Icon_Surface = SDL_LoadBMP(App_Icon); colorkey = SDL_MapRGB(App_Icon_Surface->format, 255, 0, 255); SDL_SetColorKey(App_Icon_Surface, SDL_SRCCOLORKEY, colorkey); SDL_WM_SetIcon(App_Icon_Surface,NULL); SDL_WM_SetCaption(App_Name, 0); //SDL_ShowCursor(SDL_DISABLE); //----------------------------------- SDL Audio -------------------------------- game.log.File_Write("Starting sound system..."); SDL_Init(SDL_INIT_AUDIO); Mix_AllocateChannels(game.config.Audio_Channels); Mix_OpenAudio(game.config.Audio_Rate, AUDIO_S16, 2, game.config.Audio_Buffers); Mix_Volume(-1,game.config.Audio_Sound_Volume); Mix_VolumeMusic(game.config.Audio_Music_Volume); game.log.File_Write("Initializing joystick / gamepad..."); SDL_Init(SDL_INIT_JOYSTICK); game.log.File_Write("Initializing game system..."); init_game(false); game.log.File_Write("Initializing projectiles..."); init_player_bullets(); game.log.File_Write("Initializing explosions..."); init_explosions(); game.log.File_Write("Initializing NPCs...\n"); init_active_npcs(); init_npc_bullets(); init_npcs(0); game_o.current_level = 0; game.log.File_Write("Initializing OpenGL..."); game.graphics.init_gl(game.config.Display_X_Resolution,game.config.Display_Y_Resolution); seed_rand(); TTF_Init(); game.log.File_Write("Loading resources..."); loading_screen_display("data/textures/misc/loading_screen.png"); load_resources(); game.log.File_Write("Initializing menu system..."); init_menu(); init_in_game_message_class(); init_projectiles(false); init_powerups(); init_shields(false); init_game(false); game.log.File_Write("Starting game..."); game.log.File_Write("---------------\n"); //----------------------------------- Main loop -------------------------------- game.timer.start(); game.LastTicks = game.timer.getticks(); for(int quit = 0; !quit;) { game.config.process(false); if (game.config.mouse_autohide) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); proc_textures(); events_process(); if (game.status_quit_active) quit = 1; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //****************************************** MENU ***************************************** if (game.menu_active) { SDL_ShowCursor(SDL_ENABLE); if (game.music_next_track) { music.menu_00.play(); game.music_next_track = false; } diplay_menu (); if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); } //****************************************** GAME ***************************************** if (game.game_active) { if (game.music_next_track) { game.music_next_track = false; if (game.music_track == 0) music.level_00.play(); if (game.music_track == 1) music.level_01.play(); if (game.music_track == 2) music.level_02.play(); if (game.music_track == 3) music.level_03.play(); if (game.music_track == 4) music.level_04.play(); if (game.music_track == 5) music.level_05.play(); if (game.music_track == 6) music.level_06.play(); if (game.music_track == 7) music.level_07.play(); if (game.music_track == 8) music.level_08.play(); if (game.music_track == 9) music.level_09.play(); if (game.music_track == 10) music.level_10.play(); if (game.music_track == 11) music.level_11.play(); if (game.music_track == 12) music.level_12.play(); if (game.music_track == 13) music.level_13.play(); if (game.music_track == 14) music.level_14.play(); if (game.music_track == 15) music.level_15.play(); if (game.music_track == 16) music.level_16.play(); if (game.music_track == 17) music.level_17.play(); if (game.music_track == 18) music.level_18.play(); if (game.music_track == 19) music.level_19.play(); if (game.music_track == 20) music.level_20.play(); if (game.music_track == 21) music.level_21.play(); if (game.music_track == 22) music.level_22.play(); if (game.music_track == 23) music.level_23.play(); if (game.music_track == 24) music.level_24.play(); if (game.music_track == 25) music.level_25.play(); } game.game_resume = true; if (game.process_ready) process_game(); display_game(); if ((game.config.Display_Touchscreen) && (game.process_ready)) { if(game.physics.point_in_quadrangle(-0.875f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.left = true; if(game.physics.point_in_quadrangle(-0.475f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.right = true; if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.350f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.up = true; if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.down = true; if(game.physics.point_in_quadrangle( 0.875f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.shoot = true; if(game.physics.point_in_quadrangle( 0.575f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.key_b = true; if(game.physics.point_in_quadrangle( 0.875f,0.2f, 0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.escape = true; } if (game_o.player.health < 0) { sound.menu_select_00.play(); game.game_active = false; game.game_resume = false; game.pdie_active = true; game.menu_level = 8; game.config.menu_delay_count = 0; music.level_pd.play(); game.background.set_data ( 2, 1, 1, 0.0f, 0.0f, 0.0050f, 0.0050f, texture.background_019.ref_number); game.background.set_data ( 1, 1, 1, 0.0f, 0.0f, 0.0020f, 0.0020f, texture.background_008.ref_number); game.background.set_active( 3, false); game.background.set_active( 4, false); game.background.set_movement_type(BOUNCE); SDL_WarpMouse(game.graphics.gl_to_res(game_over_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(game_over_menu.get_button_y_pos(1),game.config.mouse_resolution_y)); game.log.File_Write("User terminated due to insufficient health...better luck next time buddy!"); } if ((game.io.escape) && (game.process_ready)) { sound.menu_select_01.play(); game.music_next_track = true; game.game_active = false; game.menu_level = 1; game.menu_active = true; game.io.escape = false; game.io.keyboard_delay_count = 0; game.config.menu_delay_count = 0; while (game.config.menu_delay_count < (game.config.menu_delay/2)) { game.config.menu_delay_count++; } } if (game_o.bomb_delay_count < game_o.bomb_delay)//bomb delay counter { game_o.bomb_delay_count++; if (game_o.bomb_delay_count > game_o.bomb_delay) game_o.bomb_delay_count = game_o.bomb_delay; } if ((game.io.key_b) && (game.process_ready))//user pressed "b" for bomb { if ((game_o.number_bombs > 0) && (game_o.bomb_delay_count >= game_o.bomb_delay)) { game_o.number_bombs--; use_bomb_powerup(); game_o.bomb_delay_count = 0; if (!game_o.rumble.active) sound.explosion_001.play(); if (!game_o.rumble.active) game_o.rumble.start(0.025f,45); // shake the screen about. } } if (game.io.pause) { if (!game.game_paused) { game_o.paused.spawn(); game.game_paused = true; game.game_active = false; game.io.pause = false; game.menu_level = 11; SDL_WarpMouse(game.graphics.gl_to_res(pause_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(pause_menu.get_button_y_pos(1),game.config.mouse_resolution_y)); game.config.menu_delay_count = 0; while (game.config.menu_delay_count < (game.config.menu_delay*16)) { game.config.menu_delay_count++; } } else { game.menu_active = false; game.game_paused = false; game.game_active = true; } }; if (game_o.cheats_enabled == true) { if (game.io.key_0) game_o.victory_kills = game_o.level_kills; //complete level if (game.io.key_1) spawn_powerup(1.0f,random_GLcoord(), 1);//spawn health power-up if (game.io.key_2) spawn_powerup(1.0f,random_GLcoord(), 2);//spawn shield level power-up if (game.io.key_3) spawn_powerup(1.0f,random_GLcoord(), 3);//spawn shield new power-up if (game.io.key_4) spawn_powerup(1.0f,random_GLcoord(), 4);//spawn thruster level power-up if (game.io.key_5) spawn_powerup(1.0f,random_GLcoord(), 5);//spawn thruster new power-up if (game.io.key_6) spawn_powerup(1.0f,random_GLcoord(), 6);//spawn weapon level power-up if (game.io.key_7) spawn_powerup(1.0f,random_GLcoord(), 7);//spawn weapon new power-up if (game.io.key_8) unlock_levels(); //unlock all levels if (game.io.key_9) spawn_powerup(1.0f,random_GLcoord(), 8);//spawn bomb power-up if (game.io.key_a) game_o.anc_enabled = !game_o.anc_enabled; //toggle active NPC count display if (game.io.key_f) game_o.fps_enabled = !game_o.fps_enabled; //toggle active NPC count display if (game.io.key_q) spawn_powerup(1.0f,random_GLcoord(), 9);//spawn support ship 0 power-up if (game.io.key_w) spawn_powerup(1.0f,random_GLcoord(),10);//spawn support ship 1 power-up if (game.io.key_e) spawn_powerup(1.0f,random_GLcoord(),11);//spawn support ship 2 power-up if (game.io.key_r) spawn_powerup(1.0f,random_GLcoord(),12);//spawn support ship 3 power-up if (game.io.key_s) { if (!game_o.rumble.active) sound.explosion_001.play(); if (!game_o.rumble.active) game_o.rumble.start(); // shake the screen about. } } if (game.io.shoot) { process_supportships(true); if(game_o.fw_rof_count >= game_o.projectile[game_o.player.front_weapon].rate_of_fire) { spawn_player_bullet(0); game_o.fw_rof_count = 0; } if(game_o.sw_rof_count >= game_o.projectile[game_o.player.side_weapon].rate_of_fire) { spawn_player_bullet(1); game_o.sw_rof_count = 0; } } else { process_supportships(false); } if (game.process_ready) { if (game.io.up) process_player(1); if (game.io.down) process_player(2); if (game.io.right) process_player(3); if (game.io.left) process_player(4); } if ((game.io.key_1) && (game_o.projectile[ 0].active)) { game_o.player.front_weapon = 0; } if ((game.io.key_2) && (game_o.projectile[ 1].active)) { game_o.player.front_weapon = 1; } if ((game.io.key_3) && (game_o.projectile[ 2].active)) { game_o.player.front_weapon = 2; } if ((game.io.key_4) && (game_o.projectile[ 3].active)) { game_o.player.front_weapon = 3; } if ((game.io.key_5) && (game_o.projectile[ 4].active)) { game_o.player.front_weapon = 4; } if ((game.io.key_6) && (game_o.projectile[ 5].active)) { game_o.player.front_weapon = 5; } } //*********************************** Game paused ***************************************** if (game.game_paused) { if ((game.io.pause) && (game.process_ready)) { game.menu_active = false; game.game_paused = false; game.game_active = true; } if (game.music_next_track) { game.music_next_track = false; music.level_pd.play(); } game.menu_level = 11; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); display_game(); diplay_menu (); } //*********************************** PLAYER DEATH SCREEN ***************************************** if (game.pdie_active) { if (game.music_next_track) { game.music_next_track = false; music.level_pd.play(); } diplay_menu (); if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); if (!game.pdie_active) init_game(true); } //******************************* PLAYER NEXT LEVEL SCREEN ************************************* if (game.nlvl_active) { if (game.music_next_track) { game.music_next_track = false; music.level_nl.play(); } game.menu_level = 9; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); diplay_menu (); } //******************************* OUTRO SCREEN ************************************************* if (game.outr_active) { if (game.music_next_track) { game.music_next_track = false; music.outro_00.play(); } game.menu_level = 10; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); diplay_menu (); } //---------------------------- code for end of main loop ----------------------- game.FPS = (game.timer.getticks() - game.LastTicks); if ((game.timer.getticks() - game.LastTicks) >= 2) { game.LastTicks = game.timer.getticks(); game.process_ready = true; } else game.process_ready = false; SDL_GL_SwapBuffers(); } //----------------------------------- Exit ------------------------------------- game.log.File_Write("Saving configuration..."); game.config.File_Set("Star.P.G..cfg"); game.config.File_Clear(); game.config.File_Write(); game.log.File_Write("\n"); game.log.File_Write("Shutting down..."); game.log.File_Write("---------------\n"); // game.log.File_Write("PhysicsFS deinit..."); // PHYSFS_deinit(); game.log.File_Write("SDL deinit..."); SDL_Quit(); return(0); }
int main(int argc, char *argv[]) { SDL_Surface *screen; Uint8 *mem; int width, height; Uint8 video_bpp; Uint32 videoflags; Uint32 background; int i, done; SDL_Event event; Uint32 then, now, frames; /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); exit(1); } atexit(SDL_Quit_Wrapper); numsprites = NUM_SPRITES; videoflags = SDL_SWSURFACE|SDL_ANYFORMAT; width = 640; height = 480; video_bpp = 8; while ( argc > 1 ) { --argc; if ( strcmp(argv[argc-1], "-width") == 0 ) { width = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-height") == 0 ) { height = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-bpp") == 0 ) { video_bpp = atoi(argv[argc]); videoflags &= ~SDL_ANYFORMAT; --argc; } else if ( strcmp(argv[argc], "-fast") == 0 ) { videoflags = FastestFlags(videoflags, width, height, video_bpp); } else if ( strcmp(argv[argc], "-hw") == 0 ) { videoflags ^= SDL_HWSURFACE; } else if ( strcmp(argv[argc], "-flip") == 0 ) { videoflags ^= SDL_DOUBLEBUF; } else if ( strcmp(argv[argc], "-fullscreen") == 0 ) { videoflags ^= SDL_FULLSCREEN; } else if ( isdigit(argv[argc][0]) ) { numsprites = atoi(argv[argc]); } else { fprintf(stderr, "Usage: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen] [numsprites]\n", argv[0]); exit(1); } } /* Set video mode */ screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); if ( ! screen ) { fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", width, height, SDL_GetError()); exit(2); } /* Load the sprite */ if ( LoadSprite(screen, "icon.bmp") < 0 ) { exit(1); } /* Allocate memory for the sprite info */ mem = (Uint8 *)malloc(4*sizeof(SDL_Rect)*numsprites); if ( mem == NULL ) { SDL_FreeSurface(sprite); fprintf(stderr, "Out of memory!\n"); exit(2); } sprite_rects = (SDL_Rect *)mem; positions = sprite_rects; sprite_rects += numsprites; velocities = sprite_rects; sprite_rects += numsprites; sprite_w = sprite->w; sprite_h = sprite->h; srand(time(NULL)); for ( i=0; i<numsprites; ++i ) { positions[i].x = rand()%(screen->w - sprite_w); positions[i].y = rand()%(screen->h - sprite_h); positions[i].w = sprite->w; positions[i].h = sprite->h; velocities[i].x = 0; velocities[i].y = 0; while ( ! velocities[i].x && ! velocities[i].y ) { velocities[i].x = (rand()%(MAX_SPEED*2+1))-MAX_SPEED; velocities[i].y = (rand()%(MAX_SPEED*2+1))-MAX_SPEED; } } background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00); /* Print out information about our surfaces */ printf("Screen is at %d bits per pixel\n",screen->format->BitsPerPixel); if ( (screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { printf("Screen is in video memory\n"); } else { printf("Screen is in system memory\n"); } if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { printf("Screen has double-buffering enabled\n"); } if ( (sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE ) { printf("Sprite is in video memory\n"); } else { printf("Sprite is in system memory\n"); } /* Run a sample blit to trigger blit acceleration */ { SDL_Rect dst; dst.x = 0; dst.y = 0; dst.w = sprite->w; dst.h = sprite->h; SDL_BlitSurface(sprite, NULL, screen, &dst); SDL_FillRect(screen, &dst, background); } if ( (sprite->flags & SDL_HWACCEL) == SDL_HWACCEL ) { printf("Sprite blit uses hardware acceleration\n"); } if ( (sprite->flags & SDL_RLEACCEL) == SDL_RLEACCEL ) { printf("Sprite blit uses RLE acceleration\n"); } /* Loop, blitting sprites and waiting for a keystroke */ frames = 0; then = SDL_GetTicks(); done = 0; sprites_visible = 0; while ( !done ) { /* Check for events */ ++frames; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: SDL_WarpMouse(screen->w/2, screen->h/2); break; case SDL_KEYDOWN: /* Any keypress quits the app... */ case SDL_QUIT: done = 1; break; default: break; } } MoveSprites(screen, background); } SDL_FreeSurface(sprite); free(mem); /* Print out some timing information */ now = SDL_GetTicks(); if ( now > then ) { printf("%2.2f frames per second\n", ((double)frames*1000)/(now-then)); } SDL_Quit(); return(0); }
int main(int argc, char *argv[]) #endif { UNUSED(argc); UNUSED(argv); TUpdate lUpdate = {0,}; TConfig lConfig = { 800 /* width */, 600 /* height */, 16 /* bpp */, false /* fullscreen */, "LDPrototype", /* title */ 16, /* Hz */ 1, /* VSync */ 0, /* Multisampling (0 == disabled) */ false, /* Grab Input */ false, /* Hide Cursor */ false, /* Center Cursor */ false /* Audio */ }; DemoConfig(&lConfig); if(SDL_Init(SDL_INIT_EVERYTHING)<0) { printf("SDL_init: %s\n", SDL_GetError()); return -1; } /*! Initialize random seed */ srand(time(NULL)); if(lConfig.mAudio) { if(Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 1024) < 0) { printf("Mix_OpenAudio: %s\n", Mix_GetError()); return -2; } } /* Input */ uint32 lCenterX = lConfig.mWidth / 2; uint32 lCenterY = lConfig.mHeight/ 2; if(lConfig.mGrabInput) SDL_WM_GrabInput(SDL_GRAB_ON); if(lConfig.mHideCursor) SDL_ShowCursor(SDL_DISABLE); SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); /* OpenGL */ SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, lConfig.mVSync ); if(lConfig.mMultiSampling) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, lConfig.mMultiSampling); } /* Window */ uint32 lFlags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL; if(lConfig.mFullScreen) lFlags |= SDL_FULLSCREEN; SDL_Surface *lScreen = SDL_SetVideoMode(lConfig.mWidth, lConfig.mHeight, lConfig.mBpp, lFlags); if(lScreen == NULL) { printf("SDL_SetVideoMode: %s\n", SDL_GetError()); return -3; } if(lConfig.mTitle!=NULL) SDL_WM_SetCaption(lConfig.mTitle, lConfig.mTitle); /* OpenGL Again */ uint32 lError = 0; if((lError=glewInit()) != GLEW_OK) { printf("glewInit: %s\n", glewGetErrorString(lError)); goto exit; } if(!GLEW_VERSION_2_0) { printf("OpenGL 2.0 is not available.\n"); goto exit; } { int lTexImageUnits = 0; int lTexUnits = 0; glGetIntegerv(GL_MAX_TEXTURE_UNITS,&lTexUnits); glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS,&lTexImageUnits); printf("%d Texture and %d Image Units ...\n",lTexUnits, lTexImageUnits); if(lTexUnits<4) { printf(" => WARNING: You don't seem to have at least 4 Texture Units ...\n"); goto exit; } } if(!GLEW_EXT_framebuffer_object) { printf(" => WARNING: GL_EXT_framebuffer_object is not supported ...\n"); goto exit; } if(!GLEW_EXT_framebuffer_multisample) { printf(" => WARNING: GL_EXT_framebuffer_multisample is not supported ...\n"); goto exit; } if(!GLEW_EXT_framebuffer_blit) { printf(" => WARNING: GL_EXT_framebuffer_blit is not supported ...\n"); goto exit; } printf("Non Power Of Two Textures: %s\n", (GLEW_ARB_texture_non_power_of_two)?"yes":"no"); /* Init the demo */ if(!DemoInit(&lConfig)) goto demo_exit; lUpdate.mStartTime = SDL_GetTicks(); /* Event Loop */ while(1) { SDL_Event lEvent; while (SDL_PollEvent(&lEvent)) { switch(lEvent.type) { case SDL_QUIT: { lUpdate.mKeys[SDLK_ESCAPE] = true; } break; case SDL_KEYDOWN: { lUpdate.mKeys[lEvent.key.keysym.sym] = true; } break; case SDL_KEYUP: { lUpdate.mKeys[lEvent.key.keysym.sym] = false; } break; case SDL_MOUSEMOTION: { lUpdate.mMouseX = lEvent.motion.x; lUpdate.mMouseY = lEvent.motion.y; lUpdate.mMouseDeltaX = lEvent.motion.xrel; lUpdate.mMouseDeltaY = lEvent.motion.yrel; } break; } } if(lUpdate.mKeys[SDLK_ESCAPE]) { lUpdate.mKeys[SDLK_ESCAPE] = false; goto demo_exit; } if(lConfig.mCenterCursor) SDL_WarpMouse( lCenterX, lCenterY ); if(!DemoUpdate(&lConfig, &lUpdate)) break; DemoRender(&lConfig, &lUpdate); lUpdate.mLastTime = lUpdate.mTime; lUpdate.mTime = SDL_GetTicks(); lUpdate.mElapsedTime = lUpdate.mTime - lUpdate.mStartTime; lUpdate.mDeltaTime = (lUpdate.mTime - lUpdate.mLastTime); if(lUpdate.mDeltaTime < lConfig.mHz) SDL_Delay( lConfig.mHz - lUpdate.mDeltaTime ); } demo_exit: DemoShutdown(); exit: if(lConfig.mAudio) { Mix_CloseAudio(); } SDL_Quit(); printf("Sayonara ...\n"); return 0; }
static void IN_DeactivateMouse(void) { if (!SDL_WasInit(SDL_INIT_VIDEO)) { return; } // Always show the cursor when the mouse is disabled, // but not when fullscreen if (!Cvar_VariableIntegerValue("r_fullscreen")) { #if 0 if ((Key_GetCatcher() == KEYCATCH_UI) && (SDL_GetAppState() & SDL_APPMOUSEFOCUS)) { SDL_ShowCursor(0); } else #endif { SDL_ShowCursor(1); } } if (!mouseAvailable) { return; } #ifdef MACOS_X_ACCELERATION_HACK if (mouseActive) // mac os x mouse accel hack { if (originalMouseSpeed != -1.0) { io_connect_t mouseDev = IN_GetIOHandle(); if (mouseDev != 0) { Com_Printf("restoring mouse acceleration to: %f\n", originalMouseSpeed); if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) { Com_Printf("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); } IOServiceClose(mouseDev); } else { Com_Printf("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); } } } #endif if (mouseActive) { IN_GobbleMotionEvents(); SDL_WM_GrabInput(SDL_GRAB_OFF); // Don't warp the mouse unless the cursor is within the window if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) { SDL_WarpMouse(cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2); } mouseActive = qfalse; } }
void SurfaceSdlGraphicsManager::warpMouse(int x, int y) { //ResidualVM specific SDL_WarpMouse(x, y); }
void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) { SDL_WarpMouse(x, y); }
void SDLInputBackend::setMouseWindowPosition(int32_t x, int32_t y) { SDL_WarpMouse((uint16_t)x, (uint16_t)y); }
// // UpdateJoystick // uint32_t Xbox::UpdateJoystick(void *obj, uint32_t ival, void *arg) { int16_t axis_x = 0, axis_y = 0; int16_t move_x = 0, move_y = 0; int mouse_x, mouse_y; uint8_t button; uint8_t hat; if(!SDL_JoystickOpened(JOYPAD1) || !OpenedJoy) return false; // Get the cursor position SDL_GetMouseState(&mouse_x, &mouse_y); // Get the current joystick state SDL_JoystickUpdate(); // Left Stick X Axis axis_x = SDL_JoystickGetAxis(OpenedJoy, JOY_AXIS_LX); // Left Stick Y Axis axis_y = SDL_JoystickGetAxis(OpenedJoy, JOY_AXIS_LY); if(axis_x || axis_y) { if(axis_x > JOY_DEADZONE) axis_x -= JOY_DEADZONE; else if(axis_x < -JOY_DEADZONE) axis_x += JOY_DEADZONE; else axis_x = 0; if(axis_y > JOY_DEADZONE) axis_y -= JOY_DEADZONE; else if(axis_y < -JOY_DEADZONE) axis_y += JOY_DEADZONE; else axis_y = 0; move_x = mouse_x; move_y = mouse_y; if(axis_x) move_x += axis_x / 2000; if(axis_y) move_y += axis_y / 2000; // Move the cursor if(move_x != mouse_x || move_y != mouse_y) SDL_WarpMouse(move_x, move_y); } // Get all the button states for(int i = 0; i < JOY_BTTN_TOTAL; i++) { SDL_Event ev; button = SDL_JoystickGetButton(OpenedJoy, i); // Mouse Button Translations if(i == JOY_BTTN_A) { if(button && !BPressed[i]) { ev.button.type = SDL_MOUSEBUTTONDOWN; ev.button.state = SDL_PRESSED; } else if(!button && BPressed[i]) { ev.button.type = SDL_MOUSEBUTTONUP; ev.button.state = SDL_RELEASED; } else continue; ev.button.which = 0; ev.button.button = SDL_BUTTON_LEFT; ev.button.x = mouse_x; ev.button.y = mouse_y; } // Keyboard Translations else if(i == JOY_BTTN_B || i == JOY_BTTN_LTRIG || i == JOY_BTTN_RTRIG) { if(button && !BPressed[i]) { ev.key.type = SDL_KEYDOWN; ev.key.state = SDL_PRESSED; } else if(!button && BPressed[i]) { ev.key.type = SDL_KEYUP; ev.key.state = SDL_RELEASED; } else continue; if(i == JOY_BTTN_B) ev.key.keysym.sym = SDLK_RETURN; else if(i == JOY_BTTN_LTRIG) ev.key.keysym.sym = SDLK_PAGEUP; else ev.key.keysym.sym = SDLK_PAGEDOWN; } else continue; BPressed[i] = !BPressed[i]; // Push the translated event SDL_PushEvent(&ev); } // Hat (D-Pad) hat = SDL_JoystickGetHat(OpenedJoy, 0); if(HPressed) // A hat position is recorded { if(!(hat & HPressed)) { SDL_Event ev; ev.key.type = SDL_KEYUP; ev.key.state = SDL_RELEASED; if(HPressed == SDL_HAT_UP) ev.key.keysym.sym = SDLK_UP; else if(HPressed == SDL_HAT_DOWN) ev.key.keysym.sym = SDLK_DOWN; else ev.key.keysym.sym = SDLK_TAB; SDL_PushEvent(&ev); // In the Agar tabcycle code the action is taken when the tab keyup // event is received and it is then that the shift modifier is tested // so shift needs to be released after the tab event has been pushed or // the modifier will not be active when the test occurs. if(HPressed == SDL_HAT_LEFT) { // Push the mod keyup event ev.key.keysym.sym = SDLK_LSHIFT; SDL_PushEvent(&ev); } HPressed = 0; } } if(!HPressed) // Either nothing was pushed before or the state has changed { SDL_Event ev; ev.key.type = SDL_KEYDOWN; ev.key.state = SDL_PRESSED; if(hat & SDL_HAT_UP) { ev.key.keysym.sym = SDLK_UP; HPressed = SDL_HAT_UP; } else if(hat & SDL_HAT_DOWN) { ev.key.keysym.sym = SDLK_DOWN; HPressed = SDL_HAT_DOWN; } else if(hat & SDL_HAT_RIGHT) { ev.key.keysym.sym = SDLK_TAB; HPressed = SDL_HAT_RIGHT; } else if(hat & SDL_HAT_LEFT) { // Push the mod keydown event ev.key.keysym.sym = SDLK_LSHIFT; SDL_PushEvent(&ev); ev.key.keysym.sym = SDLK_TAB; HPressed = SDL_HAT_LEFT; } if(HPressed) SDL_PushEvent(&ev); } // Repeat after interval return ival; }
/** * Handles moving over the minimap. * Will change the camera center when the mouse is moved in mouse-moving mode. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void MiniMapView::mouseOver(Action *action, State *state) { InteractiveSurface::mouseOver(action, state); if (_isMouseScrolling && action->getDetails()->type == SDL_MOUSEMOTION) { // The following is the workaround for a rare problem where sometimes // the mouse-release event is missed for any reason. // However if the SDL is also missed the release event, then it is to no avail :( // (checking: is the dragScroll-mouse-button still pressed?) if (0==(SDL_GetMouseState(0,0)&SDL_BUTTON(Options::battleDragScrollButton))) { // so we missed again the mouse-release :( // Check if we have to revoke the scrolling, because it was too short in time, so it was a click if ((!_mouseMovedOverThreshold) && ((int)(SDL_GetTicks() - _mouseScrollingStartTime) <= (Options::dragScrollTimeTolerance))) { _camera->centerOnPosition(_posBeforeMouseScrolling); _redraw = true; } _isMouseScrolled = _isMouseScrolling = false; stopScrolling(action); return; } _isMouseScrolled = true; if (Options::touchEnabled == false) { // Set the mouse cursor back SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_WarpMouse(_xBeforeMouseScrolling, _yBeforeMouseScrolling); SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE); } // Check the threshold _totalMouseMoveX += action->getDetails()->motion.xrel; _totalMouseMoveY += action->getDetails()->motion.yrel; if (!_mouseMovedOverThreshold) _mouseMovedOverThreshold = ((std::abs(_totalMouseMoveX) > Options::dragScrollPixelTolerance) || (std::abs(_totalMouseMoveY) > Options::dragScrollPixelTolerance)); // Calculate the move int newX, newY; int scrollX, scrollY; if (Options::battleDragScrollInvert) { scrollX = action->getDetails()->motion.xrel; scrollY = action->getDetails()->motion.yrel; } else { scrollX = -action->getDetails()->motion.xrel; scrollY = -action->getDetails()->motion.yrel; } _mouseScrollX += scrollX; _mouseScrollY += scrollY; newX = _posBeforeMouseScrolling.x + _mouseScrollX / action->getXScale() / 4; newY = _posBeforeMouseScrolling.y + _mouseScrollY / action->getYScale() / 4; // Keep the limits... if (newX < -1 || _camera->getMapSizeX() < newX) { _mouseScrollX -= scrollX; newX = _posBeforeMouseScrolling.x + _mouseScrollX / 4; } if (newY < -1 || _camera->getMapSizeY() < newY) { _mouseScrollY -= scrollY; newY = _posBeforeMouseScrolling.y + _mouseScrollY / 4; } // Scrolling _camera->centerOnPosition(Position(newX,newY,_camera->getViewLevel())); _redraw = true; if (Options::touchEnabled == false) { // We don't want to see the mouse-cursor jumping :) if (Options::battleDragScrollInvert) { action->getDetails()->motion.x = _xBeforeMouseScrolling; action->getDetails()->motion.y = _yBeforeMouseScrolling; } else { Position delta(-scrollX, -scrollY, 0); int barWidth = _game->getScreen()->getCursorLeftBlackBand(); int barHeight = _game->getScreen()->getCursorTopBlackBand(); int cursorX = _cursorPosition.x + delta.x; int cursorY =_cursorPosition.y + delta.y; _cursorPosition.x = std::min((int)Round((getX() + getWidth()) * action->getXScale()) + barWidth, std::max((int)Round(getX() * action->getXScale()) + barWidth, cursorX)); _cursorPosition.y = std::min((int)Round((getY() + getHeight()) * action->getYScale()) + barHeight, std::max((int)Round(getY() * action->getYScale()) + barHeight, cursorY)); action->getDetails()->motion.x = _cursorPosition.x; action->getDetails()->motion.y = _cursorPosition.y; } } _game->getCursor()->handle(action); } }
int main(void) { unsigned ticksPerFrame = 1000/FRAMES_PER_SECOND; SDL_Surface* screen; Context* ct; if(SDL_Init(SDL_INIT_EVERYTHING) != 0) { fprintf(stderr,"SDL init failed"); return -1; } if(!(screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT, SCREEN_BPP,SDL_SWSURFACE))) { fprintf(stderr,"SDL video init failed"); return -1; } if(!(ct = createContext(SCREEN_WIDTH,SCREEN_HEIGHT))) { fprintf(stderr,"Context init failed"); return -1; } ct->depthEnabled = 1; ct->cullBackFace = 1; ct->frontFace = WINDING_CCW; ct->vertShader = &shadeVertex; ct->fragShader = &shadeFragment; mat44Perspective(matStackTop(ct->matrices[MATRIX_PROJECTION]), FOVY,SCREEN_WIDTH/(float)SCREEN_HEIGHT,1,30); printf("Projection:\n"); mat44Print(stdout,matStackTop(ct->matrices[MATRIX_PROJECTION])); mat44Ident(matStackTop(ct->matrices[MATRIX_MODELVIEW])); Mat44 translate; mat44Translate(translate,0,0,-4); Mat44 rotateVert; mat44Ident(rotateVert); Mat44 tetraTransform; mat44Ident(tetraTransform); float tetraHorizRot = 0, tetraVertRot = 0; VertexArray* varr = createVertArray(0,NULL); varr->locs = &verts[0].loc; varr->locStep = sizeof(CustomVert); varr->colors = &verts[0].color; varr->colorStep = sizeof(CustomVert); Color4 black = { 0,0,0,0 }; CustomVert* gridVerts; unsigned* gridIndices; unsigned gridNumEdges; makeGrid(&gridVerts,&gridIndices,&gridNumEdges, -6,-6,6,6,12,12); VertexArray* gridArr = createVertArray(0,NULL); gridArr->locs = &gridVerts[0].loc; gridArr->locStep = sizeof(CustomVert); gridArr->colors = &gridVerts[0].color; gridArr->colorStep = sizeof(CustomVert); Mat44 gridTransform; mat44Translate(gridTransform,0,-5,0); SDL_WM_SetCaption(TITLE,NULL); char title[256]; float fps = 0; float fpsLerp = 0.2; int numViewports = 1; int mouseCaptured = 0; int running = 1; int debugged = 0; while(running) { Uint32 startTicks = SDL_GetTicks(); int vertRot = 0, horizRot = 0; SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: running = 0; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_ESCAPE: mouseCaptured = !mouseCaptured; SDL_ShowCursor(mouseCaptured ? SDL_DISABLE : SDL_ENABLE); break; case SDLK_p: debugged = 0; break; case SDLK_BACKQUOTE: if(numViewports == 1) { numViewports = 2; } else { numViewports = 1; } mat44Perspective(matStackTop(ct->matrices[MATRIX_PROJECTION]), FOVY,SCREEN_WIDTH/(float)numViewports/SCREEN_HEIGHT,1,30); break; default: break; } break; case SDL_MOUSEMOTION: if(mouseCaptured) { SDL_WarpMouse(SCREEN_WIDTH/2,SCREEN_HEIGHT/2); horizRot = -event.motion.xrel, vertRot = event.motion.yrel; } break; default: break; } } if(!debugged) { printf("\nDebugging!\n\n"); } clearColorBuffer(ct); fillDepthBuffer(ct,1); /* fillBuffers(ct,black,1); */ Uint8* keys = SDL_GetKeyState(NULL); if(!mouseCaptured) { vertRot = horizRot = 0; if(keys[SDLK_UP]) { vertRot += 1; } if(keys[SDLK_DOWN]) { vertRot -= 1; } if(keys[SDLK_RIGHT]) { horizRot += 1; } if(keys[SDLK_LEFT]) { horizRot -= 1; } } int xDelta = 0, yDelta = 0, zDelta = 0; if(keys[SDLK_w]) { zDelta -= 1; } if(keys[SDLK_s]) { zDelta += 1; } if(keys[SDLK_a]) { xDelta -= 1; } if(keys[SDLK_d]) { xDelta += 1; } if(keys[SDLK_RSHIFT] || keys[SDLK_LSHIFT]) { yDelta -= 1; } if(keys[SDLK_SPACE]) { yDelta += 1; } Mat44 tmp; if(xDelta || yDelta || zDelta) { float xDiff = xDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME, yDiff = yDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME, zDiff = zDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME; mat44Translate(tmp,-xDiff,-yDiff,-zDiff); mat44Mult(translate,tmp,translate); } if(vertRot) { float vertDiff = vertRot*(mouseCaptured ? DEGREES_PER_PIXEL : ROTATION_SPEED*SECONDS_PER_FRAME); mat44Rotate(tmp,vertDiff,-1,0,0); mat44Mult(rotateVert,tmp,rotateVert); } if(horizRot) { float horizDiff = horizRot*(mouseCaptured ? DEGREES_PER_PIXEL : ROTATION_SPEED*SECONDS_PER_FRAME); mat44Rotate(tmp,horizDiff,0,1,0); mat44Mult(translate,tmp,translate); } tetraHorizRot += TETRA_HORIZ_ROTATION_SPEED*SECONDS_PER_FRAME; tetraVertRot += TETRA_VERT_ROTATION_SPEED *SECONDS_PER_FRAME; mat44Rotate(tetraTransform,tetraHorizRot,0,1,0); mat44Rotate(tmp,tetraHorizRot,0,1,0); Vec4 xAxis = { 1,0,0,1 }; mat44MultVec4(xAxis,tmp,xAxis); mat44Rotate(tmp,tetraVertRot,xAxis[0],xAxis[1],xAxis[2]); mat44Mult(tetraTransform,tetraTransform,tmp); ct->viewport.width = ct->_width/numViewports; unsigned i; for(i=0;i<numViewports;++i) { ct->viewport.x = ct->_width-ct->viewport.width*(i+1); matStackPush(ct->matrices[MATRIX_MODELVIEW]); if(i == 0) { matStackMult(ct->matrices[MATRIX_MODELVIEW],rotateVert); matStackMult(ct->matrices[MATRIX_MODELVIEW],translate); } else { mat44Translate(tmp,0,0,-5); matStackMult(ct->matrices[MATRIX_MODELVIEW],tmp); } //drawShapeIndexed(ct,SHAPE_TRIANGLE,4,varr,indices); matStackPush(ct->matrices[MATRIX_MODELVIEW]); matStackMult(ct->matrices[MATRIX_MODELVIEW],gridTransform); drawShapeIndexed(ct,SHAPE_LINE,gridNumEdges,gridArr,gridIndices); matStackPop(ct->matrices[MATRIX_MODELVIEW]); matStackPush(ct->matrices[MATRIX_MODELVIEW]); matStackMult(ct->matrices[MATRIX_MODELVIEW],tetraTransform); drawShapeIndexed(ct,SHAPE_TRIANGLE,4,varr,indices); matStackPop(ct->matrices[MATRIX_MODELVIEW]); matStackPop(ct->matrices[MATRIX_MODELVIEW]); debugged = 1; } SDL_BlitSurface(ct->surface,NULL,screen,NULL); SDL_Flip(screen); unsigned elapsedTime = SDL_GetTicks()-startTicks; /* printf("%d ms/frame\n",elapsedTime); */ unsigned currFps = 1000/elapsedTime; if(currFps > FRAMES_PER_SECOND) { currFps = FRAMES_PER_SECOND; } fps = fpsLerp*currFps+(1-fpsLerp)*fps; sprintf(title,"%s %u/%u ms%s",TITLE,elapsedTime,ticksPerFrame, elapsedTime > ticksPerFrame ? "!!":""); SDL_WM_SetCaption(title,NULL); if(elapsedTime < ticksPerFrame) { SDL_Delay(ticksPerFrame-elapsedTime); } } free(gridVerts); free(gridIndices); freeVertArray(gridArr); freeVertArray(varr); freeContext(ct); return 0; }
void ZGameWindow_Storage::Show() { ZVector2f Rp, Ip, Size; ZActor * Actor; ULong x,y; Actor = GameEnv->PhysicEngine->GetSelectedActor(); if (!Actor) return; // Running position computing Ip.x = 32.0f; Ip.y = 25.0f; Rp.x = Ip.x; Rp.y = Ip.y; // Main Window ZVector2f MainWindow_Pos,MainWindow_Size; MainWindow_Size.x = 758.0f; MainWindow_Size.y = 600.0f; MainWindow_Pos.x = ((float)GameEnv->ScreenResolution.x - MainWindow_Size.x) / 2.0f; MainWindow_Pos.y = ((float)GameEnv->ScreenResolution.y - MainWindow_Size.y) / 2.0f; MainWindow->SetPosition( MainWindow_Pos.x, MainWindow_Pos.y ); MainWindow->SetSize(MainWindow_Size.x,MainWindow_Size.y); MainWindow->SetTexture(8); GameEnv->GuiManager.AddFrame(MainWindow); // CloseBox Size.x = 32.0f; Size.y = 32.0f; CloseBox.SetPosition(MainWindow_Size.x - Size.x - 5.0f, 5.0f); CloseBox.SetSize(Size.x, Size.y); CloseBox.SetTileSet(GameEnv->GuiTileset); CloseBox.SetTile(11); MainWindow->AddFrame(&CloseBox); // Inventory main title MainTitle.SetStyle(GameEnv->TileSetStyles->GetStyle(ZGame::FONTSIZE_3)); MainTitle.SetDisplayText(Text_MainTitle.String); MainTitle.GetTextDisplaySize(&Size); MainTitle.SetPosition(MainWindow_Size.x / 2.0f - Size.x / 2.0f ,Rp.y); MainTitle.SetSize(Size.x,Size.y); MainTitle.SetColor(255.0f,255.0f,255.0f); MainWindow->AddFrame(&MainTitle); Rp.y += Size.y + 20.0f; // Tools Title StorageTitle.SetStyle(GameEnv->TileSetStyles->GetStyle(ZGame::FONTSIZE_1)); StorageTitle.SetDisplayText(Text_StorageTitle.String); StorageTitle.GetTextDisplaySize(&Size); StorageTitle.SetPosition(Rp.x ,Rp.y); StorageTitle.SetSize(Size.x,Size.y); StorageTitle.SetColor(255.0f,255.0f,255.0f); MainWindow->AddFrame(&StorageTitle); Rp.y += Size.y + 5.0f; // Tools for (y=0;y<4;y++) { for (x=0;x<10;x++) { ULong Indice = 0 + x + y * 10; MainStorage[Indice].SetVoxelTypeManager(&GameEnv->VoxelTypeManager); MainStorage[Indice].SetPosition(32.0f + x*70.0f, Rp.y ); MainStorage[Indice].SetSize(48.0f,48.0f); MainStorage[Indice].SetTileStyle(GameEnv->TileSetStyles->GetStyle(3)); MainStorage[Indice].SetVoxelType(&VoxelExtension_Storage->VoxelType[Indice]); MainStorage[Indice].SetQuantity(&VoxelExtension_Storage->VoxelQuantity[Indice]); MainStorage[Indice].SetColor(128.0f,128.0f,128.0f); MainWindow->AddFrame(&MainStorage[Indice]); } Rp.y += 48.0f + 6.0f; } Rp.y += 12.0f; // Inventory Zone Title InventoryTitle.SetStyle(GameEnv->TileSetStyles->GetStyle(ZGame::FONTSIZE_1)); InventoryTitle.SetDisplayText(Text_InventoryTitle.String); InventoryTitle.GetTextDisplaySize(&Size); InventoryTitle.SetPosition(Rp.x ,Rp.y); InventoryTitle.SetSize(Size.x,Size.y); InventoryTitle.SetColor(255.0f,255.0f,255.0f); MainWindow->AddFrame(&InventoryTitle); Rp.y += Size.y + 5.0f; // Inventory for (y=0;y<4;y++) { for (x=0;x<10;x++) { ULong Indice = ZInventory::Inventory_StartSlot + x + y * 10; ZInventory::Entry * Entry = Actor->Inventory->GetSlotRef(Indice); MainStorage[Indice+40].SetVoxelTypeManager(&GameEnv->VoxelTypeManager); MainStorage[Indice+40].SetPosition(32.0f + x*70.0f, Rp.y ); MainStorage[Indice+40].SetSize(48.0f,48.0f); MainStorage[Indice+40].SetTileStyle(GameEnv->TileSetStyles->GetStyle(3)); MainStorage[Indice+40].SetVoxelType(&Entry->VoxelType); MainStorage[Indice+40].SetQuantity(&Entry->Quantity); MainStorage[Indice+40].SetColor(128.0f,128.0f,128.0f); MainWindow->AddFrame(&MainStorage[Indice+40]); } Rp.y += 48.0f + 6.0f; } Rp.y += 12.0f; SDL_ShowCursor(SDL_ENABLE); SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WarpMouse((Uint16)(MainWindow_Pos.x + MainWindow_Size.x / 2.0f),(Uint16)(MainWindow_Pos.y + MainWindow_Size.y / 2.0f)); GameEnv->Game_Events->SetDisableMouseEvents(); Flag_Shown = true; }
int main(int argc, char * argv[]) { atexit(Terminate); #ifdef _IPHONE sprintf( base_path, "%s", argv[0] ); #else strcpy( base_path, argv[0] ); base_path[strlen(base_path)-9] = '\0'; #endif // printf("SDL_Init\n"); /* // Experimental - create a splash screen window whilst loading SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode( 200,200,0,SDL_NOFRAME ); SDL_Rect r = {0,0,200,200}; SDL_FillRect(screen, &r, SDL_MapRGB(screen->format, 0, 0, 50)); SDL_Flip(screen); */ SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE); #ifdef _IPHONE SDL_ShowCursor(0); #endif #ifdef _GP2X joystick=SDL_JoystickOpen(0); #endif SDL_Surface* icon = SDL_LoadBMP("graphics/icon.bmp"); if (icon) { static unsigned int mask[32] = { 0x00001fc0, 0x00003fe0, 0x00007ff0, 0x0f007df8, 0x0000f0f8, 0x0000f07c, 0x0005f87c, 0x0fbfff3c, 0x1ffffffe, 0x3ffffffe, 0x3ffffffe, 0x7ffffffe, 0x7ffffffe, 0x7ffffffe, 0x7ffffffe, 0xefffffff, 0x1fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3ffffffe, 0x3ffffff8, 0x3ffffff0, 0x3ffffff0, 0x3ffffff0, 0x3fffffe0, 0x3fffffe0, 0x1ffffff0, 0x1ffffff1, }; for (int i=0; i<32; i++) mask[i] = mask[i]>>24 | (mask[i]>>8)&0xff00 | (mask[i]<<8)&0xff0000 | (mask[i]<<24)&0xff000000; SDL_WM_SetIcon(icon, (unsigned char*) mask); SDL_FreeSurface(icon); } InitScreen(); SDL_WarpMouse(SCREEN_W/2, SCREEN_H/2); #ifdef WIN32 HWND hwnd = 0; #endif #ifdef USE_BBTABLET bbTabletDevice &td = bbTabletDevice::getInstance( ); SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); #endif // printf("Main loop...\n"); StateMakerBase::GetNew(); int time = SDL_GetTicks(); while(!quitting) { SDL_Event e; #ifdef _IPHONE SDL_PumpEvents(); #endif while(!SDL_PollEvent(&e) && !quitting) { int x = SDL_GetTicks() - time; time += x; if (x<0) x = 0, time = SDL_GetTicks(); if (x>500) x = 500; // experimental... if (!noMouse) StateMakerBase::current->Mouse(mousex, mousey, 0, 0, 0, 0, mouse_buttons); StateMakerBase::current->Update(x / 1000.0); StateMakerBase::current->Render(); #ifdef USE_OPENGL SDL_GL_SwapBuffers(); #else if (screen && realScreen!=screen) { SDL_Rect r = {0,0,SCREEN_W,SCREEN_H}; SDL_BlitSurface(screen, &r, realScreen, &r); } SDL_Flip(realScreen); #endif //#ifdef WIN32 // Sleep(1); //#endif SDL_Delay(10); #ifdef USE_BBTABLET // Tablet //////////////////////// bbTabletEvent evt; while(hwnd!=NULL && td.getNextEvent(evt)) { stylusok = 1; RECT r; if (tablet_system) { GetWindowRect(hwnd, &r); stylusx = evt.x * GetSystemMetrics(SM_CXSCREEN); stylusy = (1.0 - evt.y) * GetSystemMetrics(SM_CYSCREEN); stylusx -= (r.left + GetSystemMetrics(SM_CXFIXEDFRAME)); stylusy -= (r.top + GetSystemMetrics(SM_CYFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION));; } else { GetClientRect(hwnd, &r); stylusx = evt.x * r.right; stylusy = (1.0 - evt.y) * r.bottom; } styluspressure = (evt.buttons & 1) ? evt.pressure : 0; /* printf("id=%d csrtype=%d b=%x (%0.3f, %0.3f, %0.3f) p=%0.3f tp=%0.3f\n", evt.id, evt.type, evt.buttons, evt.x, evt.y, evt.z, evt.pressure, evt.tpressure ); */ } #endif } #if defined(_GP2X) || defined(_IPHONE) int nkey=0; int mod=0; #endif switch (e.type) { /* case SDL_VIDEOEXPOSE: w.Render(); SDL_GL_SwapBuffers(); break;*/ #ifdef WIN32 case SDL_SYSWMEVENT: { SDL_SysWMmsg* m = e.syswm.msg; hwnd = m->hwnd; static bool init=false; if (!init) { init = true; DragAcceptFiles(hwnd, TRUE); #ifdef USE_BBTABLET td.initTablet(hwnd, tablet_system ? bbTabletDevice::SYSTEM_POINTER : bbTabletDevice::SEPARATE_POINTER ); if (!td.isValid()) printf("No tablet/driver found\n"); #endif } if (m->msg == WM_DROPFILES) { HDROP h = (HDROP)m->wParam; char name[512]; if (DragQueryFile(h, 0xffffffff, 0, 0) == 1) { DragQueryFile(h, 0, name, sizeof(name)/sizeof(name[0])); StateMakerBase::current->FileDrop(name); } DragFinish(h); } break; } #endif case SDL_ACTIVEEVENT: { static int focus = 0; int gain = e.active.gain ? e.active.state : 0; int loss = e.active.gain ? 0 : e.active.state; focus = (focus | gain) & ~loss; if (gain & SDL_APPACTIVE) StateMakerBase::current->ScreenModeChanged(); if (loss & SDL_APPMOUSEFOCUS) noMouse = 1; else if (gain & SDL_APPMOUSEFOCUS) noMouse = 0; break; } case SDL_MOUSEMOTION: noMouse = false; StateMakerBase::current->Mouse(e.motion.x, e.motion.y, e.motion.x-mousex, e.motion.y-mousey, 0, 0, mouse_buttons); mousex = e.motion.x; mousey = e.motion.y; break; case SDL_MOUSEBUTTONUP: noMouse = false; mouse_buttons &= ~(1<<(e.button.button-1)); StateMakerBase::current->Mouse(e.button.x, e.button.y, e.button.x-mousex, e.button.y-mousey, 0, 1<<(e.button.button-1), mouse_buttons); mousex = e.button.x; mousey = e.button.y ; break; case SDL_MOUSEBUTTONDOWN: noMouse = false; mouse_buttons |= 1<<(e.button.button-1); StateMakerBase::current->Mouse(e.button.x, e.button.y, e.button.x-mousex, e.button.y-mousey, 1<<(e.button.button-1), 0, mouse_buttons); mousex = e.button.x; mousey = e.button.y ; break; #ifdef _IPHONE case SDL_KEYDOWN: if(e.key.keysym.sym == SDLK_KP4) nkey = SDLK_z; else if(e.key.keysym.sym == SDLK_KP6) nkey = SDLK_ESCAPE; StateMakerBase::current->KeyPressed(nkey, mod); break; case SDL_KEYUP: if(e.key.keysym.sym == SDLK_KP4) nkey = SDLK_z; else if(e.key.keysym.sym == SDLK_KP6) nkey = SDLK_ESCAPE; StateMakerBase::current->KeyReleased(nkey); break; #else case SDL_KEYUP: StateMakerBase::current->KeyReleased(e.key.keysym.sym); break; #endif #ifdef _GP2X case SDL_JOYBUTTONUP: if(e.jbutton.button==VK_UP) nkey=SDLK_UP; if(e.jbutton.button==VK_DOWN) nkey=SDLK_DOWN; if(e.jbutton.button==VK_LEFT) nkey=SDLK_LEFT; if(e.jbutton.button==VK_RIGHT) nkey=SDLK_RIGHT; if(e.jbutton.button==VK_START) nkey=SDLK_ESCAPE; if(e.jbutton.button==VK_FX) nkey=SDLK_RETURN; if(e.jbutton.button==VK_UP_LEFT) nkey=SDLK_q; if(e.jbutton.button==VK_UP_RIGHT) nkey=SDLK_e; if(e.jbutton.button==VK_DOWN_LEFT) nkey=SDLK_a; if(e.jbutton.button==VK_DOWN_RIGHT) nkey=SDLK_d; if(e.jbutton.button==VK_FY) nkey=SDLK_z; StateMakerBase::current->KeyReleased(nkey); break; case SDL_JOYBUTTONDOWN: if(e.jbutton.button==VK_UP) nkey=SDLK_UP; if(e.jbutton.button==VK_DOWN) nkey=SDLK_DOWN; if(e.jbutton.button==VK_LEFT) nkey=SDLK_LEFT; if(e.jbutton.button==VK_RIGHT) nkey=SDLK_RIGHT; if(e.jbutton.button==VK_START) nkey=SDLK_ESCAPE; if(e.jbutton.button==VK_FX) nkey=SDLK_RETURN; if(e.jbutton.button==VK_UP_LEFT) nkey=SDLK_q; if(e.jbutton.button==VK_UP_RIGHT) nkey=SDLK_e; if(e.jbutton.button==VK_DOWN_LEFT) nkey=SDLK_a; if(e.jbutton.button==VK_DOWN_RIGHT) nkey=SDLK_d; if(e.jbutton.button==VK_FY) nkey=SDLK_z; StateMakerBase::current->KeyPressed(nkey,mod); break; #endif #ifndef _IPHONE case SDL_KEYDOWN: { SDL_KeyboardEvent & k = e.key; if (k.keysym.sym==SDLK_F4 && (k.keysym.mod & KMOD_ALT)) { quitting = 1; } else if (k.keysym.sym==SDLK_F12) { // Toggle system pointer controlled by tablet or not #ifdef USE_BBTABLET if (td.isValid()) { tablet_system = !tablet_system; td.setPointerMode(tablet_system ? bbTabletDevice::SYSTEM_POINTER : bbTabletDevice::SEPARATE_POINTER); } #endif } else if (k.keysym.sym==SDLK_RETURN && (k.keysym.mod & KMOD_ALT) && !(k.keysym.mod & KMOD_CTRL)) { ToggleFullscreen(); } else if (StateMakerBase::current->KeyPressed(k.keysym.sym, k.keysym.mod)) { } else if ((k.keysym.mod & (KMOD_ALT | KMOD_CTRL))==0) { StateMakerBase::GetNew(k.keysym.sym); } } break; #endif case SDL_QUIT: quitting = 1; break; } #ifdef _IPHONE if(SDL_GetExitStatus()) { quitting = 1; } #endif } SDL_Quit(); return 0; }
static int PollEvent() { SDL_Event ev; if (!SDL_CALL SDL_PollEvent(&ev)) return -2; switch (ev.type) { case SDL_MOUSEMOTION: if (_cursor.fix_at) { int dx = ev.motion.x - _cursor.pos.x; int dy = ev.motion.y - _cursor.pos.y; if (dx != 0 || dy != 0) { _cursor.delta.x = dx; _cursor.delta.y = dy; SDL_CALL SDL_WarpMouse(_cursor.pos.x, _cursor.pos.y); } } else { _cursor.delta.x = ev.motion.x - _cursor.pos.x; _cursor.delta.y = ev.motion.y - _cursor.pos.y; _cursor.pos.x = ev.motion.x; _cursor.pos.y = ev.motion.y; _cursor.dirty = true; } HandleMouseEvents(); break; case SDL_MOUSEBUTTONDOWN: if (_rightclick_emulate && SDL_CALL SDL_GetModState() & KMOD_CTRL) { ev.button.button = SDL_BUTTON_RIGHT; } switch (ev.button.button) { case SDL_BUTTON_LEFT: _left_button_down = true; break; case SDL_BUTTON_RIGHT: _right_button_down = true; _right_button_clicked = true; break; case SDL_BUTTON_WHEELUP: _cursor.wheel--; break; case SDL_BUTTON_WHEELDOWN: _cursor.wheel++; break; default: break; } HandleMouseEvents(); break; case SDL_MOUSEBUTTONUP: if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; _left_button_clicked = false; } else if (ev.button.button == SDL_BUTTON_LEFT) { _left_button_down = false; _left_button_clicked = false; } else if (ev.button.button == SDL_BUTTON_RIGHT) { _right_button_down = false; } HandleMouseEvents(); break; case SDL_ACTIVEEVENT: if (!(ev.active.state & SDL_APPMOUSEFOCUS)) break; if (ev.active.gain) { // mouse entered the window, enable cursor _cursor.in_window = true; } else { UndrawMouseCursor(); // mouse left the window, undraw cursor _cursor.in_window = false; } break; case SDL_QUIT: HandleExitGameRequest(); break; case SDL_KEYDOWN: // Toggle full-screen on ALT + ENTER/F if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { ToggleFullScreen(!_fullscreen); } else { HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); } break; case SDL_VIDEORESIZE: { int w = max(ev.resize.w, 64); int h = max(ev.resize.h, 64); CreateMainSurface(w, h); break; } } return -1; }
void platform_event_samplebase(int devid, float xyz[3]) { if (0 == devid) SDL_WarpMouse(xyz[0], xyz[1]); }
// // I_GetEvent // void I_GetEvent (void) { event_t event; event_t mouseevent = {ev_mouse, 0, 0, 0}; static int mbuttons = 0; int sendmouseevent = 0; SDL_Event ev; if (!havefocus) I_PauseMouse(); else { I_ResumeMouse(); } while(SDL_PollEvent(&ev)) { event.data1 = event.data2 = event.data3 = 0; switch(ev.type) { case SDL_QUIT: AddCommandString("quit"); break; // Resizable window mode resolutions case SDL_VIDEORESIZE: { if (!vid_fullscreen) { std::stringstream Command; mousegrabbed = false; Command << "vid_setmode " << ev.resize.w << " " << ev.resize.h << std::endl; AddCommandString(Command.str()); vid_defwidth.Set((float)ev.resize.w); vid_defheight.Set((float)ev.resize.h); } } break; case SDL_ACTIVEEVENT: // need to update our focus state UpdateFocus(); break; case SDL_KEYDOWN: event.type = ev_keydown; event.data1 = ev.key.keysym.sym; if(event.data1 >= SDLK_KP0 && event.data1 <= SDLK_KP9) event.data2 = event.data3 = '0' + (event.data1 - SDLK_KP0); else if(event.data1 == SDLK_KP_PERIOD) event.data2 = event.data3 = '.'; else if(event.data1 == SDLK_KP_DIVIDE) event.data2 = event.data3 = '/'; else if(event.data1 == SDLK_KP_ENTER) event.data2 = event.data3 = '\r'; else if ( (ev.key.keysym.unicode & 0xFF80) == 0 ) event.data2 = event.data3 = ev.key.keysym.unicode; else event.data2 = event.data3 = 0; #ifdef _XBOX // Fix for ENTER key on Xbox if(event.data1 == SDLK_RETURN) event.data2 = event.data3 = '\r'; #endif #ifdef WIN32 //HeX9109: Alt+F4 for cheats! Thanks Spleen if(event.data1 == SDLK_F4 && SDL_GetModState() & (KMOD_LALT | KMOD_RALT)) AddCommandString("quit"); // SoM: Ignore the tab portion of alt-tab presses // [AM] Windows 7 seems to preempt this check. if(event.data1 == SDLK_TAB && SDL_GetModState() & (KMOD_LALT | KMOD_RALT)) event.data1 = event.data2 = event.data3 = 0; else #endif D_PostEvent(&event); break; case SDL_KEYUP: event.type = ev_keyup; event.data1 = ev.key.keysym.sym; if ( (ev.key.keysym.unicode & 0xFF80) == 0 ) event.data2 = event.data3 = ev.key.keysym.unicode; else event.data2 = event.data3 = 0; D_PostEvent(&event); break; case SDL_MOUSEMOTION: if(flushmouse) { flushmouse = false; break; } if (!havefocus) break; // denis - ignore artificially inserted events (see SDL_WarpMouse below) if(ev.motion.x == screen->width/2 && ev.motion.y == screen->height/2) { break; } mouseevent.data2 += AccelerateMouse(ev.motion.xrel); mouseevent.data3 -= AccelerateMouse(ev.motion.yrel); sendmouseevent = 1; break; case SDL_MOUSEBUTTONDOWN: if(nomouse || !havefocus) break; event.type = ev_keydown; if(ev.button.button == SDL_BUTTON_LEFT) { event.data1 = KEY_MOUSE1; mbuttons |= 1; } else if(ev.button.button == SDL_BUTTON_RIGHT) { event.data1 = KEY_MOUSE2; mbuttons |= 2; } else if(ev.button.button == SDL_BUTTON_MIDDLE) { event.data1 = KEY_MOUSE3; mbuttons |= 4; } // [Xyltol 07/21/2011] - Add support for MOUSE4 and MOUSE5 (back thumb and front thumb on most mice) else if(ev.button.button == SDL_BUTTON_X1){//back thumb event.data1 = KEY_MOUSE4; mbuttons |= 8; }else if(ev.button.button == SDL_BUTTON_X2){//front thumb event.data1 = KEY_MOUSE5; mbuttons |= 16; } else if(ev.button.button == SDL_BUTTON_WHEELUP) event.data1 = KEY_MWHEELUP; else if(ev.button.button == SDL_BUTTON_WHEELDOWN) event.data1 = KEY_MWHEELDOWN; D_PostEvent(&event); break; case SDL_MOUSEBUTTONUP: if(nomouse || !havefocus) break; event.type = ev_keyup; if(ev.button.button == SDL_BUTTON_LEFT) { event.data1 = KEY_MOUSE1; mbuttons &= ~1; } else if(ev.button.button == SDL_BUTTON_RIGHT) { event.data1 = KEY_MOUSE2; mbuttons &= ~2; } else if(ev.button.button == SDL_BUTTON_MIDDLE) { event.data1 = KEY_MOUSE3; mbuttons &= ~4; } // [Xyltol 07/21/2011] - Add support for MOUSE4 and MOUSE5 (back thumb and front thumb on most mice) else if(ev.button.button == SDL_BUTTON_X1){//back thumb event.data1 = KEY_MOUSE4; mbuttons &= ~8; }else if(ev.button.button == SDL_BUTTON_X2){//front thumb event.data1 = KEY_MOUSE5; mbuttons &= ~16; } else if(ev.button.button == SDL_BUTTON_WHEELUP) event.data1 = KEY_MWHEELUP; else if(ev.button.button == SDL_BUTTON_WHEELDOWN) event.data1 = KEY_MWHEELDOWN; D_PostEvent(&event); break; case SDL_JOYBUTTONDOWN: if(ev.jbutton.which == joy_active) { event.type = ev_keydown; event.data1 = ev.jbutton.button + KEY_JOY1; event.data2 = event.data1; D_PostEvent(&event); break; } case SDL_JOYBUTTONUP: if(ev.jbutton.which == joy_active) { event.type = ev_keyup; event.data1 = ev.jbutton.button + KEY_JOY1; event.data2 = event.data1; D_PostEvent(&event); break; } case SDL_JOYAXISMOTION: if(ev.jaxis.which == joy_active) { event.type = ev_joystick; event.data1 = 0; event.data2 = ev.jaxis.axis; if( (ev.jaxis.value < JOY_DEADZONE) && (ev.jaxis.value > -JOY_DEADZONE) ) event.data3 = 0; else event.data3 = ev.jaxis.value; D_PostEvent(&event); break; } case SDL_JOYHATMOTION: if(ev.jhat.which == joy_active) { // Each of these need to be tested because more than one can be pressed and a // unique event is needed for each if(ev.jhat.value & SDL_HAT_UP) RegisterJoystickEvent(&ev, SDL_HAT_UP); if(ev.jhat.value & SDL_HAT_RIGHT) RegisterJoystickEvent(&ev, SDL_HAT_RIGHT); if(ev.jhat.value & SDL_HAT_DOWN) RegisterJoystickEvent(&ev, SDL_HAT_DOWN); if(ev.jhat.value & SDL_HAT_LEFT) RegisterJoystickEvent(&ev, SDL_HAT_LEFT); break; } }; } if(!nomouse) { if(sendmouseevent) { mouseevent.data1 = mbuttons; D_PostEvent(&mouseevent); } if(mousegrabbed && screen) { SDL_WarpMouse(screen->width/ 2, screen->height / 2); } } if(use_joystick) UpdateJoystickEvents(); }
void TCOD_mouse_move(int x, int y) { SDL_WarpMouse((Uint16)x,(Uint16)y); }
void OSystem_IPOD::handleKbdMouse() { uint32 curTime = getMillis(); if (curTime >= _km.last_time + _km.delay_time) { _km.last_time = curTime; if (_km.x_down_count == 1) { _km.x_down_time = curTime; _km.x_down_count = 2; } if (_km.y_down_count == 1) { _km.y_down_time = curTime; _km.y_down_count = 2; } if (_km.x_vel || _km.y_vel) { if (_km.x_down_count) { if (curTime > _km.x_down_time + _km.delay_time * 12) { if (_km.x_vel > 0) _km.x_vel++; else _km.x_vel--; } else if (curTime > _km.x_down_time + _km.delay_time * 8) { if (_km.x_vel > 0) _km.x_vel = 5; else _km.x_vel = -5; } } if (_km.y_down_count) { if (curTime > _km.y_down_time + _km.delay_time * 12) { if (_km.y_vel > 0) _km.y_vel++; else _km.y_vel--; } else if (curTime > _km.y_down_time + _km.delay_time * 8) { if (_km.y_vel > 0) _km.y_vel = 5; else _km.y_vel = -5; } } _km.x += _km.x_vel; _km.y += _km.y_vel; if (_km.x < 0) { _km.x = 0; _km.x_vel = -1; _km.x_down_count = 1; } else if (_km.x > _km.x_max) { _km.x = _km.x_max; _km.x_vel = 1; _km.x_down_count = 1; } if (_km.y < 0) { _km.y = 0; _km.y_vel = -1; _km.y_down_count = 1; } else if (_km.y > _km.y_max) { _km.y = _km.y_max; _km.y_vel = 1; _km.y_down_count = 1; } SDL_WarpMouse(_km.x, _km.y); } } }
int ui_event( void ) { SDL_Event event; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_KEYDOWN: sdlkeyboard_keypress( &(event.key) ); break; case SDL_KEYUP: sdlkeyboard_keyrelease( &(event.key) ); break; case SDL_MOUSEBUTTONDOWN: ui_mouse_button( event.button.button, 1 ); break; case SDL_MOUSEBUTTONUP: ui_mouse_button( event.button.button, 0 ); break; case SDL_MOUSEMOTION: if( ui_mouse_grabbed ) { ui_mouse_motion( event.motion.x - 128, event.motion.y - 128 ); if( event.motion.x != 128 || event.motion.y != 128 ) SDL_WarpMouse( 128, 128 ); } break; #if defined USE_JOYSTICK && !defined HAVE_JSW_H case SDL_JOYBUTTONDOWN: sdljoystick_buttonpress( &(event.jbutton) ); break; case SDL_JOYBUTTONUP: sdljoystick_buttonrelease( &(event.jbutton) ); break; case SDL_JOYAXISMOTION: sdljoystick_axismove( &(event.jaxis) ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ case SDL_QUIT: fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); break; case SDL_VIDEOEXPOSE: display_refresh_all(); break; case SDL_ACTIVEEVENT: if( event.active.state & SDL_APPINPUTFOCUS ) { if( event.active.gain ) ui_mouse_resume(); else ui_mouse_suspend(); } break; default: break; } } return 0; }
int tecla_pulsada(void) { float x,y,z; Uint8 *keys; keys = SDL_GetKeyState(NULL); if (keys[SDLK_ESCAPE]) return -1; if (keys[SDLK_w]) { velocidad_r+=0.005f; } if (keys[SDLK_s]) { velocidad_r-=0.006f; if (velocidad_r<1.0f) velocidad_r=1.0f; } if (keys[SDLK_e]) { SDL_WarpMouse(config.SCREEN_SIZE_X/2,config.SCREEN_SIZE_Y/2); } if (keys[SDLK_q]) { SDL_WarpMouse(320,240); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glGetFloatv(GL_MODELVIEW_MATRIX,&camara[0][0]); camara[2][2]=1.0f; camara[3][2]=-1.0f; } if (keys[SDLK_SPACE]) { if (disparo_laser.ttl==0) { memcpy(&disparo_laser.posicion[0],&camara[3][0],sizeof(float)*3); memcpy(&disparo_laser.direccion[0],&camara[2][0],sizeof(float)*3); disparo_laser.posicion[0]+=(0.1f* disparo_laser.direccion[0]); disparo_laser.posicion[1]+=(0.1f* disparo_laser.direccion[1]); disparo_laser.posicion[2]+=(0.1f* disparo_laser.direccion[2]); disparo_laser.ttl=get_timer(); disparo_laser.color[0]=0.0f; disparo_laser.color[1]=0.0f; disparo_laser.color[2]=1.0f; disparo_laser.color[3]=1.0f; /* Reproducimos sonido laser */ if ( audio_on == 1){ ReproducirSonido ( 0,disparo_laser.posicion, disparo_laser.direccion,1.0f, 1.0f,10.0f, AL_FALSE); } } } if (keys[SDLK_p]) { glShadeModel(GL_FLAT); } if (keys[SDLK_o]) { glShadeModel(GL_SMOOTH); } if (keys[SDLK_m]) { if ( musica_on == 0 ){ ReproducirMusica ( ); } } if (keys[SDLK_n]){ if ( audio_on == 1 ){ ReproducirSonido ( 2, PosSonidoNave1, VelSonidoNave1 ,1.0f,1.0f,0.0f,AL_TRUE); } } if (keys[SDLK_a]) { glMatrixMode(GL_MODELVIEW); x=camara[3][0]; y=camara[3][1]; z=camara[3][2]; camara[3][0]=0; camara[3][1]=0; camara[3][2]=0; camara[3][3]=1; glLoadMatrixf(&camara[0][0]); glRotatef(-60.f*intervalo,0.0f,0.0f,1.0f); glGetFloatv(GL_MODELVIEW_MATRIX,&camara[0][0]); camara[3][0]=x; camara[3][1]=y; camara[3][2]=z; camara[3][3]=1; } if (keys[SDLK_d]) { glMatrixMode(GL_MODELVIEW); x=camara[3][0]; y=camara[3][1]; z=camara[3][2]; camara[3][0]=0; camara[3][1]=0; camara[3][2]=0; camara[3][3]=1; glLoadMatrixf(&camara[0][0]); glRotatef(60.f*intervalo,0.0f,0.0f,1.0f); glGetFloatv(GL_MODELVIEW_MATRIX,&camara[0][0]); camara[3][0]=x; camara[3][1]=y; camara[3][2]=z; camara[3][3]=1; } return 0; }
void Gource::mouseClick(SDL_MouseButtonEvent *e) { if(commitlog==0) return; if(gGourceSettings.hide_mouse) return; //mouse click should stop the cursor being idle cursor.updatePos(mousepos); if(e->type == SDL_MOUSEBUTTONUP) { if(e->button == SDL_BUTTON_LEFT) { //stop dragging mouse, return the mouse to where //the user started dragging. mousedragged=false; } if(e->button == SDL_BUTTON_LEFT || e->button == SDL_BUTTON_RIGHT) { if(!cursor.buttonPressed()) { cursor.showCursor(true); grab_mouse=false; SDL_WarpMouse(mousepos.x, mousepos.y); } } } if(e->type != SDL_MOUSEBUTTONDOWN) return; //wheel up if(e->button == SDL_BUTTON_WHEELUP) { zoom(true); return; } //wheel down if(e->button == SDL_BUTTON_WHEELDOWN) { zoom(false); return; } if(e->button == SDL_BUTTON_MIDDLE) { toggleCameraMode(); return; } if(e->button == SDL_BUTTON_RIGHT) { cursor.showCursor(false); grab_mouse=true; return; } if(e->button == SDL_BUTTON_LEFT) { //mousepos = vec2f(e->x, e->y); mouseclicked=true; if(canSeek()) { float position; if(slider.click(mousepos, &position)) { seekTo(position); } } } }
/** ** Handle interactive input event. ** ** @param callbacks Callback structure for events. ** @param event SDL event structure pointer. */ static void SdlDoEvent(const EventCallback &callbacks, SDL_Event &event) { #if (defined(USE_OPENGL) || defined(USE_GLES)) // Scale mouse-coordinates to viewport if (ZoomNoResize && (event.type & (SDL_MOUSEBUTTONUP | SDL_MOUSEBUTTONDOWN | SDL_MOUSEMOTION))) { event.button.x = (Uint16)floorf(event.button.x * float(Video.Width) / Video.ViewportWidth); event.button.y = (Uint16)floorf(event.button.y * float(Video.Height) / Video.ViewportHeight); } #endif switch (event.type) { case SDL_MOUSEBUTTONDOWN: InputMouseButtonPress(callbacks, SDL_GetTicks(), event.button.button); break; case SDL_MOUSEBUTTONUP: InputMouseButtonRelease(callbacks, SDL_GetTicks(), event.button.button); break; // FIXME: check if this is only useful for the cursor // FIXME: if this is the case we don't need this. case SDL_MOUSEMOTION: InputMouseMove(callbacks, SDL_GetTicks(), event.motion.x, event.motion.y); // FIXME: Same bug fix from X11 if ((UI.MouseWarpPos.x != -1 || UI.MouseWarpPos.y != -1) && (event.motion.x != UI.MouseWarpPos.x || event.motion.y != UI.MouseWarpPos.y)) { int xw = UI.MouseWarpPos.x; int yw = UI.MouseWarpPos.y; UI.MouseWarpPos.x = -1; UI.MouseWarpPos.y = -1; SDL_WarpMouse(xw, yw); } break; case SDL_ACTIVEEVENT: if (event.active.state & SDL_APPMOUSEFOCUS) { static bool InMainWindow = true; if (InMainWindow && !event.active.gain) { InputMouseExit(callbacks, SDL_GetTicks()); } InMainWindow = (event.active.gain != 0); } if (Preference.PauseOnLeave && (event.active.state & SDL_APPACTIVE || SDL_GetAppState() & SDL_APPACTIVE)) { static bool DoTogglePause = false; if (IsSDLWindowVisible && !event.active.gain) { IsSDLWindowVisible = false; if (!GamePaused) { DoTogglePause = true; UiTogglePause(); } } else if (!IsSDLWindowVisible && event.active.gain) { IsSDLWindowVisible = true; if (GamePaused && DoTogglePause) { DoTogglePause = false; UiTogglePause(); } } } break; case SDL_KEYDOWN: InputKeyButtonPress(callbacks, SDL_GetTicks(), event.key.keysym.sym, event.key.keysym.unicode); break; case SDL_KEYUP: InputKeyButtonRelease(callbacks, SDL_GetTicks(), event.key.keysym.sym, event.key.keysym.unicode); break; case SDL_QUIT: Exit(0); break; } if (&callbacks == GetCallbacks()) { handleInput(&event); } }