Re: [NTLK] How do I use custom pictures and sounds in NTK?

From: Frank Gruendel <newtontalk_at_pda-soft.de>
Date: Thu Apr 09 2009 - 15:53:37 EDT

> How can I use custom pictures and sounds in a
NTK project?

The sample code below is from a PC NTK project. I
assume things aren't much different on a Mac.

It makes sense to define these resources in a
separate file to keep them together and away from
the code. I usually put them in a file
"ProjectData.txt".

Pictures:

Pictures must be in Bitmap (.bmp) format. In
ProjectData.txt you write something like

  BacklightOffImage :=
getBMPAsBits("Bitmaps\\BacklightOff.bmp", nil);
  BacklightOnImage :=
getBMPAsBits("Bitmaps\\BacklightOn.bmp", nil);

  DefineGlobalConstant('kBacklightOnImage,
BacklightOnImage);
  DefineGlobalConstant('kBacklightOffImage,
BacklightOffImage);

The Bitmaps folder must be in the same folder as
your project's NTK file.

If you want, for example, to use this icon for a
button, you would refer to it in your code like
this:

  setValue(yourButton, 'icon, kBacklightOffImage);

Sounds:

Sounds must be in Wave (.wav) format. In
ProjectData.txt you write something like

  cuckooSound :=
GetWAVSound(HOME&"Sounds/coocoo.wav");
  if cuckooSound.samplingRate <> kFloat22kRate
then
    cuckooSound.samplingRate := kFloat22kRate;
  DefineGlobalConstant('kCuckooSound,
cuckooSound);

HOME is a NTK internal constant that stands for
the path name of the folder containing your NTK
file. In other words, the Sounds folder must, just
like the Bitmaps folder above, be in the same
folder as your project's NTK file. kFloat22kRate
is an internal constant that specifies the rate at
which to play the sample data.

To play the sound in your application, you'd do
something like

        local sound := Clone(cuckooSound);
        PlaySound(sound);

Hope it helps

Frank

-- Newton software and hardware at
http://www.pda-soft.de

====================================================================
The NewtonTalk Mailing List - http://www.newtontalk.net/
The Official Newton FAQ - http://www.splorp.com/newton/faq/
The Newton Glossary - http://www.splorp.com/newton/glossary/
WikiWikiNewt - http://tools.unna.org/wikiwikinewt/
====================================================================
Received on Thu Apr 9 15:53:34 2009

This archive was generated by hypermail 2.1.8 : Thu Apr 09 2009 - 20:30:00 EDT