TXApplication

TXApplication is a wrapper for a graphical crystallographic application and has been created mainly to illustrate the functionality of the library. So when the object is created, it initialises global Log variable, creates  TAtomInfo, GlRender, TXFile, TIns, TCif objects and initialises TGlMouseListner object. An example of binding of a TXApplication object to GUI is shown below:

Constructor

XApp = new TXApplication(ParamStr(0).c_str());  // pass the directory from which the program has started as a parameter

When main window is created

 XApp->InitHDC(GetDC(Handle));  // initialise OpenGl using a device context; Handle - is a HWND pointer for main window
XApp->GlRender->Resize(ClientWidth, ClientHeight);  // set proper viewport
// if necessary a perspective view can be used: XApp->GlRender->Perspective(true);  XApp->GlRender->PerspectiveAngle(20);
XApp->GlRender->Initialise();  // initialisation of OpenGl

On paint

 XApp->GlRender->Draw();  // draws current model to the screen

To rebuild the content of the model, when for example a file is loaded

XApp->XFile->LoadFromFile(dlgOpen->FileName.c_str());
XApp->InitScene();  // initialises drawing scene

On resize

 XApp->GlRender->Resize(ClientWidth, ClientHeight);

To bind mouse

 XApp->GlMouse->MouseDown(X, Y, Fl, Btn);
 XApp->GlMouse->MouseUp(X, Y, Fl, Btn);
 XApp->GlMouse->MouseMove(X, Y, Fl) );  // the function returns true if the event is handled and false otherwise

All these three handlers must be called to handle mouse events properly. The change handlers of mouse events which happen when mouse pointer is moving, use SetHandler method of the TGlMouseListner. The Btn parameter should contain an appropriate information. For example when VCL is used, the following code can be used:

void __fastcall TdlgMain::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
    short Fl = 0, Btn = 0;
    if( Shift.Contains(ssShift) )  Fl |= sssShift;
    if( Shift.Contains(ssCtrl) )   Fl |= sssCtrl;
    if( Shift.Contains(ssAlt) )    Fl |= sssAlt;
    if( Button == mbRight )      Btn = smbRight;
    if( Button == mbLeft )       Btn = smbLeft;
    if( Button == mbMiddle )  Btn = smbMiddle;
    XApp->GlMouse->MouseDown(X, Y, Fl, Btn);
};

To select an object on screen at a specific position

TGDrawObject *G = XApp->GlRender->Select(X, Y);
use  GetType() and ClassName() methods of the TGDrawObject to identify the object
 

© Oleg V. Dolomanov, 2004
Last Updated 2004.05.19