TAG Selection

 

 

 

The Tool_Tag class enable you to draw a tool that is used to select the Current TAG.  Clicking on one of the TAG's buttons will select it inside the tool.  The "Read()" method can then be used to return its index.  Right clicking on a button will open a text interface that is used to change the TAG's label.

 

 

The variables of the Tool_Tag class are:

 

There is no variable associated with this class.

 

 

The methods of the Tool_Tag class are:

 

 

Tool_TAG( void ) ;

Tool_TAG( unsigned short flag ) ;

 

Constructor. The "flag" variable is used to control the appearance of the tags depending on the "enable", "lock" or "select" flags.

 

The following values of "flag" are permitted:

TOOL_TAG_ENABLE_AS_ENABLE

// if the "enable" flag is off, the tag's button is disabled.

TOOL_TAG_LOCK_AS_ENABLE

// if the "lock" flag is on, the tag's button is disabled.

TOOL_TAG_SELECT_AS_ENABLE

// if the "select" flag is off, the tag's button is disabled.

 

TOOL_TAG_ENABLE_AS_LIGHT

// if the "enable" flag is on, the tag's button light is on.

TOOL_TAG_LOCK_AS_LIGHT

// if the "lock" flag is on, the tag's button light is on.

TOOL_TAG_SELECT_AS_LIGHT

// if the "select" flag is on, the tag's button light is on.

 

If no value for "flag" is specified, TOOL_TAG_LOCK_AS_ENABLE is assumed.

 

 

~Tool_TAG() ;

 

Destructor

 

int          Read( void ) ;

 

Return the index of the currently selected TAG.

You should use this method inside "Ctrl_Click" function to update one of the brush variables.

if ( tool_tag.Click( up_down ) >= 0  ) {

          unsigned short *TAG_Cur = (unsigned short *) Fct_Variable_Get( "$TAG_CUR" ) ;

          if ( ! TAG_Cur )

                    return( 0 ) ;

          if ( *TAG_Cur != tool_tag.Read() ) {

                    // --- we changed the current tag ---

                    *TAG_Cur = tool_tag.Read() ;

                    Fct_Update( UPDATE_CUR_TAG ) ;

          }

          return( 1 ) ;

}

 

 

The methods shared with the other SliceO_Tool classes are:

 

 

int          Click( int up_down ) ;

You must call this method if the user has activated a mouse button while the cursor is inside the tool

 

void          Draw( void ) ;

 

This method will draw the tool

 

int          Height( unsigned short nb=10 ) ;

This method returns the height (in pixel) of the tool. The "nb" parameter defines how many lines of information will be displayed.

 

int          Keyboard( int key ) ;

You must call this method if the user has activated a keyboard key while the cursor is inside the tool

 

void          Leave( void ) ;

 

You must call this method if the user move the cursor outside of the tool

 

int          Motion( int up_down ) ;

 

You must call this method if the user move the cursor inside the tool

 

int          Resize( Boxs *box ) ;

You must call this method to resize the tool. The tool will reside inside the bounding box of the "Boxs" class.

 

int          Scroll( int val ) ;

You must call this method if the user has activated the mouse wheel while the cursor is inside the tool

 

void          Update( UInt64 flag )

You must call this method when external events change the content of the tool.  The "flag" parameter is the "Update Flag" defining these changes.

The update should be called if one of the following flags are changed:

UPDATE_ALL_TOOLS

UPDATE_CUR_TAG          // the current tag has changed

UPDATE_COLOR_TAG          // the color of a tag has changed

UPDATE_TAG_LABEL          // the label of a tag has changed

UPDATE_TAG_ENABLE          // the enable flag on a tag has changed

UPDATE_TAG_LOCK          // the lock flag on a tag has changed

UPDATE_TAG_SELECT          // the select flag on a tag has changed

 

 

The TAGs in sliceOmatic are controlled by a number of system variables:

 

TAG_Max

The maximum number of TAGs that can be defined in sliceO.  This variable is read only. (=256)

 

You can get the value of  this variable with:

unsigned short          TAG_Max =           (unsigned short)           Fct_Variable_Value( "$TAG_MAX" ) ;

 

TAG_Nb

The number of TAGs defined in sliceO. (default = 128)

 

You can get the value of  this variable with:

unsigned short          TAG_Nb =           (unsigned short)           Fct_Variable_Value( "$TAG_NB" ) ;

You can get a pointer to this variable with:

unsigned short *          TAG_Nb =           (unsigned short)           Fct_Variable_Get( "$TAG_NB" ) ;

 

TAG_Cur

The currently selected TAG value.

 

You can get the value of  this variable with:

unsigned short          TAG_Cur =           (unsigned short)           Fct_Variable_Value( "$TAG_NB" ) ;

You can get a pointer to this variable with:

unsigned short *          TAG_Cur =           (unsigned short)           Fct_Variable_Get( "$TAG_NB" ) ;

 

TAG_Red,

TAG_Grn,

TAG_Blu,

TAG_Alpha

