![]() |
for Ivory Draw 1.0 A simple program that shows an image. |
Introduction
Here is the first Ivory Draw tutorial, which explains how to go to exclusive mode and display a picture on the screen.
Creating the Application Form
First create a new application, then drop down a TIvoryDraw, a TIvorySurface, a TIvoryBitmap, and a TIvoryPalette component on the main form. Next, change the following settings in the Object Inspector:
Form->BorderStyle = bsNone IvoryDraw1->BackSurface = IvorySurface1 IvoryDraw1->ExclusiveMode = true IvoryDraw1->Palette = IvoryPalette1 IvorySurface1->BackgroundBitmap = IvoryBitmap1 IvorySurface1->DrawBackground = true IvoryBitmap1->FileName = Ivory.bmp IvoryPalette1->FileName = Ivory.bmpThis requires a little bit of explanation. First of all, you set the BorderStyle property for the main form to bsNone. This ensures that your form doesn't have a title bar nor it is sizeable. You can also set the Color property for the form to clBlack, or whatever you like. When your program starts, it will display the form for a moment in the color you specified in the Color property.
Then you make the surface component the backbuffer surface by assigning it to the BackSurface property for IvoryDraw1. It's a good practice to create a new surface and make it the backbuffer surface, because this way you can have full access to the surface properties at design time. If you don't assign a backbuffer surface to BackBuffer, then TIvoryDraw creates an own surface automatically, which can only be manipulated at runtime. So BackSurface is never NULL, even if you clear it in the Object Inspector, or assign NULL to it, it always holds a pointer. That's why the default value for BackSurface is “IvoryDraw1->”. It might be strange at the first time, but it's not a bug in Ivory Draw, it's a normal behavior.
Next, you set ExclusiveMode to true, allowing Ivory Draw to use the whole screen exclusively. This means you won't be able to debug your application, but I don't think it's a big problem in such a simple case, right? If you want to debug an Ivory Draw application, you must set ExclusiveMode to false. If you forget about it, you might hang up Windows 95. Windows NT cannot be hung up this way, but it's not a good practice to always shut down your program, or maybe the whole IDE, from the Task Manager.
Then you assign a palette and a background bitmap to the surface, and enable the background bitmap. Finally, you set the background bitmap file name for both the image and the palette components. That's all you need to do to set up a background image on the backbuffer surface.
Writing the code
Now you only need to provide a way to exit the application. The simplest way is to write an OnKeyPress event handler like this:
void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key) { Close(); }Congratulations! You have written your first Ivory Draw application. Now you can compile and run. You might have noticed that the cursor is visible on the screen. To hide the mouse cursor just add the Cursor=crNone line in the FormCreate method.