Dr Wimp p1 (including an introduction)

This is the first of an occasional series of short articles giving hints and tips on how to use the Dr Wimp package in practice. I won't promise to produce one for each issue but I will try.

But, as this is the first article...

For those new to Dr Wimp

For new Archive subscribers, the Dr Wimp package was authored by Andrew Ayre, and I took over its support and distribution in May this year. Currently, it is at version 3.51, and I expect to release a new version (my first upgrade release) this autumn.

The core of the package is the rather special Dr Wimp library and its linked !RunImage skeleton. These are designed to help you write wimp programs quickly and painlessly, for example by hiding all the SWI calls 'behind the scenes'. And I don't mean just small utilities; Dr Wimp is perfectly suitable for programs big or small. The only thing it requires is that you are reasonably familiar with BBC Basic (and if you're not, then my book "Starting Basic" is still available and selling steadily!).

However, the scope of the total package goes beyond that. It comes with several PD utilities which supplement and complement the core activity. There is also a good on-disc manual to get you going, and several fully-commented example applications to show you exactly how things can be done.

The result is very comprehensive - and it's free!

On top of all this there is my book "Dr Wimp's Surgery" which introduces the package in much more detail, including taking you step-by-step through a tutorial program. My book is not free!

(If you think I am being a bit cheeky in pushing my books, it is because they are sold strictly on a non-commercial basis with all profit going to charity. Roughly 150 copies of each book have been sold so far, and the resulting donations to charity exceed £1,300. There's no reason why it has to stop there!)

OK, having got that out of the way, let's go straight into what I expect the more typical contents of these articles will look like.

Positioning printed text accurately

Dr Wimp provides a set of wimp-functions (using DrWimp-speak) to enable text in outline fonts to be accurately placed on the screen and/or paper. They include:

PROCwimp_plottext
PROCwimp_plottexth
PROCwimp_plotwindowtext
PROCwimp_plotwindowtexth
FNwimp_gettextsize
FNwimp_gettextsizeh
FNwimp_OStolength
FNwimp_lengthtoOS

A typical sequence might be:

This is all straightforward stuff covered in the on-disc manual.

However, if you are looking for very accurate alignment, it is important to realise that FNwimp_OS tolength and FNwimp_lengthtoOS will work with real numbers and not just integers. Accordingly, it can be very important to ensure that any real numbers aren't inadvertently truncated, e.g. by assigning a real result to an integer variable.

I first noticed this point when producing a printed table of money values, with the decimal points intended to be vertically aligned. I found that there was a tiny difference in the alignment of some values, which was immediately noticeable when in a vertical list.

The reason was that I had assigned a return from an OS/length conversion to an integer numeric variable quite early in a calculation chain. This had removed the fractional part of the number and made a small but significant difference to the end result. Simply changing the variable to a real numeric variable cured the problem.

Input focus

It is nearly always a good idea to follow up a window opening with an action to put the input focus in that window immediately. This is usually done by using PROCwimp_putcaret(window%,icon%) to place the caret in a writable icon in the window. But what happens if the window doesn't have a writable (or any) icon?

The answer is simply to use the same wimp-function and use -1 for the icon number. This will give the window the input focus (with the usual pale yellow title bar) but no caret is involved.

This isn't documented in the on-disc manual (but will be at the next upgrade).

FNuser_loaddata and FNuser_savedata

The conventional use of this complementary pair of user-functions (DrWimp-speak, again) is covered in the on-disc manual, but they can be used for a much wider role than that.

Any time you want to drag a filer object (file/directory/application) from/to your application, these user-functions can be used to trigger any action you wish even if it doesn't involve actual saving or loading of data. For instance, you might just want to take advantage of the source/destination path conveniently identified for you by the passed parameters.

Just remember to return 0 from the user-function if you aren't actually saving/loading data.


Source: Archive 12.12
Publication: Archive Magazine
Contributor: Ray Favre