|
// --- Callback ID assign at startup with Get_Callback_ID() ---
static unsigned short Local_Callback_ID ;
// ----------------------------------------------------------------------------
//
// Function: Get_Callback_ID
//
// Parameters: id (unsigned short) // callback id assigned to the DLL
// Returns: (void)
//
// SliceOmatic will use this function at start-up to assign a unique
// ID number to your DLL.
//
// ----------------------------------------------------------------------------
extern "C" __declspec(dllexport) unsigned short Get_Callback_ID( unsigned short *id )
{
Local_Callback_ID = id[CALLBACK_DRAW_OPENGL] ;
return( 1 << CALLBACK_DRAW_OPENGL ) ;
}
// ----------------------------------------------------------------------------
//
// Function: Measure_Callback_Register
//
// Parameters: (void)
// Returns: (int) 0 for errors
//
// This function will assign the "Measure_Draw_Tool" fct to the Fct_Draw_OpenGL
// of each frames in the database.
//
// This function is called when the mode is activated and when the database
// is modified while the mode is activated
//
// ----------------------------------------------------------------------------
int Measure_Callback_Register( void )
{
Measure_Callback_Reset() ;
// --- for all frames ---
Iterator_Init( ITERATOR_2, "Measure_Callback_Register" ) ;
while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME ) ) {
frame->Fct_Draw_OpenGL[Local_Callback_ID] = Measure_Draw_Tool ;
}
Iterator_End( ITERATOR_2 ) ;
return( 1 ) ;
}
// ----------------------------------------------------------------------------
//
// Function: Measure_Callback_Reset
//
// Parameters: (void)
// Returns: (int) 0 for errors
//
// This function will assign reset the pointers of the Fct_Draw_OpenGL
// of each frames in the database.
//
// This function is called when the mode is exited
//
// ----------------------------------------------------------------------------
int Measure_Callback_Reset( void )
{
// --- for all frames ---
Iterator_Init( ITERATOR_2, "Measure_Callback_Reset" ) ;
while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME ) ) {
frame->Fct_Draw_OpenGL[Local_Callback_ID] = NULL ;
}
Iterator_End( ITERATOR_2 ) ;
return( 1 ) ;
}
// ============================================================================
// ============================================================================
// ============================================================================
// ============================================================================
// ============================================================================
// ----------------------------------------------------------------------------
//
// Measure_Draw_Tool
//
// draw the 2D measurement tools
//
// Param: (int) cur_window
// (SliceO_Image *) ima
//
// Return: (int)
//
// ----------------------------------------------------------------------------
int Measure_Draw_Tool( SliceO_Class *pt, UInt64 flag, SliceO_Window *window )
{
// --- only draw lines to windows in Measure mode ---
if ( window->Module_Get() != Ctrl_Query() )
return( 1 ) ;
SliceO_Frame *frame = (SliceO_Frame *) pt ;
// --- critical reagion: make sure we are not interrupted ---
Access_Init( "Measure_Draw_Tool" ) ;
if ( ! Database_Viewport( window, frame ) )
return( 1 ) ;
// --- Make sure we stay in the window ---
glEnable( GL_SCISSOR_TEST ) ;
// --- look, among all the 2D tools, if any should be drawn for this frame ---
for ( int i=Measure_Active_Nb-1; i >= 0; i-- ) {
// --- wrong frame ? ---
if ( (! (Measure_Active_List[i]->m_mode & MEASURE_FLAG_GLOBAL))
&& Measure_Active_List[i]->frame != frame )
continue ;
// --- wrong group ? ---
if ( (Measure_Active_List[i]->m_mode & MEASURE_FLAG_GLOBAL)
&& Measure_Active_List[i]->frame->Parent_Get_Pt() != frame->Parent_Get_Pt() )
continue ;
Measure_Active_List[i]->Draw( window, frame ) ;
}
glDisable( GL_SCISSOR_TEST ) ;
// --- release the critical region ---
Access_End( "Measure_Draw_Tool" ) ;
return( 1 ) ;
}
|