TomoVision_Tools: Lists

 

 

The Lists class enable you to draw a list of buttons in the interface. 

 

The flags that affect the Lists 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

 

TOOL_ICON_V_CENT

TOOL_ICON_TOP

TOOL_ICON_BOTTOM

 

// vertical position of the icon's graphic

 

TOOL_ICON_H_CENT

TOOL_ICON_LEFT

TOOL_ICON_RIGHT

 

// vertical position of the icon's graphic

 

BUTTON_LIGHT

// add a "light" on each buttons in the list

 

BUTTON_MULTICOLOR

// Enable the "lights" to be multicolor.  The color is function of the value of the "Light" variable for each button: 0=off, 1=green, 2=blue, 3=yellow, 4=red.

 

 

The variables that are specific to the Lists class are:

 

 

float          Cur_Value ;

// index of the current depressed button.

 

short          Spacing ;

// minimum vertical size of buttons in vertical list

 

short          cursor ;

// width (or height) of sliders

 

Buttons **Item ;

// list of buttons

          

           

 

The methods that are specific to the Lists are:

 

 

int          Read( void ) ;

// return the index of the button under the cursor.

 

void          Scroll( int val ) ;

// scroll the list

 

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

// Grow (or shrink) the "Item" list of buttons.

 

          

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

 

 

The tool_test_lists_ctrl.cpp file from the Lists demo

 

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

static          Lists          list_demo_1 ;

static          Lists          list_demo_2 ;

static          Lists          list_demo_3 ;

 

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

//

//          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          List_Dim_Big =           (short) Fct_Variable_Value( "$INTERFACE_LIST_DIM_BIG" ) ;

