prog
This commit is contained in:
6
assets/ui/test.lua
Normal file
6
assets/ui/test.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
module('ui')
|
||||
module('color')
|
||||
|
||||
function draw(x, y)
|
||||
uiDrawRect(COLOR_WHITE, x, y, 32, 32)
|
||||
end
|
||||
@@ -65,4 +65,5 @@ add_subdirectory(script)
|
||||
add_subdirectory(thread)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(ui2)
|
||||
add_subdirectory(util)
|
||||
22
src/display/color.csv
Normal file
22
src/display/color.csv
Normal file
@@ -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
|
||||
|
@@ -11,4 +11,5 @@ add_subdirectory(item)
|
||||
add_subdirectory(locale)
|
||||
add_subdirectory(system)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(ui)
|
||||
@@ -10,4 +10,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
modulecamera.c
|
||||
modulespritebatch.c
|
||||
moduleglm.c
|
||||
modulecolor.c
|
||||
)
|
||||
48
src/script/module/display/modulecolor.c
Normal file
48
src/script/module/display/modulecolor.c
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
31
src/script/module/display/modulecolor.h
Normal file
31
src/script/module/display/modulecolor.h
Normal file
@@ -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
|
||||
);
|
||||
10
src/script/module/ui/CMakeLists.txt
Normal file
10
src/script/module/ui/CMakeLists.txt
Normal file
@@ -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
|
||||
)
|
||||
15
src/script/module/ui/moduleui.c
Normal file
15
src/script/module/ui/moduleui.c
Normal file
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
16
src/script/module/ui/moduleui.h
Normal file
16
src/script/module/ui/moduleui.h
Normal file
@@ -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);
|
||||
@@ -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 ( \
|
||||
|
||||
9
src/ui2/CMakeLists.txt
Normal file
9
src/ui2/CMakeLists.txt
Normal file
@@ -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
|
||||
)
|
||||
8
src/ui2/ui2.c
Normal file
8
src/ui2/ui2.c
Normal file
@@ -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"
|
||||
10
src/ui2/ui2.h
Normal file
10
src/ui2/ui2.h
Normal file
@@ -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).
|
||||
64
tools/display/color/csv/__main__.py
Normal file
64
tools/display/color/csv/__main__.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user