wince_events.cpp

来自「这个是延伸mame的在wince平台下的游戏模拟器的代码」· C++ 代码 · 共 263 行

CPP
263
字号
/* PocketCultMAME - MAME Emulator for PocketPC
   (c) Copyright 2006 Manuel Castrillo Mart韓ez

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <windows.h>
#include "osdepend.h"
#include "wince_cfg.h"
#include "vidsys.h"
#include "vidfunc.h"

extern "C" {
	#include "wince_input.h"

	extern PadMappingStruct rotatedPadMapping;
	extern PadMappingStruct PadStatus;
	
	extern cfgStruct GameConfig;
	extern VidSysInfo VideoInfo;

	extern int checkKey( int code );
	int checkMessages(void);
	
	void stylusMovement(int *XPos, int *YPos);
	void stylusJoystick(int *XPos, int *YPos);
}

extern HINSTANCE g_hInstance;
extern HDC hdc;
extern HWND hWnd;
extern int iScreenWidth, iScreenHeight;

short vkKey;

BOOL StylusReleased = true; // Stylus status

int oldStylusX = 0, oldStylusY = 0;
int relativeStylusX = 0, relativeStylusY = 0;
int joystickStylusX = 0, joystickStylusY = 0;


void getStylusPosFromAngle0( int &x, int&y )
{
	if( VideoInfo.displayVGA )
	{
		x = x*2;
		y = y*2;
	}
	rotateFrom0( VideoInfo.Rotation, x, y );
}

void stylusMovement(int *XPos, int *YPos)
{
	*XPos = relativeStylusX * GameConfig.inpAnalogSensibility;
	*YPos = relativeStylusY * GameConfig.inpAnalogSensibility;
	relativeStylusX = 0;
	relativeStylusY = 0;
}

void stylusJoystick(int *XPos, int *YPos)
{
	int tempx, tempy;
	
	stylusMovement( &tempx, &tempy );

	if( joystickStylusX < 128 && joystickStylusX > -128 ) joystickStylusX += tempx;
	if( joystickStylusY < 128 && joystickStylusY > -128 ) joystickStylusY += tempy;

	if( joystickStylusX > 127 ) joystickStylusX = 128; if( joystickStylusX < -127 ) joystickStylusX = -128;
	if( joystickStylusY > 127 ) joystickStylusY = 128; if( joystickStylusY < -127 ) joystickStylusY = -128;

	*XPos = joystickStylusX;
	*YPos = joystickStylusY;
}

//
//  Processes messages for the main window.
//
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{

	PAINTSTRUCT ps;
	int xPos, yPos;	// Stylus position

	switch (message) {
		case WM_COMMAND:
    		break;

		case WM_CREATE:
			break;

		case WM_ACTIVATE:
			break;

		case WM_KILLFOCUS:
			break;

		case WM_SETFOCUS:
			break;

		case WM_PAINT:
			if (GetForegroundWindow() == hWnd) {
				hdc = BeginPaint(hWnd, &ps);
				EndPaint(hWnd, &ps);
			}
			break;

		case WM_KEYDOWN:
			vkKey = (short)wParam;
			
			if( vkKey == rotatedPadMapping.Up ){ PadStatus.Up = GameConfig.inpKeyUp; }
			if( vkKey == rotatedPadMapping.Down ){ PadStatus.Down = GameConfig.inpKeyDown; }
			if( vkKey == rotatedPadMapping.Left ){ PadStatus.Left = GameConfig.inpKeyLeft; }
			if( vkKey == rotatedPadMapping.Right ){ PadStatus.Right = GameConfig.inpKeyRight; }
			if( vkKey == rotatedPadMapping.KeyA ){ PadStatus.KeyA = GameConfig.inpKeyA; }
			if( vkKey == rotatedPadMapping.KeyB ){ PadStatus.KeyB = GameConfig.inpKeyB; }
			if( vkKey == rotatedPadMapping.KeyC ){ PadStatus.KeyC = GameConfig.inpKeyC; }
			if( vkKey == rotatedPadMapping.KeyD ){ PadStatus.KeyD = GameConfig.inpKeyD; }
			if( vkKey == rotatedPadMapping.KeyE ){ PadStatus.KeyE = GameConfig.inpKeyE; }
			if( vkKey == rotatedPadMapping.KeyF ){ PadStatus.KeyF = GameConfig.inpKeyF; }
			if( vkKey == rotatedPadMapping.KeyG ){ PadStatus.KeyG = GameConfig.inpKeyG; }
			break;

		case WM_KEYUP:
			vkKey = (short)wParam;

			if( checkKey( OSD_KEY_ESC ) )
				PostMessage(hWnd, WM_QUIT, 0, 0);

			// release all keys

			if( vkKey == rotatedPadMapping.Up ){ PadStatus.Up = 0; }
			if( vkKey == rotatedPadMapping.Down ){ PadStatus.Down = 0; }
			if( vkKey == rotatedPadMapping.Left ){ PadStatus.Left = 0; }
			if( vkKey == rotatedPadMapping.Right ){ PadStatus.Right = 0; }
			if( vkKey == rotatedPadMapping.KeyA ){ PadStatus.KeyA = 0; }
			if( vkKey == rotatedPadMapping.KeyB ){ PadStatus.KeyB = 0; }
			if( vkKey == rotatedPadMapping.KeyC ){ PadStatus.KeyC = 0; }
			if( vkKey == rotatedPadMapping.KeyD ){ PadStatus.KeyD = 0; }
			if( vkKey == rotatedPadMapping.KeyE ){ PadStatus.KeyE = 0; }
			if( vkKey == rotatedPadMapping.KeyF ){ PadStatus.KeyF = 0; }
			if( vkKey == rotatedPadMapping.KeyG ){ PadStatus.KeyG = 0; }
			break;

        case WM_LBUTTONDOWN:

            if ( (wParam & MK_LBUTTON) && StylusReleased )
            {
                xPos = LOWORD(lParam);
                yPos = HIWORD(lParam);
				StylusReleased = false;

				getStylusPosFromAngle0( xPos, yPos );

				oldStylusX = xPos; oldStylusY = yPos;	// Track stylus since touch the screen

				// Press onscreen buttons

				if( GameConfig.inpAnalogControls == ANALOG_DISABLED )
				{
					if( GameConfig.inpOnscreenButtonsOrientation == ONSCREENBUTTONS_HORIZONTAL )
					{
						int yButtonsPos;
						yButtonsPos = VideoInfo.yPixelsResolution / 3; 
						if( yPos < yButtonsPos ) PadStatus.OnscreenYellow = GameConfig.inpOnscreenYellow;
						if( yPos > yButtonsPos && yPos < yButtonsPos*2 ) PadStatus.OnscreenGreen = GameConfig.inpOnscreenGreen;
						if( yPos > yButtonsPos*2 ) PadStatus.OnscreenRed = GameConfig.inpOnscreenRed;
					}
					else
					{
						int xButtonsPos;
						xButtonsPos = VideoInfo.xPixelsResolution / 3;
						if( xPos < xButtonsPos ) PadStatus.OnscreenYellow = GameConfig.inpOnscreenYellow;
						if( xPos > xButtonsPos && xPos < xButtonsPos*2 ) PadStatus.OnscreenGreen = GameConfig.inpOnscreenGreen;
						if( xPos > xButtonsPos*2 ) PadStatus.OnscreenRed = GameConfig.inpOnscreenRed;
					}
				}
			}
			break;

		case WM_LBUTTONUP:
			if (!StylusReleased)
			{
                xPos = LOWORD(lParam);
                yPos = HIWORD(lParam);
				StylusReleased = true;
				
				// Centre analog joystick when the stylus is released

				joystickStylusX = 0; 
				joystickStylusY = 0;

				// Release onscreen buttons

				PadStatus.OnscreenYellow = 0;
				PadStatus.OnscreenGreen = 0;
				PadStatus.OnscreenRed = 0;
			}
			break;

		case WM_MOUSEMOVE :

			xPos = LOWORD(lParam);
			yPos = HIWORD(lParam);

			getStylusPosFromAngle0( xPos, yPos );

			// Analog track emulation using the stylus

			if( GameConfig.inpAnalogControls == ANALOG_TRACKSTYLUS || GameConfig.inpAnalogControls == ANALOG_JOYSTYLUS )
			{
				relativeStylusX += xPos - oldStylusX;
				relativeStylusY += yPos - oldStylusY;

				oldStylusX = xPos;
				oldStylusY = yPos;
			}
			break;

		case WM_QUIT:
			break;

		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}



//
//  Check for windows messages
//
int checkMessages(void)
{

	MSG msg;

	PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
	if(msg.message == WM_QUIT)
	{
		return(1);
	}
	DispatchMessage(&msg);

	return(0);

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?