TomoVision_Tools: Selects

 

 

The Selects class enable you to draw a selection tool in the interface. This tool let you select one value out of a pre-defined list.  You can scroll through that list with arrow buttons.

 

The flags that affect the Selects 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 variables that are specific to the Selects class are:

 

 

short          Cur_Value ;

// current value of the selection

 

short          Arrow_Size ;

// Limit the size of the tool's arrows

 

short          Select_Size ;

// Limit the horizontal size of the selection box within the tool

 

Buttons **Item ;

// List of buttons. Only one of these is displayed at a time.

          

           

 

The methods that are specific to the Selects are:

 

 

int          Read( void ) ;

// return the index of the current selection.

 

int          Scroll( int val ) ;

//

 

int          Grow( int size ) ;

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

 

          

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

 

 

The tool_test_selects_ctrl.cpp file from the Selects demo

 

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

static          Buttons          but_demo_1 ;

static          Buttons          but_demo_2 ;

static          Buttons          but_demo_3 ;

 

 

static          Selects          sel_demo_1 ;

static          Selects          sel_demo_2 ;

static          Selects          sel_demo_3 ;

static          Selects          sel_number[4] ;

 

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

//

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

short          Title_Dim_Sml =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_SML" ) ;

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

                         + 70                                  // Tool 4 to 7

                         + Space_Dim                        // space between box1 and box 2

                         + Button_Dim_Big + Space_Dim   // Tool 3

                         + Space_Dim                        // space between box1 and box 2

                         + Button_Dim_Big + Space_Dim   // Tool 2

                         + Space_Dim                        // space between box2 and box 3

                         + Button_Dim_Big + Space_Dim + Title_Dim_Sml // Tool 1

                         + 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 Selectors -------" ;

          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, k, 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          Button_Dim_Big =    (short)  Fct_Variable_Value( "$INTERFACE_BUTTON_DIM_BIG" ) ;

short          Title_Dim_Sml =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_SML" ) ;

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), text at the top

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

          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 = Button_Dim_Big + Space_Dim + Title_Dim_Sml ;

 

          sel_demo_3.Flag      = NAME_H_CENT | NAME_TOP ;

          sel_demo_1.Name      = "Demo Selector 1" ;

          sel_demo_1.Pos_X     = p_x ;

          sel_demo_1.Pos_Y     = p_y ;

          sel_demo_1.Dim_X     = d_x ;

          sel_demo_1.Dim_Y     = d_y ;

          sel_demo_1.Arrow_Size = Button_Dim_Big - Space_Dim - 2 ;

          sel_demo_1.border    = Border_Dim ;

          sel_demo_1.Font_Name   = Tools_Font_Name ;

          sel_demo_1.Font_Weight = Tools_Font_Weigth ;

          sel_demo_1.Font_Scale  = Tools_Font_Scale ;

 

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

          sel_demo_1.Grow( nb_but ) ;

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

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

 

          sel_demo_1.Init( wnd ) ;

 

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

          // --- Tool 2

          //

          // text on the left

          //

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

          p_y += d_y + Space_Dim ;

          d_y = Button_Dim_Big + Space_Dim ;

 

          sel_demo_2.Flag      = NAME_V_CENT | NAME_LEFT ;

          sel_demo_2.Name      = "Demo Selector 2" ;

          sel_demo_2.Pos_X     = p_x ;

          sel_demo_2.Pos_Y     = p_y ;

          sel_demo_2.Dim_X     = d_x ;

          sel_demo_2.Dim_Y     = d_y ;

          sel_demo_2.Arrow_Size  = Button_Dim_Big - Space_Dim - 2 ;

          sel_demo_2.border    = Border_Dim ;

          sel_demo_2.Font_Name   = Tools_Font_Name ;

          sel_demo_2.Font_Weight = Tools_Font_Weigth ;

          sel_demo_2.Font_Scale  = Tools_Font_Scale ;

 

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

          sel_demo_2.Grow( nb_but ) ;

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

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

 

          sel_demo_2.Init( wnd ) ;

 

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

          // --- Tool 3

          //

          // text on the left, limit select size

          //

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

          p_y += d_y + Space_Dim ;

          d_y = Button_Dim_Big + Space_Dim ;

 

          sel_demo_3.Flag      = NAME_V_CENT | NAME_LEFT ;

          sel_demo_3.Name      = "Demo Selector 3" ;

          sel_demo_3.Pos_X     = p_x ;

          sel_demo_3.Pos_Y     = p_y ;

          sel_demo_3.Dim_X     = d_x ;

          sel_demo_3.Dim_Y     = d_y ;

          sel_demo_3.Arrow_Size = Button_Dim_Big - Space_Dim - 2 ;

          sel_demo_3.Select_Size = 100 ;

          sel_demo_3.border    = Border_Dim ;

          sel_demo_3.Font_Name   = Tools_Font_Name ;

          sel_demo_3.Font_Weight = Tools_Font_Weigth ;

          sel_demo_3.Font_Scale  = Tools_Font_Scale ;

 

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

          sel_demo_3.Grow( nb_but ) ;

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

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

 

          sel_demo_3.Init( wnd ) ;

 

 

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

          // --- Tool 4 to 7

          //

          // Vertical

          //

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

          p_x = box_box.Pos_X + Space_Dim ;

          p_y += d_y + Space_Dim ;

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

          d_y = 70 ;

 

          for ( k=0; k < 4; k++ ) {

 

              sel_number[k].Flag      = OUTIL_VERTICAL| NAME_V_CENT| NAME_LEFT ;

              sel_number[k].Pos_X     = p_x ;

              sel_number[k].Pos_Y     = p_y ;

              sel_number[k].Dim_X     = d_x ;

              sel_number[k].Dim_Y     = d_y ;

              sel_number[k].Arrow_Size = Button_Dim_Big - Space_Dim - 2 ;

              sel_number[k].border    = Border_Dim ;

              sel_number[k].Font_Name   = Tools_Font_Name ;

              sel_number[k].Font_Weight = Tools_Font_Weigth ;

              sel_number[k].Font_Scale  = Tools_Font_Scale ;

 

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

              sel_number[k].Grow( nb_but ) ;

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

                    sel_number[k].Item[i]->Set_Name( "%d", i ) ;

 

              // --- increment position for next tool ---

              p_x += d_x + Space_Dim ;

              // --- only fisrt tool has a label ---

              if ( k == 0 ) {

                    sel_number[k].Name  = "Demo Numbers" ;

                    sel_number[k].Select_Size = 30 ;

                    // --- shrink size of next tools ---

                    d_x = (d_x - 2*Space_Dim) / 3 ;

              }

 

              sel_number[k].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 )

