Thanks Lionel, Chen Kai for reply, I mean to create OSD scroll from
right
To left effect, that must often change X coordinate and the words .
If clutter API Is not thread safe, with what method is better?
Now I modify the code, can let clutter_text moving to the left, but how to
Change the dynamic of thread safe text and get actor width?
#include <glib.h>
#include <clutter/clutter.h>
ClutterActor *gStage, *acttext=NULL;
static gboolean osdtextchang=FALSE;
static gchar *vgaosdtext=NULL;
ClutterColor white = {255, 255, 255, 255};
ClutterColor black = {0, 0, 0, 0};
static gpointer vgaosd_left(gpointer data)
{
gfloat wc, wx, ww;
wx = wc = 650;
while (1)
{
if (vgaosdtext==NULL)
{
usleep(500);
continue;
}
if (g_strcmp0(vgaosdtext, "")==0)
{
usleep(500);
continue;
}
osdtextchang = FALSE;
clutter_text_set_text(CLUTTER_TEXT(acttext), vgaosdtext);
//if use clutter_actor_get_width(acttext);
//Pango:ERROR:pango-layout.c:3743:pango_layout_check_lines: assertion
failed: (!layout->log_attrs)
//ww = clutter_actor_get_width(acttext);
while (1)
{
clutter_actor_set_x(acttext, wx);
wx--;
//if (wx<=-ww) //because can not get width, only
set constants
if (wx<=-1200)
wx = 650;
usleep(50000);
//if have changed text , reload
if (osdtextchang)
break;
}
}
}
void vga_osdtext(gchar *str)
{
//dbg("vga osd: %s \n", str);
if (vgaosdtext==NULL)
g_free(vgaosdtext);
vgaosdtext = g_strdup(str);
osdtextchang = TRUE; //change osd text
}
static gint num=0;
static gboolean auto_set_text(gpointer data)
{
sprintf((gchar*)data, "TEST OSD SCROLL word %d ...", num++);
vga_osdtext((gchar*)data);
g_print("auto_set_text: %s \n", data);
return TRUE;
}
int main(int argc, char* argv[])
{
GThread *threadid;
gchar text[128];
g_thread_init(NULL);
clutter_threads_init();
clutter_init(&argc, &argv);
gStage = clutter_stage_get_default();
clutter_actor_set_size(gStage, 650, 300);
clutter_stage_set_color(CLUTTER_STAGE(gStage), &black);
sprintf(text, "TEST OSD SCROLL ... ... ");
acttext = clutter_text_new_full("Monospace 20", text, &white);
clutter_text_set_single_line_mode(CLUTTER_TEXT(acttext), TRUE);
clutter_container_add_actor(CLUTTER_CONTAINER(gStage), acttext);
clutter_actor_show(gStage);
g_timeout_add_seconds(2, auto_set_text, text);
threadid = g_thread_create(vgaosd_left, (gpointer)text, FALSE,
NULL);
clutter_main();
}
> The clutter API is not thread safe. You just can't do stuff like that.
>
> --
> Lionel
>
> On Sat, 2012-05-12 at 13:28 +0800, david.sale.75 wrote:
> > Hi, all:
> >
> > I write a test demo, use clutter_actor_get_width() get actor width, it
> > is correct if in the main thread call, but incorrect in then new thread.
> > used clutter-1.6.20 and pango-1.28.4 and glib2-2.28.6
> >
> > Pango:ERROR:pango-layout.c:3743:pango_layout_check_lines: assertion
> > failed: (!layout->log_attrs) The code is what problem? have any error?
Tks.
> >
> > #include <glib.h>
> > #include <clutter/clutter.h>
> > ClutterActor *gStage, *acttext=NULL;
> > ClutterColor white = {255, 255, 255, 255}; ClutterColor black = {0, 0,
> > 0, 0};
> >
> > static gpointer test(gpointer data)
> > {
> > gfloat ww;
> > if (acttext)
> > clutter_container_remove_actor(CLUTTER_CONTAINER(gStage), acttext);
> > acttext = clutter_text_new_full("Monospace 20", (gchar*)data ,
> > &white); clutter_text_set_single_line_mode(CLUTTER_TEXT(acttext),
> > TRUE); clutter_container_add_actor(CLUTTER_CONTAINER(gStage),
> > acttext); clutter_actor_set_position(acttext, 100, 100);
> >
> > //why not get width
> > //if use clutter_actor_get_width(acttext);
> > //Pango:ERROR:pango-layout.c:3743:pango_layout_check_lines: assertion
> > failed: (!layout->log_attrs) clutter_actor_get_width(acttext);
> > g_print("act width: %d \n", acttext);
> >
> > }
> >
> > int main(int argc, char* argv[])
> > {
> > GThread *threadid;
> > gchar text[128];
> > g_thread_init(NULL);
> > clutter_threads_init();
> > clutter_init(&argc, &argv);
> >
> > gStage = clutter_stage_get_default();
> > clutter_actor_set_size(gStage, 600, 400);
> > clutter_stage_set_color(CLUTTER_STAGE(gStage), &black);
> > clutter_actor_show(gStage); sprintf(text, "TEST TEST TEST TEST");
> > threadid = g_thread_create(test, (gpointer)text, FALSE, NULL);
> >
> > clutter_main();
> >
> > }
> >
> _______________________________________________
> clutter-app-devel-list mailing list
> [email protected]
> http://lists.clutter-project.org/listinfo/clutter-app-devel-list
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list