TweetFollow Us on Twitter

4D Graphics
Volume Number:7
Issue Number:2
Column Tag:Database Corner

Related Info: Quickdraw

4th Dimension Graphics

By Haven C. Sweet, Orlando, FL

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Graphics Output in Fourth Dimension.

Haven Sweet is a Professor of Biology at the University of Central Florida. He has been interested in using the Macintosh for a variety of educational purposes, and has tried to incorporate the computer into an academic laboratory setting. He has developed several classroom exercises using 4th Dimension.

Introduction

Although Fourth Dimension (4D) is not a programming language, I prefer to use it for most of my projects since it vastly simplifies programming and managing complex data. However, I recently discovered a very unfortunate limitation of Fourth Dimension; it is unable to draw on the screen using tool box calls.

The Problem

After creating a large data base of organisms with 4D, I added calculations for a cluster analysis to elucidate their possible relationships. When I wanted to present the final results in a dendrogram (Figure 1), I discovered there was no simple mechanism for drawing on the screen or printing text at variable locations.

Figure 1. A sample clustering output, showing the similarity of four different records in the data base. The figure was drawn on an output layout which only contained the buttons.

I would have to write the entire graphics routine in Pascal, compile it as an external procedure, and create external areas within my program. Not being proficient with MPW, I was hesitant to attempt writing anything which would require debugging by switching from MPW to Ext. Mover to 4D to MPW etc. Hoping version 2 would provide direct toolbox routines such as MoveTo(xStart,yStart), LineTo(xEnd,yEnd) and Writeln(Message), I found that Acius had no such plans.

The Solution

Facing the tedium of learning MPW and Pascal, I hit upon a much simpler solution; I created four external units which provide equivalent procedures for moving the pen, drawing a line, writing text at any location on the screen, and defining both pen and text characteristics. Then, using a blank layout screen, I wrote the graphics routines in the layout procedure and invoked these procedures. Although the graphics output is quite slow, it is more than adequate for the occasional presentation of simple data.

The “pseudo toolbox” routines can be as short or long as needed, but each must be compiled separately and given a name different from the toolbox routine. While I toyed with putting a “4D” before the name of every toolbox call, I decided to combine several I need into a single procedure. So, when text must appear at variable locations on the screen, instead of using MoveTo(xStart;yStart); Writeln(message), the new procedure is WriteAt(xStart;yStart;Message). Likewise, when a line must be drawn, instead of using MoveTo and LineTo, they were combined into DrawLine(xStart;yStart;xEnd;yEnd) which defines the start and end of the line. To alter the text or pen’s characteristics, I adopted the syntax used in ZBasic to produce Pen(xSize;ySize;visible;PenMode) and Text(font;point size;mode). Because variables are used, the procedures can use data either stored in the database or generated from it to draw appropriate lines.

These procedures were written in Pascal and compiled as units which can be moved using 4D External Mover into either the resource of a 4D program or the Proc.Ext. The units are quite small, taking under 600 bytes for all four routines. Once installed, the procedures can be called from within the program in the same manner as any global procedure.

The Output Screen

The next problem was to provide a blank screen on which the results could be written, as well as to find the best way to call the function. My solution was to create a dummy data file with all the drawing done in the output layout procedure. However, there must be exactly one record in the file; if the file is empty, the layout screen never appears, while if there are more than one record in the selection, the drawing procedure is executed for each record. Although it is possible to create a set with only one record in it, it is simpler to create a file named “Blank” which contains only one field, “Dummy”. Then, with the User mode, add one record to the file. An empty layout screen must be created for each different graphics screen.

The layout forms in the file “Blank” should have the three markers Header, Detail, and Break positioned at the very top of the page. If no buttons are to appear in the form, the Footer should also should be placed at the top; otherwise, it should be just far enough down to accomidate the buttons (Figure 2).

Figure 2. The appearance of the layout screen on which the drawing or text placement will be done. Note that the markers for Header, Detail and Break are all at the top of the page.

Although other line positions may work (including using the default positioning of the lines), having them at the top is more reliable since unusual things may occur with some positions. For example, if Break or Header are below the window’s margin, nothing will be drawn; if the Detail line is below the window, then the image is drawn and immediately erased; if space remains between the Header and Detail, clicking on the area permits the user to double click the region and jump to the data input mode. Thus, since the user may resize the window, it is safest to prevent anomalies by placing the lines at the top.

The Procedures’ Syntax

The drawing procedures should only be executed in the BEFORE phase, and should use the following formats:

