TomoVision_Tools: Color_Edit

 

 

The Color_Edit class enable you to draw a color edition tool in the interface.  This tool is composed of 3 sliders, one each for the red, green and blue component of the color, or if the tool is in HLS mode, one slider for hue, one for light and one for saturation.  The tool also has a preview box to display the resulting color, and an optional button to toggle between the RGB and HLS modes.  If the tool is given  name, it will be placed at the top of the tool's box. 

 

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

 

VALUATOR_LOCK

 

 

 

 

 

COLOR_TOGGLE

 

// Add a "RGB" / "HLS" button to the tool

 

 

The variables that are specific to the Color_Edit class are:

 

 

unsigned long          Cur_Value ;

// current value of the color (32 bit integer with 8 bits for red, green and blue).

          

           

 

The methods that are specific to the Color_Edit are:

 

 

unsigned long          Read( void ) ;

// return the value of the color defined by the mouse position.

 

unsigned long          Scroll( int val ) ;

//

 

          

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

 

The tool_test_colors_ctrl.cpp file from the Colors demo

 

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

static          Color_Edit          col_demo_1 ;

static          Hue_Edit          col_demo_2 ;

 

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

//

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

short          Val_Dim_Mid =           (short) Fct_Variable_Value( "$INTERFACE_VAL_DIM_MID" ) ;

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

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

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

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

 

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

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

                         + Val_Dim_Mid                    // hue edit

                         + Space_Dim                    // space between box1 and box 2

                         + TOOL_COL_DIM                    // color edit

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

          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          Title_Dim_Sml =           (short) Fct_Variable_Value( "$INTERFACE_TITLE_DIM_SML" ) ;

short          Val_Dim_Sml =           (short) Fct_Variable_Value( "$INTERFACE_VAL_DIM_SML" ) ;

short          Val_Dim_Mid =              (short)  Fct_Variable_Value( "$INTERFACE_VAL_DIM_MID" ) ;

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 ;

          }

 

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

          // --- Box 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 = TOOL_COL_DIM ;

 

          col_demo_1.Flag      = COLOR_TOGGLE | VALUATOR_LOCK ;// | OUTIL_NO_3D ; ;

          col_demo_1.Name      = "Color Edit" ;

          col_demo_1.Pos_X     = p_x ;

          col_demo_1.Pos_Y     = p_y ;

          col_demo_1.Dim_X     = d_x ;

          col_demo_1.Dim_Y     = d_y ;

          col_demo_1.border    = Border_Dim ;

          col_demo_1.color     = box_box.color ;

          col_demo_1.Font_Name   = Tools_Font_Name ;

          col_demo_1.Font_Weight = Tools_Font_Weigth ;

          col_demo_1.Font_Scale  = Tools_Font_Scale ;

          col_demo_1.Init( wnd ) ;

 

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

          // --- Box 2

          //

          // disbaled (blue outline only)

          //

          // Note: we use "OUTIL_OUT". It is an or of 3 bits:

          //       OUTIL_DISABLE   (so that the "select" has no effect)

          //           OUTIL_INVISIBLE (the normal graphic is not drawn)

          //           OUTIL_OUTLINE   (blue outlines of the tool are drawn)

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

          p_y += d_y + Space_Dim ;

          d_y = Val_Dim_Mid ;

 

          col_demo_2.Flag      = VALUATOR_LOCK | OUTIL_NO_3D ; ;

          col_demo_2.Name      = "Hue Edit" ;

          col_demo_2.Pos_X     = p_x ;

          col_demo_2.Pos_Y     = p_y ;

          col_demo_2.Dim_X     = d_x ;

          col_demo_2.Dim_Y     = d_y ;

          col_demo_2.border    = Border_Dim ;

          col_demo_2.Font_Name   = Tools_Font_Name ;

          col_demo_2.Font_Weight = Tools_Font_Weigth ;

          col_demo_2.Font_Scale  = Tools_Font_Scale ;

          col_demo_2.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 boxes ---

          col_demo_1.Draw() ;

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

 

          col_demo_1.Deselect() ;

          col_demo_2.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 ( col_demo_1.Select( up_down ) ) {

              col_demo_1.Cur_Value = col_demo_1.Read() ;

              col_demo_1.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_1.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_1.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_1.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in color edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

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

          if ( col_demo_2.Select( up_down ) ) {

              col_demo_2.Cur_Value = col_demo_2.Read() ;

              col_demo_2.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_2.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_2.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_2.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in hue edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

          return( 1 ) ;

}

 

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

//

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

          // we can use the same code as Click

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

          if ( col_demo_1.Select( up_down ) ) {

              col_demo_1.Cur_Value = col_demo_1.Read() ;

              col_demo_1.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_1.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_1.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_1.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Motion in color edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

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

          if ( col_demo_2.Select( up_down ) ) {

              col_demo_2.Cur_Value = col_demo_2.Read() ;

              col_demo_2.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_2.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_2.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_2.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Motion in hue edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

          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 ( col_demo_1.Select( KEY_QUERY ) ) {

              col_demo_1.Cur_Value = col_demo_1.Scroll(count) ;

              col_demo_1.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_1.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_1.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_1.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Scroll in color edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

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

          if ( col_demo_2.Select( KEY_QUERY ) ) {

              col_demo_2.Cur_Value = col_demo_2.Scroll(count) ;

              col_demo_2.Adjust() ;

              unsigned char red = RED_BYTE(col_demo_2.Cur_Value) ;

              unsigned char grn = GRN_BYTE(col_demo_2.Cur_Value) ;

              unsigned char blu = BLU_BYTE(col_demo_2.Cur_Value) ;

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Scroll in hue edit, color= R:%d G:%d B:%d", red, grn, blu) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

 

 

...