TweetFollow Us on Twitter

Updating Windows
Volume Number:4
Issue Number:3
Column Tag:Basic School

Updating Windows in Basic

By Dave Kelly, MacTutor Editorial Board

Dave Kelly is an electrical engineer for General Dynamics in Pomona, where he is involved in using work stations for hardware design. He is a founding editorial board member and currently an active board member for MacTutor.

A fresh window lets you see things more clearly. (I like mine in color, but black & white mode on the Macintosh II sure is faster). I received the following request from one of our readers which I’m sure others of you would also like to know about:

Q. I am working on an application in ZBasic 4.00 that I hope to release commercially. Previously I never had to worry about handling update events in a “correct” manner (in the past I have always reprinted everything on the screen when I’ve encountered an update event). ZBasic does provide a WINDOW PICTURE statement that I have not gotten to work to my satisfaction. I have also tried GET and PUT without much success. I’m obviously doing something wrong. could you show various ways to handle update events that involve DAs and multiple windows? My application has Edit Fields and displayed text (i.e. displaying results obtained from values entered in the edit fields).

A. Yes, there can be some tricky problems associated with refreshing windows which use edit fields. There is a standard way that refreshing should work. In Pascal the application should respond by calling BeginUpdate, drawing the window, then call EndUpdate. The Window Manager section of Inside Macintosh explains how to do this. That’s fine when using the Macintosh standard GetNextEvent loop, but in ZBasic the approach must be modified.

The object is to restore any window which gets covered up by another window. If window 1 is dragged over window 2, then if window 2 is selected it should automatically be redrawn. Or if only part of window 2 is covered up and window 1 is removed then window 2 should be refreshed. This means that you as a programmer are responsible to determine all of the possible ways the window could be erased and be sure to set up event handling to cover all the possibilities.

There are 3 options we have for screen refresh with ZBasic.

1. Redraw the picture in response to a DIALOG event.

2. Use the WINDOW PICTURE statement.

3. Use GET and PUT in response to a DIALOG event.

By the end of this discussion you will know when to use each method in different circumstances. Directly redrawing the window is probably used most often by those that don’t know about the other two methods (or don’t know how they work). Redrawing is what I think of as the “brute force” method. It is usually the method used for “quick and dirty” screen refresh. The advantage is that you have control to force the update to occur whenever you feel like it. The disadvantage is that it is slower and you may find that the screen may get updated sometimes when it doesn’t need it (in order to catch every possible event).

Fig. 1 Our Multiple Window Example

To refresh by redrawing in the “brute force” mode a DIALOG(0)=5 event should effectively determine when a window needs to be refreshed. The window that needs to be refreshed is returned in the DIALOG(5) function. A quick call to the screen drawing routine when DIALOG event occurs is all that is needed to make this work.

The 2nd method of refreshing the screen is somewhat unique to ZBasic. Using the WINDOW PICTURE statement is the most automatic way to update the screen. A good example of using WINDOW PICTURE is given in the ZBasic manual on page E-158. The example at the end of this column also demonstrates its use. There are a few problems which you should be aware of. When using WINDOW PICTURE, all DIALOG events for the window involved are not passed to the DIALOG function, but instead are automatically handled by the WINDOW PICTURE statement. This is both good and bad. It is good because now any portion of the screen can be refreshed automatically without really trying. The problem comes when you use an EDIT FIELD in the window which you are using WINDOW PICTURE. When WINDOW PICTURE is active, the EDIT FIELD is not updated properly. Ordinarily the EDIT FIELD is automatically updated, but not with WINDOW PICTURE. This is one of those cases where the window should be refreshed with the “brute force” method. The process can be improved by setting up the screen information to be updated in a PICTURE so that it can be redrawn quickly. The demo shows how this is done. The “Set Window 1 Update” routine is called whenever an update event occurs. Also the EDIT FIELD value is re-read and the text displayed is obtained from the current contents of the EDIT FIELD. It is really too bad that in ZBasic the WINDOW PICTURE statement doesn’t update controls. [My guess is that WINDOW PICTURE is nothing more than the automatic window updating procedure of placing a quickdraw picture handle in the window record’s pic field, in which case, no controls or edit fields would be updated. This method was only intended for fairly static window contents, and never meant to be a true update procedure for dynamic windows. -Ed]

To use WINDOW PICTURE you first define the PICTURE which you want to print. This can be a combination of text and graphics. The PICTURE is pointed to by a variable which is used in the WINDOW PICTURE statement to initialize the automatic update routine. To stop the update or to modify it you can use WINDOW PICTURE #1,0 (if using window #1) and then KILL PICTURE to delete the picture from memory. If you don’t remove the pictures from memory, they may use up some of your memory and sooner or later if enough pictures are used, you could run out of memory.

