From 7b52cc13af4e85f1ca2deb6b6c77de9c95ea0dcf Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:33 +0000 Subject: First commit - moving from LuaForge to SourceForge --- html/en/samples.html | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 html/en/samples.html (limited to 'html/en/samples.html') diff --git a/html/en/samples.html b/html/en/samples.html new file mode 100644 index 0000000..1759ddc --- /dev/null +++ b/html/en/samples.html @@ -0,0 +1,99 @@ + + + + +Samples + + + + + +

Samples

+

Simple Draw

+ +

This is an example of a simple drawing program using a IUP canvas:

+ + + +
cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,"CONID")); 
cdCanvasLineStyle(canvas, CD_DASHED);
cdCanvasLine(canvas, 0, 0, 100, 100);
cdCanvasKillCanvas(canvas);
+ + + +

If you want to use World Coordinates:

+ + + +
cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,"CONID")); 
wdCanvasViewport(canvas, 0, 100, 0, 100);
wdCanvasWindow(canvas, -1.5, 1.5, -3000, 3000);
cdCanvasLineStyle(canvas, CD_DASHED);
wdCanvasLine(canvas, -0.5, -500, 1.0, 1000);
cdKillCanvas(canvas);
+ + +

Off Screen Drawing (Double Buffering)

+ +

To draw in the background and later on transfer the drawing to the screen, use:

+ + + +
cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,"CONID")); 
cdCanvas* db_canvas = cdCreateCanvas(CD_DBUFFER, canvas); cdCanvasActivate(db_canvas); // update canvas size, window could be resized
cdCanvasLineStyle(db_canvas, CD_DASHED);
cdCanvasLine(db_canvas, 10, 10, 50, 50);
cdCanvasFlush(db_canvas); // swap to the window canvas
cdKillCanvas(db_canvas);
cdKillCanvas(canvas);
+ +

To draw in a RGB image, use:

+ +
cdCanvas* canvas = cdCreateCanvasf(CD_IMAGERGB, "%dx%d", width, height);
+cdCanvasLineStyle(canvas, CD_DASHED); 
+cdCanvasLine(canvas, 10, 10, 50, 50); 
+unsigned char* red = cdCanvasGetAttribute(canvas, "REDIMAGE");
+// do something with the raw image data
+cdKillCanvas(canvas); 
+
+ + +

Lua Samples

+ +

To draw in a RGB image in CDLua for Lua 5:

+ +
bitmap = cd.CreateBitmap(200,200,cd.RGB)
+canvas = cd.CreateCanvas(cd.IMAGERGB, bitmap)
+canvas:Font("Times", cd.BOLD, 12)
+canvas:Text(10, 10, "Test")
+canvas:KillCanvas()
+ +

Check the file samples_cdlua5.zip or samples_cdlua5.tar.gz for several samples in Lua. + For some of them you will need also the IUP libraries. 

+ +

Screen Capture in Windows

+ +

Using a NULL parameter to the NATIVEWINDOW driver you can get access to the entire screen:

+ +
cdCanvas *canvas = cdCreateCanvas(CD_NATIVEWINDOW, NULL);
+cdCanvasGetSize(canvas, &width, &height, NULL, NULL);
+// allocate red, green and blue pointers
+cdCanvasGetImageRGB(canvas, red, green, blue, 0, 0, width, height);
+cdKillCanvas(canvas);
+ + +

Generating an EMF file that contains an IM Image in Lua

+ +
+image = im.FileImageLoadBitmap(image_filename)
+canvas = cd.CreateCanvas(cd.EMF,emf_filename.." "..image:Width().."x"..image:Height())
+image:cdCanvasPutImageRect(canvas,0,0,0,0)
+cd.KillCanvas(canvas)
+
+ + +

Complete Example

+ +

We have created an application called Simple Draw that illustrates the use of all functions in the CD library + (including WD). You can see the source code in the simple.c file, or take the file + simple.zip for a complete set of files including makefiles for all platforms. + Extract the files creating subfolders, using parameter "-d".

+ +

Example for Tests

+ +

The CDTEST example is actually one of the applications used to test virtually + all functions of the CD library. Its interface uses the IUP library, and it can run in several platforms. You can take + either the .EXE files or the source code. Extract the files creating subfolders, using parameter "-d". + Warning: This application is not didactic.

+ + + + + -- cgit v1.2.3