diff --git a/assets/ui/test.lua b/assets/ui/test.lua new file mode 100644 index 0000000..a6c6ffc --- /dev/null +++ b/assets/ui/test.lua @@ -0,0 +1,6 @@ +module('ui') +module('color') + +function draw(x, y) + uiDrawRect(COLOR_WHITE, x, y, 32, 32) +end \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 409cef9..6b6fab3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,4 +65,5 @@ add_subdirectory(script) add_subdirectory(thread) add_subdirectory(time) add_subdirectory(ui) +add_subdirectory(ui2) add_subdirectory(util) \ No newline at end of file diff --git a/src/display/color.csv b/src/display/color.csv new file mode 100644 index 0000000..586e061 --- /dev/null +++ b/src/display/color.csv @@ -0,0 +1,22 @@ +name,r,g,b,a +black,0,0,0,1 +white,1,1,1,1 +red,1,0,0,1 +green,0,1,0,1 +blue,0,0,1,1 +yellow,1,1,0,1 +cyan,0,1,1,1 +magenta,1,0,1,1 +transparent,0,0,0,0 +transparent_white,1,1,1,0 +transparent_black,0,0,0,0 +gray,0.5,0.5,0.5,1 +light_gray,0.75,0.75,0.75,1 +dark_gray,0.25,0.25,0.25,1 +orange,1,0.65,0,1 +purple,0.5,0,0.5,1 +brown,0.6,0.4,0.2,1 +pink,1,0.75,0.8,1 +lime,0.75,1,0,1 +navy,0,0,0.5,1 +teal,0,0.5,0.5,1 \ No newline at end of file diff --git a/src/script/module/CMakeLists.txt b/src/script/module/CMakeLists.txt index 2923dc0..260f1a0 100644 --- a/src/script/module/CMakeLists.txt +++ b/src/script/module/CMakeLists.txt @@ -11,4 +11,5 @@ add_subdirectory(item) add_subdirectory(locale) add_subdirectory(system) add_subdirectory(scene) -add_subdirectory(time) \ No newline at end of file +add_subdirectory(time) +add_subdirectory(ui) \ No newline at end of file diff --git a/src/script/module/display/CMakeLists.txt b/src/script/module/display/CMakeLists.txt index b316bae..aba882e 100644 --- a/src/script/module/display/CMakeLists.txt +++ b/src/script/module/display/CMakeLists.txt @@ -10,4 +10,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME} modulecamera.c modulespritebatch.c moduleglm.c + modulecolor.c ) \ No newline at end of file diff --git a/src/script/module/display/modulecolor.c b/src/script/module/display/modulecolor.c new file mode 100644 index 0000000..b622a57 --- /dev/null +++ b/src/script/module/display/modulecolor.c @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "modulecolor.h" +#include "display/color.h" +#include "assert/assert.h" +#include "script/struct/scriptstruct.h" +#include "util/string.h" + +void moduleColor(scriptcontext_t *context) { + assertNotNull(context, "Context cannot be NULL."); + + scriptStructRegister(context, "color_mt", moduleColorGetter, NULL); +} + +void moduleColorGetter( + const scriptcontext_t *context, + const char_t *key, + const void *structPtr, + scriptvalue_t *outValue +) { + const color_t *color = (color_t*)structPtr; + + if(stringCompare(key, "r") == 0) { + outValue->type = SCRIPT_VALUE_TYPE_INT; + outValue->value.intValue = color->r; + return; + } + if(stringCompare(key, "g") == 0) { + outValue->type = SCRIPT_VALUE_TYPE_INT; + outValue->value.intValue = color->g; + return; + } + if(stringCompare(key, "b") == 0) { + outValue->type = SCRIPT_VALUE_TYPE_INT; + outValue->value.intValue = color->b; + return; + } + if(stringCompare(key, "a") == 0) { + outValue->type = SCRIPT_VALUE_TYPE_INT; + outValue->value.intValue = color->a; + return; + } +} \ No newline at end of file diff --git a/src/script/module/display/modulecolor.h b/src/script/module/display/modulecolor.h new file mode 100644 index 0000000..c180534 --- /dev/null +++ b/src/script/module/display/modulecolor.h @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "script/scriptcontext.h" + +/** + * Registers the color module with the given script context. + * + * @param context The script context to register the module with. + */ +void moduleColor(scriptcontext_t *context); + +/** + * Getter function for the color structure. + * + * @param context The script context. + * @param key The key to get. + * @param structPtr Pointer to the color structure. + * @param outValue Output value. + */ +void moduleColorGetter( + const scriptcontext_t *context, + const char_t *key, + const void *structPtr, + scriptvalue_t *outValue +); \ No newline at end of file diff --git a/src/script/module/ui/CMakeLists.txt b/src/script/module/ui/CMakeLists.txt new file mode 100644 index 0000000..8fc42de --- /dev/null +++ b/src/script/module/ui/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + moduleui.c +) \ No newline at end of file diff --git a/src/script/module/ui/moduleui.c b/src/script/module/ui/moduleui.c new file mode 100644 index 0000000..3e2b745 --- /dev/null +++ b/src/script/module/ui/moduleui.c @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "moduleui.h" +#include "assert/assert.h" + +void moduleUi(scriptcontext_t *ctx) { + assertNotNull(ctx, "Script context cannot be NULL"); + + +} \ No newline at end of file diff --git a/src/script/module/ui/moduleui.h b/src/script/module/ui/moduleui.h new file mode 100644 index 0000000..7e93ad1 --- /dev/null +++ b/src/script/module/ui/moduleui.h @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "script/scriptcontext.h" + +/** + * Registers the ui module within the given script context. + * + * @param ctx The script context to register the module in. + */ +void moduleUi(scriptcontext_t *ctx); \ No newline at end of file diff --git a/src/script/scriptmodule.c b/src/script/scriptmodule.c index 897afc4..73015a1 100644 --- a/src/script/scriptmodule.c +++ b/src/script/scriptmodule.c @@ -14,15 +14,18 @@ #include "script/module/locale/modulelocale.h" #include "script/module/time/moduletime.h" #include "script/module/event/moduleevent.h" +#include "script/module/display/modulecolor.h" #include "script/module/display/modulespritebatch.h" #include "script/module/display/modulecamera.h" #include "script/module/display/moduleglm.h" +#include "script/module/ui/moduleui.h" #include "util/string.h" const scriptmodule_t SCRIPT_MODULE_LIST[] = { { .name = "system", .callback = moduleSystem }, { .name = "input", .callback = moduleInput }, { .name = "platform", .callback = modulePlatform }, + { .name = "color", .callback = moduleColor }, { .name = "scene", .callback = moduleScene }, { .name = "item", .callback = moduleItem }, { .name = "locale", .callback = moduleLocale }, @@ -31,6 +34,7 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = { { .name = "spritebatch", .callback = moduleSpriteBatch }, { .name = "camera", .callback = moduleCamera }, { .name = "glm", .callback = moduleGLM }, + { .name = "ui", .callback = moduleUi }, }; #define SCRIPT_MODULE_COUNT ( \ diff --git a/src/ui2/CMakeLists.txt b/src/ui2/CMakeLists.txt new file mode 100644 index 0000000..9b35b01 --- /dev/null +++ b/src/ui2/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC +) \ No newline at end of file diff --git a/src/ui2/ui2.c b/src/ui2/ui2.c new file mode 100644 index 0000000..df850eb --- /dev/null +++ b/src/ui2/ui2.c @@ -0,0 +1,8 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "ui2.h" \ No newline at end of file diff --git a/src/ui2/ui2.h b/src/ui2/ui2.h new file mode 100644 index 0000000..02339b4 --- /dev/null +++ b/src/ui2/ui2.h @@ -0,0 +1,10 @@ +// Copyright (c) 2026 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dusk.h" + +// Two kinds of UI elements, those that are scripted (with a state, logic, etc) +// and those that are draw only (rectangle, text, etc). \ No newline at end of file diff --git a/tools/display/color/csv/__main__.py b/tools/display/color/csv/__main__.py new file mode 100644 index 0000000..b69fe43 --- /dev/null +++ b/tools/display/color/csv/__main__.py @@ -0,0 +1,64 @@ +import argparse +import os +import csv +from tools.util.type import detectType, stringToCType, typeToCType + +parser = argparse.ArgumentParser(description="Color CSV to .h defines") +parser.add_argument("--csv", required=True, help="Path to color CSV file") +parser.add_argument("--output", required=True, help="Path to output .h file") +args = parser.parse_args() + +def csvIdToEnumName(inputId): + return "INPUT_ACTION_" + inputId.upper() + +# Load up CSV file. +outHeader = "#pragma once\n" +outHeader += '#include "dusk.h"\n\n' + +outHeader += f"typedef float_t colorchannelf_t;\n" + + +with open(args.csv, newline="", encoding="utf-8") as csvfile: + reader = csv.DictReader(csvfile) + + # CSV must have id column. + if "id" not in reader.fieldnames: + raise Exception("CSV file must have 'id' column") + + # For each ID + inputIds = [] + inputIdValues = {} + for row in reader: + inputId = row["id"] + if inputId not in inputIds: + inputIds.append(inputId) + + # For each ID, create enum entry. + count = 0 + outHeader += "typedef enum {\n" + outHeader += f" INPUT_ACTION_NULL = {count},\n\n" + count += 1 + for inputId in inputIds: + inputIdValues[inputId] = count + outHeader += f" {csvIdToEnumName(inputId)} = {count},\n" + count += 1 + outHeader += f"\n INPUT_ACTION_COUNT = {count}\n" + outHeader += "} inputaction_t;\n\n" + + # Write IDs to char array. + outHeader += f"static const char_t* INPUT_ACTION_IDS[] = {{\n" + for inputId in inputIds: + outHeader += f" [{csvIdToEnumName(inputId)}] = \"{inputId}\",\n" + outHeader += f"}};\n\n" + + # Lua Script + outHeader += f"static const char_t *INPUT_ACTION_SCRIPT = \n" + for inputId in inputIds: + # Reference the enum + outHeader += f" \"{csvIdToEnumName(inputId)} = {inputIdValues[inputId]}\\n\"\n" + outHeader += f";\n\n" + +# Write to output file. +os.makedirs(os.path.dirname(args.output), exist_ok=True) +with open(args.output, "w", encoding="utf-8") as outFile: + outFile.write(outHeader) \ No newline at end of file