summaryrefslogtreecommitdiff
path: root/html/en/samples.html
blob: 1759ddc74872cb57cc898e68184621ce6d8882b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Samples</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<h1>Samples</h1>
<h3><a name="Simple Draw">Simple Draw</a></h3>

  <p>This is an example of a simple drawing program using a IUP canvas: </p>


  
    <pre>cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,&quot;CONID&quot;)); <br>cdCanvasLineStyle(canvas, CD_DASHED);<br>cdCanvasLine(canvas, 0, 0, 100, 100);<br>cdCanvasKillCanvas(canvas);</pre>
  


  <p>If you want to use <a name="World Coordinates"><strong>World Coordinates</strong></a>: </p>


  
    <pre>cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,&quot;CONID&quot;)); <br>wdCanvasViewport(canvas, 0, 100, 0, 100); <br>wdCanvasWindow(canvas, -1.5, 1.5, -3000, 3000); <br>cdCanvasLineStyle(canvas, CD_DASHED); <br>wdCanvasLine(canvas, -0.5, -500, 1.0, 1000); <br>cdKillCanvas(canvas);<code> </code></pre>
  

<h3><a name="Off Screen Drawing">Off Screen Drawing</a> (Double Buffering) </h3>

  <p>To draw in the background and later on transfer the drawing to the screen, use: </p>


  
    <pre>cdCanvas* canvas = cdCreateCanvas(CD_NATIVEWINDOW, IupGetAttribute(IupCanvas,&quot;CONID&quot;)); <br>cdCanvas* db_canvas = cdCreateCanvas(CD_DBUFFER, canvas); cdCanvasActivate(db_canvas); // update canvas size, window could be resized<br>cdCanvasLineStyle(db_canvas, CD_DASHED); <br>cdCanvasLine(db_canvas, 10, 10, 50, 50); <br>cdCanvasFlush(db_canvas);  // swap to the window canvas <br>cdKillCanvas(db_canvas); <br>cdKillCanvas(canvas); </pre>
  
  <p>To draw in a RGB image, use:</p>
  
    <pre><code>cdCanvas* canvas = cdCreateCanvasf(CD_IMAGERGB, &quot;%dx%d&quot;, width, height);
</code>cd<code>Canvas</code>LineStyle(<code>canvas, </code>CD_DASHED); 
cd<code>Canvas</code>Line(<code>canvas, </code>10, 10, 50, 50); 
unsigned char* red = cdCanvasGetAttribute(canvas, &quot;REDIMAGE&quot;);
// do something with the raw image data
cdKillCanvas(canvas); 
</pre>
  

<h3>Lua Samples</h3>

  <p>To draw in a RGB image in CDLua for Lua 5:</p>
  
    <pre>bitmap = cd.CreateBitmap(200,200,cd.RGB)
canvas = cd.CreateCanvas(cd.IMAGERGB, bitmap)
canvas:Font(&quot;Times&quot;, cd.BOLD, 12)
canvas:Text(10, 10, &quot;Test&quot;)
canvas:KillCanvas()</pre>
  
  <p>Check the file <a href="../download/samples_cdlua5.zip">samples_cdlua5.zip</a> or <a href="../download/samples_cdlua5.tar.gz">samples_cdlua5.tar.gz</a> for several samples in Lua. 
	For some of them you will need also the IUP libraries.&nbsp; </p>

<h3>Screen Capture in Windows</h3>

  <p>Using a NULL parameter to the NATIVEWINDOW driver you can get access to the entire screen:</p>
  
    <pre>cdCanvas *canvas = cdCreateCanvas(CD_NATIVEWINDOW, NULL);
cdCanvasGetSize(canvas, &amp;width, &amp;height, NULL, NULL);
// allocate red, green and blue pointers
cdCanvasGetImageRGB(canvas, red, green, blue, 0, 0, width, height);
cdKillCanvas(canvas);</pre>
  

<h3>Generating an EMF file that contains an IM Image in Lua</h3>

<pre>
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)
</pre>
  

<h3><a name="Complete Example">Complete Example</a></h3>

  <p>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 <a href="../download/simple.c">simple.c</a> file, or take the file
  <a href="../download/simple.zip">simple.zip</a> for a complete set of files including makefiles for all platforms. 
  Extract the files creating subfolders, using parameter &quot;<font face="Courier New">-d</font>&quot;.</p>

<h3>Example for Tests</h3>

  <p>The <a href="../download/cdtest.zip">CDTEST</a> 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 &quot;<font face="Courier New">-d</font>&quot;. 
  Warning: This application is not didactic. </p>


</body>

</html>