2007-12-24 14:11:18 -08:00
|
|
|
/*
|
2007-10-24 06:12:10 -07:00
|
|
|
* PieToaster is an OpenGL application to edit 3D models in
|
|
|
|
* Warzone 2100's (an RTS game) PIE 3D model format, which is heavily
|
|
|
|
* inspired by PieSlicer created by stratadrake.
|
|
|
|
* Copyright (C) 2007 Carl Hee
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2007-10-24 05:29:36 -07:00
|
|
|
#ifndef __game_io_h
|
|
|
|
#define __game_io_h
|
2007-12-24 14:11:18 -08:00
|
|
|
#include <SDL.h>
|
2007-10-24 07:23:59 -07:00
|
|
|
|
2007-12-24 14:11:18 -08:00
|
|
|
#include "wzglobal.h"
|
2007-10-24 05:29:36 -07:00
|
|
|
|
|
|
|
/* Simple implementation of singleclick doubleclick holdbutton via SDL */
|
|
|
|
|
|
|
|
///use max possible sdl keys
|
2007-12-24 14:50:45 -08:00
|
|
|
const Uint32 MAX_KEYS = SDLK_LAST;
|
2007-10-24 05:29:36 -07:00
|
|
|
///use max possible sdl mouse buttons(UNUSED?,LEFT,RIGHT,MIDDLE)
|
2007-12-24 14:50:45 -08:00
|
|
|
const Uint8 MAX_MOUSE_BUTTONS = 4;
|
2007-10-24 05:29:36 -07:00
|
|
|
|
|
|
|
|
|
|
|
///timer for hold,the interval between 2 key events < 100ms triggers OH_KEY_HOLD
|
2007-12-24 14:50:45 -08:00
|
|
|
const Uint32 KEY_HOLD_TIMER = 100;
|
2007-10-24 05:29:36 -07:00
|
|
|
///timer for double down(double click for mouse),the interval between 2 key events < 500ms triggers OH_KEY_DDOWN
|
2007-12-24 14:50:45 -08:00
|
|
|
const Uint32 KEY_DDOWN_TIMER = 500;
|
2007-10-24 05:29:36 -07:00
|
|
|
|
|
|
|
///state for both mouse and keyboard
|
|
|
|
enum _key_state {
|
|
|
|
OH_KEY_UP = 0x0001, ///< Key/Button is up
|
|
|
|
OH_KEY_DOWN = 0x0002, ///< Key/Button is down
|
|
|
|
OH_KEY_HOLD = 0x0004, ///< Key/Button is hold for some time
|
|
|
|
OH_KEY_DDOWN = 0x0008, ///< Key/Button is double-down/double-clickd
|
|
|
|
OH_KEY_RELEASE = 0x0010, ///< Key/Button is released(note:this one is the proper clicked event)
|
|
|
|
};
|
|
|
|
|
|
|
|
///input element with hold event duration
|
|
|
|
typedef struct _input_elem {
|
|
|
|
///key state
|
2007-12-24 14:50:45 -08:00
|
|
|
Uint32 data;
|
2007-10-24 05:29:36 -07:00
|
|
|
///last down timestamp
|
2007-12-24 14:50:45 -08:00
|
|
|
Uint32 lastDown;
|
2007-10-24 05:29:36 -07:00
|
|
|
///duration of hold
|
2007-12-24 14:50:45 -08:00
|
|
|
Uint32 duration;
|
2007-10-24 05:29:36 -07:00
|
|
|
} INPUT_ELEM;
|
|
|
|
|
2007-12-24 14:50:45 -08:00
|
|
|
extern Uint16 MouseX;
|
|
|
|
extern Uint16 MouseY;
|
|
|
|
extern Sint16 MouseMoveX;
|
|
|
|
extern Sint16 MouseMoveY;
|
2007-10-24 05:29:36 -07:00
|
|
|
extern INPUT_ELEM KeyStates[MAX_KEYS];
|
|
|
|
extern INPUT_ELEM MouseStates[MAX_MOUSE_BUTTONS];
|
|
|
|
|
|
|
|
extern void inputInitialize(void);
|
|
|
|
|
2007-12-24 14:50:45 -08:00
|
|
|
extern void inputButtonMouseEvent(SDL_MouseButtonEvent button, Uint8 newState);
|
2007-10-24 05:29:36 -07:00
|
|
|
extern void inputMotionMouseEvent(SDL_MouseMotionEvent motion);
|
|
|
|
|
2007-12-24 14:50:45 -08:00
|
|
|
extern void inputKeyEvent(SDL_KeyboardEvent key, Uint8 newState);
|
2007-10-24 05:29:36 -07:00
|
|
|
|
2007-10-24 07:04:25 -07:00
|
|
|
bool isKeyDown(SDLKey key);
|
|
|
|
bool isKeyDoubleDown(SDLKey key);
|
|
|
|
bool isKeyHold(SDLKey key);
|
2007-12-24 14:50:45 -08:00
|
|
|
bool isMouseButtonDown(Uint8 button);
|
|
|
|
bool isMouseButtonDoubleDown(Uint8 button);
|
|
|
|
bool isMouseButtonHold(Uint8 button);
|
2007-10-24 05:29:36 -07:00
|
|
|
|
|
|
|
extern void inputUpdate(void);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|