TomoVision_Tools: Tabs

 

 

The Tabs class enable you to draw ... in the interface. 

 

The flags that affect the tabs are:

 

 

OUTIL_INVISIBLE

// no graphics

 

OUTIL_DISABLE

// no select (but graphics OK)

 

OUTIL_VERTICAL

// the name is drawn vertically

 

OUTIL_EMPTY

// no fill

 

OUTIL_OUTLINE

// border as blue outline

 

OUTIL_NO_3D

// flat fill

 

OUTIL_NO_BORDER

 

// do not draw the outside box

 

NAME_V_CENT

NAME_TOP

NAME_BOTTOM

 

// vertical position of the name in the tool

 

NAME_H_CENT

NAME_LEFT

NAME_RIGHT

 

// Horizontal position of the name in the tool

 

 

The Tabs that are specific to the valuators class are:

 

 

float          Cur_Value ;

// current value of the selected tab

 

short          Page_Y ;

// height of the pages (including the tabs)

 

TabItems          **Item ;

// list of pages associated with the tabs.

          

           

 

The methods that are specific to the Tabs are:

 

 

int          Grow( int size, int flag=0 ) ;

// Adjust the number of tabs

 

int          Read( void ) ;

// return the value of the tab under the cursor or -1

 

void          Page( int dim_y=0 ) ;

// Clear the content of the page

 

          

An example of the usage of the Tabs class is given in the Samples\Demo Tools\Tabs demo directory.  the resulting interface for this demo look like this:

 

 

 

The tool_test_tabs_ctrl.cpp file from the Tabs demo

 

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

static          Tabs          tab ;

static          char          *list_tab[] = { "Tab 1", "Tab 2", "Tab 3" } ;

 

static          short          Page_Pos_X ;

static          short          Page_Pos_Y ;

static          short          Page_Dim_X ;

static          short          Page_Dim_Y ;

 

// --- For Tab 1 option ---

void          Tab_1_Init( void ) ;

int          Tab_1_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color ) ;

void          Tab_1_Draw(   HWND wnd ) ;

int          Tab_1_Click(  HWND wnd, int up_down, short x, short y ) ;

void          Tab_1_Motion( HWND wnd, int up_down, short x, short y ) ;

void          Tab_1_Scroll( HWND wnd, int count,   short x, short y ) ;

int          Tab_1_Key(    HWND wnd, int key,     short x, short y ) ;

 

// --- For Tab 2 option ---

void          Tab_2_Init( void ) ;

int          Tab_2_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color ) ;

void          Tab_2_Draw(   HWND wnd ) ;

int          Tab_2_Click(  HWND wnd, int up_down, short x, short y ) ;

void          Tab_2_Motion( HWND wnd, int up_down, short x, short y ) ;

void          Tab_2_Scroll( HWND wnd, int count,   short x, short y ) ;

int          Tab_2_Key(    HWND wnd, int key,     short x, short y ) ;

 

// --- For Tab 3 option ---

void          Tab_3_Init( void ) ;

int          Tab_3_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color ) ;

void          Tab_3_Draw(   HWND wnd ) ;

int          Tab_3_Click(  HWND wnd, int up_down, short x, short y ) ;

void          Tab_3_Motion( HWND wnd, int up_down, short x, short y ) ;

void          Tab_3_Scroll( HWND wnd, int count,   short x, short y ) ;

int          Tab_3_Key(    HWND wnd, int key,     short x, short y ) ;

 

// --- Pointers to the interface functions ---

static          void (*Func_Init[])(void) = { Tab_1_Init,

                                              Tab_2_Init,

                                              Tab_3_Init } ;

static          void (*Func_Draw[])(HWND wnd) = { Tab_1_Draw,

                                                    Tab_2_Draw,

                                                    Tab_3_Draw } ;

static          int (*Func_Resize[])(HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color )

                                                                  = { Tab_1_Resize,

                                                                        Tab_2_Resize,

                                                                        Tab_3_Resize } ;

