OceanLife sample
The OceanLife sample was designed to showcase some of Paradox’s ability to handle graphics. It is a form based on the contents of the Oceanlife.db. Running the form allows you to search through the records, including graphics, found in the database. The following techniques were used in the creation of the Ocean life form:
• creating graphical backgrounds
• storing pointers to images on disk
• using bit masks to create floating images
• using graphic objects as navigation controls
Creating a graphical background
The background image in the OceanLife sample was created using CorelDraw 10. You can use an image editor to create background images. You can also use the clipart found in WordPerfect Office 2002 (on CD #2).
To create a background image
1. Click File, New, Form.
2. Click Blank.
3. Click Insert, Graphic.
4. Place the graphic object on the form.
5. Click Edit, Paste from.
6. Choose the directory and folder where the image you want to use as the background is stored.
7. If necessary, reposition and resize the graphic object.
8. Right-click the graphic object, and click Properties.
9. Click the Design tab.
10. Disable the Contain objects check box.
Creating applications for use in different screen resolutions
Storing pointers to images on disk
Paradox allows you to store images in Paradox tables using the graphic field type when creating a table. However, because some image types, such as photographs, can be large, it is sometimes advantageous to use compressed formats like JPEG (.JPG) or Corel Photo-Paint (.CPT). You can also specify to import them only when they need to be displayed. The OceanLife template uses this technique for storing the photographs of the fish.
The OceanLife.db table (stored in the “oceanlife_data” alias) contains a field, “ImageFileName”, that contains the name of the image to display when the user browses through records in the OceanLife form. A second alias, “oceanlife_images”, points to the directory where the images are located, therefore, each image can be easily referred to in ObjectPAL.
The custom method “setFish()” (on the form object) is triggered each time the user navigates forward or backward through the table. SetFish() checks for the existence of the image, and if it exists, imports it and assigns it to and unbound graphic object on the form. If the image file is missing, the message box displays an appropriate method.
To create a form that displays images stored on the disk
1. Click File, New, Table.
You can also use an existing table.
2. In the Restructure table dialog box, click the Field roster tab.
3. Type ImageFileName in the Field name column.
4. Click Save to close the Restructure table dialog box.
5. Open the table.
6. Click the Edit button on the toolbar.
7. Click Insert, Record and enter the names of the files containing the images in this field.
8. Create a new form based on that table.
9. Click Tools, Quick design, and Quick form.
Do not place the “filename” field on the form.
9. Place a graphic object on the form.
10. Right-click the graphic, and click Properties.
11. Click the General tab.
12. Type DiskImage in the Name of object box.
13. In the action event of the form, place code that does the following. (See the example below)
• check the eventInfo variable for DataArriveRecord
• attach a tcursor to the table by using tc.attach() and referencing a field object
• ensure the file actually exists by calling isFile()
• read the file into a graphic variable
• assign the graphic variable to the unbound graphic object on your form
Example:
(You may need to make modifications to reflect your tables and folders.)
method action(var eventInfo ActionEvent)
var
siID SmallInt ;// tmp handle to the action id
gTemp graphic ;// graphic variable to hold the image
tcTable tcursor ;// handle to the form’s table
endVar
if eventInfo.isPreFilter() then
;// This code executes for each object on the form
siID = eventInfo.id()
switch
;// each time we move to a new record, import the image.
case siID = DataArriveRecord :
;// Attach to the table
;// (replace “master” with the name of a tableframe or
;// field object that is connected to your table)
tcTable.attach(master)
;// specify the path to the folder containing the images
;// aliases can be used here as well.
strFile = "c:\\myImages\\" + tcTable.ImageFileName
if isFile(strFile) then ;// make sure the file exists
if gTemp.readFromFile(strFile) then ;// load the image
DiskImage.value = gTemp ;// assign it to the graphic obj
else
msgInfo(“Error”, “Couldn’t read “ + strFile
endif
else
msgInfo(“Error”, “Couldn’t open “ + strFile
endIf
tcTable.close()
endSwitch
else
;// This code executes only for the form
endIf
endMethod
Using Bit Masks To Create “Floating” Images
The navigation controls on the OceanLife form (the two fish images on the bottom left and bottom right of the form) appear to have transparent areas surrounding them that let the background image show through. This is accomplished by creating a second bitmap, which is called a bit mask, that is based on the original, which is overlaid on the original to create a transparent area..
To create a bit mask using Corel Photo-Paint 10
1. Open the bitmap you wish to make a mask for in Corel Photo-Paint.
2. In the Mask flyout, click the Magic wand mask tool.
3. Click in the white area surrounding the image.
A mask of the area is created.
4. Click Edit, Copy.
5. Click File, New from clipboard to create a new image containing only the mask.
6. Click Image, Transform, Invert to reverse the colors.
If you want to convert the bit mask to a black-and-white image to reduce the size of the file, click Image, Mode, Black & White.
7. Click File, Export to save your bit mask as a Windows Bitmap.
To apply the bit mask in Paradox to create transparancy:
1.Paste the original bitmap and the bit mask into separate Graphic objects.
2. In the properties of the original bitmap, set the RasterOperation to "Source And"
3. In the properties of the bit mask, set the RasterOperation to "SourcePaint".
4. Place the original bitmap in front of the bit mask, and align them exactly.
You can use the alignment features found in the Format menu.
5. Group the bitmap and bit mask together with the group command from the Format
menu.
Using Graphic Objects As Navigation Controls
The two fish icons on the bottom left and bottom right of the Oceanlife form act as navigation buttons for the form: clicking on the fish on the right will move to the next record, and clicking on fish on the left moves to the previous record.
To create a navigation button using a graphic object
1. With a form open in the design window, click Insert, Graphic.
2. Right-click the graphic, and click Paste from.
3. Choose the directory and folder where the graphic is stored.
4. In the mouseClick() event of the graphic object add:
• active.action(DataNextRecord) to move to the next record, or
• active.action(DataPriorRecord) to move to the previous record.