Brush Selection

 

 

 

The Tool_Brush class enable you to draw a tool that is used to select the Current Brush. Clicking on one of the brush's buttons will select it inside the tool.  The "Read()" method can then be used to return its index.

 

 

The variables of the Tool_Brush class are:

 

There is no variable associated with this class.

 

 

The methods of the Tool_Brush class are:

 

 

Tool_Brush( void ) ;

 

Constructor

 

~Tool_Brush() ;

 

Destructor

 

int          Read( void ) ;

 

Return the index of the currently selected brush.

You should use this method inside "Ctrl_Click" function to update the current brush's variable.

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

          unsigned short *Brush_Cur = (unsigned short *) Fct_Variable_Get( "$BRUSH_CUR" ) ;

          if ( ! Brush_Cur )

                    return( 0 ) ;

          if ( *Brush_Cur != tool_brush.Read() ) {

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

                    *Brush_Cur = tool_brush.Read() ;

                    Fct_Update( UPDATE_CUR_BRUSH ) ;

          }

          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_CUR_BRUSH          // the current brush has changed

 

 

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

 

Brush_Max

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

 

You can get the value of  this variable with:

unsigned short          Brush_Max =           (unsigned short)           Fct_Variable_Value( "$BRUSH_MAX" ) ;

 

Brush_Nb

The number of brushes defined in sliceO. (default = 6)

 

You can get the value of  this variable with:

unsigned short          Brush_Nb =           (unsigned short)           Fct_Variable_Value( "$BRUSH_NB" ) ;

You can get a pointer to this variable with:

unsigned short *          Brush_Nb =           (unsigned short)           Fct_Variable_Get( "$BRUSH_NB" ) ;

 

Brush_Cur

The currently selected brush.

 

You can get the value of  this variable with:

unsigned short          Brush_Cur =           (unsigned short)           Fct_Variable_Value( "$BRUSH_NB" ) ;

You can get a pointer to this variable with:

unsigned short *          Brush_Cur =           (unsigned short)           Fct_Variable_Get( "$BRUSH_NB" ) ;

 

Brush_Radius

Maximum radius of the brushes. This variable is read only. (=25)

 

You can get the value of  this variable with:

unsigned short          Brush_Radius =           (unsigned short)           Fct_Variable_Value( "$BRUSH_RADIUS" ) ;

 

Brush_Size

A vector of brush size (one per brush).  The size is the radius (in pixels) of the brush's circle. (default = 1, 2, 4, 6, 8, 10)

 

You can get the value of  this variable with:

unsigned short  *          Brush_Size =           (unsigned short *)           Fct_Variable_Value( "$BRUSH_SIZE" ) ;

 

Brush_Big

The size of the big square brush (when the middle mouse button is pressed). (default =15)

 

You can get the value of  this variable with:

unsigned short          Brush_Big =           (unsigned short)           Fct_Variable_Value( "$BRUSH_BIG" ) ;

You can get a pointer to this variable with:

unsigned short *          Brush_Big =           (unsigned short)           Fct_Variable_Get( "$BRUSH_BIG" ) ;

 

Brush_Pt

A vector of 2D images for the brush matrix (one per brush). Each matrix is 2*Brush_Radius+1 by 2*Brush_Radius+1. each element of the matrix is an unsigned char, either transparent (0) or opaque (1).

 

You can get the value of  this variable with:

unsigned char ***          Brush_Pt =           (unsigned char ***)           Fct_Variable_Value( "$BRUSH_PT" ) ;

 

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

 

 

The tool_brush_ctrl.cpp file from the Tool_Brush demo

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

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

static          Boxs          box_brush ;

static          Tool_Brush          tool_brush ;

 

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

//

//          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_brush.Height()          // brush selection

                         + 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 Brush_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_brush.Height() ;

 

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

          box_brush.Flag = OUTIL_EMPTY ;

          box_brush.Pos_X = p_x ;

          box_brush.Pos_Y = p_y ;

          box_brush.Dim_X = d_x ;

          box_brush.Dim_Y = d_y ;

          box_brush.color = box_box.color ;

          box_brush.border = Border_Dim;

          box_brush.Init( wnd ) ;

 

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

          tool_brush.Resize( &box_brush ) ;

 

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

 

          // --- Brush Selection Tool ---

          tool_brush.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_brush.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 ) ;

          }

 

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

          // ---              Brush Selection Tool                    ---

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

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

              unsigned short *Brush_Cur = (unsigned short *) Fct_Variable_Get( "$BRUSH_CUR" ) ;

              if ( ! Brush_Cur )

                    return( 0 ) ;

              if ( *Brush_Cur != tool_brush.Read() ) {

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

                    *Brush_Cur = tool_brush.Read() ;

                    Fct_Update( UPDATE_CUR_BRUSH ) ;

              }

              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_brush.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.

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

 

          // --- Brush Selection Tool ---

          if ( box_brush.Select( up_down ) )

              tool_brush.Motion( up_down ) ;

 

          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_brush.Update( flag ) ;

          }

 

          // --- Changes that affect the Brushes ---

          if ( flag & UPDATE_CUR_BRUSH ) {

              tool_brush.Update( flag ) ;

          }

 

          return( 1 ) ;

}

 

...