static          int (*Func_Click[])(HWND wnd, int click, short x, short y) = { Tab_1_Click,

                                                                                       Tab_2_Click,

                                                                                       Tab_3_Click } ;

static          int (*Func_Key[])(HWND wnd, int key, short x, short y) =   { Tab_1_Key,

                                                                                     Tab_2_Key,

                                                                                     Tab_3_Key } ;

static          void (*Func_Scroll[])(HWND wnd, int count,   short x, short y) =   { Tab_1_Scroll,

                                                                                               Tab_2_Scroll,

                                                                                               Tab_3_Scroll } ;

static          void (*Func_Motion[])(HWND wnd, int click, short x, short y) = { Tab_1_Motion,

                                                                                           Tab_2_Motion,

                                                                                           Tab_3_Motion } ;

 

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Register

//

//          Parameters:          mode (unsigned short *)          Used only for Tools.

//                                                            If this pointer is not NULL,

//                                                            use it to specify to what tool

//                                                            window we belong.

//                                                            SLICEO_TOOL_2D, _BASIC,_3D...

//                                                  

//          Returns:          (int)                    Vertical size of your menu (in pixels)

//

//          This is called once at the start of the program.  We need it to

//          know you are using your own func. and how much space to reserve

//          in the menu interface.  You must also change the "mode" flag to

//          reflect in what tool window you want to appear.

//

//          Note: If you do not need a graphic interface, just comment out

//                the "Ctrl_Register" function.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Register( unsigned short *mode )

