home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / sharewar / vecad / examples / delphi / editor / Funcs.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-10-10  |  4.4 KB  |  177 lines

  1. unit Funcs;
  2.  
  3. interface
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   OleCtnrs, StdCtrls, ExtCtrls, ComCtrls, Menus, Printers;
  7.  
  8.  
  9. procedure CreateVecWindow (Handle:HWND);
  10. procedure ResizeVecWindow (Handle:HWND);
  11. procedure FileNew;
  12. procedure FileOpen;
  13. procedure UpdateMainTitle;
  14. procedure TestLineStyles;
  15.  
  16. var
  17.   ghwVec:HWND;   // VeCAD window to display draw
  18.   VecX0:Integer;
  19.   VecY0:Integer;
  20.   SBarH:Integer;  // height of status bar
  21.  
  22. implementation
  23.  
  24. uses
  25.   Main, VecApi, DwgProc;
  26.  
  27.  
  28. //-------------------------------------------------------------------
  29. procedure UpdateMainTitle;
  30. var
  31.   iPage, nPage : Integer;
  32. //  buf : array[0..255] of char;
  33.   FileName : array[0..255] of char;
  34.   PageName : array[0..79] of char;
  35.   Title, Pos, Pos1, Pos2 : string;
  36. begin
  37.   iPage := vlPageIndex( '', 0 );
  38.   nPage := vlPageCount();
  39. //  Pos := Str(iPage + 1)tr(nPage);
  40.   Str(iPage+1, Pos1);
  41.   Str(nPage, Pos2);
  42.   Pos := Pos1 + '/' + Pos2;
  43.   vlPropGet( VD_PAGE_NAME, iPage, @PageName );
  44.   vlPropGet( VD_DWG_FILENAME, -1, @FileName );
  45.   if (FileName='') then
  46.   begin
  47.     FileName := 'noname';
  48.   end;
  49.   Title := 'Editor - ['+FileName+'], page: ' + Pos + ' "' + PageName + '"';
  50. //  Title := Title + ', Page:' + PageName;
  51.   Form1.Caption := Title;
  52. end;
  53.  
  54. //-------------------------------------------------------------------
  55. procedure CreateVecWindow (Handle:HWND);
  56. var
  57.   x,y,w,h,h2:Integer;
  58.   str: array[0..255] of char;
  59. begin
  60.   vlRegistration( 0 ); // enter your reg. code here
  61.  
  62.   // Register your copy of Vecad.dll
  63.   vlRegistration( 0 );
  64.   // Create VeCAD toolbar
  65.   w:=0;
  66.   h:=0;
  67.   x:=0;
  68.   y:=-1;
  69.   vlToolBarCreate( Handle, VL_TB_MAIN, x, y, -1, 1, @w, @h );
  70.   y:=y+h;
  71.   h2:=h;
  72.   x:=0;
  73.   vlToolBarCreate( Handle, VL_CB_LAYER, x, y, 210, h2, @w, @h );
  74.   x:=x+w;
  75.   vlToolBarCreate( Handle, VL_CB_COLOR, x, y, 90, h2, @w, @h );
  76.   x:=x+w;
  77.   vlToolBarCreate( Handle, VL_CB_STLINE, x, y, 200, h2, @w, @h );
  78.   x:=x+w;
  79.   vlToolBarCreate( Handle, VL_TB_SNAP, x, y, -1, 1, @w, @h );
  80.   y:=y+h;
  81.   vlToolBarCreate( Handle, VL_TB_DRAW, 0, y, 60, 500, @w, @h );
  82.   y:=y+h;
  83.   vlToolBarCreate( Handle, VL_TB_EDIT, 0, y, 60, -1, @w, @h );
  84.   x:=w;
  85.   y:=h2+h2-1;
  86.   VecX0:=x;
  87.   VecY0:=y;
  88.   // Create VeCAD StatusBar
  89.   vlStatBarCreate( Handle, @SBarH );
  90.   // Create VeCAD window, size will be set in OnSize()
  91.   ghwVec := vlWndCreate( Handle, VL_WS_CHILD+VL_WS_SCROLL+VL_WS_BORDER, 0,0,400,300, @MyDwgProc );
  92.   if (ghwVec<>0) then
  93.   begin
  94.     str := 'Editor';
  95.     vlPropPut( VD_WND_EMPTYTEXT, ghwVec, @str );
  96. //    vlPropPutInt( VD_WND_CURSOR_CROSS, ghwVec, 0 );
  97.   end
  98. end;
  99.  
  100. //-------------------------------------------------------------------
  101. procedure ResizeVecWindow (Handle:HWND);
  102. var
  103.   w,h:Integer;
  104. begin
  105.   vlGetWinSize( Handle, @w, @h );
  106.   If ((w > 0) And (h > 0)) Then
  107.   begin
  108.     // Resize drawing window
  109.     vlWndResize( ghwVec, VecX0, VecY0, w - VecX0, h - VecY0 - SBarH );
  110.     // Resize statusbar
  111.     vlStatBarResize();
  112.   end
  113. end;
  114.  
  115. //-------------------------------------------------------------------
  116. procedure FileNew;
  117. //var
  118. //  iDwg:Integer;
  119. begin
  120.   vlFileNew( ghwVec, @MyDwgProc, '' );
  121. {
  122.   iDwg := vlDwgCreate( ghwVec, @MyDwgProc );
  123.   if (iDwg>=0) then
  124.   begin
  125.     vlClear( true );
  126.     vlRedraw();
  127.     vlSetFocus();
  128.   end
  129. }
  130. end;
  131.  
  132. //-------------------------------------------------------------------
  133. procedure FileOpen;
  134. //var
  135. //  iDwg:Integer;
  136. begin
  137.   vlFileOpen( ghwVec, @MyDwgProc, '' );
  138. {
  139.   iDwg := vlDwgCreate( ghwVec, @MyDwgProc );
  140.   if (iDwg>=0) then
  141.   begin
  142.     if (vlFileLoad( VL_FILE_VEC, '' )=false) then
  143.     begin
  144.       vlDwgDelete( iDwg );
  145.     end
  146.   end
  147. }
  148. end;
  149.  
  150. //-------------------------------------------------------------------
  151. //  Test line styles
  152. //-------------------------------------------------------------------
  153. procedure TestLineStyles;
  154. var
  155.   ls1, ls2, i: Integer;
  156. begin
  157.   vlFileNew( ghwVec, @MyDwgProc, '' );
  158.   ls1 := vlStLineAdd( 'abc', '1, -1' );
  159.   ls2 := vlStLineAdd( 'dash dot', '2, -0.5, 0, -0.5' );
  160.   vlStLineAdd( 'T-line', '3., -1.5, L(0. -0.5 0. 0.5), L(-0.5 0.5 0.5 0.5), -1.5' );
  161.   vlStLineActive( 0 );  // default solid line style
  162.   vlAddLine( 0,0, 10,20 );
  163.   vlStLineActive( ls1 );
  164.   vlAddLine( 10,20, 30,10 );
  165.   vlStLineActive( ls2 );
  166.   vlAddLine( 30,10, 0,0 );
  167.   i := vlStLineIndex( 'T-line', 0 );
  168.   vlStLineActive( i );
  169.   vlAddLine( 0,15, 30,0 );
  170.   vlUpdate();
  171.   vlZoom( VL_ZOOM_ALL );
  172.   vlSetFocus();
  173. end;
  174.  
  175.  
  176. end.
  177.