From bdd826fd182dbb2a619a3f9cc45634cbd5604c58 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Mon, 3 Sep 2007 16:58:48 +0000 Subject: [PATCH] image url for custom shapes implemented git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@381 6778bc44-b910-0410-a7a0-be141de4315d --- src/projectM-engine/CustomShape.cpp | 9 ++++++++- src/projectM-engine/CustomShape.hpp | 19 ++++++++++++++++--- src/projectM-engine/Expr.cpp | 2 +- src/projectM-engine/Param.cpp | 19 +++++++++++++++++++ src/projectM-engine/Param.hpp | 3 +++ src/projectM-engine/Parser.cpp | 15 +++++++++++++++ 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/projectM-engine/CustomShape.cpp b/src/projectM-engine/CustomShape.cpp index 9f51f0f6f..59d48fd12 100755 --- a/src/projectM-engine/CustomShape.cpp +++ b/src/projectM-engine/CustomShape.cpp @@ -43,7 +43,7 @@ using namespace Algorithms; -CustomShape::CustomShape ( int id ) +CustomShape::CustomShape ( int id ) : imageUrl("") { Param * param; @@ -209,6 +209,13 @@ CustomShape::CustomShape ( int id ) { DWRITE ( "%s\n", "failed to insert param!" ); } + + param = Param::new_param_string ( "imageurl", P_FLAG_NONE, &this->imageUrl); + if ( ParamUtils::insert ( param, &this->text_properties_tree ) < 0 ) + { + DWRITE ( "%s\n", "failed to insert param!" ); + } + } /* Frees a custom shape form object */ diff --git a/src/projectM-engine/CustomShape.hpp b/src/projectM-engine/CustomShape.hpp index 532ad4563..0dc092507 100755 --- a/src/projectM-engine/CustomShape.hpp +++ b/src/projectM-engine/CustomShape.hpp @@ -86,16 +86,29 @@ public: float t6; float t7; float t8; - + + + // projectM exclusive parameter to load textures over a shape + std::string imageUrl; + + /// Returns any image url (usually used for texture maps) associated with the custom shape + /// Will return empty string if none is set + inline const std::string & getImageUrl() { + return imageUrl; + } + /* Data structure to hold per frame / per frame init equations */ + std::map init_cond_tree; std::map per_frame_eqn_tree; std::map per_frame_init_eqn_tree; - + std::map text_properties_tree; + /* Denotes the index of the last character for each stdring buffer */ int per_frame_eqn_string_index; int per_frame_init_eqn_string_index; - + + /* String buffers for per frame / per frame init equations */ char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE]; diff --git a/src/projectM-engine/Expr.cpp b/src/projectM-engine/Expr.cpp index 29557db8c..ebc10ff23 100755 --- a/src/projectM-engine/Expr.cpp +++ b/src/projectM-engine/Expr.cpp @@ -149,7 +149,7 @@ float ValExpr::eval_val_expr ( int mesh_i, int mesh_j ) //assert(mesh_i >=0); } //std::cout << term.param->name << ": " << (*((float*)term.param->engine_val)) << std::endl; - return * ( ( float* ) ( term.param->engine_val ) ); + return * ( ( float* ) ( term.param->engine_val ) ); default: return EVAL_ERROR; } diff --git a/src/projectM-engine/Param.cpp b/src/projectM-engine/Param.cpp index c22d4ceb8..8a0a59242 100755 --- a/src/projectM-engine/Param.cpp +++ b/src/projectM-engine/Param.cpp @@ -202,4 +202,23 @@ Param * Param::new_param_bool(char * name, short int flags, void * engine_val, return param; } +/* Creates a new parameter of type bool */ +Param * Param::new_param_string(char * name, short int flags, void * engine_val) { + + Param * param; + CValue iv, ub, lb; + assert(engine_val); + +// iv.bool_val = init_val; + // ub.bool_val = upper_bound; + // lb.bool_val = lower_bound; + + if ((param = new Param(name, P_TYPE_STRING, flags, engine_val, NULL, iv, ub, lb)) == NULL) + return NULL; + + + /* Finished, return success */ + return param; +} + diff --git a/src/projectM-engine/Param.hpp b/src/projectM-engine/Param.hpp index 6ea841fe8..95870b41e 100755 --- a/src/projectM-engine/Param.hpp +++ b/src/projectM-engine/Param.hpp @@ -38,6 +38,7 @@ #define P_TYPE_BOOL 0 #define P_TYPE_INT 1 #define P_TYPE_DOUBLE 2 +#define P_TYPE_STRING 3 #define P_FLAG_NONE 0 #define P_FLAG_READONLY 1 @@ -49,6 +50,7 @@ #define P_FLAG_PER_PIXEL (1 << 6) #define P_FLAG_PER_POINT (1 << 7) + #include "Expr.hpp" #include "Common.hpp" #include @@ -99,6 +101,7 @@ public: int upper_bound, int lower_bound, int init_val ); static Param * new_param_bool( char * name, short int flags, void * engine_val, int upper_bound, int lower_bound, int init_val ); + static Param * new_param_string(char * name, short int flags, void * engine_val); }; diff --git a/src/projectM-engine/Parser.cpp b/src/projectM-engine/Parser.cpp index 5ba41a9b6..71b2c32f3 100755 --- a/src/projectM-engine/Parser.cpp +++ b/src/projectM-engine/Parser.cpp @@ -1552,6 +1552,7 @@ int Parser::parse_shapecode(char * token, std::istream & fs, Preset * preset) { if (PARSE_DEBUG) printf("parse_shapecode: shapecode id = %d, parameter = \"%s\"\n", id, var_string); + /* Retrieve custom shape information from preset. The 3rd argument if true creates a custom shape if one does not exist */ @@ -1561,6 +1562,20 @@ int Parser::parse_shapecode(char * token, std::istream & fs, Preset * preset) { } if (PARSE_DEBUG) printf("parse_shapecode: custom shape found (id = %d)\n", custom_shape->id); + if ((param = ParamUtils::find(var_string, &custom_shape->text_properties_tree)) != NULL) + { + + char text[MAX_TOKEN_SIZE]; + token_t token = parseToken(fs, text); + + *((std::string*)param->engine_val) = std::string(text); + if (PARSE_DEBUG) + std::cerr << "parse_shapecode: found image url, text is \"" + << std::string(text) << "\"" << std::endl; + + return PROJECTM_SUCCESS; + } + /* Retrieve parameter from this custom shapes parameter db */