I think the 3rd method is a bit more cumbersome than the first two. I call it the “GET/PUT” method. First, the window contents are drawn for the first time. Then the rectangle containing the contents of the window must be determined exactly. These coordinates are plugged in to an equation given on page 232 of the ZBasic manual. The equation determines the number of bytes to use in a DIM statement for the graphic image used in the GET and PUT statement. The equation is:

bytes = 6 + ((y2-y1)+1) * ((x2-x1)+1) * bpp + 7) / 8

where x1, y1 are the coordinates of the upper-left-corner of the graphic image on the screen; x2, y2 are the coordinates of the lower-right-corner of the image. The bits-per-pixel, bpp, depends on your Macintosh screen setup. Standard black & white Macintoshes have one bit per pixel, a Macintosh II with sixteen colors is 4 bpp and 256 colors is 8 bpp. Now divide the number of bytes by two for the integer (16 bit) array used in the DIM statement. This is the extent of the difficulty in using the “GET/PUT” method. The DIM statement should be executed only once at the beginning of your program and enough space should be allocated for whatever you plan to update. After the screen is drawn the first time, the GET statement is used to set the array to the screen image. If your array isn’t dimensioned big enough you can definitely expect a system bomb here. I would recommend that you only use the “GET/PUT” method when you are not going to change the window contents. The PUT statement is called by the DIALOG event routine whenever the window needs refreshing. (Mac II color users, notice that the PUT statement only refreshes in black & white; the color information is ignored. This is unfortunate. Maybe in a future release of ZBasic with 256 color support?????).

The demo program demonstrates the three methods discussed above. Try opening DAs and dragging a window on top of other windows and closing/opening them. I feel that this program should give you a good idea of how windows can be refreshed. I strongly recommend that most of your refreshing be done with the WINDOW PICTURE statement whenever possible. (NOTE: ‘whenever possible’ is just about always, except when controls are used on the same screen. Maybe this will get fixed someday too so that WINDOW PICTURE will work when EDIT FIELDs are active).

This has been a much more pleasant program to write as Zedcor has released version 4.01 with a much improved editor. The editor isn’t perfect, but if you remember to save your program often enough you can get by without exiting ZBasic. Also, they have added DIALOG(0)=17 for disk inserts. DIALOG(17) returns the disk drive which the disk was inserted. ZBasic is still the best Basic available today and keeps looking better each new release. Zedcor, keep up the good work.

Zedcor and True Basic have announced new versions at the San Francisco Expo. Watch for details on these new products. -Ed

‘ WINDOW UPDATE DEMO
‘ ©1988 MacTutor®
‘ By Dave Kelly

WINDOW OFF
COORDINATE WINDOW
DEF MOUSE=-1
DIM Wptr&(3)

APPLE MENU “About Updating ”
MENU 1,0,1,”File”
MENU 1,1,1,”Quit”
EDIT MENU 2
MENU 3,0,1,”Window”
MENU 3,1,1,”Show Window 1"
MENU 3,2,1,”Show Window 2"
MENU 3,3,1,”Show Window 3"
MENU 3,4,1,”Show All Windows”

‘Find out monitor size just in case we need it
CALL GETWMGRPORT(WMgrPort&)
PortTop=PEEK WORD(WMgrPort&+8)
PortLeft=PEEK WORD(WMgrPort&+10)
PortBottom=PEEK WORD(WMgrPort&+12)
PortRight=PEEK WORD(WMgrPort&+14)

WINDOW#1,”Window 1",(PortLeft+4,PortTop+42)-(300,300),5
Wptr&(1)=WINDOW(14)
TEXT 3,12
EDIT FIELD 1,”Read MacTutor!”,(50,200)-(270,225),1
GOSUB “Set Window 1 Update”

WINDOW#2,”Window 2",(PortLeft+24,PortTop+62)-(320,320),5
Wptr&(2)=WINDOW(14)
‘NOW... Create the picture for the first window
PICTURE ON
TEXT 2,24,1
COLOR=4
PRINT@(3,1)”MacTutor®”
COLOR=7
TEXT 3,12,0
PRINT@(6,4)”The Best in the West!”
PRINT@(5,6)”This is the second window”
PICTURE OFF,Pic2&
PICTURE, Pic2&:’ Draw the picture
WINDOW PICTURE #2,Pic2&

