start a sub-project to implement a texture atlas editor default tip

Mon, 13 Oct 2025 21:37:42 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 13 Oct 2025 21:37:42 +0200
changeset 280
7845f5872bed
parent 279
97a1a7fb4f1a

start a sub-project to implement a texture atlas editor

.hgignore file | annotate | diff | comparison | revisions
Makefile file | annotate | diff | comparison | revisions
configure file | annotate | diff | comparison | revisions
make/project.xml file | annotate | diff | comparison | revisions
tools/Makefile file | annotate | diff | comparison | revisions
tools/atlas-editor.c file | annotate | diff | comparison | revisions
--- a/.hgignore	Thu Oct 09 19:22:21 2025 +0200
+++ b/.hgignore	Mon Oct 13 21:37:42 2025 +0200
@@ -2,5 +2,6 @@
 nbproject/
 build/
 dist/
+toolkit/
 shader/.*\.h
 config.mk
--- a/Makefile	Thu Oct 09 19:22:21 2025 +0200
+++ b/Makefile	Mon Oct 13 21:37:42 2025 +0200
@@ -23,7 +23,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-all: snake
+all: snake tools
 
 snake: build/lib/libascension.a FORCE
 	@cd demo/snake && $(MAKE)
@@ -31,6 +31,9 @@
 build/lib/libascension.a: config.mk FORCE
 	@cd src && $(MAKE)
 
+tools: config.mk FORCE
+	cd tools && $(MAKE)
+
 clean:
 	rm -f -R build
 
--- a/configure	Thu Oct 09 19:22:21 2025 +0200
+++ b/configure	Mon Oct 13 21:37:42 2025 +0200
@@ -112,6 +112,7 @@
 
 Optional Features:
   --enable-asan           Enable address sanitization.
+  --enable-tools          Enable compilation of tools.
 
 __EOF__
 }
@@ -152,6 +153,7 @@
 if true \
       ; then
     SRCDIR=`pwd`
+    TOOLKIT_HOME="${TOOLKIT_HOME:=/usr}"
 fi
 
 # features
@@ -183,6 +185,8 @@
         "--release")          BUILD_TYPE="release" ;;
         "--enable-asan") FEATURE_ASAN=on ;;
         "--disable-asan") unset FEATURE_ASAN ;;
+        "--enable-tools") FEATURE_TOOLS=on ;;
+        "--disable-tools") unset FEATURE_TOOLS ;;
         "-"*) echo "unknown option: $ARG"; abort_configure ;;
     esac
 done
@@ -343,6 +347,64 @@
     dep_checked_sdl3_ttf=1
     return 0
 }
