Added love.focus callback

This commit is contained in:
Bart van Strien
2010-08-03 13:51:19 +02:00
parent 93910940da
commit 5235ceac53
7 changed files with 990 additions and 957 deletions
+1
View File
@@ -8,6 +8,7 @@ LOVE 0.7.0
* Added Font:getWrap. * Added Font:getWrap.
* Added identity field to love.conf. * Added identity field to love.conf.
* Added love.quit callback. * Added love.quit callback.
* Added love.focus callback.
* Added extra meter parameter to love.physics.newWorld. * Added extra meter parameter to love.physics.newWorld.
* Added love.graphics.setIcon. * Added love.graphics.setIcon.
* Enabled love.filesystem.FileData. * Enabled love.filesystem.FileData.
+7 -6
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -58,7 +58,7 @@ namespace event
return keys.find(in, out); 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}, {"kp", Event::TYPE_KEY_PRESSED},
{"kr", Event::TYPE_KEY_RELEASED}, {"kr", Event::TYPE_KEY_RELEASED},
@@ -66,12 +66,13 @@ namespace event
{"mr", Event::TYPE_MOUSE_RELEASED}, {"mr", Event::TYPE_MOUSE_RELEASED},
{"jp", Event::TYPE_JOYSTICK_PRESSED}, {"jp", Event::TYPE_JOYSTICK_PRESSED},
{"jr", Event::TYPE_JOYSTICK_RELEASED}, {"jr", Event::TYPE_JOYSTICK_RELEASED},
{"f", Event::TYPE_FOCUS},
{"q", Event::TYPE_QUIT}, {"q", Event::TYPE_QUIT},
}; };
StringMap<Event::Type, Event::TYPE_MAX_ENUM> Event::types(Event::typeEntries, sizeof(Event::typeEntries)); 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}, {"l", love::mouse::Mouse::BUTTON_LEFT},
{"m", love::mouse::Mouse::BUTTON_MIDDLE}, {"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::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}, {"backspace", love::keyboard::Keyboard::KEY_BACKSPACE},
{"tab", love::keyboard::Keyboard::KEY_TAB}, {"tab", love::keyboard::Keyboard::KEY_TAB},
+11 -4
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * in a product, an acknowledgment in the product documentation would be
@@ -44,6 +44,7 @@ namespace event
TYPE_MOUSE_RELEASED, TYPE_MOUSE_RELEASED,
TYPE_JOYSTICK_RELEASED, TYPE_JOYSTICK_RELEASED,
TYPE_JOYSTICK_PRESSED, TYPE_JOYSTICK_PRESSED,
TYPE_FOCUS,
TYPE_QUIT, TYPE_QUIT,
TYPE_MAX_ENUM = 32 TYPE_MAX_ENUM = 32
}; };
@@ -52,7 +53,7 @@ namespace event
{ {
Type type; Type type;
struct struct
{ {
Type type; Type type;
love::mouse::Mouse::Button b; love::mouse::Mouse::Button b;
@@ -73,6 +74,12 @@ namespace event
love::keyboard::Keyboard::Key k; love::keyboard::Keyboard::Key k;
unsigned short u; unsigned short u;
} keyboard; } keyboard;
struct
{
Type type;
bool f;
} focus;
}; };
virtual ~Event(); virtual ~Event();
+15 -5
View File
@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2006-2010 LOVE Development Team * Copyright (c) 2006-2010 LOVE Development Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
* arising from the use of this software. * arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any purpose, * Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it * including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions: * freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you must not * 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 * claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be * 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.button = e.jbutton.button;
m.joystick.index = e.jbutton.which; m.joystick.index = e.jbutton.which;
return true; 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: case SDL_QUIT:
m.type = Event::TYPE_QUIT; m.type = Event::TYPE_QUIT;
return true; return true;
@@ -127,6 +133,10 @@ namespace sdl
e.jbutton.which = m.joystick.index; e.jbutton.which = m.joystick.index;
e.jbutton.button = m.joystick.button; e.jbutton.button = m.joystick.button;
return true; 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: case Event::TYPE_QUIT:
e.type = SDL_QUIT; e.type = SDL_QUIT;
return true; return true;
@@ -137,7 +147,7 @@ namespace sdl
return true; 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_BACKSPACE, SDLK_BACKSPACE},
{ love::keyboard::Keyboard::KEY_TAB, SDLK_TAB}, { 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::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_LEFT, SDL_BUTTON_LEFT},
{ love::mouse::Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE}, { love::mouse::Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
+6
View File
@@ -64,6 +64,9 @@ namespace sdl
msg.joystick.index = luaL_checkint(L, 2); msg.joystick.index = luaL_checkint(L, 2);
msg.joystick.button = luaL_checkint(L, 3); msg.joystick.button = luaL_checkint(L, 3);
return true; return true;
case Event::TYPE_FOCUS:
msg.focus.f = lua_toboolean(L, 2);
return true;
case Event::TYPE_QUIT: case Event::TYPE_QUIT:
return true; return true;
default: default:
@@ -108,6 +111,9 @@ namespace sdl
lua_pushinteger(L, msg.joystick.index); lua_pushinteger(L, msg.joystick.index);
lua_pushinteger(L, msg.joystick.button); lua_pushinteger(L, msg.joystick.button);
return 3; return 3;
case Event::TYPE_FOCUS:
lua_pushboolean(L, msg.focus.f);
return 2;
case Event::TYPE_QUIT: case Event::TYPE_QUIT:
return 1; return 1;
default: default:
+3
View File
@@ -170,6 +170,9 @@ function love.createhandlers()
jr = function (j,b) jr = function (j,b)
if love.joystickreleased then love.joystickreleased(j,b) end if love.joystickreleased then love.joystickreleased(j,b) end
end, end,
f = function (f)
if love.focus then love.focus(f) end
end,
q = function () q = function ()
return return
end, end,
+947 -942
View File
File diff suppressed because it is too large Load Diff