TomoVision_Tools: Texts

 

The Texts class enable you to draw a rectangular text box in the interface. 

 

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

 

TEXT_READ_WIND

TEXT_INPUT_WIND

 

// Tool include an input line

// Tool is only composed of the input line

 

TEXT_PASSWD

 

// The input line feedback is only "*" characters

 

TEXT_INT_ONLY

TEXT_FLOAT_ONLY

TEXT_HEX_ONLY

 

// The input line only accept integer values (0 to 9)

// The input line only accept floating point values (0 to 9, . and e)

// The input line only accept hexadecimal values (0 to 9, A to F)

 

TEXT_H_CURSOR

TEXT_V_CURSOR

 

// Tool include an horizontal slider

// Tool include an vertical slider

 

TEXT_KEY_FEEDBACK

 

// Input line is updated after each character

 

The methods that are specific to the valuators are:

 

 

void          Read( char *str, ... ) ;

// Put the tool in input mode and write text to the input line

 

void          Scroll( int val ) ;

// Scroll the text window "val" lines

 

void          Write( char *str, ... ) ;

// Write a line of text to the tool

 

void          OverWrite( char *format, ... ) ;

// Overwrite a line of text

 

void          Cleanup( void ) ;

// clear the old text

 

void          Input( int c ) ;

// Catch the characters typed in the input window

 

When writing text to the tool, some ASCII values are reserved for font and color controls:

 

 

0x01

0x02

0x03

0x04

0x05

0x06

Blue text

Black text

White text

Red text

Yellow text

Green text

 

0xF0

0xF1

0xF2

Normal text

Bold text

Italic text

          

ex:

text.Write( "Text: \01 Blue, \02 Black, \03 White \04 Red, \05 Yellow, \06 Green" ) ;

text.Write( "Text: \xF0 Normal, \xF1 Bold, \xF2 Italic" ) ;

 

 

 

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

 

 

 

The tool_test_texts_ctrl.cpp file from the Texts demo

 

 

...

 

// --- Interface tools ---

static          Boxs          box_box ;

 

static          Texts          demo_1 ;

static          Texts          demo_2 ;

