mirror of
https://github.com/dyne/FreeJ.git
synced 2026-06-16 12:59:33 +02:00
GeneratorLayer now can be used from javascript
This commit is contained in:
@@ -59,6 +59,7 @@ JS_SOURCES = context_js.cpp \
|
||||
image_layer_js.cpp \
|
||||
text_layer_js.cpp \
|
||||
geo_layer_js.cpp \
|
||||
generator_layer_js.cpp \
|
||||
flash_layer_js.cpp \
|
||||
goom_layer_js.cpp \
|
||||
audio_collector_js.cpp \
|
||||
|
||||
+5
-1
@@ -125,6 +125,7 @@ Context::Context() {
|
||||
Factory<Controller>::set_default_classtype("KeyboardController", "sdl");
|
||||
Factory<ViewPort>::set_default_classtype("Screen", "sdl");
|
||||
Factory<Layer>::set_default_classtype("MovieLayer", "ffmpeg");
|
||||
Factory<Layer>::set_default_classtype("GeneratorLayer","ff_f0r");
|
||||
#ifdef WITH_UNICAP
|
||||
Factory<Layer>::set_default_classtype("CamLayer", "unicap");
|
||||
#endif
|
||||
@@ -208,7 +209,10 @@ bool Context::init() {
|
||||
error ("Couldn't install SIGPIPE handler");
|
||||
// exit (0); lets not be so drastical...
|
||||
}
|
||||
|
||||
|
||||
// refresh the list of available plugins
|
||||
plugger.refresh(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -329,9 +329,6 @@ int main (int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
// refresh the list of available plugins
|
||||
freej->plugger.refresh(freej);
|
||||
|
||||
// load default settings
|
||||
freej->config_check("keyboard.js");
|
||||
|
||||
|
||||
+23
-13
@@ -18,6 +18,9 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <generator_layer.h>
|
||||
#include <frei0r_freej.h>
|
||||
#include <freeframe_freej.h>
|
||||
@@ -25,17 +28,18 @@
|
||||
|
||||
#include <jutils.h>
|
||||
#include <context.h>
|
||||
#include <config.h>
|
||||
//#include <jsparser_data.h>
|
||||
|
||||
// our objects are allowed to be created trough the factory engine
|
||||
|
||||
|
||||
GeneratorLayer::GeneratorLayer()
|
||||
:Layer() {
|
||||
|
||||
generator = NULL;
|
||||
generators = NULL;
|
||||
|
||||
type = Layer::F0R_GENERATOR;
|
||||
set_name("F0R");
|
||||
type = Layer::GENERATOR;
|
||||
set_name("GEN");
|
||||
//jsclass = &gen0r_layer_class;
|
||||
// set_filename("/particle generator");
|
||||
swap_buffer = NULL;
|
||||
@@ -57,33 +61,34 @@ static void set_frei0r_layer_parameter(Layer *lay, Parameter *param, int idx) {
|
||||
GeneratorLayer *layer = (GeneratorLayer*)lay;
|
||||
|
||||
Freior *f = layer->generator->proto->freior;
|
||||
bool *val = (bool*)param->value;
|
||||
void *val = param->value;
|
||||
|
||||
switch(f->param_infos[idx-1].type) {
|
||||
|
||||
// idx-1 because frei0r's index starts from 0
|
||||
case F0R_PARAM_BOOL:
|
||||
(*f->f0r_set_param_value)
|
||||
(layer->generator->core, new f0r_param_bool(val[0]), idx-1);
|
||||
(layer->generator->core, new f0r_param_bool(*(bool*)val), idx-1);
|
||||
break;
|
||||
|
||||
case F0R_PARAM_DOUBLE:
|
||||
(*f->f0r_set_param_value)(layer->generator->core, new f0r_param_double(val[0]), idx-1);
|
||||
(*f->f0r_set_param_value)(layer->generator->core,
|
||||
new f0r_param_double(*(double*)val), idx-1);
|
||||
break;
|
||||
|
||||
case F0R_PARAM_COLOR:
|
||||
{ f0r_param_color *color = new f0r_param_color;
|
||||
color->r = val[0];
|
||||
color->g = val[1];
|
||||
color->b = val[2];
|
||||
color->r = ((double*)val)[0];
|
||||
color->g = ((double*)val)[1];
|
||||
color->b = ((double*)val)[2];
|
||||
(*f->f0r_set_param_value)(layer->generator->core, color, idx-1);
|
||||
// QUAAA: should we delete the new allocated object? -jrml
|
||||
} break;
|
||||
|
||||
case F0R_PARAM_POSITION:
|
||||
{ f0r_param_position *position = new f0r_param_position;
|
||||
position->x = val[0];
|
||||
position->y = val[1];
|
||||
position->x = ((double*)val)[0];
|
||||
position->y = ((double*)val)[1];
|
||||
(*f->f0r_set_param_value)(layer->generator->core, position, idx-1);
|
||||
// QUAAA: should we delete the new allocated object? -jrml
|
||||
} break;
|
||||
@@ -98,13 +103,18 @@ static void set_frei0r_layer_parameter(Layer *lay, Parameter *param, int idx) {
|
||||
|
||||
void GeneratorLayer::register_generators(Linklist<Filter> *gens) {
|
||||
generators = gens;
|
||||
act("%u registered generators found", gens->len());
|
||||
act("%u generators available", gens->len());
|
||||
}
|
||||
|
||||
bool GeneratorLayer::open(const char *file) {
|
||||
func("%s - %s",__PRETTY_FUNCTION__, file);
|
||||
int idx;
|
||||
Filter *proto;
|
||||
|
||||
if(!generators) {
|
||||
error("No generators registered");
|
||||
return false; }
|
||||
|
||||
proto = (Filter*) generators->search(file, &idx);
|
||||
if(!proto) {
|
||||
error("generator not found: %s", file);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/* FreeJ
|
||||
* (c) Copyright 2009 Denis Roio aka jaromil <jaromil@dyne.org>
|
||||
*
|
||||
* This source code is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This source code 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. Please refer
|
||||
* to the GNU Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Public License along
|
||||
* with this source code; if not, write to: Free Software Foundation,
|
||||
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <callbacks_js.h>
|
||||
#include <jsparser_data.h>
|
||||
#include <config.h>
|
||||
#include <generator_layer.h>
|
||||
|
||||
|
||||
DECLARE_CLASS_GC("GeneratorLayer",
|
||||
generator_layer_class,
|
||||
generator_layer_constructor,
|
||||
js_layer_gc);
|
||||
|
||||
|
||||
JSFunctionSpec generator_layer_methods[] = {
|
||||
ENTRY_METHODS,
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
JS(generator_layer_constructor) {
|
||||
func("%s",__PRETTY_FUNCTION__);
|
||||
GeneratorLayer *layer = NULL;
|
||||
char excp_msg[MAX_ERR_MSG + 1];
|
||||
layer = new GeneratorLayer();
|
||||
if(!layer) {
|
||||
JS_ReportErrorNumber(cx, JSFreej_GetErrorMessage, NULL,
|
||||
JSSMSG_FJ_CANT_CREATE, __func__,
|
||||
"cannot create GeneratorLayer");
|
||||
return JS_FALSE;
|
||||
}
|
||||
layer->register_generators(&global_environment->generators);
|
||||
rval = (jsval*)layer->js_constructor(global_environment,
|
||||
cx, obj, argc, argv, excp_msg);
|
||||
if(!rval) {
|
||||
delete layer;
|
||||
JS_ReportErrorNumber(cx, JSFreej_GetErrorMessage, NULL,
|
||||
JSSMSG_FJ_CANT_CREATE, __func__, excp_msg);
|
||||
return JS_FALSE;
|
||||
}
|
||||
layer->data = (void*)rval;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ class GeneratorLayer: public Layer {
|
||||
|
||||
Linklist<Filter> *generators; ///< linked list of registered generators
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -62,6 +62,7 @@ class JsParser {
|
||||
JSObject *Screen;
|
||||
JSObject *Layer;
|
||||
JSObject *GeometryLayer;
|
||||
JSObject *GeneratorLayer;
|
||||
JSObject *ImageLayer;
|
||||
JSObject *FlashLayer;
|
||||
JSObject *GoomLayer;
|
||||
|
||||
@@ -56,6 +56,7 @@ JS(layer_constructor);
|
||||
//void js_layer_gc (JSContext *cx, JSObject *obj);
|
||||
JS(vscroll_layer_constructor);
|
||||
JS(geometry_layer_constructor);
|
||||
JS(generator_layer_constructor);
|
||||
JS(image_layer_constructor);
|
||||
JS(flash_layer_constructor);
|
||||
JS(movie_layer_constructor);
|
||||
@@ -166,6 +167,10 @@ extern JSFunctionSpec js_wii_ctrl_methods[];
|
||||
extern JSClass geometry_layer_class;
|
||||
extern JSFunctionSpec geometry_layer_methods[];
|
||||
|
||||
// GeneratorLayer
|
||||
extern JSClass generator_layer_class;
|
||||
extern JSFunctionSpec generator_layer_methods[];
|
||||
|
||||
// VScrollLayer
|
||||
extern JSClass vscroll_layer_class;
|
||||
extern JSFunctionSpec vscroll_layer_methods[];
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ class Layer: public Entry, public JSyncThread {
|
||||
enum Type {
|
||||
UNKNOWN,
|
||||
TEXT,
|
||||
F0R_GENERATOR,
|
||||
GENERATOR,
|
||||
#if defined HAVE_DARWIN && defined WITH_COCOA
|
||||
GL_COCOA
|
||||
#endif
|
||||
|
||||
@@ -345,6 +345,7 @@ template <class T> T *Linklist<T>::pick(int pos) {
|
||||
/* search the linklist for the entry matching *name
|
||||
returns the Entry* on success, NULL on failure */
|
||||
template <class T> T *Linklist<T>::search(const char *name, int *idx) {
|
||||
if(!first) return NULL;
|
||||
int c = 1;
|
||||
T *ptr = (T*)first;
|
||||
while(ptr) {
|
||||
|
||||
+11
-4
@@ -149,11 +149,18 @@ void JsParser::init_class(JSContext *cx, JSObject *obj) {
|
||||
object_proto = Layer; // following registrations inherit from parent class Layer
|
||||
|
||||
REGISTER_CLASS("GeometryLayer",
|
||||
geometry_layer_class,
|
||||
geometry_layer_constructor,
|
||||
geometry_layer_methods,
|
||||
object_proto);
|
||||
geometry_layer_class,
|
||||
geometry_layer_constructor,
|
||||
geometry_layer_methods,
|
||||
object_proto);
|
||||
GeometryLayer = layer_object;
|
||||
|
||||
REGISTER_CLASS("GeneratorLayer",
|
||||
generator_layer_class,
|
||||
generator_layer_constructor,
|
||||
generator_layer_methods,
|
||||
object_proto);
|
||||
GeneratorLayer = layer_object;
|
||||
|
||||
// REGISTER_CLASS("VScrollLayer",
|
||||
// vscroll_layer_class,
|
||||
|
||||
Reference in New Issue
Block a user