short          Title_Dim =           (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 + 2                    // title at top of tool

                         + 180                              // List 1 & 2

                         + Space_Dim                    // space between Lists

                         + List_Dim_Big                    // List 3

                         + Space_Dim ;                    // space at the bottom

 

          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 Boxs -------" ;

          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          i, 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          List_Dim_Big =              (short)  Fct_Variable_Value( "$INTERFACE_LIST_DIM_BIG" ) ;

short          Cursor_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_CURSOR_DIM" ) ;

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

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

 

          int nb_but = 10 ;

 

          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 ;

          }

 

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

          // --- Tool 1:

          //

          // Default FLAG value (=NULL)

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

          p_x = box_box.Pos_X + Space_Dim ;

          p_y = box_box.Pos_Y + Space_Dim ;

          d_x = box_box.Dim_X - 2*Space_Dim ;

          d_y = List_Dim_Big ;

 

          list_demo_1.Pos_X     = p_x ;

          list_demo_1.Pos_Y     = p_y ;

          list_demo_1.Dim_X     = d_x ;

          list_demo_1.Dim_Y     = d_y ;

          list_demo_1.border    = Border_Dim ;

          list_demo_1.cursor    = Cursor_Dim ;

          list_demo_1.Font_Name   = Tools_Font_Name ;

          list_demo_1.Font_Weight = Tools_Font_Weigth ;

          list_demo_1.Font_Scale  = Tools_Font_Scale ;

 

          // --- now create the buttons for this list ---

          list_demo_1.Grow( nb_but ) ;

          for ( i=0; i < nb_but; i++ )

              list_demo_1.Item[i]->Set_Name( "but %d", i+1 ) ;

 

          list_demo_1.Init( wnd ) ;

 

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

          // --- Tool 2

          //

          // vertical

          //

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

          p_y += d_y + Space_Dim ;

          d_x = (box_box.Dim_X - 3*Space_Dim) / 2 ;

          d_y = 180 ;

 

          list_demo_2.Flag      = OUTIL_VERTICAL ;

          list_demo_2.Name      = "Demo List 2" ;

          list_demo_2.Pos_X     = p_x ;

          list_demo_2.Pos_Y     = p_y ;

          list_demo_2.Dim_X     = d_x ;

          list_demo_2.Dim_Y     = d_y ;

          list_demo_2.border    = Border_Dim ;

          list_demo_2.cursor    = Cursor_Dim ;

          list_demo_2.Font_Name   = Tools_Font_Name ;

          list_demo_2.Font_Weight = Tools_Font_Weigth ;

          list_demo_2.Font_Scale  = Tools_Font_Scale ;

 

          // --- now create the buttons for this list ---

          list_demo_2.Grow( nb_but ) ;

          for ( i=0; i < nb_but; i++ )

              list_demo_2.Item[i]->Set_Name( "but %d", i+1 ) ;

 

          list_demo_2.Init( wnd ) ;

 

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

          // --- Tool 3

          //

          // vertical, with lights on the buttons

          //

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

          p_x += d_x + Space_Dim ;

          

          list_demo_3.Flag      = OUTIL_VERTICAL | BUTTON_LIGHT ;

          list_demo_3.Name      = "Demo List 3" ;

          list_demo_3.Pos_X     = p_x ;

          list_demo_3.Pos_Y     = p_y ;

          list_demo_3.Dim_X     = d_x ;

          list_demo_3.Dim_Y     = d_y ;

          list_demo_3.border    = Border_Dim ;

          list_demo_3.cursor    = Cursor_Dim ;

          list_demo_3.Font_Name   = Tools_Font_Name ;

          list_demo_3.Font_Weight = Tools_Font_Weigth ;

          list_demo_3.Font_Scale  = Tools_Font_Scale ;

 

          // --- now create the buttons for this list ---

          list_demo_3.Grow( nb_but ) ;

          for ( i=0; i < nb_but; i++ )

              list_demo_3.Item[i]->Set_Name( "but %d", i+1 ) ;

 

          list_demo_3.Init( wnd ) ;

 

          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() ;

 

          // --- We draw each of our 3 tools ---

          list_demo_1.Draw() ;

          list_demo_2.Draw() ;

          list_demo_3.Draw() ;

 

          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 invisible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          list_demo_1.Deselect() ;

          list_demo_2.Deselect() ;

          list_demo_3.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 want the key press, not the key release ---

          if ( ! up_down ) {

              return( 0 ) ;

          }

 

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

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

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

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

          // is inside the box.

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

          if ( list_demo_1.Select( up_down ) ) {

              // --- which button is pressed ? ---

              int ret = list_demo_1.Read() ;

              list_demo_1.Cur_Value = ret ;

              list_demo_1.Adjust() ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in tool #1, button %d", ret ) ;

              return( 1 ) ;

          }

 

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

          if ( list_demo_2.Select( up_down ) ) {

              // --- which button is pressed ? ---

              int ret = list_demo_2.Read() ;

              list_demo_2.Cur_Value = ret ;

              list_demo_2.Adjust() ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in tool #2, button %d", ret ) ;

 

              // --- here, for the fun of it, toggle the light of

              // the matching button in list 3 ---

              list_demo_3.Item[ret]->Light = ! list_demo_3.Item[ret]->Light ;

              list_demo_3.Draw() ;

 

              return( 1 ) ;

          }

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

          if ( list_demo_3.Select( up_down ) ) {

              // --- which button is pressed ? ---

              int ret = list_demo_3.Read() ;

              list_demo_3.Cur_Value = ret ;

              list_demo_3.Adjust() ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in tool #3, button %d", ret ) ;

 

              // --- here, for the fun of it, toggle the "enabled" of

              // the matching button in list 3 ---

              list_demo_2.Item[ret]->Flag ^= OUTIL_OUT ;

              list_demo_2.Draw() ;

 

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

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

//

//          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 tool will get the "select" color

          // if the cursor is over it and that all graphic

          // will be updated.

          //

          // Note: It is important for tools with sliders,

          //       since this is where the slider action are

          //       performed.

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

          list_demo_1.Select( up_down ) ;

          list_demo_2.Select( up_down ) ;

          list_demo_3.Select( up_down ) ;

 

          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 )

{

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

          if ( list_demo_1.Select( KEY_QUERY ) ) {

              list_demo_1.Scroll( -count ) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Scrool tool #1" ) ;

              return( 1 ) ;

          }

 

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

          if ( list_demo_2.Select( KEY_QUERY ) ) {

              list_demo_2.Scroll( -count ) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Scrool tool #2" ) ;

              return( 1 ) ;

          }

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

          if ( list_demo_3.Select( KEY_QUERY ) ) {

              list_demo_3.Scroll( -count ) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Scrool tool #3" ) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

...