Pen([xSize] [; [YSize]; [Visible]; [Pen Mode]] )

XSize is the horizontal width of the line in pixels.

YSize is the vertical width of the line in pixels. If omitted or set to zero, the xSize value is used for ySize.

Visible is set to one if the line is to be seen or zero if it is invisible.

Pen Mode uses the following;

0 or 8 Pattern COPY

1 or 9 Pattern OR

2 or 10 Pattern XOR

3 or 11 Pattern BIC

4 or 12 Not pattern COPY

5 or 13 Not pattern OR

6 or 14 Not pattern XOR

7 or 15 Not Pattern BIC

All values are optional. A call to Pen with no parameters resets the normal pen (1 by 1 pixel, visible in the copy mode). Partial parameters may also be used. For example, Pen(3;3;1;8) would produce the same effect as Pen(3) or Pen(3;3)-- that is, a visible pen, 3 by 3 pixels in the copy mode. Although ZBasic also includes the possibility of altering the pen pattern, I did not include it in these routines.

Text( [Font] [; [Point size] ; [Face] ; [Mode]] )

Font codes include;

0 System font

1 Application font

2 New York 20 Times

3 Geneva 21 Helvetica

4 Monaco 22 Courier

5 Venice 23 Symbol

11 Cairo 24 Taliesin

Point size can range from 1 through 127

Face codes are; Mode uses the following;

0 Plain 0 or 8 Pattern COPY

1 Bold 1 or 9 Pattern OR

2 Italic 3 or 11 Pattern BIC

4 Underlined 2 or 10 Pattern XOR

8 Outlined 4 or 12 Not pattern COPY

16 Shadow 5 or 13 Not pattern OR

32 Condensed 6 or 14 Not pattern XOR

64 Extended 7 or 15 Not Pattern BIC

Combinations would be the sum of each face; i.e., bold italic text would have a code of 3.

All values are optional; if omitted, the result is 12 point, plain system font in the copy mode. Both Text(22;10;3;0) and Text(22;10;3) define text as 10 point Courier, italic and bold, which is in the COPY mode.

DrawLine( xStart; yStart; xEnd; yEnd)

This procedure draws a line, with the characteristics defined in the Pen procedure, which begins at a point xStart, yStart, and extends to the point xEnd, yEnd. For example DrawLine(1;1;200;1) would draw a line across the top of the screen.

WriteAt( xStart; yStart; Message)

This procedure writes any text stored in Message beginning at a point xStart, yStart. For example, WriteAt(10;YPos;”The results follow”) would print the text 10 pixels from the left edge and YPos pixels from the top.

Example

The following procedures are designed to draw a line on the screen and to place text near its origin. In this example, the coordinates of the line are entered by the user in a dialog box, but they could have been derived from data in the file.

‘ global procedure Draw a line
DEFAULT FILE([Blank])
ALL RECORDS([Blank]) ‘ this file has one record
 ‘ ask for characteristics of line and text
DIALOG(“Dialog box”)
If (OK=1)|(b1=1)
     INPUT LAYOUT(“Blank-line”)
     OUTPUT LAYOUT(“Blank-line”)
     DISPLAY SELECTION(*)
End if 
‘Layout procedure Blank-line
If (Before)
  visible:=1
  PenMode:=8   ‘Pattern copy  
 ‘ pen size entered by user
  Pen (xSize;Ysize;visible;PenMode)
 ‘ start and end positions entered by user
  DrawLine (h1;v1;h2;v2)
 ‘ Face entered by user
  Text (0;12;Face;0) ‘ font,point size,style,mode
  WriteAt ((h1+20);(v1+20);”This is where the line begins.”)
End if 

The Units

The Pascal versions of the four procedures are followed by one annoted example of the MPW commands needed to compile each into a unit. This method of directly creating units was devised by Jud Spencer of After Hours Software, and was distributed by Acius as Technical Note #150, March, 1989.

Unit Pen;
INTERFACE
 USES 
 Memtypes,Quickdraw,OSIntf,Toolintf,packintf;
 Procedure  PenSet(var Xsize,Ysize,visible, Mode: Integer);
IMPLEMENTATION
Procedure PenSet(var Xsize,Ysize,visible, Mode: Integer);
 begin
 PenNormal;
 if (Xsize>0) then
 {its OK}
 else
 Xsize:=1;
 if (Ysize>0) then
 {its OK}
 else
 Ysize:=Xsize;
 PenSize(Xsize,Ysize);
 if (visible=0) then
 HidePen
 else
 ShowPen;
 if (Mode>=0) and (Mode<8) then
 Mode:=Mode+8; {correct if wrong mode range used}
 if (Mode>7) and (Mode<16) then
 PenMode(Mode);
 end;
