Selasa, 25 November 2008

Encapsulating graphics

Delphi simplifies Windows graphics by encapsulating various graphics tools into a canvas. The canvas represents the drawing surface of a window or control and contains other classes, such as a pen, a brush, and a font. A canvas is like a Windows device context, but it takes care of all the bookkeeping for you.

If you have written a graphical Windows application, you are familiar with the requirements imposed by Windows’ graphics device interface (GDI). For example, GDI limits the number of device contexts available and requires that you restore graphic objects to their initial state before destroying them.

With Delphi, you do not have to worry about these things. To draw on a form or other component, you access the component’s Canvas property. If you want to customize a pen or brush, you set its color or style. When you finish, Delphi disposes of the resources. Delphi caches resources to avoid recreating them if your application frequently uses the same kinds of resource.

You still have full access to the Windows GDI, but you will often find that your code is simpler and runs faster if you use the canvas built into Delphi components.

CLX graphics encapsulation works differently. A canvas is a painter instead. To draw on a form or other component, you access the component’s Canvas property. Canvas is a property and it is also an object called TCanvas. TCanvas is a wrapper around a Qt painter that is accessible through the Handle property. You can use the handle to access low-level Qt graphics library functions.

If you want to customize a pen or brush, you set its color or style. When you finish, Delphi or Kylix disposes of the resources. CLX applications also cache the resources.

You can use the canvas built into CLX components by descending from them. How graphics images work in the component depends on the canvas of the object from which your component descends.Graphics features are detailed in Chapter 6, “Using graphics in components.”

0 komentar:


Free Blogger Templates by Isnaini Dot Com. Powered by Blogger