mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added documentation for the ctr.hid, ctr.ptm, ctr.news and ctr.gfx.texture
This commit is contained in:
parent
ab06123f7a
commit
070a0d698e
4 changed files with 263 additions and 3 deletions
102
source/hid.c
102
source/hid.c
|
|
@ -1,9 +1,55 @@
|
|||
/***
|
||||
The `hid` module.
|
||||
The circle pad pro is supported, it's keys replace de "3ds only" keys
|
||||
@module ctr.hid
|
||||
@usage local hid = require("ctr.hid")
|
||||
*/
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/services/hid.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
/***
|
||||
Keys list
|
||||
@table keys
|
||||
@field a A
|
||||
@field b B
|
||||
@field select Select
|
||||
@field start Start
|
||||
@field dRight D-Pad right
|
||||
@field dLeft D-Pad Left
|
||||
@field dUp D-Pad Up
|
||||
@field dDown D-Pad Down
|
||||
@field r R trigger
|
||||
@field l L trigger
|
||||
@field x X
|
||||
@field y Y
|
||||
@field zl ZL trigger (new3ds only)
|
||||
@field zr ZR trigger (new3ds only)
|
||||
@field touch
|
||||
@field cstickRight C-Stick right (new3ds only)
|
||||
@field cstickLeft C-Stick left (new3ds only)
|
||||
@field cstickUp C-Stick up (new3ds only)
|
||||
@field cstickDown C-Stick down (new3ds only)
|
||||
@field cpadRight Circle pad right
|
||||
@field cpadLeft Circle pad left
|
||||
@field cpadUp Circle pad up
|
||||
@field cpadDown Circle pad down
|
||||
@field up Generic up
|
||||
@field down Generic down
|
||||
@field left Generic left
|
||||
@field right Generic right
|
||||
*/
|
||||
|
||||
/***
|
||||
Keys states
|
||||
@table states
|
||||
@field down keys which have been just pressed
|
||||
@field held keys which are held down
|
||||
@field up keys whick are been just released
|
||||
*/
|
||||
|
||||
// Key list based on hid.h from the ctrulib by smealum
|
||||
struct { PAD_KEY key; char *name; } hid_keys_name[] = {
|
||||
{ KEY_A , "a" },
|
||||
|
|
@ -38,12 +84,28 @@ struct { PAD_KEY key; char *name; } hid_keys_name[] = {
|
|||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/***
|
||||
Refresh the HID state.
|
||||
@function read
|
||||
*/
|
||||
static int hid_read(lua_State *L) {
|
||||
hidScanInput();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the keys states as `state.key` in a table.
|
||||
@function keys
|
||||
@treturn table keys states
|
||||
@usage
|
||||
-- Just an example
|
||||
hid.read()
|
||||
local keys = hid.keys()
|
||||
if keys.held.a then
|
||||
-- do stuff
|
||||
end
|
||||
*/
|
||||
static int hid_keys(lua_State *L) {
|
||||
u32 kDown = hidKeysDown();
|
||||
u32 kHeld = hidKeysHeld();
|
||||
|
|
@ -79,6 +141,13 @@ static int hid_keys(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the touch position on the touch screen.
|
||||
`0,0` is the top-left corner.
|
||||
@function touch
|
||||
@treturn number X position
|
||||
@treturn number Y position
|
||||
*/
|
||||
static int hid_touch(lua_State *L) {
|
||||
touchPosition pos;
|
||||
hidTouchRead(&pos);
|
||||
|
|
@ -89,6 +158,13 @@ static int hid_touch(lua_State *L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the circle pad position.
|
||||
`0,0` is the center position. Warning: the circle pad doesn't always go back to `0,0`.
|
||||
@function circle
|
||||
@treturn number X position
|
||||
@treturn number Y position
|
||||
*/
|
||||
static int hid_circle(lua_State *L) {
|
||||
circlePosition pos;
|
||||
hidCircleRead(&pos);
|
||||
|
|
@ -99,6 +175,13 @@ static int hid_circle(lua_State *L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the accelerometer vector
|
||||
@function accel
|
||||
@treturn number X acceleration
|
||||
@treturn number Y acceleration
|
||||
@treturn number Z acceleration
|
||||
*/
|
||||
static int hid_accel(lua_State *L) {
|
||||
accelVector pos;
|
||||
hidAccelRead(&pos);
|
||||
|
|
@ -110,6 +193,13 @@ static int hid_accel(lua_State *L) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the gyroscope rate.
|
||||
@function gyro
|
||||
@treturn number roll
|
||||
@treturn number pitch
|
||||
@treturn number yaw
|
||||
*/
|
||||
static int hid_gyro(lua_State *L) {
|
||||
angularRate pos;
|
||||
hidGyroRead(&pos);
|
||||
|
|
@ -121,6 +211,11 @@ static int hid_gyro(lua_State *L) {
|
|||
return 3;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the sound volume.
|
||||
@function volume
|
||||
@treturn number volume (`0` to `63`)
|
||||
*/
|
||||
static int hid_volume(lua_State *L) {
|
||||
u8 volume = 0;
|
||||
HIDUSER_GetSoundVolume(&volume);
|
||||
|
|
@ -130,6 +225,11 @@ static int hid_volume(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the 3D cursor position.
|
||||
@function pos3d
|
||||
@treturn number 3d cursor position (`0` to `1`)
|
||||
*/
|
||||
static int hid_3d(lua_State *L) {
|
||||
float slider = (*(float*)0x1FF81080);
|
||||
|
||||
|
|
@ -165,4 +265,4 @@ void load_hid_lib(lua_State *L) {
|
|||
void unload_hid_lib(lua_State *L) {
|
||||
HIDUSER_DisableAccelerometer();
|
||||
HIDUSER_DisableGyroscope();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
/***
|
||||
The `news` module.
|
||||
@module ctr.news
|
||||
@usage local news = require("ctr.news")
|
||||
*/
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/util/utf.h>
|
||||
#include <3ds/services/news.h>
|
||||
|
|
@ -5,12 +10,24 @@
|
|||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
|
||||
/***
|
||||
Initialize the news module.
|
||||
@function init
|
||||
*/
|
||||
static int news_init(lua_State *L) {
|
||||
newsInit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Send a notification to the user. WIP, do not use !!!
|
||||
@function notification
|
||||
@tparam string title title of the notification
|
||||
@tparam string message message of the notification
|
||||
@tparam string imageData data from a JPEG image (content of a file) or raw data
|
||||
@tparam[OPT=false] boolean jpeg set to `true` if the data is from a JPEG file
|
||||
*/
|
||||
static int news_notification(lua_State *L) {
|
||||
const char *title = luaL_checkstring(L, 1);
|
||||
const char *message = luaL_checkstring(L, 2);
|
||||
|
|
@ -33,6 +50,10 @@ static int news_notification(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Disable the news module.
|
||||
@function shutdown
|
||||
*/
|
||||
static int news_shutdown(lua_State *L) {
|
||||
newsExit();
|
||||
|
||||
|
|
|
|||
42
source/ptm.c
42
source/ptm.c
|
|
@ -1,3 +1,8 @@
|
|||
/***
|
||||
The `ptm` module.
|
||||
@module ctr.ptm
|
||||
@usage local ptm = require("ctr.ptm")
|
||||
*/
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/services/ptm.h>
|
||||
|
||||
|
|
@ -6,18 +11,31 @@
|
|||
|
||||
static Handle *ptmHandle;
|
||||
|
||||
/***
|
||||
Initialize the PTM module.
|
||||
@function init
|
||||
*/
|
||||
static int ptm_init(lua_State *L) {
|
||||
ptmInit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Disable the PTM module.
|
||||
@function shutdown
|
||||
*/
|
||||
static int ptm_shutdown(lua_State *L) {
|
||||
ptmExit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the shell state. Don't care about this.
|
||||
@function getShellState
|
||||
@treturn number shell state
|
||||
*/
|
||||
static int ptm_getShellState(lua_State *L) {
|
||||
u8 out = 0;
|
||||
PTMU_GetShellState(ptmHandle, &out);
|
||||
|
|
@ -27,6 +45,11 @@ static int ptm_getShellState(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the battery level.
|
||||
@function getBatteryLevel
|
||||
@treturn number battery level (`5`: fully charged; `0`: empty)
|
||||
*/
|
||||
static int ptm_getBatteryLevel(lua_State *L) {
|
||||
u8 out = 0;
|
||||
PTMU_GetBatteryLevel(ptmHandle, &out);
|
||||
|
|
@ -36,24 +59,39 @@ static int ptm_getBatteryLevel(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return whether or not the battery is charging.
|
||||
@function getBatteryChargeState
|
||||
@treturn boolean `true` if the battery is charging
|
||||
*/
|
||||
static int ptm_getBatteryChargeState(lua_State *L) {
|
||||
u8 out = 0;
|
||||
PTMU_GetBatteryChargeState(ptmHandle, &out);
|
||||
|
||||
lua_pushinteger(L, out);
|
||||
lua_pushboolean(L, out);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return whether or not the pedometer is counting.
|
||||
@function getPedometerState
|
||||
@treturn boolean `true` if the pedometer is counting
|
||||
*/
|
||||
static int ptm_getPedometerState(lua_State *L) {
|
||||
u8 out = 0;
|
||||
PTMU_GetPedometerState(ptmHandle, &out);
|
||||
|
||||
lua_pushinteger(L, out);
|
||||
lua_pushboolean(L, out);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the total steps taken with the system.
|
||||
@function getTotalStepCount
|
||||
@treturn number step count
|
||||
*/
|
||||
static int ptm_getTotalStepCount(lua_State *L) {
|
||||
u32 steps = 0;
|
||||
PTMU_GetTotalStepCount(ptmHandle, &steps);
|
||||
|
|
|
|||
101
source/texture.c
101
source/texture.c
|
|
@ -1,3 +1,8 @@
|
|||
/***
|
||||
The `gfx.texture` module.
|
||||
@module ctr.gfx.texture
|
||||
@usage local texture = require("ctr.gfx.texture")
|
||||
*/
|
||||
#include <sf2d.h>
|
||||
#include <sfil.h>
|
||||
|
||||
|
|
@ -14,6 +19,15 @@ u8 getType(const char *name) {
|
|||
}
|
||||
|
||||
// module functions
|
||||
|
||||
/***
|
||||
Load a texture from a file. Supported formats: PNG, JPEG, BMP.
|
||||
@function load
|
||||
@tparam string path path to the image file
|
||||
@tparam[opt=PLACE_RAM] number place where to put the loaded texture
|
||||
@tparam[opt=auto] number type type of the image
|
||||
@treturn texture the loaded texture object
|
||||
*/
|
||||
static int texture_load(lua_State *L) {
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
u8 place = luaL_optinteger(L, 2, SF2D_PLACE_RAM); //place in ram by default
|
||||
|
|
@ -51,6 +65,18 @@ static int texture_load(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Texture object
|
||||
@section Methods
|
||||
*/
|
||||
|
||||
/***
|
||||
Draw a texture.
|
||||
@function :draw
|
||||
@tparam number x X position
|
||||
@tparam number y Y position
|
||||
@tparam[opt=0.0] number rad rotation of the texture (in radians)
|
||||
*/
|
||||
static int texture_draw(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
|
|
@ -66,6 +92,17 @@ static int texture_draw(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Draw a part of the texture
|
||||
@function :drawPart
|
||||
@tparam number x X position
|
||||
@tparam number y Y position
|
||||
@tparam number sx X position of the beginning of the part
|
||||
@tparam number sy Y position of the beginning of the part
|
||||
@tparam number w width of the part
|
||||
@tparam number h height of the part
|
||||
@tparam[opt=0.0] number rad rotation of the part (in radians)
|
||||
*/
|
||||
static int texture_drawPart(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
|
|
@ -81,6 +118,12 @@ static int texture_drawPart(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the size of the texture.
|
||||
@function :getSize
|
||||
@treturn number width of the texture
|
||||
@treturn number height of the texture
|
||||
*/
|
||||
static int texture_getSize(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
|
||||
|
|
@ -90,6 +133,10 @@ static int texture_getSize(lua_State *L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
/***
|
||||
Unload a texture.
|
||||
@function :unload
|
||||
*/
|
||||
static int texture_unload(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
|
||||
|
|
@ -101,6 +148,12 @@ static int texture_unload(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Rescale the texture. The default scale is `1.0`.
|
||||
@function :scale
|
||||
@tparam number scaleX new scale of the width
|
||||
@tparam number scaleY new scale of the height
|
||||
*/
|
||||
static int texture_scale(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
float sx = luaL_checknumber(L, 2);
|
||||
|
|
@ -112,6 +165,13 @@ static int texture_scale(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Return the color of a pixel.
|
||||
@function :getPixel
|
||||
@tparam number x X position of the pixel
|
||||
@tparam number y Y position of the pixel
|
||||
@treturn number color of the pixel.
|
||||
*/
|
||||
static int texture_getPixel(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
|
|
@ -122,6 +182,13 @@ static int texture_getPixel(lua_State *L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
Set the color of a pixel.
|
||||
@function :setPixel
|
||||
@tparam number x X position of the pixel
|
||||
@tparam number y Y position of the pixel
|
||||
@tparam number color New color of the pixel
|
||||
*/
|
||||
static int texture_setPixel(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
int x = luaL_checkinteger(L, 2);
|
||||
|
|
@ -133,6 +200,11 @@ static int texture_setPixel(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
Set the blend color of the texture.
|
||||
@function :setBlendColor
|
||||
@tparam number color new blend color
|
||||
*/
|
||||
static int texture_setBlendColor(lua_State *L) {
|
||||
texture_userdata *texture = luaL_checkudata(L, 1, "LTexture");
|
||||
u32 color = luaL_checkinteger(L, 2);
|
||||
|
|
@ -162,13 +234,42 @@ static const struct luaL_Reg texture_functions[] = {
|
|||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/***
|
||||
Fields
|
||||
@section Fields
|
||||
*/
|
||||
|
||||
// constants
|
||||
struct { char *name; int value; } texture_constants[] = {
|
||||
/***
|
||||
Constant used to select the RAM.
|
||||
@field PLACE_RAM
|
||||
*/
|
||||
{"PLACE_RAM", SF2D_PLACE_RAM },
|
||||
/***
|
||||
Constant used to select the VRAM.
|
||||
@field PLACE_VRAM
|
||||
*/
|
||||
{"PLACE_VRAM", SF2D_PLACE_VRAM},
|
||||
/***
|
||||
Constant used to select a temporary RAM pool. Don't use it.
|
||||
@field PLACE_TEMP
|
||||
*/
|
||||
{"PLACE_TEMP", SF2D_PLACE_TEMP},
|
||||
/***
|
||||
Constant used to select the PNG type.
|
||||
@field TYPE_PNG
|
||||
*/
|
||||
{"TYPE_PNG", 0 },
|
||||
/***
|
||||
Constant used to select the JPEG type.
|
||||
@field TYPE_JPEG
|
||||
*/
|
||||
{"TYPE_JPEG", 1 },
|
||||
/***
|
||||
Constant used to select the BMP type.
|
||||
@field TYPE_BMP
|
||||
*/
|
||||
{"TYPE_BMP", 2 },
|
||||
{NULL, 0}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue