int main(void) { static uint8_t state[16]; static uint8_t prev_state[16]; // set for 16 MHz clock CPU_PRESCALE(0); init_keyboard_interface(); // Initialize the USB, and then wait for the host to set configuration. // If the Teensy is powered without a PC connected to the USB port, // this will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; // Wait for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(3000); memset(prev_state, 0, sizeof prev_state); while (1) { poll_keyboard(state); if (memcmp(state, prev_state, sizeof state)) { send_keys(state); memcpy(prev_state, state, sizeof state); } _delay_ms(10); } }
Byte read_P2(void){ int i,si,so,km; if (NeedsPoll) poll_keyboard(); if (!(p1 & 0x04)) { si = (p2 & 7); so=0xff; if (si<6) { for (i=0; i<8; i++) { km = key_map[si][i]; if ((key[km] && ((!joykeystab[km]) || (key_shifts & KB_CAPSLOCK_FLAG))) || (key2[km])) { so = i ^ 0x07; } } } if (so != 0xff) { p2 = p2 & 0x0F; p2 = p2 | (so << 5); } else { p2 = p2 | 0xF0; } } else { p2 = p2 | 0xF0; } return(p2); }
void TKeyHandler::update() { if (keyboard_needs_poll()) poll_keyboard(); // detect key changes ... // (note that changes in-between updates are not seen by this so it's not 100% accurate) int i; for ( i = 0; i < KEY_MAX; ++i ) { // keep record of prev and new states keyold[i] = keynew[i]; keynew[i] = key[i]; // detect changes keyhit[i] = 0; keyreleased[i] = 0; if (keynew[i] != keyold[i]) { if (keynew[i]) keyhit[i] = 1; else keyreleased[i] = 1; } } Nbuf = Nbackbuf; for ( i = 0; i < Nbuf; ++i ) { keybuf[i] = keybackbuf[i]; } // reset the back-buffer for reading new stuf. Nbackbuf = 0; }
int main(int argc, char * argv[]) { setup_windowing(); int width = 500; int height = 500; resize_window_callback = resize_callback; window = window_create(100,100,500,500); ctx = init_graphics_window(window); draw_fill(ctx, rgba(0,0,0,127)); window_enable_alpha(window); render(); while (1) { w_keyboard_t * kbd = poll_keyboard(); if (kbd != NULL) { if (kbd->key == 'q') { break; } free(kbd); } } teardown_windowing(); return 0; }
int console_read_char(void) { unsigned int code; for (;;) { if (++cursor_timer == BLINK_INTERVAL) { invert_cursor(); cursor_state = !cursor_state; cursor_timer = 0; } code = poll_keyboard(); if ((code != 0xffffffff) && (code & KBD_PRESSED)) break; } if (cursor_state) { invert_cursor(); cursor_state = 0; } return code & 0xff; }
int Control::choose_ship(VideoWindow *window, char * prompt, Fleet *fleet) { STACKTRACE; int ret = -1, slot = 0; if (fleet->getSize() == 0) { tw_error ("Empty fleet! (prompt:%s)", prompt); } selectDialog[SELECT_DIALOG_LIST].dp3 = fleet; strcpy(selectShipPrompt,prompt); slot = -1; while (!always_random) { while (key[KEY_ENTER] || key[KEY_SPACE]) poll_keyboard(); ret = tw_do_dialog(window, selectDialog, SELECT_DIALOG_LIST); if (ret == SELECT_DIALOG_INFO) { ship_view_dialog( selectDialog[SELECT_DIALOG_LIST].d1, fleet ); continue; } break; } if ((ret == SELECT_DIALOG_SHIP) || (ret == SELECT_DIALOG_LIST)) slot = selectDialog[SELECT_DIALOG_LIST].d1; if ((ret == SELECT_DIALOG_ARANDOM) || (ret == -1)) always_random = 1; return(slot); }
/* handle the setup command */ static void setup_all_keys(void) { int focus = 2; int i; /* Prepare dialog. */ set_dialog_color(keymap_dialog, black, white); centre_dialog(keymap_dialog); /* Parse input. */ while (1) { focus = do_dialog(keymap_dialog, focus); switch (focus) { case 2: case 4: textprintf_centre_ex (screen, font, keymap_dialog[7].x, keymap_dialog[7].y, red, -1, "Press a key to map to the current scancode"); textprintf_centre_ex (screen, font, keymap_dialog[7].x, keymap_dialog[7].y + 8, red, -1, "(or a mouse button to leave it unchanged)"); /* Wait for new key press. */ new_keycode = -1; waiting_for_key = 1; do { poll_keyboard(); poll_mouse(); if (mouse_b) waiting_for_key = 0; } while (waiting_for_key); /* Save keycode to scancode mapping. */ if ((new_keycode >= 0) && (new_keycode < 256)) { keycode_to_scancode[new_keycode] = keymap_dialog[2].d1 + 1; } clear_keybuf(); break; case 5: return; case 6: for (i = 0; i < 256; i++) { if (keycode_to_scancode[i] >= 0) _xwin.keycode_to_scancode[i] = keycode_to_scancode[i]; } return; } } }
/* scanline interrupt */ void geneve_hblank_interrupt(void) { static int line_count; v9938_interrupt(); if (++line_count == 262) { line_count = 0; poll_keyboard(); poll_mouse(); } }
Byte keyjoy(int jn){ Byte d; d=0xFF; if ((jn>=0) && (jn<=1)){ if (NeedsPoll) poll_keyboard(); if (key[joykeys[jn][0]]) d &= 0xFE; if (key[joykeys[jn][1]]) d &= 0xFB; if (key[joykeys[jn][2]]) d &= 0xF7; if (key[joykeys[jn][3]]) d &= 0xFD; if (key[joykeys[jn][4]]) d &= 0xEF; } return d; }
int uip_checkkeyboard(void) { int pad; int joystick; if (uip_keypoll) poll_keyboard(); for (pad = 0; pad < 2; pad++) { if ((joystick = ui_bindings[pad].joystick) >= 0) { /* not supported - yet */ } else { switch (ui_bindings[pad].keyboard) { case 0: /* main keys */ mem68k_cont[pad].a = key[KEY_A] ? 1 : 0; mem68k_cont[pad].b = (key[KEY_B] || key[KEY_S]) ? 1 : 0; mem68k_cont[pad].c = (key[KEY_C] || key[KEY_D]) ? 1 : 0; mem68k_cont[pad].left = key[KEY_LEFT] ? 1 : 0; mem68k_cont[pad].up = key[KEY_UP] ? 1 : 0; mem68k_cont[pad].right = key[KEY_RIGHT] ? 1 : 0; mem68k_cont[pad].down = key[KEY_DOWN] ? 1 : 0; mem68k_cont[pad].start = key[KEY_ENTER] ? 1 : 0; break; case 1: /* left side of keyboard */ mem68k_cont[pad].a = key[KEY_Z] ? 1 : 0; mem68k_cont[pad].b = key[KEY_X] ? 1 : 0; mem68k_cont[pad].c = key[KEY_C] ? 1 : 0; mem68k_cont[pad].left = key[KEY_D] ? 1 : 0; mem68k_cont[pad].up = key[KEY_R] ? 1 : 0; mem68k_cont[pad].right = key[KEY_G] ? 1 : 0; mem68k_cont[pad].down = key[KEY_F] ? 1 : 0; mem68k_cont[pad].start = key[KEY_V] ? 1 : 0; break; case 2: /* right side of keyboard */ mem68k_cont[pad].a = key[KEY_COMMA] ? 1 : 0; mem68k_cont[pad].b = key[KEY_STOP] ? 1 : 0; mem68k_cont[pad].c = key[KEY_SLASH] ? 1 : 0; mem68k_cont[pad].left = key[KEY_LEFT] ? 1 : 0; mem68k_cont[pad].up = key[KEY_UP] ? 1 : 0; mem68k_cont[pad].right = key[KEY_RIGHT] ? 1 : 0; mem68k_cont[pad].down = key[KEY_DOWN] ? 1 : 0; mem68k_cont[pad].start = key[KEY_ENTER] ? 1 : 0; break; } } } return (key[KEY_ESC] ? 1 : 0); }
/* really_quit: ask if we really want to quit */ void really_quit(void) { draw_yes_no_box(vscreen, "Really quit?", (EDITOR_WIN_W / 2) - 50, (EDITOR_WIN_H / 2) - 50); while (1) { update_screen(); poll_keyboard(); if (key[KEY_Y]) { close_program = 1; break; } else if (key[KEY_N]) { break; } } }
//****************************************************************************** // Función tcj_comprobar() // Comprueba el estado del teclado y/o joystick/joypad para actualizar los // valores de la tabla tcj_estado. //****************************************************************************** void tcj_comprobar() { char f; // inicializamos y hacemos los polls necesarios for(f=0;f<8+TCJ_NUM_BOTONES;tcj_estado[f++]=0); if(ini_t) poll_keyboard(); if(ini_j) poll_joystick(); // Comprobamos las cuatro direcciones básicas. for(f=0;f<TCJ_MAX_ENTRADAS*4;f++) if(entrada[f]) if(*entrada[f]) tcj_estado[(f/TCJ_MAX_ENTRADAS)*2]=1; // En función de las cuatro básicas, informamos las cuatro de suma. if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_ABJ]) tcj_estado[TCJ_ARR]=tcj_estado[TCJ_ABJ]=0; if(tcj_estado[TCJ_IZQ] && tcj_estado[TCJ_DER]) tcj_estado[TCJ_IZQ]=tcj_estado[TCJ_DER]=0; if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_DER]) { tcj_estado[TCJ_ARR]=tcj_estado[TCJ_DER]=0; tcj_estado[TCJ_A_D]=1; } if(tcj_estado[TCJ_ARR] && tcj_estado[TCJ_IZQ]) { tcj_estado[TCJ_ARR]=tcj_estado[TCJ_IZQ]=0; tcj_estado[TCJ_A_I]=1; } if(tcj_estado[TCJ_ABJ] && tcj_estado[TCJ_DER]) { tcj_estado[TCJ_ABJ]=tcj_estado[TCJ_DER]=0; tcj_estado[TCJ_B_D]=1; } if(tcj_estado[TCJ_ABJ] && tcj_estado[TCJ_IZQ]) { tcj_estado[TCJ_ABJ]=tcj_estado[TCJ_IZQ]=0; tcj_estado[TCJ_B_I]=1; } // Comprobamos las acciones. for(;f<TCJ_MAX_ENTRADAS*(4+TCJ_NUM_BOTONES);f++) if(entrada[f]) if(*entrada[f]) tcj_estado[(f/TCJ_MAX_ENTRADAS)+4]=1; }
/* ti99_handset_task() Manage handsets, posting an event if the state of any handset has changed. */ void ti99_handset_device::do_task() { int i; if (m_buflen == 0) { /* poll every handset */ for (i=0; i < MAX_HANDSETS; i++) if (poll_joystick(i)==true) return; for (i=0; i < MAX_HANDSETS; i++) if (poll_keyboard(i)==true) return; } else if (m_buflen == 3) { /* update messages after they have been posted */ if (m_buf & 1) { /* keyboard */ poll_keyboard((~(m_buf >> 1)) & 0x3); } else { /* joystick */
/*============================================================================*/ Byte read_P2() { int i, si, so, km; if (NeedsPoll) poll_keyboard(); if (!(p1 & 0x04)) { si = (p2 & 7); so = 0xff; #ifdef __O2EM_KEYBOARD_DEBUG__ /*printf("%s si=%d\n", __func__, si);*/ #endif if (si < 6) { for (i = 0; i < 8; i++) { km = key_map_G7400[si][i]; #ifdef __O2EM_KEYBOARD_DEBUG__ /*if (key[km] > 0 || key[km] < 0) printf("%s km=%d si=%d i=%d SDLK_z=%d KEY_1=%d\n", __func__, km, si, i, KEY_Z, KEY_1);*/ #endif if ((key[km] && ((!joykeystab[km]) || (key_shifts & KB_CAPSLOCK_FLAG))) || (key2[km])) { so = i ^ 0x07; } } } if (so != 0xff) { p2 = p2 & 0x0F; p2 = p2 | (so << 5); } else { p2 = p2 | 0xF0; } } else { p2 = p2 | 0xF0; } #ifdef __O2EM_KEYBOARD_DEBUG__ /*printf("p2 = %d\n", p2);*/ #endif return p2; }
void main(void) { bit test_radio = 0; bit bounce_radio = 0; /* Initialize app modules. Not reinitialized upon reset. */ message_init(); compose_init(); inbox_init(); info_init(); reset: sleepy_ = 0; state_ = STATE_VIEW; if (bounce_radio) { repeater_mode(); } /* Initialize system modules. */ clock_init(); setIOPorts(); configureSPI(); LCDReset(); radio_init(); random_init(); inbox_draw(); if (test_radio) { run_test_radio(); } /* Main loop. */ radio_listen(); while (1) { poll_keyboard(); /* Send and receive messages. */ message_tick(); /* Handle background tasks (like progress bar) */ if (compose_tick() && state_ == STATE_COMPOSE) { compose_draw(); } if (info_tick() && state_ == STATE_INFO) { info_draw(); } /* go to sleep (more or less a shutdown) if power button pressed */ if (sleepy_) { clear(); clock_delayms(1000); SSN = LOW; LCDPowerSave(); SSN = HIGH; sleep(); /* reset on wake */ goto reset; } } }
/* handle the test command */ int tester() { char buf[256]; int a, i; show_mouse(NULL); acquire_screen(); clear_to_color(screen, palette_color[8]); for (i=0; i<KEY_MAX; i++) textout_ex(screen, font, scancode_to_name(i), 32+(i%4)*160, 60+(i/4)*10, palette_color[255], palette_color[8]); release_screen(); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); do { poll_keyboard(); poll_mouse(); acquire_screen(); for (i=0; i<KEY_MAX; i++) textout_ex(screen, font, key[i] ? "*" : " ", 16+(i%4)*160, 60+(i/4)*10, palette_color[255], palette_color[8]); buf[0] = 0; if (key_shifts & KB_SHIFT_FLAG) strcat(buf, "shift "); if (key_shifts & KB_CTRL_FLAG) strcat(buf, "ctrl "); if (key_shifts & KB_ALT_FLAG) strcat(buf, "alt "); if (key_shifts & KB_LWIN_FLAG) strcat(buf, "lwin "); if (key_shifts & KB_RWIN_FLAG) strcat(buf, "rwin "); if (key_shifts & KB_MENU_FLAG) strcat(buf, "menu "); if (key_shifts & KB_COMMAND_FLAG) strcat(buf, "command "); if (key_shifts & KB_SCROLOCK_FLAG) strcat(buf, "scrolock "); if (key_shifts & KB_NUMLOCK_FLAG) strcat(buf, "numlock "); if (key_shifts & KB_CAPSLOCK_FLAG) strcat(buf, "capslock "); if (key_shifts & KB_INALTSEQ_FLAG) strcat(buf, "inaltseq "); if (key_shifts & KB_ACCENT1_FLAG) strcpy(buf, "accent1 "); if (key_shifts & KB_ACCENT2_FLAG) strcpy(buf, "accent2 "); if (key_shifts & KB_ACCENT3_FLAG) strcpy(buf, "accent3 "); if (key_shifts & KB_ACCENT4_FLAG) strcpy(buf, "accent4 "); while (strlen(buf) < 128) strcat(buf, " "); textout_ex(screen, font, buf, 0, 0, palette_color[255], palette_color[8]); release_screen(); if (keypressed()) { a = ureadkey(&i); if (!a) a = ' '; textprintf_ex(screen, font, 32, 34, palette_color[255], palette_color[8], "ureadkey() returns scancode 0x%02X, U+0x%04X, '%c'", i, a, a); } } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf(); show_mouse(screen); return D_REDRAW; }
void handle_key(void){ if (NeedsPoll) poll_keyboard(); if (key[syskeys[0]] || key[KEY_ESC]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[0]] || key[KEY_ESC]); key_done=1; } if (key[syskeys[1]]) { do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); mute_audio(); mute_voice(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); abaut(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } } while ((!key[syskeys[1]]) && (!key[KEY_ESC]) && (!key[syskeys[0]])); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[1]]); init_sound_stream(); } if (key[syskeys[5]]) { if (savestate(app_data.statefile)==0) { display_msg("Savefile saved.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[5]]); } /* LOAD STATE */ if (key[syskeys[6]]) { int stateError; if ((stateError=loadstate(app_data.statefile))==0) { display_msg("Savefile loaded.",5); } else if (stateError>=199) { if (stateError==199) display_msg("Wrong ROM-File for Savefile.",5); else if (stateError==200+ROM_O2) display_msg("Wrong BIOS for Savefile: O2ROM needed.",5); else if (stateError==200+ROM_G7400) display_msg("Wrong BIOS for Savefile: G7400 ROM needed.",5); else if (stateError==200+ROM_C52) display_msg("Wrong BIOS for Savefile: C52 ROM needed.",5); else if (stateError==200+ROM_JOPAC) display_msg("Wrong BIOS for Savefile: JOPAC ROM needed.",5); else display_msg("Wrong BIOS for Savefile: UNKNOWN ROM needed.",5); } do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[6]]); } if (key[syskeys[2]]) key_debug=1; if (key[syskeys[3]]) { init_cpu(); init_roms(); init_vpp(); clearscr(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[3]]); } /* SET HIGHSCORE */ if (key[syskeys[7]]) { set_score(app_data.scoretype, app_data.scoreaddress, app_data.default_highscore); } if (key[syskeys[4]]) { BITMAP *bmp; PALETTE pal; char *p; static char name[1024]; static int scshot_counter = 0; if (strlen(app_data.scshot)>0){ if ((p=strchr(app_data.scshot,'@'))) { *p = 0; sprintf(name, "%s%02d%s", app_data.scshot, scshot_counter++, p+1); *p = '@'; } else { strcpy(name, app_data.scshot); } get_palette(pal); bmp = create_sub_bitmap(screen, 0, 0, SCREEN_W, SCREEN_H); save_bitmap(name, bmp, pal); destroy_bitmap(bmp); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[4]]); } } // switch joystick if (key[syskeys[8]]) { joyswitch = joyswitch ? 0 : 1; set_defjoykeys(0,joyswitch); set_defjoykeys(1,joyswitch ? 0 : 1); int tmp = app_data.stick[0]; app_data.stick[0] = app_data.stick[1]; app_data.stick[1] = tmp; do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[syskeys[8]]); } if (key[KEY_ALT] && key[KEY_ENTER]) { app_data.fullscreen = app_data.fullscreen ? 0 : 1; grmode(); do { rest(5); if (NeedsPoll) poll_keyboard(); } while (key[KEY_ENTER]); } }
// Returns false when the user stop the click-loop: releases the // button or press the second click (depend of the mode) int Editor::editor_click(int *x, int *y, int *update, void (*scroll_callback) (int before_change)) { int prev_x, prev_y; poll_keyboard(); if (click_first) { click_first = false; if (click_mode == MODE_CLICKANDCLICK) { do { jmouse_poll(); gui_feedback(); } while (jmouse_b(0)); jmouse_set_position(click_start_x, click_start_y); clear_keybuf(); } } *update = jmouse_poll(); screenToEditor(click_last_x, click_last_y, &prev_x, &prev_y); click_prev_last_b = click_last_b; click_last_x = jmouse_x(0); click_last_y = jmouse_y(0); click_last_b = jmouse_b(0); screenToEditor(click_last_x, click_last_y, x, y); /* the mouse was moved */ if (*update) { View* view = View::getView(this); gfx::Rect vp = view->getViewportBounds(); /* update scroll */ if (jmouse_control_infinite_scroll(vp)) { if (scroll_callback) (*scroll_callback)(true); /* smooth scroll movement */ if (get_config_bool("Options", "MoveSmooth", true)) { jmouse_set_position(MID(vp.x+1, click_last_x, vp.x+vp.w-2), MID(vp.y+1, click_last_y, vp.y+vp.h-2)); } /* this is better for high resolutions: scroll movement by big steps */ else { jmouse_set_position((click_last_x != jmouse_x(0)) ? (click_last_x + (vp.x+vp.w/2))/2: jmouse_x(0), (click_last_y != jmouse_y(0)) ? (click_last_y + (vp.y+vp.h/2))/2: jmouse_y(0)); } gfx::Point scroll = view->getViewScroll(); setEditorScroll(scroll.x+click_last_x-jmouse_x(0), scroll.y+click_last_y-jmouse_y(0), true); click_last_x = jmouse_x(0); click_last_y = jmouse_y(0); if (scroll_callback) (*scroll_callback)(false); } // If the cursor hasn't subpixel movement if (!editor_cursor_is_subpixel()) { // Check if the mouse change to other pixel of the sprite *update = ((prev_x != *x) || (prev_y != *y)); } else { // Check if the mouse change to other pixel of the screen *update = ((prev_x != click_last_x) || (prev_y != click_last_y)); } } /* click-and-click mode */ if (click_mode == MODE_CLICKANDCLICK) { if (click_last_b) { click_prev_last_b = click_last_b; do { jmouse_poll(); gui_feedback(); } while (jmouse_b(0)); jmouse_set_position(click_last_x, click_last_y); clear_keybuf(); return false; } else { return true; } } /* click-and-release mode */ else { return (click_last_b) ? true: false; } }
int main(int argc, char* argv[]) { // init allegro and add keyboard and optional mouse support allegro_init(); install_timer(); install_keyboard(); if (ENABLE_MOUSE_SUPPORT) { install_mouse(); } // set the video mode set_color_depth(WINDOW_COLOR_DEPTH); set_gfx_mode( (WINDOW_USE_FULLSCREEN) ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0); // set the window caption text set_window_title(WINDOW_CAPTION); // create the back buffer bitmap backbuffer = create_bitmap(SCREEN_W, SCREEN_H); // seed the random number generator srand(time(0)); // lock the static functions and variables we need for handling timing and closing the window via the [X] button LOCK_FUNCTION(my_allegro_close_button_handler); LOCK_FUNCTION(my_allegro_timer_speed_controller); LOCK_VARIABLE(allegrotimerspeedcounter); // set the callback function for the close-button to our global handler function set_close_button_callback(my_allegro_close_button_handler); // set our FPS lock timing global function install_int_ex(my_allegro_timer_speed_controller, BPS_TO_TIMER(FRAME_LOCK_RATE)); // setup the game if (!setup_game()) { fprintf(stderr, "The game initialization has failed. Cannot continue!\n"); exit(1); } // main loop bool gameover = false; while(!gameover) { // if our global is ever false if (!mainthreadisrunning) { gameover = true; } // we only draw when the FPS should be locked if (allegrotimerspeedcounter > 0) { // we only update during our FPS lock time while (allegrotimerspeedcounter > 0) { // ensure the keyboard data is current if (keyboard_needs_poll()) { poll_keyboard(); } // ensure the mosue data is current if (ENABLE_MOUSE_SUPPORT) { if (mouse_needs_poll()) { poll_mouse(); } } // update update_game(); // decrement the global timing var so that we can leave the update loop! allegrotimerspeedcounter--; } // start rendering the scene render_game(); if (ENABLE_MOUSE_SUPPORT) { show_mouse(backbuffer); } // make it all visible blit(backbuffer, screen, 0, 0, 0, 0, backbuffer->w, backbuffer->h); } else { // a little rest to keep CPU usage down ^-^ rest(1); } } // shutdown the game shutdown_game(); // clean up the back buffer if (backbuffer) { if (ENABLE_MOUSE_SUPPORT) { show_mouse(0); } destroy_bitmap(backbuffer); } return 0; }
static void test_key_map(void) { int i, k, u; static int key_was_pressed[KEY_MAX + 1] = {0}; static int key_is_pressed[KEY_MAX + 1] = {0}; static char *welcome[] = { "Key that is pressed now is marked with red", "Key that was pressed is marked with yellow", "Press mouse button or Escape to exit test", 0 }; /* Clear screen and output prompt. */ clear_to_color(screen, white); for (i = 0; welcome[i] != 0; i++) textout_ex(screen, font, welcome[i], 8, i * 8 + 8, black, -1); clear_to_color(screen, white); for (i = 0; i < KEY_MAX; i++) textprintf_ex(screen, font, 32 + (i % 4) * 160, 32 + (i / 4) * 14, black, -1, "%s", scancode_to_name (i)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); do { while (keypressed()) { u = ureadkey (&k); textprintf_centre_ex (screen, font, SCREEN_W / 2, 8, red, white, "> %c <", u); } poll_keyboard(); poll_mouse(); for (i = 0; i < KEY_MAX; i++) { if (key[i]) key_was_pressed[i] = key_is_pressed[i] = 1; else key_is_pressed[i] = 0; } for (i = 0; i < KEY_MAX; i++) { int x = 16 + (i % 4) * 160; int y = 32 + (i / 4) * 14; if (key_is_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, red); else if (key_was_pressed[i]) rectfill(screen, x, y, x + 7, y + 7, yellow); else rectfill(screen, x, y, x + 7, y + 7, white); } rest(1); } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard(); poll_mouse(); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf(); }
int cControls::ProcessActions() { uInt32 i; sControl ctrl; // allegro get keyboard, joystick, and mouse info poll_keyboard(); poll_joystick(); // // error check if(m_player == NULL) return 1; if(m_game == NULL) return 1; if(info == NULL) return 2; info->Reset(); // ////////////////////////////////////////////////////////////// // check player for(i = 0; i < m_gsize; ++i) { ctrl = m_game[i]; // Keyboard if(ctrl.key != -1) { if( key[ ctrl.key ] ) // key is allegro variable { info->g[ ctrl.action ] = true; } } // // JoyStick if(ctrl.joy_num != -1) { if(ctrl.joy_type == 1) // stick { if( ctrl.joy_pos > 0) // if greater then zero, check if pressed is greater then { if( joy[ ctrl.joy_num ]. stick[ ctrl.joy_stick ]. axis[ ctrl.joy_axis ].pos > ctrl.joy_pos ) { info->g[ ctrl.action ] = true; } } else { // if less then zero, check if pressed is less then if( joy[ ctrl.joy_num ]. stick[ ctrl.joy_stick ]. axis[ ctrl.joy_axis ].pos < ctrl.joy_pos ) { info->g[ ctrl.action ] = true; } } } else if(ctrl.joy_type == 2) // button { if( joy[ ctrl.joy_num ].button[ ctrl.joy_button ].b == 1 ) { info->g[ ctrl.action ] = true; } } } // } // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // check player for(i = 0; i < m_psize; ++i) { ctrl = m_player[i]; // Keyboard if(ctrl.key != -1) { if( key[ ctrl.key ] ) // key is allegro variable { info->p[ ctrl.player ][ ctrl.action ] = true; } } // // JoyStick if(ctrl.joy_num != -1) { if(ctrl.joy_type == 1) // stick { if( ctrl.joy_pos > 0) // if greater then zero, check if pressed is greater then { if( joy[ ctrl.joy_num ]. stick[ ctrl.joy_stick ]. axis[ ctrl.joy_axis ].pos > ctrl.joy_pos ) { info->p[ ctrl.player ][ ctrl.action ] = true; } } else { // if less then zero, check if pressed is less then if( joy[ ctrl.joy_num ]. stick[ ctrl.joy_stick ]. axis[ ctrl.joy_axis ].pos < ctrl.joy_pos ) { info->p[ ctrl.player ][ ctrl.action ] = true; } } } else if(ctrl.joy_type == 2) // button { if( joy[ ctrl.joy_num ].button[ ctrl.joy_button ].b == 1 ) { info->p[ ctrl.player ][ ctrl.action ] = true; } } } // } // ////////////////////////////////////////////////////////////// // pointer, todo // mouse /* mouse_x */ return 0; }
void c_simulation::main_loop () { // PALETTE palette; //BITMAP *img_bgr = load_bitmap("dat/bgr-bright.tga", NULL); // TODO: s_font_allegl.reset (allegro_gl_convert_allegro_font(font,AGL_FONT_TYPE_TEXTURED,500.0), [](FONT *f){allegro_gl_destroy_font(f);}); for(auto &obj : m_world->m_objects) { obj->set_font(s_font_allegl); } int viewport_x = 0, viewport_y = 0; //show_mouse(m_screen); set_close_button_callback(c_close_button_handler); bool print_connect_line = false; bool start_simulation = false; bool simulation_pause = true; shared_ptr<c_cjddev> connect_node; std::chrono::steady_clock::time_point last_click_time = std::chrono::steady_clock::now() - std::chrono::milliseconds(1000); m_gui = make_shared<c_gui>(); // prepare drawtarget surface to draw to switch (m_drawtarget_type) { case e_drawtarget_type_allegro: m_drawtarget = make_shared<c_drawtarget_allegro>(m_frame); break; case e_drawtarget_type_opengl: m_drawtarget = make_shared<c_drawtarget_opengl>(); break; default: _erro("Warning: unsupported drawtarget"); } m_drawtarget->m_gui = m_gui; // bool allegro_keys_any_was=false; // is any key pressed right now (for key press/release) long loop_miliseconds = 0; long unsigned int frame_checkpoint = 0; /// needed for speed control (without world_draw manipulate in spacetime!) _UNUSED(frame_checkpoint); bool use_input_allegro = true; // always for now. input from Allegro bool use_draw_allegro = m_drawtarget_type == e_drawtarget_type_allegro; // draw in allegro bool use_draw_opengl = m_drawtarget_type == e_drawtarget_type_opengl; // draw in opengl _note("Entering main simulation loop"); // The main drawing is done inside this loop. ///@see rendering.txt/[[drawing_main]] float view_angle = 0.0; //float camera_offset = 1.0; float zoom = 1.0; float camera_step_z=-11.0; // === main loop === while (!m_goodbye && !close_button_pressed) { auto start_time = std::chrono::high_resolution_clock::now(); // --- process the keyboard/inputs --- if (use_input_allegro) { // TODO move this code here, but leave the variables in higher scope } poll_keyboard(); auto allegro_keys = key; auto allegro_shifts = key_shifts; // bool allegro_keys_any_is=false; // for (size_t i=0; i<sizeof(allegro_keys)/sizeof(allegro_keys[0]); ++i) allegro_keys_any_is=true; // the direct raw position const int allegro_mouse_x = mouse_x; const int allegro_mouse_y = mouse_y; const int allegro_mouse_b = mouse_b; // buttons // the position in display port GUI const int gui_mouse_x = allegro_mouse_x; const int gui_mouse_y = allegro_mouse_y; const int gui_mouse_b = allegro_mouse_b; // buttons // the position in the world coordinates const int gui_cursor_x = m_gui->view_x_rev(gui_mouse_x); const int gui_cursor_y = m_gui->view_y_rev(gui_mouse_y); const int gui_cursor_z = 0; // m_gui->view_z_rev(gui_mouse_z); _UNUSED(gui_mouse_b); _UNUSED(gui_cursor_x); _UNUSED(gui_cursor_y); _UNUSED(gui_cursor_z); //_dbg1("mouse_x mouse_y: " << gui_mouse_x << " " << gui_mouse_y); int allegro_char = 0; if (keypressed()) { allegro_char = readkey(); } // end of input // draw background of frame if (use_draw_allegro) { clear_to_color(m_frame, makecol(0, 128, 0)); blit(c_bitmaps::get_instance().m_background, m_frame, 0, 0, viewport_x, viewport_y, c_bitmaps::get_instance().m_background->w, c_bitmaps::get_instance().m_background->h); } if (use_draw_opengl) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //glDisable(GL_DEPTH_TEST); // ??? Enables Depth Testing //glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //glLoadIdentity(); // glTranslatef(m_gui->camera_x, m_gui->camera_y,camera_offset); // minimum and maximum value for zoom in/out and rotate the scene // if (camera_offset >= 10.0) camera_offset = 10.0; // if (camera_offset <= 0.5) camera_offset = 0.5; if (view_angle >= 70) view_angle = 70; if(view_angle <= 0) view_angle = 0; if( zoom <= 0.1 ) zoom = 0.1; //because of glFrustum -> when left=right, or bottom=top there's error GL_INVALID_VALUE, so we can't multiply e.g left,right by 0 glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0*zoom, 1.0*zoom, -1.0*zoom, 1.0*zoom, 1.0,60.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glTranslatef(0.0f,0.0f,-11.0); glTranslatef(0.0f,0.0f,camera_step_z); glRotatef(-view_angle, 1,0,0); glScalef(10,10,10); // drawing backgound glPushMatrix(); //glScalef(1,1,1); glBindTexture(GL_TEXTURE_2D,c_bitmaps::get_instance().m_background_opengl); glEnable(GL_BLEND); //float q=1.0/zoom; float q=1.0; glBegin(GL_QUADS); glTexCoord2f(0,q); glVertex3f(-1.0f,1.0f, 0.0f); glTexCoord2f(q,q); glVertex3f(1.0f,1.0f, 0.0f); glTexCoord2f(q,0); glVertex3f(1.0f,-1.0f,0.0f); glTexCoord2f(0,0); glVertex3f(-1.0f,-1.0f,0.0f); glEnd(); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); // texture glPopMatrix(); } // clear additional things if (use_draw_allegro) { clear_to_color(smallWindow, makecol(128, 128, 128)); } // main controll keys if (allegro_keys[KEY_ESC]) { _note("User exits the simulation from user interface"); m_goodbye = true; } if ((allegro_char & 0xff) == 'n' && !start_simulation) { std::cout << "ADD " << std::endl; _warn("THIS CODE IS NOT IMPLEMENTED NOW"); /* m_world->m_objects.push_back( make_shared<c_cjddev>( cjddev_detail_random_name(), // gui_mouse_x, gui_mouse_y, gui_cursor_x, gui_cursor_y, cjddev_detail_random_addr())); */ } if(allegro_keys[KEY_F1]){ //auto ptr = get_move_object(gui_mouse_x,gui_mouse_y); // TODO -in allegro? -not entire screen? /* try{ if(ptr != NULL){ int col_num =0; textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1); if(c_cjddev* tmp = dynamic_cast<c_cjddev *>(ptr.get()) ){ char* addr =(char *) malloc(45); sprintf(addr,"address: %ld",tmp->get_address()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); sprintf(addr,"neighbors: %d",(int)tmp->get_neighbors().size()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); sprintf(addr,"waitng: %d",(int)tmp->num_of_wating()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); // textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1);{ free (addr); } if (use_draw_allegro) { // draw the information window blit (smallWindow,m_frame,0,0,m_frame->w-200,m_frame->h-200,screen->w/8, screen->h/4); } } } catch(...) {} */ // std::cout<<ptr->get_name().c_str()<<std::endl; } if(allegro_keys[KEY_F2]){ // BITMAP* screen = gui_get_screen(); int m_x =0; int m_y =0; static unsigned int num =0; if(num>=m_world->m_objects.size()){ num=0; } try{ // auto obj = m_world->m_objects.at(0); // m_x = m_world->m_objects.at(num)->get_x() - (screen->w/2); // m_y = m_world->m_objects.at(num)->get_y() - (screen->h/2); m_x = m_world->m_objects.at(num)->get_x()*m_gui->camera_zoom - (allegro_mouse_x); m_y = m_world->m_objects.at(num)->get_y()*m_gui->camera_zoom - (allegro_mouse_y); // std::cout<< screen->w<<" "<<screen->h<<" "<<screen->x_ofs<<" "<<screen->y_ofs<<std::endl; m_gui->camera_x = m_x ; m_gui->camera_y = m_y; std::this_thread::sleep_for(std::chrono::milliseconds(100)); num++; }catch(...) { } } // animation & tick if (m_frame_number % g_max_anim_frame == 0 && !simulation_pause) { frame_checkpoint = m_frame_number; m_world->tick(); // <=== } // === main user interface === // the mode typedef enum { e_mode_node, e_mode_camera } t_mode; t_mode mode; mode = e_mode_node; // by default we will move/edit etc the node (or entityt) if (allegro_shifts & KB_SHIFT_FLAG) mode = e_mode_camera; // with key SHIFT we move camera instea // mode: camera movement etc if (mode == e_mode_camera) { if (allegro_keys[KEY_LEFT]) m_gui->camera_x -= 10; if (allegro_keys[KEY_RIGHT]) m_gui->camera_x += 10; if (allegro_keys[KEY_UP]) m_gui->camera_y -= 10; if (allegro_keys[KEY_DOWN]) m_gui->camera_y += 10; const double zoom_speed = 1.1; if (allegro_keys[KEY_PGUP]) m_gui->camera_zoom *= zoom_speed; if (allegro_keys[KEY_PGDN]) m_gui->camera_zoom /= zoom_speed; } // rotate and zoom in/out the scene if(allegro_keys[KEY_Z]) { //camera_offset+=0.1; zoom+=0.1; _dbg1("zoom: " << zoom); } if(allegro_keys[KEY_X]) { //camera_offset-=0.1; zoom-=0.1; _dbg1("zoom: " << zoom); } if(allegro_keys[KEY_C]) { view_angle+=1.0; //farVal+=10; _dbg1("view_angle: " << view_angle); } if(allegro_keys[KEY_V]) { view_angle-=1.0; _dbg1("view_angle: " << view_angle); } if(allegro_keys[KEY_Q]) { camera_step_z+=0.1; } if(allegro_keys[KEY_W]) { camera_step_z -= 0.1; if(camera_step_z <= -11.0) camera_step_z=-11.0; } // === text debug on screen === string mouse_pos_str = std::to_string(gui_mouse_x) + " " + std::to_string(gui_mouse_y); string fps_str = "fps ???"; if (loop_miliseconds != 0) { fps_str = "fps: " + std::to_string(1000 / loop_miliseconds); } const int txt_h = 12; // line height (separation between lines) int txt_x = 10, txt_y = 10; // starting position of text if (use_draw_allegro) { string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame); textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, fps_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, ("Frame nr.: " + std::to_string(m_frame_number)).c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, pck_speed_str.c_str(), 100, 10, makecol(0, 0, 255), -1); if(allegro_keys[KEY_H]) { int tex_y = 10; int lineh = 10; textout_ex(m_frame, font, "s - start", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "p - pause", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "f - send FTP", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "t - select target", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "r - select source", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "d - remove node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "n - add node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "enter/esc - exit", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "Arrows: move selected node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "SHIFT-Arrows: move the camera", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "SHIFT-PageUp/Down: zimm in/out", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "F1: info about node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "F2: next node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); } else{ textout_ex(m_frame, font, "h - help", 1140, 30, makecol(0, 0, 255), -1); } } if (use_draw_opengl) { // TODO @opengl //textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); float offset = 0.03; float tex_y = 0.9; float tex_x = 0.7; string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame); glColor4f(0.0,0.0,1.0,0.0); //glScalef(0.2f,0.2f,0.2f); //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y, 0.0, mouse_pos_str.c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, fps_str.c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, ("Frame nr.: " + std::to_string(m_frame_number)).c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.7, 0.97, 0.0, pck_speed_str.c_str()); glDisable(GL_BLEND); glPopMatrix(); if(allegro_keys[KEY_H]) { _dbg1("KEY_H - opengl"); //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"s - start"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"p - pause"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"f - send FTP"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"t - select target"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"r - select source"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"d - remove node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"n - add node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"enter/esc - exit"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"Arrows: move selected node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-Arrows: move the camera"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-PageUp/Down: zoom in/out"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F1: info about node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F2: next node"); glDisable(GL_BLEND); glPopMatrix(); } else { //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); //allegro_gl_printf(s_font_allegl.get(), 0.8, 0.9, 0.0,0xFF0000,"h - help"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"h - help"); //glBlendFunc(GL_ONE, GL_ZERO); glDisable(GL_BLEND); glPopMatrix(); } } //_dbg3("m_world->m_objects.size(): " << m_world->m_objects.size()); //_dbg3("get_move_object ret: " << get_move_object(gui_mouse_x, gui_mouse_y)); int move_object_index = get_move_object(gui_mouse_x, gui_mouse_y); ///< -1 if 'empty' if (move_object_index != -1) { // working with selected object m_gui->m_selected_object = m_world->m_objects.begin(); std::advance(m_gui->m_selected_object, move_object_index); auto selected_object = m_gui->m_selected_object; (*selected_object)->m_selected = true; c_entity *selected_object_raw = dynamic_cast<c_entity *>((*selected_object).get()); c_osi2_switch *selected_switch = dynamic_cast<c_osi2_switch *>((*selected_object).get()); // selected_switch->send_hello_to_neighbors(); // TODO //shared_ptr<c_cjddev> selected_device = std::dynamic_pointer_cast<c_cjddev>(selected_object); if (selected_object != m_world->m_objects.end()) { // editing the selected object // TODO: add connect /*if (gui_mouse_b == 1 && !print_connect_line) { print_connect_line = true; connect_node = std::dynamic_pointer_cast<c_cjddev>(selected_object); last_click_time = std::chrono::steady_clock::now(); } if (gui_mouse_b == 1 && print_connect_line && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(500)) { // assert( connect_node && selected_object ); connect_node->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(selected_object)); (std::dynamic_pointer_cast<c_cjddev>(selected_object))->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(connect_node)); print_connect_line = false; }*/ if (mode == e_mode_node) { // working with selected object - moving if (!print_connect_line) { int speed = 5; if (allegro_keys[KEY_LEFT]) selected_object_raw->m_x += -speed; if (allegro_keys[KEY_RIGHT]) selected_object_raw->m_x += speed; if (allegro_keys[KEY_DOWN]) selected_object_raw->m_y += speed; if (allegro_keys[KEY_UP]) selected_object_raw->m_y += -speed; } } // moving selected object } /* if ((allegro_char & 0xff) == 's' && !start_simulation) { if (!m_gui->m_source || !m_gui->m_target) { std::cout << "please choose target and source node\n"; } else { m_gui->m_source->buy_net(m_gui->m_target->get_address()); start_simulation = true; simulation_pause = false; } } if ((allegro_char & 0xff) == 'd' && selected_device && !start_simulation) { for (shared_ptr<c_cjddev> &it : selected_device->get_neighbors()) { selected_device->remove_neighbor(it); it->remove_neighbor(selected_device); } for (auto it = m_world->m_objects.begin(); it != m_world->m_objects.end(); ++it) { if (it->get() == selected_device.get()) { m_world->m_objects.erase(it); break; } } } if ((allegro_char & 0xff) == 't' && selected_device && !start_simulation) { m_gui->m_target = selected_device; } if ((allegro_char & 0xff) == 'r' && selected_device && !start_simulation) { m_gui->m_source = selected_device; } if ((allegro_char & 0xff) == 'f') { if (!m_gui->m_source || !m_gui->m_target) std::cout << "please choose target and source node\n"; else { m_gui->m_source->send_ftp_packet(m_gui->m_target->get_address(), "FTP data"); last_click_time = std::chrono::steady_clock::now(); } } */ // === animation clock controll === if ((allegro_char & 0xff) == 'p') { simulation_pause = !simulation_pause; last_click_time = std::chrono::steady_clock::now(); } if (allegro_keys[KEY_MINUS_PAD] && g_max_anim_frame < 400 && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) { //std::cout << m_frame_number-frame_checkpoint << " - " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame << std::endl; g_max_anim_frame += 1; last_click_time = std::chrono::steady_clock::now(); } if (allegro_keys[KEY_PLUS_PAD] && g_max_anim_frame > 10 && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) { //std::cout << m_frame_number-frame_checkpoint << " + " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame << std::endl; g_max_anim_frame -= 1; last_click_time = std::chrono::steady_clock::now(); } } // === animation clock operations === m_world->draw(*m_drawtarget.get()); // <===== DRAW THE WORLD /* if ((m_frame_number - frame_checkpoint) < g_max_anim_frame) { m_world->draw(*m_drawtarget.get(), (m_frame_number - frame_checkpoint) % g_max_anim_frame); // <== } else { m_world->draw(*m_drawtarget.get(), g_max_anim_frame); } */ if (print_connect_line) { // the line the creates new connections if (use_draw_allegro) { line(m_frame, connect_node->m_x, connect_node->m_y, allegro_mouse_x, allegro_mouse_y, makecol(0, 255, 255)); } // TODO @opengl if (use_draw_opengl) { glColor3f(0.0f,1.0f,1.0f); glLineWidth(1.0); glScalef(1.0f,1.0f,1.0f); const int vx = m_gui->view_x(connect_node->m_x), vy = m_gui->view_y(connect_node->m_y); // position in viewport - because camera position //float start_line_x = ((connect_node->m_x)-0.5*SCREEN_W)/(0.5*SCREEN_W); //float start_line_y = -((connect_node->m_y)-0.5*SCREEN_H)/(0.5*SCREEN_H); float start_line_x = (vx-0.5*SCREEN_W)/(0.5*SCREEN_W); float start_line_y = -(vy-0.5*SCREEN_H)/(0.5*SCREEN_H); float end_line_x = (allegro_mouse_x-0.5*SCREEN_W)/(0.5*SCREEN_W); float end_line_y = -(allegro_mouse_y-0.5*SCREEN_H)/(0.5*SCREEN_H); //_dbg1("connect_node: " << connect_node->m_x << " " << connect_node->m_y); //_dbg1("allegro_mouse: " << allegro_mouse_x << " " << allegro_mouse_y); //_dbg1("start_line: " << start_line_x << " " << start_line_y); //_dbg1("end_line: " << end_line_x << " " << end_line_y); //glLoadIdentity(); glPushMatrix(); glBegin(GL_LINES); glVertex3f(start_line_x,start_line_y,0.0f); glVertex3f(end_line_x,end_line_y,0.0f); glEnd(); glPopMatrix(); } } if (allegro_mouse_b == 2) { // end/stop the line that creates new connections print_connect_line = false; } { auto x = allegro_mouse_x, y = allegro_mouse_y; int r = 5, rr = 4; if (use_draw_allegro) { line(m_frame, x - rr, y, x + rr, y, makecol(0, 0, 0)); line(m_frame, x, y - rr, x, y + rr, makecol(0, 0, 0)); circle(m_frame, x, y, r, makecol(255, 255, 255)); } // TODO @opengl if(use_draw_opengl) { float opengl_mouse_x = (x-SCREEN_W*0.5)/(0.5*SCREEN_W); float opengl_mouse_y = -(y-SCREEN_H*0.5)/(0.5*SCREEN_H); float cursor_size=0.01; //_dbg1("mouse_x mouse_y: " << mouse_x << " " << mouse_y); //_dbg1("screenW screenH: " << SCREEN_W << " " << SCREEN_H); //glLoadIdentity(); //glScalef(1/camera_offset, 1/camera_offset, 1.0); //glScalef(1.0*zoom, 1.0*zoom, 1.0*zoom); glPushMatrix(); glScalef(1.0f,1.0f,1.0f); glTranslatef(opengl_mouse_x,opengl_mouse_y,0.0f); //glTranslatef(m_gui->view_x_rev(mouse_x),m_gui->view_y_rev(mouse_y),0.0f); glColor3f(0.0, 0.0, 0.0); // draw cursor glBegin(GL_LINES); glVertex2f(-1.0f*cursor_size,0.0f); glVertex2f(1.0f*cursor_size,0.0f); glVertex2f(0.0f,-1.0f*cursor_size); glVertex2f(0.0f,1.0f*cursor_size); glEnd(); glPopMatrix(); } } // === show frame === if (use_draw_allegro) { //_dbg1("Allegro: frame done. fps = " << fps_str); scare_mouse(); blit(m_frame, m_screen, 0, 0, 0, 0, m_frame->w, m_frame->h); unscare_mouse(); if (!simulation_pause) { ++m_frame_number; } } if (use_draw_opengl) { //_dbg1("OpenGL: frame flip. fps = " << fps_str); allegro_gl_flip(); } for (auto &object : m_world->m_objects) { object->m_selected = false; } // std::this_thread::sleep_for(std::chrono::milliseconds(10)); auto stop_time = std::chrono::high_resolution_clock::now(); auto diff = stop_time - start_time; loop_miliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count(); } std::ofstream out_file("../layout/current/out.map.txt"); out_file << *m_world << std::endl; }
void OpenLayerInput::pollKeyInput() { int unicode, scancode; if (keyboard_needs_poll()) { poll_keyboard(); } while (keypressed()) { unicode = ureadkey(&scancode); Key keyObj = convertToKey(scancode, unicode); KeyInput keyInput(keyObj, KeyInput::Pressed); keyInput.setNumericPad(isNumericPad(scancode)); keyInput.setShiftPressed(key_shifts & KB_SHIFT_FLAG); keyInput.setAltPressed(key_shifts & KB_ALT_FLAG); keyInput.setControlPressed(key_shifts & KB_CTRL_FLAG); #ifdef KB_COMMAND_FLAG keyInput.setMetaPressed(key_shifts & (KB_COMMAND_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG)); #else keyInput.setMetaPressed(key_shifts & (KB_LWIN_FLAG | KB_RWIN_FLAG)); #endif mKeyQueue.push(keyInput); mPressedKeys[scancode] = keyInput; } if (key[KEY_ALT] && mPressedKeys.find(KEY_ALT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALT] = keyInput; } if (key[KEY_ALTGR] && mPressedKeys.find(KEY_ALTGR) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_ALTGR, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_ALTGR] = keyInput; } if (key[KEY_LSHIFT] && mPressedKeys.find(KEY_LSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LSHIFT] = keyInput; } if (key[KEY_RSHIFT] && mPressedKeys.find(KEY_RSHIFT) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RSHIFT, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RSHIFT] = keyInput; } if (key[KEY_LCONTROL] && mPressedKeys.find(KEY_LCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_LCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_LCONTROL] = keyInput; } if (key[KEY_RCONTROL] && mPressedKeys.find(KEY_RCONTROL) == mPressedKeys.end()) { KeyInput keyInput(convertToKey(KEY_RCONTROL, 0), KeyInput::Pressed); mKeyQueue.push(keyInput); mPressedKeys[KEY_RCONTROL] = keyInput; } // Check for released keys std::map<int, KeyInput>::iterator iter, tempIter; for (iter = mPressedKeys.begin(); iter != mPressedKeys.end(); ) { if (!key[iter->first]) { KeyInput keyInput(iter->second.getKey(), KeyInput::Released); keyInput.setNumericPad(iter->second.isNumericPad()); keyInput.setShiftPressed(iter->second.isShiftPressed()); keyInput.setAltPressed(iter->second.isAltPressed()); keyInput.setControlPressed(iter->second.isControlPressed()); mKeyQueue.push(keyInput); tempIter = iter; iter++; mPressedKeys.erase(tempIter); } else { iter++; } } }
static void PollEvent() { poll_mouse(); bool mouse_action = false; /* Mouse buttons */ static int prev_button_state; if (prev_button_state != mouse_b) { uint diff = prev_button_state ^ mouse_b; while (diff != 0) { uint button = FindFirstBit(diff); ClrBit(diff, button); if (HasBit(mouse_b, button)) { /* Pressed mouse button */ if (_rightclick_emulate && (key_shifts & KB_CTRL_FLAG)) { button = RIGHT_BUTTON; ClrBit(diff, RIGHT_BUTTON); } switch (button) { case LEFT_BUTTON: _left_button_down = true; break; case RIGHT_BUTTON: _right_button_down = true; _right_button_clicked = true; break; default: /* ignore rest */ break; } } else { /* Released mouse button */ if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; _left_button_clicked = false; } else if (button == LEFT_BUTTON) { _left_button_down = false; _left_button_clicked = false; } else if (button == RIGHT_BUTTON) { _right_button_down = false; } } } prev_button_state = mouse_b; mouse_action = true; } /* Mouse movement */ int dx = mouse_x - _cursor.pos.x; int dy = mouse_y - _cursor.pos.y; if (dx != 0 || dy != 0) { if (_cursor.fix_at) { _cursor.delta.x = dx; _cursor.delta.y = dy; position_mouse(_cursor.pos.x, _cursor.pos.y); } else { _cursor.delta.x = dx; _cursor.delta.y = dy; _cursor.pos.x = mouse_x; _cursor.pos.y = mouse_y; _cursor.dirty = true; } mouse_action = true; } static int prev_mouse_z = 0; if (prev_mouse_z != mouse_z) { _cursor.wheel = (prev_mouse_z - mouse_z) < 0 ? -1 : 1; prev_mouse_z = mouse_z; mouse_action = true; } if (mouse_action) HandleMouseEvents(); poll_keyboard(); if ((key_shifts & KB_ALT_FLAG) && (key[KEY_ENTER] || key[KEY_F])) { ToggleFullScreen(!_fullscreen); } else if (keypressed()) { WChar character; uint keycode = ConvertAllegroKeyIntoMy(&character); HandleKeypress(keycode, character); } }
static void test_key_map (void) { int i; static int key_was_pressed[KEY_MAX + 1]; static int key_is_pressed[KEY_MAX + 1]; static char *welcome[] = { "Key that is pressed now is marked with red", "Key that was pressed is marked with yellow", "Press mouse button or Escape to exit test", 0 }; text_mode (-1); /* Clear screen and output prompt. */ clear_to_color (screen, white); for (i = 0; welcome[i] != 0; i++) textout (screen, font, welcome[i], 8, i * 8 + 8, black); clear_to_color (screen, white); for (i = 0; keymap[i].string != 0; i++) textout (screen, font, keymap[i].string, 32 + (i % 4) * 160, 40 + (i / 4) * 14, black); do { poll_keyboard (); poll_mouse (); } while ((key[KEY_ESC]) || (mouse_b)); do { poll_keyboard (); poll_mouse (); for (i = 0; i < KEY_MAX; i++) { if (key[i]) key_was_pressed[i] = key_is_pressed[i] = 1; else key_is_pressed[i] = 0; } for (i = 0; keymap[i].string != 0; i++) { int x = 16 + (i % 4) * 160; int y = 40 + (i / 4) * 14; int k = keymap[i].key; if (key_is_pressed[k]) rectfill (screen, x, y, x + 7, y + 7, red); else if (key_was_pressed[k]) rectfill (screen, x, y, x + 7, y + 7, yellow); else rectfill (screen, x, y, x + 7, y + 7, white); } } while ((!key[KEY_ESC]) && (!mouse_b)); do { poll_keyboard (); poll_mouse (); } while ((key[KEY_ESC]) || (mouse_b)); clear_keybuf (); }
int main (int argc, char ** argv) { init_sprite_png(0, "/usr/share/logo_login.png"); init_shmemfonts(); while (1) { syscall_print("Setup...\n"); setup_windowing(); int width = wins_globals->server_width; int height = wins_globals->server_height; win_width = width; win_height = height; /* Do something with a window */ window_t * wina = window_create(0,0, width, height); assert(wina); window_reorder (wina, 0); /* Disables movement */ ctx = init_graphics_window_double_buffer(wina); for (int i = 0; i < LOGO_FINAL_OFFSET; ++i) { draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - i); flip(ctx); } size_t buf_size = wina->width * wina->height * sizeof(uint32_t); char * buf = malloc(buf_size); uint32_t i = 0; uint32_t black = rgb(0,0,0); uint32_t white = rgb(255,255,255); uint32_t red = rgb(240, 20, 20); int x_offset = 65; int y_offset = 64; int fuzz = 3; char username[INPUT_SIZE] = {0}; char password[INPUT_SIZE] = {0}; char hostname[512]; { char _hostname[256]; syscall_gethostname(_hostname); struct tm * timeinfo; struct timeval now; syscall_gettimeofday(&now, NULL); //time(NULL); timeinfo = localtime((time_t *)&now.tv_sec); char _date[256]; strftime(_date, 256, "%a %B %d %Y", timeinfo); sprintf(hostname, "%s // %s", _hostname, _date); } char kernel_v[512]; { struct utsname u; uname(&u); /* UTF-8 Strings FTW! */ uint8_t * os_name_ = "PonyOS"; uint32_t l = snprintf(kernel_v, 512, "%s %s", os_name_, u.release); } uid = 0; #define BOX_WIDTH 272 #define BOX_HEIGHT 104 #define USERNAME_BOX 1 #define PASSWORD_BOX 2 #define EXTRA_TEXT_OFFSET 12 #define TEXTBOX_INTERIOR_LEFT 4 #define LEFT_OFFSET 80 int box_x = center_x(BOX_WIDTH); int box_y = center_y(0) + 8; int focus = USERNAME_BOX; set_font_size(11); int username_label_left = LEFT_OFFSET - 2 - draw_string_width("Username:"******"Password:"******""); for (int i = 0; i < strlen(password); ++i) { strcat(password_circles, "●"); } /* Redraw the background */ draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); draw_string(ctx, hostname_label_left, height - 12, white, hostname); draw_string(ctx, kernel_v_label_left, height - 12, white, kernel_v); /* Draw backdrops */ draw_box(ctx, box_x, box_y, BOX_WIDTH, BOX_HEIGHT, rgb(180,124,205)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(255,255,255)); draw_box(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(255,255,255)); /* Draw labels */ draw_string(ctx, box_x + username_label_left, box_y + 32 + EXTRA_TEXT_OFFSET, white, "Username:"******"Password:"******"Incorrect username or password."; draw_string(ctx, box_x + (BOX_WIDTH - draw_string_width(error_message)) / 2, box_y + 8 + EXTRA_TEXT_OFFSET, red, error_message); } if (focus == USERNAME_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 32, 168, 16, rgb(229, 68, 138)); } else if (focus == PASSWORD_BOX) { draw_box_border(ctx, box_x + LEFT_OFFSET, box_y + 56, 168, 16, rgb(229, 68, 138)); } flip(ctx); w_keyboard_t * kbd = NULL; do { kbd = poll_keyboard(); } while (!kbd); if (kbd->key == '\n') { if (focus == USERNAME_BOX) { free(kbd); focus = PASSWORD_BOX; continue; } else if (focus == PASSWORD_BOX) { free(kbd); break; } } if (kbd->key == '\t') { if (focus == USERNAME_BOX) { focus = PASSWORD_BOX; } else if (focus == PASSWORD_BOX) { focus = USERNAME_BOX; } free(kbd); continue; } if (focus == USERNAME_BOX) { buffer_put(username, kbd->key); } else if (focus == PASSWORD_BOX) { buffer_put(password, kbd->key); } free(kbd); } uid = checkUserPass(username, password); if (uid >= 0) { break; } show_error = 1; } draw_fill(ctx, rgb(39,55,113)); draw_sprite(ctx, sprites[0], center_x(sprites[0]->width), center_y(sprites[0]->height) - LOGO_FINAL_OFFSET); flip(ctx); teardown_windowing(); pid_t _session_pid = fork(); if (!_session_pid) { setenv("PATH", "/usr/bin:/bin", 0); syscall_setuid(uid); char * args[] = {"/bin/gsession", NULL}; execvp(args[0], args); } free(buf); free(ctx->backbuffer); free(ctx); syscall_wait(_session_pid); } return 0; }
static void game_loop() { BITMAP *buffer = create_bitmap(GFX_W, GFX_H); // initialize the player input the_input = new Input(); // start the game the_game = new Game(); the_game->start(); while (continuing) { while (beats > 0 && continuing) { // update game logic continuing = the_game->update(); --beats; } the_game->draw(buffer); // flip to screen (double buffering technique) vsync(); stretch_blit(buffer, screen, 0, 0, GFX_W, GFX_H, 0, 0, SCREEN_W, SCREEN_H); // switch graphics mode if (key[KEY_F11] || gfx_switched) { int old_beats = beats; if (!gfx_switched) { gfx_widescreen = !gfx_widescreen; } else { gfx_switched = false; } switch_widescreen(); destroy_bitmap(buffer); buffer = create_bitmap(GFX_W, GFX_H); do { poll_keyboard(); } while (key[KEY_F11]); beats = old_beats; } // screen shot if (key[KEY_F12]) { int old_beats = beats; make_screenshot(buffer); do { poll_keyboard(); } while (key[KEY_F12]); beats = old_beats; } } // destroy the game delete the_game; the_game = NULL; delete the_input; destroy_bitmap(buffer); }
static void setup_all_keys (void) { int i, y, ymin, ymax; static char *welcome[] = { "Press a key to map to this scancode", "Press mouse button for next scancode", 0 }; text_mode (-1); /* Clear screen and output prompt. */ clear_to_color (screen, white); for (i = 0; welcome[i] != 0; i++) textout (screen, font, welcome[i], 8, i * 8 + 8, black); ymin = i * 8 + 16; ymax = ymin + 8 * 8; y = ymin - 8; for (i = 0; keymap[i].string != 0; i++) { y += 8; if (y >= ymax) { blit (screen, screen, 8, ymin + 8, 8, ymin, 200, ymax - ymin); y -= 8; } textprintf (screen, font, 8, y, red, "scancode: %s", keymap[i].string); /* Wait while any mouse button is pressed. */ do { poll_mouse (); } while (mouse_b); /* Wait for new key press. */ new_keycode = -1; waiting_for_key = 1; do { poll_keyboard (); poll_mouse (); if (mouse_b) waiting_for_key = 0; } while (waiting_for_key); /* Save keycode to scancode mapping. */ if ((new_keycode >= 0) && (new_keycode < 256)) { _xwin.keycode_to_scancode[new_keycode] = keymap[i].scancode; keycode_to_scancode[new_keycode] = keymap[i].scancode; } } do { poll_keyboard (); poll_mouse (); } while ((key[KEY_MUHENKAN]) || (mouse_b)); clear_keybuf (); }
int commandes_clavier()//la fonction sprintf tue l acces clavier { if ( keypressed()) { int chi = readkey(); scan_ascii_is=(chi & 0xff);//prend pas en compte touches fonctions scan_allegro_key_is=(chi >> 8);//prend en compte tout le monde mais à redistribuer fr et anglais switch (chi >> 8) { case KEY_ESC://nettoyage chaine de caractere et deselection totale reset_indexs_confirmation(); reset_index_actions(); key_unselect_ch(); if(window_focus_id==W_PLOT ) { if(index_menus_lighting_plot==1) unselect_all_shapes(); else if( index_menus_lighting_plot==2 || index_menus_lighting_plot==4) {reset_symbols_selected(view_plot_calc_number_is);} } else if(window_focus_id==W_ASKCONFIRM) { substract_a_window(W_ASKCONFIRM); substract_a_window(previous_window_focus_id); mouse_released=1; window_focus_id=previous_window_focus_id; add_a_window(window_focus_id); } sprintf(string_key_id,list_keyname[9]); break; ///////////////////////PAGE UP DOWN POUR FENETRES ///////////////////////////// case KEY_PGUP: sprintf(string_key_id,list_keyname[0]); key_switch_window_up(); break; case KEY_PGDN: sprintf(string_key_id,list_keyname[0]); key_switch_window_down(); break; //////////////////SPECIAL KEYS //////////////////////////////////////////////// case KEY_TILDE://carré if(window_focus_id==W_PLOT) {index_move_plot_view_port=toggle(index_move_plot_view_port);} break; case KEY_F1://dock mode if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { reset_indexs_confirmation(); index_ask_confirm=1; index_do_overrecord_mem=1; clear_keybuf(); } else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { int mem_to_rec=(int)(atof(numeric)*10); reset_indexs_confirmation(); index_ask_confirm=1; index_do_create_mem=1; } else { index_do_report=0; index_do_modify=0; index_main_clear=0; index_do_dock=toggle(index_do_dock); switch (window_focus_id) { case W_CHASERS: index_affect_chaser_to_dock=index_do_dock; break; case W_GRID: for(int i=0;i<4;i++) { if(index_show_grid_player[i]==1) { gridplayer_to_affect_is=i; break; } } break; case W_MOVER: index_affect_to_dock_mover=index_do_dock; break; case W_DRAW: index_affect_draw_to_dock=index_do_dock; break; case W_ECHO: index_affect_echo_to_dock=index_do_dock; break; case W_TIME: index_affect_time=index_do_dock; break; case W_TRACKINGVIDEO: index_affect_video_tracking_to_dock=index_do_dock; break; case W_TRICHROMY: index_affect_color_to_dock=index_do_dock; break; case W_AUDIO: index_affect_audio_to_dock=index_do_dock; player_to_affect_to_dock=0; audio_type_for_dock_affectation_is=0; break; case W_CFGMENU: if(config_page_is==1) { index_affect_dmxin=index_do_dock; } else if(config_page_is==3) {index_do_affect_net_to_dock=index_do_dock; } break; default: break; } } break; case KEY_F2: index_do_dock=0; index_do_report=0; index_main_clear=0; index_do_modify=toggle(index_do_modify);; break; case KEY_F3: if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { index_do_dock=0; index_do_modify=0; index_main_clear=0; index_do_report=1; reset_indexs_confirmation(); index_ask_confirm=1; index_do_overecord_mem_plus_faders=1; } else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) //creation mémoires en mode merge Faders / seq { index_do_dock=0; index_do_modify=0; index_main_clear=0; index_do_report=1; int mem_to_rec=(int)(atof(numeric)*10); reset_indexs_confirmation(); index_ask_confirm=1; index_do_create_mem_plus_faders=1; } else { index_do_dock=0; index_do_modify=0; index_main_clear=0; index_do_report=toggle(index_do_report); } break; case KEY_F4: index_do_dock=0; index_do_modify=0; index_do_report=0; index_main_clear=toggle(index_main_clear); break; case KEY_F5: index_type=toggle(index_type); sprintf(numeric,"");numeric_postext=0; break; case KEY_F6: if(index_time==0){add_a_window(W_TIME); } else { substract_a_window(W_TIME); } break; case KEY_F7: if(index_trichro_window==0){add_a_window(W_TRICHROMY);} else { substract_a_window(W_TRICHROMY); } break; case KEY_F8: if(index_video_window==0){ add_a_window(W_TRACKINGVIDEO); } else{ substract_a_window(W_TRACKINGVIDEO);} break; case KEY_F9: if(index_window_sequentiel==0){;add_a_window(W_SEQUENCIEL);} else {substract_a_window(W_SEQUENCIEL);} break; case KEY_F10: if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) //CONFIG { if(index_show_minifaders==0){add_a_window(W_MINIFADERS);} else {substract_a_window(W_MINIFADERS);} } else { if(index_show_faders==0){add_a_window(W_FADERS);} else {substract_a_window(W_FADERS);} } break; case KEY_F11: if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) //CONFIG { if(index_show_config_window==0){add_a_window(W_CFGMENU);} else {substract_a_window(W_CFGMENU);} } else if (key_shifts & KB_CTRL_FLAG || index_false_control==1 ) {index_blind=toggle(index_blind); } else { if(index_show_banger_window==0) {add_a_window(W_BANGER);mouse_level_for_event=mouse_z;mouse_level_for_banger=mouse_z;} else {substract_a_window(W_BANGER);} } break; case KEY_F12://black out if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { index_ask_confirm=1;index_do_quit_with_save=1; } else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { for (int i=0;i<12;i++) { specify_who_to_save_load[i]=0;} reset_save_load_report_string(); index_ask_confirm=1;index_do_quit_without_save=1; } else { if(index_blind==0) { for (int rs=0;rs<513;rs++) {bufferSaisie[rs]=0;Selected_Channel[rs]=0; } sprintf(string_Last_Order,">> Black Out done for On Stage channels"); } else if(index_blind==1) { for (int rs=0;rs<513;rs++) {bufferBlind[rs]=0; Selected_Channel[rs]=0; } sprintf(string_Last_Order,">> Black Out done for On Blind channels"); } substract_channel_selection_to_layers_plot(); } break; case KEY_UP: key_up(); sprintf(string_key_id,list_keyname[1]); break; case KEY_DOWN: key_down(); sprintf(string_key_id,list_keyname[2]); break; case KEY_ENTER : key_affectation(); sprintf(string_key_id,list_keyname[3]); break; case KEY_ENTER_PAD: key_affectation(); sprintf(string_key_id,list_keyname[4]); break; case KEY_EQUALS://+ key_add_ch(); sprintf(string_key_id,list_keyname[5]); break; case KEY_PLUS_PAD://+ num key_add_ch(); sprintf(string_key_id,list_keyname[6]); break; case KEY_MINUS://- key_minus_ch(); sprintf(string_key_id,list_keyname[7]); break; case KEY_MINUS_PAD://- num key_minus_ch(); sprintf(string_key_id,list_keyname[8]); break; case KEY_TAB: if(numeric_postext>0) { key_thruth(); sprintf(string_key_id,list_keyname[10]); } else { if(window_focus_id==W_PLOT) {index_tab_on=toggle(index_tab_on); } } break; //////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////TEXT TYPING OR FUNCTIONS CALLING////////////////////////////////////////// case KEY_SPACE: if (index_type==0) { key_go(); } else if(index_type==1) { numeric[numeric_postext]=' '; numeric_postext++; } sprintf(string_key_id,list_keyname[11]); break; case KEY_Q: //lettre a if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { if(index_show_audio_window==0){add_a_window(W_AUDIO);} else {substract_a_window(W_AUDIO);} reset_audio_indexs_to_dock(); } else { if(index_type==0) { key_presetvideo(0); } else if (index_type==1) { numeric[numeric_postext]='A'; numeric_postext++; } } sprintf(string_key_id,list_keyname[12]); break; case KEY_B: if (index_type==0) { key_roi(10); } else if (index_type==1) { numeric[numeric_postext]='B'; numeric_postext++; } sprintf(string_key_id,list_keyname[13]); break; case KEY_C: if (index_type==0) { if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { if(numeric_postext==0) { channel_copy(); } else { snap_mem_to_copy(); } } else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { if(index_window_chasers==0){add_a_window(W_CHASERS);} else {substract_a_window(W_CHASERS);} } else { key_roi(8); } } else if (index_type==1) { numeric[numeric_postext]='C'; numeric_postext++; } sprintf(string_key_id,list_keyname[14]); break; case KEY_D://dock mode on if(index_type==0) { key_roi(2); } else if(index_type==1) { numeric[numeric_postext]='D'; numeric_postext++; } sprintf(string_key_id,list_keyname[15]); break; case KEY_E: if (index_type==0) { key_presetvideo(2); } else if (index_type==1) { numeric[numeric_postext]='E'; numeric_postext++; } sprintf(string_key_id,list_keyname[16]); break; case KEY_F: if(index_type==0) { key_roi(3); } else if (index_type==1) { numeric[numeric_postext]='F'; numeric_postext++; } sprintf(string_key_id,list_keyname[17]); break; case KEY_G: if (index_type==0) { if ((key_shifts & KB_CTRL_FLAG || index_false_control==1 ) && numeric_postext>0) { //GET CHANNELS FROM A MEMORY int mem_to_take=(int)(atof(numeric)*10); if(MemoiresExistantes[mem_to_take]==1) { Get_channels_from_memory(mem_to_take); } else {sprintf(string_Last_Order,"Get Sel. channel from %d.%d: mem doesn't exist",mem_to_take/10,mem_to_take%10);} } else {key_roi(4);} } else if (index_type==1) { numeric[numeric_postext]='G'; numeric_postext++; } sprintf(string_key_id,list_keyname[18]); break; case KEY_H: if (index_type==0) { key_roi(5); } else if (index_type==1) { numeric[numeric_postext]='H'; numeric_postext++; } sprintf(string_key_id,list_keyname[19]); break; case KEY_I: if(index_type==0) //full { key_full(); } else if(index_type==1) { numeric[numeric_postext]='I'; numeric_postext++; } sprintf(string_key_id,list_keyname[20]); break; case KEY_J: if (index_type==0) { key_time_out(); } if (index_type==1) { numeric[numeric_postext]='J'; numeric_postext++; } sprintf(string_key_id,list_keyname[21]); break; case KEY_K: if (index_type==0) { key_time_in(); } else if (index_type==1) { numeric[numeric_postext]='K'; numeric_postext++; } sprintf(string_key_id,list_keyname[22]); break; case KEY_L://in + out if(index_type==0) { key_time_in_out(); } else if(index_type==1) { numeric[numeric_postext]='L'; numeric_postext++; } sprintf(string_key_id,list_keyname[23]); break; case KEY_SEMICOLON: if(index_type==0)//le M qui est point en clavier americain { if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { if(index_show_mover_window=0){add_a_window(W_MOVER);} else {substract_a_window(W_MOVER);}} } else if(index_type==1) { numeric[numeric_postext]='M'; numeric_postext++; } sprintf(string_key_id,list_keyname[38]); break; case KEY_N: if (index_type==0) { key_roi(11); } else if (index_type==1) { numeric[numeric_postext]='N'; numeric_postext++; } sprintf(string_key_id,list_keyname[24]); break; case KEY_O: if(index_type==0) { key_at_zero(); } else if (index_type==1) { numeric[numeric_postext]='O'; numeric_postext++; } sprintf(string_key_id,list_keyname[25]); break; case KEY_P: if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { if(index_patch_window==0){add_a_window(W_PATCH);} else {substract_a_window(W_PATCH);} } else{ if (index_type==0) { if(index_visual_pad==0){add_a_window(W_NUMPAD);} else {substract_a_window(W_NUMPAD);} } else if (index_type==1) { numeric[numeric_postext]='P'; numeric_postext++; } } sprintf(string_key_id,list_keyname[39]); break; case KEY_A: // lettre Q if (index_type==0) { key_roi(1); } else if (index_type==1) { numeric[numeric_postext]='Q'; numeric_postext++; } sprintf(string_key_id,list_keyname[26]); break; case KEY_R://report mode on if(index_type==0 ) { key_presetvideo(3);;//les banques de tracking cam } else if(index_type==1) { numeric[numeric_postext]='R'; numeric_postext++; } sprintf(string_key_id,list_keyname[27]); break; case KEY_S: if (index_type==0) { if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { if(index_is_saving==0){index_save_global_is=1;index_do_quick_save=1;} } else { key_roi(1); } } else if (index_type==1) { numeric[numeric_postext]='S'; numeric_postext++; } sprintf(string_key_id,list_keyname[28]); break; case KEY_T: if(index_type==0) { key_presetvideo(4);//les banques de tracking cam } else if (index_type==1) { numeric[numeric_postext]='T'; numeric_postext++; } sprintf(string_key_id,list_keyname[29]); break; case KEY_U://inverse selection if (index_type==0) { key_select_inv(); } else if (index_type==1) { numeric[numeric_postext]='U'; numeric_postext++; } sprintf(string_key_id,list_keyname[30]); break; case KEY_V: if (index_type==0) { if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { if(numeric_postext==0) { channel_paste(); } else//si chiffre de mem tapée { index_copy_mem_in=1; index_ask_confirm=1; } } else { //les aires de tracking cam key_roi(9); } } else if (index_type==1) { numeric[numeric_postext]='V'; numeric_postext++; } sprintf(string_key_id,list_keyname[31]); break; case KEY_Z://w if (index_type==0) { if(key_shifts ) { key_backward(); } else{//les aires de tracking cam key_roi(6); } } else if (index_type==1) { numeric[numeric_postext]='W'; numeric_postext++; } sprintf(string_key_id,list_keyname[32]); break; case KEY_X: if (index_type==0) { if(key_shifts) { key_forward(); } else{//les aires de tracking cam key_roi(7); } } else if (index_type==1) { numeric[numeric_postext]='X'; numeric_postext++; } sprintf(string_key_id,list_keyname[33]); break; case KEY_Y://select all if (index_type==0) { key_select_all(); } else if (index_type==1) { numeric[numeric_postext]='Y'; numeric_postext++; } sprintf(string_key_id,list_keyname[34]); break; case KEY_W://z if (key_shifts & KB_CTRL_FLAG || index_false_control==1) { //ctrl Z reload mem as recorded index_do_reload_mem=1; index_ask_confirm=1; } else if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { //ctrl Z resurrect mem as recorded mem_to_resurrect=(int)(atof(numeric)*10); index_do_resurrect_mem=1; index_ask_confirm=1; } else { if (index_type==0 ) { key_presetvideo(1);//les banques de tracking cam } else if (index_type==1) { numeric[numeric_postext]='Z'; numeric_postext++; } } sprintf(string_key_id,list_keyname[35]); break; case KEY_LEFT: key_left(); sprintf(string_key_id,list_keyname[36]); break; case KEY_RIGHT: key_right(); sprintf(string_key_id,list_keyname[37]); break; case KEY_DEL: if (key_shifts & KB_SHIFT_FLAG || index_false_shift==1) { reset_indexs_confirmation(); index_do_delete_mem=1; index_ask_confirm=1; } break; //////////////////////ENTREES NUMERIQUES COMMUNES////////////////////////////////////////// case KEY_0: numeric[numeric_postext]='0'; numeric_postext++; break; case KEY_0_PAD: numeric[numeric_postext]='0'; numeric_postext++; break; case KEY_1: numeric[numeric_postext]='1'; numeric_postext++; break; case KEY_1_PAD: numeric[numeric_postext]='1'; numeric_postext++; break; case KEY_2: numeric[numeric_postext]='2'; numeric_postext++; break; case KEY_2_PAD: numeric[numeric_postext]='2'; numeric_postext++; break; case KEY_3: numeric[numeric_postext]='3'; numeric_postext++; break; case KEY_3_PAD: numeric[numeric_postext]='3'; numeric_postext++; break; case KEY_4: numeric[numeric_postext]='4'; numeric_postext++; break; case KEY_4_PAD: numeric[numeric_postext]='4'; numeric_postext++; break; case KEY_5: numeric[numeric_postext]='5'; numeric_postext++; break; case KEY_5_PAD: numeric[numeric_postext]='5'; numeric_postext++; break; case KEY_6: numeric[numeric_postext]='6'; numeric_postext++; break; case KEY_6_PAD: numeric[numeric_postext]='6'; numeric_postext++; break; case KEY_7: numeric[numeric_postext]='7'; numeric_postext++; break; case KEY_7_PAD: numeric[numeric_postext]='7'; numeric_postext++; break; case KEY_8: numeric[numeric_postext]='8'; numeric_postext++; break; case KEY_8_PAD: numeric[numeric_postext]='8'; numeric_postext++; break; case KEY_9: numeric[numeric_postext]='9'; numeric_postext++; break; case KEY_9_PAD: numeric[numeric_postext]='9'; numeric_postext++; break; case KEY_COMMA: numeric[numeric_postext]='.'; numeric_postext++; break; case KEY_DEL_PAD: numeric[numeric_postext]='.'; numeric_postext++; break; case KEY_M: numeric[numeric_postext]='.'; numeric_postext++; break; case KEY_BACKSPACE: numeric[numeric_postext]=' '; numeric_postext--; numeric[numeric_postext]=' '; if (numeric_postext<0) {numeric_postext=0;} break; ////////////////////MISE EN MEMOIRES DES FENETRES ET TOGGLE///////////////////// case KEY_PRTSCR: key_printscreen(); break; default: break; } for(int u=0;u<nbre_key_persos;u++) { //keys persos if( (int)(chi & 0xff)==mapping_temporaire[u]) { switch(u) { case 0://AT level key_affectation(); sprintf(string_key_id,"At Level");//max 16 char break; case 1://CH+ key_add_ch(); sprintf(string_key_id,"Ch +");//max 16 char break; case 2://CH- key_minus_ch(); sprintf(string_key_id,"Ch -");//max 16 char break; case 3://CH THRUTH key_thruth(); sprintf(string_key_id,"To Ch");//max 16 char break; case 4://CLEAR key_unselect_ch(); sprintf(string_key_id,"Clear");//max 16 char break; default: break; } } } //protections if (numeric_postext>maxchar_numeric){numeric[numeric_postext]=' ';numeric_postext=maxchar_numeric-1;} if (numeric_postext<0) {numeric_postext=0;} } sprintf(string_numeric_entry,"<< %s",numeric); //CTRL-S if(index_do_quick_save==1 ) { Save_Show(); sprintf(string_Last_Order,">> Show Saved at %s", tmp_time); index_do_quick_save=0; } poll_keyboard(); return(0); }
void Application::Run() { // // keyboard // if (keyboard_needs_poll()) poll_keyboard(); for (int k = 0; k < 256; k++) { if (key[k]) { OnKeyPress(k); if (!prevKeyState[k]) OnKeyPressed(k); } else if (!key[k]) { if (prevKeyState[k]) OnKeyReleased(k); } } memcpy(prevKeyState,(char*)key,256); // // mouse // if (mouse_needs_poll()) poll_mouse(); for (int button = 0; button < (numMouseButtons); button++) { if ((mouse_b & (1 << button)) != 0) { mouseButtons[button] = true; } else { mouseButtons[button] = false; } if (mouseButtons[button] && (!prevMouseButtons[button])) { OnMousePressed(button, mouse_x, mouse_y); mousePressedLocs[button].x = mouse_x; mousePressedLocs[button].y = mouse_y; } else if ((!mouseButtons[button]) && prevMouseButtons[button]) { OnMouseReleased(button, mouse_x, mouse_y); if ((mousePressedLocs[button].x == mouse_x) && (mousePressedLocs[button].y == mouse_y)) { OnMouseClick(button,mouse_x,mouse_y); } } } memcpy(prevMouseButtons,mouseButtons,sizeof(bool)*(numMouseButtons+1)); if ((mouse_x != prevMouseX) || (mouse_y != prevMouseY)) { OnMouseMove(mouse_x,mouse_y); prevMouseX = mouse_x; prevMouseY = mouse_y; } // mouse wheel if (mouse_z > prevMouseZ) { OnMouseWheelUp( mouse_x, mouse_y ); prevMouseZ = mouse_z; } else if (mouse_z < prevMouseZ) { OnMouseWheelDown( mouse_x, mouse_y ); prevMouseZ = mouse_z; } // // run the game // show_mouse(NULL); RunGame(); show_mouse(canvas); // // render canvas to the screen // blit(canvas,screen,0,0,0,0,screen->w,screen->h); // // sound polling (to ensure sounds currently playing will keep playing) // SoundOGG::PollSounds(); // // handle timing // HandleTiming(); }