END.
____________________________________________
Unit DrawLine;
INTERFACE
 USES 
 Memtypes,Quickdraw,OSIntf,Toolintf,packintf;
 
 Procedure DrawALine(var h1,v1,h2,v2: Integer);
 
IMPLEMENTATION
 Procedure DrawALine(var h1,v1,h2,v2: Integer);
 begin
 MoveTo(h1,v1);
 LineTo(h2,v2);
 end;
END.
____________________________________________
Unit Text;
INTERFACE
 USES 
  Memtypes,Quickdraw,OSIntf,Toolintf,packintf;
 Procedure TextSet(var font,point,StyleNum,mode: Integer);
IMPLEMENTATION
 Procedure TextSet(var font,point,StyleNum,mode: Integer);
 begin
 if (font>0) then
 TextFont(font)
 else
 TextFont(0);
 if (point>0) and (point<128) then
 TextSize(point)
 else
 TextSize(12);
 if (mode>7) and (mode<16) then
 mode:=mode-8; {correct if wrong mode range used}
 if (mode>=0) and (mode<8) then
 TextMode(mode) 
 else
 TextMode(0);
 if (StyleNum>0) and (StyleNum<128) then
 TextFace(Style(StyleNum))
 else
 TextFace([]);
 end; {procedure}
END.
____________________________________________
Unit WriteAt;
INTERFACE
 USES 
 Memtypes,Quickdraw,OSIntf,Toolintf,packintf;
 Procedure WriteItAt(var h1,v1:Integer;var s: Str255);   IMPLEMENTATION
 Procedure WriteItAt(var h1,v1:Integer;var s: Str255);
 begin
 MoveTo(h1,v1);
 DrawString(s);
 end;
END.

Workshop Commands

MPW worksheet commands for the WriteAt procedure are described below. Set the correct directory, then replace or correct all the items noted below as each different unit is compiled and linked.

Pascal WriteAt.p
#      Fix ^     Use unit’s name
Link -w -p WriteAt.p.o 
#             Fix ^    Use unit’s name
“{Libraries}”Runtime.o 
“{Libraries}”Interface.o 
“{PLibraries}”PasLib.o 
-m WRITEITAT 
#    Fix ^    use ALL CAPS with the procedure’s name (not the Unit’s)
-rt 4DEX=16114 
#Fix ^ be sure 4D is name of 4th Dimension, or change it here
-sg Main2 
-sn “Main2=WriteAt(&I;&I;&S)” 
#      Fix ^         Fix ^  with proper variable list, where I=integer, 
S=String
-o Proc.Ext(WriteAt)
#          Fix ^      with proper unit name

Conclusions

Although some labor is required to initially write and compile the graphics external procedures, it only needs to be done once. After being installed in the Proc.Ext, a 4th Dimension database can access the procedures with minimal effort. Unfortunately, describing the process makes it sound much more difficult than it actually is.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Dropbox 193.4.5594 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
Google Chrome 122.0.6261.57 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Skype 8.113.0.210 - Voice-over-internet...
Skype is a telecommunications app that provides HD video calls, instant messaging, calling to any phone number or landline, and Skype for Business for productive cooperation on the projects. This... Read more
Tor Browser 13.0.10 - Anonymize Web brow...
Using Tor Browser you can protect yourself against tracking, surveillance, and censorship. Tor was originally designed, implemented, and deployed as a third-generation onion-routing project of the U.... Read more
Deeper 3.0.4 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
OnyX 4.5.5 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Hopper Disassembler 5.14.1 - Binary disa...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more

Latest Forum Discussions