static          Texts          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          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

                         + 25                              // Box 1

                         + Space_Dim                    // space between box1 and box 2

                         + 150                              // Box 2

                         + Space_Dim                    // space between box2 and box 3

                         + 100                              // Box 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 Texts -------" ;

          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 ;

          }

 

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

          // --- Box 1:

          //

          // Default FLAG value (=NULL) with title

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

          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 = 100 ;

 

          demo_1.Name      = "Demo Text 1" ;

          demo_1.Pos_X     = p_x ;

          demo_1.Pos_Y     = p_y ;

          demo_1.Dim_X     = d_x ;

          demo_1.Dim_Y     = d_y ;

          demo_1.border    = Border_Dim ;

          demo_1.Font_Name   = Tools_Font_Name ;

          demo_1.Font_Weight = Tools_Font_Weigth ;

          demo_1.Font_Scale  = Tools_Font_Scale ;

          demo_1.Init( wnd ) ;

 

          // --- write a couple of lines ---

          demo_1.Write( "Text: \001Blue, \002Black, \003White, \004Red, \005Yellow, \006Green" ) ;

          demo_1.Write( "Text: \xF0 Normal, \xF1 Bold, \xF2 Italic" ) ;

          demo_1.Read(  "Edit this line and press \"Enter\"" ) ;

 

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

          // --- Box 2

          //

          // With both vertical and horizontal sliders

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

          p_y += d_y + Space_Dim ;

          d_y = 150 ;

 

          demo_2.Flag      = TEXT_H_CURSOR | TEXT_V_CURSOR ;

          demo_2.Pos_X     = p_x ;

          demo_2.Pos_Y     = p_y ;

          demo_2.Dim_X     = d_x ;

          demo_2.Dim_Y     = d_y ;

          demo_2.border    = Border_Dim ;

          demo_2.Font_Name   = Tools_Font_Name ;

          demo_2.Font_Weight = Tools_Font_Weigth ;

          demo_2.Font_Scale  = Tools_Font_Scale ;

          demo_2.Init( wnd ) ;

 

          // --- write a few lines to show the cursors ---

          demo_2.Write( "Text Demo Window #2 line 1: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 2: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 3: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 4: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 5: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 6: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 7: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 8: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 9: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 10: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 11: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 12: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 13: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 14: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 15: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 16: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 17: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 18: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

          demo_2.Write( "Text Demo Window #2 line 19: with a long line of text that should be long enough to necessitate the use of the horizontal slider" ) ;

 

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

          // --- Box 3

          //

          // input line only

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

          p_y += d_y + Space_Dim ;

          d_y = 25 ;

 

          demo_3.Flag      = TEXT_INPUT_WIND ;

          demo_3.Name      = "Demo Text 3" ;

          demo_3.Pos_X     = p_x ;

          demo_3.Pos_Y     = p_y ;

          demo_3.Dim_X     = d_x ;

          demo_3.Dim_Y     = d_y ;

          demo_3.border    = Border_Dim ;

          demo_3.Font_Name   = Tools_Font_Name ;

          demo_3.Font_Weight = Tools_Font_Weigth ;

          demo_3.Font_Scale  = Tools_Font_Scale ;

          demo_3.Init( wnd ) ;

 

          demo_3.Read(  "Edit this line and press \"Enter\"" ) ;

 

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

          demo_1.Draw() ;

          demo_2.Draw() ;

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

          if ( ! Flag_Ctrl_Wnd_On )

              return( 1 ) ;

          if ( ! Flag_Ctrl_Visible )

              return( 1 ) ;

 

          demo_1.Deselect() ;

          demo_2.Deselect() ;

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

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in box #1" ) ;

              return( 1 ) ;

          }

 

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

          if ( demo_2.Select( up_down ) ) {

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in box #2" ) ;

              return( 1 ) ;

          }

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

          if ( demo_3.Select( up_down ) ) {

              Error_Fct( hwnd, ERROR_CODE_REPORT, "Click in box #3" ) ;

              return( 1 ) ;

          }

 

          return( 1 ) ;

}

 

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

//

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

{

 

          // --- we activated a keyborad key while inside a text window ---

          if ( demo_3.Select( 1 ) ) {

              // --- parse this key ---

              demo_3.Input( key ) ;

              // --- did we press "Enter?" ---

              char *str = demo_3.Update() ;

              if ( str ) {

                    Error_Fct( hwnd, ERROR_CODE_REPORT, "Text #3, read: \"%s\"", str ) ;

                    // --- put back in "read" mode ---

                    demo_3.Read( "" ) ;

              }

              return( 1 ) ;

          }

 

          if ( demo_1.Select( 1 ) ) {

              // --- parse this key ---

              demo_1.Input( key ) ;

              // --- did we press "Enter?" ---

              char *str = demo_1.Update() ;

              if ( str ) {

                    Error_Fct( hwnd, ERROR_CODE_REPORT, "Text #1, read: \"%s\"", str ) ;

                    // --- put back in "read" mode ---

                    demo_1.Read( "" ) ;

              }

              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.

          //

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

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

          //       effect on it.

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

          demo_1.Select( up_down ) ;

          demo_2.Select( up_down ) ;

          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 )

{

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

          // The scroll can be used by the vertical and horizontal cursors

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

          if ( demo_1.Select( KEY_QUERY ) ) {

              demo_1.Scroll( -count ) ;

              return( 1 ) ;

          }

 

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

          if ( demo_2.Select( KEY_QUERY ) ) {

              demo_2.Scroll( -count ) ;

              return( 1 ) ;

          }

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

          if ( demo_3.Select( KEY_QUERY ) ) {

              demo_3.Scroll( -count ) ;

              return( 1 ) ;

          }

 

          return( 0 ) ;

}

...