Each of these is a vector of component colors (one per tag). The high byte is used to represent the color's component intensity (0 to 255).

 

You can get the value of  this variable with:

unsigned short *          TAG_Red =           (unsigned short *)           Fct_Variable_Value( "$TAG_RED" ) ;

 

TAG_Label

A vector of TAG labels (one per tag).

 

You can get the value of  this variable with:

char   **          TAG_Label =           (char **)           Fct_Variable_Value( "$TAG_LABEL" ) ;

 

TAG_Mix

The TAG opacity when displaying images in mode "Mix". (default = 0.5)

 

You can get a pointer to this variable with:

float  *          TAG_Mix =           (float *)           Fct_Variable_Get( "$TAG_MIX" ) ;

 

TAG_Enable

A vector of "enable" flags (one per tag).

 

You can get the value of  this variable with:

unsigned char *          TAG_Enable =           (unsigned char *)           Fct_Variable_Value( "$TAG_ENABLE" ) ;

 

TAG_Lock

A vector of "lock" flags (one per tag).

 

You can get the value of  this variable with:

unsigned char *          TAG_Lock =           (unsigned char *)           Fct_Variable_Value( "$TAG_LOCK" ) ;

 

TAG_Select

A vector of "select" flags (one per tag).

 

You can get the value of  this variable with:

unsigned char *          TAG_Select =           (unsigned char *)           Fct_Variable_Value( "$TAG_SELECT" ) ;

 

 

An example of the usage of the Tool_Tag class is given in the Samples\SliceO Tools\Tag_Selection demo directory. 

 

 

The tool_tag_ctrl.cpp file from the Tool_Tag demo

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

// --- for Brush Selection Tool ---

static          Boxs          box_tag ;

static          Tool_Tag          tool_tag( TOOL_TAG_LOCK_AS_ENABLE ) ;

 

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

//

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

{

          // --- this is a 2D TAG tool only ---

          if ( mode )

              (*mode) = SLICEO_TOOL_2D ;

 

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

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

                         + tool_tag.Height(4)          // tag selection tool (4 buttons high)

                         + 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 = "------- SliceO TAG_Selection -------" ;

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

 

 

          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 ;

          }

 

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

          // --- Brush_Selection Tool

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

          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 = tool_tag.Height(4) ;

 

          // --- The tool will be inside this box ---

          box_tag.Flag = OUTIL_NO_3D ;

          box_tag.Pos_X = p_x ;

          box_tag.Pos_Y = p_y ;

          box_tag.Dim_X = d_x ;

          box_tag.Dim_Y = d_y ;

          box_tag.color = box_box.color ;

          box_tag.border    = Border_Dim;

          box_tag.Font_Name   = Tools_Font_Name ;

          box_tag.Font_Weight = Tools_Font_Weigth ;

          box_tag.Font_Scale  = Tools_Font_Scale ; // + 1 ;

          box_tag.Init( wnd ) ;

          box_tag.Flag = OUTIL_EMPTY ;

 

          // --- now prepare the tool itself ---

          tool_tag.Resize( &box_tag ) ;

 

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

 

          // --- TAG Selection Tool ---

          tool_tag.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 invible, we can get out ---

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          tool_tag.Leave() ;

 

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

          }

 

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

          // ---              TAG Selection Tool                              ---

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

          if ( tool_tag.Click( up_down ) >= 0  ) {

              unsigned short *TAG_Cur = (unsigned short *) Fct_Variable_Get( "$TAG_CUR" ) ;

              if ( ! TAG_Cur )

                    return( 0 ) ;

              if ( *TAG_Cur != tool_tag.Read() ) {

                    // --- we changed the current tag ---

                    *TAG_Cur = tool_tag.Read() ;

                    Fct_Update( UPDATE_CUR_TAG ) ;

              }

              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 )

{

          // --- Brush Selection Tool ---

          if ( tool_tag.Keyboard( key ) )

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

          // if the cursor is over it.

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

 

          // --- TAG Selection Tool ---

          if ( box_tag.Select( up_down ) )

              tool_tag.Motion( up_down ) ;

 

          return( 0 ) ;

}

 

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

//

//          Function:          Ctrl_Scroll

//

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

//          wheel has been activated.

//

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

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

{

          // --- TAG Selection Tool ---

          if ( box_tag.Select( KEY_QUERY ) ) {

              tool_tag.Scroll( count ) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

 

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

//

//          Function:          Ctrl_Update

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called each time something has been modified from another

//          control and sliceO Beleive it may affect you.

//

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

int          Ctrl_Update( UInt64 flag )

{

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

 

          // --- Changes that affect both TAGs and Brushes ---

          if ( flag & (UPDATE_CUR_TAG | UPDATE_COLOR_TAG) ) {

              tool_tag.Update( flag ) ;

          }

 

          // --- Changes that affect the TAGs ---

          if ( flag & (UPDATE_TAG_LABEL | UPDATE_TAG_LOCK) ) {

              tool_tag.Update( flag ) ;

          }

 

          return( 1 ) ;

}

...