Esempio n. 1
0
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));
}
Esempio n. 2
0
void mouse_poller_init()
{
  double_click_level = DOUBLE_CLICK_NONE;
  double_click_ticks = 0;
  moved = true;

#ifdef __APPLE__
  osx_mouse_enter_callback = osx_mouser_enter_she_callback;
  osx_mouse_leave_callback = osx_mouser_leave_she_callback;
#endif

  // optional mouse callback for supported platforms
  she_mouse_polling_required = (mouse_needs_poll() != 0);
  if (!she_mouse_polling_required)
    mouse_callback = she_mouse_callback;
}
Esempio n. 3
0
// <- 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 */
}
    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;
    }
    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;
    }
Esempio n. 6
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();
}
Esempio n. 7
0
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;
    }
}
Esempio n. 8
0
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;
}