The V C++ GUI Framework User Guide:Tutorial:Drawing with V

From EDM2
Jump to: navigation, search

Introduction to Drawing

The basic V model of drawing is a canvas. V supports several kinds of drawing canvases. The most obvious canvas is the screen drawing canvas. This will often be the main or even only canvas you use. V also supports printing canvases. Each kind of canvas has identical drawing methods, so you can write code to draw that is mostly independent of which kind of canvas is being used.

There is also a specialized drawing canvas to support OpenGL. This class differs somewhat from the other drawing canvases.

Drawing with the vDC Class

You draw to the various canvases using a vDC class, the general V Drawing Canvas Class (the OpenGL canvas does not use the vDC class). The vDC class for drawing to the screen is vCanvasPaneDC. The class vPrintDC is the platform independent class to draw to a printer. For X, vPrintDC supports PostScript printing. The Windows version supports standard Windows printers. (You can also use the PostScript DC independently on Windows.) If you write your drawing code to use a vDC pointer, you will be able to draw to several canvases just by changing the value of the pointer.

Each vDC supports the methods described in the vDC section. Because the vCanvasPane class is so central to most applications, it duplicates all the vDC methods so you can call them directly from your vCanvasPane object. In fact, all the methods in vCanvasPane are just calls to the corresponding vDC using the vCanvasPaneDC of the canvas pane. You can get the vCanvasPaneDC pointer with the GetDC method.

There are three kinds of drawing methods supported by V. The simplest methods draw lines of various widths and colors using the current vPen. You change the color and width of the lines being drawn by setting the current vPen with the SetPen method.

The second type of drawing includes filling the space surrounded by a shape such as a polygon. The edges of the shape are drawn using the current vPen. The filled area is drawn using the current vBrush. You can set various attributes of the brush, and use SetBrush to change how the shapes will be filled, as well as changing the attributes of the vPen used to draw the surrounding line. Both the pen and the brush can be transparent, allowing you to draw unfilled outline shaped, or to fill a shape without an outline.

Finally, V supports drawing of text on a canvas using various vFonts and text attributes. The canvas pane will start out using the default system font (vfSystemDefault). If you need a different initial font, use vFont::SetFontValues to select the font you want, then vCanvasPane::SetFont to set the new font.


All V drawing canvas classes use integer physical coordinates appropriate to the canvas. All devices call the upper left corner x,y coordinate of the drawing canvas 0,0. The x values increase to the right, and y values increase down.

It it up to each application to provide appropriate mapping from the coordinates used for the particular model being used (often called the world coordinate system) to the physical mapping used by each V drawing canvas. Each drawing canvas will have a physical limit for the maximum x and maximum y, usually imposed by the particular canvas (a screen or a paper size, for example). You can set a scale factor for each drawing canvas which can be helpful for using different kinds of drawing canvases. V also supports setting an x,y translation. This will allow you to more easily use the scroll bars and set margins on printers. Your application can usually use the messages received from the scroll bars to set the translation coordinates to map your the canvas to a different drawing area. The system will handle clipping.

However, the application is for the most part responsible for determining all coordinate mapping - translations of a viewport of the drawing, determining the scaling for various drawing canvases, and any mapping from the world to the physical coordinates. The application will have to map the mouse input accordingly, too.

See Also

vCanvasPaneDC, vMemoryDC, and vPrintDC.