If there is a wrong place in this article, you can contact the author through ttch007@sina.com, and hope to discuss with you.
The image in the VCL displays the core unit Graphics, where the image object is mainly divided into 2 Class TGRIPHICs.
TGRIPHICSOBJECT, both from the literal meaning is an image body, one is an image tool. Tell a metaphor
The drawing body is a drawing tool body. Next we specifically understand how the unit is packaged in this unit.
TFONT, TPEN, TBRUSH 3 objects form Tcanvas
You can see TGRIPHICSOBJECT coming in Figure 1, TFONT, TPEN, TBRUSH, and TGRIPHICSObject is a lasting class with storage capabilities. Understanding Tcanvas is to understand these three objects, they offer the basic features and data of Tcanvas, and Tcanvas starts to operate on the data of these three objects. What did TFONT, TPEN, TBRUSH do to provide data from Tcanvas?
Take this question, let's take a look at TFont, Tbrush, TPEN
Let's take a look at TGRAPHICSOBJECT offers these three classes.
TGRAPHICSOBJECT = Class (TPERSIStent)
Private
FONCHANGE: TNOTIFYEVENT;
Fresource: PRESOURCE;
Fownerlock: prtlcriticalsection;
protected
Dynamic;
Procedure lock;
Procedure unlock;
public
Function HandleAllocated: boolean;
Property Onchange: TNotifyEvent Read Fonchange Write Fonchange
Property OwnerCritics: property OwnerCriticalSection: property OwnerCriticalSection: property OwnerCritics;
END;
From above we can see TGRAPHICS provides a standard changing event function pointer, a resource pointer, a critical zone lock function, then what is the structure pointed to by the resource pointer?
PRESOURCE = ^ TRESOURCE;
TRESOURCE = Record
Next: PRESOURCE;
REFCOUNT: INTEGER;
Handle: thandle;
Hashcode: Word;
Case Integer of
0: (Data: TRESDATA);
1: (font: tfontdata);
2: (Pen: tpendata);
3: (brush: tbrushdata);
END;
The above is his structure
He is a Hash table, the data structure is not talking, we skip, you can see 4 structures, there is the 3 class property storage structure of our unit to talk, Bit, everyone found it.
We skip 3 structures and directly explain the following mechanisms.
We know that TGRAPHICS provides the most basic feature of these three classes, then we will know how these three classes are established and set attributes.
TRESOURCEMANAGER is a class that establishes actual data space, which provides true data space for these three classes. (He and Windows have no relationships) This may not be understood, I painted a picture, you can find a detailed introduction in the threeclass.png in the compressed package.
First come, first introduce a mechanism, and then talk about the specific operation details in the future.