WINDOW#3,”Window 3",(PortLeft+44,PortTop+82)-(340,340),5
Wptr&(3)=WINDOW(14)
x1=0:x2=300:y1=0:y2=300
‘ bytes used = 6 + ((y2-y1)+1) * ((x2-x1+1)* bpp + 7) / 8)
DIM Pic3%(58293) :’ space for 32 bits-per-pixel (MAC II)
‘ NOW... Create the picture for the third window
TEXT 2,24,1
COLOR=4
PRINT@(3,1)”MacTutor®”
COLOR=7
TEXT 3,12,0
PRINT@(6,4)”The Best in the West!”
PRINT@(5,6)”This is the third window”
GET (x1,y1)-(x2,y2),Pic3%(1)
PUT (0,0),Pic3%(1),0

ON DIALOG GOSUB “DialogEvent”
ON MENU GOSUB “MenuEvent”
FLUSHEVENTS
MENU ON:DIALOG ON

“Loop”
GOTO “Loop”
MENU OFF:DIALOG OFF

“DialogEvent”
D=DIALOG(0)
SELECT D
 CASE 3
 WINDOW DIALOG(3)
 CASE 4
 CALL HIDEWINDOW(Wptr&(DIALOG(4)))
 CASE 5,6,7
 IF DIALOG(5)=3 THEN GOSUB”Window3 Update” ELSE GOSUB “Set Window 1 Update”
END SELECT
RETURN

“MenuEvent”
Menunumber=MENU(0)
Menuitem=MENU(1)
MENU
SELECT Menunumber
 CASE 255
 GOSUB “AppleMenu”
 CASE 1
 GOSUB “FileMenu”
 CASE 3
 GOSUB “WindowMenu”
END SELECT
RETURN

“AppleMenu”
WINDOW 4,””,(100,100)-(400,250),-2
PICTURE ON
TEXT 0,12,0,0
PRINT @(2,2) “(ZBASIC) Window Update Demo V1.0”
PRINT @(10,3)”by”
PRINT @(8,4)”Dave Kelly”
COLOR=6
PRINT @(7,6)”©MacTutor, 1988"
COLOR=7
PRINT @(7,7)”ZBasic version 4.01"
PICTURE OFF,Pic4&
PICTURE ,Pic4&
WINDOW PICTURE #4,Pic4&
MOUSE ON
DO
mous=MOUSE(0)
outsiderect=(MOUSE(1)<0 OR MOUSE(1)>300 OR MOUSE(2)<0 OR MOUSE(2)>150)
IF MOUSE(1)=0 AND MOUSE(2)=0 THEN “Stop”
UNTIL mous<>0 AND NOT (outsiderect)
MOUSE OFF
KILL PICTURE Pic4&:’ Delete the picture from memory
DIALOG ON
WINDOW CLOSE 4
DIALOG OFF
RETURN

“Window3 Update”
ActiveWindow=WINDOW(0)
WINDOW OUTPUT 3
PUT (0,0),Pic3%(1),0
WINDOW OUTPUT ActiveWindow
RETURN

“Set Window 1 Update”
ActiveWindow=WINDOW(0)
WINDOW OUTPUT 1
‘NOW... Create the picture for the first window
 KILL PICTURE Pic1&
 PICTURE ON
 TEXT 2,24,1
 COLOR=4
 PRINT@(3,1)”MacTutor®”
 COLOR=7
 TEXT 3,12,0,0
 PRINT@(6,4)”The Best in the West!”
 PRINT@(5,6)”This is the first window”
 Editvariable$=EDIT$(1)
 PRINT@(5,8)”The edit field = “;Editvariable$
 PICTURE OFF,Pic1&
PRINT@(5,8);SPC(100)
PICTURE, Pic1&:’ Draw the picture
WINDOW OUTPUT ActiveWindow
RETURN

“FileMenu”
IF Menuitem=1 THEN “Stop”
RETURN

“WindowMenu”
SELECT Menuitem
 CASE 1
 CALL SHOWWINDOW(Wptr&(1)):WINDOW 1
 CASE 2
 CALL SHOWWINDOW(Wptr&(2)):WINDOW 2
 CASE 3
 CALL SHOWWINDOW(Wptr&(3)):WINDOW 3
 CASE 4
 FOR i=1 TO 3
 CALL SHOWWINDOW(Wptr&(i))
 WINDOW i
 NEXT i
END SELECT
RETURN

“Stop”
WINDOW PICTURE #1,0:’Don’t update the first window anymore
KILL PICTURE Pic1&:’ Delete the picture from memory
WINDOW PICTURE #2,0:’Don’t update the second window anymore
KILL PICTURE Pic2&:’ Delete the picture from memory
END
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.