From 560d67ca3d09f979c6f9ee5fefa70cebb324b4ee Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 17 Mar 2026 13:47:25 +0100 Subject: [PATCH] =?UTF-8?q?VERSI=C3=93=201.4.3=20-=20[NEW]=20key.text()=20?= =?UTF-8?q?-=20[NEW]=20key.utf8char()=20-=20[NEW]=20pal.trans()=20ara=20to?= =?UTF-8?q?rna=20el=20color=20transparent=20-=20[NEW]=20pal.subpal(index)?= =?UTF-8?q?=20i=20pal.subpal(index,color)=20ara=20tornen=20el=20color=20al?= =?UTF-8?q?=20que=20estaba=20abans=20asignat=20el=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua.cpp | 20 ++++++++++++++++++-- mini.cpp | 38 +++++++++++++++++++++++--------------- mini.h | 4 +++- version.h | 2 +- vscode/library.lua | 20 ++++++++++++++++++-- 5 files changed, 63 insertions(+), 21 deletions(-) diff --git a/lua.cpp b/lua.cpp index ee36703..9b9baae 100644 --- a/lua.cpp +++ b/lua.cpp @@ -310,12 +310,16 @@ extern "C" { break; case 1: index = luaL_checkinteger(L, 1); - subpal(index,index); + const uint8_t old = subpal(index,index); + lua_pushinteger(L, old); + return 1; break; case 2: index = luaL_checkinteger(L, 1); color = luaL_checkinteger(L, 2); - subpal(index, color); + const uint8_t old = subpal(index, color); + lua_pushinteger(L, old); + return 1; break; case 3: index = luaL_checkinteger(L, 1); @@ -956,6 +960,16 @@ extern "C" { return 1; } + static int cpp_key_text(lua_State *L) { + textenable(lua_toboolean(L, 1)); + return 0; + } + + static int cpp_key_utf8char(lua_State *L) { + lua_pushstring(L, textinput()); + return 1; + } + // pad // =============================================== @@ -1134,6 +1148,8 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_key_down); lua_setfield(L, -2, "down"); lua_pushcfunction(L,cpp_key_press); lua_setfield(L, -2, "press"); lua_pushcfunction(L,cpp_key_any); lua_setfield(L, -2, "any"); + lua_pushcfunction(L,cpp_key_text); lua_setfield(L, -2, "text"); + lua_pushcfunction(L,cpp_key_utf8char); lua_setfield(L, -2, "utf8char"); //lua_setglobal(L, "key"); //lua_newtable(L); diff --git a/mini.cpp b/mini.cpp index 41afc06..cd7b3ae 100644 --- a/mini.cpp +++ b/mini.cpp @@ -109,6 +109,8 @@ char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAV //Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X }; const bool *keys; Uint8 key_just_pressed = 0; +static char text_input_buffer[10]; +static bool has_text_input = false; int mouse_x, mouse_y, mouse_wheel; Uint32 mouse_buttons; @@ -544,26 +546,17 @@ int main(int argc,char*argv[]){ mouse_just_pressed = 0; mouse_wheel = 0; double_click = false; + has_text_input = false; while(!should_exit) { if (update_mode==UPDATE_WAIT) SDL_WaitEvent(NULL); else if (update_mode==UPDATE_TIMEOUT) SDL_WaitEventTimeout(NULL, timeout); while(SDL_PollEvent(&mini_eve)) { if (mini_eve.type == SDL_EVENT_QUIT) { should_exit=true; should_quit=true; break; } + if (mini_eve.type == SDL_EVENT_TEXT_INPUT) { + SDL_strlcpy(text_input_buffer, mini_eve.text.text, sizeof(text_input_buffer)); + has_text_input = true; + } if (mini_eve.type == SDL_EVENT_KEY_DOWN) { -/* - if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F2) { - screen_zoom+=2; if (screen_zoom>=10) screen_zoom=2; - destroyDisplay(); - createDisplay(); - char strzoom[3]; - file_setconfigvalue("zoom", SDL_itoa(screen_zoom, strzoom, 10)); - } else if (mini_eve.key.keysym.scancode == SDL_SCANCODE_F3) { - screen_fullscreen = !screen_fullscreen; - destroyDisplay(); - createDisplay(); - file_setconfigvalue("fullscreen", screen_fullscreen?"true":"false"); - } -*/ #ifdef DEBUG if (mini_eve.key.scancode == SDL_SCANCODE_F12) { if (lua_is_playing()) { @@ -626,6 +619,8 @@ int main(int argc,char*argv[]){ if (beats>0)beats--; key_just_pressed = 0; mouse_just_pressed = 0; + has_text_input = false; + text_input_buffer[0] = '\0'; double_click = false; mouse_wheel = 0; pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID; @@ -734,8 +729,10 @@ uint8_t gettrans() { return ds::trans; } -void subpal(uint8_t index, uint8_t color) { +uint8_t subpal(uint8_t index, uint8_t color) { + const uint8_t old = ds::draw_palette[SDL_clamp(index,0,255)]; ds::draw_palette[SDL_clamp(index,0,255)] = SDL_clamp(color,0,255); + return old; } void reset_subpal() { @@ -1343,6 +1340,17 @@ bool anykey() { return something_pressed; } +void textenable(const bool enable) { + if (enable) + SDL_StartTextInput(mini_win); + else + SDL_StopTextInput(mini_win); +} + +const char* textinput() { + return has_text_input ? text_input_buffer : nullptr; +} + bool pad(int8_t i) { if (!gamepad) return false; return SDL_GetGamepadButton(gamepad, SDL_GamepadButton(i)) == 1; diff --git a/mini.h b/mini.h index 2d41aad..9f323db 100644 --- a/mini.h +++ b/mini.h @@ -152,7 +152,7 @@ void setcolor(uint8_t index, uint32_t color); uint32_t getcolor(uint8_t index); void settrans(uint8_t index); uint8_t gettrans(); -void subpal(uint8_t index, uint8_t color); +uint8_t subpal(uint8_t index, uint8_t color); void reset_subpal(); void set_draw_mode(uint8_t mode); @@ -225,6 +225,8 @@ bool btn(uint8_t i); int wbtnp(); bool btnp(uint8_t i); bool anykey(); +void textenable(const bool enable); +const char *textinput(); bool pad(int8_t i); bool padp(int8_t i); diff --git a/version.h b/version.h index 01e335a..d4722b2 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.4.2" +#define MINI_VERSION "1.4.3" diff --git a/vscode/library.lua b/vscode/library.lua index b71dadb..f581325 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -122,6 +122,10 @@ function pal.color(index) end ---Set (r,g,b) color for the specified index in the current palette function pal.color(index, r, g, b) end +---@return number index +---Get the index specified as transparent color +function pal.trans() end + ---@param index number ---Set the index specified as transparent color function pal.trans(index) end @@ -130,12 +134,16 @@ function pal.trans(index) end function pal.subpal() end ---@param index number ----Reset the specified subpalette index to its default palette index +---@return number index +---Reset the specified subpalette index to its default palette index, +---returns the previously mapped index function pal.subpal(index) end ---@param index number ---@param color number ----Set the specified subpalette index to the specified palette index +---@return number index +---Set the specified subpalette index to the specified palette index, +---returns the previously mapped index function pal.subpal(index, color) end ---@param index1 number @@ -601,6 +609,14 @@ function key.press(key) end ---Returns whether any keyboard key has just been pressed function key.any() end +---@param enable boolean +---Enable or disable utf8 text input +function key.text(enable) end + +---@return string +---Returns a string with the utf-8 character sequence pressed. Only when utf8 is enabled +function key.utf8char() end + ---@class pad ---@field pad.INVALID number