int main(int argc, char **argv) { (void)argc; (void)argv; zoom = 1.0; mouse_x = -4.0; mouse_y = -4.0; focus = 1; rotation = m4f_ident(); atexit(SDL_Quit); SDL_Init(SDL_INIT_VIDEO); resize_screen(640, 480); SDL_WM_SetCaption("SDL OpenGL Skeleton", "sos"); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); init_gl(); make_list(); for (;;) { draw(); if (focus) SDL_Delay(10); else SDL_Delay(100); handle_events(); } return 0; }
/* * Called when the properties on the root window change, e.g. when the screen * resolution changes. If so we update the window to cover the whole screen * and also redraw the image, if any. * */ void handle_screen_resize(void) { xcb_get_geometry_cookie_t geomc; xcb_get_geometry_reply_t *geom; geomc = xcb_get_geometry(conn, screen->root); if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) == NULL) return; if (last_resolution[0] == geom->width && last_resolution[1] == geom->height) { free(geom); return; } last_resolution[0] = geom->width; last_resolution[1] = geom->height; free(geom); glx_resize(last_resolution[0], last_resolution[1]); resize_screen(); redraw_screen(); uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; xcb_configure_window(conn, win, mask, last_resolution); xcb_flush(conn); xinerama_query_screens(); redraw_screen(); }
int main() { SDL_Init(SDL_INIT_VIDEO); resize_screen(640, 480); SDL_WM_SetCaption("Mandelbrot", "mandelbrot"); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); uint32_t stat_ticks = SDL_GetTicks(); uint64_t stat_pixels = 0; uint32_t palette[MAX_ITER]; for (int i = 0; i < MAX_ITER; i++) palette[i] = i ? color(i / (float)MAX_ITER) : 0; while (1) { handle_events(); uint32_t *fbp = (uint32_t *)screen->pixels; int w = screen->w; int h = screen->h; float dx = 1.0f / (float)w; float dy = 1.0f / (float)h; for (int j = 0; j < (h * w - NUM); j += NUM) { complex float c[NUM]; for (int k = 0; k < NUM; k++) c[k] = (zoom * (dx * (float)((j+k)%w) - 0.5f) + xoff) + I * (zoom * (dy * (float)((j+k)/w) - 0.5f) + yoff); int t[NUM]; calc(t, c); for (int k = 0; k < NUM; k++) fbp[j + k] = palette[t[k]]; } #if 0 for (int j = 0; j < h; j++) for (int i = 0; i < MAX_ITER; i++) fbp[j * w + i] = palette[i]; #endif stat_pixels += w*h; uint32_t cur_ticks = SDL_GetTicks(); if ((cur_ticks - stat_ticks) > 1000) { handle_stats(0.001 * (double)(cur_ticks - stat_ticks), stat_pixels, w*h); stat_pixels = 0; stat_ticks = cur_ticks; } SDL_Flip(screen); } return 0; }
int main(int argc, char *argv[]) { int i, y, z, optchr, keypress; int j = 0; int count = 0; int screensaver = 0; int asynch = 0; int bold = 0; int force = 0; int firstcoldone = 0; int oldstyle = 0; int random = 0; int update = 4; int highnum = 0; int mcolor = COLOR_GREEN; int rainbow = 0; int lambda = 0; int randnum = 0; int randmin = 0; int pause = 0; int classic = 0; srand((unsigned) time(NULL)); setlocale(LC_ALL, ""); /* Many thanks to morph- ([email protected]) for this getopt patch */ opterr = 0; while ((optchr = getopt(argc, argv, "abBcfhlLnrosmxVu:C:")) != EOF) { switch (optchr) { case 's': screensaver = 1; break; case 'a': asynch = 1; break; case 'b': if (bold != 2) { bold = 1; } break; case 'B': bold = 2; break; case 'C': if (!strcasecmp(optarg, "green")) { mcolor = COLOR_GREEN; } else if (!strcasecmp(optarg, "red")) { mcolor = COLOR_RED; } else if (!strcasecmp(optarg, "blue")) { mcolor = COLOR_BLUE; } else if (!strcasecmp(optarg, "white")) { mcolor = COLOR_WHITE; } else if (!strcasecmp(optarg, "yellow")) { mcolor = COLOR_YELLOW; } else if (!strcasecmp(optarg, "cyan")) { mcolor = COLOR_CYAN; } else if (!strcasecmp(optarg, "magenta")) { mcolor = COLOR_MAGENTA; } else if (!strcasecmp(optarg, "black")) { mcolor = COLOR_BLACK; } else { c_die(" Invalid color selection\n Valid " "colors are green, red, blue, " "white, yellow, cyan, magenta " "and black.\n"); } break; case 'c': classic = 1; break; case 'f': force = 1; break; case 'l': console = 1; break; case 'L': lock = 1; break; case 'n': bold = -1; break; case 'h': case '?': usage(); exit(0); case 'o': oldstyle = 1; break; case 'u': update = atoi(optarg); break; case 'x': xwindow = 1; break; case 'V': version(); exit(0); case 'r': rainbow = 1; break; case 'm': lambda = 1; break; } } if (force && strcmp("linux", getenv("TERM"))) { /* setenv is much more safe to use than putenv */ setenv("TERM", "linux", 1); } initscr(); savetty(); nonl(); cbreak(); noecho(); timeout(0); leaveok(stdscr, TRUE); curs_set(0); signal(SIGINT, sighandler); signal(SIGQUIT, sighandler); signal(SIGWINCH, sighandler); signal(SIGTSTP, sighandler); if (console) { #ifdef HAVE_CONSOLECHARS if (va_system("consolechars -f matrix") != 0) { c_die (" There was an error running consolechars. Please make sure the\n" " consolechars program is in your $PATH. Try running \"consolechars -f matrix\" by hand.\n"); } #elif defined(HAVE_SETFONT) if (va_system("setfont matrix") != 0) { c_die (" There was an error running setfont. Please make sure the\n" " setfont program is in your $PATH. Try running \"setfont matrix\" by hand.\n"); } #else c_die(" Unable to use both \"setfont\" and \"consolechars\".\n"); #endif } if (has_colors()) { start_color(); /* Add in colors, if available */ #ifdef HAVE_USE_DEFAULT_COLORS if (use_default_colors() != ERR) { init_pair(COLOR_BLACK, -1, -1); init_pair(COLOR_GREEN, COLOR_GREEN, -1); init_pair(COLOR_WHITE, COLOR_WHITE, -1); init_pair(COLOR_RED, COLOR_RED, -1); init_pair(COLOR_CYAN, COLOR_CYAN, -1); init_pair(COLOR_MAGENTA, COLOR_MAGENTA, -1); init_pair(COLOR_BLUE, COLOR_BLUE, -1); init_pair(COLOR_YELLOW, COLOR_YELLOW, -1); } else { #else { /* Hack to deal the after effects of else in HAVE_USE_DEFAULT_COLOURS*/ #endif init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); } } /* Set up values for random number generation */ if(classic) { /* Japanese character unicode range [they are seen in the original cmatrix] */ randmin = 12288; highnum = 12351; } else if (console || xwindow) { randmin = 166; highnum = 217; } else { randmin = 33; highnum = 123; } randnum = highnum - randmin; var_init(); while (1) { /* Check for signals */ if (signal_status == SIGINT || signal_status == SIGQUIT) { if(lock != 1) finish(); /* exits */ } if (signal_status == SIGWINCH) { resize_screen(); signal_status = 0; } if(signal_status == SIGTSTP){ if(lock != 1) finish(); } count++; if (count > 4) { count = 1; } if ((keypress = wgetch(stdscr)) != ERR) { if (screensaver == 1) { #ifdef USE_TIOCSTI char *str = malloc(0); size_t str_len = 0; do { str = realloc(str, str_len + 1); str[str_len++] = keypress; } while ((keypress = wgetch(stdscr)) != ERR); size_t i; for (i = 0; i < str_len; i++) ioctl(STDIN_FILENO, TIOCSTI, (char*)(str + i)); free(str); #endif finish(); } else { switch (keypress) { case 'q': if(lock != 1) finish(); break; case 'a': asynch = 1 - asynch; break; case 'b': bold = 1; break; case 'B': bold = 2; break; case 'L': lock = 1; break; case 'n': bold = 0; break; case '0': /* Fall through */ case '1': /* Fall through */ case '2': /* Fall through */ case '3': /* Fall through */ case '4': /* Fall through */ case '5': /* Fall through */ case '6': /* Fall through */ case '7': /* Fall through */ case '8': /* Fall through */ case '9': update = keypress - 48; break; case '!': mcolor = COLOR_RED; rainbow = 0; break; case '@': mcolor = COLOR_GREEN; rainbow = 0; break; case '#': mcolor = COLOR_YELLOW; rainbow = 0; break; case '$': mcolor = COLOR_BLUE; rainbow = 0; break; case '%': mcolor = COLOR_MAGENTA; rainbow = 0; break; case 'r': rainbow = 1; break; case 'm': lambda = !lambda; break; case '^': mcolor = COLOR_CYAN; rainbow = 0; break; case '&': mcolor = COLOR_WHITE; rainbow = 0; break; case 'p': case 'P': pause = (pause == 0)?1:0; break; } } } for (j = 0; j <= COLS - 1; j += 2) { if ((count > updates[j] || asynch == 0) && pause == 0) { /* I dont like old-style scrolling, yuck */ if (oldstyle) { for (i = LINES - 1; i >= 1; i--) { matrix[i][j].val = matrix[i - 1][j].val; } random = (int) rand() % (randnum + 8) + randmin; if (matrix[1][j].val == 0) { matrix[0][j].val = 1; } else if (matrix[1][j].val == ' ' || matrix[1][j].val == -1) { if (spaces[j] > 0) { matrix[0][j].val = ' '; spaces[j]--; } else { /* Random number to determine whether head of next collumn of chars has a white 'head' on it. */ if (((int) rand() % 3) == 1) { matrix[0][j].val = 0; } else { matrix[0][j].val = (int) rand() % randnum + randmin; } spaces[j] = (int) rand() % LINES + 1; } } else if (random > highnum && matrix[1][j].val != 1) { matrix[0][j].val = ' '; } else { matrix[0][j].val = (int) rand() % randnum + randmin; } } else { /* New style scrolling (default) */ if (matrix[0][j].val == -1 && matrix[1][j].val == ' ' && spaces[j] > 0) { matrix[0][j].val = -1; spaces[j]--; } else if (matrix[0][j].val == -1 && matrix[1][j].val == ' ') { length[j] = (int) rand() % (LINES - 3) + 3; matrix[0][j].val = (int) rand() % randnum + randmin; spaces[j] = (int) rand() % LINES + 1; } i = 0; y = 0; firstcoldone = 0; while (i <= LINES) { /* Skip over spaces */ while (i <= LINES && (matrix[i][j].val == ' ' || matrix[i][j].val == -1)) { i++; } if (i > LINES) { break; } /* Go to the head of this collumn */ z = i; y = 0; while (i <= LINES && (matrix[i][j].val != ' ' && matrix[i][j].val != -1)) { matrix[i][j].is_head = false; i++; y++; } if (i > LINES) { matrix[z][j].val = ' '; continue; } matrix[i][j].val = (int) rand() % randnum + randmin; matrix[i][j].is_head = true; /* If we're at the top of the collumn and it's reached its full length (about to start moving down), we do this to get it moving. This is also how we keep segments not already growing from growing accidentally => */ if (y > length[j] || firstcoldone) { matrix[z][j].val = ' '; matrix[0][j].val = -1; } firstcoldone = 1; i++; } } } /* A simple hack */ if (!oldstyle) { y = 1; z = LINES; } else { y = 0; z = LINES - 1; } for (i = y; i <= z; i++) { move(i - y, j); if (matrix[i][j].val == 0 || (matrix[i][j].is_head && !rainbow)) { if (console || xwindow) { attron(A_ALTCHARSET); } attron(COLOR_PAIR(COLOR_WHITE)); if (bold) { attron(A_BOLD); } if (matrix[i][j].val == 0) { if (console || xwindow) { addch(183); } else { addch('&'); } } else { addch(matrix[i][j].val); } attroff(COLOR_PAIR(COLOR_WHITE)); if (bold) { attroff(A_BOLD); } if (console || xwindow) { attroff(A_ALTCHARSET); } } else { if(rainbow) { int randomColor = rand() % 6; switch(randomColor){ case 0: mcolor = COLOR_GREEN; break; case 1: mcolor = COLOR_BLUE; break; case 2: mcolor = COLOR_BLACK; break; case 3: mcolor = COLOR_YELLOW; break; case 4: mcolor = COLOR_CYAN; break; case 5: mcolor = COLOR_MAGENTA; break; } } attron(COLOR_PAIR(mcolor)); if (matrix[i][j].val == 1) { if (bold) { attron(A_BOLD); } addch('|'); if (bold) { attroff(A_BOLD); } } else { if (console || xwindow) { attron(A_ALTCHARSET); } if (bold == 2 || (bold == 1 && matrix[i][j].val % 2 == 0)) { attron(A_BOLD); } if (matrix[i][j].val == -1) { addch(' '); } else if (lambda && matrix[i][j].val != ' ') { addstr("λ"); } else { addch(matrix[i][j].val); } if (bold == 2 || (bold == 1 && matrix[i][j].val % 2 == 0)) { attroff(A_BOLD); } if (console || xwindow) { attroff(A_ALTCHARSET); } } attroff(COLOR_PAIR(mcolor)); } } } //Check if computer is locked if(lock == 1){ //Add our message to the screen char *msg = "Computer locked."; int msg_x = LINES/2; int msg_y = COLS/2 - strlen(msg)/2; int i = 0; //Add space before message move(msg_x-1, msg_y-2); for(i = 0; i < strlen(msg)+4; i++) addch(' '); //Write message move(msg_x, msg_y-2); addch(' '); addch(' '); addstr(msg); addch(' '); addch(' '); //Add space after message move(msg_x+1, msg_y-2); for(i = 0; i < strlen(msg)+4; i++) addch(' '); } napms(update * 10); } finish(); }
static bool process_event(SDL_Event *event) { struct buffered_status *status = store_status(); enum keycode ckey; /* SDL's numlock keyboard modifier handling seems to be broken on X11, * and it will only get numlock's status right on application init. We * can trust this value once, and then toggle based on user presses of * the numlock key. * * On Windows, KEYDOWN/KEYUP seem to be sent separately, to indicate * enabling or disabling of numlock. But on X11, both KEYDOWN/KEYUP are * sent for each toggle, so this must be handled differently. * * What a mess! */ if(!numlock_status_initialized) { status->numlock_status = !!(SDL_GetModState() & KMOD_NUM); numlock_status_initialized = true; } switch(event->type) { case SDL_QUIT: { // Stuff an escape status->key = IKEY_ESCAPE; status->keymap[IKEY_ESCAPE] = 1; status->keypress_time = get_ticks(); break; } #if SDL_VERSION_ATLEAST(2,0,0) case SDL_WINDOWEVENT: { switch(event->window.event) { case SDL_WINDOWEVENT_RESIZED: { resize_screen(event->window.data1, event->window.data2); break; } case SDL_WINDOWEVENT_FOCUS_LOST: { // Pause while minimized if(input.unfocus_pause) { while(1) { SDL_WaitEvent(event); if(event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) break; } } break; } } break; } #else // !SDL_VERSION_ATLEAST(2,0,0) case SDL_VIDEORESIZE: { resize_screen(event->resize.w, event->resize.h); break; } case SDL_ACTIVEEVENT: { if(input.unfocus_pause) { // Pause while minimized if(event->active.state & (SDL_APPACTIVE | SDL_APPINPUTFOCUS)) { // Wait for SDL_APPACTIVE with gain of 1 do { SDL_WaitEvent(event); } while((event->type != SDL_ACTIVEEVENT) || (event->active.state & ~(SDL_APPACTIVE | SDL_APPINPUTFOCUS))); } } break; } #endif // !SDL_VERSION_ATLEAST(2,0,0) case SDL_MOUSEMOTION: { SDL_Window *window = SDL_GetWindowFromID(sdl_window_id); int mx_real = event->motion.x; int my_real = event->motion.y; int mx, my, min_x, min_y, max_x, max_y; get_screen_coords(mx_real, my_real, &mx, &my, &min_x, &min_y, &max_x, &max_y); if(mx > 639) SDL_WarpMouseInWindow(window, max_x, my_real); if(mx < 0) SDL_WarpMouseInWindow(window, min_x, my_real); if(my > 349) SDL_WarpMouseInWindow(window, mx_real, max_y); if(my < 0) SDL_WarpMouseInWindow(window, mx_real, min_y); status->real_mouse_x = mx; status->real_mouse_y = my; status->mouse_x = mx / 8; status->mouse_y = my / 14; status->mouse_moved = true; break; } case SDL_MOUSEBUTTONDOWN: { status->mouse_button = event->button.button; status->mouse_repeat = event->button.button; status->mouse_button_state |= SDL_BUTTON(event->button.button); status->mouse_repeat_state = 1; status->mouse_drag_state = -1; status->mouse_time = SDL_GetTicks(); break; } case SDL_MOUSEBUTTONUP: { status->mouse_button_state &= ~SDL_BUTTON(event->button.button); status->mouse_repeat = 0; status->mouse_drag_state = 0; status->mouse_repeat_state = 0; break; } #if SDL_VERSION_ATLEAST(2,0,0) // emulate the X11-style "wheel is a button" that SDL 1.2 used case SDL_MOUSEWHEEL: { SDL_Event fake_event; fake_event.type = SDL_MOUSEBUTTONDOWN; fake_event.button.windowID = event->wheel.windowID; fake_event.button.which = event->wheel.which; fake_event.button.state = SDL_PRESSED; fake_event.button.x = 0; fake_event.button.y = 0; if(event->wheel.y < 0) fake_event.button.button = MOUSE_BUTTON_WHEELDOWN; else fake_event.button.button = MOUSE_BUTTON_WHEELUP; SDL_PushEvent(&fake_event); fake_event.type = SDL_MOUSEBUTTONUP; fake_event.button.state = SDL_RELEASED; SDL_PushEvent(&fake_event); break; } #endif // SDL_VERSION_ATLEAST(2,0,0) case SDL_KEYDOWN: { Uint16 unicode = 0; #if SDL_VERSION_ATLEAST(2,0,0) // FIXME: SDL 2.0 finally implements proper key repeat. // We should probably use it instead of our hand-rolled stuff. if(event->key.repeat) break; #endif ckey = convert_SDL_internal(event->key.keysym.sym); if(!ckey) { #if !SDL_VERSION_ATLEAST(2,0,0) if(!event->key.keysym.unicode) break; #endif ckey = IKEY_UNICODE; } #if SDL_VERSION_ATLEAST(2,0,0) // SDL 2.0 sends the raw key and translated 'text' as separate events. // There is no longer a UNICODE mode that sends both at once. // Because of the way the SDL 1.2 assumption is embedded deeply in // the MZX event queue processor, emulate the 1.2 behaviour by waiting // for a TEXTINPUT event after a KEYDOWN. if(SDL_WaitEventTimeout(event, 1)) { if(event->type == SDL_TEXTINPUT) unicode = event->text.text[0] | event->text.text[1] << 8; else SDL_PushEvent(event); } #else unicode = event->key.keysym.unicode; #endif if((ckey == IKEY_RETURN) && get_alt_status(keycode_internal) && get_ctrl_status(keycode_internal)) { toggle_fullscreen(); break; } if(ckey == IKEY_CAPSLOCK) { status->caps_status = true; } if(ckey == IKEY_NUMLOCK) { #if !SDL_VERSION_ATLEAST(2,0,0) && defined(__WIN32__) status->numlock_status = true; #endif break; } if(ckey == IKEY_F12) { dump_screen(); break; } // Ignore alt + tab if((ckey == IKEY_TAB) && get_alt_status(keycode_internal)) { break; } if(status->key_repeat && (status->key_repeat != IKEY_LSHIFT) && (status->key_repeat != IKEY_RSHIFT) && (status->key_repeat != IKEY_LALT) && (status->key_repeat != IKEY_RALT) && (status->key_repeat != IKEY_LCTRL) && (status->key_repeat != IKEY_RCTRL)) { // Stack current repeat key if it isn't shift, alt, or ctrl if(input.repeat_stack_pointer != KEY_REPEAT_STACK_SIZE) { input.key_repeat_stack[input.repeat_stack_pointer] = status->key_repeat; input.unicode_repeat_stack[input.repeat_stack_pointer] = status->unicode_repeat; input.repeat_stack_pointer++; } } key_press(status, ckey, unicode); break; } case SDL_KEYUP: { #if SDL_VERSION_ATLEAST(2,0,0) // FIXME: SDL 2.0 finally implements proper key repeat. // We should probably use it instead of our hand-rolled stuff. if(event->key.repeat) break; #endif ckey = convert_SDL_internal(event->key.keysym.sym); if(!ckey) { #if !SDL_VERSION_ATLEAST(2,0,0) if(!status->keymap[IKEY_UNICODE]) break; #endif ckey = IKEY_UNICODE; } if(ckey == IKEY_NUMLOCK) { #if !SDL_VERSION_ATLEAST(2,0,0) && defined(__WIN32__) status->numlock_status = false; #else status->numlock_status = !status->numlock_status; #endif break; } if(ckey == IKEY_CAPSLOCK) { status->caps_status = false; } status->keymap[ckey] = 0; if(status->key_repeat == ckey) { status->key_repeat = IKEY_UNKNOWN; status->unicode_repeat = 0; } status->key_release = ckey; break; } case SDL_JOYAXISMOTION: { int axis_value = event->jaxis.value; int digital_value = -1; int which = event->jaxis.which; int axis = event->jaxis.axis; Sint8 last_axis = status->axis[which][axis]; enum keycode stuffed_key; if(axis_value > 10000) digital_value = 1; else if(axis_value < -10000) digital_value = 0; if(digital_value != -1) { stuffed_key = input.joystick_axis_map[which][axis][digital_value]; if(stuffed_key) { joystick_key_press(status, stuffed_key, stuffed_key); if(last_axis == (digital_value ^ 1)) { joystick_key_release(status, input.joystick_axis_map[which][axis][last_axis]); } } } else if(last_axis != -1) { joystick_key_release(status, input.joystick_axis_map[which][axis][last_axis]); } status->axis[which][axis] = digital_value; break; } case SDL_JOYBUTTONDOWN: { int which = event->jbutton.which; int button = event->jbutton.button; enum keycode stuffed_key = input.joystick_button_map[which][button]; if(stuffed_key) joystick_key_press(status, stuffed_key, stuffed_key); break; } case SDL_JOYBUTTONUP: { int which = event->jbutton.which; int button = event->jbutton.button; enum keycode stuffed_key = input.joystick_button_map[which][button]; if(stuffed_key) joystick_key_release(status, stuffed_key); break; } case SDL_JOYHATMOTION: { int which = event->jhat.which; int dir = event->jhat.value; enum keycode key_up = input.joystick_hat_map[which][0]; enum keycode key_down = input.joystick_hat_map[which][1]; enum keycode key_left = input.joystick_hat_map[which][2]; enum keycode key_right = input.joystick_hat_map[which][3]; //if(dir & SDL_HAT_CENTERED) { joystick_key_release(status, key_up); joystick_key_release(status, key_down); joystick_key_release(status, key_left); joystick_key_release(status, key_right); } if(dir & SDL_HAT_UP) { if (key_up) joystick_key_press(status, key_up, key_up); } if(dir & SDL_HAT_DOWN) { if (key_down) joystick_key_press(status, key_down, key_down); } if(dir & SDL_HAT_LEFT) { if (key_left) joystick_key_press(status, key_left, key_left); } if(dir & SDL_HAT_RIGHT) { if (key_right) joystick_key_press(status, key_right, key_right); } break; } default: return false; } return true; }
void main(int argc, char **argv) { Errcode err; UBYTE oldconfig; static Argparse_list apl[] = { ARGP(apl,0,"-flic",get_flic_arg), ARGP(apl,APLAST,"-poc",get_poco_arg), }; if((err = init_pj_startup(apl,get_rest_of_command_line,argc,argv, "pj_help","aa.mu")) < Success) { goto error; } oldconfig = err; add_local_pdr(&fli_local_pdr); add_local_pdr(&pic_local_pdr); set_hotkey_func(do_pj_hotkey); /* set input hot key function */ /* initialize pj resource files */ if((err = init_pj_resources()) < Success) goto error; if((err = init_ptools()) < Success) /* initialize tools */ goto error; if((err = init_inks()) < Success) /* load any loadable inks */ goto error; if(cl_poco_name != NULL) { if ((err = compile_cl_poco(cl_poco_name)) < Success) { if (err == Err_in_err_file) po_file_to_stdout(poco_err_name); err = Err_reported; goto error; } } vs = default_vs; /* copy in default settings */ if((err = open_pj_startup_screen(init_after_screen)) < Success) goto error; #ifdef WIDGET widge_ask = TRUE; #endif /* WIDGET */ if(!oldconfig) soft_continu_box("newconfig"); if (cl_flic_name != NULL) pj_delete(tflxname); /* Delete old tempflx */ if((err = force_temp_files()) < Success) goto error; if (cl_flic_name != NULL) resize_load_fli(cl_flic_name); err = go_vpaint(); for(;;) { switch(err) { case RESET_SCREEN_SIZE: err = resize_screen(); break; case RESET_NEW_SIZE: case KILL_NEW_SIZE: scrub_cur_frame(); /* clean up act in case user aborts */ flush_tflx(); err = resize_pencel(FALSE,err == RESET_NEW_SIZE); break; case RESET_DEFAULT_FLX: push_close_toscreen(); if((err = clear_vtemps(TRUE)) < 0) goto error; if((err = open_default_flx()) < 0) goto error; case RESTART_VPAINT: err = go_vpaint(); break; case EXIT_SYSTEM: outofhere(TRUE); /* we've exited, don't need to break... */ case QUIT_SYSTEM: outofhere(FALSE); default: /* not a good return */ goto error; } } error: cleanup_all(err); exit(err); }
int main ( int argc, char** argv ) { /// initialisation son & image /// initialisation FMOD FMOD_SYSTEM * system; FMOD_System_Create(&system); /// initialisation image & son initialisation(system); /// verification de la date struct tm Today; time_t maintenant; time(&maintenant); Today = *localtime(&maintenant); Today.tm_year += 1900; Today.tm_mon += 1; Today.tm_mday; /// username DWORD StrLen = 256; TCHAR SysInfoStr[256]; GetComputerName(SysInfoStr, &StrLen); std::string nameComputeur = SysInfoStr; GetUserName(SysInfoStr, &StrLen); std::string nameUser = SysInfoStr; /// déclaration et chargements des ressources /// create a new window putenv("SDL_VIDEO_WINDOW_POS=center"); /// pour centrer la fenêtre SDL_Surface* screen = SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE|SDL_FULLSCREEN); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } /// images SDL_Surface** images = NULL; images = (SDL_Surface **) malloc (sizeof(SDL_Surface*)*NOMBRE_IMAGE); load_images(images); /// sons FMOD_SOUND ** musiques = NULL; musiques = (FMOD_SOUND **) malloc (sizeof(FMOD_SOUND*)*NOMBRE_MUSIQUE); load_musiques(system, musiques); /// polices TTF_Font ** polices = NULL; polices = (TTF_Font **) malloc(sizeof(TTF_Font*) * NOMBRE_POLICE); load_polices(polices); /// Icone SDL_WM_SetIcon(images[0], NULL); /// titre SDL_WM_SetCaption("Julie", NULL); /// program main loop Input * in = new Input; int tempsPrecedent = 0, tempsActuel = 0; int ghost = 255; bool devient_ghost = true; int * menu = new int; *menu = -1; SDL_Rect place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; /// musiques FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, musiques[0], 0, NULL); /// affichage du logo int i = 0; while(i<256) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; SDL_SetAlpha(images[0], SDL_SRCALPHA, i); SDL_BlitSurface(images[0], NULL, SDL_GetVideoSurface(), &place); i++; SDL_Flip(SDL_GetVideoSurface()); } while(i>=0) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; SDL_SetAlpha(images[0], SDL_SRCALPHA, i); SDL_BlitSurface(images[0], NULL, SDL_GetVideoSurface(), &place); i--; SDL_Flip(SDL_GetVideoSurface()); } place = {LARGEUR_ECRAN/2 - images[1]->w/2,HAUTEUR_ECRAN/2 - images[1]->h/2,0,0}; while(!in->get_touche(SDLK_ESCAPE) && !in->get_exit()) /// boucle principale { /// mise à jour des events in->update(); /// gestion du frame fps(&tempsPrecedent, &tempsActuel, SCREEN_REFRESH); /// resize taille écran resize_screen(*in); if(*menu == 1 || in->get_touche(SDLK_1) || in->get_touche(SDLK_KP1)) /// jouer { in->set_touche(SDLK_1, 0); in->set_touche(SDLK_KP1, 0); Jeu * party = new Jeu(images); party->game(); delete party; in->set_touche(SDLK_ESCAPE, 0); } if(*menu == 2 || in->get_touche(SDLK_2) || in->get_touche(SDLK_KP2)) /// jouer { in->set_touche(SDLK_2, 0); in->set_touche(SDLK_KP2, 0); Jeu * party = new Jeu(images); party->conjugaison(); delete party; in->set_touche(SDLK_ESCAPE, 0); } if(*menu == -9) /// quitter le jeu { in->set_exit(1); } if(*menu == -1) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[1]->w/2,HAUTEUR_ECRAN/2 - images[1]->h/2,0,0}; SDL_BlitSurface(images[1], NULL, SDL_GetVideoSurface(), &place); /* if(devient_ghost) { ghost -= 8; } else { ghost += 8; } if(ghost >= 255 || ghost <= 88) { devient_ghost = !devient_ghost; } place = {LARGEUR_ECRAN/2 - images[2]->w/2,3*HAUTEUR_ECRAN/4 - images[2]->h/2,0,0}; SDL_SetAlpha(images[2], SDL_SRCALPHA, ghost); SDL_BlitSurface(images[2], NULL, SDL_GetVideoSurface(), &place); */ Texte menu1; Texte menu2; menu1.print("1 - Mathématiques", "arial", 60, {255,255,255}, SDL_GetVideoSurface()->w/3, 3*SDL_GetVideoSurface()->h/4); menu2.print("2 - Conjugaison", "arial", 60, {255,255,255}, SDL_GetVideoSurface()->w/3, 3*SDL_GetVideoSurface()->h/4+100); } SDL_Flip(screen); }/// end main loop /// nettoyage /// free pointeurs delete menu; delete in; /// free loaded bitmap and created surface SDL_FreeSurface(screen); free_images(images); free_polices(polices); /// libération des sons free_musiques(musiques); /// fermeture propre de ce qui est ouvert dans initialisation() fermeture(system); /// all is well ;) printf("Exited cleanly\n"); return 0; }
void handle_events() { static int button_left = 0; static int button_right = 0; static int button_middle = 0; int width = 0, height = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: switch (event.button.button) { case SDL_BUTTON_LEFT: button_left = 1; break; case SDL_BUTTON_MIDDLE: button_middle = 1; break; case SDL_BUTTON_RIGHT: button_right = 1; break; default: break; } break; case SDL_MOUSEBUTTONUP: switch (event.button.button) { case SDL_BUTTON_LEFT: button_left = 0; break; case SDL_BUTTON_MIDDLE: button_middle = 0; break; case SDL_BUTTON_RIGHT: button_right = 0; break; default: break; } break; case SDL_MOUSEMOTION: if (button_left) { yoff -= zoom * (float)event.motion.yrel / (float)screen->h; xoff -= zoom * (float)event.motion.xrel / (float)screen->w; } if (button_middle) { } if (button_right) { zoom -= zoom * (float)event.motion.yrel / (float)screen->h; } break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_q: exit(0); break; case SDLK_ESCAPE: exit(0); break; case SDLK_r: zoom = 5.0; xoff = -0.75; yoff = 0.0; break; default: break; } break; case SDL_VIDEORESIZE: width = event.resize.w; height = event.resize.h; break; case SDL_QUIT: exit(1); break; default: break; } } if (width && height) resize_screen(width, height); }
void handle_events() { int w = 0, h = 0; static int button_left = 0; static int button_right = 0; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_ACTIVEEVENT: focus = event.active.gain; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_r: rotation = m4f_ident(); break; case SDLK_q: case SDLK_ESCAPE: exit(0); break; default: break; } break; case SDL_MOUSEBUTTONDOWN: switch (event.button.button) { case SDL_BUTTON_LEFT: button_left = 1; break; case SDL_BUTTON_RIGHT: button_right = 1; break; case SDL_BUTTON_WHEELUP: zoom += 0.01; recalc_projection(); break; case SDL_BUTTON_WHEELDOWN: zoom -= 0.01; recalc_projection(); break; default: break; } break; case SDL_MOUSEBUTTONUP: switch (event.button.button) { case SDL_BUTTON_LEFT: button_left = 0; break; case SDL_BUTTON_RIGHT: button_right = 0; break; default: break; } break; case SDL_MOUSEMOTION: if (button_left) { rotation = m4f_mul(rotation, m4f_rot(-M_PI * (float)event.motion.yrel / (float)screen->h, v3f(1, 0, 0))); rotation = m4f_mul(rotation, m4f_rot(-M_PI * (float)event.motion.xrel / (float)screen->w, v3f(0, 1, 0))); } if (button_right) { mouse_x += (float)event.motion.xrel / (float)screen->w; mouse_y += -(float)event.motion.yrel / (float)screen->h; } break; case SDL_VIDEORESIZE: w = event.resize.w; h = event.resize.h; break; case SDL_QUIT: exit(0); break; default: break; } } if (w && h) resize_screen(w, h); }