From c0a28689710361c18d71e9210c4faf473a31e787 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Mon, 9 Dec 2024 16:36:30 +0100 Subject: [PATCH] Add user sprite functions to C API. --- src/api/CMakeLists.txt | 4 + src/api/include/projectM-4/projectM.h | 1 + src/api/include/projectM-4/user_sprites.h | 128 ++++++++++++++++++++++ src/libprojectM/ProjectMCWrapper.cpp | 60 +++++++++- 4 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 src/api/include/projectM-4/user_sprites.h diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 656f1529c..1674d9aa6 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -5,10 +5,14 @@ target_sources(projectM_api "${PROJECTM_EXPORT_HEADER}" include/projectM-4/audio.h include/projectM-4/callbacks.h + include/projectM-4/core.h include/projectM-4/debug.h include/projectM-4/memory.h include/projectM-4/projectM.h + include/projectM-4/render_opengl.h + include/projectM-4/touch.h include/projectM-4/types.h + include/projectM-4/user_sprites.h ) set_target_properties(projectM_api PROPERTIES diff --git a/src/api/include/projectM-4/projectM.h b/src/api/include/projectM-4/projectM.h index ba4f70a79..2e93d7b5c 100644 --- a/src/api/include/projectM-4/projectM.h +++ b/src/api/include/projectM-4/projectM.h @@ -34,3 +34,4 @@ #include "projectM-4/render_opengl.h" #include "projectM-4/touch.h" #include "projectM-4/version.h" +#include "projectM-4/user_sprites.h" diff --git a/src/api/include/projectM-4/user_sprites.h b/src/api/include/projectM-4/user_sprites.h new file mode 100644 index 000000000..1bbf29bc5 --- /dev/null +++ b/src/api/include/projectM-4/user_sprites.h @@ -0,0 +1,128 @@ +/** + * @file user_sprites.h + * @copyright 2003-2024 projectM Team + * @brief Types and enumerations used in the other API headers. + * @since 4.2.0 + * + * projectM -- Milkdrop-esque visualisation SDK + * Copyright (C)2003-2024 projectM Team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE.txt' included within this release + * + */ + +#pragma once + +#include "projectM-4/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Loads and displays a new sprite. + * + * Currently, these sprite types are supported: + * + * + * Unsupported types and loading errors will result in failure, and no sprite will be added or replaced. + * + * @important The same OpenGL context used to create the projectM instance @a must be active when calling this method! + * @param instance The projectM instance handle. + * @param type The case-insensitive type name of the sprite to be displayed. See description for supported values. + * @param code The type-specific sprite code, e.g. the contents of an imgNN section from a Milkdrop user + * sprite INI file. + * @return A non-zero identifier if the sprite was successfully created, or zero if the type was + * unrecognized or the code couldn't be parsed. + * @since 4.2.0 + */ +PROJECTM_EXPORT uint32_t projectm_sprites_create(projectm_handle instance, + const char* type, + const char* code); + +/** + * @brief Destroys a single sprite. + * + * If there is no active sprite with the given ID, this method is a no-op. + * + * @param instance The projectM instance handle. + * @param sprite_id The ID of the sprite as returned by projectm_sprites_create(). + * @since 4.2.0 + */ +PROJECTM_EXPORT void projectm_sprites_destroy(projectm_handle instance, uint32_t sprite_id); + +/** + * @brief Destroys all active sprites. + * @param instance The projectM instance handle. + * @since 4.2.0 + */ +PROJECTM_EXPORT void projectm_sprites_destroy_all(projectm_handle instance); + +/** + * @brief Returns the number of currently active sprites. + * + * @note Sprites may destroy themselves after a frame has been rendered, and projectM can also + * remove a sprite if a new one is added and the sprite limit was already reached. + * Keep this in mind when calling projectm_sprites_get_sprite_ids() - ideally, + * call projectm_sprites_get_sprite_count() @a immediately before allocating the + * ID list. + * @param instance The projectM instance handle. + * @return The current number of sprites being rendered. + * @since 4.2.0 + */ +PROJECTM_EXPORT uint32_t projectm_sprites_get_sprite_count(projectm_handle instance); + +/** + * @brief Returns the number of currently active sprites. + * + * Identifiers are ordered by sprite age, with the oldest sprite first and the newest last. + * + * @param instance The projectM instance handle. + * @param sprite_ids A pointer to an already-allocated list which will receive the sprite IDs. + * Call projectm_sprites_get_sprite_count() to get the required length + * or allocate a list with the current sprite limit as its size and init all entries + * to zero. + * @since 4.2.0 + */ +PROJECTM_EXPORT void projectm_sprites_get_sprite_ids(projectm_handle instance, uint32_t* sprite_ids); + +/** + * @brief Sets the limit of concurrently displayed sprites. + * + * Once the limit is exceeded, the oldest sprite will be destroyed in order to display a new one. + * + * @param instance The projectM instance handle. + * @param max_sprites Maximum number of sprites to be displayed at once. Defaults to 16. + * @since 4.2.0 + */ +PROJECTM_EXPORT void projectm_sprites_set_max_sprites(projectm_handle instance, + uint32_t max_sprites); + +/** + * @brief Returns the currently set limit of concurrently displayed sprites. + * + * @param instance The projectM instance handle. + * @return The current maximum number of sprites to be displayed at once. + * @since 4.2.0 + */ +PROJECTM_EXPORT uint32_t projectm_sprites_get_max_sprites(projectm_handle instance); + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/libprojectM/ProjectMCWrapper.cpp b/src/libprojectM/ProjectMCWrapper.cpp index 15b7745d3..d2b942402 100644 --- a/src/libprojectM/ProjectMCWrapper.cpp +++ b/src/libprojectM/ProjectMCWrapper.cpp @@ -5,9 +5,9 @@ #include