+dependency_error_gtk3()
+{
+    print_check_msg "$dep_checked_gtk3" "checking for gtk3... "
+    # dependency gtk3
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "gtk+-3.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-3.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-3.0`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK3"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread"
+        print_check_msg "$dep_checked_gtk3" "yes\n"
+        dep_checked_gtk3=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_gtk3" "no\n"
+    dep_checked_gtk3=1
+    return 0
+}
+dependency_error_toolkit()
+{
+    print_check_msg "$dep_checked_toolkit" "checking for toolkit... "
+    # dependency toolkit
+    while true
+    do
+        if test -n "$TOOLKIT_HOME" > /dev/null ; then
+            :
+        else
+            break
+        fi
+        if test -f "$TOOLKIT_HOME/lib/libuitk.a" > /dev/null ; then
+            :
+        else
+            break
+        fi
+        if test -f "$TOOLKIT_HOME/include/ui/ui.h" > /dev/null ; then
+            :
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -I$TOOLKIT_HOME/include"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS $TOOLKIT_HOME/lib/libuitk.a"
+        print_check_msg "$dep_checked_toolkit" "yes\n"
+        dep_checked_toolkit=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_toolkit" "no\n"
+    dep_checked_toolkit=1
+    return 0
+}
 dependency_error_glew()
 {
     print_check_msg "$dep_checked_glew" "checking for glew... "
@@ -555,6 +617,52 @@
     echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
 fi
 
+echo >> "$TEMP_DIR/flags.mk"
+echo "configuring target: tools"
+echo "# flags for target tools" >> "$TEMP_DIR/flags.mk"
+TEMP_CFLAGS=
+TEMP_CXXFLAGS=
+TEMP_LDFLAGS=
+
+if dependency_error_toolkit; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED toolkit "
+    ERROR=1
+fi
+if dependency_error_gtk3; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED gtk3 "
+    ERROR=1
+fi
+if dependency_error_ucx; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx "
+    ERROR=1
+fi
+
+# Features
+if [ -n "$FEATURE_TOOLS" ]; then
+    if [ -n "$DISABLE_FEATURE_TOOLS" ]; then
+        unset FEATURE_TOOLS
+    fi
+fi
+if [ -n "$FEATURE_TOOLS" ]; then
+    :
+else
+    :
+    cat >> "$TEMP_DIR/make.mk" << __EOF__
+NO_TOOLS=1
+__EOF__
+fi
+
+
+if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then
+    echo "TOOLS_CFLAGS  += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
+fi
+if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then
+    echo "TOOLS_CXXFLAGS  += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
+fi
+if [ -n "${TEMP_LDFLAGS}" ]; then
+    echo "TOOLS_LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
+fi
+
 
 # final result
 if [ $ERROR -ne 0 ]; then
@@ -633,6 +741,11 @@
 else
 echo "  asan: off"
 fi
+if [ -n "$FEATURE_TOOLS" ]; then
+echo "  tools: on"
+else
+echo "  tools: off"
+fi
 echo
 
 # generate the config.mk file
--- a/make/project.xml	Thu Oct 09 19:22:21 2025 +0200
+++ b/make/project.xml	Mon Oct 13 21:37:42 2025 +0200
@@ -2,6 +2,7 @@
 <project xmlns="http://unixwork.de/uwproj" version="0.3">
     <config>
         <var name="SRCDIR" exec="true">pwd</var>
+        <var name="TOOLKIT_HOME">${TOOLKIT_HOME:=/usr}</var>
     </config>
 	<dependency>
 		<lang>c</lang>
@@ -35,6 +36,20 @@
         <ldflags>-fsanitize=address</ldflags>
     </dependency>
 
+    <dependency name="toolkit">
+        <test>test -n "$TOOLKIT_HOME"</test>
+        <test>test -f "$TOOLKIT_HOME/lib/libuitk.a"</test>
+        <test>test -f "$TOOLKIT_HOME/include/ui/ui.h"</test>
+        <cflags>-I$TOOLKIT_HOME/include</cflags>
+        <ldflags>$TOOLKIT_HOME/lib/libuitk.a</ldflags>
+    </dependency>
+
+    <dependency name="gtk3">
+        <pkgconfig>gtk+-3.0</pkgconfig>
+        <cflags>-DUI_GTK3</cflags>
+        <ldflags>-lpthread</ldflags>
+    </dependency>
+
     <target>
         <feature name="asan">
             <desc>Enable address sanitization.</desc>
@@ -42,5 +57,14 @@
         </feature>
         <dependencies>ucx,sdl3,sdl3_ttf,sdl3_image,glew</dependencies>
     </target>
+    <target name="tools">
+        <feature name="tools">
+            <desc>Enable compilation of tools.</desc>
+            <disabled>
+                <make>NO_TOOLS=1</make>
+            </disabled>
+        </feature>
+        <dependencies>toolkit,gtk3,ucx</dependencies>
+    </target>
 </project>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/Makefile	Mon Oct 13 21:37:42 2025 +0200
@@ -0,0 +1,47 @@
+# Copyright 2025 Mike Becker. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#
+#   2. Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+include ../config.mk
+
+BUILD_DIR=../build/tools
+
+all:
+	@if test -z "$(NO_TOOLS)"; then \
+		$(MAKE) tools; \
+	else \
+	    echo "Tools compilation skipped."; \
+	fi
+
+tools: atlas-editor
+
+$(BUILD_DIR):
+	mkdir -p $@
+
+atlas-editor: $(BUILD_DIR) $(BUILD_DIR)/atlas-editor
+	@echo "Texture atlas editor compiled and linked."
+
+$(BUILD_DIR)/atlas-editor: atlas-editor.c
+	$(CC) -o $@ $(TOOLS_CFLAGS) $^ $(TOOLS_LDFLAGS)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/atlas-editor.c	Mon Oct 13 21:37:42 2025 +0200
@@ -0,0 +1,46 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ * Copyright 2025 Mike Becker. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ui/ui.h>
+
+static void application_startup([[maybe_unused]] UiEvent *event, [[maybe_unused]]  void *data) {
+    UiObject *window = ui_window("Ascension - Texture Atlas Editor", NULL);
+
+    ui_show(window);
+}
+
+int main(int argc, char** argv) { 
+    ui_init("asc_atlas_editor", argc, argv);
+    ui_onstartup(application_startup, NULL);
+
+    ui_set_property("ui.gtk.window.showtitle", "sidebar");
+    ui_set_property("ui.gtk.window.appmenu.position", "rightpanel");
+
+    ui_main();
+    
+    return 0;
+}

mercurial