aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2005-11-22 06:20:38 +0000
committerN.N. <sevyves@users.sourceforge.net>2005-11-22 06:20:38 +0000
commita49131316e752f09d459b58f827bc6025cb97af7 (patch)
tree304fb672389005409c3c9c2ee5a2b6c5da158efe /modules
parentbd0e7606604ce39c6f5914f6d61d4d1feaaf1904 (diff)
PiDiP 0.12.20
svn path=/trunk/externals/pidip/; revision=4015
Diffstat (limited to 'modules')
-rw-r--r--modules/Makefile4
-rw-r--r--modules/Makefile.in2
-rw-r--r--modules/pdp_imgloader.c211
-rwxr-xr-xmodules/pdp_qtext.c1086
4 files changed, 1236 insertions, 67 deletions
diff --git a/modules/Makefile b/modules/Makefile
index a00c7d3..171ebfd 100644
--- a/modules/Makefile
+++ b/modules/Makefile
@@ -20,7 +20,7 @@ OBJECTS = pdp_intrusion.o pdp_yqt.o pdp_simura.o pdp_underwatch.o \
pdp_disintegration.o pdp_distance.o pdp_theorin~.o \
pdp_theorout~.o pdp_cropper.o pdp_background.o \
pdp_mapper.o pdp_theonice~.o pdp_icedthe~.o\
- pdp_fdiff.o pdp_hue.o \
- pdp_live~.o pdp_ffmpeg~.o # pdp_xcanvas.o pdp_aa.o
+ pdp_fdiff.o pdp_hue.o pdp_qtext.o \
+ # pdp_xcanvas.o pdp_aa.o
all_modules: $(OBJECTS)
diff --git a/modules/Makefile.in b/modules/Makefile.in
index 128795c..b3c712c 100644
--- a/modules/Makefile.in
+++ b/modules/Makefile.in
@@ -20,7 +20,7 @@ OBJECTS = pdp_intrusion.o pdp_yqt.o pdp_simura.o pdp_underwatch.o \
pdp_disintegration.o pdp_distance.o pdp_theorin~.o \
pdp_theorout~.o pdp_cropper.o pdp_background.o \
pdp_mapper.o pdp_theonice~.o pdp_icedthe~.o\
- pdp_fdiff.o pdp_hue.o \
+ pdp_fdiff.o pdp_hue.o pdp_qtext.o \
@PDP_STREAMING_OBJECTS@ # pdp_xcanvas.o pdp_aa.o
all_modules: $(OBJECTS)
diff --git a/modules/pdp_imgloader.c b/modules/pdp_imgloader.c
index 752e4bc..2d74738 100644
--- a/modules/pdp_imgloader.c
+++ b/modules/pdp_imgloader.c
@@ -1,6 +1,6 @@
/*
* PiDiP module
- * Copyright (c) by Yves Degoyon (ydegoyon@free.fr)
+ * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) and Pablo Martin Caedes ( caedes@sindominio.net )
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@
#define MAX_ZONES 20
-static char *pdp_imgloader_version = "pdp_imgloader: version 0.1 : image loading object written by ydegoyon@free.fr ";
+static char *pdp_imgloader_version = "pdp_imgloader: version 0.2 : image loading object written by ydegoyon@free.fr, improved by caedes@sindominio.net";
typedef struct _triangle
{
@@ -66,14 +66,18 @@ typedef struct pdp_imgloader_struct
DATA32 *x_imdata;
t_int x_iwidth;
t_int x_iheight;
+ t_int x_operation;
+ t_int b_fit;
t_float x_blend;
+ t_int x_quality; // quality forces an additional yuv->rgb conversion in yuv mode
t_triangle x_hiddenzones[ MAX_ZONES ]; // hide these parts of the image
unsigned char *x_mask;
} t_pdp_imgloader;
+static void draw_rgb_image(t_pdp_imgloader *x);
/* load an image */
static void pdp_imgloader_load(t_pdp_imgloader *x, t_symbol *filename, t_floatarg fx, t_floatarg fy)
{
@@ -98,8 +102,16 @@ static void pdp_imgloader_load(t_pdp_imgloader *x, t_symbol *filename, t_floatar
x->x_iwidth = imlib_image_get_width();
x->x_iheight = imlib_image_get_height();
post( "pdp_imgloader : loaded : %s (%dx%d)", filename->s_name, x->x_iwidth, x->x_iheight );
- if ( fx!= 0.) x->x_xoffset = (int) fx;
- if ( fy!= 0.) x->x_yoffset = (int) fy;
+ x->x_xoffset = (int) fx;
+ x->x_yoffset = (int) fy;
+
+ //if ( fx!= 0.) x->x_xoffset = (int) fx;
+ //if ( fy!= 0.) x->x_yoffset = (int) fy;
+ DATA8 tablas[768];
+ DATA8 *redt,*greent,*bluet;
+ redt = &tablas[0];
+ greent = &tablas[256];
+ bluet = &tablas[512];
}
static void pdp_imgloader_xoffset(t_pdp_imgloader *x, t_floatarg fx )
@@ -112,14 +124,32 @@ static void pdp_imgloader_yoffset(t_pdp_imgloader *x, t_floatarg fy )
x->x_yoffset = (int) fy;
}
+static void pdp_imgloader_quality(t_pdp_imgloader *x, t_floatarg fqual )
+{
+ x->x_quality = (int) fqual;
+}
+
static void pdp_imgloader_blend(t_pdp_imgloader *x, t_floatarg fblend )
{
- if ( ( fblend > 0.0 ) && ( fblend < 1.0 ) )
+ if ( ( fblend >= 0.0 ) && ( fblend <= 1.0 ) )
{
x->x_blend = fblend;
}
}
-
+static void pdp_imgloader_fit(t_pdp_imgloader *x, t_floatarg ffit )
+{
+ if ( ( ffit >= 0.0 ) )
+ {
+ x->b_fit = (int)ffit;
+ }
+}
+static void pdp_imgloader_operation(t_pdp_imgloader *x, t_symbol *s)
+{
+ if (s == gensym("copy")) x->x_operation = IMLIB_OP_COPY;
+ else if (s == gensym("add")) x->x_operation = IMLIB_OP_ADD;
+ else if (s == gensym("substract")) x->x_operation = IMLIB_OP_SUBTRACT;
+ else if (s == gensym("reshade")) x->x_operation = IMLIB_OP_RESHADE;
+}
static t_int pdp_imgloader_isinzone(t_pdp_imgloader *x, t_int px, t_int py, t_int index)
{
t_int c1=0, c2=0, c3=0;
@@ -472,10 +502,12 @@ static void pdp_imgloader_unhide(t_pdp_imgloader *x, t_floatarg findex )
static void pdp_imgloader_clear(t_pdp_imgloader *x )
{
- //if ( x->x_image != NULL )
- //{
- // imlib_free_image();
- //}
+ if ( x->x_image != NULL )
+ {
+ imlib_context_set_image(x->x_image);
+ imlib_image_put_back_data(x->x_imdata);
+ imlib_free_image();
+ }
x->x_image = NULL;
}
@@ -492,6 +524,46 @@ static void pdp_imgloader_allocate(t_pdp_imgloader *x )
x->x_mask = (unsigned char*)getbytes( x->x_vsize );
}
+static void draw_rgb_image(t_pdp_imgloader *x)
+{
+ Imlib_Image im_target = imlib_context_get_image();
+ imlib_context_set_operation(x->x_operation);
+
+ int i;
+ DATA8 redt[256], greent[256], bluet[256], alphat[256];
+ Imlib_Color_Modifier colormod = imlib_create_color_modifier();
+ imlib_context_set_color_modifier(colormod);
+ imlib_context_set_image(x->x_image);
+ Imlib_Image image_buf= imlib_clone_image(); //clones for color mod
+ imlib_context_set_image(image_buf);
+ if ( x->x_blend < 1.0 )
+ {
+ imlib_get_color_modifier_tables( redt, greent, bluet, alphat );
+ for ( i=0; i<=255; i++ )
+ {
+ alphat[i]=alphat[i]*x->x_blend;
+ }
+ imlib_set_color_modifier_tables( redt, greent, bluet, alphat );
+ imlib_apply_color_modifier();
+ }
+ imlib_context_set_image(im_target);
+ if (x->b_fit)
+ {
+ imlib_blend_image_onto_image(image_buf,0,0,0,x->x_iwidth,x->x_iheight,x->x_xoffset,x->x_yoffset,
+ x->x_xoffset+x->x_vwidth,x->x_yoffset+x->x_vheight);
+ }
+ else
+ {
+ imlib_blend_image_onto_image(image_buf,0,0,0,x->x_iwidth,x->x_iheight,x->x_xoffset,x->x_yoffset,x->x_iwidth,x->x_iheight);
+ }
+ imlib_context_set_operation(IMLIB_OP_COPY);
+
+ imlib_context_set_image(image_buf);
+ imlib_free_image();
+ imlib_free_color_modifier();
+ imlib_context_set_image(im_target);
+}
+
static void pdp_imgloader_process_yv12(t_pdp_imgloader *x)
{
t_pdp *header = pdp_packet_header(x->x_packet0);
@@ -516,62 +588,65 @@ static void pdp_imgloader_process_yv12(t_pdp_imgloader *x)
newheader->info.image.encoding = header->info.image.encoding;
newheader->info.image.width = x->x_vwidth;
newheader->info.image.height = x->x_vheight;
-
- memcpy( newdata, data, (x->x_vsize+(x->x_vsize>>1))<<1 );
-
- if ( x->x_image != NULL ) imlib_context_set_image(x->x_image);
- pY = newdata;
- pV = newdata+x->x_vsize;
- pU = newdata+x->x_vsize+(x->x_vsize>>2);
- for ( py=0; py<x->x_vheight; py++ )
+ if (x->x_quality && x->x_image != NULL)
{
- for ( px=0; px<x->x_vwidth; px++ )
- {
- if ( ( x->x_image != NULL )
- && (px >= x->x_xoffset) && ( px < x->x_xoffset + x->x_iwidth )
- && (py >= x->x_yoffset) && ( py < x->x_yoffset + x->x_iheight )
- && ( !(*(x->x_mask+py*x->x_vwidth+px)) )
- )
+ Imlib_Image newframe; //only for quality mode
+ newframe = imlib_create_image(x->x_vwidth, x->x_vheight);
+ imlib_context_set_image(newframe);
+ DATA32 *imdata = imlib_image_get_data();
+ yuv_Y122RGB( data, imdata, x->x_vwidth, x->x_vheight );
+ draw_rgb_image(x);
+ yuv_RGB2Y12( imdata, newdata, x->x_vwidth, x->x_vheight );
+ imlib_image_put_back_data(imdata);
+ imlib_free_image();
+ }
+ else
+ {
+ if ( x->x_image != NULL ) imlib_context_set_image(x->x_image);
+ memcpy( newdata, data, (x->x_vsize+(x->x_vsize>>1))<<1 );
+
+ pY = newdata;
+ pV = newdata+x->x_vsize;
+ pU = newdata+x->x_vsize+(x->x_vsize>>2);
+ for ( py=0; py<x->x_vheight; py++ )
{
- y = yuv_RGBtoY(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
- u = yuv_RGBtoU(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
- v = yuv_RGBtoV(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
-
-
- if ( imlib_image_has_alpha() )
- {
- alpha = (x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)] >> 24)/255;
- }
- else
- {
- alpha = 1.0;
- }
- factor = x->x_blend*alpha;
-
- *(pY) = (int)((1-factor)*(*(pY)) + factor*(y<<7));
+ for ( px=0; px<x->x_vwidth; px++ )
+ {
+ if ( ( x->x_image != NULL )
+ && (px >= x->x_xoffset) && ( px < x->x_xoffset + x->x_iwidth )
+ && (py >= x->x_yoffset) && ( py < x->x_yoffset + x->x_iheight )
+ && ( !(*(x->x_mask+py*x->x_vwidth+px)) )
+ )
+ {
+ y = yuv_RGBtoY(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
+ u = yuv_RGBtoU(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
+ v = yuv_RGBtoV(x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)]);
+
+
+ if ( imlib_image_has_alpha() )
+ {
+ alpha = (x->x_imdata[(py-x->x_yoffset)*x->x_iwidth+(px-x->x_xoffset)] >> 24)/255;
+ }
+ else
+ {
+ alpha = 1.0;
+ }
+ factor = x->x_blend*alpha;
+
+ *(pY) = (int)((1-factor)*(*(pY)) + factor*(y<<7));
+ if ( (px%2==0) && (py%2==0) )
+ {
+ *(pV) = (int)((1-factor)*(*(pV)) + factor*((v-128)<<8));
+ *(pU) = (int)((1-factor)*(*(pU)) + factor*((u-128)<<8));
+ }
+ }
+ pY++;
if ( (px%2==0) && (py%2==0) )
{
- *(pV) = (int)((1-factor)*(*(pV)) + factor*((v-128)<<8));
- *(pU) = (int)((1-factor)*(*(pU)) + factor*((u-128)<<8));
+ pV++;pU++;
}
+ }
}
- // paint it white ( for debugging )
- /*
- if ( ( abs( py - x->x_hiddenzones[0].a1*px - x->x_hiddenzones[0].b1 ) < 0.1 ) ||
- ( abs( py - x->x_hiddenzones[0].a2*px - x->x_hiddenzones[0].b2 ) < 0.1 ) ||
- ( abs( py - x->x_hiddenzones[0].a3*px - x->x_hiddenzones[0].b3 ) < 0.1 ) )
- {
- *(pY) = (0xff<<7);
- *(pU) = (0xff<<8);
- *(pV) = (0xff<<8);
- }
- */
- pY++;
- if ( (px%2==0) && (py%2==0) )
- {
- pV++;pU++;
- }
- }
}
return;
@@ -609,7 +684,6 @@ static void pdp_imgloader_process(t_pdp_imgloader *x)
// should write something to handle these one day
// but i don't use this mode
break;
-
default:
/* don't know the type, so dont pdp_imgloader_process */
break;
@@ -625,8 +699,12 @@ static void pdp_imgloader_input_0(t_pdp_imgloader *x, t_symbol *s, t_floatarg f)
/* if this is a register_ro message or register_rw message, register with packet factory */
if (s== gensym("register_rw"))
- x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("image/YCrCb/*") );
-
+ switch(pdp_packet_header((int)f)->info.image.encoding)
+ {
+ case PDP_IMAGE_YV12:
+ x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("image/YCrCb/*") );
+ break;
+ }
if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){
/* add the process method and callback to the process queue */
@@ -662,8 +740,10 @@ void *pdp_imgloader_new(void)
x->x_queue_id = -1;
x->x_image = NULL;
- x->x_blend = 1;
+ x->x_blend = 1.0;
x->x_mask = NULL;
+ x->x_quality = 0;
+ x->b_fit = 0;
for ( ti=0; ti<MAX_ZONES; ti++ )
{
@@ -694,9 +774,12 @@ void pdp_imgloader_setup(void)
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_xoffset, gensym("xoffset"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_yoffset, gensym("yoffset"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_blend, gensym("blend"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_quality, gensym("quality"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_hide, gensym("hide"), A_GIMME, A_NULL);
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_rawhide, gensym("rawhide"), A_GIMME, A_NULL);
class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_unhide, gensym("unhide"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_operation, gensym("operation"), A_SYMBOL, A_NULL);
+ class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_fit, gensym("fit"), A_DEFFLOAT, A_NULL);
class_sethelpsymbol( pdp_imgloader_class, gensym("pdp_imgloader.pd") );
}
diff --git a/modules/pdp_qtext.c b/modules/pdp_qtext.c
new file mode 100755
index 0000000..8bcf4a4
--- /dev/null
+++ b/modules/pdp_qtext.c
@@ -0,0 +1,1086 @@
+/*
+ * PiDiP module
+ * Copyright (c) by Yves Degoyon (ydegoyon@free.fr)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* This object is a text rendering object for PDP
+ * It uses imlib2 for all graphical operations
+ */
+
+/* Listening to :
+ * Deviants - Nothing Man
+ * Os Mutantes - El Justeciero
+ */
+
+#define _GNU_SOURCE
+#include <string.h>
+#include "pdp.h"
+#include "yuv.h"
+#include <math.h>
+#include <wchar.h>
+#include <ctype.h>
+#include <Imlib2.h> // imlib2 is required
+
+#define DEFAULT_CAPACITY 10
+#define DEFAULT_FONT "helmetr/16"
+
+#define PIDIP_TEXT_MODE_STATIC 0
+#define PIDIP_TEXT_MODE_SCROLL 1
+#define PIDIP_TEXT_MODE_FEED 2
+#define PIDIP_TEXT_MODE_SLOW 3
+
+#define PIDIP_ALIGNMENT_CENTER 0
+#define PIDIP_ALIGNMENT_LEFT 1
+#define PIDIP_ALIGNMENT_RIGHT 2
+
+static char *pdp_qtext_version = "pdp_qtext: version 0.2 : modified pdp_text by Pablo Martin Caedes";
+
+typedef struct text_frame_struct TEXT_FRAME;
+struct text_frame_struct
+{
+ char *text_array;
+ TEXT_FRAME *next;
+ double time;
+};
+
+typedef struct text_layer_struct
+{
+ t_int l_xoffset; // x position
+ t_int l_yoffset; // y position
+ t_int l_r; // first color
+ t_int l_g;
+ t_int l_b;
+ t_int l_a;
+ t_int l_2r; // color for even lines of feed
+ t_int l_2g;
+ t_int l_2b;
+ t_int l_2a;
+ t_int l_borderr; // color for the border
+ t_int l_borderg;
+ t_int l_borderb;
+ t_float l_angle; // angle
+ t_int l_scroll;
+ t_int l_alignment; // 0 - center; 1 - left; 2 - right;
+ t_int l_marginh; // top margin
+ t_int l_marginv; // bottom margin
+ t_int l_active; // slot is active?
+
+ t_int l_feed_turn; // even or odd turn
+
+ t_int l_mode; // work mode: static, scroll, feed/chat, slow
+ t_int l_scroll_speed;
+ t_int l_upwards; // whether to put new elements at top or bottom of the queue
+ TEXT_FRAME *l_texts;
+ TEXT_FRAME *l_last_text;
+ t_int l_ntexts; // number of texts in the chat queue
+ Imlib_Font l_font;
+} TEXTLAYER;
+
+typedef struct pdp_qtext_struct
+{
+ t_object x_obj;
+ t_float x_f;
+
+ t_int x_packet0;
+ t_int x_packet1;
+ t_int x_dropped;
+ t_int x_queue_id;
+
+ t_outlet *x_outlet0;
+ t_int x_vwidth;
+ t_int x_vheight;
+ t_int x_vsize;
+
+ t_int x_nbtexts;
+ t_int x_current; // currently selected layer
+ t_int x_capacity; // maximum texts
+
+ // text layers
+ TEXTLAYER *x_layers;
+ /* imlib data */
+ Imlib_Image x_image;
+
+} t_pdp_qtext;
+
+void text_layer_flush(TEXTLAYER *layer)
+{
+ while(layer->l_texts != NULL)
+ {
+ TEXT_FRAME *oldframe = layer->l_texts;
+ layer->l_texts = oldframe->next;
+ free(oldframe->text_array);
+ free(oldframe);
+ }
+ layer->l_last_text = NULL;
+ layer->l_ntexts = 0;
+
+}
+void text_layer_add_start(TEXTLAYER *layer,char *text)
+{
+ TEXT_FRAME *newframe = (TEXT_FRAME*)getbytes(sizeof(TEXT_FRAME));
+ newframe->text_array = text;
+ newframe->time = 0;
+
+ if (layer->l_texts == NULL)
+ {
+ layer->l_last_text = newframe;
+ newframe->next = NULL;
+ }
+ else
+ newframe->next = layer->l_texts;
+ layer->l_texts = newframe;
+ layer->l_ntexts++;
+}
+
+void text_layer_add_end(TEXTLAYER *layer, char *text)
+{
+ TEXT_FRAME *newframe = (TEXT_FRAME*)getbytes(sizeof(TEXT_FRAME));
+ newframe->text_array = text;
+ newframe->time = 0;
+ newframe->next = NULL;
+
+ if (layer->l_texts == NULL)
+ layer->l_texts = newframe;
+ else
+ layer->l_last_text->next = newframe;
+ layer->l_last_text = newframe;
+ layer->l_ntexts++;
+}
+void text_layer_delete_start(TEXTLAYER *layer)
+{
+ if (layer->l_texts != NULL)
+ {
+ TEXT_FRAME *oldframe = layer->l_texts;
+ //free(oldframe->text_array);
+ free(oldframe);
+ layer->l_texts = oldframe->next;
+ }
+ layer->l_ntexts--;
+}
+
+TEXT_FRAME * text_layer_find_last(TEXTLAYER *layer)
+{
+ TEXT_FRAME *actual= layer->l_texts;
+ if (actual == NULL)
+ return NULL;
+ while(actual->next != NULL)
+ actual = actual->next;
+ return actual;
+}
+TEXT_FRAME * text_layer_find_ancestor(TEXTLAYER *layer, TEXT_FRAME *following)
+{
+ TEXT_FRAME *actual= layer->l_texts;
+ if (actual == NULL)
+ return NULL;
+ while(actual->next != following)
+ actual = actual->next;
+ return actual;
+}
+
+void text_layer_delete_end(TEXTLAYER *layer)
+{
+ if (layer->l_texts != NULL)
+ {
+ TEXT_FRAME *oldframe = layer->l_last_text;
+ //free(oldframe->text_array);
+ if (oldframe == layer->l_texts) // IF IT WAS FIRST
+ {
+ layer->l_last_text = NULL;
+ layer->l_texts = NULL;
+ free(oldframe);
+ }
+ else
+ {
+ layer->l_last_text = text_layer_find_ancestor(layer,layer->l_last_text);
+ layer->l_last_text->next = NULL;
+ }
+ free(oldframe);
+ }
+ layer->l_ntexts--;
+}
+
+static void pdp_qtext_delete(t_pdp_qtext *x, t_floatarg fnum );
+ /* add a new text : syntax : text <my%20text> x y */
+static void pdp_qtext_add(t_pdp_qtext *x, t_symbol *s, int argc, t_atom *argv)
+{
+ char *pname;
+ char *pdname;
+ t_int len;
+
+ if ( argc < 3 )
+ {
+ post( "pdp_qtext : error in the number of arguments ( minimum is 3 )", argc );
+ return;
+ }
+ if ( argv[0].a_type != A_SYMBOL || argv[1].a_type != A_FLOAT || argv[2].a_type != A_FLOAT ) {
+ post( "pdp_qtext : add : wrong arguments" );
+ return;
+ }
+
+ // allocate new text area
+ len = strlen( argv[0].a_w.w_symbol->s_name );
+ if ( x->x_current == -1 ) x->x_current = 0;
+
+ // get memory
+ pdname = (char *) getbytes( len+1 );
+ pname = (char *) getbytes( len+1 );
+ memset( pname, 0x0, len+1 );
+ memcpy( pname, argv[0].a_w.w_symbol->s_name, len );
+
+ x->x_layers[x->x_current].l_active = 1;
+ // add text to selected queue
+ switch ( x->x_layers[x->x_current].l_mode)
+ {
+ case PIDIP_TEXT_MODE_STATIC: // REPLACE_CURRENT_TEXT
+ text_layer_delete_start(&x->x_layers[x->x_current]);
+ text_layer_add_start(&x->x_layers[x->x_current],pdname);
+ break;
+ case PIDIP_TEXT_MODE_SLOW: // REPLACE_CURRENT_TEXT
+ text_layer_delete_start(&x->x_layers[x->x_current]);
+ text_layer_add_start(&x->x_layers[x->x_current],pdname);
+ break;
+ case PIDIP_TEXT_MODE_SCROLL: // ADD_TEXT_AT_END
+ text_layer_add_end(&x->x_layers[x->x_current],pdname);
+ break;
+ case PIDIP_TEXT_MODE_FEED: // ADD_TEXT_AT_END_OR_START
+ if (!x->x_layers[x->x_current].l_upwards) // DOWNWARDS FEED
+ text_layer_add_start(&x->x_layers[x->x_current],pdname);
+ else
+ text_layer_add_end(&x->x_layers[x->x_current],pdname);
+ break;
+ }
+
+ // process new text
+ while (*(pname))
+ {
+ if ( (*pname=='%') && ( isdigit(*(pname+1)) || (*(pname+1)=='%') ) )
+ {
+ t_int ivalue;
+ t_int ndigits;
+ char *piname;
+
+ ndigits=0;
+ piname=pname+1;
+ while ( isdigit( *(piname++) ) ) ndigits++;
+
+ ivalue=atoi(pname+1);
+
+ // special case %%
+ if ( ( pname != argv[0].a_w.w_symbol->s_name ) && ( *(pname+1) == '%' ) )
+ {
+ *(pdname++)=*(pname++);
+ pname++;
+ continue;
+ }
+ *(pdname++)=(char)ivalue;
+ pname+=ndigits+1;
+ }
+ else if ( !strncmp( pname, "\"", 1 ) ) // quotes are ignored unless %34
+ {
+ pname++;
+ }
+ else
+ {
+ *(pdname++)=*(pname++);
+ }
+ }
+ //freebytes( pname,len+1 ); NOT SO STRANGE CRASHES XXX
+ *(pdname)='\0';
+
+ // get other parameters in command
+ x->x_layers[x->x_current].l_xoffset = (int)argv[1].a_w.w_float;
+ /*if (x->x_layers[x->x_current].l_mode == PIDIP_TEXT_MODE_SCROLL)
+ {
+ x->x_layers[x->x_current].l_yoffset = -10; // XXX: GET REAL STARTING POSITION
+ }*/
+ //else
+ //{
+ x->x_layers[x->x_current].l_yoffset = (int)argv[2].a_w.w_float;
+ //}
+
+ if ( (argc>=4) && (argv[3].a_type == A_FLOAT) )
+ {
+ x->x_layers[x->x_current].l_r = (int)argv[3].a_w.w_float;
+ }
+ if ( (argc>=5) && (argv[4].a_type == A_FLOAT) )
+ {
+ x->x_layers[x->x_current].l_g = (int)argv[4].a_w.w_float;
+ }
+ if ( (argc>=6) && (argv[5].a_type == A_FLOAT) )
+ {
+ x->x_layers[x->x_current].l_b = (int)argv[5].a_w.w_float;
+ }
+ if ( (argc>=7) && (argv[6].a_type == A_FLOAT) )
+ {
+ x->x_layers[x->x_current].l_angle = argv[6].a_w.w_float;
+ }
+ if ( (argc>=8) && (argv[7].a_type == A_FLOAT) )
+ {
+ x->x_layers[x->x_current].l_scroll = (int)argv[7].a_w.w_float;
+ }
+
+ // post( "pdp_qtext : added text >%s< @ %d",
+ // x->x_layers[x->x_current].l_texts->text_array, x->x_current);
+
+ /*if ( x->x_current > x->x_chat_base )
+ x->x_current = x->x_chat_base;
+ x->x_nbtexts = x->x_capacity; // XXX why is this exactly ?? */
+ //x->x_nbtexts++;
+
+}
+
+static void pdp_qtext_current(t_pdp_qtext *x, t_floatarg fcurrent )
+{
+ if ( ( fcurrent >= 0 ) && ( fcurrent < x->x_capacity ) )
+ {
+ x->x_current = fcurrent;
+ }
+}
+
+static void pdp_qtext_textx(t_pdp_qtext *x, t_floatarg fx )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_xoffset = fx;
+ }
+}
+
+static void pdp_qtext_margin(t_pdp_qtext *x, t_floatarg fx )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_marginh = fx;
+ }
+}
+
+static void pdp_qtext_marginv(t_pdp_qtext *x, t_floatarg fx )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_marginv = fx;
+ }
+}
+
+static void pdp_qtext_direction(t_pdp_qtext *x, t_floatarg fx )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_upwards = fx;
+ // post( "pdp_qtext : set direction to %d for layer %d", fx, x->x_current );
+ }
+}
+
+static void pdp_qtext_texty(t_pdp_qtext *x, t_floatarg fy )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_yoffset = fy;
+ }
+}
+
+static void pdp_qtext_textr(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_r = fr;
+ }
+}
+static void pdp_qtext_texta(t_pdp_qtext *x, t_floatarg fa )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_a = fa;
+ }
+}
+
+static void pdp_qtext_textg(t_pdp_qtext *x, t_floatarg fg )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_g = fg;
+ }
+}
+
+static void pdp_qtext_textb(t_pdp_qtext *x, t_floatarg fb )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_b = fb;
+ }
+}
+static void pdp_qtext_text2r(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_2r = fr;
+ }
+}
+static void pdp_qtext_text2g(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_2g = fr;
+ }
+}
+static void pdp_qtext_text2b(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_2b = fr;
+ }
+}
+static void pdp_qtext_text2a(t_pdp_qtext *x, t_floatarg fa )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_2a = fa;
+ }
+}
+static void pdp_qtext_borderr(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_borderr = fr;
+ }
+}
+static void pdp_qtext_borderg(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_borderg = fr;
+ }
+}
+static void pdp_qtext_borderb(t_pdp_qtext *x, t_floatarg fr )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity) )
+ {
+ x->x_layers[x->x_current].l_borderb = fr;
+ }
+}
+
+static void pdp_qtext_angle(t_pdp_qtext *x, t_floatarg fangle )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_angle = fangle;
+ }
+}
+
+static void pdp_qtext_scroll(t_pdp_qtext *x, t_floatarg fscroll )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_scroll = fscroll;
+ }
+}
+
+static void pdp_qtext_center(t_pdp_qtext *x )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_alignment = PIDIP_ALIGNMENT_CENTER;
+ }
+}
+static void pdp_qtext_left(t_pdp_qtext *x )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_alignment = PIDIP_ALIGNMENT_LEFT;
+ }
+}
+static void pdp_qtext_right(t_pdp_qtext *x )
+{
+ if ( ( x->x_current >= 0 ) && ( x->x_current < x->x_capacity ) )
+ {
+ x->x_layers[x->x_current].l_alignment = PIDIP_ALIGNMENT_RIGHT;
+ }
+}
+
+static void pdp_qtext_delete(t_pdp_qtext *x, t_floatarg fnum )
+{
+ t_int i;
+ char *lostword;
+
+ text_layer_flush(&x->x_layers[x->x_current]);
+ /*if ( ( fnum>=0 ) && ( fnum<x->x_capacity ) )
+ {
+ if (fnum >= x->x_chat_base && x->x_active[x->x_chat_base])
+ {
+ lostword = x->x_text_array[ (int)fnum];
+ fnum = x->x_chat_base;
+ if (x->upwards)
+ x->x_chat_turn++;
+ for ( i=(int)x->x_chat_base; i<x->x_chat_base+x->x_chat_texts-1; i++ )
+ {
+ x->x_text_array[ i ] = x->x_text_array[ i+1 ];
+ }
+ x->x_active[x->x_chat_base+x->x_chat_texts-1]=0;
+ x->x_chat_texts--;
+ free( lostword );
+ x->x_nbtexts--;
+ }
+ else if (x->x_active[(int)fnum])
+ {
+ lostword = x->x_text_array[ (int)fnum];
+ x->x_active[(int)fnum]=0;
+ free( lostword );
+ x->x_nbtexts--;
+ }
+ }*/
+}
+static void pdp_qtext_clear(t_pdp_qtext *x )
+{
+ text_layer_flush(&x->x_layers[x->x_current]);
+ // must free the texts XXX
+ x->x_nbtexts = 0;
+}
+static void pdp_qtext_mode(t_pdp_qtext *x, t_symbol *s)
+{
+ if (s == gensym("static")) x->x_layers[x->x_current].l_mode = PIDIP_TEXT_MODE_STATIC;
+ else if (s == gensym("scroll")) x->x_layers[x->x_current].l_mode = PIDIP_TEXT_MODE_SCROLL;
+ else if (s == gensym("feed")) x->x_layers[x->x_current].l_mode = PIDIP_TEXT_MODE_FEED;
+ else if (s == gensym("slow")) x->x_layers[x->x_current].l_mode = PIDIP_TEXT_MODE_SLOW;
+}
+
+static void pdp_qtext_resize(t_pdp_qtext *x, t_floatarg fnewsize )
+{
+ char **text_array;
+ t_int *xoffsets;
+ t_int *yoffsets;
+ t_int *r;
+ t_int *g;
+ t_int *b;
+ t_float *angle;
+ t_int *scroll;
+
+ t_int i, csize;
+
+ TEXTLAYER * layers;
+ if ( (int) fnewsize<=0 ) return;
+
+ // allocate new structures
+ layers = (TEXTLAYER*) getbytes( x->x_capacity*sizeof(TEXTLAYER) );
+
+ for ( i=0; i<fnewsize; i++ )
+ {
+ layers[i].l_r = layers[i].l_g = layers[i].l_b = layers[i].l_a = 255;
+ layers[i].l_2r = layers[i].l_2g = layers[i].l_2b = layers[i].l_2a = 255;
+ layers[i].l_borderr = x->x_layers[i].l_borderg = x->x_layers[i].l_borderb = 255;
+ layers[i].l_xoffset = 0;
+ layers[i].l_yoffset = 0;
+ layers[i].l_marginh = 0;
+ layers[i].l_marginv = 0;
+ layers[i].l_active = 0;
+ layers[i].l_alignment = PIDIP_ALIGNMENT_LEFT;
+ layers[i].l_mode = PIDIP_TEXT_MODE_STATIC;
+ layers[i].l_font = imlib_context_get_font();
+ layers[i].l_feed_turn = 0;
+ layers[i].l_upwards = 0;
+ layers[i].l_ntexts = 0;
+ layers[i].l_texts = NULL;
+ layers[i].l_last_text = NULL;
+ }
+
+ if ( fnewsize < x->x_nbtexts )
+ {
+ post( "pdp_qtext : new size is too small : texts lost !!" );
+ csize = fnewsize;
+ }
+ else
+ {
+ csize = x->x_nbtexts;
+ }
+
+ // copy all values
+ for ( i=0; i<csize; i++ )
+ {
+ layers[i].l_r=x->x_layers[i].l_r;
+ layers[i].l_g=x->x_layers[i].l_g;
+ layers[i].l_b=x->x_layers[i].l_b;
+ layers[i].l_a=x->x_layers[i].l_a;
+ layers[i].l_2r=x->x_layers[i].l_2r;
+ layers[i].l_2g=x->x_layers[i].l_2g;
+ layers[i].l_2b=x->x_layers[i].l_2b;
+ layers[i].l_2a=x->x_layers[i].l_2a;
+ layers[i].l_borderr=x->x_layers[i].l_borderr;
+ layers[i].l_borderg=x->x_layers[i].l_borderg;
+ layers[i].l_borderb=x->x_layers[i].l_borderb;
+ layers[i].l_xoffset=x->x_layers[i].l_xoffset;
+ layers[i].l_yoffset=x->x_layers[i].l_yoffset;
+ layers[i].l_marginh=x->x_layers[i].l_marginh;
+ layers[i].l_marginv=x->x_layers[i].l_marginv;
+ layers[i].l_active=x->x_layers[i].l_active;
+ layers[i].l_alignment=x->x_layers[i].l_alignment;
+ layers[i].l_mode=x->x_layers[i].l_mode;
+ layers[i].l_font=x->x_layers[i].l_font;
+ layers[i].l_feed_turn=x->x_layers[i].l_feed_turn;
+ layers[i].l_upwards=x->x_layers[i].l_upwards;
+ layers[i].l_ntexts=x->x_layers[i].l_ntexts;
+ layers[i].l_texts=x->x_layers[i].l_texts;
+ layers[i].l_last_text=x->x_layers[i].l_last_text;
+ }
+
+ // free old structures
+ if ( x->x_layers ) freebytes( x->x_layers, x->x_capacity*sizeof(TEXTLAYER) );
+ if ((int)fnewsize < x->x_capacity)
+ {
+ // do something with left over texts XXX
+ }
+
+ // set new structures
+ x->x_layers = layers;
+ x->x_nbtexts = csize;
+ x->x_capacity = (int) fnewsize;
+ x->x_current = 0;
+ post( "pdp_qtext : resized to %d", (int) fnewsize );
+}
+
+static void pdp_qtext_font(t_pdp_qtext *x, t_symbol *sfont )
+{
+ Imlib_Font font;
+
+ font = imlib_load_font(sfont->s_name);
+ if ( !font )
+ {
+ post( "pdp_qtext : could not load font : >%s<", sfont->s_name );
+ return;
+ }
+ imlib_context_set_font( font );
+ x->x_layers[x->x_current].l_font = font;
+}
+
+static void pdp_qtext_allocate(t_pdp_qtext *x)
+{
+ x->x_image = imlib_create_image( x->x_vwidth, x->x_vheight );
+ if ( x->x_image == NULL )
+ {
+ post( "pdp_qtext : severe error : could not allocate image !!" );
+ return;
+ }
+ imlib_context_set_image(x->x_image);
+}
+
+static void pdp_qtext_free_ressources(t_pdp_qtext *x)
+{
+ // if ( x->x_image != NULL ) imlib_free_image();
+}
+
+void qtext_line_draw(t_pdp_qtext *x,char *text,int text_width,int text_height,int tlayer, int ti, int linenumber,double stime)
+{
+ int base = tlayer;
+ double newyoffset = 0;
+ int yfinalposition;
+ int alpha = x->x_layers[base].l_a;
+ if (x->x_layers[base].l_mode == PIDIP_TEXT_MODE_SCROLL)
+ {
+ if ((x->x_layers[base].l_upwards))
+ newyoffset = -stime+x->x_vheight;
+ else
+ newyoffset = stime;
+ if (stime<50)
+ alpha = (alpha*(stime/50));
+ if (stime>350)
+ alpha = alpha-(alpha*((stime-350)/50));
+ }
+ yfinalposition = newyoffset + x->x_layers[base].l_yoffset + ((linenumber)*(text_height)) + (sin(x->x_layers[base].l_angle) * x->x_layers[base].l_scroll);
+ /*if (ti>=x->x_chat_base)
+ base = x->x_chat_base;*/
+ if (((text_height)*(linenumber+1)) + x->x_layers[base].l_yoffset + x->x_layers[base].l_marginv < x->x_vheight) // CABE EN LOS MARGENES ESPECIFICADOS (DE ALTO)
+ {
+ if ((x->x_layers[base].l_feed_turn+ti)%2&&(x->x_layers[base].l_mode==PIDIP_TEXT_MODE_FEED))
+ imlib_context_set_color( x->x_layers[base].l_2r, x->x_layers[base].l_2g, x->x_layers[base].l_2b, x->x_layers[base].l_2a);
+ else
+ imlib_context_set_color( x->x_layers[base].l_r, x->x_layers[base].l_g, x->x_layers[base].l_b, alpha );
+ if (x->x_layers[base].l_alignment == PIDIP_ALIGNMENT_CENTER)
+ {
+ imlib_text_draw( x->x_layers[base].l_xoffset - (0.5*text_width) + (cos(x->x_layers[base].l_angle) * x->x_layers[base].l_scroll),
+ yfinalposition,
+ text );
+ }
+ else // left aligned text
+ {
+ // CODE FOR A NOT SO NICE BORDER
+ /*imlib_context_set_color( 0, 0, 0, 255 );
+ int borde = 2;
+ imlib_text_draw( x->x_xoffsets[base] + (cos(x->x_angle[base]) * x->x_scroll[base])+borde,
+ x->x_yoffsets[base] + (linenumber*(text_height)) + (sin(x->x_angle[base]) * x->x_scroll[base])-borde,
+ text );
+ imlib_text_draw( x->x_xoffsets[base] + (cos(x->x_angle[base]) * x->x_scroll[base])-borde,
+ x->x_yoffsets[base] + (linenumber*(text_height)) + (sin(x->x_angle[base]) * x->x_scroll[base])+borde,
+ text );
+ imlib_text_draw( x->x_xoffsets[base] + (cos(x->x_angle[base]) * x->x_scroll[base])-borde,
+ x->x_yoffsets[base] + (linenumber*(text_height)) + (sin(x->x_angle[base]) * x->x_scroll[base])-borde,
+ text );
+ imlib_text_draw( x->x_xoffsets[base] + (cos(x->x_angle[base]) * x->x_scroll[base])+borde,
+ x->x_yoffsets[base] + (linenumber*(text_height)) + (sin(x->x_angle[base]) * x->x_scroll[base])+borde,
+ text );*/
+ // SET ALTERNATING COLORS
+ imlib_text_draw( x->x_layers[base].l_xoffset + (cos(x->x_layers[base].l_angle) * x->x_layers[base].l_scroll),
+ yfinalposition,text);
+ }
+ }
+}
+
+// DRAW ALL TEXTS
+
+static void pdp_qtext_draw_all_texts(t_pdp_qtext *x)
+{
+ int text_width, text_height;
+ int chat_lines = 0; // total lines of chat rendered
+ int linenumber; // lines of chat we have rendered in current message
+ int feed_mes = 0; // messages rendered
+ t_int tlayer;
+
+ // draw all texts
+ imlib_context_set_direction(IMLIB_TEXT_TO_ANGLE);
+
+ for (tlayer=0; tlayer<x->x_capacity; tlayer++)
+ {
+ TEXT_FRAME *curr_text = x->x_layers[tlayer].l_texts;
+ while (curr_text != NULL) {
+ if (x->x_layers[tlayer].l_active)
+ {
+ t_int base=tlayer;
+ linenumber = 0;
+ int ti = feed_mes;
+ imlib_context_set_angle( x->x_layers[base].l_angle );
+ imlib_context_set_font( x->x_layers[base].l_font );
+ if (x->x_layers[base].l_mode == PIDIP_TEXT_MODE_FEED)
+ {
+ if ((x->x_layers[base].l_feed_turn+ti)%2)
+ imlib_context_set_color( x->x_layers[base].l_r, x->x_layers[base].l_g, x->x_layers[base].l_b, x->x_layers[base].l_a );
+ else
+ imlib_context_set_color( x->x_layers[base].l_r, x->x_layers[base].l_g, x->x_layers[base].l_b, x->x_layers[base].l_a );
+ }
+ else
+ {
+ imlib_context_set_color( x->x_layers[base].l_r, x->x_layers[base].l_g, x->x_layers[base].l_b, x->x_layers[base].l_a );
+ }
+
+ imlib_context_set_font( x->x_layers[base].l_font );
+ imlib_get_text_size( curr_text->text_array, &text_width, &text_height);
+
+ // code which separates the message in lines
+ if (text_width + x->x_layers[base].l_xoffset + x->x_layers[base].l_marginh > x->x_vwidth)
+ { // MESSAGE CAN'T BE DRAWN IN A LINE
+ char *token = NULL, *cp;
+ cp = strdup (curr_text->text_array);
+ if (x->x_layers[base].l_mode == PIDIP_TEXT_MODE_SLOW && curr_text->time/10<strlen(curr_text->text_array))
+ cp[(int)(curr_text->time/10)] = '\0';
+ token = strtok (cp, " .,;:");
+ char buf[256];
+ char *position = buf;
+ char prev[256];
+ int wordcount = 0;
+ while (token != NULL)
+ {
+ strcpy(prev,buf);
+ wordcount++;
+ if (wordcount != 1)
+ *(position++) = ' ';
+ position = stpcpy(position,token);
+ imlib_get_text_size( buf, &text_width, &text_height);
+ if (text_width + x->x_layers[base].l_xoffset + x->x_layers[base].l_marginh> x->x_vwidth)
+ { // YA TENEMOS UNA CADENA PARA LA 1 LINEA
+ char * textofinal;
+ if (wordcount == 1)
+ textofinal = buf;
+ else
+ textofinal = prev;
+ imlib_get_text_size( textofinal, &text_width, &text_height);
+ qtext_line_draw(x,textofinal, text_width,text_height,tlayer,feed_mes,chat_lines+linenumber,curr_text->time);
+ if (wordcount == 1)
+ {
+ position = stpcpy(buf,"");
+ wordcount=0;
+ }
+ else
+ {
+ position = stpcpy(buf,token);
+ wordcount=1;
+ }
+ linenumber++;
+ }
+ token = strtok (NULL, " .,;:");
+ }
+ // draw the rests in the buffer
+ if (strlen(buf)>0)
+ {
+ imlib_get_text_size( buf, &text_width, &text_height);
+ qtext_line_draw(x,buf, text_width,text_height,tlayer,feed_mes,chat_lines+linenumber,curr_text->time);
+ linenumber++;
+ }
+ free(cp);
+ }
+ else // MESSAGE CAN BE DRAWN IN A LINE
+ {
+ char *cp;
+ cp = strdup (curr_text->text_array);
+ if (x->x_layers[base].l_mode == PIDIP_TEXT_MODE_SLOW && curr_text->time/10<strlen(curr_text->text_array))
+ cp[(int)(curr_text->time/10)] = '\0';
+ qtext_line_draw(x,cp, text_width,text_height,tlayer,feed_mes,chat_lines,curr_text->time);
+ linenumber=1;
+ free(cp);
+ }
+ // if we are in chat mode remember number of lines
+ if (x->x_layers[base].l_mode == PIDIP_TEXT_MODE_FEED )
+ chat_lines+=linenumber;
+ }
+ feed_mes++;
+ curr_text->time++;
+ if (curr_text->time > 400 && x->x_layers[tlayer].l_mode == PIDIP_TEXT_MODE_SCROLL && curr_text == x->x_layers[tlayer].l_texts)
+ {
+ text_layer_delete_start(&x->x_layers[tlayer]);
+ }
+ curr_text = curr_text->next;
+ } // while(curr_text != NULL);
+ } // for (tlayer=0; tlayer<x->x_capacity; tlayer++)
+}
+
+static void pdp_qtext_process_yv12(t_pdp_qtext *x)
+{
+ t_pdp *header = pdp_packet_header(x->x_packet0);
+ short int *data = (short int *)pdp_packet_data(x->x_packet0);
+ t_pdp *newheader = pdp_packet_header(x->x_packet1);
+ short int *newdata = (short int *)pdp_packet_data(x->x_packet1);
+ t_int ti;
+ t_int px, py;
+ unsigned char y, u, v;
+ DATA32 *imdata;
+ DATA32 bgcolor=0;
+ short int *pY, *pU, *pV;
+ int text_width, text_height;
+ int chat_lines = 0;
+
+ // ensure the prepared surface is the same size as the image
+ if ( ( (int)(header->info.image.width) != x->x_vwidth ) ||
+ ( (int)(header->info.image.height) != x->x_vheight ) )
+ {
+ pdp_qtext_free_ressources(x);
+ x->x_vwidth = header->info.image.width;
+ x->x_vheight = header->info.image.height;
+ x->x_vsize = x->x_vwidth*x->x_vheight;
+ pdp_qtext_allocate(x);
+ }
+
+ // prepare packets
+ newheader->info.image.encoding = header->info.image.encoding;
+ newheader->info.image.width = x->x_vwidth;
+ newheader->info.image.height = x->x_vheight;
+
+ // prepare image
+ if ( x->x_image != NULL ) imlib_context_set_image(x->x_image);
+ imdata = imlib_image_get_data();
+
+ // copy incoming packet to Imlib image
+ yuv_Y122RGB( data, imdata, x->x_vwidth, x->x_vheight );
+
+ // draw all texts to imlib surface
+ pdp_qtext_draw_all_texts(x);
+
+ // copy Imlib image to outgoing packet
+ yuv_RGB2Y12( imdata, newdata, x->x_vwidth, x->x_vheight );
+
+ return;
+}
+
+static void pdp_qtext_sendpacket(t_pdp_qtext *x)
+{
+ /* delete source packet */
+ pdp_packet_mark_unused(x->x_packet0);
+ x->x_packet0 = -1;
+
+ /* unregister and propagate if valid dest packet */
+ pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1);
+}
+
+static void pdp_qtext_process(t_pdp_qtext *x)
+{
+ int encoding;
+ t_pdp *header = 0;
+
+ /* check if image data packets are compatible */
+ if ( (header = pdp_packet_header(x->x_packet0))
+ && (PDP_IMAGE == header->type)){
+
+ /* pdp_qtext_process inputs and write into active inlet */
+ switch(pdp_packet_header(x->x_packet0)->info.image.encoding)
+ {
+
+ case PDP_IMAGE_YV12:
+ x->x_packet1 = pdp_packet_clone_rw(x->x_packet0);
+ pdp_queue_add(x, pdp_qtext_process_yv12, pdp_qtext_sendpacket, &x->x_queue_id);
+ break;
+
+ case PDP_IMAGE_GREY:
+ // should write something to handle these one day
+ // but i don't use this mode
+ break;
+ default:
+ /* don't know the type, so dont pdp_qtext_process */
+ break;
+
+ }
+ }
+
+}
+
+static void pdp_qtext_input_0(t_pdp_qtext *x, t_symbol *s, t_floatarg f)
+{
+
+ /* if this is a register_ro message or register_rw message, register with packet factory */
+
+ if (s== gensym("register_rw"))
+ {
+ switch(pdp_packet_header((int)f)->info.image.encoding)
+ {
+ case PDP_IMAGE_YV12:
+ x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("image/YCrCb/*") );
+ break;
+ }
+ }
+ if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){
+
+ /* add the process method and callback to the process queue */
+ pdp_qtext_process(x);
+
+ }
+
+}
+
+static void pdp_qtext_free(t_pdp_qtext *x)
+{
+ int i;
+
+ pdp_qtext_free_ressources(x);
+ pdp_queue_finish(x->x_queue_id);
+ pdp_packet_mark_unused(x->x_packet0);
+}
+
+t_class *pdp_qtext_class;
+
+void *pdp_qtext_new(void)
+{
+ int i;
+
+ t_pdp_qtext *x = (t_pdp_qtext *)pd_new(pdp_qtext_class);
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("current"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("textx"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("texty"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("textr"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("textg"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("textb"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("angle"));
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("scroll"));
+
+ x->x_outlet0 = outlet_new(&x->x_obj, &s_anything);
+ x->x_packet0 = -1;
+ x->x_packet1 = -1;
+ x->x_queue_id = -1;
+ x->x_image = NULL;
+
+
+ x->x_capacity = DEFAULT_CAPACITY;
+
+
+ x->x_layers = (TEXTLAYER*) getbytes( x->x_capacity*sizeof(TEXTLAYER) );
+
+ for ( i=0; i<x->x_capacity; i++ )
+ {
+ x->x_layers[i].l_r = x->x_layers[i].l_g = x->x_layers[i].l_b = x->x_layers[i].l_a = 255;
+ x->x_layers[i].l_2r = x->x_layers[i].l_2g = x->x_layers[i].l_2b = x->x_layers[i].l_2a = 255;
+ x->x_layers[i].l_borderr = x->x_layers[i].l_borderg = x->x_layers[i].l_borderb = 255;
+ x->x_layers[i].l_xoffset = 0;
+ x->x_layers[i].l_yoffset = 0;
+ x->x_layers[i].l_marginh = 0;
+ x->x_layers[i].l_scroll_speed = 1;
+ x->x_layers[i].l_marginv = 0;
+ x->x_layers[i].l_active = 0;
+ x->x_layers[i].l_alignment = PIDIP_ALIGNMENT_LEFT;
+ x->x_layers[i].l_mode = PIDIP_TEXT_MODE_STATIC;
+ x->x_layers[i].l_font = imlib_context_get_font();
+ x->x_layers[i].l_feed_turn = 0;
+ x->x_layers[i].l_upwards = 0;
+ x->x_layers[i].l_ntexts = 0;
+ x->x_layers[i].l_texts = NULL;
+ x->x_layers[i].l_last_text = NULL;
+ }
+ x->x_current = 0;
+ x->x_nbtexts = 0;
+ return (void *)x;
+}
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+void pdp_qtext_setup(void)
+{
+ Imlib_Font font;
+
+ // post( pdp_qtext_version );
+ pdp_qtext_class = class_new(gensym("pdp_qtext"), (t_newmethod)pdp_qtext_new,
+ (t_method)pdp_qtext_free, sizeof(t_pdp_qtext), 0, A_NULL);
+
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_input_0, gensym("pdp"),
+ A_SYMBOL, A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_add, gensym("text"), A_GIMME, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_current, gensym("current"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_textx, gensym("textx"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_texty, gensym("texty"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_textr, gensym("textr"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_textg, gensym("textg"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_textb, gensym("textb"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_texta, gensym("texta"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_text2r, gensym("text2r"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_text2g, gensym("text2g"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_text2b, gensym("text2b"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_text2a, gensym("text2a"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_borderr, gensym("borderr"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_borderg, gensym("borderg"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_borderb, gensym("borderb"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_clear, gensym("clear"), A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_delete, gensym("delete"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_resize, gensym("resize"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_font, gensym("font"), A_SYMBOL, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_angle, gensym("angle"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_scroll, gensym("scroll"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_left, gensym("left"), A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_right, gensym("right"), A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_center, gensym("center"), A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_margin, gensym("margin"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_marginv, gensym("marginv"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_direction, gensym("direction"), A_DEFFLOAT, A_NULL);
+ class_addmethod(pdp_qtext_class, (t_method)pdp_qtext_mode, gensym("layermode"), A_SYMBOL, A_NULL);
+ class_sethelpsymbol( pdp_qtext_class, gensym("pdp_qtext.pd") );
+
+ imlib_add_path_to_font_path("/usr/X11R6/lib/X11/fonts/TTF");
+ font = imlib_load_font(DEFAULT_FONT);
+ if ( !font )
+ {
+ post( "pdp_qtext : severe error : could not load default font : no rendering !!!" );
+ }
+ imlib_context_set_font( font );
+}
+
+#ifdef __cplusplus
+}
+#endif