{

short          k ;

 

          // --- 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 boxes ---

          sel_demo_1.Draw() ;

          sel_demo_2.Draw() ;

          sel_demo_3.Draw() ;

          for ( k=0; k < 4; k++ )

              sel_number[k].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 )

{

short          k ;

 

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

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          sel_demo_1.Deselect() ;

          sel_demo_2.Deselect() ;

          sel_demo_3.Deselect() ;

          for ( k=0; k < 4; k++ )

              sel_number[k].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 )

{

short          k ;

 

          // --- 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 tool's box.

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

          if ( sel_demo_1.Select( up_down ) ) {

              // --- Read the index of the button. ---

              // -1 is used for a click on the arrows, so we skip it ---

              int rep = sel_demo_1.Read() ;

              if ( rep >= 0 ) {

                    sel_demo_1.Cur_Value = rep ;

                    sel_demo_1.Adjust() ;

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

              }

              return( 1 ) ;

          }

 

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

          if ( sel_demo_2.Select( up_down ) ) {

              // --- Read the index of the button. ---

              // -1 is used for a click on the arrows, so we skip it ---

              int rep = sel_demo_2.Read() ;

              if ( rep >= 0 ) {

                    sel_demo_2.Cur_Value = rep ;

                    sel_demo_2.Adjust() ;

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

              }

 

              return( 1 ) ;

          }

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

          if ( sel_demo_3.Select( up_down ) ) {

              // --- Read the index of the button. ---

              // -1 is used for a click on the arrows, so we skip it ---

              int rep = sel_demo_3.Read() ;

              if ( rep >= 0 ) {

                    sel_demo_3.Cur_Value = rep ;

                    sel_demo_3.Adjust() ;

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

              }

 

              return( 1 ) ;

          }

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

          for ( k=0; k < 4; k++ )

              if ( sel_number[k].Select( up_down ) ) {

                    // --- Read the index of the button. ---

                    // -1 is used for a click on the arrows, so we skip it ---

                    int rep = sel_number[k].Read() ;

                    if ( rep >= 0 ) {

                        sel_number[k].Cur_Value = rep ;

                        sel_number[k].Adjust() ;

                    }

                    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 )

{

short          k ;

 

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

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

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

          // if the cursor is over it.

          //

          // Note: since box #2 has the "OUTIL_DISABLE" bit

          //       set in its flag, the "select" has no

          //       effect on it.

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

          sel_demo_1.Select( up_down ) ;

          sel_demo_2.Select( up_down ) ;

          sel_demo_3.Select( up_down ) ;

          for ( k=0; k < 4; k++ )

              sel_number[k].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 )

{

short          k ;

 

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

          if ( sel_demo_1.Select( KEY_QUERY ) ) {

              sel_demo_1.Cur_Value = sel_demo_1.Scroll( -count ) ;

              sel_demo_1.Adjust() ;

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

              return( 1 ) ;

          }

 

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

          if ( sel_demo_2.Select( KEY_QUERY ) ) {

              sel_demo_2.Cur_Value = sel_demo_2.Scroll( -count ) ;

              sel_demo_2.Adjust() ;

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

              return( 1 ) ;

          }

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

          if ( sel_demo_3.Select( KEY_QUERY ) ) {

              sel_demo_3.Cur_Value = sel_demo_3.Scroll( -count ) ;

              sel_demo_3.Adjust() ;

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

              return( 1 ) ;

          }

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

          for ( k=0; k < 4; k++ )

              if ( sel_number[k].Select( KEY_QUERY ) ) {

                    sel_number[k].Cur_Value = sel_number[k].Scroll( -count ) ;

                    sel_number[k].Adjust() ;

                    return( 1 ) ;

              }

          return( 0 ) ;

}

 

...