[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtkmm
Subject:    Re: Help with Clutter::Scriptable
From:       Brian Gregg <biscuitalmighty () gmail ! com>
Date:       2011-02-27 4:39:13
Message-ID: 17B9A3C9-B4F2-4BD1-B906-2512EC48881B () gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Actually, after testing this, it gives no errors or warnings, but it's not doing what \
I expect.  My on_paint method is never called, and in fact the \
Clutter::Actor::on_paint method is never called.  My constructor is only called once \
to create the type:

 3 MainGridActor::MainGridActor() : Glib::ObjectBase("MainGridActor"), padding(10)
 4 {
 5     std::cout << "In MainGridActor constructor.";
 6 }
I don't know how the object is constructed out of the script, but it seems the C \
types are constructed correctly (it works if I subclass ClutterRectangle because its \
paint method is implemented in C).  If the on_paint is a C++ method only, then it's \
not being called.

Brian

On Feb 26, 2011, at 9:51 PM, Brian Gregg wrote:

> > 
> > > // Get the stage by name, casting it to the correct C++-type.
> > > const Glib::RefPtr<Clutter::Stage> stage =
> > > Glib::RefPtr<Clutter::Stage>::cast_static(script->get_object("stage"));
> > 
> > A cast_dyanmic<>, with an if() check, would be generally safer. That's
> > what we generally use with Gtk::Builder::get_widget() too.
> 
> I believe Glib::wrap does a cast_dynamic, I was using that instead to wrap the C \
> types after they come out of the script.  Here's what I've got working: 
> 66 int main(int argc, char** argv)
> 67 {
> 68   try
> 69   {
> 70     Clutter::init(&argc, &argv);
> 71 
> 72     // This is needed on OS X to make fonts appear correctly
> 73     clutter_set_font_flags(CLUTTER_FONT_HINTING);
> 74 
> 75     Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
> 76     stage->set_size(1024, 768);
> 77 
> 78     // Call this to instantiate the MainGridActor custom type
> 79     MainGridActor::create();
> 80 
> 81     ClutterScript *script = clutter_script_new();
> 82     clutter_script_load_from_file(script, "GameActor.js", NULL);
> 83 
> 84     Glib::RefPtr<NavManager> navManager = NavManager::create(stage);
> 85 
> 86     ClutterRectangle *rect = CLUTTER_RECTANGLE(clutter_script_get_object(script, \
> "active_rect")); 87     ClutterAnimation *anim = \
> clutter_actor_animate(CLUTTER_ACTOR(rect), Clutter::EASE_IN_OUT_CUBIC, 600, 88      \
> "x", 540.0, "y", 284.0, NULL); 89 
> 90     // Need to do this in C API since Clutter::Box is not a Clutter::Actor
> 91     ClutterBox *box = CLUTTER_BOX(clutter_script_get_object(script, \
> "game_box")); 92     clutter_container_add_actor(CLUTTER_CONTAINER(stage->gobj()), \
> CLUTTER_ACTOR(box)); 93 
> 94     stage->show();
> 95 
> 96     // Start the main loop, so we can respond to events:
> 97     Clutter::main();
> 98   }
> 99   catch (const Glib::Error& error)
> 100   {
> 101     std::cerr << "Exception: " << error.what() << std::endl;
> 102     return 1;
> 103   }
> 104 
> 105   return 0;
> 106 }
> And my script file:
> 
> 2     {
> 3         "id"    : "game_box",
> 4         "type"  : "ClutterBox",
> 5         "width" : 1024,
> 6         "height": 768,
> 7         "layout-manager": {
> 8             "type"  : "ClutterFixedLayout"
> 9         },
> 10         "children"  : [
> 11             
> ...
> {
> 46                 "type"  : "gtkmm__CustomObject_MainGridActor",
> 47                 "x"     : 340,
> 48                 "y"     : 84,
> 49                 "width" : 600,
> 50                 "height": 600
> 51             },
> You notice in my main.cpp file that I used mostly the C API to get what I wanted \
> from the script.  I tried to use cluttermm objects first, but this would often not \
> work as expected. 
> Brian
> 


[Attachment #5 (unknown)]

<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; ">Actually, after testing this, it gives no \
errors or warnings, but it's not doing what I expect. &nbsp;My on_paint method is \
never called, and in fact the Clutter::Actor::on_paint method is never called. \
&nbsp;My constructor is only called once to create the type:<div><br></div><div><span \
class="Apple-style-span" style="font-family: monospace; color: rgb(127, 127, 127); \
"><pre style="font-family: monospace; color: rgb(127, 127, 127); background-color: \
rgb(26, 26, 26); "><span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 3 </span>MainGridActor::MainGridActor() : \
Glib::ObjectBase(<span class="String" style="color: rgb(74, 112, 139); \
">"MainGridActor"</span>), padding(<span class="Constant" style="color: rgb(255, 193, \
37); ">10</span>) <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 4 </span>{ <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 5 </span>    std::cout &lt;&lt; <span \
class="String" style="color: rgb(74, 112, 139); ">"In MainGridActor \
constructor."</span>; <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 6 </span>}</pre></span><div>I don't know how \
the object is constructed out of the script, but it seems the C types are constructed \
correctly (it works if I subclass ClutterRectangle because its paint method is \
implemented in C). &nbsp;If the on_paint is a C++ method only, then it's not being \
called.</div></div><div><br></div><div>Brian</div><div><br><div><div>On Feb 26, 2011, \
at 9:51 PM, Brian Gregg wrote:</div><br class="Apple-interchange-newline"><blockquote \
type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; \
-webkit-line-break: after-white-space; "><div><blockquote \
type="cite"><div><br><blockquote type="cite"> &nbsp;// Get the stage by name, casting \
it to the correct C++-type.<br></blockquote><blockquote type="cite"> &nbsp;const \
Glib::RefPtr&lt;Clutter::Stage&gt; stage =<br></blockquote><blockquote type="cite"> \
&nbsp;&nbsp;&nbsp;Glib::RefPtr&lt;Clutter::Stage&gt;::cast_static(script-&gt;get_object("stage"));<br></blockquote><br>A \
cast_dyanmic&lt;&gt;, with an if() check, would be generally safer. That's<br>what we \
generally use with Gtk::Builder::get_widget() \
too.<br></div></blockquote><div><br></div><div>I believe Glib::wrap does a \
cast_dynamic, I was using that instead to wrap the C types after they come out of the \
script. &nbsp;Here's what I've got working:</div><div><br></div><div><span \
class="Apple-style-span" style="font-family: monospace; color: rgb(127, 127, 127); \
"><pre style="font-family: monospace; color: rgb(127, 127, 127); background-color: \
rgb(26, 26, 26); position: static; z-index: auto; "><span class="lnr" style="color: \
rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 66 </span><span class="Type" \
style="color: rgb(0, 139, 139); font-weight: bold; ">int</span> main(<span \
class="Type" style="color: rgb(0, 139, 139); font-weight: bold; ">int</span> argc, \
<span class="Type" style="color: rgb(0, 139, 139); font-weight: bold; ">char</span>** \
argv) <span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, \
13); "> 67 </span>{ <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 68 </span>  <span class="Statement" \
style="color: rgb(155, 48, 255); font-weight: bold; ">try</span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 69 </span>  { \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
"> 70 </span>    Clutter::init(&amp;argc, &amp;argv); <span class="lnr" style="color: \
rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 71 </span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 72 </span>    \
<span class="Comment" style="color: rgb(122, 197, 205); font-style: italic; ">// This \
is needed on OS X to make fonts appear correctly</span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 73 </span>    \
clutter_set_font_flags(CLUTTER_FONT_HINTING); <span class="lnr" style="color: rgb(85, \
42, 123); background-color: rgb(13, 13, 13); "> 74 </span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 75 </span>    \
Glib::RefPtr&lt;Clutter::Stage&gt; stage = Clutter::Stage::get_default(); <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 76 \
</span>    stage-&gt;set_size(<span class="Constant" style="color: rgb(255, 193, 37); \
">1024</span>, <span class="Constant" style="color: rgb(255, 193, 37); ">768</span>); \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
"> 77 </span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 78 </span>    <span class="Comment" style="color: rgb(122, 197, \
205); font-style: italic; ">// Call this to instantiate the MainGridActor custom \
type</span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 79 </span>    MainGridActor::create(); <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 80 </span> \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
"> 81 </span>    ClutterScript *script = clutter_script_new(); <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 82 </span>    \
clutter_script_load_from_file(script, <span class="String" style="color: rgb(74, 112, \
139); ">"GameActor.js"</span>, <span class="Constant" style="color: rgb(255, 193, \
37); ">NULL</span>); <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 83 </span> <span class="lnr" style="color: \
rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 84 </span>    \
Glib::RefPtr&lt;NavManager&gt; navManager = NavManager::create(stage); <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 85 \
</span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, \
13, 13); "> 86 </span>    ClutterRectangle *rect = \
CLUTTER_RECTANGLE(clutter_script_get_object(script, <span class="String" \
style="color: rgb(74, 112, 139); ">"active_rect"</span>)); <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 87 </span>    \
ClutterAnimation *anim = clutter_actor_animate(CLUTTER_ACTOR(rect), \
Clutter::EASE_IN_OUT_CUBIC, <span class="Constant" style="color: rgb(255, 193, 37); \
">600</span>, <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 88 </span>                    <span class="String" style="color: \
rgb(74, 112, 139); ">"x"</span>, <span class="Constant" style="color: rgb(255, 193, \
37); ">540.0</span>, <span class="String" style="color: rgb(74, 112, 139); \
">"y"</span>, <span class="Constant" style="color: rgb(255, 193, 37); ">284.0</span>, \
<span class="Constant" style="color: rgb(255, 193, 37); ">NULL</span>); <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 89 \
</span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, \
13, 13); "> 90 </span>    <span class="Comment" style="color: rgb(122, 197, 205); \
font-style: italic; ">// Need to do this in C API since Clutter::Box is not a \
Clutter::Actor</span> <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 91 </span>    ClutterBox *box = \
CLUTTER_BOX(clutter_script_get_object(script, <span class="String" style="color: \
rgb(74, 112, 139); ">"game_box"</span>)); <span class="lnr" style="color: rgb(85, 42, \
123); background-color: rgb(13, 13, 13); "> 92 </span>    \
clutter_container_add_actor(CLUTTER_CONTAINER(stage-&gt;gobj()), CLUTTER_ACTOR(box)); \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
"> 93 </span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 94 </span>    stage-&gt;show(); <span class="lnr" style="color: \
rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 95 </span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 96 </span>    \
<span class="Comment" style="color: rgb(122, 197, 205); font-style: italic; ">// \
Start the main loop, so we can respond to events:</span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 97 </span>    \
Clutter::main(); <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 98 </span>  } <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 99 </span>  <span class="Statement" \
style="color: rgb(155, 48, 255); font-weight: bold; ">catch</span> (<span \
class="Type" style="color: rgb(0, 139, 139); font-weight: bold; ">const</span> \
Glib::Error&amp; error) <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); ">100 </span>  { <span class="lnr" style="color: \
rgb(85, 42, 123); background-color: rgb(13, 13, 13); ">101 </span>    std::cerr \
&lt;&lt; <span class="String" style="color: rgb(74, 112, 139); ">"Exception: "</span> \
&lt;&lt; error.what() &lt;&lt; std::endl; <span class="lnr" style="color: rgb(85, 42, \
123); background-color: rgb(13, 13, 13); ">102 </span>    <span class="Statement" \
style="color: rgb(155, 48, 255); font-weight: bold; ">return</span> <span \
class="Constant" style="color: rgb(255, 193, 37); ">1</span>; <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); ">103 </span>  } \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
">104 </span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); ">105 </span>  <span class="Statement" style="color: rgb(155, 48, \
255); font-weight: bold; ">return</span> <span class="Constant" style="color: \
rgb(255, 193, 37); ">0</span>; <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); ">106 </span>}</pre></span><div>And my script \
file:</div><div><br></div><div><span class="Apple-style-span" style="font-family: \
monospace; color: rgb(127, 127, 127); "><pre style="font-family: monospace; color: \
rgb(127, 127, 127); background-color: rgb(26, 26, 26); position: static; z-index: \
auto; "><span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, \
13, 13); "> 2 </span>    <span class="Identifier" style="color: rgb(69, 139, 116); \
">{</span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); ">  3 </span>        <span class="String" style="color: rgb(74, 112, \
139); ">"id"</span>    : <span class="String" style="color: rgb(74, 112, 139); \
">"game_box"</span>, <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); ">  4 </span>        <span class="String" \
style="color: rgb(74, 112, 139); ">"type"</span>  : <span class="String" \
style="color: rgb(74, 112, 139); ">"ClutterBox"</span>, <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); ">  5 </span>      \
<span class="String" style="color: rgb(74, 112, 139); ">"width"</span> : 1024, <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); ">  6 \
</span>        <span class="String" style="color: rgb(74, 112, 139); \
">"height"</span>: 768, <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); ">  7 </span>        <span class="String" \
style="color: rgb(74, 112, 139); ">"layout-manager"</span>: <span class="Identifier" \
style="color: rgb(69, 139, 116); ">{</span> <span class="lnr" style="color: rgb(85, \
42, 123); background-color: rgb(13, 13, 13); ">  8 </span>            <span \
class="String" style="color: rgb(74, 112, 139); ">"type"</span>  : <span \
class="String" style="color: rgb(74, 112, 139); ">"ClutterFixedLayout"</span> <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); ">  9 \
</span>        <span class="Identifier" style="color: rgb(69, 139, 116); ">}</span>, \
<span class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); \
"> 10 </span>        <span class="String" style="color: rgb(74, 112, 139); \
">"children"</span>  : <span class="Identifier" style="color: rgb(69, 139, 116); \
">[</span> <span class="lnr" style="color: rgb(85, 42, 123); background-color: \
rgb(13, 13, 13); "> 11 </span>           &nbsp;</pre><pre style="font-family: \
monospace; color: rgb(127, 127, 127); background-color: rgb(26, 26, 26); position: \
static; z-index: auto; "><span class="Identifier" style="color: rgb(69, 139, 116); \
">...</span></pre><pre style="font-family: monospace; color: rgb(127, 127, 127); \
background-color: rgb(26, 26, 26); position: static; z-index: auto; "><span \
class="Identifier" style="color: rgb(69, 139, 116); ">{</span> <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 46 </span>      \
<span class="String" style="color: rgb(74, 112, 139); ">"type"</span>  : <span \
class="String" style="color: rgb(74, 112, 139); \
">"gtkmm__CustomObject_MainGridActor"</span>, <span class="lnr" style="color: rgb(85, \
42, 123); background-color: rgb(13, 13, 13); "> 47 </span>                <span \
class="String" style="color: rgb(74, 112, 139); ">"x"</span>     : 340, <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 48 \
</span>                <span class="String" style="color: rgb(74, 112, 139); \
">"y"</span>     : 84, <span class="lnr" style="color: rgb(85, 42, 123); \
background-color: rgb(13, 13, 13); "> 49 </span>                <span class="String" \
style="color: rgb(74, 112, 139); ">"width"</span> : 600, <span class="lnr" \
style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 50 </span>      \
<span class="String" style="color: rgb(74, 112, 139); ">"height"</span>: 600 <span \
class="lnr" style="color: rgb(85, 42, 123); background-color: rgb(13, 13, 13); "> 51 \
</span>            <span class="Identifier" style="color: rgb(69, 139, 116); \
">}</span>,</pre></span></div></div><div>You notice in my main.cpp file that I used \
mostly the C API to get what I wanted from the script. &nbsp;I tried to use cluttermm \
objects first, but this would often not work as \
expected.</div><div><br></div><div>Brian</div></div><br></div></blockquote></div><br></div></body></html>




_______________________________________________
gtkmm-list mailing list
gtkmm-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic