/** * Updates the mouse information (position, wheel and buttons). * * @return Returns true if the mouse moved. */ bool jmouse_poll() { m_b[1] = m_b[0]; m_x[1] = m_x[0]; m_y[1] = m_y[0]; m_z[1] = m_z[0]; poll_mouse(); m_b[0] = mouse_b; m_z[0] = mouse_z; update_mouse_position(); if ((m_x[0] != m_x[1]) || (m_y[0] != m_y[1])) { poll_mouse(); update_mouse_position(); moved = true; } if (moved) { moved = false; return true; } else return false; }
/* let the user input a list of path nodes */ void input_nodes(void) { clear_to_color(screen, makecol(255, 255, 255)); textout_centre_ex(screen, font, "Click the left mouse button to add path " "nodes", SCREEN_W/2, 8, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "Right mouse button or any key to finish", SCREEN_W/2, 24, palette_color[255], palette_color[0]); node_count = 1; show_mouse(screen); do { poll_mouse(); } while (mouse_b); clear_keybuf(); for (;;) { poll_mouse(); if (mouse_b & 1) { if (node_count < MAX_NODES-1) { nodes[node_count].x = mouse_x; nodes[node_count].y = mouse_y; show_mouse(NULL); draw_node(node_count); show_mouse(screen); node_count++; } do { poll_mouse(); } while (mouse_b & 1); } if ((mouse_b & 2) || (keypressed())) { if (node_count < 3) alert("You must enter at least two nodes", NULL, NULL, "OK", NULL, 13, 0); else break; } } show_mouse(NULL); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }
int mouse_dclick(int mode) { int ox, oy; int start = clock(); do { ox = m_x; oy = m_y; poll_mouse(); if (!mode) if ((ox != m_x) || (oy != m_y)) return TRUE; if (m_b & 1) { if (mode) return TRUE; } else if (!mode) return FALSE; } while ((clock() - start) < CLOCKS_PER_SEC / 4); return !mode; }
void optionsScreen::update() { poll_mouse(); menu->update(); while(keypressed()) { int newkey = readkey(); char ASCII = newkey & 0xff; char scancode = newkey >> 8; // a character key was pressed; add it to the string if(ASCII >= 32 && ASCII <= 126) { // add the new char, inserting or replacing as need be if(insert || iter == edittext.end()) iter = edittext.insert(iter, ASCII); else edittext.replace(caret, 1, 1, ASCII); // increment both the caret and the iterator caret++; iter++; } // some other, "special" key was pressed; handle it here else switch(scancode) { case KEY_DEL: if(iter != edittext.end()) iter = edittext.erase(iter); break; case KEY_BACKSPACE: if(iter != edittext.begin()) { caret--; iter--; iter = edittext.erase(iter); } break; case KEY_RIGHT: if(iter != edittext.end()) caret++, iter++; break; case KEY_LEFT: if(iter != edittext.begin()) caret--, iter--; break; case KEY_INSERT: if(insert) insert = 0; else insert = 1; break; default: break; } } }
/* callback to quit out of the FLI player */ static int fli_stopper(void) { poll_mouse(); if ((keypressed()) || (mouse_b)) return 1; else return 0; }
void Menu::update(){ poll_mouse(); angle = atan2(mouse_y-cy,mouse_x-cx)*255.0/(2.0*3.14150926); masked_blit(bgd,image,0,0,x,y,width,height); populate(); cy = 190 + 50*selectNum; //masked_blit(cursor,image,0,0,cx,cy,32,32); pivot_sprite(image,cursor,cx,cy,16,16,ftofix(angle)); //angle++; }
/* 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(); } }
void alert_box(char *s) /* alert the user to an error */ { char *b; int x, y, w; w = strlen(s) + 20; b = prepare_popup("Error", &x, &y, &w); hide_c(); mywrite(s); clear_keybuf(); while (m_b) poll_mouse(); while ((!input_waiting()) && (!m_b)) poll_mouse(); if (input_waiting()) input_char(); else while (m_b) poll_mouse(); show_c(); end_popup(b, &x, &y, &w); }
/* handles double-clicking on a FLIC object in the grabber */ static int view_fli(DATAFILE *dat) { show_mouse(NULL); clear_to_color(screen, gui_mg_color); play_memory_fli(dat->dat, screen, TRUE, fli_stopper); do { poll_mouse(); } while (mouse_b); clear_keybuf(); set_palette(datedit_current_palette); show_mouse(screen); return D_REDRAW; }
void normalmouse::update() { if (mouse_needs_poll()) poll_mouse(); oldpos = pos2; // this is exactly the "old" position, unmoved pos.set(mouse_x, mouse_y, mouse_z); pos2 = pos; int b = mouse_b; left.update(bool(b & 1)); // make distinction here; individual buttons shouldn't know of each other mid.update(bool(b & 4)); right.update(bool(b & 2)); }
static bool CreateMainSurface(uint w, uint h) { int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); set_color_depth(bpp); GetAvailableVideoMode(&w, &h); if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) { DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on '%s'", allegro_error); return false; } /* The size of the screen might be bigger than the part we can actually draw on! * So calculate the size based on the top, bottom, left and right */ _allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct); _screen.width = _allegro_screen->w; _screen.height = _allegro_screen->h; _screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8); _screen.dst_ptr = _allegro_screen->line[0]; /* Initialise the screen so we don't blit garbage to the screen */ memset(_screen.dst_ptr, 0, _screen.height * _screen.pitch); /* Set the mouse at the place where we expect it */ poll_mouse(); _cursor.pos.x = mouse_x; _cursor.pos.y = mouse_y; BlitterFactoryBase::GetCurrentBlitter()->PostResize(); InitPalette(); char caption[32]; snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); set_window_title(caption); enable_hardware_cursor(); select_mouse_cursor(MOUSE_CURSOR_ARROW); show_mouse(_allegro_screen); GameSizeChanged(); return true; }
void mouse_init() { __dpmi_regs reg; if (!mouse_state) { reg.x.ax = 0; __dpmi_int(0x33, ®); mouse_state = reg.x.ax; } reg.x.ax = 10; reg.x.bx = 0; reg.x.cx = 0xffff; reg.x.dx = 0x7700; __dpmi_int(0x33, ®); poll_mouse(); set_mouse_height(1); }
static void lr_input_poll_mouse(const int port_) { freedo_pbus_mouse_t m; m.x = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_X); m.y = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_Y); m.left = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_LEFT); m.middle = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_MIDDLE); m.right = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_RIGHT); m.shift = poll_mouse(port_,RETRO_DEVICE_ID_MOUSE_BUTTON_4); freedo_pbus_add_mouse(&m); }
void set_mouse_height(int h) { __dpmi_regs reg; if (!mouse_state) return; poll_mouse(); reg.x.ax = 8; reg.x.cx = 0; reg.x.dx = screen_h * h * 8 - 1; __dpmi_int(0x33, ®); reg.x.ax = 15; reg.x.cx = 8; reg.x.dx = MAX(16/h, 1); __dpmi_int(0x33, ®); set_mouse_pos(m_x, m_y*h/mouse_height); mouse_height = h; }
// <- FUNCTIONS -> // void init() { int depth, res; allegro_init(); depth = desktop_color_depth(); if (depth == 0) depth = 32; set_color_depth(depth); res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); perform_creations(); //to create bitmaps, etc... if (res != 0) { allegro_message(allegro_error); exit(-1); } install_timer(); install_keyboard(); install_mouse(); if(mouse_needs_poll() == true) poll_mouse(); /* add other initializations here */ }
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); } }
void ExtendedAllegroInput::pollMouseInput() { if (mouse_needs_poll()) { poll_mouse(); } int mouseX = mouse_x / 2; int mouseY = mouse_y / 2; int mouseZ = mouse_z; int mouseB1 = mouse_b & 1; int mouseB2 = mouse_b & 2; int mouseB3 = mouse_b & 4; // Check mouse movement if (mouseX != mLastMouseX || mouseY != mLastMouseY) { mMouseQueue.push(MouseInput(MouseInput::EMPTY, MouseInput::MOVED, mouseX, mouseY, 0)); mLastMouseX = mouseX; mLastMouseY = mouseY; } // Check mouse Wheel while (mLastMouseZ < mouseZ) { mMouseQueue.push(MouseInput(MouseInput::EMPTY, MouseInput::WHEEL_MOVED_UP, mouseX, mouseY, 0)); mLastMouseZ++; } while (mLastMouseZ > mouseZ) { mMouseQueue.push(MouseInput(MouseInput::EMPTY, MouseInput::WHEEL_MOVED_DOWN, mouseX, mouseY, 0)); mLastMouseZ--; } // Check mouse buttons if (!mMouseButton1 && mouseB1) { mMouseQueue.push(MouseInput(MouseInput::LEFT, MouseInput::PRESSED, mouseX, mouseY, 0)); } if (mMouseButton1 && !mouseB1) { mMouseQueue.push(MouseInput(MouseInput::LEFT, MouseInput::RELEASED, mouseX, mouseY, 0)); } if (!mMouseButton2 && mouseB2) { mMouseQueue.push(MouseInput(MouseInput::RIGHT, MouseInput::PRESSED, mouseX, mouseY, 0)); } if (mMouseButton2 && !mouseB2) { mMouseQueue.push(MouseInput(MouseInput::RIGHT, MouseInput::RELEASED, mouseX, mouseY, 0)); } if (!mMouseButton3 && mouseB3) { mMouseQueue.push(MouseInput(MouseInput::MIDDLE, MouseInput::PRESSED, mouseX, mouseY, 0)); } if (mMouseButton3 && !mouseB3) { mMouseQueue.push(MouseInput(MouseInput::MIDDLE, MouseInput::RELEASED, mouseX, mouseY, 0)); } mMouseButton1 = mouseB1; mMouseButton2 = mouseB2; mMouseButton3 = mouseB3; }
int main(int argc, char *argv[]) { PALETTE pal; BITMAP *buffer; BITMAP *planet; char buf[256]; if (allegro_init() != 0) return 1; install_keyboard(); install_mouse(); if (set_gfx_mode(GFX_AUTODETECT, 320, 240, 0, 0) != 0) { if (set_gfx_mode(GFX_SAFE, 320, 240, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); return 1; } } replace_filename(buf, argv[0], "planet.pcx", sizeof(buf)); planet = load_bitmap(buf, pal); if (!planet) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error reading %s\n", buf); return 1; } buffer = create_bitmap(SCREEN_W, SCREEN_H); clear_bitmap(buffer); set_palette(pal); create_rgb_table(&rgb_table, pal, NULL); rgb_map = &rgb_table; create_light_table(&light_table, pal, 0, 0, 0, NULL); color_map = &light_table; set_trans_blender(0, 0, 0, 128); do { poll_mouse(); draw_gouraud_sprite(buffer, planet, SCREEN_W/2, SCREEN_H/2, distance(SCREEN_W/2, SCREEN_H/2, mouse_x, mouse_y), distance(SCREEN_W/2 + planet->w, SCREEN_H/2, mouse_x, mouse_y), distance(SCREEN_W/2 + planet->w, SCREEN_H/2 + planet->h, mouse_x, mouse_y), distance(SCREEN_W/2, SCREEN_H/2 + planet->h, mouse_x, mouse_y)); textout_ex(buffer, font, "Gouraud Shaded Sprite Demo", 0, 0, palette_color[10], -1); show_mouse(buffer); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); show_mouse(NULL); } while (!keypressed()); destroy_bitmap(planet); destroy_bitmap(buffer); 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(); }
/* moves a sprite along the spline path */ void walk(void) { #define MAX_POINTS 256 int points[8]; int x[MAX_POINTS], y[MAX_POINTS]; int n, i; int npoints; int ox, oy; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); for (i=1; i<node_count-1; i++) draw_node(i); release_screen(); do { poll_mouse(); } while (mouse_b); clear_keybuf(); ox = -16; oy = -16; xor_mode(TRUE); for (n=1; n < node_count-2; n++) { npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4; if (npoints < 1) npoints = 1; else if (npoints > MAX_POINTS) npoints = MAX_POINTS; get_control_points(nodes[n], nodes[n+1], points); calc_spline(points, npoints, x, y); for (i=1; i<npoints; i++) { vsync(); acquire_screen(); circlefill(screen, ox, oy, 6, palette_color[2]); circlefill(screen, x[i], y[i], 6, palette_color[2]); release_screen(); ox = x[i]; oy = y[i]; poll_mouse(); if ((keypressed()) || (mouse_b)) goto getout; } } getout: xor_mode(FALSE); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }
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; }
void OpenLayerInput::pollMouseInput() { if (mouse_needs_poll()) { poll_mouse(); } int mouseX = mouse_x; int mouseY = mouse_y; int mouseZ = mouse_z; int mouseB1 = mouse_b & 1; int mouseB2 = mouse_b & 2; int mouseB3 = mouse_b & 4; // Check mouse movement if (mouseX != mLastMouseX || mouseY != mLastMouseY) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::Moved, mouseX, mouseY, 0)); mLastMouseX = mouseX; mLastMouseY = mouseY; } // Check mouse Wheel while (mLastMouseZ < mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedUp, mouseX, mouseY, 0)); mLastMouseZ++; } while (mLastMouseZ > mouseZ) { mMouseQueue.push(MouseInput(MouseInput::Empty, MouseInput::WheelMovedDown, mouseX, mouseY, 0)); mLastMouseZ--; } // Check mouse buttons if (!mMouseButton1 && mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton1 && !mouseB1) { mMouseQueue.push(MouseInput(MouseInput::Left, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton2 && mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton2 && !mouseB2) { mMouseQueue.push(MouseInput(MouseInput::Right, MouseInput::Released, mouseX, mouseY, 0)); } if (!mMouseButton3 && mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Pressed, mouseX, mouseY, 0)); } if (mMouseButton3 && !mouseB3) { mMouseQueue.push(MouseInput(MouseInput::Middle, MouseInput::Released, mouseX, mouseY, 0)); } mMouseButton1 = mouseB1; mMouseButton2 = mouseB2; mMouseButton3 = mouseB3; }
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(); }
void osd_update_inputs(void) { /* Reset input states */ input.system = 0; input.pad[0] = 0; input.pad[1] = 0; input.analog[0] = 0x7F; input.analog[1] = 0x7F; /* Alt+W : Dump work RAM */ if((key[KEY_ALT] || key[KEY_ALTGR]) && check_key(KEY_W)) dump_wram(); /* Alt+V : Dump video RAM */ if((key[KEY_ALT] || key[KEY_ALTGR]) && check_key(KEY_V)) dump_vram(); /* DEL : User-requested hard reset */ if(check_key(KEY_DEL)) system_reset(); /* ENTER | SPACE : SMS PAUSE or GG START button */ if(key[KEY_ENTER] || key[KEY_SPACE]) input.system |= (IS_GG) ? INPUT_START : INPUT_PAUSE; /* Player #1 inputs */ if(key[KEY_UP]) input.pad[0] |= INPUT_UP; else if(key[KEY_DOWN]) input.pad[0] |= INPUT_DOWN; if(key[KEY_LEFT]) input.pad[0] |= INPUT_LEFT; else if(key[KEY_RIGHT]) input.pad[0] |= INPUT_RIGHT; if(key[KEY_A]) input.pad[0] |= INPUT_BUTTON2; if(key[KEY_S]) input.pad[0] |= INPUT_BUTTON1; /* Player #2 inputs */ if(key[KEY_8_PAD]) input.pad[1] |= INPUT_UP; else if(key[KEY_2_PAD]) input.pad[1] |= INPUT_DOWN; if(key[KEY_4_PAD]) input.pad[1] |= INPUT_LEFT; else if(key[KEY_6_PAD]) input.pad[1] |= INPUT_RIGHT; if(key[KEY_1_PAD]) input.pad[1] |= INPUT_BUTTON2; if(key[KEY_3_PAD]) input.pad[1] |= INPUT_BUTTON1; /* TAB : SMS RESET button */ if(key[KEY_TAB]) input.system |= INPUT_RESET; /* Check for any joysticks present */ if(option.joy_driver != JOY_TYPE_NONE) { poll_joystick(); /* Parse player 1 joystick state */ if(joy[0].stick[0].axis[1].d1) input.pad[0] |= INPUT_UP; else if(joy[0].stick[0].axis[1].d2) input.pad[0] |= INPUT_DOWN; if(joy[0].stick[0].axis[0].d1) input.pad[0] |= INPUT_LEFT; else if(joy[0].stick[0].axis[0].d2) input.pad[0] |= INPUT_RIGHT; if(joy[0].button[0].b) input.pad[0] |= INPUT_BUTTON2; if(joy[0].button[1].b) input.pad[0] |= INPUT_BUTTON1; if(joy[0].button[2].b) input.system |= (IS_GG) ? INPUT_START : INPUT_PAUSE; /* Check if a 2nd joystick is present */ if(num_joysticks > 2) { /* Parse player 2 joystick state */ if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP; else if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN; if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT; else if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT; if(joy[1].button[0].b) input.pad[1] |= INPUT_BUTTON2; if(joy[1].button[1].b) input.pad[1] |= INPUT_BUTTON1; } } /* Check if a mouse is present. */ if(use_mouse) { int temp; /* Poll mouse if necessary */ if(mouse_needs_poll() == TRUE) poll_mouse(); /* Calculate X axis value */ temp = mouse_x; if(temp > 0xFF) temp = 0xFF; if(temp < 0x00) temp = 0x00; input.analog[0] = temp; /* Calculate Y axis value */ temp = mouse_y; if(temp > 0xFF) temp = 0xFF; if(temp < 0x00) temp = 0x00; input.analog[1] = temp; /* Map mouse buttons to player #1 inputs */ if(mouse_b & 4) input.pad[0] |= (IS_GG) ? INPUT_START : INPUT_PAUSE; if(mouse_b & 2) input.pad[0] |= INPUT_BUTTON2; if(mouse_b & 1) input.pad[0] |= INPUT_BUTTON1; } }
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 (); }
static int AM_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp) { static int mz; static int hidingmouse; int mickeyx = 0; int mickeyy = 0; int mickeyz = 0; int buttons = 0; poll_mouse(); if (ALLEGRO_SUB_VERSION >2){ //mouse_on_screen() not available on version 4.2 -> starting with 4.3 if (mouse_on_screen()){ //mouse inside microwindows window if (hidingmouse == 1){ //already shown? GdShowCursor(&scrdev); hidingmouse == 0; } }else{ if (hidingmouse == 0){ //already hidden? GdHideCursor(&scrdev); hidingmouse=1; } } } /* microwindows reads the motion */ get_mouse_mickeys(&mickeyx,&mickeyy); #if 0 *dx=mickeyx; *dy=mickeyy; #else /* return position */ *dx=mouse_x; *dy=mouse_y; #endif //calculate wheel button (up/down) if(mouse_z != mz) mickeyz = mouse_z - mz; else mickeyz = 0; mz = mouse_z; *dz = 0; *bp = 0; buttons = 0; //the buttons seem to be returned different than documented in allegro if (mouse_b & 1) buttons |= MWBUTTON_L; if (mouse_b & 2) buttons |= MWBUTTON_R; if (mouse_b & 4) buttons |= MWBUTTON_M; if (mickeyz > 0) buttons |= MWBUTTON_SCROLLUP; if (mickeyz < 0) buttons |= MWBUTTON_SCROLLDN; *bp = buttons; /* return absolute mouse position */ return MOUSE_ABSPOS; }
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 (); }
void editeur_de_case(BITMAP* affiche[15][19], int valeurs[15][19]) { int compteur=0; int Case=0; int test=1,x=100,y=100; BITMAP* buffer; BITMAP* affiche2[NBSPRITE]; init_mode_graphique(1, affiche2); buffer= create_bitmap(TSPRITE*19, TSPRITE*15); buffer= affiche_buffer(affiche); show_mouse(buffer); blit(buffer, screen ,0,0,0,0, 19*TSPRITE, 15*TSPRITE); rest(500); while (test) { poll_mouse(); show_mouse(buffer); blit(buffer, screen ,0,0,0,0, 19*TSPRITE, 15*TSPRITE); if ((mouse_b & 1)) { if (((int)(mouse_x-mouse_x%TSPRITE)/TSPRITE!=x)||((int)(mouse_y-mouse_y%TSPRITE)/TSPRITE!=y)) { Case=0; x= (int)(mouse_x-mouse_x%TSPRITE)/TSPRITE; y=(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE; affiche[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]=affiche2[Case]; valeurs[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]= conversion(Case, &compteur); buffer= create_bitmap(TSPRITE*19, TSPRITE*15); buffer= affiche_buffer(affiche); show_mouse(buffer); blit(buffer, screen ,0,0,0,0, 19*TSPRITE, 15*TSPRITE); rest(100); destroy_bitmap(buffer); } else { if (Case==13) { Case=-1; compteur--; } affiche[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]=affiche2[++Case]; valeurs[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]= conversion(Case, &compteur); buffer= create_bitmap(TSPRITE*19, TSPRITE*15); buffer= affiche_buffer(affiche); show_mouse(buffer); blit(buffer, screen ,0,0,0,0, 19*TSPRITE, 15*TSPRITE); rest(150); destroy_bitmap(buffer); } } if (key[KEY_ENTER]) { if (compteur%2==0) { allegro_message("attention!\n les telporteurs sont liées 2 à 2! il ne peut pas y en avoir un nombre impair!"); } else test--; } if(mouse_b & 2) { if (Case==9) compteur--; Case=7; x= (int)(mouse_x-mouse_x%TSPRITE)/TSPRITE; y=(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE; affiche[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]=affiche2[Case]; valeurs[(int)(mouse_y-mouse_y%TSPRITE)/TSPRITE][(int)(mouse_x-mouse_x%TSPRITE)/TSPRITE]= conversion(Case, &compteur); buffer= create_bitmap(TSPRITE*19, TSPRITE*15); buffer= affiche_buffer(affiche); show_mouse(buffer); blit(buffer, screen ,0,0,0,0, 19*TSPRITE, 15*TSPRITE); rest(100); destroy_bitmap(buffer); } } destroy_bitmap(buffer); }
/* 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; }