mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -185,6 +185,9 @@ public:
|
||||
**/
|
||||
virtual void setVelocity(float *v) = 0;
|
||||
|
||||
virtual void setDopplerScale(float scale) = 0;
|
||||
virtual float getDopplerScale() const = 0;
|
||||
|
||||
/**
|
||||
* Begins recording audio input from the microphone.
|
||||
**/
|
||||
|
||||
@@ -132,6 +132,15 @@ void Audio::setVelocity(float *)
|
||||
{
|
||||
}
|
||||
|
||||
void Audio::setDopplerScale(float)
|
||||
{
|
||||
}
|
||||
|
||||
float Audio::getDopplerScale() const
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
void Audio::record()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,6 +67,9 @@ public:
|
||||
void getVelocity(float *v) const;
|
||||
void setVelocity(float *v);
|
||||
|
||||
void setDopplerScale(float scale);
|
||||
float getDopplerScale() const;
|
||||
|
||||
void record();
|
||||
love::sound::SoundData *getRecordedData();
|
||||
love::sound::SoundData *stopRecording(bool returnData);
|
||||
|
||||
@@ -256,6 +256,17 @@ void Audio::setVelocity(float *v)
|
||||
alListenerfv(AL_VELOCITY, v);
|
||||
}
|
||||
|
||||
void Audio::setDopplerScale(float scale)
|
||||
{
|
||||
if (scale >= 0.0f)
|
||||
alDopplerFactor(scale);
|
||||
}
|
||||
|
||||
float Audio::getDopplerScale() const
|
||||
{
|
||||
return alGetFloat(AL_DOPPLER_FACTOR);
|
||||
}
|
||||
|
||||
void Audio::record()
|
||||
{
|
||||
if (!canRecord()) return;
|
||||
|
||||
@@ -85,6 +85,9 @@ public:
|
||||
void getVelocity(float *v) const;
|
||||
void setVelocity(float *v);
|
||||
|
||||
void setDopplerScale(float scale);
|
||||
float getDopplerScale() const;
|
||||
|
||||
void record();
|
||||
love::sound::SoundData *getRecordedData();
|
||||
love::sound::SoundData *stopRecording(bool returnData);
|
||||
|
||||
@@ -218,6 +218,18 @@ int w_getVelocity(lua_State *L)
|
||||
return 3;
|
||||
}
|
||||
|
||||
int w_setDopplerScale(lua_State *L)
|
||||
{
|
||||
instance()->setDopplerScale(luax_checkfloat(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getDopplerScale(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, instance()->getDopplerScale());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_record(lua_State *)
|
||||
{
|
||||
instance()->record();
|
||||
@@ -299,6 +311,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getOrientation", w_getOrientation },
|
||||
{ "setVelocity", w_setVelocity },
|
||||
{ "getVelocity", w_getVelocity },
|
||||
{ "setDopplerScale", w_setDopplerScale },
|
||||
{ "getDopplerScale", w_getDopplerScale },
|
||||
/*{ "record", w_record },
|
||||
{ "getRecordedData", w_getRecordedData },
|
||||
{ "stopRecording", w_stopRecording },*/
|
||||
|
||||
@@ -47,6 +47,8 @@ int w_setOrientation(lua_State *L);
|
||||
int w_getOrientation(lua_State *L);
|
||||
int w_setVelocity(lua_State *L);
|
||||
int w_getVelocity(lua_State *L);
|
||||
int w_setDopplerScale(lua_State *L);
|
||||
int w_getDopplerScale(lua_State *L);
|
||||
int w_record(lua_State *L);
|
||||
int w_getRecordedData(lua_State *L);
|
||||
int w_stopRecording(lua_State *L);
|
||||
|
||||
@@ -30,10 +30,19 @@ namespace filesystem
|
||||
{
|
||||
|
||||
FileData::FileData(uint64 size, const std::string &filename)
|
||||
: data(new char[(size_t) size])
|
||||
: data(nullptr)
|
||||
, size((size_t) size)
|
||||
, filename(filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
data = new char[(size_t) size];
|
||||
}
|
||||
catch (std::bad_alloc &)
|
||||
{
|
||||
throw love::Exception("Out of memory.");
|
||||
}
|
||||
|
||||
if (filename.rfind('.') != std::string::npos)
|
||||
extension = filename.substr(filename.rfind('.')+1);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
|
||||
virtual Rasterizer *newRasterizer(love::filesystem::FileData *data) = 0;
|
||||
|
||||
virtual Rasterizer *newTrueTypeRasterizer(int size) = 0;
|
||||
virtual Rasterizer *newTrueTypeRasterizer(love::filesystem::FileData *data, int size) = 0;
|
||||
|
||||
virtual Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images) = 0;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,8 @@
|
||||
|
||||
#include "libraries/utf8/utf8.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
@@ -33,6 +35,9 @@ namespace font
|
||||
namespace freetype
|
||||
{
|
||||
|
||||
// Default TrueType font.
|
||||
#include "font/Vera.ttf.h"
|
||||
|
||||
Font::Font()
|
||||
{
|
||||
if (FT_Init_FreeType(&library))
|
||||
@@ -54,6 +59,16 @@ Rasterizer *Font::newRasterizer(love::filesystem::FileData *data)
|
||||
throw love::Exception("Invalid font file: %s", data->getFilename().c_str());
|
||||
}
|
||||
|
||||
Rasterizer *Font::newTrueTypeRasterizer(int size)
|
||||
{
|
||||
StrongRef<filesystem::FileData> data(new filesystem::FileData(sizeof(Vera_ttf), "Vera.ttf"));
|
||||
data->release();
|
||||
|
||||
memcpy(data->getData(), Vera_ttf, sizeof(Vera_ttf));
|
||||
|
||||
return new TrueTypeRasterizer(library, data.get(), size);
|
||||
}
|
||||
|
||||
Rasterizer *Font::newTrueTypeRasterizer(love::filesystem::FileData *data, int size)
|
||||
{
|
||||
return new TrueTypeRasterizer(library, data, size);
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
// Implements Font
|
||||
Rasterizer *newRasterizer(love::filesystem::FileData *data);
|
||||
|
||||
Rasterizer *newTrueTypeRasterizer(int size);
|
||||
Rasterizer *newTrueTypeRasterizer(love::filesystem::FileData *data, int size);
|
||||
|
||||
Rasterizer *newBMFontRasterizer(love::filesystem::FileData *fontdef, const std::vector<image::ImageData *> &images);
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2015 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_Font.h"
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
#include "font/wrap_GlyphData.h"
|
||||
#include "font/wrap_Rasterizer.h"
|
||||
|
||||
#include "filesystem/wrap_Filesystem.h"
|
||||
|
||||
#include "TrueTypeRasterizer.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
namespace freetype
|
||||
{
|
||||
|
||||
#define instance() (Module::getInstance<Font>(Module::M_FONT))
|
||||
|
||||
int w_newRasterizer(lua_State *L)
|
||||
{
|
||||
Rasterizer *t = nullptr;
|
||||
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
const char *g = luaL_checkstring(L, 2);
|
||||
std::string glyphs(g);
|
||||
luax_catchexcept(L, [&](){ t = instance()->newRasterizer(d, glyphs); });
|
||||
}
|
||||
else if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
{
|
||||
love::filesystem::FileData *d = love::filesystem::luax_getfiledata(L, 1);
|
||||
int size = luaL_checkint(L, 2);
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newRasterizer(d, size); },
|
||||
[&]() { d->release(); }
|
||||
);
|
||||
}
|
||||
else
|
||||
return luaL_argerror(L, 1, "expected ImageData, filename, or FileData");
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newGlyphData(lua_State *L)
|
||||
{
|
||||
Rasterizer *r = luax_checkrasterizer(L, 1);
|
||||
GlyphData *t = nullptr;
|
||||
|
||||
// newGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
std::string glyph = luax_checkstring(L, 2);
|
||||
luax_catchexcept(L, [&](){ t = instance()->newGlyphData(r, glyph); });
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 g = (uint32) luaL_checknumber(L, 2);
|
||||
t = instance()->newGlyphData(r, g);
|
||||
}
|
||||
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "newRasterizer", w_newRasterizer },
|
||||
{ "newGlyphData", w_newGlyphData },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] =
|
||||
{
|
||||
luaopen_glyphdata,
|
||||
luaopen_rasterizer,
|
||||
0
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_font(lua_State *L)
|
||||
{
|
||||
Font *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
luax_catchexcept(L, [&](){ instance = new Font(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "font";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
} // freetype
|
||||
} // font
|
||||
} // love
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2015 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
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_FONT_FREETYPE_WRAP_FONT_H
|
||||
#define LOVE_FONT_FREETYPE_WRAP_FONT_H
|
||||
|
||||
// LOVE
|
||||
#include "common/config.h"
|
||||
#include "common/runtime.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace font
|
||||
{
|
||||
namespace freetype
|
||||
{
|
||||
|
||||
int w_newRasterizer(lua_State *L);
|
||||
int w_newGlyphData(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_font(lua_State *L);
|
||||
|
||||
} // freetype
|
||||
} // font
|
||||
} // love
|
||||
|
||||
#endif // LOVE_FONT_FREETYPE_WRAP_FONT_H
|
||||
@@ -39,7 +39,11 @@ int w_newRasterizer(lua_State *L)
|
||||
{
|
||||
if (lua_isnoneornil(L, 2))
|
||||
{
|
||||
// Single argument: call Font::newRasterizer.
|
||||
// Single number argument: use the default TrueType font.
|
||||
if (lua_type(L, 1) == LUA_TNUMBER)
|
||||
return w_newTrueTypeRasterizer(L);
|
||||
|
||||
// Single argument of another type: call Font::newRasterizer.
|
||||
Rasterizer *t = nullptr;
|
||||
filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
|
||||
|
||||
@@ -68,13 +72,22 @@ int w_newTrueTypeRasterizer(lua_State *L)
|
||||
{
|
||||
Rasterizer *t = nullptr;
|
||||
|
||||
filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
if (lua_type(L, 1) == LUA_TNUMBER)
|
||||
{
|
||||
// First argument is a number: use the default TrueType font.
|
||||
int size = luaL_checkint(L, 1);
|
||||
luax_catchexcept(L, [&](){ t = instance()->newTrueTypeRasterizer(size); });
|
||||
}
|
||||
else
|
||||
{
|
||||
filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
|
||||
int size = luaL_optint(L, 2, 12);
|
||||
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newTrueTypeRasterizer(d, size); },
|
||||
[&]() { d->release(); }
|
||||
);
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newTrueTypeRasterizer(d, size); },
|
||||
[&]() { d->release(); }
|
||||
);
|
||||
}
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
t->release();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "Graphics.h"
|
||||
#include "window/sdl/Window.h"
|
||||
#include "font/Font.h"
|
||||
#include "Polyline.h"
|
||||
|
||||
// C++
|
||||
@@ -70,6 +71,7 @@ Graphics::~Graphics()
|
||||
{
|
||||
// We do this manually so the love objects get released before the window.
|
||||
states.clear();
|
||||
defaultFont.set(nullptr);
|
||||
|
||||
if (Shader::defaultShader)
|
||||
{
|
||||
@@ -170,6 +172,29 @@ void Graphics::restoreStateChecked(const DisplayState &s)
|
||||
setDefaultMipmapFilter(s.defaultMipmapFilter, s.defaultMipmapSharpness);
|
||||
}
|
||||
|
||||
void Graphics::checkSetDefaultFont()
|
||||
{
|
||||
// We don't create or set the default Font if an existing font is in use.
|
||||
if (states.back().font.get() != nullptr)
|
||||
return;
|
||||
|
||||
// Create a new default font if we don't have one yet.
|
||||
if (!defaultFont.get())
|
||||
{
|
||||
font::Font *fontmodule = Module::getInstance<font::Font>(M_FONT);
|
||||
if (!fontmodule)
|
||||
throw love::Exception("Font module has not been loaded.");
|
||||
|
||||
StrongRef<font::Rasterizer> r(fontmodule->newTrueTypeRasterizer(12));
|
||||
r->release();
|
||||
|
||||
defaultFont.set(newFont(r.get()));
|
||||
defaultFont->release();
|
||||
}
|
||||
|
||||
states.back().font.set(defaultFont.get());
|
||||
}
|
||||
|
||||
void Graphics::setViewportSize(int width, int height)
|
||||
{
|
||||
this->width = width;
|
||||
@@ -704,18 +729,16 @@ Color Graphics::getBackgroundColor() const
|
||||
|
||||
void Graphics::setFont(Font *font)
|
||||
{
|
||||
// Hack: the Lua-facing love.graphics.print function will set the current
|
||||
// font if needed, but only on its first call... we want to make sure a nil
|
||||
// font is never accidentally set (e.g. via love.graphics.reset.)
|
||||
if (font == nullptr)
|
||||
return;
|
||||
// We don't need to set a default font here if null is passed in, since we
|
||||
// only care about the default font in getFont and print.
|
||||
|
||||
DisplayState &state = states.back();
|
||||
state.font.set(font);
|
||||
}
|
||||
|
||||
Font *Graphics::getFont() const
|
||||
Font *Graphics::getFont()
|
||||
{
|
||||
checkSetDefaultFont();
|
||||
return states.back().font.get();
|
||||
}
|
||||
|
||||
@@ -953,6 +976,8 @@ bool Graphics::isWireframe() const
|
||||
|
||||
void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
{
|
||||
checkSetDefaultFont();
|
||||
|
||||
DisplayState &state = states.back();
|
||||
|
||||
if (state.font.get() != nullptr)
|
||||
@@ -961,6 +986,8 @@ void Graphics::print(const std::string &str, float x, float y , float angle, flo
|
||||
|
||||
void Graphics::printf(const std::string &str, float x, float y, float wrap, Font::AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||
{
|
||||
checkSetDefaultFont();
|
||||
|
||||
DisplayState &state = states.back();
|
||||
|
||||
if (state.font.get() != nullptr)
|
||||
|
||||
@@ -182,15 +182,8 @@ public:
|
||||
**/
|
||||
Color getBackgroundColor() const;
|
||||
|
||||
/**
|
||||
* Sets the current font.
|
||||
* @param font A Font object.
|
||||
**/
|
||||
void setFont(Font *font);
|
||||
/**
|
||||
* Gets the current Font, or nil if none.
|
||||
**/
|
||||
Font *getFont() const;
|
||||
Font *getFont();
|
||||
|
||||
void setShader(Shader *shader);
|
||||
void setShader();
|
||||
@@ -466,8 +459,12 @@ private:
|
||||
void restoreState(const DisplayState &s);
|
||||
void restoreStateChecked(const DisplayState &s);
|
||||
|
||||
void checkSetDefaultFont();
|
||||
|
||||
love::window::Window *currentWindow;
|
||||
|
||||
StrongRef<Font> defaultFont;
|
||||
|
||||
std::vector<double> pixel_size_stack; // stores current size of a pixel (needed for line drawing)
|
||||
|
||||
int width;
|
||||
|
||||
@@ -132,8 +132,6 @@ void OpenGL::setupContext()
|
||||
initMaxValues();
|
||||
createDefaultTexture();
|
||||
|
||||
state.lastPseudoInstanceID = -1;
|
||||
|
||||
// Invalidate the cached matrices by setting some elements to NaN.
|
||||
float nan = std::numeric_limits<float>::quiet_NaN();
|
||||
state.lastProjectionMatrix.setTranslation(nan, nan);
|
||||
@@ -276,14 +274,6 @@ void OpenGL::prepareDraw()
|
||||
// love-provided uniforms.
|
||||
shader->checkSetScreenParams();
|
||||
|
||||
// Make sure the Instance ID variable is up-to-date when
|
||||
// pseudo-instancing is used.
|
||||
if (state.lastPseudoInstanceID != 0 && shader->hasVertexAttrib(ATTRIB_PSEUDO_INSTANCE_ID))
|
||||
{
|
||||
glVertexAttrib1f((GLuint) ATTRIB_PSEUDO_INSTANCE_ID, 0.0f);
|
||||
state.lastPseudoInstanceID = 0;
|
||||
}
|
||||
|
||||
// We need to make sure antialiased Canvases are properly resolved
|
||||
// before sampling from their textures in a shader.
|
||||
// This is kind of a big hack. :(
|
||||
@@ -346,58 +336,6 @@ void OpenGL::drawElements(GLenum mode, GLsizei count, GLenum type, const void *i
|
||||
++stats.drawCalls;
|
||||
}
|
||||
|
||||
void OpenGL::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
|
||||
{
|
||||
Shader *shader = Shader::current;
|
||||
|
||||
if (GLAD_ARB_draw_instanced)
|
||||
glDrawArraysInstancedARB(mode, first, count, primcount);
|
||||
else
|
||||
{
|
||||
bool shaderHasID = shader && shader->hasVertexAttrib(ATTRIB_PSEUDO_INSTANCE_ID);
|
||||
|
||||
// Pseudo-instancing fallback.
|
||||
for (int i = 0; i < primcount; i++)
|
||||
{
|
||||
if (shaderHasID)
|
||||
glVertexAttrib1f((GLuint) ATTRIB_PSEUDO_INSTANCE_ID, (GLfloat) i);
|
||||
|
||||
glDrawArrays(mode, first, count);
|
||||
}
|
||||
|
||||
if (shaderHasID)
|
||||
state.lastPseudoInstanceID = primcount - 1;
|
||||
}
|
||||
|
||||
++stats.drawCalls;
|
||||
}
|
||||
|
||||
void OpenGL::drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount)
|
||||
{
|
||||
Shader *shader = Shader::current;
|
||||
|
||||
if (GLAD_ARB_draw_instanced)
|
||||
glDrawElementsInstancedARB(mode, count, type, indices, primcount);
|
||||
else
|
||||
{
|
||||
bool shaderHasID = shader && shader->hasVertexAttrib(ATTRIB_PSEUDO_INSTANCE_ID);
|
||||
|
||||
// Pseudo-instancing fallback.
|
||||
for (int i = 0; i < primcount; i++)
|
||||
{
|
||||
if (shaderHasID)
|
||||
glVertexAttrib1f((GLuint) ATTRIB_PSEUDO_INSTANCE_ID, (GLfloat) i);
|
||||
|
||||
glDrawElements(mode, count, type, indices);
|
||||
}
|
||||
|
||||
if (shaderHasID)
|
||||
state.lastPseudoInstanceID = primcount - 1;
|
||||
}
|
||||
|
||||
++stats.drawCalls;
|
||||
}
|
||||
|
||||
void OpenGL::setColor(const Color &c)
|
||||
{
|
||||
GLfloat glc[] = {c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f};
|
||||
|
||||
@@ -187,13 +187,6 @@ public:
|
||||
void drawArrays(GLenum mode, GLint first, GLsizei count);
|
||||
void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices);
|
||||
|
||||
/**
|
||||
* glDrawArraysInstanced and glDrawElementsInstanced with pseudo-instancing
|
||||
* fallbacks. They also increment the draw-call counter (once per call).
|
||||
**/
|
||||
void drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount);
|
||||
void drawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei primcount);
|
||||
|
||||
/**
|
||||
* Sets the current constant color.
|
||||
**/
|
||||
@@ -369,9 +362,6 @@ private:
|
||||
|
||||
BlendState blend;
|
||||
|
||||
// The last ID value used for pseudo-instancing.
|
||||
int lastPseudoInstanceID;
|
||||
|
||||
Matrix lastProjectionMatrix;
|
||||
Matrix lastTransformMatrix;
|
||||
|
||||
|
||||
@@ -655,6 +655,14 @@ int w_getBackgroundColor(lua_State *L)
|
||||
return 4;
|
||||
}
|
||||
|
||||
int w_setNewFont(lua_State *L)
|
||||
{
|
||||
int ret = w_newFont(L);
|
||||
Font *font = luax_checktype<Font>(L, -1, "Font", GRAPHICS_FONT_T);
|
||||
instance()->setFont(font);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int w_setFont(lua_State *L)
|
||||
{
|
||||
Font *font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
|
||||
@@ -664,10 +672,8 @@ int w_setFont(lua_State *L)
|
||||
|
||||
int w_getFont(lua_State *L)
|
||||
{
|
||||
Font *f = instance()->getFont();
|
||||
|
||||
if (f == 0)
|
||||
return 0;
|
||||
Font *f = nullptr;
|
||||
luax_catchexcept(L, [&](){ f = instance()->getFont(); });
|
||||
|
||||
luax_pushtype(L, "Font", GRAPHICS_FONT_T, f);
|
||||
return 1;
|
||||
@@ -1461,6 +1467,7 @@ static const luaL_Reg functions[] =
|
||||
{ "setBackgroundColor", w_setBackgroundColor },
|
||||
{ "getBackgroundColor", w_getBackgroundColor },
|
||||
|
||||
{ "setNewFont", w_setNewFont },
|
||||
{ "setFont", w_setFont },
|
||||
{ "getFont", w_getFont },
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ int w_setColor(lua_State *L);
|
||||
int w_getColor(lua_State *L);
|
||||
int w_setBackgroundColor(lua_State *L);
|
||||
int w_getBackgroundColor(lua_State *L);
|
||||
int w_setNewFont(lua_State *L);
|
||||
int w_setFont(lua_State *L);
|
||||
int w_getFont(lua_State *L);
|
||||
int w_setColorMask(lua_State *L);
|
||||
|
||||
@@ -27,18 +27,30 @@ namespace love
|
||||
namespace keyboard
|
||||
{
|
||||
|
||||
bool Keyboard::getConstant(const char *in, Keyboard::Key &out)
|
||||
bool Keyboard::getConstant(const char *in, Key &out)
|
||||
{
|
||||
return keys.find(in, out);
|
||||
}
|
||||
|
||||
bool Keyboard::getConstant(Keyboard::Key in, const char *&out)
|
||||
bool Keyboard::getConstant(Key in, const char *&out)
|
||||
{
|
||||
return keys.find(in, out);
|
||||
}
|
||||
|
||||
bool Keyboard::getConstant(const char *in, Scancode &out)
|
||||
{
|
||||
return scancodes.find(in, out);
|
||||
}
|
||||
|
||||
bool Keyboard::getConstant(Scancode in, const char *&out)
|
||||
{
|
||||
return scancodes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
|
||||
{
|
||||
{"unknown", Keyboard::KEY_UNKNOWN},
|
||||
|
||||
{"return", Keyboard::KEY_RETURN},
|
||||
{"escape", Keyboard::KEY_ESCAPE},
|
||||
{"backspace", Keyboard::KEY_BACKSPACE},
|
||||
@@ -244,6 +256,269 @@ StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM>::Entry Keyboard::keyEntries[] =
|
||||
|
||||
StringMap<Keyboard::Key, Keyboard::KEY_MAX_ENUM> Keyboard::keys(Keyboard::keyEntries, sizeof(Keyboard::keyEntries));
|
||||
|
||||
StringMap<Keyboard::Scancode, Keyboard::SCANCODE_MAX_ENUM>::Entry Keyboard::scancodeEntries[] =
|
||||
{
|
||||
{"unknown", SCANCODE_UNKNOWN},
|
||||
|
||||
{"a", SCANCODE_A},
|
||||
{"b", SCANCODE_B},
|
||||
{"c", SCANCODE_C},
|
||||
{"d", SCANCODE_D},
|
||||
{"e", SCANCODE_E},
|
||||
{"f", SCANCODE_F},
|
||||
{"g", SCANCODE_G},
|
||||
{"h", SCANCODE_H},
|
||||
{"i", SCANCODE_I},
|
||||
{"j", SCANCODE_J},
|
||||
{"k", SCANCODE_K},
|
||||
{"l", SCANCODE_L},
|
||||
{"m", SCANCODE_M},
|
||||
{"n", SCANCODE_N},
|
||||
{"o", SCANCODE_O},
|
||||
{"p", SCANCODE_P},
|
||||
{"q", SCANCODE_Q},
|
||||
{"r", SCANCODE_R},
|
||||
{"s", SCANCODE_S},
|
||||
{"t", SCANCODE_T},
|
||||
{"u", SCANCODE_U},
|
||||
{"v", SCANCODE_V},
|
||||
{"w", SCANCODE_W},
|
||||
{"x", SCANCODE_X},
|
||||
{"y", SCANCODE_Y},
|
||||
{"z", SCANCODE_Z},
|
||||
|
||||
{"1", SCANCODE_1},
|
||||
{"2", SCANCODE_2},
|
||||
{"3", SCANCODE_3},
|
||||
{"4", SCANCODE_4},
|
||||
{"5", SCANCODE_5},
|
||||
{"6", SCANCODE_6},
|
||||
{"7", SCANCODE_7},
|
||||
{"8", SCANCODE_8},
|
||||
{"9", SCANCODE_9},
|
||||
{"0", SCANCODE_0},
|
||||
|
||||
{"return", SCANCODE_RETURN},
|
||||
{"escape", SCANCODE_ESCAPE},
|
||||
{"backspace", SCANCODE_BACKSPACE},
|
||||
{"tab", SCANCODE_TAB},
|
||||
{" ", SCANCODE_SPACE},
|
||||
|
||||
{"-", SCANCODE_MINUS},
|
||||
{"=", SCANCODE_EQUALS},
|
||||
{"[", SCANCODE_LEFTBRACKET},
|
||||
{"]", SCANCODE_RIGHTBRACKET},
|
||||
{"\\", SCANCODE_BACKSLASH},
|
||||
{"nonus#", SCANCODE_NONUSHASH},
|
||||
{";", SCANCODE_SEMICOLON},
|
||||
{"'", SCANCODE_APOSTROPHE},
|
||||
{"`", SCANCODE_GRAVE},
|
||||
{",", SCANCODE_COMMA},
|
||||
{".", SCANCODE_PERIOD},
|
||||
{"/", SCANCODE_SLASH},
|
||||
|
||||
{"capslock", SCANCODE_CAPSLOCK},
|
||||
|
||||
{"f1", SCANCODE_F1},
|
||||
{"f2", SCANCODE_F2},
|
||||
{"f3", SCANCODE_F3},
|
||||
{"f4", SCANCODE_F4},
|
||||
{"f5", SCANCODE_F5},
|
||||
{"f6", SCANCODE_F6},
|
||||
{"f7", SCANCODE_F7},
|
||||
{"f8", SCANCODE_F8},
|
||||
{"f9", SCANCODE_F9},
|
||||
{"f10", SCANCODE_F10},
|
||||
{"f11", SCANCODE_F11},
|
||||
{"f12", SCANCODE_F12},
|
||||
|
||||
{"printscreen", SCANCODE_PRINTSCREEN},
|
||||
{"scrolllock", SCANCODE_SCROLLLOCK},
|
||||
{"pause", SCANCODE_PAUSE},
|
||||
{"insert", SCANCODE_INSERT},
|
||||
{"home", SCANCODE_HOME},
|
||||
{"pageup", SCANCODE_PAGEUP},
|
||||
{"delete", SCANCODE_DELETE},
|
||||
{"end", SCANCODE_END},
|
||||
{"pagedown", SCANCODE_PAGEDOWN},
|
||||
{"right", SCANCODE_RIGHT},
|
||||
{"left", SCANCODE_LEFT},
|
||||
{"down", SCANCODE_DOWN},
|
||||
{"up", SCANCODE_UP},
|
||||
|
||||
{"numlock", SCANCODE_NUMLOCKCLEAR},
|
||||
{"kp/", SCANCODE_KP_DIVIDE},
|
||||
{"kp*", SCANCODE_KP_MULTIPLY},
|
||||
{"kp-", SCANCODE_KP_MINUS},
|
||||
{"kp+", SCANCODE_KP_PLUS},
|
||||
{"kpenter", SCANCODE_KP_ENTER},
|
||||
{"kp1", SCANCODE_KP_1},
|
||||
{"kp2", SCANCODE_KP_2},
|
||||
{"kp3", SCANCODE_KP_3},
|
||||
{"kp4", SCANCODE_KP_4},
|
||||
{"kp5", SCANCODE_KP_5},
|
||||
{"kp6", SCANCODE_KP_6},
|
||||
{"kp7", SCANCODE_KP_7},
|
||||
{"kp8", SCANCODE_KP_8},
|
||||
{"kp9", SCANCODE_KP_9},
|
||||
{"kp0", SCANCODE_KP_0},
|
||||
{"kp.", SCANCODE_KP_PERIOD},
|
||||
|
||||
{"nonusbackslash", SCANCODE_NONUSBACKSLASH},
|
||||
{"application", SCANCODE_APPLICATION},
|
||||
{"power", SCANCODE_POWER},
|
||||
{"=", SCANCODE_KP_EQUALS},
|
||||
{"f13", SCANCODE_F13},
|
||||
{"f14", SCANCODE_F14},
|
||||
{"f15", SCANCODE_F15},
|
||||
{"f16", SCANCODE_F16},
|
||||
{"f17", SCANCODE_F17},
|
||||
{"f18", SCANCODE_F18},
|
||||
{"f19", SCANCODE_F19},
|
||||
{"f20", SCANCODE_F20},
|
||||
{"f21", SCANCODE_F21},
|
||||
{"f22", SCANCODE_F22},
|
||||
{"f23", SCANCODE_F23},
|
||||
{"f24", SCANCODE_F24},
|
||||
{"execute", SCANCODE_EXECUTE},
|
||||
{"help", SCANCODE_HELP},
|
||||
{"menu", SCANCODE_MENU},
|
||||
{"select", SCANCODE_SELECT},
|
||||
{"stop", SCANCODE_STOP},
|
||||
{"again", SCANCODE_AGAIN},
|
||||
{"undo", SCANCODE_UNDO},
|
||||
{"cut", SCANCODE_CUT},
|
||||
{"copy", SCANCODE_COPY},
|
||||
{"paste", SCANCODE_PASTE},
|
||||
{"find", SCANCODE_FIND},
|
||||
{"mute", SCANCODE_MUTE},
|
||||
{"volumeup", SCANCODE_VOLUMEUP},
|
||||
{"volumedown", SCANCODE_VOLUMEDOWN},
|
||||
{"kp,", SCANCODE_KP_COMMA},
|
||||
{"kp=400", SCANCODE_KP_EQUALSAS400},
|
||||
|
||||
{"international1", SCANCODE_INTERNATIONAL1},
|
||||
{"international2", SCANCODE_INTERNATIONAL2},
|
||||
{"international3", SCANCODE_INTERNATIONAL3},
|
||||
{"international4", SCANCODE_INTERNATIONAL4},
|
||||
{"international5", SCANCODE_INTERNATIONAL5},
|
||||
{"international6", SCANCODE_INTERNATIONAL6},
|
||||
{"international7", SCANCODE_INTERNATIONAL7},
|
||||
{"international8", SCANCODE_INTERNATIONAL8},
|
||||
{"international9", SCANCODE_INTERNATIONAL9},
|
||||
{"lang1", SCANCODE_LANG1},
|
||||
{"lang2", SCANCODE_LANG2},
|
||||
{"lang3", SCANCODE_LANG3},
|
||||
{"lang4", SCANCODE_LANG4},
|
||||
{"lang5", SCANCODE_LANG5},
|
||||
{"lang6", SCANCODE_LANG6},
|
||||
{"lang7", SCANCODE_LANG7},
|
||||
{"lang8", SCANCODE_LANG8},
|
||||
{"lang9", SCANCODE_LANG9},
|
||||
|
||||
{"alterase", SCANCODE_ALTERASE},
|
||||
{"sysreq", SCANCODE_SYSREQ},
|
||||
{"cancel", SCANCODE_CANCEL},
|
||||
{"clear", SCANCODE_CLEAR},
|
||||
{"prior", SCANCODE_PRIOR},
|
||||
{"return2", SCANCODE_RETURN2},
|
||||
{"separator", SCANCODE_SEPARATOR},
|
||||
{"out", SCANCODE_OUT},
|
||||
{"oper", SCANCODE_OPER},
|
||||
{"clearagain", SCANCODE_CLEARAGAIN},
|
||||
{"crsel", SCANCODE_CRSEL},
|
||||
{"exsel", SCANCODE_EXSEL},
|
||||
|
||||
{"kp00", SCANCODE_KP_00},
|
||||
{"kp000", SCANCODE_KP_000},
|
||||
{"thsousandsseparator", SCANCODE_THOUSANDSSEPARATOR},
|
||||
{"decimalseparator", SCANCODE_DECIMALSEPARATOR},
|
||||
{"currencyunit", SCANCODE_CURRENCYUNIT},
|
||||
{"currencysubunit", SCANCODE_CURRENCYSUBUNIT},
|
||||
{"kp(", SCANCODE_KP_LEFTPAREN},
|
||||
{"kp)", SCANCODE_KP_RIGHTPAREN},
|
||||
{"kp{", SCANCODE_KP_LEFTBRACE},
|
||||
{"kp}", SCANCODE_KP_RIGHTBRACE},
|
||||
{"kptab", SCANCODE_KP_TAB},
|
||||
{"kpbackspace", SCANCODE_KP_BACKSPACE},
|
||||
{"kpa", SCANCODE_KP_A},
|
||||
{"kpb", SCANCODE_KP_B},
|
||||
{"kpc", SCANCODE_KP_C},
|
||||
{"kpd", SCANCODE_KP_D},
|
||||
{"kpe", SCANCODE_KP_E},
|
||||
{"kpf", SCANCODE_KP_F},
|
||||
{"kpxor", SCANCODE_KP_XOR},
|
||||
{"kpower", SCANCODE_KP_POWER},
|
||||
{"kp%", SCANCODE_KP_PERCENT},
|
||||
{"kp<", SCANCODE_KP_LESS},
|
||||
{"kp>", SCANCODE_KP_GREATER},
|
||||
{"kp&", SCANCODE_KP_AMPERSAND},
|
||||
{"kp&&", SCANCODE_KP_DBLAMPERSAND},
|
||||
{"kp|", SCANCODE_KP_VERTICALBAR},
|
||||
{"kp||", SCANCODE_KP_DBLVERTICALBAR},
|
||||
{"kp:", SCANCODE_KP_COLON},
|
||||
{"kp#", SCANCODE_KP_HASH},
|
||||
{"kp ", SCANCODE_KP_SPACE},
|
||||
{"kp@", SCANCODE_KP_AT},
|
||||
{"kp!", SCANCODE_KP_EXCLAM},
|
||||
{"kpmemstore", SCANCODE_KP_MEMSTORE},
|
||||
{"kpmemrecall", SCANCODE_KP_MEMRECALL},
|
||||
{"kpmemclear", SCANCODE_KP_MEMCLEAR},
|
||||
{"kpmem+", SCANCODE_KP_MEMADD},
|
||||
{"kpmem-", SCANCODE_KP_MEMSUBTRACT},
|
||||
{"kpmem*", SCANCODE_KP_MEMMULTIPLY},
|
||||
{"kpmem/", SCANCODE_KP_MEMDIVIDE},
|
||||
{"kp+-", SCANCODE_KP_PLUSMINUS},
|
||||
{"kpclear", SCANCODE_KP_CLEAR},
|
||||
{"kpclearentry", SCANCODE_KP_CLEARENTRY},
|
||||
{"kpbinary", SCANCODE_KP_BINARY},
|
||||
{"kpoctal", SCANCODE_KP_OCTAL},
|
||||
{"kpdecimal", SCANCODE_KP_DECIMAL},
|
||||
{"kphex", SCANCODE_KP_HEXADECIMAL},
|
||||
|
||||
{"lctrl", SCANCODE_LCTRL},
|
||||
{"lshift", SCANCODE_LSHIFT},
|
||||
{"lalt", SCANCODE_LALT},
|
||||
{"lgui", SCANCODE_LGUI},
|
||||
{"rctrl", SCANCODE_RCTRL},
|
||||
{"rshift", SCANCODE_RSHIFT},
|
||||
{"ralt", SCANCODE_RALT},
|
||||
{"rgui", SCANCODE_RGUI},
|
||||
|
||||
{"mode", SCANCODE_MODE},
|
||||
|
||||
{"audionext", SCANCODE_AUDIONEXT},
|
||||
{"audioprev", SCANCODE_AUDIOPREV},
|
||||
{"audiostop", SCANCODE_AUDIOSTOP},
|
||||
{"audioplay", SCANCODE_AUDIOPLAY},
|
||||
{"audiomute", SCANCODE_AUDIOMUTE},
|
||||
{"mediaselect", SCANCODE_MEDIASELECT},
|
||||
{"www", SCANCODE_WWW},
|
||||
{"mail", SCANCODE_MAIL},
|
||||
{"calculator", SCANCODE_CALCULATOR},
|
||||
{"computer", SCANCODE_COMPUTER},
|
||||
{"acsearch", SCANCODE_AC_SEARCH},
|
||||
{"achome", SCANCODE_AC_HOME},
|
||||
{"acback", SCANCODE_AC_BACK},
|
||||
{"acforward", SCANCODE_AC_FORWARD},
|
||||
{"acstop", SCANCODE_AC_STOP},
|
||||
{"acrefresh", SCANCODE_AC_REFRESH},
|
||||
{"acbookmarks", SCANCODE_AC_BOOKMARKS},
|
||||
|
||||
{"brightnessdown", SCANCODE_BRIGHTNESSDOWN},
|
||||
{"brightnessup", SCANCODE_BRIGHTNESSUP},
|
||||
{"displayswitch", SCANCODE_DISPLAYSWITCH},
|
||||
{"kbdillumtoggle", SCANCODE_KBDILLUMTOGGLE},
|
||||
{"kbdillumdown", SCANCODE_KBDILLUMDOWN},
|
||||
{"kbdillumup", SCANCODE_KBDILLUMUP},
|
||||
{"eject", SCANCODE_EJECT},
|
||||
{"sleep", SCANCODE_SLEEP},
|
||||
|
||||
{"app1", SCANCODE_APP1},
|
||||
{"app2", SCANCODE_APP2},
|
||||
};
|
||||
|
||||
StringMap<Keyboard::Scancode, Keyboard::SCANCODE_MAX_ENUM> Keyboard::scancodes(Keyboard::scancodeEntries, sizeof(Keyboard::scancodeEntries));
|
||||
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
@@ -34,6 +34,9 @@ class Keyboard : public Module
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Keyboard keys. They are dependent on the current layout of the keyboard.
|
||||
**/
|
||||
enum Key
|
||||
{
|
||||
KEY_UNKNOWN,
|
||||
@@ -244,6 +247,275 @@ public:
|
||||
KEY_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* Scancodes represent physical keys independent of the current layout.
|
||||
* Their names may not match the names of the keys printed on the keyboard.
|
||||
* Some of them are very esoteric...
|
||||
**/
|
||||
enum Scancode
|
||||
{
|
||||
SCANCODE_UNKNOWN,
|
||||
|
||||
SCANCODE_A,
|
||||
SCANCODE_B,
|
||||
SCANCODE_C,
|
||||
SCANCODE_D,
|
||||
SCANCODE_E,
|
||||
SCANCODE_F,
|
||||
SCANCODE_G,
|
||||
SCANCODE_H,
|
||||
SCANCODE_I,
|
||||
SCANCODE_J,
|
||||
SCANCODE_K,
|
||||
SCANCODE_L,
|
||||
SCANCODE_M,
|
||||
SCANCODE_N,
|
||||
SCANCODE_O,
|
||||
SCANCODE_P,
|
||||
SCANCODE_Q,
|
||||
SCANCODE_R,
|
||||
SCANCODE_S,
|
||||
SCANCODE_T,
|
||||
SCANCODE_U,
|
||||
SCANCODE_V,
|
||||
SCANCODE_W,
|
||||
SCANCODE_X,
|
||||
SCANCODE_Y,
|
||||
SCANCODE_Z,
|
||||
|
||||
SCANCODE_1,
|
||||
SCANCODE_2,
|
||||
SCANCODE_3,
|
||||
SCANCODE_4,
|
||||
SCANCODE_5,
|
||||
SCANCODE_6,
|
||||
SCANCODE_7,
|
||||
SCANCODE_8,
|
||||
SCANCODE_9,
|
||||
SCANCODE_0,
|
||||
|
||||
SCANCODE_RETURN,
|
||||
SCANCODE_ESCAPE,
|
||||
SCANCODE_BACKSPACE,
|
||||
SCANCODE_TAB,
|
||||
SCANCODE_SPACE,
|
||||
|
||||
SCANCODE_MINUS,
|
||||
SCANCODE_EQUALS,
|
||||
SCANCODE_LEFTBRACKET,
|
||||
SCANCODE_RIGHTBRACKET,
|
||||
SCANCODE_BACKSLASH,
|
||||
SCANCODE_NONUSHASH,
|
||||
SCANCODE_SEMICOLON,
|
||||
SCANCODE_APOSTROPHE,
|
||||
SCANCODE_GRAVE,
|
||||
SCANCODE_COMMA,
|
||||
SCANCODE_PERIOD,
|
||||
SCANCODE_SLASH,
|
||||
|
||||
SCANCODE_CAPSLOCK,
|
||||
|
||||
SCANCODE_F1,
|
||||
SCANCODE_F2,
|
||||
SCANCODE_F3,
|
||||
SCANCODE_F4,
|
||||
SCANCODE_F5,
|
||||
SCANCODE_F6,
|
||||
SCANCODE_F7,
|
||||
SCANCODE_F8,
|
||||
SCANCODE_F9,
|
||||
SCANCODE_F10,
|
||||
SCANCODE_F11,
|
||||
SCANCODE_F12,
|
||||
|
||||
SCANCODE_PRINTSCREEN,
|
||||
SCANCODE_SCROLLLOCK,
|
||||
SCANCODE_PAUSE,
|
||||
SCANCODE_INSERT,
|
||||
SCANCODE_HOME,
|
||||
SCANCODE_PAGEUP,
|
||||
SCANCODE_DELETE,
|
||||
SCANCODE_END,
|
||||
SCANCODE_PAGEDOWN,
|
||||
SCANCODE_RIGHT,
|
||||
SCANCODE_LEFT,
|
||||
SCANCODE_DOWN,
|
||||
SCANCODE_UP,
|
||||
|
||||
SCANCODE_NUMLOCKCLEAR,
|
||||
SCANCODE_KP_DIVIDE,
|
||||
SCANCODE_KP_MULTIPLY,
|
||||
SCANCODE_KP_MINUS,
|
||||
SCANCODE_KP_PLUS,
|
||||
SCANCODE_KP_ENTER,
|
||||
SCANCODE_KP_1,
|
||||
SCANCODE_KP_2,
|
||||
SCANCODE_KP_3,
|
||||
SCANCODE_KP_4,
|
||||
SCANCODE_KP_5,
|
||||
SCANCODE_KP_6,
|
||||
SCANCODE_KP_7,
|
||||
SCANCODE_KP_8,
|
||||
SCANCODE_KP_9,
|
||||
SCANCODE_KP_0,
|
||||
SCANCODE_KP_PERIOD,
|
||||
|
||||
SCANCODE_NONUSBACKSLASH,
|
||||
SCANCODE_APPLICATION,
|
||||
SCANCODE_POWER,
|
||||
SCANCODE_KP_EQUALS,
|
||||
SCANCODE_F13,
|
||||
SCANCODE_F14,
|
||||
SCANCODE_F15,
|
||||
SCANCODE_F16,
|
||||
SCANCODE_F17,
|
||||
SCANCODE_F18,
|
||||
SCANCODE_F19,
|
||||
SCANCODE_F20,
|
||||
SCANCODE_F21,
|
||||
SCANCODE_F22,
|
||||
SCANCODE_F23,
|
||||
SCANCODE_F24,
|
||||
SCANCODE_EXECUTE,
|
||||
SCANCODE_HELP,
|
||||
SCANCODE_MENU,
|
||||
SCANCODE_SELECT,
|
||||
SCANCODE_STOP,
|
||||
SCANCODE_AGAIN,
|
||||
SCANCODE_UNDO,
|
||||
SCANCODE_CUT,
|
||||
SCANCODE_COPY,
|
||||
SCANCODE_PASTE,
|
||||
SCANCODE_FIND,
|
||||
SCANCODE_MUTE,
|
||||
SCANCODE_VOLUMEUP,
|
||||
SCANCODE_VOLUMEDOWN,
|
||||
SCANCODE_KP_COMMA,
|
||||
SCANCODE_KP_EQUALSAS400,
|
||||
|
||||
SCANCODE_INTERNATIONAL1,
|
||||
SCANCODE_INTERNATIONAL2,
|
||||
SCANCODE_INTERNATIONAL3,
|
||||
SCANCODE_INTERNATIONAL4,
|
||||
SCANCODE_INTERNATIONAL5,
|
||||
SCANCODE_INTERNATIONAL6,
|
||||
SCANCODE_INTERNATIONAL7,
|
||||
SCANCODE_INTERNATIONAL8,
|
||||
SCANCODE_INTERNATIONAL9,
|
||||
SCANCODE_LANG1,
|
||||
SCANCODE_LANG2,
|
||||
SCANCODE_LANG3,
|
||||
SCANCODE_LANG4,
|
||||
SCANCODE_LANG5,
|
||||
SCANCODE_LANG6,
|
||||
SCANCODE_LANG7,
|
||||
SCANCODE_LANG8,
|
||||
SCANCODE_LANG9,
|
||||
|
||||
SCANCODE_ALTERASE,
|
||||
SCANCODE_SYSREQ,
|
||||
SCANCODE_CANCEL,
|
||||
SCANCODE_CLEAR,
|
||||
SCANCODE_PRIOR,
|
||||
SCANCODE_RETURN2,
|
||||
SCANCODE_SEPARATOR,
|
||||
SCANCODE_OUT,
|
||||
SCANCODE_OPER,
|
||||
SCANCODE_CLEARAGAIN,
|
||||
SCANCODE_CRSEL,
|
||||
SCANCODE_EXSEL,
|
||||
|
||||
SCANCODE_KP_00,
|
||||
SCANCODE_KP_000,
|
||||
SCANCODE_THOUSANDSSEPARATOR,
|
||||
SCANCODE_DECIMALSEPARATOR,
|
||||
SCANCODE_CURRENCYUNIT,
|
||||
SCANCODE_CURRENCYSUBUNIT,
|
||||
SCANCODE_KP_LEFTPAREN,
|
||||
SCANCODE_KP_RIGHTPAREN,
|
||||
SCANCODE_KP_LEFTBRACE,
|
||||
SCANCODE_KP_RIGHTBRACE,
|
||||
SCANCODE_KP_TAB,
|
||||
SCANCODE_KP_BACKSPACE,
|
||||
SCANCODE_KP_A,
|
||||
SCANCODE_KP_B,
|
||||
SCANCODE_KP_C,
|
||||
SCANCODE_KP_D,
|
||||
SCANCODE_KP_E,
|
||||
SCANCODE_KP_F,
|
||||
SCANCODE_KP_XOR,
|
||||
SCANCODE_KP_POWER,
|
||||
SCANCODE_KP_PERCENT,
|
||||
SCANCODE_KP_LESS,
|
||||
SCANCODE_KP_GREATER,
|
||||
SCANCODE_KP_AMPERSAND,
|
||||
SCANCODE_KP_DBLAMPERSAND,
|
||||
SCANCODE_KP_VERTICALBAR,
|
||||
SCANCODE_KP_DBLVERTICALBAR,
|
||||
SCANCODE_KP_COLON,
|
||||
SCANCODE_KP_HASH,
|
||||
SCANCODE_KP_SPACE,
|
||||
SCANCODE_KP_AT,
|
||||
SCANCODE_KP_EXCLAM,
|
||||
SCANCODE_KP_MEMSTORE,
|
||||
SCANCODE_KP_MEMRECALL,
|
||||
SCANCODE_KP_MEMCLEAR,
|
||||
SCANCODE_KP_MEMADD,
|
||||
SCANCODE_KP_MEMSUBTRACT,
|
||||
SCANCODE_KP_MEMMULTIPLY,
|
||||
SCANCODE_KP_MEMDIVIDE,
|
||||
SCANCODE_KP_PLUSMINUS,
|
||||
SCANCODE_KP_CLEAR,
|
||||
SCANCODE_KP_CLEARENTRY,
|
||||
SCANCODE_KP_BINARY,
|
||||
SCANCODE_KP_OCTAL,
|
||||
SCANCODE_KP_DECIMAL,
|
||||
SCANCODE_KP_HEXADECIMAL,
|
||||
|
||||
SCANCODE_LCTRL,
|
||||
SCANCODE_LSHIFT,
|
||||
SCANCODE_LALT,
|
||||
SCANCODE_LGUI,
|
||||
SCANCODE_RCTRL,
|
||||
SCANCODE_RSHIFT,
|
||||
SCANCODE_RALT,
|
||||
SCANCODE_RGUI,
|
||||
|
||||
SCANCODE_MODE,
|
||||
|
||||
SCANCODE_AUDIONEXT,
|
||||
SCANCODE_AUDIOPREV,
|
||||
SCANCODE_AUDIOSTOP,
|
||||
SCANCODE_AUDIOPLAY,
|
||||
SCANCODE_AUDIOMUTE,
|
||||
SCANCODE_MEDIASELECT,
|
||||
SCANCODE_WWW,
|
||||
SCANCODE_MAIL,
|
||||
SCANCODE_CALCULATOR,
|
||||
SCANCODE_COMPUTER,
|
||||
SCANCODE_AC_SEARCH,
|
||||
SCANCODE_AC_HOME,
|
||||
SCANCODE_AC_BACK,
|
||||
SCANCODE_AC_FORWARD,
|
||||
SCANCODE_AC_STOP,
|
||||
SCANCODE_AC_REFRESH,
|
||||
SCANCODE_AC_BOOKMARKS,
|
||||
|
||||
SCANCODE_BRIGHTNESSDOWN,
|
||||
SCANCODE_BRIGHTNESSUP,
|
||||
SCANCODE_DISPLAYSWITCH,
|
||||
SCANCODE_KBDILLUMTOGGLE,
|
||||
SCANCODE_KBDILLUMDOWN,
|
||||
SCANCODE_KBDILLUMUP,
|
||||
SCANCODE_EJECT,
|
||||
SCANCODE_SLEEP,
|
||||
|
||||
SCANCODE_APP1,
|
||||
SCANCODE_APP2,
|
||||
|
||||
SCANCODE_MAX_ENUM
|
||||
};
|
||||
|
||||
virtual ~Keyboard() {}
|
||||
|
||||
// Implements Module.
|
||||
@@ -268,6 +540,18 @@ public:
|
||||
**/
|
||||
virtual bool isDown(Key *keylist) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the key corresponding to the specified scancode according to the
|
||||
* current keyboard layout.
|
||||
**/
|
||||
virtual Key getKeyFromScancode(Scancode scancode) const = 0;
|
||||
|
||||
/**
|
||||
* Gets the scancode corresponding to the specified key according to the
|
||||
* current keyboard layout.
|
||||
**/
|
||||
virtual Scancode getScancodeFromKey(Key key) const = 0;
|
||||
|
||||
/**
|
||||
* Sets whether text input events should be sent
|
||||
* @param enable Whether to send text input events.
|
||||
@@ -280,13 +564,19 @@ public:
|
||||
virtual bool hasTextInput() const = 0;
|
||||
|
||||
static bool getConstant(const char *in, Key &out);
|
||||
static bool getConstant(Key in, const char *&out);
|
||||
static bool getConstant(Key in, const char *&out);
|
||||
|
||||
static bool getConstant(const char *in, Scancode &out);
|
||||
static bool getConstant(Scancode in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Key, KEY_MAX_ENUM>::Entry keyEntries[];
|
||||
static StringMap<Key, KEY_MAX_ENUM> keys;
|
||||
|
||||
static StringMap<Scancode, SCANCODE_MAX_ENUM>::Entry scancodeEntries[];
|
||||
static StringMap<Scancode, SCANCODE_MAX_ENUM> scancodes;
|
||||
|
||||
}; // Keyboard
|
||||
|
||||
} // keyboard
|
||||
|
||||
@@ -61,6 +61,37 @@ bool Keyboard::isDown(Key *keylist) const
|
||||
return false;
|
||||
}
|
||||
|
||||
Keyboard::Key Keyboard::getKeyFromScancode(Scancode scancode) const
|
||||
{
|
||||
SDL_Scancode sdlscancode = SDL_SCANCODE_UNKNOWN;
|
||||
scancodes.find(scancode, sdlscancode);
|
||||
|
||||
SDL_Keycode sdlkey = SDL_GetKeyFromScancode(sdlscancode);
|
||||
|
||||
for (int i = 0; i < KEY_MAX_ENUM; i++)
|
||||
{
|
||||
if (keymap[i] == sdlkey)
|
||||
return (Key) i;
|
||||
}
|
||||
|
||||
return KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
Keyboard::Scancode Keyboard::getScancodeFromKey(Key key) const
|
||||
{
|
||||
Scancode scancode = SCANCODE_UNKNOWN;
|
||||
|
||||
if (key != KEY_MAX_ENUM)
|
||||
{
|
||||
SDL_Keycode sdlkey = keymap[key];
|
||||
|
||||
SDL_Scancode sdlscancode = SDL_GetScancodeFromKey(sdlkey);
|
||||
scancodes.find(sdlscancode, scancode);
|
||||
}
|
||||
|
||||
return scancode;
|
||||
}
|
||||
|
||||
void Keyboard::setTextInput(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
@@ -288,6 +319,270 @@ const SDL_Keycode *Keyboard::createKeyMap()
|
||||
|
||||
const SDL_Keycode *Keyboard::keymap = Keyboard::createKeyMap();
|
||||
|
||||
EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry Keyboard::scancodeEntries[] =
|
||||
{
|
||||
{SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN},
|
||||
|
||||
{SCANCODE_A, SDL_SCANCODE_A},
|
||||
{SCANCODE_B, SDL_SCANCODE_B},
|
||||
{SCANCODE_C, SDL_SCANCODE_C},
|
||||
{SCANCODE_D, SDL_SCANCODE_D},
|
||||
{SCANCODE_E, SDL_SCANCODE_E},
|
||||
{SCANCODE_F, SDL_SCANCODE_F},
|
||||
{SCANCODE_G, SDL_SCANCODE_G},
|
||||
{SCANCODE_H, SDL_SCANCODE_H},
|
||||
{SCANCODE_I, SDL_SCANCODE_I},
|
||||
{SCANCODE_J, SDL_SCANCODE_J},
|
||||
{SCANCODE_K, SDL_SCANCODE_K},
|
||||
{SCANCODE_L, SDL_SCANCODE_L},
|
||||
{SCANCODE_M, SDL_SCANCODE_M},
|
||||
{SCANCODE_N, SDL_SCANCODE_N},
|
||||
{SCANCODE_O, SDL_SCANCODE_O},
|
||||
{SCANCODE_P, SDL_SCANCODE_P},
|
||||
{SCANCODE_Q, SDL_SCANCODE_Q},
|
||||
{SCANCODE_R, SDL_SCANCODE_R},
|
||||
{SCANCODE_S, SDL_SCANCODE_S},
|
||||
{SCANCODE_T, SDL_SCANCODE_T},
|
||||
{SCANCODE_U, SDL_SCANCODE_U},
|
||||
{SCANCODE_V, SDL_SCANCODE_V},
|
||||
{SCANCODE_W, SDL_SCANCODE_W},
|
||||
{SCANCODE_X, SDL_SCANCODE_X},
|
||||
{SCANCODE_Y, SDL_SCANCODE_Y},
|
||||
{SCANCODE_Z, SDL_SCANCODE_Z},
|
||||
|
||||
{SCANCODE_1, SDL_SCANCODE_1},
|
||||
{SCANCODE_2, SDL_SCANCODE_2},
|
||||
{SCANCODE_3, SDL_SCANCODE_3},
|
||||
{SCANCODE_4, SDL_SCANCODE_4},
|
||||
{SCANCODE_5, SDL_SCANCODE_5},
|
||||
{SCANCODE_6, SDL_SCANCODE_6},
|
||||
{SCANCODE_7, SDL_SCANCODE_7},
|
||||
{SCANCODE_8, SDL_SCANCODE_8},
|
||||
{SCANCODE_9, SDL_SCANCODE_9},
|
||||
{SCANCODE_0, SDL_SCANCODE_0},
|
||||
|
||||
{SCANCODE_RETURN, SDL_SCANCODE_RETURN},
|
||||
{SCANCODE_ESCAPE, SDL_SCANCODE_ESCAPE},
|
||||
{SCANCODE_BACKSPACE, SDL_SCANCODE_BACKSPACE},
|
||||
{SCANCODE_TAB, SDL_SCANCODE_TAB},
|
||||
{SCANCODE_SPACE, SDL_SCANCODE_SPACE},
|
||||
|
||||
{SCANCODE_MINUS, SDL_SCANCODE_MINUS},
|
||||
{SCANCODE_EQUALS, SDL_SCANCODE_EQUALS},
|
||||
{SCANCODE_LEFTBRACKET, SDL_SCANCODE_LEFTBRACKET},
|
||||
{SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RIGHTBRACKET},
|
||||
{SCANCODE_BACKSLASH, SDL_SCANCODE_BACKSLASH},
|
||||
{SCANCODE_NONUSHASH, SDL_SCANCODE_NONUSHASH},
|
||||
{SCANCODE_SEMICOLON, SDL_SCANCODE_SEMICOLON},
|
||||
{SCANCODE_APOSTROPHE, SDL_SCANCODE_APOSTROPHE},
|
||||
{SCANCODE_GRAVE, SDL_SCANCODE_GRAVE},
|
||||
{SCANCODE_COMMA, SDL_SCANCODE_COMMA},
|
||||
{SCANCODE_PERIOD, SDL_SCANCODE_PERIOD},
|
||||
{SCANCODE_SLASH, SDL_SCANCODE_SLASH},
|
||||
|
||||
{SCANCODE_CAPSLOCK, SDL_SCANCODE_CAPSLOCK},
|
||||
|
||||
{SCANCODE_F1, SDL_SCANCODE_F1},
|
||||
{SCANCODE_F2, SDL_SCANCODE_F2},
|
||||
{SCANCODE_F3, SDL_SCANCODE_F3},
|
||||
{SCANCODE_F4, SDL_SCANCODE_F4},
|
||||
{SCANCODE_F5, SDL_SCANCODE_F5},
|
||||
{SCANCODE_F6, SDL_SCANCODE_F6},
|
||||
{SCANCODE_F7, SDL_SCANCODE_F7},
|
||||
{SCANCODE_F8, SDL_SCANCODE_F8},
|
||||
{SCANCODE_F9, SDL_SCANCODE_F9},
|
||||
{SCANCODE_F10, SDL_SCANCODE_F10},
|
||||
{SCANCODE_F11, SDL_SCANCODE_F11},
|
||||
{SCANCODE_F12, SDL_SCANCODE_F12},
|
||||
|
||||
{SCANCODE_PRINTSCREEN, SDL_SCANCODE_PRINTSCREEN},
|
||||
{SCANCODE_SCROLLLOCK, SDL_SCANCODE_SCROLLLOCK},
|
||||
{SCANCODE_PAUSE, SDL_SCANCODE_PAUSE},
|
||||
{SCANCODE_INSERT, SDL_SCANCODE_INSERT},
|
||||
{SCANCODE_HOME, SDL_SCANCODE_HOME},
|
||||
{SCANCODE_PAGEUP, SDL_SCANCODE_PAGEUP},
|
||||
{SCANCODE_DELETE, SDL_SCANCODE_DELETE},
|
||||
{SCANCODE_END, SDL_SCANCODE_END},
|
||||
{SCANCODE_PAGEDOWN, SDL_SCANCODE_PAGEDOWN},
|
||||
{SCANCODE_RIGHT, SDL_SCANCODE_RIGHT},
|
||||
{SCANCODE_LEFT, SDL_SCANCODE_LEFT},
|
||||
{SCANCODE_DOWN, SDL_SCANCODE_DOWN},
|
||||
{SCANCODE_UP, SDL_SCANCODE_UP},
|
||||
|
||||
{SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_NUMLOCKCLEAR},
|
||||
{SCANCODE_KP_DIVIDE, SDL_SCANCODE_KP_DIVIDE},
|
||||
{SCANCODE_KP_MULTIPLY, SDL_SCANCODE_KP_MULTIPLY},
|
||||
{SCANCODE_KP_MINUS, SDL_SCANCODE_KP_MINUS},
|
||||
{SCANCODE_KP_PLUS, SDL_SCANCODE_KP_PLUS},
|
||||
{SCANCODE_KP_ENTER, SDL_SCANCODE_KP_ENTER},
|
||||
{SCANCODE_KP_1, SDL_SCANCODE_KP_1},
|
||||
{SCANCODE_KP_2, SDL_SCANCODE_KP_2},
|
||||
{SCANCODE_KP_3, SDL_SCANCODE_KP_3},
|
||||
{SCANCODE_KP_4, SDL_SCANCODE_KP_4},
|
||||
{SCANCODE_KP_5, SDL_SCANCODE_KP_5},
|
||||
{SCANCODE_KP_6, SDL_SCANCODE_KP_6},
|
||||
{SCANCODE_KP_7, SDL_SCANCODE_KP_7},
|
||||
{SCANCODE_KP_8, SDL_SCANCODE_KP_8},
|
||||
{SCANCODE_KP_9, SDL_SCANCODE_KP_9},
|
||||
{SCANCODE_KP_0, SDL_SCANCODE_KP_0},
|
||||
{SCANCODE_KP_PERIOD, SDL_SCANCODE_KP_PERIOD},
|
||||
|
||||
{SCANCODE_NONUSBACKSLASH, SDL_SCANCODE_NONUSBACKSLASH},
|
||||
{SCANCODE_APPLICATION, SDL_SCANCODE_APPLICATION},
|
||||
{SCANCODE_POWER, SDL_SCANCODE_POWER},
|
||||
{SCANCODE_KP_EQUALS, SDL_SCANCODE_KP_EQUALS},
|
||||
{SCANCODE_F13, SDL_SCANCODE_F13},
|
||||
{SCANCODE_F14, SDL_SCANCODE_F14},
|
||||
{SCANCODE_F15, SDL_SCANCODE_F15},
|
||||
{SCANCODE_F16, SDL_SCANCODE_F16},
|
||||
{SCANCODE_F17, SDL_SCANCODE_F17},
|
||||
{SCANCODE_F18, SDL_SCANCODE_F18},
|
||||
{SCANCODE_F19, SDL_SCANCODE_F19},
|
||||
{SCANCODE_F20, SDL_SCANCODE_F20},
|
||||
{SCANCODE_F21, SDL_SCANCODE_F21},
|
||||
{SCANCODE_F22, SDL_SCANCODE_F22},
|
||||
{SCANCODE_F23, SDL_SCANCODE_F23},
|
||||
{SCANCODE_F24, SDL_SCANCODE_F24},
|
||||
{SCANCODE_EXECUTE, SDL_SCANCODE_EXECUTE},
|
||||
{SCANCODE_HELP, SDL_SCANCODE_HELP},
|
||||
{SCANCODE_MENU, SDL_SCANCODE_MENU},
|
||||
{SCANCODE_SELECT, SDL_SCANCODE_SELECT},
|
||||
{SCANCODE_STOP, SDL_SCANCODE_STOP},
|
||||
{SCANCODE_AGAIN, SDL_SCANCODE_AGAIN},
|
||||
{SCANCODE_UNDO, SDL_SCANCODE_UNDO},
|
||||
{SCANCODE_CUT, SDL_SCANCODE_CUT},
|
||||
{SCANCODE_COPY, SDL_SCANCODE_COPY},
|
||||
{SCANCODE_PASTE, SDL_SCANCODE_PASTE},
|
||||
{SCANCODE_FIND, SDL_SCANCODE_FIND},
|
||||
{SCANCODE_MUTE, SDL_SCANCODE_MUTE},
|
||||
{SCANCODE_VOLUMEUP, SDL_SCANCODE_VOLUMEUP},
|
||||
{SCANCODE_VOLUMEDOWN, SDL_SCANCODE_VOLUMEDOWN},
|
||||
{SCANCODE_KP_COMMA, SDL_SCANCODE_KP_COMMA},
|
||||
{SCANCODE_KP_EQUALSAS400, SDL_SCANCODE_KP_EQUALSAS400},
|
||||
|
||||
{SCANCODE_INTERNATIONAL1, SDL_SCANCODE_INTERNATIONAL1},
|
||||
{SCANCODE_INTERNATIONAL2, SDL_SCANCODE_INTERNATIONAL2},
|
||||
{SCANCODE_INTERNATIONAL3, SDL_SCANCODE_INTERNATIONAL3},
|
||||
{SCANCODE_INTERNATIONAL4, SDL_SCANCODE_INTERNATIONAL4},
|
||||
{SCANCODE_INTERNATIONAL5, SDL_SCANCODE_INTERNATIONAL5},
|
||||
{SCANCODE_INTERNATIONAL6, SDL_SCANCODE_INTERNATIONAL6},
|
||||
{SCANCODE_INTERNATIONAL7, SDL_SCANCODE_INTERNATIONAL7},
|
||||
{SCANCODE_INTERNATIONAL8, SDL_SCANCODE_INTERNATIONAL8},
|
||||
{SCANCODE_INTERNATIONAL9, SDL_SCANCODE_INTERNATIONAL9},
|
||||
{SCANCODE_LANG1, SDL_SCANCODE_LANG1},
|
||||
{SCANCODE_LANG2, SDL_SCANCODE_LANG2},
|
||||
{SCANCODE_LANG3, SDL_SCANCODE_LANG3},
|
||||
{SCANCODE_LANG4, SDL_SCANCODE_LANG4},
|
||||
{SCANCODE_LANG5, SDL_SCANCODE_LANG5},
|
||||
{SCANCODE_LANG6, SDL_SCANCODE_LANG6},
|
||||
{SCANCODE_LANG7, SDL_SCANCODE_LANG7},
|
||||
{SCANCODE_LANG8, SDL_SCANCODE_LANG8},
|
||||
{SCANCODE_LANG9, SDL_SCANCODE_LANG9},
|
||||
|
||||
{SCANCODE_ALTERASE, SDL_SCANCODE_ALTERASE},
|
||||
{SCANCODE_SYSREQ, SDL_SCANCODE_SYSREQ},
|
||||
{SCANCODE_CANCEL, SDL_SCANCODE_CANCEL},
|
||||
{SCANCODE_CLEAR, SDL_SCANCODE_CLEAR},
|
||||
{SCANCODE_PRIOR, SDL_SCANCODE_PRIOR},
|
||||
{SCANCODE_RETURN2, SDL_SCANCODE_RETURN2},
|
||||
{SCANCODE_SEPARATOR, SDL_SCANCODE_SEPARATOR},
|
||||
{SCANCODE_OUT, SDL_SCANCODE_OUT},
|
||||
{SCANCODE_OPER, SDL_SCANCODE_OPER},
|
||||
{SCANCODE_CLEARAGAIN, SDL_SCANCODE_CLEARAGAIN},
|
||||
{SCANCODE_CRSEL, SDL_SCANCODE_CRSEL},
|
||||
{SCANCODE_EXSEL, SDL_SCANCODE_EXSEL},
|
||||
|
||||
{SCANCODE_KP_00, SDL_SCANCODE_KP_00},
|
||||
{SCANCODE_KP_000, SDL_SCANCODE_KP_000},
|
||||
{SCANCODE_THOUSANDSSEPARATOR, SDL_SCANCODE_THOUSANDSSEPARATOR},
|
||||
{SCANCODE_DECIMALSEPARATOR, SDL_SCANCODE_DECIMALSEPARATOR},
|
||||
{SCANCODE_CURRENCYUNIT, SDL_SCANCODE_CURRENCYUNIT},
|
||||
{SCANCODE_CURRENCYSUBUNIT, SDL_SCANCODE_CURRENCYSUBUNIT},
|
||||
{SCANCODE_KP_LEFTPAREN, SDL_SCANCODE_KP_LEFTPAREN},
|
||||
{SCANCODE_KP_RIGHTPAREN, SDL_SCANCODE_KP_RIGHTPAREN},
|
||||
{SCANCODE_KP_LEFTBRACE, SDL_SCANCODE_KP_LEFTBRACE},
|
||||
{SCANCODE_KP_RIGHTBRACE, SDL_SCANCODE_KP_RIGHTBRACE},
|
||||
{SCANCODE_KP_TAB, SDL_SCANCODE_KP_TAB},
|
||||
{SCANCODE_KP_BACKSPACE, SDL_SCANCODE_KP_BACKSPACE},
|
||||
{SCANCODE_KP_A, SDL_SCANCODE_KP_A},
|
||||
{SCANCODE_KP_B, SDL_SCANCODE_KP_B},
|
||||
{SCANCODE_KP_C, SDL_SCANCODE_KP_C},
|
||||
{SCANCODE_KP_D, SDL_SCANCODE_KP_D},
|
||||
{SCANCODE_KP_E, SDL_SCANCODE_KP_E},
|
||||
{SCANCODE_KP_F, SDL_SCANCODE_KP_F},
|
||||
{SCANCODE_KP_XOR, SDL_SCANCODE_KP_XOR},
|
||||
{SCANCODE_KP_POWER, SDL_SCANCODE_KP_POWER},
|
||||
{SCANCODE_KP_PERCENT, SDL_SCANCODE_KP_PERCENT},
|
||||
{SCANCODE_KP_LESS, SDL_SCANCODE_KP_LESS},
|
||||
{SCANCODE_KP_GREATER, SDL_SCANCODE_KP_GREATER},
|
||||
{SCANCODE_KP_AMPERSAND, SDL_SCANCODE_KP_AMPERSAND},
|
||||
{SCANCODE_KP_DBLAMPERSAND, SDL_SCANCODE_KP_DBLAMPERSAND},
|
||||
{SCANCODE_KP_VERTICALBAR, SDL_SCANCODE_KP_VERTICALBAR},
|
||||
{SCANCODE_KP_DBLVERTICALBAR, SDL_SCANCODE_KP_DBLVERTICALBAR},
|
||||
{SCANCODE_KP_COLON, SDL_SCANCODE_KP_COLON},
|
||||
{SCANCODE_KP_HASH, SDL_SCANCODE_KP_HASH},
|
||||
{SCANCODE_KP_SPACE, SDL_SCANCODE_KP_SPACE},
|
||||
{SCANCODE_KP_AT, SDL_SCANCODE_KP_AT},
|
||||
{SCANCODE_KP_EXCLAM, SDL_SCANCODE_KP_EXCLAM},
|
||||
{SCANCODE_KP_MEMSTORE, SDL_SCANCODE_KP_MEMSTORE},
|
||||
{SCANCODE_KP_MEMRECALL, SDL_SCANCODE_KP_MEMRECALL},
|
||||
{SCANCODE_KP_MEMCLEAR, SDL_SCANCODE_KP_MEMCLEAR},
|
||||
{SCANCODE_KP_MEMADD, SDL_SCANCODE_KP_MEMADD},
|
||||
{SCANCODE_KP_MEMSUBTRACT, SDL_SCANCODE_KP_MEMSUBTRACT},
|
||||
{SCANCODE_KP_MEMMULTIPLY, SDL_SCANCODE_KP_MEMMULTIPLY},
|
||||
{SCANCODE_KP_MEMDIVIDE, SDL_SCANCODE_KP_MEMDIVIDE},
|
||||
{SCANCODE_KP_PLUSMINUS, SDL_SCANCODE_KP_PLUSMINUS},
|
||||
{SCANCODE_KP_CLEAR, SDL_SCANCODE_KP_CLEAR},
|
||||
{SCANCODE_KP_CLEARENTRY, SDL_SCANCODE_KP_CLEARENTRY},
|
||||
{SCANCODE_KP_BINARY, SDL_SCANCODE_KP_BINARY},
|
||||
{SCANCODE_KP_OCTAL, SDL_SCANCODE_KP_OCTAL},
|
||||
{SCANCODE_KP_DECIMAL, SDL_SCANCODE_KP_DECIMAL},
|
||||
{SCANCODE_KP_HEXADECIMAL, SDL_SCANCODE_KP_HEXADECIMAL},
|
||||
|
||||
{SCANCODE_LCTRL, SDL_SCANCODE_LCTRL},
|
||||
{SCANCODE_LSHIFT, SDL_SCANCODE_LSHIFT},
|
||||
{SCANCODE_LALT, SDL_SCANCODE_LALT},
|
||||
{SCANCODE_LGUI, SDL_SCANCODE_LGUI},
|
||||
{SCANCODE_RCTRL, SDL_SCANCODE_RCTRL},
|
||||
{SCANCODE_RSHIFT, SDL_SCANCODE_RSHIFT},
|
||||
{SCANCODE_RALT, SDL_SCANCODE_RALT},
|
||||
{SCANCODE_RGUI, SDL_SCANCODE_RGUI},
|
||||
|
||||
{SCANCODE_MODE, SDL_SCANCODE_MODE},
|
||||
|
||||
{SCANCODE_AUDIONEXT, SDL_SCANCODE_AUDIONEXT},
|
||||
{SCANCODE_AUDIOPREV, SDL_SCANCODE_AUDIOPREV},
|
||||
{SCANCODE_AUDIOSTOP, SDL_SCANCODE_AUDIOSTOP},
|
||||
{SCANCODE_AUDIOPLAY, SDL_SCANCODE_AUDIOPLAY},
|
||||
{SCANCODE_AUDIOMUTE, SDL_SCANCODE_AUDIOMUTE},
|
||||
{SCANCODE_MEDIASELECT, SDL_SCANCODE_MEDIASELECT},
|
||||
{SCANCODE_WWW, SDL_SCANCODE_WWW},
|
||||
{SCANCODE_MAIL, SDL_SCANCODE_MAIL},
|
||||
{SCANCODE_CALCULATOR, SDL_SCANCODE_CALCULATOR},
|
||||
{SCANCODE_COMPUTER, SDL_SCANCODE_COMPUTER},
|
||||
{SCANCODE_AC_SEARCH, SDL_SCANCODE_AC_SEARCH},
|
||||
{SCANCODE_AC_HOME, SDL_SCANCODE_AC_HOME},
|
||||
{SCANCODE_AC_BACK, SDL_SCANCODE_AC_BACK},
|
||||
{SCANCODE_AC_FORWARD, SDL_SCANCODE_AC_FORWARD},
|
||||
{SCANCODE_AC_STOP, SDL_SCANCODE_AC_STOP},
|
||||
{SCANCODE_AC_REFRESH, SDL_SCANCODE_AC_REFRESH},
|
||||
{SCANCODE_AC_BOOKMARKS, SDL_SCANCODE_AC_BOOKMARKS},
|
||||
|
||||
{SCANCODE_BRIGHTNESSDOWN, SDL_SCANCODE_BRIGHTNESSDOWN},
|
||||
{SCANCODE_BRIGHTNESSUP, SDL_SCANCODE_BRIGHTNESSUP},
|
||||
{SCANCODE_DISPLAYSWITCH, SDL_SCANCODE_DISPLAYSWITCH},
|
||||
{SCANCODE_KBDILLUMTOGGLE, SDL_SCANCODE_KBDILLUMTOGGLE},
|
||||
{SCANCODE_KBDILLUMDOWN, SDL_SCANCODE_KBDILLUMDOWN},
|
||||
{SCANCODE_KBDILLUMUP, SDL_SCANCODE_KBDILLUMUP},
|
||||
{SCANCODE_EJECT, SDL_SCANCODE_EJECT},
|
||||
{SCANCODE_SLEEP, SDL_SCANCODE_SLEEP},
|
||||
|
||||
{SCANCODE_APP1, SDL_SCANCODE_APP1},
|
||||
{SCANCODE_APP2, SDL_SCANCODE_APP2},
|
||||
};
|
||||
|
||||
EnumMap<Keyboard::Scancode, SDL_Scancode, SDL_NUM_SCANCODES> Keyboard::scancodes(Keyboard::scancodeEntries, sizeof(Keyboard::scancodeEntries));
|
||||
|
||||
} // sdl
|
||||
} // keyboard
|
||||
} // love
|
||||
|
||||
@@ -48,6 +48,9 @@ public:
|
||||
bool hasKeyRepeat() const;
|
||||
bool isDown(Key *keylist) const;
|
||||
|
||||
Key getKeyFromScancode(Scancode scancode) const;
|
||||
Scancode getScancodeFromKey(Key key) const;
|
||||
|
||||
void setTextInput(bool enable);
|
||||
bool hasTextInput() const;
|
||||
|
||||
@@ -60,6 +63,9 @@ private:
|
||||
static const SDL_Keycode *createKeyMap();
|
||||
static const SDL_Keycode *keymap;
|
||||
|
||||
static EnumMap<Scancode, SDL_Scancode, SDL_NUM_SCANCODES>::Entry scancodeEntries[];
|
||||
static EnumMap<Scancode, SDL_Scancode, SDL_NUM_SCANCODES> scancodes;
|
||||
|
||||
}; // Keyboard
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -62,6 +62,40 @@ int w_isDown(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getScancodeFromKey(lua_State *L)
|
||||
{
|
||||
const char *keystr = luaL_checkstring(L, 1);
|
||||
Keyboard::Key key;
|
||||
if (!Keyboard::getConstant(keystr, key))
|
||||
return luaL_error(L, "Invalid key constant: %s", keystr);
|
||||
|
||||
Keyboard::Scancode scancode = instance()->getScancodeFromKey(key);
|
||||
|
||||
const char *scancodestr;
|
||||
if (!Keyboard::getConstant(scancode, scancodestr))
|
||||
return luaL_error(L, "Unknown scancode.");
|
||||
|
||||
lua_pushstring(L, scancodestr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getKeyFromScancode(lua_State *L)
|
||||
{
|
||||
const char *scancodestr = luaL_checkstring(L, 1);
|
||||
Keyboard::Scancode scancode;
|
||||
if (!Keyboard::getConstant(scancodestr, scancode))
|
||||
return luaL_error(L, "Invalid scancode: %s", scancode);
|
||||
|
||||
Keyboard::Key key = instance()->getKeyFromScancode(scancode);
|
||||
|
||||
const char *keystr;
|
||||
if (!Keyboard::getConstant(key, keystr))
|
||||
return luaL_error(L, "Unknown key constant");
|
||||
|
||||
lua_pushstring(L, keystr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setTextInput(lua_State *L)
|
||||
{
|
||||
instance()->setTextInput(luax_toboolean(L, 1));
|
||||
@@ -82,6 +116,8 @@ static const luaL_Reg functions[] =
|
||||
{ "setTextInput", w_setTextInput },
|
||||
{ "hasTextInput", w_hasTextInput },
|
||||
{ "isDown", w_isDown },
|
||||
{ "getScancodeFromKey", w_getScancodeFromKey },
|
||||
{ "getKeyFromScancode", w_getKeyFromScancode },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace keyboard
|
||||
int w_setKeyRepeat(lua_State *L);
|
||||
int w_hasKeyRepeat(lua_State *L);
|
||||
int w_isDown(lua_State *L);
|
||||
int w_getKeyFromScancode(lua_State *L);
|
||||
int w_getScancodeFromkey(lua_State *L);
|
||||
int w_setTextInput(lua_State *L);
|
||||
int w_hasTextInput(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
|
||||
|
||||
@@ -71,8 +71,8 @@ public:
|
||||
virtual bool isVisible() const = 0;
|
||||
virtual void setGrabbed(bool grab) = 0;
|
||||
virtual bool isGrabbed() const = 0;
|
||||
virtual bool setRelative(bool relative) = 0;
|
||||
virtual bool isRelative() const = 0;
|
||||
virtual bool setRelativeMode(bool relative) = 0;
|
||||
virtual bool getRelativeMode() const = 0;
|
||||
|
||||
static bool getConstant(const char *in, Button &out);
|
||||
static bool getConstant(Button in, const char *&out);
|
||||
|
||||
@@ -112,18 +112,10 @@ love::mouse::Cursor *Mouse::getCursor() const
|
||||
return curCursor.get();
|
||||
}
|
||||
|
||||
static Uint32 GetSDLMouseState(int *x, int *y)
|
||||
{
|
||||
// SDL's Linux and Windows video backends don't update the internal mouse
|
||||
// state until the next PumpEvents, if SDL_WarpMouse was called previously.
|
||||
SDL_PumpEvents();
|
||||
return SDL_GetMouseState(x, y);
|
||||
}
|
||||
|
||||
int Mouse::getX() const
|
||||
{
|
||||
int x;
|
||||
GetSDLMouseState(&x, nullptr);
|
||||
SDL_GetMouseState(&x, nullptr);
|
||||
windowToPixelCoords(&x, nullptr);
|
||||
|
||||
return x;
|
||||
@@ -132,7 +124,7 @@ int Mouse::getX() const
|
||||
int Mouse::getY() const
|
||||
{
|
||||
int y;
|
||||
GetSDLMouseState(nullptr, &y);
|
||||
SDL_GetMouseState(nullptr, &y);
|
||||
windowToPixelCoords(nullptr, &y);
|
||||
|
||||
return y;
|
||||
@@ -141,7 +133,7 @@ int Mouse::getY() const
|
||||
void Mouse::getPosition(int &x, int &y) const
|
||||
{
|
||||
int mx, my;
|
||||
GetSDLMouseState(&mx, &my);
|
||||
SDL_GetMouseState(&mx, &my);
|
||||
windowToPixelCoords(&mx, &my);
|
||||
|
||||
x = mx;
|
||||
@@ -158,6 +150,11 @@ void Mouse::setPosition(int x, int y)
|
||||
|
||||
pixelToWindowCoords(&x, &y);
|
||||
SDL_WarpMouseInWindow(handle, x, y);
|
||||
|
||||
// SDL_WarpMouse doesn't directly update SDL's internal mouse state in Linux
|
||||
// and Windows, so we call SDL_PumpEvents now to make sure the next
|
||||
// getPosition call always returns the updated state.
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
void Mouse::setX(int x)
|
||||
@@ -211,12 +208,12 @@ bool Mouse::isGrabbed() const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Mouse::setRelative(bool relative)
|
||||
bool Mouse::setRelativeMode(bool relative)
|
||||
{
|
||||
return SDL_SetRelativeMouseMode(relative ? SDL_TRUE : SDL_FALSE) == 0;
|
||||
}
|
||||
|
||||
bool Mouse::isRelative() const
|
||||
bool Mouse::getRelativeMode() const
|
||||
{
|
||||
return SDL_GetRelativeMouseMode() != SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
bool isVisible() const;
|
||||
void setGrabbed(bool grab);
|
||||
bool isGrabbed() const;
|
||||
bool setRelative(bool relative);
|
||||
bool isRelative() const;
|
||||
bool setRelativeMode(bool relative);
|
||||
bool getRelativeMode() const;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -179,16 +179,16 @@ int w_isGrabbed(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setRelative(lua_State *L)
|
||||
int w_setRelativeMode(lua_State *L)
|
||||
{
|
||||
bool relative = luax_toboolean(L, 1);
|
||||
luax_pushboolean(L, instance()->setRelative(relative));
|
||||
luax_pushboolean(L, instance()->setRelativeMode(relative));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_isRelative(lua_State *L)
|
||||
int w_getRelativeMode(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance()->isRelative());
|
||||
luax_pushboolean(L, instance()->getRelativeMode());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -210,8 +210,8 @@ static const luaL_Reg functions[] =
|
||||
{ "getPosition", w_getPosition },
|
||||
{ "setGrabbed", w_setGrabbed },
|
||||
{ "isGrabbed", w_isGrabbed },
|
||||
{ "setRelative", w_setRelative },
|
||||
{ "isRelative", w_isRelative },
|
||||
{ "setRelativeMode", w_setRelativeMode },
|
||||
{ "getRelativeMode", w_getRelativeMode },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ int w_setVisible(lua_State *L);
|
||||
int w_isVisible(lua_State *L);
|
||||
int w_setGrabbed(lua_State *L);
|
||||
int w_isGrabbed(lua_State *L);
|
||||
int w_setRelative(lua_State *L);
|
||||
int w_isRelative(lua_State *L);
|
||||
int w_setRelativeMode(lua_State *L);
|
||||
int w_getRelativeMode(lua_State *L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_mouse(lua_State *L);
|
||||
|
||||
} // mouse
|
||||
|
||||
Reference in New Issue
Block a user