int ft_key_hook(int key_code, t_data *e) { t_files *ptr; void *fun_ptr; ptr = e->file; fun_ptr = menu_hook; if (e->pos == 1) { ptr = e->quality; fun_ptr = quality_hook; } while (ptr) { if (ptr->selected == TRUE) break ; ptr = ptr->next; } if (arrow_keys(key_code, e, ptr, fun_ptr) == TRUE) return (0); else if (key_code == ENTER) enter_key(e, ptr); else if (key_code == ESC) exit(0); return (0); }
int my_key_funct(int keycode, t_frac *frac) { if (keycode == 53) { ft_putendl("exit"); exit(0); } else if (keycode == 15) { frac_reset(frac); mlx_clear_window(frac->mlx, frac->win); frac->aff_frac(frac); } else if (keycode == 38) frac->juliamove = (frac->juliamove) ? 0 : 1; else if (keycode == 40) { frac->juliax = 0.285; frac->juliay = 0.01; frac->juliamove = 0; mlx_clear_window(frac->mlx, frac->win); frac->aff_frac(frac); } arrow_keys(frac, keycode); change_iter(frac, keycode); change_color(frac, keycode); return (0); }
/* Handles the keyboard interrupt */ void keyboard_handler(struct regs *r) { static UInt8 scancode, flag; if(scancode == 224) { flag = 1; return ; } else flag = 0; /* Read from the keyboard's data buffer 0x60 is the register which contains data from keyboard */ scancode = inportb(0x60); /* If the top bit of the byte we read from the keyboard is * set, that means that a key has just been released */ if (scancode & 0x80) { /* You can use this one to see if the user released the * shift, alt, or control keys... */ switch(scancode & ~0x80) { case 29 : if(flag) toggle_rctrl(); else toggle_lctrl(); break; case 42 : toggle_lshift(); break; case 54 : toggle_rshift(); break; case 56 : if(flag) toggle_ralt(); else toggle_lalt(); break; default : break; } } else { /* Here, a key was just pressed. Please note that if you * hold a key down, you will get repeated key press * interrupts. */ /* Just to show you how this works, we simply translate * the keyboard scancode into an ASCII value, and then * display it to the screen. You can get creative and * use some flags to see if a shift is pressed and use a * different layout, or you can add another 128 entries * to the above layout to correspond to 'shift' being * held. If shift is held using the larger lookup table, * you would add 128 to the scancode when you look for it */ switch(scancode) { case 29 : if(flag) toggle_rctrl(); else toggle_lctrl(); break; case 42 : toggle_lshift(); break; case 54 : toggle_rshift(); break; case 56 : if(flag) toggle_ralt(); else toggle_lalt(); break; case 58 : toggle_caps(); break; case 72 : arrow_keys('u'); break; case 75 : arrow_keys('l'); break; case 77 : arrow_keys('r'); break; case 80 : arrow_keys('d'); break; default : s_putch(kbdus[scancode]); break; } } }
int main() { srand(time(NULL)); ////////////////////////// // // GAME INITIALIZATION // ////////////////////////// //Uint16 SIZE = rand() % 14 + 1; Uint16 SIZE = 10; hexes = HexWorld_create(SIZE, 15, 0); printf("MAIN: World built.\n"); ctrl = WorldControl_create(); entities = Entities_create(); Entities_add(entities, hexes, HEXWORLD); ////////////////////////// // // SDL INITIALIZATION // ////////////////////////// SDL_Init(SDL_INIT_EVERYTHING); const SDL_VideoInfo* v = SDL_GetVideoInfo(); screen = SDL_SetVideoMode(v->current_w, v->current_h, 24, SDL_FULLSCREEN | SDL_HWSURFACE); SDL_Surface* wldSurface; if (!(wldSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, hexes->width, hexes->height, 24, 0, 0, 0, 0))) { printf("Error creating surface.\n"); exit(1); } ctrl->offset.x = (v->current_w - hexes->width) / 2; ctrl->offset.y = (v->current_h - hexes->height) / 2; SDL_Rect temp_rect; ////////////////////////// // // Main game loop // ////////////////////////// SDL_Event evt; bool done = 0; while(!done) { if (SDL_PollEvent(&evt)) { ////////////////////////// // // EVENTS // ////////////////////////// switch(evt.type) { case SDL_QUIT: done = true; break; case SDL_KEYDOWN: switch(evt.key.keysym.sym) { case SDLK_ESCAPE: done = true; break; case SDLK_LEFT: case SDLK_RIGHT: case SDLK_UP: case SDLK_DOWN: arrow_keys(&evt); default: break; } break; case SDL_MOUSEBUTTONUP: click(&evt); break; default: break; } } ////////////////////////// // // LOGIC // ////////////////////////// // Most likely there will be little-to-nothing here; // since the game is turn-based, almost all logic can be // event-driven rather than real-time // This also means that setting a constant timestep is unimportant. WorldControl_update(ctrl); ////////////////////////// // // RENDERING // ////////////////////////// SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); Entities_render_all(entities, wldSurface); temp_rect.x = ctrl->offset.x; temp_rect.y = ctrl->offset.y; SDL_BlitSurface(wldSurface, NULL, screen, &temp_rect); SDL_Flip(screen); } // end game loop ////////////////////////// // // CLEANUP // ////////////////////////// Entities_destroy(entities, true); // true -> call destroy functions for contained objects SDL_Quit(); printf("Shut down successfully.\n"); return 0; }