See All

Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »
TouchArcade Game of the Week: ‘Vroomies’
So here’s a thing: Vroomies from developer Alex Taber aka Unordered Games is the Game of the Week! Except… Vroomies came out an entire month ago. It wasn’t on my radar until this week, which is why I included it in our weekly new games round-up, but... | Read more »
SwitchArcade Round-Up: ‘MLB The Show 24’...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for March 15th, 2024. We’re closing out the week with a bunch of new games, with Sony’s baseball franchise MLB The Show up to bat yet again. There are several other interesting games to... | Read more »
Steam Deck Weekly: WWE 2K24 and Summerho...
Welcome to this week’s edition of the Steam Deck Weekly. The busy season has begun with games we’ve been looking forward to playing including Dragon’s Dogma 2, Horizon Forbidden West Complete Edition, and also console exclusives like Rise of the... | Read more »
Steam Spring Sale 2024 – The 10 Best Ste...
The Steam Spring Sale 2024 began last night, and while it isn’t as big of a deal as say the Steam Winter Sale, you may as well take advantage of it to save money on some games you were planning to buy. I obviously recommend checking out your own... | Read more »
New ‘SaGa Emerald Beyond’ Gameplay Showc...
Last month, Square Enix posted a Let’s Play video featuring SaGa Localization Director Neil Broadley who showcased the worlds, companions, and more from the upcoming and highly-anticipated RPG SaGa Emerald Beyond. | Read more »
Choose Your Side in the Latest ‘Marvel S...
Last month, Marvel Snap (Free) held its very first “imbalance" event in honor of Valentine’s Day. For a limited time, certain well-known couples were given special boosts when conditions were right. It must have gone over well, because we’ve got a... | Read more »
Warframe welcomes the arrival of a new s...
As a Warframe player one of the best things about it launching on iOS, despite it being arguably the best way to play the game if you have a controller, is that I can now be paid to talk about it. To whit, we are gearing up to receive the first... | Read more »
Apple Arcade Weekly Round-Up: Updates an...
Following the new releases earlier in the month and April 2024’s games being revealed by Apple, this week has seen some notable game updates and events go live for Apple Arcade. What The Golf? has an April Fool’s Day celebration event going live “... | Read more »

Price Scanner via MacPrices.net

Apple Education is offering $100 discounts on...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take $100 off the price of a new M3 MacBook Air.... Read more
Apple Watch Ultra 2 with Blood Oxygen feature...
Best Buy is offering Apple Watch Ultra 2 models for $50 off MSRP on their online store this week. Sale prices available for online orders only, in-store prices may vary. Order online, and choose... Read more
New promo at Sams Club: Apple HomePods for $2...
Sams Club has Apple HomePods on sale for $259 through March 31, 2024. Their price is $40 off Apple’s MSRP, and both Space Gray and White colors are available. Sale price is for online orders only, in... Read more
Get Apple’s 2nd generation Apple Pencil for $...
Apple’s Pencil (2nd generation) works with the 12″ iPad Pro (3rd, 4th, 5th, and 6th generation), 11″ iPad Pro (1st, 2nd, 3rd, and 4th generation), iPad Air (4th and 5th generation), and iPad mini (... Read more
10th generation Apple iPads on sale for $100...
Best Buy has Apple’s 10th-generation WiFi iPads back on sale for $100 off MSRP on their online store, starting at only $349. With the discount, Best Buy’s prices are the lowest currently available... Read more
iPad Airs on sale again starting at $449 on B...
Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices again for $150 off Apple’s MSRP, starting at $449. Sale prices for online orders only, in-store price may vary. Order online, and choose... Read more
Best Buy is blowing out clearance 13-inch M1...
Best Buy is blowing out clearance Apple 13″ M1 MacBook Airs this weekend for only $649.99, or $350 off Apple’s original MSRP. Sale prices for online orders only, in-store prices may vary. Order... Read more
Low price alert! You can now get a 13-inch M1...
Walmart has, for the first time, begun offering new Apple MacBooks for sale on their online store, albeit clearance previous-generation models. They now have the 13″ M1 MacBook Air (8GB RAM, 256GB... Read more
Best Apple MacBook deal this weekend: Get the...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New 15-inch M3 MacBook Air (Midnight) on sale...
Amazon has the new 15″ M3 MacBook Air (8GB RAM/256GB SSD/Midnight) in stock and on sale today for $1249.99 including free shipping. Their price is $50 off MSRP, and it’s the lowest price currently... Read more

Jobs Board

Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Senior Software Engineer - *Apple* Fundamen...
…center of Microsoft's efforts to empower our users to do more. The Apple Fundamentals team focused on defining and improving the end-to-end developer experience in Read more
Relationship Banker *Apple* Valley Main - W...
…Alcohol Policy to learn more. **Company:** WELLS FARGO BANK **Req Number:** R-350696 **Updated:** Mon Mar 11 00:00:00 UTC 2024 **Location:** APPLE VALLEY,California Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill WellSpan Medical Group, York, PA | Nursing | Nursing Support | FTE: 1 | Regular | Tracking Code: 200555 Apply Now Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.