Skip to content
Zplutor edited this page Apr 29, 2017 · 1 revision

What’s Graphic Resources

We need different kinds of resources when we draw image or text.

Firstly, renderer is the most important resource. A renderer just like a canvas, it displays what we draw on it. Nothing can be drawn without a renderer. In zaf, every window has an associated renderer, which displays controls.

Secondly, drawing on a renderer needs corresponding resources. For instance, drawing a green rectangle needs a green brush; drawing a red dashed line needs a red brush and a dashed stroke; and drawing a single line black text needs a black brush and a text format, which specifies the style of text, such as font, size and weight etc.

zaf classifies resources to two category: global resources and renderer resources.

Global Resources

Global resources are created by a singleton resource factory zaf::ResourceFactory. The lifetimes of these resources are not affected by renderers. Also, a global resource can be used on several renderers.

For example, strokes and text formats are both global resources, they are created by CreateStroke and CreateTextFormat methods respectively.

Renderers themselves are global resources. CreateWindowRenderer method can be used to create a renderer associated with a specified window.

Renderer Resources

Renderer resources are created by renderers. The lifetimes of these resources are affected by the renderers who create them. When a renderer is destroy, the resources it creates are destroyed as well. Renderer resources can only be used on the renderers who creates them.

For example, brushes and bitmaps are both renderer resources, they can be created by methods like CreateSolidColorBrush and CreateBitmap.

Compatible renderers are special renderers, they are created by CreateCompatibleRenderer method of the renderer, so they are renderer resources, rather than global resources.