The LiteCAD graphics window is used to display and edit graphics data contained in the drawing object. Put it as a child-window it on the desired window/form of your application, by call the function lcCreateWindow, and link it with a drawing by the function lcWndSetBlock. LiteCAD graphics window have service objects Magnifier and Aerial View.
Hover text demo When user presses left mouse button - the hover text with cursor coordinates will appear at left-bottom corner of graphics window.When user moves cursor - the text disappear.
HANDLE lcWndGetEntByPoint (HANDLE hLcWnd,int Xwin,int Ywin);Returns handle to the entity located at the specified window point, within pickbox surroundings. The size of the pickbox is defined by the LC_PROP_G_PICKBOXSIZE property. HANDLE lcWndGetEntByPoint2 (HANDLE hLcWnd,double X,double Y,double Delta);Returns a handle to an entity which is touched by specified point. If several entities was found then the function will return the later created entity.
Get one entity by LC_EVENT_LBDOWN event:When user presses left mouse button and key, we try to retrieve an entity at cursor position.If any entity have been found, we change its color to red/yellow.
Gets an array of entities at specified position (window coordinates): int lcWndGetEntsByPoint (HANDLE hLcWnd,int Xwin,int Ywin,int nMaxEnts); Parameters: hLcWnd(Handle to LiteCAD graphics window.);Xwin Ywin(Coordinate in LiteCAD window. If -1 specified for both parameters, then cursor coordinates will be used. );nMaxEnts(Maximal number of entities that can be retrieved.You can specify -1 to retrieve unlimited number of entities.In order to free the inner memory buffer set 0. ). Return Value: A number of found entities. Remarks: Found entities can be retrieved by the lcWndGetEntity function.
Get several entities by LC_EVENT_LBDOWN event:When user presses left mouse button and key, we try to retrieve all entities at cursor position.For each found entity, we change its color to yellow/red.
Returns an array of entities which are placed inside or crossed by the specified rectangle: int lcWndGetEntsByRect (HANDLE hLcWnd,double Left,double Bottom,double Right,double Top,BOOL bCross,int nMaxEnts); Parameters: hLcWnd(Handle to LiteCAD graphics window.);Left Bottom Right Top(Specify a selecting rectangle coordinates, on the view coordinate space.In order to use currenly visible area, specify zero for all parameters.);bCross(If TRUE, then the function will retrieve entities which are inside or crossed by the specified rectangle.If FALSE, then the function will retrieve entities which are completely inside of the specified rectangle.)nMaxEnts(Maximal number of entities that can be retrieved.You can specify -1 to retrieve unlimited number of entities.In order to free the inner memory buffer set 0. ). Return Value: A number of found entities. Remarks: Found entities can be retrieved by the lcWndGetEntity function.
Get several entities by LC_EVENT_LBDOWN event:When user presses left mouse button and key, we try to retrieve all entities at cursor position.For each found entity, we change its color to yellow/red.
Magnifier is a frame at the right-bottom corner of in LiteCAD graphics window (see the picture below).It displays enlarged area of a drawing which is currently under cursor. As user moves a cursor over a drawing, image in the magnifier is being changed accordingly, in real-time.
三、Aerial view (Navigator)
“Aerial View” is a floating window which displays an image of entire drawing. The window also contains red rectangle which indicates a part of a drawing that is currenly visible in LiteCAD graphics window.User can move this rectangle inside of “Aerial View” window, thereby changing the view in the LiteCAD graphics window. By rotating mouse wheel user changes size of the red rectangle and visible part of a drawing.
四、Object properties window
The properties window is used to display and edit properties of various LiteCAD objects.In Litecad.exe program this window is placed at left side of the design window. When you select an entity, its properties appear in the window, so you can modify it (see the picture below).
In your application you can put it on desired place.In order to link the properties window with a drawing, youhave to call the lcWndSetProps function. These are the functions of the properties window:lcCreateProps(Creates the properties window);lcDeleteProps(Deletes the properties window);lcPropsResize(Changes the size and position of the properties window);lcPropsUpdate(Updates the properties window).
五、Polar Tracking
Setting polar tracking on/off: lcPropPutBool ( hLcWnd, LC_PROP_WND_PTRACK, true ); lcPropPutBool ( hLcWnd, LC_PROP_WND_PTRACK, false ); Setting base point for polar tracking: lcWndSetBasePoint (hLcWnd, true, X, Y );
If LC_PROP_WND_JUMPLINES property is set to true, then LiteCAD graphics window displays draw direction of graphics objects and pen movement between them, as shown on the picture below. This arrows are called “Jump Lines”.In Litecad.exe program you can switch this option by main menu item “View / Jump lines”.
七、Events
Event processing permits you to control user actions while the user is running your application. LiteCAD features several types of events that can be used to instantiate additional procedural code. For each of these events you create an “event procedure” in your application. It has the following syntax: void __stdcall EventProc (HANDLE hEvent);
These are some LiteCAD types of events:
1.LC_EVENT_SNAP
LiteCAD generates LC_EVENT_SNAP event when a user moves a mouse inside of the graphics window.In the event procedure your application can analyse the current cursor position and correct it, to make an effect of sticking cursor to specific points when it goes nearby (like magnet). In order to notify LiteCAD that cursor must be snapped to specific point, within the event procedure call lcEventReturnCode function with non-zero parameter, and set properties LC_PROP_EVENT_FLOAT1 and LC_PROP_EVENT_FLOAT2 with coordinates X, Y of the specific point.
//-----------------------------------------------
void LcAppPaint::OnSnap (HANDLE hEvent)
{int i;CGePoint Pnt[6];HANDLE hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );double X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );double Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );double Delta = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT3 );double Lef, Bot, Rig, Top;Pnt[0].Set(50,90);Pnt[1].Set(60,100);Pnt[2].Set(70,90);Pnt[3].Set(80,100);Pnt[4].Set(90,90);Pnt[5].Set(70,80);Lef = X - Delta;Bot = Y - Delta;Rig = X + Delta;Top = Y + Delta;for (i=0; i<6; i++){X = Pnt[i].x;Y = Pnt[i].y;if (Lef<X && X<Rig && Bot<Y && Y<Top){lcPropPutFloat( hEvent, LC_PROP_EVENT_FLOAT1, X );lcPropPutFloat( hEvent, LC_PROP_EVENT_FLOAT2, Y );lcEventReturnCode( 1 );return;}}
}
2.LC_EVENT_ENTPROP
LiteCAD generates LC_EVENT_ENTPROP event when a property of graphic entity has been changed.
Properties of “HANDLE” type use object identifier, for example,we have to catch a moment when text style of text entity was changed:
//-----------------------------------------------
void OnEntProp (HANDLE hEvent)
{HANDLE hDrw, hEnt, hStyle;int idProp, ival;WCHAR szBuf[256];hDrw = lcPropGetHandle( hEvent, LC_PROP_EVENT_DRW );hEnt = lcPropGetHandle( hEvent, LC_PROP_EVENT_ENTITY );idProp = lcPropGetInt( hEvent, LC_PROP_EVENT_INT1 );switch( idProp ){case LC_PROP_TEXT_STYLE:// text style of entity hEnt was changed ival = lcPropGetInt( hEvent, LC_PROP_EVENT_INT3 ); // previous text style IDival = lcPropGetInt( hEvent, LC_PROP_EVENT_INT4 ); // current text style ID// get text style handle by its IDhStyle = lcDrwGetObjectByID( hDrw, LC_OBJ_TEXTSTYLE, ival );if (hStyle){// get name of current text stylewcsncpy( szBuf, lcPropGetStr( hStyle, LC_PROP_TSTYLE_NAME ), 250 );}break;
... }
}//-----------------------------------------------
void CALLBACK EventProc (HANDLE hEvent)
{int EventType;EventType = lcPropGetInt( hEvent, LC_PROP_EVENT_TYPE );switch( EventType ){case LC_EVENT_ENTPROP: OnEntProp( hEvent ); break;...}
}
3.LC_EVENT_DRAWIMAGE
LiteCAD generates LC_EVENT_DRAWIMAGE event when required to display an image object created via the lcBlockAddImagePlace function.
Draw custom raster image (rendered by application)
...// register event procedurelcEventSetProc( LC_EVENT_DRAWIMAGE, DrawImageProc, 0, 0 );
...// create image object in a drawingHANDLE hImgRef;hImgRef = lcBlockAddImagePlace( hBlock, 105, 10,20,100,50, true );lcBlockUpdate( hBlock, false, hImgRef );lcWndRedraw( m_hLcWnd );
...// This function is called on LC_EVENT_DRAWIMAGE event
//-----------------------------------------------
void CALLBACK DrawImageProc (HANDLE hEvent)
{COkDib Dib;OK_DIBDRAWPRM Prm;double W, H, PixelSize;int idImage;HANDLE hLcWnd;if (Dib.Load( L"d:/Pictures/SomeImage.bmp" ) == false){return;}hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );idImage = lcPropGetInt( hEvent, LC_PROP_EVENT_INT6 ); // ID passed by lcBlockAddImagePlace()W = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 ); // image width (drawing's units)H = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 ); // image height (drawing's units)memset( &Prm, 0, sizeof(Prm) );Prm.hDC = (HDC)lcPropGetHandle( hEvent, LC_PROP_EVENT_HDC );Prm.ImgLeft = lcPropGetInt( hEvent, LC_PROP_EVENT_INT1 );Prm.ImgBottom = lcPropGetInt( hEvent, LC_PROP_EVENT_INT2 );PixelSize = lcPropGetFloat( hLcWnd, LC_PROP_WND_PIXELSIZE );Prm.ImgWidth = (UINT)(W/PixelSize + 0.5); // 0 for non-scalable imagePrm.ImgHeight = (UINT)(H/PixelSize + 0.5); // 0 for non-scalable image
// Prm.Align = 1; // alignment for non-scalable image, 0: center, 1: left-bottomPrm.bDevRectValid = true; // if TRUE then a device rectangle (below parameters) are validPrm.DevLeft = 0;Prm.DevTop = 0;Prm.DevRight = lcPropGetInt( hEvent, LC_PROP_EVENT_INT3 );Prm.DevBottom = lcPropGetInt( hEvent, LC_PROP_EVENT_INT4 );// the next function draws the image using WinAPI function StretchDIBitsDib.Draw( Prm );
}
4.lcCreateCommand
Creates a custom command object.This function can be called only within the LC_EVENT_ADDCMD event procedure. HANDLE lcCreateCommand (HANDLE hLcWnd,int Id,LPCWSTR szName); Parameters: hLcWnd(Handle to LiteCAD graphics window.);Id(Command identifier. Must be unique for any command. Use offset from the constant LC_CMD_CUSTOM, in order do not collide with LiteCAD inner commands.This identifier will be used to call custom command by the lcWndExeCommand function. );szName(Command name.). Return Value: Handle to the created command object.If the function fails, the return value is NULL. Code sample
八、Custom Commands
Register custom command events with the lcEventSetProc functions.
When LiteCAD fires the LC_EVENT_ADDCMD event, create your custom commands objects with the lcCreateCommand function.
Call your command with the lcWndExeCommand function.
During the command execution, LiteCAD will fire LC_EVENT_CCMD events
In order to finish the command, call lcCmdExit function fromevent procedure.