Draw_Cursor

 

The "Draw_Cursor()" function is used to draw (and erase) cursors. 

 

The function call a number of OpenGL drawing functions to draw the shape of the cursor on the screen.  OpenGL will use XOR operation to draw the cursor on the images.  The same function will be called with the same parameters when sliceO want to remove the cursor. Even though X and Y are provided, you do not need them, when your function is called, the drawing matrix has already centered OpenGL on the position where you will draw the cursor.  You do need scale and ratio to adjust the matrix to the correct size for your cursor.

 

 

Syntax

 

extern "C" __declspec(dllexportint  Draw_Cursor(

          int up_down,

          int brush,

          int x, int y,

          float scale,

          float ratio

)

 

 

Parameters

 

up_down

Is an image of the 3 mouse button states. The lower byte contain a code giving the mouse button action (off, on, pressed or double clicked).  The next byte give the state of each of the 3 keys as on or off. The different values for the variable are:

 

KEY_DBLCLK          3

KEY_PRESS          2

KEY_ON          1

KEY_OFF          0

MOUSE_KEY_LEFT          0x010

MOUSE_KEY_MIDDLE          0x020

MOUSE_KEY_RIGHT          0x040

 

So, for example, if you click on the left mouse button, the value of up_down will be (KEY_PRESS | MOUSE_KEY_LEFT). When you release the button the value will be KEY_OFF.

 

brush

Is the Size (in pixel) of the brush diameter.

 

x, y

Horizontal (x) and vertical (y) position of the cursor within the current window. (0,0 at bottom left).

 

scale

Is the pixel scaling factor. A pixel of the image can use many pixels of the screen.

 

ratio

Is the screen pixel aspect ration.

 

 

Return value

 

The function returns "0" if an error occurred, "1" otherwise.

 

 

Remarks

 

The Draw_Cursor() function is only called if your DLL specify a Mode not a Tool.

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

Library:

          sliceO_Structures.lib

 

 

Example

 

...

 

#include          <windows.h>

#include          "sliceO_OpenGL.hpp"

 

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

//

//          Function:          Draw_Cursor

//

//          Parameters:          up_down (int)          Give the mouse key status.

//                              brush (int)          Size (in pixel) of the brush diameter

//                              scale (float)          pixel scaling factor

//                              ratio (float)          Vertical/vs/horiz pixel dim. ratio

//          Returns:          (int)                    1 if you did draw something.

//

//          This is called each time the cursor is drawn or erased.  If you want to

//          control the shape of the cursor, you can do it here.  The cursor is

//          drawn in OpenGL.  The matrix is already set so that the cursor is

//          centered and an horizontal pixel is measured 1.0.

//

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

extern "C" __declspec(dllexport) int          Draw_Cursor( int up_down, int brush, int x, int y, float scale, float ratio )

{

 

          // --- The brush is deformed according to the pixel ratio ---

          glScalef( 1.01f, 1.01f, 1.0f ) ;

          glScalef( 1.0f, ratio, 1.0f ) ;

          // --- Compute the actual brush size (minimum is 1 pixel of radius) ---

          float size = brush*scale*0.5f ;

          size = MAX( 1.0f, size ) ;

          glScalef( size, size, 1.0f ) ;

          glLineWidth( 1.0f );

 

          YGL_ERROR("glMatrix") ;

 

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

          // This is the "standard" cursor: a round brush (unless the middle

          // mouse key is pressed, or the brush is 1x1, then it is a square brush)

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

 

          // --- square brush for 1x1 and middle mouse button ---

          if ( (up_down & MOUSE_KEY_MIDDLE) || (brush <= 1) ) {

 

              // --- square brush ---

              glBegin( GL_LINE_LOOP ) ;

                    glVertex2i( -1, -1 ) ;

                    glVertex2i( -1,  1 ) ;

                    glVertex2i(  1,  1 ) ;

                    glVertex2i(  1, -1 ) ;

              glEnd( ) ;

              YGL_ERROR("glBegin/End") ;

 

          // --- normal round brush ---

          } else {

 

              // --- nb_step fct of radius ---

              float step = (2.0f*M_PI) / (8.0f * size) ;

 

              glBegin( GL_LINE_LOOP ) ;

                    for ( float angle=0.0f; angle <= 2*M_PI; angle += step )

                        glVertex2f( sinf(angle), cosf(angle) ) ;

              glEnd( ) ;

              YGL_ERROR("glBegin/End") ;

          }

          return( 1 ) ;

}

 

...

 

See also