|
// ----------------------------------------------------------------------------
//
// Interface_Click()
//
// param: window (SliceO_Window *) The curent window
// up_down (int) state of the mouse buttons
// mouse inf (Point_2D *) mouse pos (in "Inf" coord)
//
// return: (int) 1 if this click has been used
//
// ----------------------------------------------------------------------------
int SliceO_Class::Interface_Click( SliceO_Window *window, int up_down, Point_2D *mouse_inf )
{
VALIDITY_TEST_CLASS( this, "SliceO_Class::Interface_Click" ) ;
// --- if this element is not visible get out ---
if ( ! this->Flag_Get_Bit( CLASS_MODE_THIS, window, CLASS_FLAG_VISIBLE ) )
return( 0 ) ;
// --- by default, there's 2 gadgets we use, the +/- expand icon
// and the selection icon. in some modes we also have a slider ---
int a_x, a_y ;
// ====================================================================
// === the +/- expand icon (completely at the top left of the class)===
// ====================================================================
a_x = (int) m_inside[window->Id_Get()].min_x - 2 ;
a_y = (int) m_inside[window->Id_Get()].min_y - 2 ;
Region_2D region_expand( COORD_INF, a_x, a_y, a_x+18, a_y+18 ) ;
if ( region_expand.Inside( mouse_inf ) ) {
// --- we have a click in the expand. either colaps or expand the class ---
UInt64 flag = Flag_Get_Bit( CLASS_MODE_THIS, window, CLASS_MASK_DISPLAY ) ;
switch( flag ) {
case CLASS_FLAG_EXPAND :
if ( Child_Get_Nb() <= 1 )
// --- no child: toggle expand/collapse ---
Flag_Set_Off( CLASS_MODE_THIS, window, CLASS_FLAG_EXPAND ) ;
else {
// --- child: loop: expand, one, loop, collapse ---
Flag_Set_Off( CLASS_MODE_THIS, window, CLASS_FLAG_EXPAND ) ;
Flag_Set_On( CLASS_MODE_THIS, window, CLASS_FLAG_ONE ) ;
}
break ;
case CLASS_FLAG_ONE :
// --- child: loop: expand, one, loop, collapse ---
Flag_Set_Off( CLASS_MODE_THIS, window, CLASS_FLAG_ONE ) ;
Flag_Set_On( CLASS_MODE_THIS, window, CLASS_FLAG_LOOP ) ;
Fct_Loop_Start( window, this ) ;
break ;
case CLASS_FLAG_LOOP :
// --- child: loop: expand, one, loop, collapse ---
Flag_Set_Off( CLASS_MODE_THIS, window, CLASS_FLAG_LOOP ) ;
Fct_Loop_Stop( window, this ) ;
break ;
default :
Flag_Set_On( CLASS_MODE_THIS, window, CLASS_FLAG_EXPAND ) ;
break ;
}
// --- we need to "resize" the window's content ---
Fct_Update( UPDATE_WINDOW_2D, window ) ;
// --- we need to redraw the windows and frames ---
Fct_Redraw( REDRAW_WINDOW_AND_UP, window ) ;
// --- we used this key ---
return( 1 ) ;
}
// ====================================================================
// === the selection icon (on the right of the +/- expand) ===
// ====================================================================
a_x += MODE_ALL_HORIZ_SPACING+1 ;
a_y = (int) m_inside[window->Id_Get()].min_y ;
Region_2D region_icon( COORD_INF, a_x, a_y, a_x+18, a_y+14 ) ;
if ( region_icon.Inside( mouse_inf ) ) {
// --- update the selection flags ---
Region_2D select_inf( *mouse_inf, *mouse_inf ) ;
Interface_Select( window, &select_inf ) ;
// --- we used this key ---
return( 1 ) ;
}
// ====================================================================
// === The slider for display one and loop ===
// ====================================================================
a_x += 24 ;
a_y = (int) m_inside[window->Id_Get()].min_y ;
Region_2D region_slider( COORD_INF, a_x, a_y, a_x+MODE_ALL_SLIDER_DIM_X, a_y+MODE_ALL_SLIDER_DIM_Y ) ;
switch( Flag_Get_Bit( CLASS_MODE_THIS, window, CLASS_MASK_DISPLAY ) ) {
case CLASS_FLAG_ONE :
// --- for display one, the slice selection slider on the right of the icon ---
if ( region_slider.Inside( mouse_inf ) ) {
float fact = (float) MODE_ALL_SLIDER_DIM_X / (float) Child_Get_Nb() ;
int val = (int) (*mouse_inf)[0] - a_x ;
val -= (int) (fact/2) ;
val = (int) ((float) val / fact) ;
val = CLIP( 0, val, Child_Get_Nb()-1 ) ;
Fct_Change_Child( window, Child_Get_Pt( val ) ) ;
return( 1 ) ;
}
break ;
case CLASS_FLAG_LOOP :
// --- for display one, the slice selection slider on the right of the icon ---
if ( region_slider.Inside( mouse_inf ) ) {
float fact = (float) MODE_ALL_SLIDER_DIM_X / (float) 30 ;
int val = (int) (*mouse_inf)[0] - a_x ;
val -= (int) (fact/2) ;
val = (int) ((float) val / fact) ;
val = CLIP( 0, val, 29 ) ;
m_fps[window->Id_Get()] = (unsigned short) val + 1 ;
// --- set the timer ---
Fct_Loop_Start( window, this ) ;
// -- we need to redraw this level ---
Fct_Redraw( REDRAW_DB_OPENGL_AND_UP, window, this ) ;
return( 1 ) ;
}
break ;
}
// --- does one of the children use this event ? ---
for ( int i=0; i < m_child_nb; i++ )
if ( m_child_pt[i]->Interface_Click( window, up_down, mouse_inf ) )
return( 1 ) ;
// --- we did not use this click ---
return( 0 ) ;
}
|