mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Added love.focus callback
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
@@ -58,7 +58,7 @@ namespace event
|
||||
return keys.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Event::Type, Event::TYPE_MAX_ENUM>::Entry Event::typeEntries[] =
|
||||
StringMap<Event::Type, Event::TYPE_MAX_ENUM>::Entry Event::typeEntries[] =
|
||||
{
|
||||
{"kp", Event::TYPE_KEY_PRESSED},
|
||||
{"kr", Event::TYPE_KEY_RELEASED},
|
||||
@@ -66,12 +66,13 @@ namespace event
|
||||
{"mr", Event::TYPE_MOUSE_RELEASED},
|
||||
{"jp", Event::TYPE_JOYSTICK_PRESSED},
|
||||
{"jr", Event::TYPE_JOYSTICK_RELEASED},
|
||||
{"f", Event::TYPE_FOCUS},
|
||||
{"q", Event::TYPE_QUIT},
|
||||
};
|
||||
|
||||
StringMap<Event::Type, Event::TYPE_MAX_ENUM> Event::types(Event::typeEntries, sizeof(Event::typeEntries));
|
||||
|
||||
StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
|
||||
StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
|
||||
{
|
||||
{"l", love::mouse::Mouse::BUTTON_LEFT},
|
||||
{"m", love::mouse::Mouse::BUTTON_MIDDLE},
|
||||
@@ -84,7 +85,7 @@ namespace event
|
||||
|
||||
StringMap<love::mouse::Mouse::Button, love::mouse::Mouse::BUTTON_MAX_ENUM> Event::buttons(Event::buttonEntries, sizeof(Event::buttonEntries));
|
||||
|
||||
StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
|
||||
StringMap<love::keyboard::Keyboard::Key, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
|
||||
{
|
||||
{"backspace", love::keyboard::Keyboard::KEY_BACKSPACE},
|
||||
{"tab", love::keyboard::Keyboard::KEY_TAB},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
@@ -44,6 +44,7 @@ namespace event
|
||||
TYPE_MOUSE_RELEASED,
|
||||
TYPE_JOYSTICK_RELEASED,
|
||||
TYPE_JOYSTICK_PRESSED,
|
||||
TYPE_FOCUS,
|
||||
TYPE_QUIT,
|
||||
TYPE_MAX_ENUM = 32
|
||||
};
|
||||
@@ -52,7 +53,7 @@ namespace event
|
||||
{
|
||||
Type type;
|
||||
|
||||
struct
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
love::mouse::Mouse::Button b;
|
||||
@@ -73,6 +74,12 @@ namespace event
|
||||
love::keyboard::Keyboard::Key k;
|
||||
unsigned short u;
|
||||
} keyboard;
|
||||
|
||||
struct
|
||||
{
|
||||
Type type;
|
||||
bool f;
|
||||
} focus;
|
||||
};
|
||||
|
||||
virtual ~Event();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 LOVE Development Team
|
||||
*
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
@@ -96,6 +96,12 @@ namespace sdl
|
||||
m.joystick.button = e.jbutton.button;
|
||||
m.joystick.index = e.jbutton.which;
|
||||
return true;
|
||||
case SDL_ACTIVEEVENT:
|
||||
if (e.active.state & SDL_APPINPUTFOCUS) {
|
||||
m.type = Event::TYPE_FOCUS;
|
||||
m.focus.f = e.active.gain;
|
||||
return true;
|
||||
} else break;
|
||||
case SDL_QUIT:
|
||||
m.type = Event::TYPE_QUIT;
|
||||
return true;
|
||||
@@ -127,6 +133,10 @@ namespace sdl
|
||||
e.jbutton.which = m.joystick.index;
|
||||
e.jbutton.button = m.joystick.button;
|
||||
return true;
|
||||
case Event::TYPE_FOCUS:
|
||||
e.type = SDL_ACTIVEEVENT;
|
||||
e.active.state = SDL_APPINPUTFOCUS;
|
||||
e.active.gain = m.focus.f;
|
||||
case Event::TYPE_QUIT:
|
||||
e.type = SDL_QUIT;
|
||||
return true;
|
||||
@@ -137,7 +147,7 @@ namespace sdl
|
||||
return true;
|
||||
}
|
||||
|
||||
EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
|
||||
EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM>::Entry Event::keyEntries[] =
|
||||
{
|
||||
{ love::keyboard::Keyboard::KEY_BACKSPACE, SDLK_BACKSPACE},
|
||||
{ love::keyboard::Keyboard::KEY_TAB, SDLK_TAB},
|
||||
@@ -284,7 +294,7 @@ namespace sdl
|
||||
|
||||
EnumMap<love::keyboard::Keyboard::Key, SDLKey, love::keyboard::Keyboard::KEY_MAX_ENUM> Event::keys(Event::keyEntries, sizeof(Event::keyEntries));
|
||||
|
||||
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
|
||||
EnumMap<love::mouse::Mouse::Button, Uint8, love::mouse::Mouse::BUTTON_MAX_ENUM>::Entry Event::buttonEntries[] =
|
||||
{
|
||||
{ love::mouse::Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
|
||||
{ love::mouse::Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
|
||||
|
||||
@@ -64,6 +64,9 @@ namespace sdl
|
||||
msg.joystick.index = luaL_checkint(L, 2);
|
||||
msg.joystick.button = luaL_checkint(L, 3);
|
||||
return true;
|
||||
case Event::TYPE_FOCUS:
|
||||
msg.focus.f = lua_toboolean(L, 2);
|
||||
return true;
|
||||
case Event::TYPE_QUIT:
|
||||
return true;
|
||||
default:
|
||||
@@ -108,6 +111,9 @@ namespace sdl
|
||||
lua_pushinteger(L, msg.joystick.index);
|
||||
lua_pushinteger(L, msg.joystick.button);
|
||||
return 3;
|
||||
case Event::TYPE_FOCUS:
|
||||
lua_pushboolean(L, msg.focus.f);
|
||||
return 2;
|
||||
case Event::TYPE_QUIT:
|
||||
return 1;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user