Re: [NTLK] Waba Development

From: Sean Luke (sean_at_cs.gmu.edu)
Date: Tue Jan 03 2006 - 18:03:36 PST


[Sorry everyone for the code discussion below -- perhaps people might
find it interesting, dunno]

Frank writes:

> So what would be necessary first would be an API that allows
> creating CONTROLS in the java language and make it possible to put
> them on the Newton.

Interesting that you say this. :-) I was just doing this today.

Waba has a fairly decent standard GUI library which was designed to
run across various platforms (Palms, etc.), and that runs fine on the
Newton. But it doesn't *feel* anything like a Newton. However I had
also added to Waba a library which enables you to access most all of
NewtonScript from Java calls. Using this library, you can make an
app which is made entirely out of NewtonScript widgets, but has Waba
code underneath. This is called the NSWabaAPI.

However, though it's actually quite straightforward for an
experienced developer, the NSWabaAPI will make no sense to someone
who's not done both C++ and NewtonScript coding on the Newton
("What's a 'Ref'?"). So I was thinking of putting together a Java
library which sits on top of the NSWabaAPI but tries to present a
subset of the Newton toolkit in a manner fairly easy for a Java coder
to grok. I spent today whipping up a test version of this library: a
View class, a TextButton class, and a few other little things. There
are still some NSWabaAPI things sticking out here and there, but I've
got it looking pretty good. Here's an example code which makes a
protoTextButton that says "Wow", and when you press it, you get a
notification popping up:

        TextButton button = new TextButton(View.wabaDrawingArea);
        button.setBounds(40,10,80,30);
        button.setText("Wow!");
        button.setButtonClickScript(new Callback()
             {
             public Ref call(Ref[] args)
                 {
                NS.notify("Waba for the Newton!!!",
                          "Isn't this fun?");
                return new Ref(); // returns nil in NewtonScript
                 }
             });

I think you'll agree that feels fairly Java-ish and easy to
understand, modulo the Ref stuff in the Callback (which will be
unavoidable probably). Here's the same code in Raw NSWabaAPI calls.

         Ref buttontemplate = NS.frameWithProto("protoTextButton");
         buttontemplate.setSlot("viewBounds",NS.bounds(40,10,80,30));
         buttontemplate.setSlot("text", new Ref("Wow!"));
         Callback mycallback = new Callback()
             {
             public Ref call(Ref[] args)
                 {
                 Ref.call("GetRoot").send("Notify",
                     new Ref(4 /*kNotifyQAlert*/),
                     new Ref("Waba for the Newton!!!"),
                     new Ref("Isn't this fun?"));
                 return new Ref();
                 }
             };
         Ref myfunc = mycallback.func(0);
         buttontemplate.setSlot("ButtonClickScript", myfunc);
         Ref button = Ref.call("AddStepView", NS.wabaDrawingArea(),
buttontemplate);
         button.send("Dirty");

Ick.

> I have never spent any time on evaluating WABA because people said
> it is an Interpreter interpreting an Interpreter. Which makes
> things so dead slow that using such an app wouldn't exactly be fun.
> If this can be changed: Wow!

This is fairly mistaken, so allow me to clear some things up about
Waba. It's a bytecode interpreter for a subset of Java. Its core is
written in fairly optimized C++, *not* in NewtonScript. However
there's a lot of NewtonScript attached to it which is crucial for it
to do its job. Most importantly for this discussion, in order to
draw to the screen, Waba must construct NewtonScript requests and
submit them to the NewtonScript interpreter to draw for Waba. That's
where most of the slowdown comes from. The reason for this is that
Apple never released a C++ API to Quickdraw; the only way to do this
is to go through NS. In my experience, if you're doing lots of
computation, Waba is *fast*. Quite surprisingly fast. If you're
drawing to the screen a lot -- games etc. -- Waba starts to slow
down. On an MP2K, Waba's pretty good.

Now it just so happens that Jim Witte (whom I've cc:ed) has been
poking around with C++ calls to QuickDraw. He thinks he may be able
to get DrawShape working, which would speed up Waba's screen drawing
tremendously. Unfortunately, I no longer have NTK on my machine (I
don't have classic), so helping out in the coding myself is not easy:
I'll have to rely on him to smash it in there, perhaps with help from
anyone interested.

> I could use a decent IDE like Eclipse instead of having to put up
> with the stupid Newton ToolKit IDE.

Yes indeed. Actually, you would be interested in knowing that I
spent today with a new coding environment:

1. javac -target 1.2 Example.java
2. java wababin.Warp c /f 4 Example [Steve Weyer is awesome]
3. java wababin.Exegen /l 30000 /h 40 /w 100 /f 4 \
        Example Example Example
4. [Load Example.pkg into Einstein and run it!] [Paul Guyot is The
Man]

Honest! That's the entire compilation procedure.

Sean

-- 
This is the NewtonTalk list - http://www.newtontalk.net/ for all inquiries
Official Newton FAQ: http://www.chuma.org/newton/faq/
WikiWikiNewt for all kinds of articles: http://tools.unna.org/wikiwikinewt/


This archive was generated by hypermail 2.1.5 : Tue Jan 03 2006 - 19:00:05 PST