{

// --------------------------------------------------------------------

// In the "Config" menu, the user can change the interface's size.

// This action change a number of variables that are used to compute

// the size of the tool in the intearface.  We now load a few of these

// variables and use them to compute the dimension of our interface box.

// --------------------------------------------------------------------

short          Title_Dim_Big =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_BIG" ) ;

short          Space_Dim =           (short) Fct_Variable_Value( "$INTERFACE_SPACE_DIM" ) ;

 

          // --- compute the height of the interface ---

          short height = Title_Dim_Big + 2                    // title at top of tool

                         + Space_Dim + Title_Dim_Big          // tabs

                         + 200                                                  // content of the Tab pages

                         + Space_Dim ;

 

          return( height ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Create

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Create( HWND wnd, int width, int height )

{

char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

short          Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          box_box.Name = "------- Tool Test Tabs -------" ;

          box_box.Flag      = OUTIL_DISABLE | OUTIL_NO_3D ;

          box_box.Pos_X     = 1 ;

          box_box.Pos_Y     = 1 ;

          box_box.Dim_X     = width - 2 ;

          box_box.Dim_Y     = height - 2 ;

          box_box.border    = Border_Dim;

          box_box.color.set( WINDOW_COLOR_TOOL_R,

                                 WINDOW_COLOR_TOOL_G,

                                 WINDOW_COLOR_TOOL_B ) ;

          box_box.Font_Name   = Title_Font_Name ;

          box_box.Font_Scale  = Title_Font_Scale ;

          box_box.Font_Weight = Title_Font_Weight ;

          box_box.Init( wnd ) ; 

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Resize

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Resize( HWND wnd, int width, int height )

{

short          p_x, p_y, d_x, d_y ;

 

// -----------------------------------------------------------------------

// In the "Config" menu, the user can change the interface's size.

// This action change a number of variables that are used to compute

// the size of the tool in the intearface.  We now load a few of these

// variables and use them to compute the dimension of our interface tools.

// -----------------------------------------------------------------------

char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

char   *Tools_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TOOL_FONT_NAME" ) ;

char   *Tools_Font_Weigth = (char *) Fct_Variable_Value( "$INTERFACE_TOOL_FONT_WEIGHT" ) ;

short          Tools_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TOOL_FONT_SCALE" ) ;

 

short          Space_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_SPACE_DIM" ) ;

short          Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

short          Title_Dim_Big =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_BIG" ) ;

 

 

          if ( wnd ) {

              box_box.Pos_X     = 1 ;

              box_box.Pos_Y     = 1 ;

              box_box.Dim_X     = width - 2 ;

              box_box.Dim_Y     = height - 2 ;

              box_box.border    = Border_Dim;

              box_box.Font_Name   = Title_Font_Name ;

              box_box.Font_Scale  = Title_Font_Scale ;

              box_box.Font_Weight = Title_Font_Weight ;

              box_box.Init( wnd ) ; 

          } else {

              wnd = box_box.wnd ;

          }

 

          // ===========================================================================

          // --- Tabs:

          //

          // ===========================================================================

          p_x = box_box.Pos_X + Space_Dim ;

          p_y = box_box.Pos_Y + box_box.Dim_Y - 2*Title_Dim_Big ;

          d_x = box_box.Dim_X - 2*Space_Dim ;

          d_y = Title_Dim_Big ;

 

              tab.Flag  = NULL ;

              tab.Pos_X = p_x ;

              tab.Pos_Y = p_y ;

              tab.Dim_X = d_x ;

              tab.Dim_Y = d_y ;

 

              // --- vertical size of the pages (including tabs) ---

              tab.Page_Y = box_box.Dim_Y - Title_Dim_Big - Space_Dim ;

 

              // --- initialize the tabs the first time only ---

              if ( ! tab.Item ) {

 

                    int nb_item = (sizeof list_tab) / sizeof(char *) ;

 

                    tab.Grow( nb_item ) ;

 

                    for ( int i=0; i < nb_item; i++ ) {

                        tab.Item[i]->Flag = NULL ;

                        tab.Item[i]->Set_Name( list_tab[i] ) ;

                    }

 

                    // --- assign a different color for each tab ---

                    tab.Item[0]->color.set( 150, 150, 170 ) ;

                    tab.Item[1]->color.set( 170, 170, 150 ) ;

                    tab.Item[2]->color.set( 150, 170, 150 ) ;

              }

 

              tab.Init( wnd ) ;

 

              // --- call resize for the content of this tab page ---

              Page_Pos_X = box_box.Pos_X + 3*Space_Dim ;

              Page_Pos_Y = box_box.Pos_Y + 3*Space_Dim ;

              Page_Dim_X = box_box.Dim_X - 6*Space_Dim ;

              Page_Dim_Y = box_box.Dim_Y - 2*Title_Dim_Big - 6*Space_Dim ;

 

              (*(Func_Resize[tab.Cur_Value]))( wnd,

                                                       Page_Pos_X, Page_Pos_Y, Page_Dim_X, Page_Dim_Y,

                                                       tab.Item[tab.Cur_Value]->color ) ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Draw

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time your menu has to be re-drawn

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Draw( HWND wnd )

{

          // --- if the window if off or invible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          box_box.Draw() ;

 

          // --- draw the tab container ---

          tab.Draw() ;

          tab.Page() ;

          (*(Func_Draw[tab.Cur_Value]))( wnd ) ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Leave

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor leave your menu

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Leave( void )

{

          // --- if the window if off or invible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          tab.Deselect() ;

 

          return( 1 ) ;

}

 

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Click

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the state

//          of the mouse buttons has changed.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Click( HWND wnd, int up_down, short x, short y )

{

 

          // --- We only refresh the image when we release the button ---

          if ( ! up_down ) {

              return( 0 ) ;

          }

 

          // ------------------------------------------------

          // We received a mouse click, now we try to find in

          // which box the click was.  For this we use the

          // "select" method.  If will tell us if the mouse

          // is inside the box.

          // ------------------------------------------------

          if ( tab.Select( up_down ) ) {

 

              // --- did we click on a new tab ? ---

              int i = tab.Read() ;

              if ( i >= 0 ) {

 

                    // --- change the current tab ---

                    tab.Cur_Value = i ;

                    tab.Adjust() ;

 

                    // --- clear the page with the current color ---

                    tab.Page() ;

 

                    // --- resize the content of this tab page ---

                    (*(Func_Resize[tab.Cur_Value]))( wnd,

                                                       Page_Pos_X, Page_Pos_Y, Page_Dim_X, Page_Dim_Y,

                                                       tab.Item[tab.Cur_Value]->color ) ;

                    (*(Func_Init[tab.Cur_Value]))() ;

              }

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Key

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              key (int)          code of the activated key

//                              x, y (int)          current cursor position

//          Returns:          (int)                    1 if key is used

//

//          This is called each time the cursor is inside your menu and a keyboard

//          key has been pressed.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Key( HWND wnd, int key, short x, short y )

{

          // --- Depending on the current tab, call the appropriate func ---

          return( (*(Func_Key[tab.Cur_Value]))( wnd, key, x, y ) ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Motion

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the cursor

//          has moved.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Motion( HWND wnd, int up_down, short x, short y )

{

          // ------------------------------------------------

          // The mouse has moved.  By calling "select" we

          // insure that the box will get the "select" color

          // if the cursor is over it.

          // ------------------------------------------------

          tab.Select( KEY_QUERY ) ;

 

          // --- Depending on the current tab, call the appropriate func ---

          (*(Func_Motion[tab.Cur_Value]))( wnd, up_down, x, y ) ;

 

          return( 0 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Scroll

//

//          Parameters:          count (int)          number of mouse wheel cliks

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the mouse

//          wheel has been activated.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Scroll( HWND wnd, int count, short x, short y )

{

 

          // --- Depending on the current tab, call the appropriate func ---

          (*(Func_Scroll[tab.Cur_Value]))( wnd, count, x, y ) ;

 

          return( 0 ) ;

}

 

...

 

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

 

void          Tab_1_Init( void )

{

}

 

int          Tab_1_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color )

{

          return( 1 ) ;

}

 

void          Tab_1_Draw(   HWND wnd )

{

}

 

int          Tab_1_Click(  HWND wnd, int up_down, short x, short y )

{

          return( 1 ) ;

}

 

void          Tab_1_Motion( HWND wnd, int up_down, short x, short y )

{

}

 

void          Tab_1_Scroll( HWND wnd, int count,   short x, short y )

{

}

 

int          Tab_1_Key(    HWND wnd, int key,     short x, short y )

{

          return( 1 ) ;

}

 

// ============================================================================

 

void          Tab_2_Init( void )

{

}

 

int          Tab_2_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color )

{

          return( 1 ) ;

}

 

void          Tab_2_Draw(   HWND wnd )

{

}

 

int          Tab_2_Click(  HWND wnd, int up_down, short x, short y )

{

          return( 1 ) ;

}

 

void          Tab_2_Motion( HWND wnd, int up_down, short x, short y )

{

}

 

void          Tab_2_Scroll( HWND wnd, int count,   short x, short y )

{

}

 

int          Tab_2_Key(    HWND wnd, int key,     short x, short y )

{

          return( 1 ) ;

}

 

// ============================================================================

 

void          Tab_3_Init( void )

{

}

 

int          Tab_3_Resize( HWND wnd, short p_x, short p_y, short d_x, short d_y, Colors color )

{

          return( 1 ) ;

}

 

void          Tab_3_Draw(   HWND wnd )

{

}

 

int          Tab_3_Click(  HWND wnd, int up_down, short x, short y )

{

          return( 1 ) ;

}

 

void          Tab_3_Motion( HWND wnd, int up_down, short x, short y )

{

}

 

void          Tab_3_Scroll( HWND wnd, int count,   short x, short y )

{

}

 

int          Tab_3_Key(    HWND wnd, int key,     short x, short y )

{

          return( 1 ) ;

}